Skip to content

Commit

Permalink
fix: ensure manager.socket() returns an active socket
Browse files Browse the repository at this point in the history
Related: #1460
  • Loading branch information
darrachequesne committed Feb 3, 2023
1 parent 655dce9 commit b7dd891
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,10 @@ export class Manager<
this.nsps[nsp] = socket;
}

if (this._autoConnect) {
socket.connect();
}

return socket;
}

Expand Down
24 changes: 24 additions & 0 deletions test/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -814,4 +814,28 @@ describe("connection", () => {
});
});
}

it("should reopen a cached socket", () => {
return wrap((done) => {
const manager = new Manager(BASE_URL, {
autoConnect: true,
});
const socket = manager.socket("/");
socket.on("connect", () => {
socket.disconnect();
});

socket.on("disconnect", () => {
const socket2 = manager.socket("/");

expect(socket2 === socket).to.be(true);
expect(socket2.active).to.be(true);

socket2.on("connect", () => {
socket2.disconnect();
done();
});
});
});
});
});

0 comments on commit b7dd891

Please sign in to comment.