V
V
vetsmen2017-11-21 14:13:37
JavaScript
vetsmen, 2017-11-21 14:13:37

User information system via socket. How?

I am writing a system for informing clients in real time via a socket server using the following system:
1) The client sends an authorization token to the server in which the user id is encrypted
2) The server receives it and checks the validity of the token
3) Upon successful validation in redis, I enter the pair "id: count". If there is already an entry, I increase count by 1.
4) I create a socket room with the id value and forward the user to it.
As a result, I have a complete list of active connections of authorized users.
Questions:
1) I need to transfer information to the client by his id. To do this, I check if such an id exists, if so, I do an emit to room with the current identifier.
Whether it is adequate each time to do check on existence of record and then only date? Perhaps it would be wiser not to store any pair, just emit to room with the current id, and then the socket will figure it out on its own: if anyone is listening to this room, it will send data, no, it will simply not reach anywhere.
2) Is it safe to work with rooms by id? The user from the client cannot listen to a room while I from the server will not force to listen to it?
3) I use Count if there are 2 or more active connections from one user. When the connection is terminated, I decrease the count by 1. Can it be that the socket disconnect event does not work on the server and the record remains in redis forever?
Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Valeriu, 2017-11-21
@vodniciarv

If the project is not very large, I advise you to use feathersjs.com , there is already everything ready for working with sockets.
that is, if there is an opportunity to switch to the framework - go

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question