Skip to content

Commit

Permalink
fix: fix io.except() method
Browse files Browse the repository at this point in the history
Previously, calling `io.except("theroom").emit(...)` did not exclude
the sockets in the given room.

This method was forgotten in [1].

[1]: ac9e8ca
  • Loading branch information
darrachequesne committed Jul 10, 2021
1 parent a4dffc6 commit 94e27cd
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
7 changes: 2 additions & 5 deletions lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -700,11 +700,8 @@ export class Server<
* @return self
* @public
*/
public except(
name: Room | Room[]
): Server<ListenEvents, EmitEvents, ServerSideEvents> {
this.sockets.except(name);
return this;
public except(name: Room | Room[]): BroadcastOperator<EmitEvents> {
return this.sockets.except(name);
}

/**
Expand Down
21 changes: 21 additions & 0 deletions test/socket.io.ts
Original file line number Diff line number Diff line change
Expand Up @@ -836,6 +836,27 @@ describe("socket.io", () => {
});

it("should exclude a specific socket when emitting", (done) => {
const srv = createServer();
const io = new Server(srv);

srv.listen(() => {
const socket1 = client(srv, "/");
const socket2 = client(srv, "/");

socket2.on("a", () => {
done(new Error("should not happen"));
});
socket1.on("a", () => {
done();
});

socket2.on("connect", () => {
io.except(socket2.id).emit("a");
});
});
});

it("should exclude a specific socket when emitting (in a namespace)", (done) => {
const srv = createServer();
const sio = new Server(srv);

Expand Down

0 comments on commit 94e27cd

Please sign in to comment.