Skip to content

Commit 7a6149d

Browse files
committed
fix: sync at startup being lost
1 parent 9245c19 commit 7a6149d

File tree

2 files changed

+18
-15
lines changed

2 files changed

+18
-15
lines changed

packages/mos-gateway/src/mosHandler.ts

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -309,24 +309,25 @@ export class MosHandler {
309309

310310
deviceEntry.coreMosHandler = coreMosHandler
311311

312-
if (deviceEntry.deviceOptions.statuses?.enabled) {
313-
if (deviceEntry.statusHandler) {
314-
deviceEntry.statusHandler.dispose()
315-
}
316-
deviceEntry.statusHandler = new MosStatusHandler(
317-
this._logger,
318-
mosDevice,
319-
coreMosHandler,
320-
deviceEntry.deviceOptions.statuses,
321-
this.strict
322-
)
323-
}
324-
325312
// Initial Status check:
326313
// Profile 0: -------------------------------------------------
327314
mosDevice.onConnectionChange((newStatus: IMOSConnectionStatus) => {
328315
// MOSDevice >>>> Core
329316
coreMosHandler.onMosConnectionChanged(newStatus)
317+
318+
// Setup the status handler upon first connection to the NRCS
319+
const isConnected = newStatus.PrimaryConnected || newStatus.SecondaryConnected
320+
if (deviceEntry.deviceOptions.statuses?.enabled && !deviceEntry.statusHandler && isConnected) {
321+
// Creating the handler at this point avoids sending status messages before the connection is established,
322+
// allowing for a sync at startup without needing manual queueing
323+
deviceEntry.statusHandler = new MosStatusHandler(
324+
this._logger,
325+
mosDevice,
326+
coreMosHandler,
327+
deviceEntry.deviceOptions.statuses,
328+
this.strict
329+
)
330+
}
330331
})
331332
coreMosHandler.onMosConnectionChanged(mosDevice.getConnectionStatus())
332333
mosDevice.onRequestMachineInfo(async () => {

packages/mos-gateway/src/mosStatusHandler.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,11 @@ export class MosStatusHandler {
110110
if (this.#isDeviceConnected()) {
111111
// Send status
112112
await this.#mosDevice.sendStoryStatus(newStatus)
113+
} else if (this.#config.onlySendPlay) {
114+
// No need to do anything.
115+
this.#logger.info(`Not connected, skipping play status: ${JSON.stringify(newStatus)}`)
113116
} else {
114-
// nocommit
115-
this.#logger.info(`Not connected`)
117+
this.#logger.info(`Not connected, discarding status: ${JSON.stringify(newStatus)}`)
116118
}
117119
})
118120
.catch((e) => {

0 commit comments

Comments
 (0)