Skip to content

Commit 3334d99

Browse files
authored
fix: fix broadcasting (#361)
`except` is undefined when using the namespace to broadcast. This should fix the following error in the latest release: ``` TypeError: opts.except is not iterable at RedisAdapter.broadcast (.../node_modules/socket.io-redis/dist/index.js:255:34) at Namespace.emit (.../node_modules/socket.io/dist/namespace.js:175:22) at Server.<computed> [as emit] (.../node_modules/socket.io/dist/index.js:442:33) ```
1 parent 2cab2e3 commit 3334d99

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

lib/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ export class RedisAdapter extends Adapter {
346346
if (!onlyLocal) {
347347
const rawOpts = {
348348
rooms: [...opts.rooms],
349-
except: [...opts.except],
349+
except: [...new Set(opts.except)],
350350
flags: opts.flags,
351351
};
352352
const msg = msgpack.encode([this.uid, packet, rawOpts]);

test/index.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,26 @@ let socket1, socket2, socket3;
6565
});
6666
});
6767

68+
it("uses a namespace to broadcast to rooms", () => {
69+
socket1.join("woot");
70+
client2.emit("do broadcast");
71+
socket2.on("do broadcast", () => {
72+
namespace2.to("woot").emit("broadcast");
73+
});
74+
75+
client1.on("broadcast", () => {
76+
setTimeout(done, 100);
77+
});
78+
79+
client2.on("broadcast", () => {
80+
throw new Error("Not in room");
81+
});
82+
83+
client3.on("broadcast", () => {
84+
throw new Error("Not in room");
85+
});
86+
});
87+
6888
it("broadcasts to multiple rooms at a time", (done) => {
6989
function test() {
7090
client2.emit("do broadcast");

0 commit comments

Comments
 (0)