Skip to content

Commit 0fadc8a

Browse files
committed
wip: boilerplate
1 parent 17ccf66 commit 0fadc8a

File tree

4 files changed

+73
-45
lines changed

4 files changed

+73
-45
lines changed

packages/mos-gateway/src/$schemas/devices.json

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -63,18 +63,11 @@
6363
"default": 10542
6464
}
6565
},
66-
"required": [
67-
"lower",
68-
"upper",
69-
"query"
70-
],
66+
"required": ["lower", "upper", "query"],
7167
"additionalProperties": false
7268
}
7369
},
74-
"required": [
75-
"id",
76-
"host"
77-
],
70+
"required": ["id", "host"],
7871
"additionalProperties": false
7972
},
8073
"secondary": {
@@ -141,23 +134,30 @@
141134
"default": 10542
142135
}
143136
},
144-
"required": [
145-
"lower",
146-
"upper",
147-
"query"
148-
],
137+
"required": ["lower", "upper", "query"],
149138
"additionalProperties": false
150139
}
151140
},
152-
"required": [
153-
"id",
154-
"host"
155-
],
141+
"required": ["id", "host"],
142+
"additionalProperties": false
143+
},
144+
"statuses": {
145+
"type": "object",
146+
"ui:title": "Statuses",
147+
"title": "MosDeviceStatusesConfig",
148+
"properties": {
149+
"enabled": {
150+
"type": "boolean",
151+
"ui:title": "Write Statuses to NRCS",
152+
"ui:description": "",
153+
"ui:summaryTitle": "Statuses",
154+
"default": true
155+
}
156+
},
157+
"required": ["enabled"],
156158
"additionalProperties": false
157159
}
158160
},
159-
"required": [
160-
"primary"
161-
],
161+
"required": ["primary", "statuses"],
162162
"additionalProperties": false
163-
}
163+
}

packages/mos-gateway/src/generated/devices.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,8 @@ export interface MosDeviceConfig {
3131
query: number
3232
}
3333
}
34+
statuses: MosDeviceStatusesConfig
35+
}
36+
export interface MosDeviceStatusesConfig {
37+
enabled: boolean
3438
}

packages/mos-gateway/src/mosHandler.ts

