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
parent 2e5ba76dd5
commit fa3212590d
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

@ -34,12 +34,12 @@ class Server {
app.ws('/embark/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, () => {});
});
});