mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-01 00:10:07 +00:00
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:
@@ -33,6 +33,7 @@ export async function identify(shardId: number, maxShards: number) {
|
||||
},
|
||||
queue: [],
|
||||
processingQueue: false,
|
||||
queueStartedAt: Date.now(),
|
||||
});
|
||||
|
||||
socket.onopen = () => {
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user