user938363
user938363

Reputation: 10350

Updates user with new message in chat app

I am writing a chat app (react native) with socket.io. A chat user belongs to a room and there are many users in one room. Most of time there are a few to a few dozens users in one room. When there is a new chat message is posted for a room to the server, The chat message can be socketed to users in one room or, a short and standard message is socketed to users in the room asking them to pull and update from the sever. The third way I can think of is to push the message to the users (need a push notification support. Let's say it is available). I am not sure what are the pros and cons with those update methods. Is there other ways to update besides to the above 3?

Upvotes: 0

Views: 380

Answers (1)

Keith Dawson
Keith Dawson

Reputation: 1495

I literally just created an in-production application using React and Socket.io for pushing messages to the users in a specific room when a user sends a message to a specific conversation. I did not use push notifications because I was building a web app rather than a mobile app, but your mention about the push notifications is the logical mobile equivalent of sending the message information directly to all users in a room. As far as I had considered the available options in my situation, I think that you have covered all of your available options above.

That being said, as you mentioned, there are pros and cons to both approaches (sending the whole message directly to all users or send a small notification to all users to retrieve all latest messages). The pro for the former would be that the message is just sent to all of the users straight away so they will receive it much faster than the latter scenario. But if you are using Socket.io in such a way that, for instance, you are sending messages to all users in a volatile fashion, the con for the former scenario would be that the client users may not receive the message due to a network hiccup and that message that was sent would not appear in their conversation messages. Also, sending all of the message information directly does not give the client application control over when to receive ALL of the message data. On the flip side, the pro for the latter scenario would be that only a small message would be sent to all users in a conversation, thereby saving on transmitted data size, and then those users could query for the latest messages at their leisure as the client application deems appropriate. The con in this case would be that the actual sent message would not get to the client applications immediately, thereby adding some amount of delay between message sending and receiving. But of course such a thing would be hard to notice without having two client applications open on two separate devices side by side and someone watching with a stopwatch to check the latency time.

In summary, I believe that you have listed all of your options above. It now comes down to which scenario you feel is appropriate to implement for your application situation based on the pros and cons of those scenarios.

Upvotes: 1

Related Questions