From d5fc46460341439cd64a6d38b223534edd3032e6 Mon Sep 17 00:00:00 2001 From: midoks Date: Fri, 27 Jan 2023 00:40:06 +0800 Subject: [PATCH] ssh update 90% --- class/core/ssh_terminal.py | 6 ++++- plugins/webssh/js/webssh.js | 17 +++++++++++++++ route/static/js/term-websocketio.js | 34 +++++++++++++++++++---------- 3 files changed, 44 insertions(+), 13 deletions(-) diff --git a/class/core/ssh_terminal.py b/class/core/ssh_terminal.py index 3baad80cc..a813e6220 100644 --- a/class/core/ssh_terminal.py +++ b/class/core/ssh_terminal.py @@ -383,6 +383,9 @@ class ssh_terminal: def wsSendConnect(self): return emit('connect', {'data': 'ok'}) + def wsSendReConnect(self): + return emit('reconnect', {'data': 'ok'}) + def heartbeat(self): # limit_cos = 10 while True: @@ -393,7 +396,6 @@ class ssh_terminal: sid_off_cos = cur_time - ssh_last_time # print("heartbeat off cos :", x, sid_off_cos) - if sid_off_cos > 3: cur_ssh = self.__ssh_list[x] if not cur_ssh: @@ -423,6 +425,8 @@ class ssh_terminal: return self.wsSendConnect() else: return self.wsSend(result['msg']) + else: + return self.wsSendReConnect() result = self.returnMsg(False, '') if sid in self.__ssh_list: diff --git a/plugins/webssh/js/webssh.js b/plugins/webssh/js/webssh.js index 2441af1d2..a62a030ff 100755 --- a/plugins/webssh/js/webssh.js +++ b/plugins/webssh/js/webssh.js @@ -293,8 +293,25 @@ function Terms_WebSocketIO_Create(ip, random){ }); n.registerConnectedCallBack(function(){ + var that = this; + $('.term_item_tab .item').each(function(){ + var id = $(this).data('id'); + if (id == that.id){ + $(this).find('.icon').removeClass('icon-warning').addClass('icon-sucess'); + } + }); webShell_Resize(); }); + + n.registerExitCallBack(function(){ + var that = this; + $('.term_item_tab .item').each(function(){ + var id = $(this).data('id'); + if (id == that.id){ + $(this).find('.icon').removeClass('icon-sucess').addClass('icon-warning'); + } + }); + }); return n; } diff --git a/route/static/js/term-websocketio.js b/route/static/js/term-websocketio.js index c4a3054d7..145598f5e 100644 --- a/route/static/js/term-websocketio.js +++ b/route/static/js/term-websocketio.js @@ -30,6 +30,10 @@ Terms_WebSocketIO.prototype = { this.callback_connected = callback; }, + registerExitCallBack:function(callback){ + this.callback_exit = callback; + }, + connectWs: function (callback) { this.ws = io.connect(); // console.log(this.ws); @@ -61,18 +65,24 @@ Terms_WebSocketIO.prototype = { } }, - - on_connect:function(ws_event){ - // console.log(ws_event); this.is_connected = true; if (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){ @@ -97,29 +107,29 @@ Terms_WebSocketIO.prototype = { this.term.setOption('cursorBlink', true); this.ws.on('server_response', function (ev) { that.on_message(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)}); if (this.ws) { - that.send(''); this.term_timer = setInterval(function () { if (that.is_connected){ that.send(''); + } else{ + that.on_exit(); } }, 600); } this.term.on('data', function (data) { if (that.is_connected){ - try { - that.send(data) - } catch (e) { - that.term.write('\r\n连接丢失,正在尝试重新连接!\r\n'); - that.connectSsh(); - } + that.send(data); + } else{ + that.term.write('\r\n连接丢失,正在尝试重新连接!\r\n'); + that.connectSsh(); } }); - that.term.write('\r\n请稍等,正在链接中...\r\n'); + this.term.write('\r\n请稍等,正在链接中...\r\n'); this.connectSsh(); this.term.focus(); }