@@ -326,7 +326,9 @@ async function obs_init () {
326326 }
327327
328328 // Create a new OBS WebSocket instance
329- globalThis . obs = new OBSWebSocket ( ) ;
329+ if ( globalThis . obs === undefined ) {
330+ globalThis . obs = new OBSWebSocket ( ) ;
331+ }
330332 update_status ( `Trying to connect to ${ url } ` )
331333
332334 try {
@@ -341,17 +343,22 @@ async function obs_init () {
341343 forEach ( '.ssl-warning' , div => {
342344 div . style [ 'display' ] = 'none'
343345 } )
346+ forEach ( '.reconnect-button' , x => { x . style . display = 'none' } )
344347 // Poll to keep the connection alive
345348 globalThis . obs_pinger = setInterval ( async function ( ) { console . log ( "Connection ping: " , ( await obs . call ( 'GetVersion' ) ) . obsVersion ) } ,
346349 60000 ) ;
347- obs . on ( 'ConnectionClosed' , e => { update_status ( `OBS Disconnected (closed)!: ${ e } ` ) ; obs_reconnect ( ) ; } )
348- obs . on ( 'ConnectionError' , e => { update_status ( `OBS Disconnected (error)!: ${ e } ` ) ; obs_reconnect ( ) ; } )
350+ obs . on ( 'ConnectionClosed' , e => { obs_disconnected ( e ) } )
351+ obs . on ( 'ConnectionError' , e => { obs_disconnected ( e ) } )
349352}
350353
351- async function obs_reconnect ( n ) {
354+ async function obs_disconnected ( e ) {
352355 if ( obs_pinger ) {
353356 clearInterval ( obs_pinger )
354357 }
358+ update_status ( `OBS Disconnected (closed)!: ${ e } ` )
359+ forEach ( '.reconnect-button' , x => { x . style . display = '' } )
360+ }
361+ async function obs_reconnect ( n ) {
355362 return // disabled
356363 append_status ( "Reconnecting in 5s..." )
357364 setTimeout ( obs_init , 5000 )
0 commit comments