Merge pull request #859 from discordeno/ws-fixxxxxxeessssssss

fix some ws things (better title later when I found and finished fixing stuff)
This commit is contained in:
ITOH
2021-04-14 21:13:13 +02:00
committed by GitHub
4 changed files with 15 additions and 2 deletions

View File

@@ -33,6 +33,7 @@ export async function identify(shardId: number, maxShards: number) {
},
queue: [],
processingQueue: false,
queueStartedAt: Date.now(),
});
socket.onopen = () => {

View File

@@ -16,6 +16,12 @@ export async function processQueue(id: number) {
return;
}
const now = Date.now();
if (now - shard.queueStartedAt >= 60000) {
shard.queueStartedAt = now;
counter = 0;
}
// Send a request that is next in line
const request = shard.queue.shift();

View File

@@ -12,8 +12,11 @@ export async function resume(shardId: number) {
const oldShard = ws.shards.get(shardId);
if (oldShard) {
// HOW TO CLOSE OLD SHARD SOCKET!!!
oldShard.ws.close(3065, "Resuming the shard, closing old shard.");
// ONLY CLOSE IF SHARD SOCKET IS STILL CONNECTED
if (oldShard.ws.readyState === WebSocket.OPEN) {
// HOW TO CLOSE OLD SHARD SOCKET!!!
oldShard.ws.close(3065, "Resuming the shard, closing old shard.");
}
// STOP OLD HEARTBEAT
clearInterval(oldShard.heartbeat.intervalId);
}
@@ -40,6 +43,7 @@ export async function resume(shardId: number) {
},
queue: oldShard?.queue || [],
processingQueue: false,
queueStartedAt: Date.now(),
});
// Resume on open

View File

@@ -145,6 +145,8 @@ export interface DiscordenoShard {
queue: WebSocketRequest[];
/** Whether or not the queue for this shard is being processed. */
processingQueue: boolean;
/** When the first request for this minute has been sent. */
queueStartedAt: number;
}
export interface WebSocketRequest {