Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use server/namespace to broadcast #361

Merged

Conversation

tomasvidhall
Copy link
Contributor

@tomasvidhall tomasvidhall commented Nov 12, 2020

This line in the README suggests that you should be able to use the server to send messages to all clients in a room. When I do that I end up with the stacktrace below error.
io.to('room42').emit('hello', "to all clients in 'room42' room");

Not sure if I have understood how to use the server/namespace correctly, but I found this bug in my app when I wanted to update to socketio v3. In my app I want the server to broadcast a message to a specific room and that triggers the following stacktrace.

TypeError: opts.except is not iterable
  at RedisAdapter.broadcast (/usr/src/node_modules/socket.io-redis/dist/index.js:255:34)
  at Namespace.emit (/usr/src/node_modules/socket.io/dist/namespace.js:175:22)
  at Server.<computed> [as emit] (/usr/src/node_modules/socket.io/dist/index.js:442:33)
  at /usr/src/services/websocket-handler-service/src/events/rooms.js:13:25
  at /usr/src/packages/message-broker/index.js:28:5
  at Array.forEach (<anonymous>)
  at Redis.<anonymous> (/usr/src/packages/message-broker/index.js:27:22)
  at Redis.emit (events.js:315:20)
  at DataHandler.handleSubscriberReply (/usr/src/node_modules/ioredis/built/DataHandler.js:80:32)
  at DataHandler.returnReply (/usr/src/node_modules/ioredis/built/DataHandler.js:47:18)

Please either merge this PR or explain to me how I'm supposed to broadcast a message to a specific room. (tried to do it with client.broadcast.to(roomId), but that doesn't actually send it to everyone in the room. My guess is that it's because the client doesn't actually know what sockets are in the specified room.

@tomasvidhall tomasvidhall changed the title Use namespace to broadcast Use server/namespace to broadcast Nov 13, 2020
@cstrnt
Copy link

cstrnt commented Nov 13, 2020

Having the same problem; The same syntax works without the adapter

@darrachequesne darrachequesne merged commit 3334d99 into socketio:master Nov 13, 2020
@darrachequesne
Copy link
Member

@tomasvidhall arf, thanks a lot 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants