Skip to content

Commit 60be869

Browse files
committed
fix: Broken merge
1 parent af59bc1 commit 60be869

File tree

9 files changed

+140
-967
lines changed

9 files changed

+140
-967
lines changed

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

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -140,36 +140,8 @@
140140
},
141141
"required": ["id", "host"],
142142
"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-
"sendInRehearsal": {
157-
"type": "boolean",
158-
"ui:title": "Send when in Rehearsal mode",
159-
"ui:description": "",
160-
"default": false
161-
},
162-
"onlySendPlay": {
163-
"type": "boolean",
164-
"ui:title": "Only send PLAY statuses",
165-
"ui:description": "",
166-
"default": false
167-
}
168-
},
169-
"required": ["enabled"],
170-
"additionalProperties": false
171143
}
172144
},
173-
"required": ["primary", "statuses"],
145+
"required": ["primary"],
174146
"additionalProperties": false
175147
}

packages/mos-gateway/src/CoreMosDeviceHandler.ts

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import {
44
protectString,
55
Observer,
66
PeripheralDevicePubSub,
7-
stringifyError,
87
} from '@sofie-automation/server-core-integration'
98
import {
109
IMOSConnectionStatus,
@@ -22,6 +21,7 @@ import {
2221
IMOSItem,
2322
IMOSROReadyToAir,
2423
IMOSROFullStory,
24+
IMOSObjectStatus,
2525
IMOSROAck,
2626
getMosTypes,
2727
MosTypes,
@@ -112,7 +112,9 @@ export class CoreMosDeviceHandler {
112112
deviceName: this._mosDevice.idPrimary,
113113
})
114114
this.core.on('error', (err) => {
115-
this._coreParentHandler.logger.error(`Core Error: ${stringifyError(err)}`)
115+
this._coreParentHandler.logger.error(
116+
'Core Error: ' + (typeof err === 'string' ? err : err.message || err.toString())
117+
)
116118
})
117119

118120
this.setupSubscriptionsAndObservers()
@@ -136,7 +138,7 @@ export class CoreMosDeviceHandler {
136138
Promise.all([
137139
this.core.autoSubscribe(PeripheralDevicePubSub.peripheralDeviceCommands, this.core.deviceId),
138140
]).catch((e) => {
139-
this._coreParentHandler.logger.error(stringifyError(e))
141+
this._coreParentHandler.logger.error(e)
140142
})
141143

142144
this._coreParentHandler.logger.info('CoreMos: Setting up observers..')
@@ -347,6 +349,42 @@ export class CoreMosDeviceHandler {
347349
// console.log('GOT REPLY', results)
348350
return this.fixMosData(ro)
349351
}
352+
async setROStatus(roId: string, status: IMOSObjectStatus): Promise<any> {
353+
// console.log('setStoryStatus')
354+
const result = await this._mosDevice.sendRunningOrderStatus({
355+
ID: this.mosTypes.mosString128.create(roId),
356+
Status: status,
357+
Time: this.mosTypes.mosTime.create(new Date()),
358+
})
359+
360+
// console.log('got result', result)
361+
return this.fixMosData(result)
362+
}
363+
async setStoryStatus(roId: string, storyId: string, status: IMOSObjectStatus): Promise<any> {
364+
// console.log('setStoryStatus')
365+
const result = await this._mosDevice.sendStoryStatus({
366+
RunningOrderId: this.mosTypes.mosString128.create(roId),
367+
ID: this.mosTypes.mosString128.create(storyId),
368+
Status: status,
369+
Time: this.mosTypes.mosTime.create(new Date()),
370+
})
371+
372+
// console.log('got result', result)
373+
return this.fixMosData(result)
374+
}
375+
async setItemStatus(roId: string, storyId: string, itemId: string, status: IMOSObjectStatus): Promise<any> {
376+
// console.log('setStoryStatus')
377+
const result = await this._mosDevice.sendItemStatus({
378+
RunningOrderId: this.mosTypes.mosString128.create(roId),
379+
StoryId: this.mosTypes.mosString128.create(storyId),
380+
ID: this.mosTypes.mosString128.create(itemId),
381+
Status: status,
382+
Time: this.mosTypes.mosTime.create(new Date()),
383+
})
384+
385+
// console.log('got result', result)
386+
return this.fixMosData(result)
387+
}
350388
async replaceStoryItem(
351389
roID: string,
352390
storyID: string,

packages/mos-gateway/src/connector.ts

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,19 +44,14 @@ export class Connector implements IConnector {
4444
this._logger.info('Process initialized')
4545

4646
this._logger.info('Initializing Core...')
47-
this.coreHandler = await CoreHandler.create(
48-
this._logger,
49-
this._config.core,
50-
certificates,
51-
this._config.device
52-
)
47+
await this.initCore(certificates)
5348

5449
if (!this.coreHandler) throw Error('coreHandler is undefined!')
5550

5651
new HealthEndpoints(this, this.coreHandler, config.health)
5752

5853
this._logger.info('Initializing Mos...')
59-
this.mosHandler = await MosHandler.create(this._logger, this._config.mos, this.coreHandler)
54+
await this.initMos()
6055

6156
this._logger.info('Initialization done')
6257
this.initialized = true
@@ -67,15 +62,40 @@ export class Connector implements IConnector {
6762

6863
this._logger.info('Shutting down in 10 seconds!')
6964

70-
this.dispose().catch((e2) => this._logger.error(stringifyError(e2)))
65+
this.dispose().catch((e2) => this._logger.error(e2))
7166

7267
setTimeout(() => {
7368
// eslint-disable-next-line n/no-process-exit
7469
process.exit(0)
7570
}, 10 * 1000)
7671
}
7772
}
73+
async initCore(certificates: Buffer[]): Promise<void> {
74+
if (!this._config) {
75+
throw Error('_config is undefined!')
76+
}
77+
78+
this.coreHandler = new CoreHandler(this._logger, this._config.device)
79+
80+
if (!this.coreHandler) {
81+
throw Error('coreHandler is undefined!')
82+
}
83+
84+
return this.coreHandler.init(this._config.core, certificates)
85+
}
86+
async initMos(): Promise<void> {
87+
this.mosHandler = new MosHandler(this._logger)
7888

89+
if (!this._config) {
90+
throw Error('_config is undefined!')
91+
}
92+
93+
if (!this.coreHandler) {
94+
throw Error('coreHandler is undefined!')
95+
}
96+
97+
return this.mosHandler.init(this._config.mos, this.coreHandler)
98+
}
7999
async dispose(): Promise<void> {
80100
if (this.mosHandler) await this.mosHandler.dispose()
81101

packages/mos-gateway/src/coreHandler.ts

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -44,23 +44,12 @@ export class CoreHandler implements ICoreHandler {
4444
private _coreConfig?: CoreConfig
4545
private _certificates?: Buffer[]
4646

47-
public static async create(
48-
logger: Winston.Logger,
49-
config: CoreConfig,
50-
certificates: Buffer[],
51-
deviceOptions: DeviceConfig
52-
): Promise<CoreHandler> {
53-
const handler = new CoreHandler(logger, deviceOptions)
54-
await handler.init(config, certificates)
55-
return handler
56-
}
57-
58-
private constructor(logger: Winston.Logger, deviceOptions: DeviceConfig) {
47+
constructor(logger: Winston.Logger, deviceOptions: DeviceConfig) {
5948
this.logger = logger
6049
this._deviceOptions = deviceOptions
6150
}
6251

63-
private async init(config: CoreConfig, certificates: Buffer[]): Promise<void> {
52+
async init(config: CoreConfig, certificates: Buffer[]): Promise<void> {
6453
// this.logger.info('========')
6554
this._coreConfig = config
6655
this._certificates = certificates

0 commit comments

Comments
 (0)