@@ -97,7 +97,7 @@ class Connection extends EventEmitter {
97
97
return new Promise ( ( resolve ) => {
98
98
this . udp . once ( 'message' , ( message ) => {
99
99
const data = message . readUInt16BE ( 0 )
100
- if ( data != 2 ) return ;
100
+ if ( data !== 2 ) return ;
101
101
102
102
const packet = Buffer . from ( message )
103
103
@@ -198,10 +198,10 @@ class Connection extends EventEmitter {
198
198
199
199
let packet = Buffer . from ( Sodium . open ( voice , this . nonceBuffer , this . udpInfo . secretKey ) )
200
200
201
- if ( packet [ 0 ] == 0xbe && packet [ 1 ] == 0xde )
201
+ if ( packet [ 0 ] === 0xbe && packet [ 1 ] = == 0xde )
202
202
packet = packet . subarray ( 4 + 4 * packet . readUInt16BE ( 2 ) )
203
203
204
- if ( packet . compare ( OPUS_SILENCE_FRAME ) == 0 ) {
204
+ if ( packet . compare ( OPUS_SILENCE_FRAME ) === 0 ) {
205
205
if ( userData . stream . _readableState . ended ) return ;
206
206
207
207
this . emit ( 'speakEnd' , userData . userId , ssrc )
@@ -322,7 +322,7 @@ class Connection extends EventEmitter {
322
322
this . player . timestamp += TIMESTAMP_INCREMENT
323
323
if ( this . player . timestamp >= MAX_TIMESTAMP ) this . player . timestamp = 0
324
324
this . player . sequence ++
325
- if ( this . player . sequence == MAX_SEQUENCE ) this . player . sequence = 0
325
+ if ( this . player . sequence === MAX_SEQUENCE ) this . player . sequence = 0
326
326
327
327
let packet = null
328
328
@@ -344,7 +344,7 @@ class Connection extends EventEmitter {
344
344
}
345
345
case 'xsalsa20_poly1305_lite' : {
346
346
this . nonce ++
347
- if ( this . nonce == MAX_NONCE ) this . nonce = 0
347
+ if ( this . nonce === MAX_NONCE ) this . nonce = 0
348
348
this . nonceBuffer . writeUInt32LE ( this . nonce , 0 )
349
349
350
350
const output = Sodium . close ( chunk , this . nonceBuffer , this . udpInfo . secretKey )
@@ -422,7 +422,7 @@ class Connection extends EventEmitter {
422
422
clearInterval ( this . hbInterval )
423
423
clearInterval ( this . playInterval )
424
424
425
- if ( this . ws ) {
425
+ if ( this . ws && ! this . ws . closing ) {
426
426
this . ws . close ( code , reason )
427
427
this . ws . removeAllListeners ( )
428
428
this . ws = null
@@ -457,25 +457,22 @@ class Connection extends EventEmitter {
457
457
this . sessionId = obj . session_id
458
458
}
459
459
460
- _voiceServerUpdate ( obj ) {
460
+ voiceServerUpdate ( obj ) {
461
+ if ( this . voiceServer ?. token === obj . token && this . voiceServer ?. endpoint === obj . endpoint ) return ;
462
+
461
463
this . voiceServer = {
462
464
token : obj . token ,
463
465
endpoint : obj . endpoint
464
466
}
465
467
466
- this . _updateState ( { status : 'connecting' } )
467
- }
468
-
469
- voiceServerUpdate ( obj ) {
470
- if ( this . voiceServer ?. token == obj . token && this . voiceServer ?. endpoint == obj . endpoint ) return ;
471
-
472
- this . _voiceServerUpdate ( obj )
473
-
474
468
if ( this . ws ) {
475
469
this . _destroyConnection ( 4015 , 'Voice server update' )
476
470
477
- this . connect ( ( ) => this . unpause ( 'reconnected' ) , false )
478
- }
471
+ this . connect ( ( ) => {
472
+ if ( this . audioStream ) this . unpause ( 'reconnected' )
473
+ else this . _updatePlayerState ( { status : 'idle' , reason : 'reconnected' } )
474
+ } , false )
475
+ } else this . _updateState ( { status : 'connecting' } )
479
476
}
480
477
}
481
478
0 commit comments