send logs to ws

This commit is contained in:
Iuri Matias 2018-02-26 17:44:09 -05:00 committed by Pascal Precht
parent 7bd6b9da8f
commit ceb107f43b
No known key found for this signature in database
GPG Key ID: 0EE28D8D6FD85D7D
2 changed files with 14 additions and 22 deletions

View File

@ -1,29 +1,22 @@
Welcome to Embark! Welcome to Embark!
<script> <script>
var ws = new WebSocket("ws://localhost:8000/embark/logs");
var ws = new WebSocket("ws://localhost:8000/logs"); ws.onopen = function() {
};
ws.onopen = function() { ws.onmessage = function (evt) {
// Web Socket is connected, send data using send()
ws.send("Message to send");
alert("Message is sent...");
};
ws.onmessage = function (evt) {
var received_msg = evt.data; var received_msg = evt.data;
console.log(received_msg); console.log(received_msg);
//alert("Message is received..."); };
};
ws.onclose = function() { ws.onclose = function() {
// websocket is closed. console.log("Connection is closed...");
alert("Connection is closed..."); };
};
window.onbeforeunload = function(event) {
socket.close();
};
window.onbeforeunload = function(event) {
ws.close();
};
</script> </script>

View File

@ -69,8 +69,7 @@ class Server {
this.app.ws('/logs', function(ws, req) { this.app.ws('/logs', function(ws, req) {
self.events.on("log", function(logLevel, logMsg) { self.events.on("log", function(logLevel, logMsg) {
console.dir("got message " + logMsg); ws.send(logMsg.stripColors);
ws.send(logMsg);
}); });
ws.on('message', function(msg) { ws.on('message', function(msg) {
console.dir("got message"); console.dir("got message");