Answer the question
In order to leave comments, you need to log in
How to set Socket.IO handlers in SailsJS on client side in DOM?
After I decided to write a simple to-do list using sockets, I got into the off-docs, from the docks I realized that the binding action occurs according to the principle: a handler is placed in the controller that notifies of all changes in the Model, and it is called subscribe .
Further, on the client side in JS, you can use the functions of the basic suckat socket.io , as well as additional gingerbread of Sails itself, which are described on the same page of the docks, a little resting on the use of this functionality, I looked at stackoverflow - in which I was told to look at the cast on using sockets .
I caught the main point and was able to get my controller to follow the updates using the method specified in the cast
subscribe: function (req, res) {
Task.find(function foundTask (err, tasks) {
if (err) return next(err);
// оповещает когда создается запись
Task.subscribe(req.socket);
// оповещает когда произошло обновление или удаление
Task.subscribe(req.socket, tasks);
});
}
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