🐛 fix hearbeat gateway

This commit is contained in:
Flam3rboy
2021-04-06 14:15:13 +02:00
parent 509394b592
commit 7279df5efb
6 changed files with 21 additions and 21 deletions
+7 -8
View File
@@ -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];