Skip to content

Commit

Permalink
fix: emitting of 'debug' events should only be done if the debug prop…
Browse files Browse the repository at this point in the history
…erty is truthy.
  • Loading branch information
nytamin committed Sep 30, 2021
1 parent 51b9834 commit 5d015a1
Show file tree
Hide file tree
Showing 20 changed files with 61 additions and 41 deletions.
1 change: 1 addition & 0 deletions packages/timeline-state-resolver-types/src/device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export interface DeviceOptionsBase<T> extends SlowReportOptions {
threadUsage?: number
disable?: boolean
options?: T
debug?: boolean
}

export interface SlowReportOptions {
Expand Down
2 changes: 1 addition & 1 deletion packages/timeline-state-resolver/src/devices/abstract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ export class AbstractDevice extends DeviceWithState<AbstractState, DeviceOptions
content: cmd.content,
},
}
this.emit('debug', cwc)
this.emitDebug(cwc)

// Note: In the Abstract case, the execution does nothing

Expand Down
5 changes: 2 additions & 3 deletions packages/timeline-state-resolver/src/devices/atem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,7 @@ export class AtemDevice extends DeviceWithState<DeviceState, DeviceOptionsAtemIn
if (this.firstStateAfterMakeReady) {
// emit a debug message with the states:
this.firstStateAfterMakeReady = false
this.emit(
'debug',
this.emitDebug(
JSON.stringify({
reason: 'firstStateAfterMakeReady',
before: (oldAtemState || {}).video,
Expand Down Expand Up @@ -420,7 +419,7 @@ export class AtemDevice extends DeviceWithState<DeviceState, DeviceOptionsAtemIn
command: command,
timelineObjId: timelineObjId,
}
this.emit('debug', cwc)
this.emitDebug(cwc)

return this._atem
.sendCommand(command)
Expand Down
4 changes: 2 additions & 2 deletions packages/timeline-state-resolver/src/devices/casparCG.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ export class CasparCGDevice extends DeviceWithState<State, DeviceOptionsCasparCG
vfilter: mediaObj.content.videoFilter,
afilter: mediaObj.content.audioFilter,
})
// this.emit('debug', stateLayer)
// this.emitDebug(stateLayer)
} else if (layer.content.type === TimelineContentTypeCasparCg.IP) {
const ipObj = layer as any as TimelineObjCCGIP

Expand Down Expand Up @@ -832,7 +832,7 @@ export class CasparCGDevice extends DeviceWithState<State, DeviceOptionsCasparCG
timelineObjId: timelineObjId,
command: JSON.stringify(cmd),
}
this.emit('debug', cwc)
this.emitDebug(cwc)

return this._ccg
.do(cmd)
Expand Down
12 changes: 12 additions & 0 deletions packages/timeline-state-resolver/src/devices/device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,13 @@ export abstract class Device<TOptions extends DeviceOptionsBase<any>>
protected _deviceOptions: TOptions
protected _reportAllCommands = false
protected _isActive = true
private debugLogging: boolean

constructor(deviceId: string, deviceOptions: TOptions, getCurrentTime: () => Promise<number>) {
super()
this._deviceId = deviceId
this._deviceOptions = deviceOptions
this.debugLogging = deviceOptions.debug ?? true // Default to true to keep backwards compatibility

this._instanceId = Math.floor(Math.random() * 10000)
this._startTime = Date.now()
Expand Down Expand Up @@ -202,6 +204,16 @@ export abstract class Device<TOptions extends DeviceOptionsBase<any>>
}
abstract getStatus(): DeviceStatus

setDebugLogging(debug: boolean) {
this.debugLogging = debug
}

protected emitDebug(...args: any[]) {
if (this.debugLogging) {
this.emit('debug', ...args)
}
}

get deviceId() {
return this._deviceId
}
Expand Down
11 changes: 11 additions & 0 deletions packages/timeline-state-resolver/src/devices/deviceContainer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ export class DeviceContainer<TOptions extends DeviceOptionsBase<any>> {
private _instanceId = -1
private _startTime = -1
private _onEventListener: { stop: () => void } | undefined
private _debugLogging: boolean = true

private constructor(deviceOptions: TOptions, threadConfig?: ThreadedClassConfig) {
this._deviceOptions = deviceOptions
this._threadConfig = threadConfig
this._debugLogging = deviceOptions.debug || false
}

static async create<
Expand Down Expand Up @@ -77,6 +79,11 @@ export class DeviceContainer<TOptions extends DeviceOptionsBase<any>> {
await ThreadedClassManager.destroy(this._device)
}

public async setDebugLogging(debug: boolean): Promise<void> {
this._debugLogging = debug
await this._device.setDebugLogging(debug)
}

public get device(): ThreadedClass<Device<TOptions>> {
return this._device
}
Expand All @@ -101,4 +108,8 @@ export class DeviceContainer<TOptions extends DeviceOptionsBase<any>> {
public get startTime(): number {
return this._startTime
}

public get debugLogging(): boolean {
return this._debugLogging
}
}
5 changes: 2 additions & 3 deletions packages/timeline-state-resolver/src/devices/httpSend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ export class HTTPSendDevice extends DeviceWithState<HTTPSendState, DeviceOptions
command: cmd,
timelineObjId: timelineObjId,
}
this.emit('debug', cwc)
this.emitDebug(cwc)

const t = Date.now()
debug(`${cmd.type}: ${cmd.url} ${JSON.stringify(cmd.params)} (${timelineObjId})`)
Expand All @@ -251,8 +251,7 @@ export class HTTPSendDevice extends DeviceWithState<HTTPSendState, DeviceOptions
})

