diff --git a/lib/index.ts b/lib/index.ts index 6f9f882ad6..c7b04d03cd 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -700,11 +700,8 @@ export class Server< * @return self * @public */ - public except( - name: Room | Room[] - ): Server { - this.sockets.except(name); - return this; + public except(name: Room | Room[]): BroadcastOperator { + return this.sockets.except(name); } /** diff --git a/test/socket.io.ts b/test/socket.io.ts index 87c36693fb..7860405a88 100644 --- a/test/socket.io.ts +++ b/test/socket.io.ts @@ -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);