Skip to content

Commit

Permalink
fix: broken publishes for expires/create
Browse files Browse the repository at this point in the history
Result of nonexistent options prop of mqttclient
  • Loading branch information
hi-liang committed Jan 8, 2025
1 parent 7788423 commit 9051952
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ arenaSchema.index({'attributes.parent': 1}, {sparse: true});
const ArenaObject = mongoose.model('ArenaObject', arenaSchema);

let mqttClient;
let mqttClientOptions;
let persists = new Set();
let expirations;
let expireTimer;
Expand Down Expand Up @@ -86,7 +87,7 @@ mongoose.connect(config.mongodb.uri).then(async () => {
* Initializes MQTT connection and setts event handlers
*/
async function runMQTT() {
const connectOpts = {
mqttClientOptions = {
clientId: 'arena_persist' + config.mqtt.topic_realm + '_' + Math.floor(Math.random() * 100),
clean: false, // Receive QoS 1+ messages (object delete) always
qos: 1,
Expand Down Expand Up @@ -442,7 +443,7 @@ const createArenaObj = async (
await mqttClient.publish(TOPICS.PUBLISH.SCENE_OBJECTS.formatStr({
nameSpace: namespace,
sceneName: sceneId,
userClient: mqttClient.options.clientId,
userClient: mqttClientOptions.clientId,
// eslint-disable-next-line camelcase
objectId: object_id,
}), JSON.stringify(msg));
Expand Down Expand Up @@ -530,7 +531,7 @@ const publishExpires = async () => {
await mqttClient.publish(TOPICS.PUBLISH.SCENE_OBJECTS.formatStr({
nameSpace: obj.namespace,
sceneName: obj.sceneId,
userClient: mqttClient.options.clientId,
userClient: mqttClientOptions.clientId,
// eslint-disable-next-line camelcase
objectId: obj.object_id,
}), JSON.stringify(msg));
Expand Down

0 comments on commit 9051952

Please sign in to comment.