Lines changed: 34 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import {
1616
IMOSROReadyToAir,
1717
IMOSROFullStory,
1818
IConnectionConfig,
19-
IMOSDeviceConnectionOptions,
2019
MosDevice,
2120
IMOSListMachInfo,
2221
IMOSString128,
@@ -40,12 +39,13 @@ import { MosGatewayConfig } from './generated/options'
4039
import { MosDeviceConfig } from './generated/devices'
4140
import { PeripheralDeviceForDevice } from '@sofie-automation/server-core-integration'
4241
import _ = require('underscore')
42+
import { MosStatusHandler } from './mosStatusHandler'
4343

44-
export interface MosConfig {
44+
interface MosConfig {
4545
self: IConnectionConfig
4646
// devices: Array<IMOSDeviceConnectionOptions>
4747
}
48-
export type MosSubDeviceSettings = Record<
48+
type MosSubDeviceSettings = Record<
4949
string,
5050
{
5151
type: ''
@@ -59,10 +59,13 @@ export type MosSubDeviceSettings = Record<
5959
interface MosDeviceHandle {
6060
readonly deviceId: string
6161
readonly mosDevice: MosDevice
62-
readonly deviceOptions: Readonly<IMOSDeviceConnectionOptions>
62+
readonly deviceOptions: Readonly<MosDeviceConfig>
6363

6464
// Once connected, a core handler is setup
6565
coreMosHandler?: CoreMosDeviceHandler
66+
67+
// If writing back story/item status is enabled, the setup handler
68+
statusHandler?: MosStatusHandler
6669
}
6770

6871
export class MosHandler {
@@ -147,11 +150,9 @@ export class MosHandler {
147150
return Promise.resolve()
148151
}
149152
}
150-
setupObservers(): void {
153+
private setupObservers(): void {
151154
if (this._observers.length) {
152-
this._observers.forEach((obs) => {
153-
obs.stop()
154-
})
155+
this._observers.forEach((obs) => obs.stop())
155156
this._observers = []
156157
}
157158
this._logger.info('Renewing observers')
@@ -167,15 +168,9 @@ export class MosHandler {
167168
const deviceObserver = this._coreHandler.core.observe(
168169
PeripheralDevicePubSubCollectionsNames.peripheralDeviceForDevice
169170
)
170-
deviceObserver.added = () => {
171-
this._deviceOptionsChanged()
172-
}
173-
deviceObserver.changed = () => {
174-
this._deviceOptionsChanged()
175-
}
176-
deviceObserver.removed = () => {
177-
this._deviceOptionsChanged()
178-
}
171+
deviceObserver.added = () => this._deviceOptionsChanged()
172+
deviceObserver.changed = () => this._deviceOptionsChanged()
173+
deviceObserver.removed = () => this._deviceOptionsChanged()
179174
this._observers.push(deviceObserver)
180175

181176
this._deviceOptionsChanged()
@@ -288,7 +283,6 @@ export class MosHandler {
288283

289284
if (!this._coreHandler) throw Error('_coreHandler is undefined!')
290285

291-
//@ts-expect-error this is not yet added to the official mos-connection
292286
const openMediaHotStandby = deviceEntry.deviceOptions.secondary?.openMediaHotStandby || false
293287

294288
const coreMosHandler = await this._coreHandler.registerMosDevice(
@@ -301,9 +295,18 @@ export class MosHandler {
301295

302296
deviceEntry.coreMosHandler = coreMosHandler
303297

298+
if (deviceEntry.deviceOptions.statuses?.enabled) {
299+
if (deviceEntry.statusHandler) {
300+
deviceEntry.statusHandler.dispose()
301+
}
302+
deviceEntry.statusHandler = new MosStatusHandler(
303+
mosDevice,
304+
coreMosHandler,
305+
deviceEntry.deviceOptions.statuses
306+
)
307+
}
308+
304309
// Initial Status check:
305-
const connectionStatus = mosDevice.getConnectionStatus()
306-
coreMosHandler.onMosConnectionChanged(connectionStatus) // initial check
307310
// Profile 0: -------------------------------------------------
308311
mosDevice.onConnectionChange((newStatus: IMOSConnectionStatus) => {
309312
// MOSDevice >>>> Core
@@ -518,7 +521,7 @@ export class MosHandler {
518521

519522
if (!this.mos) throw Error('mos is undefined, call _initMosConnection first!')
520523

521-
const deviceOptions: IMOSDeviceConnectionOptions = JSON.parse(JSON.stringify(deviceOptions0)) // deep clone
524+
const deviceOptions: MosDeviceConfig = JSON.parse(JSON.stringify(deviceOptions0)) // deep clone
522525
deviceOptions.primary.timeout ||= DEFAULT_MOS_TIMEOUT_TIME
523526
deviceOptions.primary.heartbeatInterval ||= DEFAULT_MOS_HEARTBEAT_INTERVAL
524527

@@ -577,13 +580,21 @@ export class MosHandler {
577580
}
578581
}
579582
private async _removeDevice(deviceId: string): Promise<void> {
580-
const mosDevice = this._allMosDevices.get(deviceId)?.mosDevice
583+
const deviceEntry = this._allMosDevices.get(deviceId)
581584
this._allMosDevices.delete(deviceId)
582585

583-
if (mosDevice) {
586+
if (deviceEntry) {
587+
const mosDevice = deviceEntry.mosDevice
588+
584589
// Cleanup the coreMosHandler from the device
585590
if (this._coreHandler) await this._coreHandler.unRegisterMosDevice(mosDevice)
586591

592+
// Stop the status handler, if enabled
593+
if (deviceEntry.statusHandler) {
594+
deviceEntry.statusHandler.dispose()
595+
delete deviceEntry.statusHandler
596+
}
597+
587598
if (!this.mos) {
588599
throw Error('mos is undefined!')
589600
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import type { IMOSDevice } from '@mos-connection/connector'
2+
import type { MosDeviceStatusesConfig } from './generated/devices'
3+
import type { CoreMosDeviceHandler } from './CoreMosDeviceHandler'
4+
5+
export class MosStatusHandler {
6+
constructor(mosDevice: IMOSDevice, coreMosHandler: CoreMosDeviceHandler, config: MosDeviceStatusesConfig) {
7+
// TODO
8+
}
9+
10+
dispose(): void {
11+
// TODO
12+
}
13+
}

0 commit comments

Comments
 (0)