1- import { InstanceBase , runEntrypoint } from '@companion-module/base'
1+ import { InstanceBase , InstanceStatus , runEntrypoint } from '@companion-module/base'
22import { getActions } from './actions.js'
33import { getPresets } from './presets.js'
44import { getVariables , updateVariables } from './variables.js'
@@ -15,7 +15,7 @@ class VDONinjaInstance extends InstanceBase {
1515 }
1616
1717 async init ( config ) {
18- this . updateStatus ( 'connecting' )
18+ this . updateStatus ( InstanceStatus . Connecting )
1919
2020 this . config = config
2121
@@ -118,7 +118,7 @@ class VDONinjaInstance extends InstanceBase {
118118 this . log ( 'info' , `Connection opened to VDO.Ninja` )
119119 this . connected = true
120120 }
121- this . updateStatus ( 'ok' )
121+ this . updateStatus ( InstanceStatus . Ok )
122122
123123 this . ws . send ( `{"join": "${ this . config . apiID } " }` )
124124 this . ws . send ( `{"action": "getDetails"}` )
@@ -139,7 +139,7 @@ class VDONinjaInstance extends InstanceBase {
139139 this . ws . on ( 'error' , ( data ) => {
140140 if ( this . connected !== false ) {
141141 this . connected = false
142- this . updateStatus ( 'connection_failure' )
142+ this . updateStatus ( InstanceStatus . ConnectionFailure )
143143 if ( data ?. code == 'ENOTFOUND' ) {
144144 this . log ( 'error' , `Unable to reach ${ serverUrl } ` )
145145 } else {
@@ -152,7 +152,7 @@ class VDONinjaInstance extends InstanceBase {
152152 } )
153153 } else {
154154 this . log ( 'warn' , `API ID required to connect to VDO.Ninja, please add one in the module settings` )
155- this . updateStatus ( 'bad_config' , 'Missing API ID' )
155+ this . updateStatus ( InstanceStatus . BadConfig , 'Missing API ID' )
156156 }
157157 }
158158
@@ -166,6 +166,17 @@ class VDONinjaInstance extends InstanceBase {
166166 let data = result [ x ]
167167 this . processGetDetails ( data )
168168 }
169+ } else if ( callback . local ) {
170+ for ( let x in this . states ) {
171+ if ( this . states [ x ] . localStream ) {
172+ let result = callback . result
173+ if ( callback . value !== 'toggle' ) {
174+ this . processUpdate ( { streamID : this . states [ x ] . streamID , action : callback . action , value : result } )
175+ }
176+ }
177+ }
178+ } else {
179+ //console.log(callback)
169180 }
170181 } else if ( message ?. update ) {
171182 let data = message . update
@@ -186,6 +197,10 @@ class VDONinjaInstance extends InstanceBase {
186197 label = data . label
187198 }
188199
200+ if ( data . localStream ) {
201+ label = `${ label } (Local)`
202+ }
203+
189204 let streamObject = { id : data . streamID , label : label }
190205
191206 if ( this . streams . find ( ( o ) => o . id === data . streamID ) ) {
@@ -244,17 +259,20 @@ class VDONinjaInstance extends InstanceBase {
244259 this . ws . send ( `{"action": "getDetails"}` )
245260 break
246261 case 'directorMuted' :
247- this . states [ data . streamID ] . others [ 'mute-guest' ] = data . value ? 1 : 0
262+ this . states [ data . streamID ] . others [ 'mute-guest' ] = data . value ? '1' : '0'
248263 break
249- case 'directorVideoMuted ' :
250- this . states [ data . streamID ] . others [ 'hide-guest' ] = data . value ? 1 : 0
264+ case 'directorVideoHide ' :
265+ this . states [ data . streamID ] . others [ 'hide-guest' ] = data . value ? '1' : '0'
251266 break
252267 case 'remoteMuted' :
268+ case 'mic' :
253269 this . states [ data . streamID ] . muted = data . value
254270 break
255271 case 'remoteVideoMuted' :
272+ case 'camera' :
256273 this . states [ data . streamID ] . videoMuted = data . value
257274 break
275+
258276 default :
259277 this . states [ data . streamID ] [ data . action ] = data . value
260278 break
@@ -267,11 +285,12 @@ class VDONinjaInstance extends InstanceBase {
267285 }
268286 }
269287
270- sendRequest ( action , target , value ) {
288+ sendRequest ( action , target , value , local ) {
271289 let object = {
272- action : action ? action : 'null' ,
273- target : target ? target : 'null' ,
274- value : value ? value : 'null' ,
290+ action : action ?? 'null' ,
291+ target : target ?? 'null' ,
292+ value : value ?? 'null' ,
293+ local : local ?? false ,
275294 }
276295 this . ws . send ( JSON . stringify ( object ) )
277296 }
0 commit comments