From 6a0ab380e74431259bfac09e31c9501d8845f73a Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Fri, 16 Apr 2021 19:15:12 +0200 Subject: [PATCH] Update resume.ts --- src/ws/resume.ts | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/ws/resume.ts b/src/ws/resume.ts index 9e6ae9223..4be26a0ac 100644 --- a/src/ws/resume.ts +++ b/src/ws/resume.ts @@ -1,13 +1,11 @@ import { DiscordGatewayOpcodes } from "../types/codes/gateway_opcodes.ts"; import { closeWS } from "./close_ws.ts"; +import { sendShardMessage } from "./send_shard_message.ts"; import { ws } from "./ws.ts"; export async function resume(shardId: number) { ws.log("RESUMING", { shardId }); - // CREATE A SHARD - const socket = await ws.createShard(shardId); - // NOW WE HANDLE RESUMING THIS SHARD // Get the old data for this shard necessary for resuming const oldShard = ws.shards.get(shardId); @@ -19,6 +17,9 @@ export async function resume(shardId: number) { clearInterval(oldShard.heartbeat.intervalId); } + // CREATE A SHARD + const socket = await ws.createShard(shardId); + const sessionId = oldShard?.sessionId || ""; const previousSequenceNumber = oldShard?.previousSequenceNumber || 0; @@ -47,15 +48,13 @@ export async function resume(shardId: number) { // Resume on open socket.onopen = () => { - ws.shards.get(shardId)?.queue.unshift({ + sendShardMessage(shardId, { op: DiscordGatewayOpcodes.Resume, d: { token: ws.identifyPayload.token, session_id: sessionId, seq: previousSequenceNumber, }, - }); - - ws.processQueue(shardId); + }, true); }; }