From 04c6fdb1b12743812627a24062ac0a69f2e846e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Xose=20P=C3=A9rez?= Date: Sat, 11 Feb 2017 00:29:03 +0100 Subject: [PATCH] Rename connect method in JS and add some feedback messages --- code/html/custom.js | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/code/html/custom.js b/code/html/custom.js index 825876e1..d9c35bfc 100644 --- a/code/html/custom.js +++ b/code/html/custom.js @@ -335,14 +335,20 @@ function getJson(str) { } } -function initWebSocket(host) { - if (host === undefined) { +function connect(host) { + if (typeof host === 'undefined') { host = window.location.hostname; } websock = new WebSocket('ws://' + host + '/ws'); - websock.onopen = function(evt) {}; - websock.onclose = function(evt) {}; - websock.onerror = function(evt) {}; + websock.onopen = function(evt) { + console.log("Connected"); + }; + websock.onclose = function(evt) { + console.log("Disconnected"); + }; + websock.onerror = function(evt) { + console.log("Error: ", evt); + }; websock.onmessage = function(evt) { var data = getJson(evt.data); if (data) processData(data); @@ -363,7 +369,7 @@ function init() { 'method': 'GET', 'url': '/auth' }).done(function(data) { - initWebSocket(); + connect(); }); }