diff --git a/src/gateway/events/Message.ts b/src/gateway/events/Message.ts
index 8bd1adda..043b7376 100644
--- a/src/gateway/events/Message.ts
+++ b/src/gateway/events/Message.ts
@@ -17,7 +17,8 @@
*/
import { CLOSECODES, Payload, WebSocket } from "@spacebar/gateway";
-import { ErlpackType } from "@spacebar/util";
+// import { ErlpackType } from "@spacebar/util";
+import * as erlpack from "harmony-erlpack";
import fs from "node:fs/promises";
import BigIntJson from "json-bigint";
import path from "node:path";
@@ -28,12 +29,12 @@ import { PayloadSchema } from "@spacebar/schemas";
const bigIntJson = BigIntJson({ storeAsString: true });
-let erlpack: ErlpackType | null = null;
-try {
- erlpack = require("@yukikaze-bot/erlpack") as ErlpackType;
-} catch (e) {
- console.log("Failed to import @yukikaze-bot/erlpack: ", e);
-}
+// let erlpack: ErlpackType | null = null;
+// try {
+// erlpack = require("@yukikaze-bot/erlpack") as ErlpackType;
+// } catch (e) {
+// console.log("Failed to import @yukikaze-bot/erlpack: ", e);
+// }
export async function Message(this: WebSocket, buffer: WS.Data) {
// TODO: compression
@@ -61,7 +62,8 @@ export async function Message(this: WebSocket, buffer: WS.Data) {
data = bigIntJson.parse(buffer as string);
} else if (this.encoding === "etf" && Buffer.isBuffer(buffer) && erlpack) {
try {
- data = erlpack.unpack(buffer);
+ // cast is ~safe: unpack returns the parsed data in the shape it was provided, @yukikaze-bot/erlpack got around this by returning `any` instead of an actual type union.
+ data = erlpack.unpack(buffer.buffer.slice(buffer.byteOffset, buffer.byteOffset + buffer.byteLength)) as unknown as Payload;
} catch {
console.error(`[Gateway/${this.user_id ?? this.ipAddress}] Failed to decode ETF payload`);
return this.close(CLOSECODES.Decode_error);
diff --git a/src/gateway/util/Send.ts b/src/gateway/util/Send.ts
index 00fd4b45..6a9c639d 100644
--- a/src/gateway/util/Send.ts
+++ b/src/gateway/util/Send.ts
@@ -21,12 +21,14 @@ import fs from "node:fs/promises";
import path from "node:path";
import { ErlpackType, JSONReplacer } from "@spacebar/util";
-let erlpack: ErlpackType | null = null;
-try {
- erlpack = require("@yukikaze-bot/erlpack") as ErlpackType;
-} catch (e) {
- console.log("Failed to import @yukikaze-bot/erlpack: ", e);
-}
+import * as erlpack from "harmony-erlpack";
+
+// let erlpack: ErlpackType | null = null;
+// try {
+// erlpack = require("@yukikaze-bot/erlpack") as ErlpackType;
+// } catch (e) {
+// console.log("Failed to import @yukikaze-bot/erlpack: ", e);
+// }
// don't care
// eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -58,7 +60,7 @@ export async function Send(socket: WebSocket, data: Payload) {
if (socket.encoding === "etf" && erlpack) {
// Erlpack doesn't like Date objects, encodes them as {}
data = recurseJsonReplace(data);
- buffer = erlpack.pack(data);
+ buffer = Buffer.from(erlpack.pack(data));
}
// TODO: encode circular object
else if (socket.encoding === "json") buffer = JSON.stringify(data, JSONReplacer);
|