summary refs log tree commit diff
path: root/webrtc/src/util
diff options
context:
space:
mode:
authorMadeline <46743919+MaddyUnderStars@users.noreply.github.com>2022-03-12 13:10:05 +1100
committerMadeline <46743919+MaddyUnderStars@users.noreply.github.com>2022-03-12 13:10:05 +1100
commit09a33edcbb1ec7bab6734eeb3a98637f9c1e6f7f (patch)
tree0204d76c2153af8735ceb3b05937e48aa0dcf16b /webrtc/src/util
parentMerge branch 'master' into slowcord (diff)
parentAdded preferred_region optional property of VoiceStateUpdateSchema to allow e... (diff)
downloadserver-09a33edcbb1ec7bab6734eeb3a98637f9c1e6f7f.tar.xz
Merge branch 'maddyrtc' into slowcord
Diffstat (limited to '')
-rw-r--r--webrtc/src/util/Heartbeat.ts23
-rw-r--r--webrtc/src/util/index.ts1
2 files changed, 24 insertions, 0 deletions
diff --git a/webrtc/src/util/Heartbeat.ts b/webrtc/src/util/Heartbeat.ts
new file mode 100644

index 00000000..8c5e3a7a --- /dev/null +++ b/webrtc/src/util/Heartbeat.ts
@@ -0,0 +1,23 @@ +import { WebSocket, CLOSECODES } from "@fosscord/gateway"; +import { VoiceOPCodes } from "@fosscord/util"; + +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); + + 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 })); + } +} \ No newline at end of file diff --git a/webrtc/src/util/index.ts b/webrtc/src/util/index.ts new file mode 100644
index 00000000..e8557452 --- /dev/null +++ b/webrtc/src/util/index.ts
@@ -0,0 +1 @@ +export * from "./Heartbeat" \ No newline at end of file