mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-16 19:28:17 +00:00
i have no idea why i did this
This commit is contained in:
+41
-35
@@ -81,6 +81,7 @@ export async function identify(shardID: number, maxShards: number) {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
socket.onopen = () => {
|
||||||
socket.send(
|
socket.send(
|
||||||
JSON.stringify(
|
JSON.stringify(
|
||||||
{
|
{
|
||||||
@@ -89,6 +90,7 @@ export async function identify(shardID: number, maxShards: number) {
|
|||||||
},
|
},
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
};
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
ws.loadingShards.set(shardID, {
|
ws.loadingShards.set(shardID, {
|
||||||
@@ -151,7 +153,45 @@ export async function createShard(shardID: number) {
|
|||||||
ws.log("ERROR", { shardID, error: errorEvent });
|
ws.log("ERROR", { shardID, error: errorEvent });
|
||||||
};
|
};
|
||||||
|
|
||||||
socket.onmessage = ({ data: message }) => {
|
socket.onmessage = ({ data: message }) => handleOnMessage(message, shardID);
|
||||||
|
|
||||||
|
socket.onclose = (event) => {
|
||||||
|
ws.log("CLOSED", { shardID, payload: event });
|
||||||
|
|
||||||
|
// TODO: ENUM FOR THESE CODES?
|
||||||
|
switch (event.code) {
|
||||||
|
case 4001:
|
||||||
|
case 4002:
|
||||||
|
case 4004:
|
||||||
|
case 4005:
|
||||||
|
case 4010:
|
||||||
|
case 4011:
|
||||||
|
case 4012:
|
||||||
|
case 4013:
|
||||||
|
case 4014:
|
||||||
|
throw new Error(
|
||||||
|
event.reason || "Discord gave no reason! GG! You broke Discord!",
|
||||||
|
);
|
||||||
|
// THESE ERRORS CAN NO BE RESUMED! THEY MUST RE-IDENTIFY!
|
||||||
|
case 4003:
|
||||||
|
case 4007:
|
||||||
|
case 4008:
|
||||||
|
case 4009:
|
||||||
|
ws.log("CLOSED_RECONNECT", { shardID, payload: event });
|
||||||
|
identify(shardID, ws.maxShards);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
resume(shardID);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return socket;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Handler for handling every message event from websocket. */
|
||||||
|
// deno-lint-ignore no-explicit-any
|
||||||
|
export function handleOnMessage(message: any, shardID: number) {
|
||||||
if (message instanceof ArrayBuffer) {
|
if (message instanceof ArrayBuffer) {
|
||||||
message = new Uint8Array(message);
|
message = new Uint8Array(message);
|
||||||
}
|
}
|
||||||
@@ -237,40 +277,6 @@ export async function createShard(shardID: number) {
|
|||||||
ws.handleDiscordPayload(messageData, shardID);
|
ws.handleDiscordPayload(messageData, shardID);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
socket.onclose = (event) => {
|
|
||||||
ws.log("CLOSED", { shardID, payload: event });
|
|
||||||
|
|
||||||
// TODO: ENUM FOR THESE CODES?
|
|
||||||
switch (event.code) {
|
|
||||||
case 4001:
|
|
||||||
case 4002:
|
|
||||||
case 4004:
|
|
||||||
case 4005:
|
|
||||||
case 4010:
|
|
||||||
case 4011:
|
|
||||||
case 4012:
|
|
||||||
case 4013:
|
|
||||||
case 4014:
|
|
||||||
throw new Error(
|
|
||||||
event.reason || "Discord gave no reason! GG! You broke Discord!",
|
|
||||||
);
|
|
||||||
// THESE ERRORS CAN NO BE RESUMED! THEY MUST RE-IDENTIFY!
|
|
||||||
case 4003:
|
|
||||||
case 4007:
|
|
||||||
case 4008:
|
|
||||||
case 4009:
|
|
||||||
ws.log("CLOSED_RECONNECT", { shardID, payload: event });
|
|
||||||
identify(shardID, ws.maxShards);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
resume(shardID);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
return socket;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Handler for processing all dispatch payloads that should be sent/forwarded to another server/vps/process. */
|
/** Handler for processing all dispatch payloads that should be sent/forwarded to another server/vps/process. */
|
||||||
|
|||||||
Reference in New Issue
Block a user