diff options
Diffstat (limited to 'src/gateway/util')
-rw-r--r-- | src/gateway/util/Send.ts | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/gateway/util/Send.ts b/src/gateway/util/Send.ts index 1c0f33c3..c31233c8 100644 --- a/src/gateway/util/Send.ts +++ b/src/gateway/util/Send.ts @@ -7,8 +7,27 @@ try { ); } import { Payload, WebSocket } from "@fosscord/gateway"; +import fs from "fs/promises"; +import path from "path"; export 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), + ); + })(); + } + let buffer: Buffer | string; if (socket.encoding === "etf") buffer = erlpack.pack(data); // TODO: encode circular object |