verbose mode

This commit is contained in:
Rodolphe Breard 2012-11-03 23:04:42 +01:00
parent a64ca3df66
commit 95b2f85a8c
2 changed files with 15 additions and 0 deletions

1
.gitignore vendored
View file

@ -1 +1,2 @@
*~
old.txt

View file

@ -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);
});
}