if (response.statusCode === 200) {
this.emit(
'debug',
this.emitDebug(
`HTTPSend: ${cmd.type}: Good statuscode response on url "${cmd.url}": ${response.statusCode} (${context})`
)
} else {
Expand Down
2 changes: 1 addition & 1 deletion packages/timeline-state-resolver/src/devices/hyperdeck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,7 @@ export class HyperdeckDevice extends DeviceWithState<DeviceState, DeviceOptionsH
timelineObjId: timelineObjId,
command: command,
}
this.emit('debug', cwc)
this.emitDebug(cwc)

return this._hyperdeck.sendCommand(command).catch((error) => {
this.emit('commandError', error, cwc)
Expand Down
13 changes: 6 additions & 7 deletions packages/timeline-state-resolver/src/devices/lawo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ export class LawoDevice extends DeviceWithState<LawoState, DeviceOptionsLawoInte
}
})
// this._lawo.on('warn', (w) => {
// this.emit('debug', 'Warning: Lawo.Emberplus', w)
// this.emitDebug('Warning: Lawo.Emberplus', w)
// })
let firstConnection = true
this._lawo.on('connected', async () => {
Expand Down Expand Up @@ -496,7 +496,7 @@ export class LawoDevice extends DeviceWithState<LawoState, DeviceOptionsLawoInte
command: command,
timelineObjId: timelineObjId,
}
this.emit('debug', cwc)
this.emitDebug(cwc)

// save start time of command
const startSend = this.getCurrentTime()
Expand Down Expand Up @@ -543,7 +543,7 @@ export class LawoDevice extends DeviceWithState<LawoState, DeviceOptionsLawoInte
{ type: EmberModel.ParameterType.Real, value: command.value },
{ type: EmberModel.ParameterType.Real, value: command.transitionDuration / 1000 }
)
this.emit('debug', `Ember function invoked (${timelineObjId}, ${command.identifier}, ${command.value})`)
this.emitDebug(`Ember function invoked (${timelineObjId}, ${command.identifier}, ${command.value})`)
const res = await req.response
if (res && res.success === false) {
const reasons = {
Expand Down Expand Up @@ -574,13 +574,12 @@ export class LawoDevice extends DeviceWithState<LawoState, DeviceOptionsLawoInte
new Error('Lawo Result ' + res.result![0].value)
)
}
this.emit('debug', `Lawo: Ember fn error ${command.identifier}): result ${result}: ${reasons[result]}`, {
this.emitDebug(`Lawo: Ember fn error ${command.identifier}): result ${result}: ${reasons[result]}`, {
...res,
source: command.identifier,
})
} else {
this.emit(
'debug',
this.emitDebug(
`Ember function result (${timelineObjId}, ${command.identifier}): ${JSON.stringify(res)}`,
res
)
Expand All @@ -607,7 +606,7 @@ export class LawoDevice extends DeviceWithState<LawoState, DeviceOptionsLawoInte
const req = await this._lawo.setValue(node, value, logResult)
if (logResult) {
const res = await req.response
this.emit('debug', `Ember result (${timelineObjId}): ${res && res.contents.value}`, {
this.emitDebug(`Ember result (${timelineObjId}): ${res && res.contents.value}`, {
command,
res: res && res.contents,
})
Expand Down
2 changes: 1 addition & 1 deletion packages/timeline-state-resolver/src/devices/obs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,7 @@ export class OBSDevice extends DeviceWithState<OBSState, DeviceOptionsOBSInterna
command: cmd,
timelineObjId: timelineObjId,
}
this.emit('debug', cwc)
this.emitDebug(cwc)

return this._obs.send(cmd.command.requestName, cmd.command.args as any).catch((error) => {
this.emit('commandError', error, cwc)
Expand Down
4 changes: 2 additions & 2 deletions packages/timeline-state-resolver/src/devices/osc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ export class OSCMessageDevice extends DeviceWithState<OSCDeviceState, DeviceOpti
command: cmd,
timelineObjId: timelineObjId,
}
this.emit('debug', cwc)
this.emitDebug(cwc)
debug(cmd)

try {
Expand Down Expand Up @@ -330,7 +330,7 @@ export class OSCMessageDevice extends DeviceWithState<OSCDeviceState, DeviceOpti
}
}
private _defaultOscSender(msg: osc.OscMessage, address?: string | undefined, port?: number | undefined): void {
this.emit('debug', 'sending ' + msg.address)
this.emitDebug('sending ' + msg.address)
this._oscClient.send(msg, address, port)
}
private runAnimation() {
Expand Down
10 changes: 5 additions & 5 deletions packages/timeline-state-resolver/src/devices/panasonicPTZ.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export class PanasonicPtzDevice extends DeviceWithState<PanasonicPtzState, Devic
this._setConnected(false)
})
this._device.on('debug', (...args) => {
this.emit('debug', 'Panasonic PTZ', ...args)
this.emitDebug('Panasonic PTZ', ...args)
})
} else {
this._device = undefined
Expand Down Expand Up @@ -276,27 +276,27 @@ export class PanasonicPtzDevice extends DeviceWithState<PanasonicPtzState, Devic
// recall preset
if (cmd.preset !== undefined) {
const res = await this._device.recallPreset(cmd.preset)
this.emit('debug', `Panasonic PTZ result: ${res}`)
this.emitDebug(`Panasonic PTZ result: ${res}`)
} else throw new Error(`Bad parameter: preset`)
} else if (cmd.type === TimelineContentTypePanasonicPtz.SPEED) {
// set speed
if (cmd.speed !== undefined) {
const res = await this._device.setSpeed(cmd.speed)
this.emit('debug', `Panasonic PTZ result: ${res}`)
this.emitDebug(`Panasonic PTZ result: ${res}`)
} else throw new Error(`Bad parameter: speed`)
} else if (cmd.type === TimelineContentTypePanasonicPtz.ZOOM_SPEED) {
// set zoom speed
if (cmd.zoomSpeed !== undefined) {
// scale -1 - 0 - +1 range to 01 - 50 - 99 range
const res = await this._device.setZoomSpeed(cmd.zoomSpeed * 49 + 50)
this.emit('debug', `Panasonic PTZ result: ${res}`)
this.emitDebug(`Panasonic PTZ result: ${res}`)
} else throw new Error(`Bad parameter: zoomSpeed`)
} else if (cmd.type === TimelineContentTypePanasonicPtz.ZOOM) {
// set zoom
if (cmd.zoom !== undefined) {
// scale 0 - +1 range to 555h - FFFh range
const res = await this._device.setZoom(cmd.zoom * 0xaaa + 0x555)
this.emit('debug', `Panasonic PTZ result: ${res}`)
this.emitDebug(`Panasonic PTZ result: ${res}`)
} else throw new Error(`Bad parameter: zoom`)
} else throw new Error(`PTZ: Unknown type: "${cmd.type}"`)
} else throw new Error(`PTZ device not set up`)
Expand Down
2 changes: 1 addition & 1 deletion packages/timeline-state-resolver/src/devices/pharos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ export class PharosDevice extends DeviceWithState<PharosState, DeviceOptionsPhar
},
timelineObjId: timelineObjId,
}
this.emit('debug', cwc)
this.emitDebug(cwc)

