diff options
author | Madeline <46743919+MaddyUnderStars@users.noreply.github.com> | 2022-09-26 22:29:30 +1000 |
---|---|---|
committer | Madeline <46743919+MaddyUnderStars@users.noreply.github.com> | 2022-09-26 22:41:21 +1000 |
commit | dbaf39237ae3a41b6b1ac6a6cd3486129599b815 (patch) | |
tree | 350cca4889d0804445eddbd8467d274b27307776 /src/webrtc/events | |
parent | Remove the cdn storage location log (diff) | |
download | server-dbaf39237ae3a41b6b1ac6a6cd3486129599b815.tar.xz |
Prettier
Diffstat (limited to 'src/webrtc/events')
-rw-r--r-- | src/webrtc/events/Close.ts | 2 | ||||
-rw-r--r-- | src/webrtc/events/Connection.ts | 17 | ||||
-rw-r--r-- | src/webrtc/events/Message.ts | 13 |
3 files changed, 21 insertions, 11 deletions
diff --git a/src/webrtc/events/Close.ts b/src/webrtc/events/Close.ts index 1c203653..4cf80bb2 100644 --- a/src/webrtc/events/Close.ts +++ b/src/webrtc/events/Close.ts @@ -6,4 +6,4 @@ export async function onClose(this: WebSocket, code: number, reason: string) { if (this.session_id) await Session.delete({ session_id: this.session_id }); this.removeAllListeners(); -} \ No newline at end of file +} diff --git a/src/webrtc/events/Connection.ts b/src/webrtc/events/Connection.ts index bf228d64..9300b6b2 100644 --- a/src/webrtc/events/Connection.ts +++ b/src/webrtc/events/Connection.ts @@ -14,7 +14,11 @@ try { // TODO: specify rate limit in config // TODO: check msg max size -export async function Connection(this: WS.Server, socket: WebSocket, request: IncomingMessage) { +export async function Connection( + this: WS.Server, + socket: WebSocket, + request: IncomingMessage, +) { try { socket.on("close", onClose.bind(socket)); socket.on("message", onMessage.bind(socket)); @@ -29,7 +33,7 @@ export async function Connection(this: WS.Server, socket: WebSocket, request: In "open", "ping", "pong", - "unexpected-response" + "unexpected-response", ].forEach((x) => { socket.on(x, (y) => console.log("[WebRTC]", x, y)); }); @@ -39,7 +43,8 @@ export async function Connection(this: WS.Server, socket: WebSocket, request: In socket.encoding = "json"; socket.version = Number(searchParams.get("v")) || 5; - if (socket.version < 3) return socket.close(CLOSECODES.Unknown_error, "invalid version"); + if (socket.version < 3) + return socket.close(CLOSECODES.Unknown_error, "invalid version"); setHeartbeat(socket); @@ -50,11 +55,11 @@ export async function Connection(this: WS.Server, socket: WebSocket, request: In await Send(socket, { op: VoiceOPCodes.HELLO, d: { - heartbeat_interval: 1000 * 30 - } + heartbeat_interval: 1000 * 30, + }, }); } catch (error) { console.error("[WebRTC]", error); return socket.close(CLOSECODES.Unknown_error); } -} \ No newline at end of file +} diff --git a/src/webrtc/events/Message.ts b/src/webrtc/events/Message.ts index 8f75a815..38676f6c 100644 --- a/src/webrtc/events/Message.ts +++ b/src/webrtc/events/Message.ts @@ -7,13 +7,14 @@ const PayloadSchema = { op: Number, $d: new Tuple(Object, Number), // or number for heartbeat sequence $s: Number, - $t: String + $t: String, }; export async function onMessage(this: WebSocket, buffer: Buffer) { try { var data: Payload = JSON.parse(buffer.toString()); - if (data.op !== VoiceOPCodes.IDENTIFY && !this.user_id) return this.close(CLOSECODES.Not_authenticated); + if (data.op !== VoiceOPCodes.IDENTIFY && !this.user_id) + return this.close(CLOSECODES.Not_authenticated); // @ts-ignore const OPCodeHandler = OPCodeHandlers[data.op]; @@ -25,7 +26,11 @@ export async function onMessage(this: WebSocket, buffer: Buffer) { return; } - if (![VoiceOPCodes.HEARTBEAT, VoiceOPCodes.SPEAKING].includes(data.op as VoiceOPCodes)) { + if ( + ![VoiceOPCodes.HEARTBEAT, VoiceOPCodes.SPEAKING].includes( + data.op as VoiceOPCodes, + ) + ) { // @ts-ignore console.log("[WebRTC] Opcode " + VoiceOPCodes[data.op]); } @@ -35,4 +40,4 @@ export async function onMessage(this: WebSocket, buffer: Buffer) { console.error("[WebRTC] error", error); // if (!this.CLOSED && this.CLOSING) return this.close(CloseCodes.Unknown_error); } -} \ No newline at end of file +} |