@@ -13,6 +13,7 @@ export default class CommsManager {
1313 private ws : WebSocket ;
1414 private observers : { [ id : string ] : Function [ ] } = { } ;
1515 private pendingPromises : Map < string , PromiseHandlers > = new Map ( ) ;
16+ private static timeoutId ?: NodeJS . Timeout ;
1617 private static state : string = "idle" ;
1718 private static adress : string = "ws://127.0.0.1:7163" ;
1819 private static universe ?: string ;
@@ -67,13 +68,13 @@ export default class CommsManager {
6768 this . ws . onclose = ( e ) => {
6869 if ( e . wasClean ) {
6970 console . log (
70- `Connection with ${ CommsManager . adress } closed, all suscribers cleared`
71+ `Connection with ${ CommsManager . adress } closed, all suscribers cleared` ,
7172 ) ;
7273 } else {
7374 console . log ( `Connection with ${ CommsManager . adress } interrupted` ) ;
7475 }
7576
76- setTimeout ( function ( ) {
77+ CommsManager . timeoutId = setTimeout ( function ( ) {
7778 delete CommsManager . instance ;
7879 CommsManager . instance = new CommsManager ( ) ;
7980 } , 1000 ) ;
@@ -93,6 +94,10 @@ export default class CommsManager {
9394 if ( CommsManager . instance ) {
9495 delete CommsManager . instance ;
9596 CommsManager . instance = undefined ;
97+ if ( CommsManager . timeoutId ) {
98+ clearTimeout ( CommsManager . timeoutId ) ;
99+ CommsManager . timeoutId = undefined ;
100+ }
96101 }
97102 }
98103
@@ -120,7 +125,7 @@ export default class CommsManager {
120125 for ( let i = 0 , length = events . length ; i < length ; i ++ ) {
121126 this . observers [ events [ i ] ] = this . observers [ events [ i ] ] || [ ] ;
122127 this . observers [ events [ i ] ] . splice (
123- this . observers [ events [ i ] ] . indexOf ( callback )
128+ this . observers [ events [ i ] ] . indexOf ( callback ) ,
124129 ) ;
125130 }
126131 } ;
0 commit comments