verbose mode
This commit is contained in:
parent
a64ca3df66
commit
95b2f85a8c
2 changed files with 15 additions and 0 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1 +1,2 @@
|
||||||
*~
|
*~
|
||||||
|
old.txt
|
||||||
|
|
|
@ -20,17 +20,26 @@ var NsClient = function() {
|
||||||
this.allowed_statuses = ["actif", "away", "idle", "lock"];
|
this.allowed_statuses = ["actif", "away", "idle", "lock"];
|
||||||
this.is_connected = false;
|
this.is_connected = false;
|
||||||
this.socket = null;
|
this.socket = null;
|
||||||
|
this.verbose = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
NsClient.prototype.connect = function() {
|
NsClient.prototype.connect = function() {
|
||||||
var cnt = function(elem) {
|
var cnt = function(elem) {
|
||||||
return function(infos) {
|
return function(infos) {
|
||||||
if (typeof infos.login !== "undefined" && typeof infos.pwd_socks !== "undefined") {
|
if (typeof infos.login !== "undefined" && typeof infos.pwd_socks !== "undefined") {
|
||||||
|
if (elem.verbose)
|
||||||
|
console.log('creating socket...');
|
||||||
chrome.socket.create('tcp', {}, function(sock_inf) {
|
chrome.socket.create('tcp', {}, function(sock_inf) {
|
||||||
|
if (elem.verbose)
|
||||||
|
console.log('socket created, id: ' + sock_inf.socketId);
|
||||||
elem.socket = sock_inf.socketId;
|
elem.socket = sock_inf.socketId;
|
||||||
chrome.socket.connect(elem.socket, "ns-server.epita.fr", 4242, function(res) {
|
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) {
|
chrome.socket.read(elem.socket, null, function(rd_inf) {
|
||||||
if (rd_inf.resultCode > 0) {
|
if (rd_inf.resultCode > 0) {
|
||||||
|
if (elem.verbose)
|
||||||
|
console.log(ab2str(rd_inf.data));
|
||||||
var data = ab2str(rd_inf.data).split(' '),
|
var data = ab2str(rd_inf.data).split(' '),
|
||||||
auth = "ext_user_log ";
|
auth = "ext_user_log ";
|
||||||
auth += infos.login + " ";
|
auth += infos.login + " ";
|
||||||
|
@ -83,8 +92,13 @@ NsClient.prototype.daemonize = function() {
|
||||||
if (rd_inf.resultCode > 0) {
|
if (rd_inf.resultCode > 0) {
|
||||||
var data = ab2str(rd_inf.data);
|
var data = ab2str(rd_inf.data);
|
||||||
|
|
||||||
|
if (elem.verbose)
|
||||||
|
console.log("recv: " + data);
|
||||||
|
|
||||||
if (data.substr(0, 5) === "ping ") {
|
if (data.substr(0, 5) === "ping ") {
|
||||||
chrome.socket.write(elem.socket, rd_inf.data, function(w_inf) {
|
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);
|
chrome.socket.read(elem.socket, null, this);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue