From 56d5e056eefb57d884f9af31d9d2e89861a06cea Mon Sep 17 00:00:00 2001 From: Mint de Wit Date: Wed, 11 Oct 2023 08:42:15 +0200 Subject: [PATCH] chore: rebase branch --- .../quantel/__tests__/quantel.spec.ts | 29 ++++++++-------- .../src/integrations/quantel/diff.ts | 2 +- .../src/integrations/quantel/index.ts | 34 ++++++++----------- 3 files changed, 31 insertions(+), 34 deletions(-) diff --git a/packages/timeline-state-resolver/src/integrations/quantel/__tests__/quantel.spec.ts b/packages/timeline-state-resolver/src/integrations/quantel/__tests__/quantel.spec.ts index 9de92cac6..00473472d 100644 --- a/packages/timeline-state-resolver/src/integrations/quantel/__tests__/quantel.spec.ts +++ b/packages/timeline-state-resolver/src/integrations/quantel/__tests__/quantel.spec.ts @@ -13,9 +13,10 @@ import { QuantelCommandWithContext, QuantelDevice } from '..' import { QuantelCommandType, QuantelState } from '../types' import { setupQuantelGatewayMock } from './quantelGatewayMock' import { MockTime } from '../../../__tests__/mockTime' +import { getDeviceContext } from '../../../integrations/__tests__/testlib' async function getInitialisedQuantelDevice(clearMock?: jest.Mock) { - const dev = new QuantelDevice() + const dev = new QuantelDevice(getDeviceContext()) await dev.init({ gatewayUrl: 'localhost:3000', ISAUrlMaster: 'myISA:8000', @@ -326,7 +327,7 @@ describe('Quantel Device', () => { channel: 2, }, context: 'Old state did not have port', - tlObjId: 'obj0', + timelineObjId: 'obj0', }, { command: { @@ -338,7 +339,7 @@ describe('Quantel Device', () => { transition: undefined, }, context: 'New clip is empty', - tlObjId: 'obj0', + timelineObjId: 'obj0', }, ] ) @@ -392,7 +393,7 @@ describe('Quantel Device', () => { allowedToPrepareJump: true, }, context: 'Load from current state', - tlObjId: 'obj1', + timelineObjId: 'obj1', }, { command: { @@ -410,7 +411,7 @@ describe('Quantel Device', () => { transition: undefined, }, context: 'New clip is paused', - tlObjId: 'obj1', + timelineObjId: 'obj1', }, ] ) @@ -469,7 +470,7 @@ describe('Quantel Device', () => { allowedToPrepareJump: true, }, context: 'Load from current state', - tlObjId: 'obj1', + timelineObjId: 'obj1', }, { command: { @@ -487,7 +488,7 @@ describe('Quantel Device', () => { transition: undefined, }, context: 'New clip is playing', - tlObjId: 'obj1', + timelineObjId: 'obj1', }, ] ) @@ -546,7 +547,7 @@ describe('Quantel Device', () => { allowedToPrepareJump: true, }, context: 'Load from current state', - tlObjId: 'obj1', + timelineObjId: 'obj1', }, { command: { @@ -564,7 +565,7 @@ describe('Quantel Device', () => { transition: undefined, }, context: 'New clip is playing', - tlObjId: 'obj1', + timelineObjId: 'obj1', }, ] ) @@ -599,7 +600,7 @@ describe('Quantel Device', () => { timelineObjId: 'obj0', fromLookahead: false, }, - tlObjId: 'obj0', + timelineObjId: 'obj0', context: 'Port does not exist in new state', }, ] @@ -627,7 +628,7 @@ describe('Quantel Device', () => { channel: 2, }, context: 'Old state did not have port', - tlObjId: 'obj0', + timelineObjId: 'obj0', }) .catch((e) => { throw e @@ -675,7 +676,7 @@ describe('Quantel Device', () => { allowedToPrepareJump: true, }, context: 'Load from current state', - tlObjId: 'obj1', + timelineObjId: 'obj1', }) .catch((e) => { throw e @@ -718,7 +719,7 @@ describe('Quantel Device', () => { transition: undefined, }, context: 'New clip is playing', - tlObjId: 'obj1', + timelineObjId: 'obj1', }) .catch((e) => { throw e @@ -764,7 +765,7 @@ describe('Quantel Device', () => { fromLookahead: false, }, context: 'Clear', - tlObjId: 'obj1', + timelineObjId: 'obj1', }) .catch((e) => { throw e diff --git a/packages/timeline-state-resolver/src/integrations/quantel/diff.ts b/packages/timeline-state-resolver/src/integrations/quantel/diff.ts index 4e0b1cbd5..05d4d67d8 100644 --- a/packages/timeline-state-resolver/src/integrations/quantel/diff.ts +++ b/packages/timeline-state-resolver/src/integrations/quantel/diff.ts @@ -17,7 +17,7 @@ export function diffStates( const addCommand = (command: QuantelCommand, lowPriority: boolean, context?: string) => { ;(lowPriority ? lowPrioCommands : highPrioCommands).push({ command, - tlObjId: command.timelineObjId, + timelineObjId: command.timelineObjId, context: context ?? 'Context not specified..', }) } diff --git a/packages/timeline-state-resolver/src/integrations/quantel/index.ts b/packages/timeline-state-resolver/src/integrations/quantel/index.ts index d1f3dc57a..49ea4d609 100644 --- a/packages/timeline-state-resolver/src/integrations/quantel/index.ts +++ b/packages/timeline-state-resolver/src/integrations/quantel/index.ts @@ -11,10 +11,9 @@ import { Timeline, TSRTimelineContent, } from 'timeline-state-resolver-types' -import { CommandWithContext, Device, DeviceEvents } from '../../service/device' +import { CommandWithContext, Device } from '../../service/device' import Debug from 'debug' -import EventEmitter = require('eventemitter3') import { QuantelCommand, QuantelCommandType, QuantelState } from './types' import { QuantelGateway } from 'tv-automation-quantel-gateway-client' import { QuantelManager } from './connection' @@ -32,13 +31,10 @@ interface OSCDeviceStateContent extends OSCMessageCommandContent { export interface QuantelCommandWithContext { command: QuantelCommand context: string - tlObjId: string + timelineObjId: string } -export class QuantelDevice - extends EventEmitter - implements Device -{ +export class QuantelDevice extends Device { // TODO - monitor ports: this._quantel.setMonitoredPorts(this._getMappedPorts(newMappings)) private _quantel: QuantelGateway @@ -46,20 +42,20 @@ export class QuantelDevice async init(options: QuantelOptions): Promise { this._quantel = new QuantelGateway() - this._quantel.on('error', (e) => this.emit('error', 'Quantel.QuantelGateway', e)) + this._quantel.on('error', (e) => this.context.logger.error('Quantel.QuantelGateway', e)) // this._quantelManager = new QuantelManager(this._quantel, () => this.getCurrentTime(), { // todo - obv this._quantelManager = new QuantelManager(this._quantel, () => Date.now(), { allowCloneClips: options.allowCloneClips, }) this._quantelManager.on('info', (x) => - this.emit('info', `Quantel: ${typeof x === 'string' ? x : JSON.stringify(x)}`) + this.context.logger.info(`Quantel: ${typeof x === 'string' ? x : JSON.stringify(x)}`) ) this._quantelManager.on('warning', (x) => - this.emit('warning', `Quantel: ${typeof x === 'string' ? x : JSON.stringify(x)}`) + this.context.logger.warning(`Quantel: ${typeof x === 'string' ? x : JSON.stringify(x)}`) ) - this._quantelManager.on('error', (e) => this.emit('error', 'Quantel: ', e)) - this._quantelManager.on('debug', (...args) => this.emit('debug', ...args)) + this._quantelManager.on('error', (e) => this.context.logger.error('Quantel: ', e)) + this._quantelManager.on('debug', (...args) => this.context.logger.debug(...args)) const ISAUrlMaster: string = options.ISAUrlMaster || options['ISAUrl'] // tmp: ISAUrl for backwards compatibility, to be removed later if (!options.gatewayUrl) throw new Error('Quantel bad connection option: gatewayUrl') @@ -73,7 +69,7 @@ export class QuantelDevice await this._quantel.init(options.gatewayUrl, isaURLs, options.zoneId, options.serverId) // todo - maybe not to be awaited... this._quantel.monitorServerStatus((_connected: boolean) => { - this.emit('connectionChanged', this.getStatus()) + this.context.connectionChanged(this.getStatus()) }) return Promise.resolve(true) @@ -91,13 +87,13 @@ export class QuantelDevice diffStates(oldState: QuantelState | undefined, newState: QuantelState): Array { return diffStates(oldState, newState) } - async sendCommand({ command, context, tlObjId }: QuantelCommandWithContext): Promise { + async sendCommand({ command, context, timelineObjId }: QuantelCommandWithContext): Promise { const cwc: CommandWithContext = { context: context, command: command, - tlObjId: tlObjId, + timelineObjId: timelineObjId, } - this.emit('debug', cwc) + this.context.logger.debug(cwc) debug(command) try { @@ -123,7 +119,7 @@ export class QuantelDevice if (error?.stack) { errorString += error.stack } - this.emit('commandError', new Error(errorString), cwc) + this.context.commandError(new Error(errorString), cwc) } } @@ -156,7 +152,7 @@ export class QuantelDevice actions: Record Promise> = { [QuantelActions.ClearStates]: async () => { - this.emit('resetResolver') + this.context.resetResolver() return { result: ActionExecutionResultCode.Ok, } @@ -167,7 +163,7 @@ export class QuantelDevice await this._quantel.kill() return { result: ActionExecutionResultCode.Ok } } catch (e) { - this.emit('error', 'Error killing quantel gateway', new Error(e as any)) // todo - what to do here... + this.context.logger.error('Error killing quantel gateway', new Error(e as any)) // todo - what to do here... } } return { result: ActionExecutionResultCode.Error }