@@ -298,9 +298,14 @@ export class Networking extends EventEmitter {
298298 * Creates a new WebSocket to a Discord Voice gateway.
299299 *
300300 * @param endpoint - The endpoint to connect to
301+ * @param lastSequence - The last sequence to set for this WebSocket
301302 */
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+ }
304309
305310 ws . on ( 'error' , this . onChildError ) ;
306311 ws . once ( 'open' , this . onWsOpen ) ;
@@ -347,6 +352,7 @@ export class Networking extends EventEmitter {
347352 server_id : this . state . connectionOptions . serverId ,
348353 session_id : this . state . connectionOptions . sessionId ,
349354 token : this . state . connectionOptions . token ,
355+ seq_ack : this . state . ws . sequence ,
350356 } ,
351357 } ;
352358 this . state . ws . sendPacket ( packet ) ;
@@ -363,10 +369,11 @@ export class Networking extends EventEmitter {
363369 private onWsClose ( { code } : CloseEvent ) {
364370 const canResume = code === 4_015 || code < 4_000 ;
365371 if ( canResume && this . state . code === NetworkingStatusCode . Ready ) {
372+ const lastSequence = this . state . ws . sequence ;
366373 this . state = {
367374 ...this . state ,
368375 code : NetworkingStatusCode . Resuming ,
369- ws : this . createWebSocket ( this . state . connectionOptions . endpoint ) ,
376+ ws : this . createWebSocket ( this . state . connectionOptions . endpoint , lastSequence ) ,
370377 } ;
371378 } else if ( this . state . code !== NetworkingStatusCode . Closed ) {
372379 this . destroy ( ) ;
@@ -379,10 +386,11 @@ export class Networking extends EventEmitter {
379386 */
380387 private onUdpClose ( ) {
381388 if ( this . state . code === NetworkingStatusCode . Ready ) {
389+ const lastSequence = this . state . ws . sequence ;
382390 this . state = {
383391 ...this . state ,
384392 code : NetworkingStatusCode . Resuming ,
385- ws : this . createWebSocket ( this . state . connectionOptions . endpoint ) ,
393+ ws : this . createWebSocket ( this . state . connectionOptions . endpoint , lastSequence ) ,
386394 } ;
387395 }
388396 }
0 commit comments