Answer the question
In order to leave comments, you need to log in
How to sync Socket.io with all devices?
How can Socket.io be synchronized with all devices when a user logs in?
Authorization is based on jwt token.
The assumption is this: since on the client I can only operate with the jwt token itself, it would be reasonable to create a room with such an identifier and emit this token to the server, in which to push it into an object of the form: { userid: { token, timestamp }, userid: { token, timestamp } , ... }
Make a condition to send a ping request over sockets once a minute to check that the user is still on the site and update the timestamp. And in parallel, run setInterval to remove all dead users from whom ping does not come for more than a minute.
Well, if it is necessary to send data to this user, check its existence in this object, if it exists, we send the data to this room.
But there are questions: Is it safe? Are there any restrictions on the length of the room name, because the length of the token is rather big? Is this approach reasonable at all and am I inventing another bicycle that has already been implemented in the form of some convenient library?
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question