@@ -298,9 +298,14 @@ export class Networking extends EventEmitter {
298
298
* Creates a new WebSocket to a Discord Voice gateway.
299
299
*
300
300
* @param endpoint - The endpoint to connect to
301
+ * @param lastSequence - The last sequence to set for this WebSocket
301
302
*/
302
- private createWebSocket ( endpoint : string ) {
303
- const ws = new VoiceWebSocket ( `wss://${ endpoint } ?v=4` , Boolean ( this . debug ) ) ;
303
+ private createWebSocket ( endpoint : string , lastSequence ?: number ) {
304
+ const ws = new VoiceWebSocket ( `wss://${ endpoint } ?v=8` , Boolean ( this . debug ) ) ;
305
+
306
+ if ( lastSequence !== undefined ) {
307
+ ws . sequence = lastSequence ;
308
+ }
304
309
305
310
ws . on ( 'error' , this . onChildError ) ;
306
311
ws . once ( 'open' , this . onWsOpen ) ;
@@ -347,6 +352,7 @@ export class Networking extends EventEmitter {
347
352
server_id : this . state . connectionOptions . serverId ,
348
353
session_id : this . state . connectionOptions . sessionId ,
349
354
token : this . state . connectionOptions . token ,
355
+ seq_ack : this . state . ws . sequence ,
350
356
} ,
351
357
} ;
352
358
this . state . ws . sendPacket ( packet ) ;
@@ -363,10 +369,11 @@ export class Networking extends EventEmitter {
363
369
private onWsClose ( { code } : CloseEvent ) {
364
370
const canResume = code === 4_015 || code < 4_000 ;
365
371
if ( canResume && this . state . code === NetworkingStatusCode . Ready ) {
372
+ const lastSequence = this . state . ws . sequence ;
366
373
this . state = {
367
374
...this . state ,
368
375
code : NetworkingStatusCode . Resuming ,
369
- ws : this . createWebSocket ( this . state . connectionOptions . endpoint ) ,
376
+ ws : this . createWebSocket ( this . state . connectionOptions . endpoint , lastSequence ) ,
370
377
} ;
371
378
} else if ( this . state . code !== NetworkingStatusCode . Closed ) {
372
379
this . destroy ( ) ;
@@ -379,10 +386,11 @@ export class Networking extends EventEmitter {
379
386
*/
380
387
private onUdpClose ( ) {
381
388
if ( this . state . code === NetworkingStatusCode . Ready ) {
389
+ const lastSequence = this . state . ws . sequence ;
382
390
this . state = {
383
391
...this . state ,
384
392
code : NetworkingStatusCode . Resuming ,
385
- ws : this . createWebSocket ( this . state . connectionOptions . endpoint ) ,
393
+ ws : this . createWebSocket ( this . state . connectionOptions . endpoint , lastSequence ) ,
386
394
} ;
387
395
}
388
396
}
0 commit comments