Skip to content

Commit

Permalink
chore: fix some todos
Browse files Browse the repository at this point in the history
  • Loading branch information
mint-dewit committed Dec 8, 2023
1 parent db4c3e6 commit f9eccd5
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export function getDeviceContext(): DeviceContextAPI<any> {
info: jest.fn(),
debug: jest.fn(),
},
getCurrentTime: jest.fn(() => Date.now()),
emitDebugState: jest.fn(),
connectionChanged: jest.fn(),
resetResolver: jest.fn(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1137,6 +1137,7 @@ describe('Quantel Device', () => {
})

describe('sendCommand', () => {
const ogTimeout = setTimeout
const mockTime = new MockTime()
beforeAll(() => {
mockTime.init()
Expand All @@ -1146,6 +1147,9 @@ describe('Quantel Device', () => {
// note - the internals of the QuantelManager class are state-based so it's easier to do all of this in one long test
const dev = await getInitialisedQuantelDevice()

// give it some time to finish the init
await new Promise<void>((r) => ogTimeout(() => r(), 10))

dev
.sendCommand({
command: {
Expand All @@ -1161,7 +1165,7 @@ describe('Quantel Device', () => {
throw e
})

// give it some time to settle
// give it some time to settle after the command
await mockTime.tick()

expect(onRequest).toHaveBeenCalledTimes(5)
Expand Down
19 changes: 10 additions & 9 deletions packages/timeline-state-resolver/src/integrations/quantel/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@ export class QuantelDevice extends Device<QuantelOptions, QuantelState, QuantelC
async init(options: QuantelOptions): Promise<boolean> {
this._quantel = new QuantelGateway()
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(), {
this._quantelManager = new QuantelManager(this._quantel, () => this.context.getCurrentTime(), {
allowCloneClips: options.allowCloneClips,
})
this._quantelManager.on('info', (x) =>
Expand All @@ -65,11 +63,14 @@ export class QuantelDevice extends Device<QuantelOptions, QuantelState, QuantelC
if (ISAUrlMaster) isaURLs.push(ISAUrlMaster)
if (options.ISAUrlBackup) isaURLs.push(options.ISAUrlBackup)

await this._quantel.init(options.gatewayUrl, isaURLs, options.zoneId, options.serverId) // todo - maybe not to be awaited...

this._quantel.monitorServerStatus((_connected: boolean) => {
this.context.connectionChanged(this.getStatus())
})
this._quantel
.init(options.gatewayUrl, isaURLs, options.zoneId, options.serverId)
.then(() => {
this._quantel.monitorServerStatus((_connected: boolean) => {
this.context.connectionChanged(this.getStatus())
})
})
.catch((e) => this.context.logger.error('Error initialising quantel', e))

return Promise.resolve(true)
}
Expand Down Expand Up @@ -169,7 +170,7 @@ export class QuantelDevice extends Device<QuantelOptions, QuantelState, QuantelC
await this._quantel.kill()
return { result: ActionExecutionResultCode.Ok }
} catch (e) {
this.context.logger.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)) // note - not 100% sure this is correct?
}
}
return { result: ActionExecutionResultCode.Error }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,8 @@ export class DeviceInstanceWrapper extends EventEmitter<DeviceInstanceEvents> {
},
},

getCurrentTime: () => this.getCurrentTime(),

emitDebugState: (state: object) => {
if (this._logDebugStates) {
this.emit('debugState', state)
Expand Down
2 changes: 2 additions & 0 deletions packages/timeline-state-resolver/src/service/device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ export interface DeviceContextAPI<DeviceState> {
/** Emit a "debugState" message */
emitDebugState: (state: object) => void

getCurrentTime: () => number

/** Notify that the connection status has changed. */
connectionChanged: (status: Omit<DeviceStatus, 'active'>) => void
/**
Expand Down

0 comments on commit f9eccd5

Please sign in to comment.