From ef1c4c8bb771f007f3db3131af59f2027ccb181c Mon Sep 17 00:00:00 2001 From: Damien Arrachequesne Date: Thu, 13 Jun 2024 23:55:16 +0200 Subject: [PATCH] refactor: remove the wsPreEncoded option The wsPreEncoded option was added in the `socket.io-adapter` package when broadcasting a message to multiple clients. It was removed in [1] and is now superseded by the `wsPreEncodedFrame` option, which directly computes the WebSocket frame once for all clients (see [2]). [1]: https://github.com/socketio/socket.io-adapter/commit/88eee5948aba94f999405239025f29c754a002e2 [2]: https://github.com/socketio/socket.io-adapter/commit/5f7b47d40f9daabe4e3c321eda620bbadfe5ce96 --- lib/transports/websocket.ts | 4 +--- test/server.js | 19 ------------------- 2 files changed, 1 insertion(+), 22 deletions(-) diff --git a/lib/transports/websocket.ts b/lib/transports/websocket.ts index 1f98fb7d..83d4de57 100644 --- a/lib/transports/websocket.ts +++ b/lib/transports/websocket.ts @@ -85,9 +85,7 @@ export class WebSocket extends Transport { this.socket.send(data, opts, onSent); }; - if (packet.options && typeof packet.options.wsPreEncoded === "string") { - send(packet.options.wsPreEncoded); - } else if (this._canSendPreEncodedFrame(packet)) { + if (this._canSendPreEncodedFrame(packet)) { // the WebSocket frame was computed with WebSocket.Sender.frame() // see https://github.com/websockets/ws/issues/617#issuecomment-283002469 this.socket._sender.sendFrame(packet.options.wsPreEncodedFrame, onSent); diff --git a/test/server.js b/test/server.js index d0301308..cacb6774 100644 --- a/test/server.js +++ b/test/server.js @@ -2889,25 +2889,6 @@ describe("server", () => { }); describe("pre-encoded content", () => { - it("should use the pre-encoded content", (done) => { - engine = listen((port) => { - client = new ClientSocket(`ws://localhost:${port}`, { - transports: ["websocket"], - }); - - engine.on("connection", (conn) => { - conn.send("test", { - wsPreEncoded: "4test pre-encoded", - }); - }); - - client.on("message", (msg) => { - expect(msg).to.be("test pre-encoded"); - done(); - }); - }); - }); - it("should use the pre-encoded frame", function (done) { if (process.env.EIO_WS_ENGINE === "uws") { return this.skip();