send & parse JSON in the ws calls; add cb to avoid crash due to unavailable connection

This commit is contained in:
Iuri Matias 2018-02-27 06:34:50 -05:00 committed by Pascal Precht
parent 5de1c6e539
commit 8bf344e4a0
No known key found for this signature in database
GPG Key ID: 0EE28D8D6FD85D7D
2 changed files with 3 additions and 3 deletions

View File

@ -8,7 +8,7 @@ Welcome to Embark!
ws.onmessage = function (evt) {
var received_msg = evt.data;
console.log(received_msg);
console.log(JSON.parse(received_msg));
};
ws.onclose = function() {

View File

@ -69,12 +69,12 @@ class Server {
this.app.ws('/logs', function(ws, req) {
self.events.on("log", function(logLevel, logMsg) {
ws.send(logMsg.stripColors);
ws.send(JSON.stringify({msg: logMsg, msg_clear: logMsg.stripColors, logLevel: logLevel}), () => {});
});
ws.on('message', function(msg) {
console.dir("got message");
console.dir(msg);
ws.send(msg);
ws.send(msg, () => {});
});
});