diff --git a/.gitignore b/.gitignore index b25c15b..b3c7022 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ *~ +old.txt diff --git a/lib/ns_client.js b/lib/ns_client.js index 79b1b16..6eb0155 100644 --- a/lib/ns_client.js +++ b/lib/ns_client.js @@ -20,17 +20,26 @@ var NsClient = function() { this.allowed_statuses = ["actif", "away", "idle", "lock"]; this.is_connected = false; this.socket = null; + this.verbose = false; }; NsClient.prototype.connect = function() { var cnt = function(elem) { return function(infos) { if (typeof infos.login !== "undefined" && typeof infos.pwd_socks !== "undefined") { + if (elem.verbose) + console.log('creating socket...'); chrome.socket.create('tcp', {}, function(sock_inf) { + if (elem.verbose) + console.log('socket created, id: ' + sock_inf.socketId); elem.socket = sock_inf.socketId; chrome.socket.connect(elem.socket, "ns-server.epita.fr", 4242, function(res) { + if (elem.verbose) + console.log('connected to server'); chrome.socket.read(elem.socket, null, function(rd_inf) { if (rd_inf.resultCode > 0) { + if (elem.verbose) + console.log(ab2str(rd_inf.data)); var data = ab2str(rd_inf.data).split(' '), auth = "ext_user_log "; auth += infos.login + " "; @@ -83,8 +92,13 @@ NsClient.prototype.daemonize = function() { if (rd_inf.resultCode > 0) { var data = ab2str(rd_inf.data); + if (elem.verbose) + console.log("recv: " + data); + if (data.substr(0, 5) === "ping ") { chrome.socket.write(elem.socket, rd_inf.data, function(w_inf) { + if (elem.verbose) + console.log("sent: " + data); chrome.socket.read(elem.socket, null, this); }); }