setup listeners
This commit is contained in:
parent
caafbc606c
commit
3f8c652d68
@ -5,7 +5,6 @@ import { Message } from "./Message";
|
|||||||
import { setHeartbeat } from "../util/setHeartbeat";
|
import { setHeartbeat } from "../util/setHeartbeat";
|
||||||
import { Send } from "../util/Send";
|
import { Send } from "../util/Send";
|
||||||
import { CLOSECODES, OPCODES } from "../util/Constants";
|
import { CLOSECODES, OPCODES } from "../util/Constants";
|
||||||
import { setupListener } from "../listener/listener";
|
|
||||||
|
|
||||||
// TODO: check rate limit
|
// TODO: check rate limit
|
||||||
// TODO: specify rate limit in config
|
// TODO: specify rate limit in config
|
||||||
@ -37,8 +36,6 @@ export async function Connection(this: Server, socket: WebSocket, request: Incom
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
await setupListener.call(socket);
|
|
||||||
|
|
||||||
socket.readyTimeout = setTimeout(() => {
|
socket.readyTimeout = setTimeout(() => {
|
||||||
return socket.close(CLOSECODES.Session_timed_out);
|
return socket.close(CLOSECODES.Session_timed_out);
|
||||||
}, 1000 * 30);
|
}, 1000 * 30);
|
||||||
|
@ -18,7 +18,8 @@ export async function Message(this: WebSocket, buffer: Data) {
|
|||||||
try {
|
try {
|
||||||
if (this.encoding === "etf" && buffer instanceof Buffer) data = erlpack.unpack(buffer);
|
if (this.encoding === "etf" && buffer instanceof Buffer) data = erlpack.unpack(buffer);
|
||||||
else if (this.encoding === "json" && typeof buffer === "string") data = JSON.parse(buffer);
|
else if (this.encoding === "json" && typeof buffer === "string") data = JSON.parse(buffer);
|
||||||
if (!instanceOf(PayloadSchema, data)) throw "invalid data";
|
const result = instanceOf(PayloadSchema, data);
|
||||||
|
if (result !== true) throw "invalid data";
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return this.close(CLOSECODES.Decode_error);
|
return this.close(CLOSECODES.Decode_error);
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { Payload } from "../util/Constants";
|
import { CLOSECODES, Payload } from "../util/Constants";
|
||||||
import { Send } from "../util/Send";
|
import { Send } from "../util/Send";
|
||||||
import { setHeartbeat } from "../util/setHeartbeat";
|
import { setHeartbeat } from "../util/setHeartbeat";
|
||||||
import WebSocket from "../util/WebSocket";
|
import WebSocket from "../util/WebSocket";
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
import { Payload } from "../util/Constants";
|
import { CLOSECODES, Payload } from "../util/Constants";
|
||||||
import WebSocket from "../util/WebSocket";
|
import WebSocket from "../util/WebSocket";
|
||||||
|
|
||||||
export function onPresenceUpdate(this: WebSocket, data: Payload) {}
|
export function onPresenceUpdate(this: WebSocket, data: Payload) {
|
||||||
|
return this.close(CLOSECODES.Unknown_error);
|
||||||
|
}
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
import { Payload } from "../util/Constants";
|
import { CLOSECODES, Payload } from "../util/Constants";
|
||||||
|
|
||||||
import WebSocket from "../util/WebSocket";
|
import WebSocket from "../util/WebSocket";
|
||||||
|
|
||||||
export function onRequestGuildMembers(this: WebSocket, data: Payload) {}
|
export function onRequestGuildMembers(this: WebSocket, data: Payload) {
|
||||||
|
return this.close(CLOSECODES.Unknown_error);
|
||||||
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { Payload } from "../util/Constants";
|
import { CLOSECODES, Payload } from "../util/Constants";
|
||||||
|
|
||||||
import WebSocket from "../util/WebSocket";
|
import WebSocket from "../util/WebSocket";
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { Payload } from "../util/Constants";
|
import { CLOSECODES, Payload } from "../util/Constants";
|
||||||
|
|
||||||
import WebSocket from "../util/WebSocket";
|
import WebSocket from "../util/WebSocket";
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user