Hi, I’m doing a web socket in a comment view, on server side, what i need to send to the client to load the comments?. I was sending just the json with the data but i get an error
Hello @Dalaz,
I would like to point you to the direction of our guide covering integration with Websockets in detail, which should help you out with your endeavour:
Websocket: Real-time Data Updates for Webix Widgets.
The demo can be found via this link (or at the very top/bottom of the article).
The backend is as simple as possible:
const WebSocket = require('ws');
//live updates for data sample
const wss = new WebSocket.Server({ port:8080 });
wss.on('connection', function connection(ws) {
ws.on('message', function incoming(message) {
// save message to DB
message = _dummySave(message);
// send it to all clients
wss.clients.forEach(function each(client) {
client.send(message);
});
});
});
//emulate saving to db, where record id usually defined
function _dummySave(message){
message = JSON.parse(message);
if (message.operation == "insert"){
message.data.id = "s"+ message.data.id;
}
message = JSON.stringify(message);
return message;
}
For starters, try to implement the logic as described in our guide.