Skip to content

Commit 94e27cd

Browse files
committedJul 10, 2021
fix: fix io.except() method
Previously, calling `io.except("theroom").emit(...)` did not exclude the sockets in the given room. This method was forgotten in [1]. [1]: ac9e8ca
1 parent a4dffc6 commit 94e27cd

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed
 

‎lib/index.ts

+2-5
Original file line numberDiff line numberDiff line change
@@ -700,11 +700,8 @@ export class Server<
700700
* @return self
701701
* @public
702702
*/
703-
public except(
704-
name: Room | Room[]
705-
): Server<ListenEvents, EmitEvents, ServerSideEvents> {
706-
this.sockets.except(name);
707-
return this;
703+
public except(name: Room | Room[]): BroadcastOperator<EmitEvents> {
704+
return this.sockets.except(name);
708705
}
709706

710707
/**

‎test/socket.io.ts

+21
Original file line numberDiff line numberDiff line change
@@ -836,6 +836,27 @@ describe("socket.io", () => {
836836
});
837837

838838
it("should exclude a specific socket when emitting", (done) => {
839+
const srv = createServer();
840+
const io = new Server(srv);
841+
842+
srv.listen(() => {
843+
const socket1 = client(srv, "/");
844+
const socket2 = client(srv, "/");
845+
846+
socket2.on("a", () => {
847+
done(new Error("should not happen"));
848+
});
849+
socket1.on("a", () => {
850+
done();
851+
});
852+
853+
socket2.on("connect", () => {
854+
io.except(socket2.id).emit("a");
855+
});
856+
});
857+
});
858+
859+
it("should exclude a specific socket when emitting (in a namespace)", (done) => {
839860
const srv = createServer();
840861
const sio = new Server(srv);
841862

0 commit comments

Comments
 (0)
Please sign in to comment.