question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Join other sockets to a dynamic room in multi instance

See original GitHub issue

Hi, new to socket.io here. I find it very easy to build simple chat app following tutorial, but having difficulties as I progress to build more complex features.

I want to create a group chat app like whatsapp or facebook messenger. I can do this with room feature and broadcasting messages to the room when all users are connected and joined to the same room. Where I’m stuck is when I start a new group chat.

Suppose, A wants to create a new group chat with B and C. So A starts with a message like this. (assume B, C are also connected to socket.io server)

{ 
  id: 'groupchat-123', // randomly generated id
  receipients: ['B', 'C'],
  message: 'Hey',
  sender: 'A'
}

The outcome I want is, B & C receives this message on the client with no user interaction.

On server side, A will do socket.join(‘groupchat-123’). But B, and C haven’t join to the same room yet, hence broadcasting won’t do anything to B and C. How do I make B and C join the room before broadcasting? How’d I achieve this if I have multiple node instances?

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:8

github_iconTop GitHub Comments

3reactions
sibe7691commented, May 31, 2015

I dont suppose you have some code to share?

1reaction
arthurparkcommented, Mar 16, 2015

Got it. So I’ve made it work by creating predefined channel(“join”) from server and let subClient to subscribe to that channel. Then I’m publishing to that channel(“join”) when I need to force other sockets to join a specific room. Thanks for your help!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Join multiple rooms at once Socket.io - Stack Overflow
I have an application where a user can get a list of chat rooms they are in, they can then click ...
Read more >
Rooms | Socket.IO
A room is an arbitrary channel that sockets can join and leave. It can be used to broadcast events to a subset of...
Read more >
Angular 7 + Socket IO using multiple namespaces & dynamic ...
Now lets implement SocketIO with another namespace and dynamic rooms. This will be shown by taking forward the above directors-movies example.
Read more >
How to pass a single Web Socket instance across all ... - Reddit
I want that to connect to different dynamic namespaces and pass that single ... namespaces/room without creating multiple socket instances.
Read more >
Socket IO Rooms Tutorial (Backend part 1) - YouTube
In this video I demonstrate the usage of socket io rooms. Socket io rooms, allows us to create separate channels which sockets can...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found