mirror of
https://github.com/socketio/socket.io.git
synced 2026-01-10 07:28:06 -05:00
fix(sio-client): allow to manually stop the reconnection loop
```js
socket.io.on("reconnect_attempt", () => {
socket.io.reconnection(false); // will now work properly
});
```
Related: https://github.com/socketio/socket.io/issues/5126
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user