From 5d015a1dfde3ffc86f9aea9366bf72f76537d9a4 Mon Sep 17 00:00:00 2001 From: Johan Nyman Date: Thu, 30 Sep 2021 13:20:38 +0200 Subject: [PATCH] fix: emitting of 'debug' events should only be done if the debug property is truthy. --- .../timeline-state-resolver-types/src/device.ts | 1 + .../timeline-state-resolver/src/devices/abstract.ts | 2 +- .../timeline-state-resolver/src/devices/atem.ts | 5 ++--- .../timeline-state-resolver/src/devices/casparCG.ts | 4 ++-- .../timeline-state-resolver/src/devices/device.ts | 12 ++++++++++++ .../src/devices/deviceContainer.ts | 11 +++++++++++ .../timeline-state-resolver/src/devices/httpSend.ts | 5 ++--- .../src/devices/hyperdeck.ts | 2 +- .../timeline-state-resolver/src/devices/lawo.ts | 13 ++++++------- packages/timeline-state-resolver/src/devices/obs.ts | 2 +- packages/timeline-state-resolver/src/devices/osc.ts | 4 ++-- .../src/devices/panasonicPTZ.ts | 10 +++++----- .../timeline-state-resolver/src/devices/pharos.ts | 2 +- .../timeline-state-resolver/src/devices/quantel.ts | 4 ++-- .../timeline-state-resolver/src/devices/shotoku.ts | 2 +- .../src/devices/singularLive.ts | 5 ++--- .../timeline-state-resolver/src/devices/sisyfos.ts | 2 +- .../timeline-state-resolver/src/devices/tcpSend.ts | 2 +- .../timeline-state-resolver/src/devices/vizMSE.ts | 10 +++++----- .../timeline-state-resolver/src/devices/vmix.ts | 4 ++-- 20 files changed, 61 insertions(+), 41 deletions(-) diff --git a/packages/timeline-state-resolver-types/src/device.ts b/packages/timeline-state-resolver-types/src/device.ts index 5784a56200..d3c9d710d2 100644 --- a/packages/timeline-state-resolver-types/src/device.ts +++ b/packages/timeline-state-resolver-types/src/device.ts @@ -27,6 +27,7 @@ export interface DeviceOptionsBase extends SlowReportOptions { threadUsage?: number disable?: boolean options?: T + debug?: boolean } export interface SlowReportOptions { diff --git a/packages/timeline-state-resolver/src/devices/abstract.ts b/packages/timeline-state-resolver/src/devices/abstract.ts index c15a2598cb..f04b88c9cf 100644 --- a/packages/timeline-state-resolver/src/devices/abstract.ts +++ b/packages/timeline-state-resolver/src/devices/abstract.ts @@ -211,7 +211,7 @@ export class AbstractDevice extends DeviceWithState> protected _deviceOptions: TOptions protected _reportAllCommands = false protected _isActive = true + private debugLogging: boolean constructor(deviceId: string, deviceOptions: TOptions, getCurrentTime: () => Promise) { 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() @@ -202,6 +204,16 @@ export abstract class Device> } 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 } diff --git a/packages/timeline-state-resolver/src/devices/deviceContainer.ts b/packages/timeline-state-resolver/src/devices/deviceContainer.ts index b578594aaf..8daad4aaae 100644 --- a/packages/timeline-state-resolver/src/devices/deviceContainer.ts +++ b/packages/timeline-state-resolver/src/devices/deviceContainer.ts @@ -18,10 +18,12 @@ export class DeviceContainer> { 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< @@ -77,6 +79,11 @@ export class DeviceContainer> { await ThreadedClassManager.destroy(this._device) } + public async setDebugLogging(debug: boolean): Promise { + this._debugLogging = debug + await this._device.setDebugLogging(debug) + } + public get device(): ThreadedClass> { return this._device } @@ -101,4 +108,8 @@ export class DeviceContainer> { public get startTime(): number { return this._startTime } + + public get debugLogging(): boolean { + return this._debugLogging + } } diff --git a/packages/timeline-state-resolver/src/devices/httpSend.ts b/packages/timeline-state-resolver/src/devices/httpSend.ts index 2cb52acfad..e623eb7c7b 100644 --- a/packages/timeline-state-resolver/src/devices/httpSend.ts +++ b/packages/timeline-state-resolver/src/devices/httpSend.ts @@ -239,7 +239,7 @@ export class HTTPSendDevice extends DeviceWithState { this.emit('commandError', error, cwc) diff --git a/packages/timeline-state-resolver/src/devices/lawo.ts b/packages/timeline-state-resolver/src/devices/lawo.ts index b867c36d31..32e398c84d 100644 --- a/packages/timeline-state-resolver/src/devices/lawo.ts +++ b/packages/timeline-state-resolver/src/devices/lawo.ts @@ -161,7 +161,7 @@ export class LawoDevice extends DeviceWithState { - // this.emit('debug', 'Warning: Lawo.Emberplus', w) + // this.emitDebug('Warning: Lawo.Emberplus', w) // }) let firstConnection = true this._lawo.on('connected', async () => { @@ -496,7 +496,7 @@ export class LawoDevice extends DeviceWithState { this.emit('commandError', error, cwc) diff --git a/packages/timeline-state-resolver/src/devices/osc.ts b/packages/timeline-state-resolver/src/devices/osc.ts index b43e2f30d9..098ad04dad 100644 --- a/packages/timeline-state-resolver/src/devices/osc.ts +++ b/packages/timeline-state-resolver/src/devices/osc.ts @@ -285,7 +285,7 @@ export class OSCMessageDevice extends DeviceWithState { - this.emit('debug', 'Panasonic PTZ', ...args) + this.emitDebug('Panasonic PTZ', ...args) }) } else { this._device = undefined @@ -276,27 +276,27 @@ export class PanasonicPtzDevice extends DeviceWithState 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( () => { @@ -610,7 +610,7 @@ export class QuantelDevice extends DeviceWithState 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) @@ -219,9 +219,9 @@ export class VizMSEDevice extends DeviceWithState): 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) } } @@ -670,7 +670,7 @@ export class VizMSEDevice extends DeviceWithState 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) } @@ -1017,7 +1017,7 @@ export class VMixDevice extends DeviceWithState { this.emit('commandError', error, cwc)