Skip to content
This repository has been archived by the owner on Mar 3, 2022. It is now read-only.

Commit

Permalink
fix: resend device statuses to core, on core reconnect
Browse files Browse the repository at this point in the history
  • Loading branch information
nytamin committed Apr 21, 2021
1 parent e4de498 commit 2c139f6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/coreHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ export class CoreMosDeviceHandler {
}
onMosConnectionChanged (connectionStatus: IMOSConnectionStatus) {

let statusCode = P.StatusCode.UNKNOWN
let statusCode: P.StatusCode
let messages: Array<string> = []

if (connectionStatus.PrimaryConnected) {
Expand Down
18 changes: 15 additions & 3 deletions src/mosHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
} from 'mos-connection'
import * as _ from 'underscore'
import * as Winston from 'winston'
import { CoreHandler } from './coreHandler'
import { CoreHandler, CoreMosDeviceHandler } from './coreHandler'
import { CollectionObj } from '@sofie-automation/server-core-integration'

// export interface MosOptions {
Expand Down Expand Up @@ -68,7 +68,7 @@ export class MosHandler {
public mosOptions: MosConfig
public debugLogging: boolean = false

private allMosDevices: {[id: string]: IMOSDevice} = {}
private allMosDevices: {[id: string]: {mosDevice: IMOSDevice, coreMosHandler?: CoreMosDeviceHandler}} = {}
private _ownMosDevices: {[deviceId: string]: MosDevice} = {}
private _logger: Winston.LoggerInstance
private _disposed: boolean = false
Expand Down Expand Up @@ -109,7 +109,9 @@ export class MosHandler {
})
.then(() => {
this._coreHandler.onConnected(() => {
// This is called whenever a connection to Core has been (re-)established
this.setupObservers()
this.sendStatusOfAllMosDevices()
})
this.setupObservers()

Expand Down Expand Up @@ -231,13 +233,15 @@ export class MosHandler {
// a new connection to a device has been made
this._logger.info('new mosConnection established: ' + mosDevice.idPrimary + ', ' + mosDevice.idSecondary)

this.allMosDevices[mosDevice.idPrimary] = mosDevice
this.allMosDevices[mosDevice.idPrimary] = { mosDevice: mosDevice }

return this._coreHandler.registerMosDevice(mosDevice, this)
.then((coreMosHandler) => {
// this._logger.info('mosDevice registered -------------')
// Setup message flow between the devices:

this.allMosDevices[mosDevice.idPrimary].coreMosHandler = coreMosHandler

// Initial Status check:
let connectionStatus = mosDevice.getConnectionStatus()
coreMosHandler.onMosConnectionChanged(connectionStatus) // initial check
Expand Down Expand Up @@ -342,6 +346,14 @@ export class MosHandler {
return
})
}
private sendStatusOfAllMosDevices() {
// Send an update to Core of the status of all mos devices
for (const handler of Object.values(this.allMosDevices)) {
if (handler.coreMosHandler) {
handler.coreMosHandler.onMosConnectionChanged(handler.mosDevice.getConnectionStatus())
}
}
}
private getThisPeripheralDevice (): CollectionObj | undefined {
let peripheralDevices = this._coreHandler.core.getCollection('peripheralDevices')
return peripheralDevices.findOne(this._coreHandler.core.deviceId)
Expand Down

0 comments on commit 2c139f6

Please sign in to comment.