summary refs log tree commit diff
path: root/src/events/Message.ts
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/events/Message.ts15
1 files changed, 7 insertions, 8 deletions
diff --git a/src/events/Message.ts b/src/events/Message.ts

index 6aa62a22..2d461e1d 100644 --- a/src/events/Message.ts +++ b/src/events/Message.ts
@@ -3,6 +3,7 @@ import erlpack from "erlpack"; import OPCodeHandlers from "../opcodes"; import { Payload, CLOSECODES } from "../util/Constants"; import { instanceOf, Tuple } from "lambert-server"; +import { check } from "../opcodes/instanceOf"; const PayloadSchema = { op: Number, @@ -15,14 +16,12 @@ export async function Message(this: WebSocket, buffer: Data) { // TODO: compression var data: Payload; - try { - if (this.encoding === "etf" && buffer instanceof Buffer) data = erlpack.unpack(buffer); - else if (this.encoding === "json" && typeof buffer === "string") data = JSON.parse(buffer); - const result = instanceOf(PayloadSchema, data); - if (result !== true) throw "invalid data"; - } catch (error) { - return this.close(CLOSECODES.Decode_error); - } + if (this.encoding === "etf" && buffer instanceof Buffer) data = erlpack.unpack(buffer); + else if (this.encoding === "json" && typeof buffer === "string") data = JSON.parse(buffer); + + check.call(this, PayloadSchema, data); + + console.log(data); // @ts-ignore const OPCodeHandler = OPCodeHandlers[data.op];