diff --git a/src/gateway/util/Send.ts b/src/gateway/util/Send.ts
index 9b1eef6a6..cee3aa8c9 100644
--- a/src/gateway/util/Send.ts
+++ b/src/gateway/util/Send.ts
@@ -43,22 +43,20 @@ const recurseJsonReplace = (json: any) => {
return json;
};
-export function Send(socket: WebSocket, data: Payload) {
+export async function Send(socket: WebSocket, data: Payload) {
if (process.env.WS_VERBOSE)
console.log(`[Websocket] Outgoing message: ${JSON.stringify(data)}`);
if (process.env.WS_DUMP) {
const id = socket.session_id || "unknown";
- (async () => {
- await fs.mkdir(path.join("dump", id), {
- recursive: true,
- });
- await fs.writeFile(
- path.join("dump", id, `${Date.now()}.out.json`),
- JSON.stringify(data, null, 2),
- );
- })();
+ await fs.mkdir(path.join("dump", id), {
+ recursive: true,
+ });
+ await fs.writeFile(
+ path.join("dump", id, `${Date.now()}.out.json`),
+ JSON.stringify(data, null, 2),
+ );
}
let buffer: Buffer | string;
@@ -71,9 +69,15 @@ export function Send(socket: WebSocket, data: Payload) {
else if (socket.encoding === "json")
buffer = JSON.stringify(data, JSONReplacer);
else return;
+
// TODO: compression
- if (socket.deflate) {
- buffer = socket.deflate.process(buffer) as Buffer;
+ if (socket.compress === "zlib-stream") {
+ buffer = socket.deflate!.process(buffer) as Buffer;
+ } else if (socket.compress === "zstd-stream") {
+ if (typeof(buffer) === "string")
+ buffer = Buffer.from(buffer as string);
+
+ buffer = await socket.zstdEncoder!.encode(buffer as Buffer) as Buffer;
}
return new Promise((res, rej) => {
|