make erlpack optional

This commit is contained in:
Flam3rboy 2021-04-25 21:18:21 +02:00
parent 0da86386d0
commit 3427672659
4 changed files with 18 additions and 7 deletions

View File

@ -15,7 +15,6 @@
"dependencies": { "dependencies": {
"@fosscord/server-util": "^1.0.7", "@fosscord/server-util": "^1.0.7",
"dotenv": "^8.2.0", "dotenv": "^8.2.0",
"erlpack": "^0.1.3",
"jsonwebtoken": "^8.5.1", "jsonwebtoken": "^8.5.1",
"lambert-server": "^1.1.7", "lambert-server": "^1.1.7",
"missing-native-js-functions": "^1.2.3", "missing-native-js-functions": "^1.2.3",
@ -29,6 +28,7 @@
"@types/jsonwebtoken": "^8.5.0", "@types/jsonwebtoken": "^8.5.0",
"@types/mongoose-autopopulate": "^0.10.1", "@types/mongoose-autopopulate": "^0.10.1",
"@types/uuid": "^8.3.0", "@types/uuid": "^8.3.0",
"@types/ws": "^7.4.0" "@types/ws": "^7.4.0",
"erlpack": "^0.1.3"
} }
} }

View File

@ -6,6 +6,10 @@ 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 { createDeflate } from "zlib"; import { createDeflate } from "zlib";
var erlpack: any;
try {
erlpack = require("erlpack");
} catch (error) {}
// TODO: check rate limit // TODO: check rate limit
// TODO: specify rate limit in config // TODO: specify rate limit in config
@ -19,7 +23,10 @@ export async function Connection(this: Server, socket: WebSocket, request: Incom
const { searchParams } = new URL(`http://localhost${request.url}`); const { searchParams } = new URL(`http://localhost${request.url}`);
// @ts-ignore // @ts-ignore
socket.encoding = searchParams.get("encoding") || "json"; socket.encoding = searchParams.get("encoding") || "json";
if (!["json", "etf"].includes(socket.encoding)) return socket.close(CLOSECODES.Decode_error); if (!["json", "etf"].includes(socket.encoding)) {
if (socket.encoding === "etf" && erlpack) throw new Error("Erlpack is not installed: 'npm i -D erlpack'");
return socket.close(CLOSECODES.Decode_error);
}
// @ts-ignore // @ts-ignore
socket.version = Number(searchParams.get("version")) || 8; socket.version = Number(searchParams.get("version")) || 8;

View File

@ -1,5 +1,8 @@
import WebSocket, { Data } from "../util/WebSocket"; import WebSocket, { Data } from "../util/WebSocket";
import erlpack from "erlpack"; var erlpack: any;
try {
erlpack = require("erlpack");
} catch (error) {}
import OPCodeHandlers from "../opcodes"; import OPCodeHandlers from "../opcodes";
import { Payload, CLOSECODES } from "../util/Constants"; import { Payload, CLOSECODES } from "../util/Constants";
import { instanceOf, Tuple } from "lambert-server"; import { instanceOf, Tuple } from "lambert-server";

View File

@ -1,7 +1,8 @@
import erlpack from "erlpack"; var erlpack: any;
import { promisify } from "util"; try {
erlpack = require("erlpack");
} catch (error) {}
import { Payload } from "../util/Constants"; import { Payload } from "../util/Constants";
import { deflateSync } from "zlib";
import WebSocket from "./WebSocket"; import WebSocket from "./WebSocket";