Skip to content

Commit

Permalink
chore: rebase branch
Browse files Browse the repository at this point in the history
  • Loading branch information
mint-dewit committed Oct 11, 2023
1 parent a3be276 commit 56d5e05
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -326,7 +327,7 @@ describe('Quantel Device', () => {
channel: 2,
},
context: 'Old state did not have port',
tlObjId: 'obj0',
timelineObjId: 'obj0',
},
{
command: {
Expand All @@ -338,7 +339,7 @@ describe('Quantel Device', () => {
transition: undefined,
},
context: 'New clip is empty',
tlObjId: 'obj0',
timelineObjId: 'obj0',
},
]
)
Expand Down Expand Up @@ -392,7 +393,7 @@ describe('Quantel Device', () => {
allowedToPrepareJump: true,
},
context: 'Load from current state',
tlObjId: 'obj1',
timelineObjId: 'obj1',
},
{
command: {
Expand All @@ -410,7 +411,7 @@ describe('Quantel Device', () => {
transition: undefined,
},
context: 'New clip is paused',
tlObjId: 'obj1',
timelineObjId: 'obj1',
},
]
)
Expand Down Expand Up @@ -469,7 +470,7 @@ describe('Quantel Device', () => {
allowedToPrepareJump: true,
},
context: 'Load from current state',
tlObjId: 'obj1',
timelineObjId: 'obj1',
},
{
command: {
Expand All @@ -487,7 +488,7 @@ describe('Quantel Device', () => {
transition: undefined,
},
context: 'New clip is playing',
tlObjId: 'obj1',
timelineObjId: 'obj1',
},
]
)
Expand Down Expand Up @@ -546,7 +547,7 @@ describe('Quantel Device', () => {
allowedToPrepareJump: true,
},
context: 'Load from current state',
tlObjId: 'obj1',
timelineObjId: 'obj1',
},
{
command: {
Expand All @@ -564,7 +565,7 @@ describe('Quantel Device', () => {
transition: undefined,
},
context: 'New clip is playing',
tlObjId: 'obj1',
timelineObjId: 'obj1',
},
]
)
Expand Down Expand Up @@ -599,7 +600,7 @@ describe('Quantel Device', () => {
timelineObjId: 'obj0',
fromLookahead: false,
},
tlObjId: 'obj0',
timelineObjId: 'obj0',
context: 'Port does not exist in new state',
},
]
Expand Down Expand Up @@ -627,7 +628,7 @@ describe('Quantel Device', () => {
channel: 2,
},
context: 'Old state did not have port',
tlObjId: 'obj0',
timelineObjId: 'obj0',
})
.catch((e) => {
throw e
Expand Down Expand Up @@ -675,7 +676,7 @@ describe('Quantel Device', () => {
allowedToPrepareJump: true,
},
context: 'Load from current state',
tlObjId: 'obj1',
timelineObjId: 'obj1',
})
.catch((e) => {
throw e
Expand Down Expand Up @@ -718,7 +719,7 @@ describe('Quantel Device', () => {
transition: undefined,
},
context: 'New clip is playing',
tlObjId: 'obj1',
timelineObjId: 'obj1',
})
.catch((e) => {
throw e
Expand Down Expand Up @@ -764,7 +765,7 @@ describe('Quantel Device', () => {
fromLookahead: false,
},
context: 'Clear',
tlObjId: 'obj1',
timelineObjId: 'obj1',
})
.catch((e) => {
throw e
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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..',
})
}
Expand Down
34 changes: 15 additions & 19 deletions packages/timeline-state-resolver/src/integrations/quantel/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -32,34 +31,31 @@ interface OSCDeviceStateContent extends OSCMessageCommandContent {
export interface QuantelCommandWithContext {
command: QuantelCommand
context: string
tlObjId: string
timelineObjId: string
}

export class QuantelDevice
extends EventEmitter<DeviceEvents>
implements Device<QuantelOptions, QuantelState, QuantelCommandWithContext>
{
export class QuantelDevice extends Device<QuantelOptions, QuantelState, QuantelCommandWithContext> {
// TODO - monitor ports: this._quantel.setMonitoredPorts(this._getMappedPorts(newMappings))

private _quantel: QuantelGateway
private _quantelManager: QuantelManager

async init(options: QuantelOptions): Promise<boolean> {
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')
Expand All @@ -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)
Expand All @@ -91,13 +87,13 @@ export class QuantelDevice
diffStates(oldState: QuantelState | undefined, newState: QuantelState): Array<QuantelCommandWithContext> {
return diffStates(oldState, newState)
}
async sendCommand({ command, context, tlObjId }: QuantelCommandWithContext): Promise<any> {
async sendCommand({ command, context, timelineObjId }: QuantelCommandWithContext): Promise<any> {
const cwc: CommandWithContext = {
context: context,
command: command,
tlObjId: tlObjId,
timelineObjId: timelineObjId,
}
this.emit('debug', cwc)
this.context.logger.debug(cwc)
debug(command)

try {
Expand All @@ -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)
}
}

Expand Down Expand Up @@ -156,7 +152,7 @@ export class QuantelDevice

actions: Record<QuantelActions, (id: QuantelActions) => Promise<ActionExecutionResult>> = {
[QuantelActions.ClearStates]: async () => {
this.emit('resetResolver')
this.context.resetResolver()
return {
result: ActionExecutionResultCode.Ok,
}
Expand All @@ -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 }
Expand Down

0 comments on commit 56d5e05

Please sign in to comment.