mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-16 11:28:15 +00:00
feat(ws/shard): add closeWS() function (#543)
* feat(ws/shard): add closeWS() function
* foolproof reason lol
* feat(ws/shard): handle 3069 close code
* be less verbose 😂
This commit is contained in:
@@ -163,6 +163,8 @@ export function createShard(
|
||||
data: { shardID: basicShard.id, code, reason, wasClean },
|
||||
});
|
||||
createShard(data, identifyPayload, false, shardID);
|
||||
} else if (code === 3069 && reason === "[discordeno] requested closure") {
|
||||
return;
|
||||
} else {
|
||||
basicShard.needToResume = true;
|
||||
await resumeConnection(botGatewayData, identifyPayload, shardID);
|
||||
@@ -407,5 +409,16 @@ export function sendWS(payload: DiscordPayload, shardID = 0) {
|
||||
|
||||
const serialized = JSON.stringify(payload);
|
||||
shard.ws.send(serialized);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/** Closes the WebSocket connection or connection attempt */
|
||||
export function closeWS(shardID = 0) {
|
||||
const shard = basicShards.get(shardID);
|
||||
if (!shard) return false;
|
||||
|
||||
shard.ws.close(3069, "[discordeno] requested closure");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user