Join other sockets to a dynamic room in multi instance
See original GitHub issueHi, 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:
- Created 9 years ago
- Comments:8
Top GitHub Comments
I dont suppose you have some code to share?
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!