Skip to content

Commit

Permalink
fix: fix broadcasting (#361)
Browse files Browse the repository at this point in the history
`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)
```
  • Loading branch information
tomasvidhall authored Nov 13, 2020
1 parent 2cab2e3 commit 3334d99
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ export class RedisAdapter extends Adapter {
if (!onlyLocal) {
const rawOpts = {
rooms: [...opts.rooms],
except: [...opts.except],
except: [...new Set(opts.except)],
flags: opts.flags,
};
const msg = msgpack.encode([this.uid, packet, rawOpts]);
Expand Down
20 changes: 20 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,26 @@ let socket1, socket2, socket3;
});
});

it("uses a namespace to broadcast to rooms", () => {
socket1.join("woot");
client2.emit("do broadcast");
socket2.on("do broadcast", () => {
namespace2.to("woot").emit("broadcast");
});

client1.on("broadcast", () => {
setTimeout(done, 100);
});

client2.on("broadcast", () => {
throw new Error("Not in room");
});

client3.on("broadcast", () => {
throw new Error("Not in room");
});
});

it("broadcasts to multiple rooms at a time", (done) => {
function test() {
client2.emit("do broadcast");
Expand Down

0 comments on commit 3334d99

Please sign in to comment.