Skip to content
This repository has been archived by the owner on Mar 3, 2022. It is now read-only.

Commit

Permalink
feat: added debugLogging
Browse files Browse the repository at this point in the history
  • Loading branch information
nytamin committed Jun 26, 2018
1 parent 9042cc0 commit b390c67
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/coreHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,7 @@ export class CoreHandler {
this._coreMosHandlers.push(coreMos)
return coreMos.init()
.then(() => {
this.logger.info('registerMosDevice done!')
return coreMos
})
}
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ if (logPath) {
console.log('Logging to Console')
// Log json to console
logger.add(Winston.transports.Console,{
level: 'verbose',
handleExceptions: true,
json: true,
stringify: (obj) => JSON.stringify(obj) // make single line
Expand Down
36 changes: 28 additions & 8 deletions src/mosHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
import * as _ from 'underscore'
import * as Winston from 'winston'
import { CoreHandler } from './coreHandler'
import { CollectionObj } from 'tv-automation-server-core-integration'

// export interface MosOptions {
// mosID: string,
Expand All @@ -46,7 +47,8 @@ export interface MosDeviceSettings {
mosId: string,
devices: {
[deviceId: string]: MosDeviceSettingsDevice
}
},
debugLogging: boolean
}
export interface MosDeviceSettingsDevice {
primary: MosDeviceSettingsDeviceOptions
Expand All @@ -62,6 +64,7 @@ export class MosHandler {
public mos: MosConnection

public mosOptions: MosConfig
public debugLogging: boolean = false

private allMosDevices: {[id: string]: IMOSDevice} = {}
private _ownMosDevices: {[deviceId: string]: MosDevice} = {}
Expand Down Expand Up @@ -151,13 +154,26 @@ export class MosHandler {
// this._observers.push(mappingsObserver)

let deviceObserver = this._coreHandler.core.observe('peripheralDevices')
deviceObserver.added = () => { this._triggerupdateDevices() }
deviceObserver.changed = () => { this._triggerupdateDevices() }
deviceObserver.removed = () => { this._triggerupdateDevices() }
deviceObserver.added = () => { this._deviceOptionsChanged() }
deviceObserver.changed = () => { this._deviceOptionsChanged() }
deviceObserver.removed = () => { this._deviceOptionsChanged() }
this._observers.push(deviceObserver)

}
private _triggerupdateDevices () {
debugLog (msg: any, ...args: any[]) {
if (this.debugLogging) {
this._logger.debug(msg, ...args)
}
}
private _deviceOptionsChanged () {
let peripheralDevice = this.getThisPeripheralDevice()
if (peripheralDevice) {
let settings: MosDeviceSettings = peripheralDevice.settings || {}
if (this.debugLogging !== settings.debugLogging) {
this._logger.debug('Changing debugLogging to ' + settings.debugLogging)
this.debugLogging = settings.debugLogging
}
}
if (this._triggerupdateDevicesTimeout) {
clearTimeout(this._triggerupdateDevicesTimeout)
}
Expand All @@ -181,7 +197,8 @@ export class MosHandler {

this.mos = new MosConnection(connectionConfig)
this.mos.on('rawMessage', (source, type, message) => {
this._logger.debug('rawMessage', source, type, message)
this.debugLog('rawMessage', source, type, message)
// this._logger.debug('rawMessage', source, type, message)
})
this.mos.on('info', (message) => {
this._logger.info(message)
Expand Down Expand Up @@ -305,15 +322,18 @@ export class MosHandler {
return
})
}
private getThisPeripheralDevice (): CollectionObj | undefined {
let peripheralDevices = this._coreHandler.core.getCollection('peripheralDevices')
return peripheralDevices.findOne(this._coreHandler.core.deviceId)
}
private _updateDevices (): Promise<void> {
return (
!this.mos ?
this._initMosConnection() :
Promise.resolve()
)
.then(() => {
let peripheralDevices = this._coreHandler.core.getCollection('peripheralDevices')
let peripheralDevice = peripheralDevices.findOne(this._coreHandler.core.deviceId)
let peripheralDevice = this.getThisPeripheralDevice()

if (peripheralDevice) {
let settings: MosDeviceSettings = peripheralDevice.settings || {}
Expand Down

0 comments on commit b390c67

Please sign in to comment.