This commit is contained in:
Madeline
2022-03-07 19:15:33 +11:00
parent ce9d7339d3
commit b529a37264
10 changed files with 133 additions and 39 deletions
+13 -8
View File
@@ -1,18 +1,23 @@
import { WebSocket, CLOSECODES } from "@fosscord/gateway";
import { VoiceOPCodes } from "@fosscord/util";
export async function setHeartbeat(socket: WebSocket) {
export async function setHeartbeat(socket: WebSocket, nonce?: Number) {
if (socket.heartbeatTimeout) clearTimeout(socket.heartbeatTimeout);
socket.heartbeatTimeout = setTimeout(() => {
return socket.close(CLOSECODES.Session_timed_out);
}, 1000 * 45);
socket.send(JSON.stringify({
op: VoiceOPCodes.HEARTBEAT_ACK,
d: {
v: 6,
heartbeat_interval: 13750,
}
}));
if (!nonce) {
socket.send(JSON.stringify({
op: VoiceOPCodes.HELLO,
d: {
v: 5,
heartbeat_interval: 13750,
}
}));
}
else {
socket.send(JSON.stringify({ op: VoiceOPCodes.HEARTBEAT_ACK, d: nonce }));
}
}