Skip to content

Commit

Permalink
fix(sio-client): allow to manually stop the reconnection loop
Browse files Browse the repository at this point in the history
  • Loading branch information
darrachequesne committed Sep 18, 2024
1 parent 60c757f commit 4088fb7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
3 changes: 3 additions & 0 deletions packages/socket.io-client/lib/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,9 @@ export class Manager<
public reconnection(v?: boolean): this | boolean {
if (!arguments.length) return this._reconnection;
this._reconnection = !!v;
if (!v) {
this.skipReconnect = true;
}
return this;
}

Expand Down
22 changes: 22 additions & 0 deletions packages/socket.io-client/test/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,28 @@ describe("connection", () => {
});
});

it("should stop trying to reconnect", () => {
return wrap((done) => {
const manager = new Manager("http://localhost:9823", {
reconnectionDelay: 10,
});

manager.on("reconnect_error", () => {
// disable current reconnection loop
manager.reconnection(false);

manager.on("reconnect_attempt", () => {
done(new Error("should not happen"));
});

setTimeout(() => {
manager._close();
done();
}, 100);
});
});
});

// Ignore incorrect connection test for old IE due to no support for
// `script.onerror` (see: http://requirejs.org/docs/api.html#ieloadfail)
if (!global.document || hasCORS) {
Expand Down

0 comments on commit 4088fb7

Please sign in to comment.