[Fixed]-Django, socket.io, node.js โ€“ Manage private messages and group conversations

3๐Ÿ‘

โœ…

  1. Private messages

Node keeps track of which sockets that are currently connected with an array of socket ids keyed with some user identifier.

You pretty much said it there. Django does not need to know the socket id of the target user, but node.js does. If you want to send a message to user 3 you would sent to message + target user (or any other meta data you want) to redis. Node.js will look up the user by reading the element with the id 3 from the socket array and send the message to this connection. If there is no element with id = 3, the user is offline and you can send your push notification. Eather in node.js or by notifying the django server.

  1. Rooms

Since you want your rooms to be persistant you should store them in some kind of database like mysql or mongodb. The node.js server would create all the rooms and if a user connects you can look up in which rooms they participated using their user id. If they join a new room you have to update the database. If a new room is created, node.js needs to create the socket.io room and the database needs to be updated as well.

๐Ÿ‘คMartin

Leave a comment