-1

Friends I am going to plan an application like skype. I have few concerns of multiple rooms on one socket connection.

Suppose I have 200 friends online. In phoenix socket when a person joins a room he will be able send and recieve all message (send by other users in a same room)

My question is in this scnaioro .

  • I am chatting with my Friend "A"

  • "Myself" and "A" both joins a room "1" , we both are sending and receiving messages successfully.

  • My other friend "B" sends me a message, I have not join room:2 yet. I won't going to receive alert and notification from "B".

  • My question is that what should I do. Should I join multiple rooms at the same time according to list of my online friends ? in this case alot of room will be joined by myself and other friends. is there any performance issue.Because maybe my online friends count may b more than 200 to 400. and also when any friend become online or offline, I also need myself to join and leave rooms continuously.

  • Another scenario is, I should keep only one room with the name of chat. I should write a SubChaneel Module which contains my logic. each message will be broadcast with subchannel param. My javascript and ui will control that which message belongs to which user's (friend's) room. Active chat (Friend) will be appended and not active (online) user will be also append in their hidden ui element.

Ali Abbas
  • 498
  • 7
  • 20

1 Answers1

0

I have answered very similar questions How to keep a user subscribed to every chat and Phoenix Channels - Multiple channels per socket. In summary, I would have a user channel and a room/channel for each open chat session. Use the chat channels to broadcast messages and the user channel to push updates to each channel for the part of the UI that tracks current subscriptions.

In my chat app, if someone @mentions someone not subscribed in that room, I automatically create a subscription for that person and add it to the list of their subscriptions on the UI.

I don't push messages for a room if the user does not have a chat session open. However, I do push alerts (for @at mentions and direct messages) and unread message notifications through the user channel.

My application has a single chat window layout (similar to Slack). Right now, if someone switches between a couple windows, I reload the messages each time. However, it takes a couple seconds to load the room each time. I'm going modify my design so that when a user changes room, I save the old room in the client. This way I can just reload the room in the client without having to go back out to the server. However, I will then need to keep multiple room channels open and handle incoming messages for the rooms that are not open to active chat.

Community
  • 1
  • 1
Steve Pallen
  • 4,417
  • 16
  • 33