Prettier
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user