// execute the command here
try {
Expand Down
4 changes: 2 additions & 2 deletions packages/timeline-state-resolver/src/devices/quantel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export class QuantelDevice extends DeviceWithState<QuantelState, DeviceOptionsQu
this.emit('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('debug', (...args) => this.emitDebug(...args))

this._doOnTime = new DoOnTime(
() => {
Expand Down Expand Up @@ -610,7 +610,7 @@ export class QuantelDevice extends DeviceWithState<QuantelState, DeviceOptionsQu
timelineObjId: timelineObjId,
command: cmd,
}
this.emit('debug', cwc)
this.emitDebug(cwc)

try {
const cmdType = cmd.type
Expand Down
2 changes: 1 addition & 1 deletion packages/timeline-state-resolver/src/devices/shotoku.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ export class ShotokuDevice extends DeviceWithState<ShotokuDeviceState, DeviceOpt
command: cmd,
timelineObjId: timelineObjId,
}
this.emit('debug', cwc)
this.emitDebug(cwc)

try {
if (this._shotoku.connected) {
Expand Down
5 changes: 2 additions & 3 deletions packages/timeline-state-resolver/src/devices/singularLive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ export class SingularLiveDevice extends DeviceWithState<SingularLiveState, Devic
command: cmd,
timelineObjId: timelineObjId,
}
this.emit('debug', cwc)
this.emitDebug(cwc)

const url = SINGULAR_LIVE_API + this._accessToken

Expand All @@ -325,8 +325,7 @@ export class SingularLiveDevice extends DeviceWithState<SingularLiveState, Devic
this.emit('error', `SingularLive.response error ${cmd.compositionName} (${context}`, error)
reject(error)
} else if (response.statusCode === 200) {
this.emit(
'debug',
this.emitDebug(
`SingularLive: ${cmd.compositionName}: Good statuscode response on url "${url}": ${response.statusCode} (${context})`
)
resolve()
Expand Down
2 changes: 1 addition & 1 deletion packages/timeline-state-resolver/src/devices/sisyfos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ export class SisyfosMessageDevice extends DeviceWithState<SisyfosState, DeviceOp
command: cmd,
timelineObjId: timelineObjId,
}
this.emit('debug', cwc)
this.emitDebug(cwc)

if (cmd.type === SisyfosCommandType.RESYNC) {
return this._makeReadyInner(true, true)
Expand Down
2 changes: 1 addition & 1 deletion packages/timeline-state-resolver/src/devices/tcpSend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ export class TCPSendDevice extends DeviceWithState<TSCSendState, DeviceOptionsTC
command: cmd,
timelineObjId: timelineObjId,
}
this.emit('debug', cwc)
this.emitDebug(cwc)

if (cmd.message) {
return this._sendTCPMessage(cmd.message)
Expand Down
10 changes: 5 additions & 5 deletions packages/timeline-state-resolver/src/devices/vizMSE.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ export class VizMSEDevice extends DeviceWithState<VizMSEState, DeviceOptionsVizM
this._vizmseManager.on('info', (str) => this.emit('info', 'VizMSE: ' + str))
this._vizmseManager.on('warning', (str) => this.emit('warning', 'VizMSE' + str))
this._vizmseManager.on('error', (e) => this.emit('error', 'VizMSE', e))
this._vizmseManager.on('debug', (...args) => this.emit('debug', ...args))
this._vizmseManager.on('debug', (...args) => this.emitDebug(...args))

await this._vizmseManager.initializeRundown(activeRundownPlaylistId)

Expand Down Expand Up @@ -219,9 +219,9 @@ export class VizMSEDevice extends DeviceWithState<VizMSEState, DeviceOptionsVizM
return true
}
public handleExpectedPlayoutItems(expectedPlayoutItems: Array<ExpectedPlayoutItem>): void {
this.emit('debug', 'VIZDEBUG: handleExpectedPlayoutItems called')
this.emitDebug('VIZDEBUG: handleExpectedPlayoutItems called')
if (this._vizmseManager) {
this.emit('debug', 'VIZDEBUG: manager exists')
this.emitDebug('VIZDEBUG: manager exists')
this._vizmseManager.setExpectedPlayoutItems(expectedPlayoutItems)
}
}
Expand Down Expand Up @@ -670,7 +670,7 @@ export class VizMSEDevice extends DeviceWithState<VizMSEState, DeviceOptionsVizM
})
}

this.emit('debug', `VIZMSE: COMMANDS: ${JSON.stringify(sortCommands(concatCommands))}`)
this.emitDebug(`VIZMSE: COMMANDS: ${JSON.stringify(sortCommands(concatCommands))}`)

return sortCommands(concatCommands)
}
Expand Down Expand Up @@ -723,7 +723,7 @@ export class VizMSEDevice extends DeviceWithState<VizMSEState, DeviceOptionsVizM
timelineObjId: timelineObjId,
command: cmd,
}
this.emit('debug', cwc)
this.emitDebug(cwc)

try {
if (this._vizmseManager) {
Expand Down
4 changes: 2 additions & 2 deletions packages/timeline-state-resolver/src/devices/vmix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export class VMixDevice extends DeviceWithState<VMixStateExtended, DeviceOptions
})
this._vmix.on('error', (e) => this.emit('error', 'VMix', e))
this._vmix.on('stateChanged', (state) => this._onVMixStateChanged(state))
this._vmix.on('debug', (...args) => this.emit('debug', ...args))
this._vmix.on('debug', (...args) => this.emitDebug(...args))

return this._vmix.connect(options)
}
Expand Down Expand Up @@ -1017,7 +1017,7 @@ export class VMixDevice extends DeviceWithState<VMixStateExtended, DeviceOptions
command: cmd,
timelineObjId: timelineObjId,
}
this.emit('debug', cwc)
this.emitDebug(cwc)

return this._vmix.sendCommand(cmd.command).catch((error) => {
this.emit('commandError', error, cwc)
Expand Down

0 comments on commit 5d015a1

Please sign in to comment.