Reputation: 490
I have simple Socket.IO based chat, and when User1 clicked on User2 at "friends list", User1 will be connected into room with User2 (based on "token" from server). Everything works without problem, when both have opened "chat window" (they are both in room).
But how can I "ping" the User2, when he have chat window closed (he isn't connected into room)?
Thank you for your help!
EDIT:
Okey, now is User1 in room. But User2 is not, because he is not opened window (but he is "online" = connected into server io.connect(...)).
Simplified client JS:
socket = io.connect "...", {port: 1234}
token = ajaxRequestToServerForToken mineID, hisID
socket.emit "joinIntoRoom", token
Simplified node.js code:
//In handler class
joinIntoRoom: (socket, token) ->
socket.leave socket.room
socket.join token
socket.emit "connected"
Upvotes: 0
Views: 1431
Reputation: 19138
Ok, you need a way identify user2 so you can emit an event to him.
This question has a similar answer - does it help?
Once you have a socket object for user2, you can just call
socket.emit('joinIntoRoom', {token: token, message: message})
with the first message, then the client should interpret that.
Upvotes: 0