user1834809
user1834809

Reputation: 1311

How to map users for chatting?

I am building a new chat application with a real-time communication server. I can send and receive messages from the server. Now I need to map the the users for private real time communication. How can I get it either client side or server side?

I am getting msg from the server as follows:

msg:"blah blah",
participants: [id1,id99],
sessionid: "I need to create unique id for each conversation"(this id is the whole thing to maintain msgs between users), 

use case

  1. I have 100 users
  2. I have to send a message from 1 to 55
  3. Now I need to map 1 and 55
  4. One more 2 to 33
  5. Again I need to map 2 and 33
  6. Similarly I need to map each and every user with other user.

Is there anything wrong in my approach?

Please suggest what the other approaches are for building a multi-user chat application with JavaScript?

Upvotes: 0

Views: 81

Answers (1)

ppoliani
ppoliani

Reputation: 4906

I don't know if i correctly understood your question, but how about introducing the concept of a private conversation at the back-end. Then you can store all the participants of that conversation (in your case i guess there will be only two).

This way you set the server side responsible for all the details needed to make this possible. The clients would only need to pass the message and the id of the private conversation (that will probably be store in a list of private conversations), and leave the server do all the other stuff.

Upvotes: 1

Related Questions