L
L
Lekha Yarkov2017-05-18 15:03:51
JavaScript
Lekha Yarkov, 2017-05-18 15:03:51

How to competently design the backend part of the server API using web sockets?

Hello everybody. Friends! Prompt suitable tutorials or give advice. SPA
is being done . Frontend - Vue.js , backend - express + swagger . The theme will be something like a toaster. I want to add the maximum realtime out of the box. Take, for example, tape. How to correctly implement the loading of the tape via websocket, taking into account signed users? That is, on the server, we add a question to MongoDB and do it. But do we still need to filter clients by interests? Here I have a complete plug. There was such an idea: to load a list of tags that the user is subscribed to and cache on the client. And when receiving data from the server, check the tags of the new question and decide on the client whether to draw or not.
socket.emit('new-question', questionData);
Am I approaching the decision correctly or am I again tormenting the bike out of crutches?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Evgeniy Odinets, 2017-05-18
@evgeniy2194

forEach(sockets, function (socket)){
    if(socket.user.questionCategoryId === questionData.categoryId) {
         socket.emit('new-question', questionData);      
    }
}

sockets - array of connected sockets. The socket.user variable can store the user from the database. Iterate over all users and see who needs to send a question and who does not.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question