Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/socket.io-client/lib/socket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,7 @@ export class Socket<
args,
flags: Object.assign({ fromQueue: true }, this.flags),
};
this.flags = {};

args.push((err, ...responseArgs) => {
if (packet !== this._queue[0]) {
Expand Down
54 changes: 54 additions & 0 deletions packages/socket.io-client/test/retry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,4 +146,58 @@ describe("retry", () => {
}, 100);
});
});

it("should not apply the flags of a queued packet to the next one", () => {
return wrap((done) => {
const socket = io(BASE_URL, {
forceNew: true,
retries: 3,
ackTimeout: 50,
});

const compressFlags: boolean[] = [];

socket.io.engine.on("packetCreate", ({ type, data, options }) => {
if (type === "message" && data.startsWith("2")) {
compressFlags.push(options.compress);
}
});

// the socket is not connected yet, so both packets are queued
socket.compress(false).emit("echo", 1);
socket.emit("echo", 2, () => {
expect(compressFlags).to.eql([false, true]);

success(done, socket);
});
});
});

it("should not apply the flags of a pending packet to the next one", () => {
return wrap((done) => {
const socket = io(BASE_URL, {
forceNew: true,
retries: 3,
ackTimeout: 50,
});

const compressFlags: boolean[] = [];

socket.io.engine.on("packetCreate", ({ type, data, options }) => {
if (type === "message" && data.startsWith("2")) {
compressFlags.push(options.compress);
}
});

socket.on("connect", () => {
socket.emit("echo", 1);
socket.compress(false).emit("echo", 2);
socket.emit("echo", 3, () => {
expect(compressFlags).to.eql([true, false, true]);

success(done, socket);
});
});
});
});
});
Loading