|
|
@ -30,6 +30,10 @@ Terms_WebSocketIO.prototype = { |
|
|
|
this.callback_connected = callback; |
|
|
|
this.callback_connected = callback; |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
registerExitCallBack:function(callback){ |
|
|
|
|
|
|
|
this.callback_exit = callback; |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
connectWs: function (callback) { |
|
|
|
connectWs: function (callback) { |
|
|
|
this.ws = io.connect(); |
|
|
|
this.ws = io.connect(); |
|
|
|
// console.log(this.ws);
|
|
|
|
// console.log(this.ws);
|
|
|
@ -61,18 +65,24 @@ Terms_WebSocketIO.prototype = { |
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
on_connect:function(ws_event){ |
|
|
|
on_connect:function(ws_event){ |
|
|
|
// console.log(ws_event);
|
|
|
|
|
|
|
|
this.is_connected = true; |
|
|
|
this.is_connected = true; |
|
|
|
if (this.callback_connected){ |
|
|
|
if (this.callback_connected){ |
|
|
|
this.callback_connected(); |
|
|
|
this.callback_connected(); |
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
on_exit:function(ws_event){ |
|
|
|
on_reconnect:function(ws_event){ |
|
|
|
|
|
|
|
this.is_connected = false; |
|
|
|
|
|
|
|
// if (this.callback_connected){
|
|
|
|
|
|
|
|
// this.callback_connected();
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
on_exit:function(){ |
|
|
|
|
|
|
|
if (this.callback_exit){ |
|
|
|
|
|
|
|
this.callback_exit(); |
|
|
|
|
|
|
|
} |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
send:function(data){ |
|
|
|
send:function(data){ |
|
|
@ -97,29 +107,29 @@ Terms_WebSocketIO.prototype = { |
|
|
|
this.term.setOption('cursorBlink', true); |
|
|
|
this.term.setOption('cursorBlink', true); |
|
|
|
this.ws.on('server_response', function (ev) { that.on_message(ev)}); |
|
|
|
this.ws.on('server_response', function (ev) { that.on_message(ev)}); |
|
|
|
this.ws.on('connect', function (ev) { that.on_connect(ev)}); |
|
|
|
this.ws.on('connect', function (ev) { that.on_connect(ev)}); |
|
|
|
|
|
|
|
this.ws.on('reconnect', function (ev) { that.on_reconnect(ev)}); |
|
|
|
this.ws.on('exit', function (ev) { that.on_exit(ev)}); |
|
|
|
this.ws.on('exit', function (ev) { that.on_exit(ev)}); |
|
|
|
|
|
|
|
|
|
|
|
if (this.ws) { |
|
|
|
if (this.ws) { |
|
|
|
that.send(''); |
|
|
|
|
|
|
|
this.term_timer = setInterval(function () { |
|
|
|
this.term_timer = setInterval(function () { |
|
|
|
if (that.is_connected){ |
|
|
|
if (that.is_connected){ |
|
|
|
that.send(''); |
|
|
|
that.send(''); |
|
|
|
|
|
|
|
} else{ |
|
|
|
|
|
|
|
that.on_exit(); |
|
|
|
} |
|
|
|
} |
|
|
|
}, 600); |
|
|
|
}, 600); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
this.term.on('data', function (data) { |
|
|
|
this.term.on('data', function (data) { |
|
|
|
if (that.is_connected){ |
|
|
|
if (that.is_connected){ |
|
|
|
try { |
|
|
|
that.send(data); |
|
|
|
that.send(data) |
|
|
|
} else{ |
|
|
|
} catch (e) { |
|
|
|
that.term.write('\r\n连接丢失,正在尝试重新连接!\r\n'); |
|
|
|
that.term.write('\r\n连接丢失,正在尝试重新连接!\r\n'); |
|
|
|
that.connectSsh(); |
|
|
|
that.connectSsh(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
that.term.write('\r\n请稍等,正在链接中...\r\n'); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.term.write('\r\n请稍等,正在链接中...\r\n'); |
|
|
|
this.connectSsh(); |
|
|
|
this.connectSsh(); |
|
|
|
this.term.focus(); |
|
|
|
this.term.focus(); |
|
|
|
} |
|
|
|
} |
|
|
|