summary refs log tree commit diff
path: root/webrtc/src/util
diff options
context:
space:
mode:
authorMadeline <46743919+MaddyUnderStars@users.noreply.github.com>2022-01-16 02:37:38 +1100
committerMadeline <46743919+MaddyUnderStars@users.noreply.github.com>2022-01-16 02:38:43 +1100
commit1569fec0cf23442b176b2a9a775208349aa719ed (patch)
treef36aff30a3d5e82f569fa7815c83a33a3066c7d3 /webrtc/src/util
parentFix typo in commit 277b28c (diff)
downloadserver-1569fec0cf23442b176b2a9a775208349aa719ed.tar.xz
boilerplate stuff
Diffstat (limited to '')
-rw-r--r--webrtc/src/util/Heartbeat.ts18
-rw-r--r--webrtc/src/util/index.ts1
2 files changed, 19 insertions, 0 deletions
diff --git a/webrtc/src/util/Heartbeat.ts b/webrtc/src/util/Heartbeat.ts
new file mode 100644

index 00000000..7b5ed9cd --- /dev/null +++ b/webrtc/src/util/Heartbeat.ts
@@ -0,0 +1,18 @@ +import { WebSocket, CLOSECODES } from "@fosscord/gateway"; +import { VoiceOPCodes } from "@fosscord/util"; + +export async function setHeartbeat(socket: WebSocket) { + 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, + } + })); +} \ 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