V
V
vetsmen2019-08-29 02:43:33
JavaScript
vetsmen, 2019-08-29 02:43:33

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

1 answer(s)
V
Vitaly, 2019-08-30
@vshvydky

as soon as the client falls off, its client connection will be completed and the corresponding event will work
ping pong socket io does without your help
about all sorts of network intervals straight smiled, do you happen to have your server leak from memory?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question