summary refs log tree commit diff
path: root/src/gateway/util
diff options
context:
space:
mode:
authorMadeline <46743919+MaddyUnderStars@users.noreply.github.com>2023-02-01 13:00:04 +1100
committerGitHub <noreply@github.com>2023-02-01 13:00:04 +1100
commitda2086696784f4d4d82eb853630e4d94662661dd (patch)
treec8bf2c3b587844f7993d76db555d70f2dbfa0d2b /src/gateway/util
parentuse print instead of console.log in client cache so it doesn't output weirdness (diff)
downloadserver-da2086696784f4d4d82eb853630e4d94662661dd.tar.xz
Use erlpack instead of @yukikaze-bot/erlpack (#968)
Diffstat (limited to 'src/gateway/util')
-rw-r--r--src/gateway/util/Send.ts18
1 files changed, 9 insertions, 9 deletions
diff --git a/src/gateway/util/Send.ts b/src/gateway/util/Send.ts
index a89d92d7..38e5ab4a 100644
--- a/src/gateway/util/Send.ts
+++ b/src/gateway/util/Send.ts
@@ -16,18 +16,18 @@
 	along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */
 
-let erlpack: { pack: (data: Payload) => Buffer };
-try {
-	erlpack = require("@yukikaze-bot/erlpack");
-} catch (error) {
-	console.log(
-		"Missing @yukikaze-bot/erlpack, electron-based desktop clients designed for discord.com will not be able to connect!",
-	);
-}
 import { Payload, WebSocket } from "@fosscord/gateway";
 import fs from "fs/promises";
 import path from "path";
 
+import type { ErlpackType } from "@fosscord/util";
+let erlpack: ErlpackType | null = null;
+try {
+	erlpack = require("erlpack") as ErlpackType;
+} catch (e) {
+	// empty
+}
+
 export function Send(socket: WebSocket, data: Payload) {
 	if (process.env.WS_VERBOSE)
 		console.log(`[Websocket] Outgoing message: ${JSON.stringify(data)}`);
@@ -47,7 +47,7 @@ export function Send(socket: WebSocket, data: Payload) {
 	}
 
 	let buffer: Buffer | string;
-	if (socket.encoding === "etf") buffer = erlpack.pack(data);
+	if (socket.encoding === "etf" && erlpack) buffer = erlpack.pack(data);
 	// TODO: encode circular object
 	else if (socket.encoding === "json") buffer = JSON.stringify(data);
 	else return;