Skip to content

Commit

Permalink
refactor: remove the wsPreEncoded option
Browse files Browse the repository at this point in the history
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]: socketio/socket.io-adapter@88eee59
[2]: socketio/socket.io-adapter@5f7b47d
  • Loading branch information
darrachequesne committed Jun 13, 2024
1 parent 8955eb7 commit ef1c4c8
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 22 deletions.
4 changes: 1 addition & 3 deletions lib/transports/websocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
19 changes: 0 additions & 19 deletions test/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit ef1c4c8

Please sign in to comment.