From: Shuanglei Tao Date: Sun, 23 Jun 2019 09:33:03 +0000 (+0800) Subject: html: auto reconnect on zmodem error X-Git-Url: http://git.prime8.dev/?a=commitdiff_plain;h=9762993129fbadd04d5588fc9df581f51b7c7a56;p=ttyd.git html: auto reconnect on zmodem error --- diff --git a/html/src/components/terminal/index.tsx b/html/src/components/terminal/index.tsx index 759215d..a0f9b8a 100644 --- a/html/src/components/terminal/index.tsx +++ b/html/src/components/terminal/index.tsx @@ -47,7 +47,7 @@ export class Xterm extends Component { private overlayAddon: OverlayAddon; private socket: WebSocket; private title: string; - private autoReconnect: number; + private reconnect: number; private resizeTimeout: number; private sentry: Zmodem.Sentry; private session: Zmodem.Session; @@ -252,7 +252,7 @@ export class Xterm extends Component { private onSocketClose(event: CloseEvent) { console.log(`[ttyd] websocket connection closed with code: ${event.code}`); - const { overlayAddon, openTerminal, autoReconnect } = this; + const { overlayAddon, openTerminal, reconnect } = this; overlayAddon.showOverlay('Connection Closed', null); window.removeEventListener('beforeunload', this.onWindowUnload); @@ -261,8 +261,8 @@ export class Xterm extends Component { window.location.reload(); } // 1000: CLOSE_NORMAL - if (event.code !== 1000 && autoReconnect > 0) { - setTimeout(openTerminal, autoReconnect * 1000); + if (event.code !== 1000 && reconnect > 0) { + setTimeout(openTerminal, reconnect * 1000); } } @@ -279,8 +279,8 @@ export class Xterm extends Component { this.sentry.consume(data); } catch (e) { console.log(`[ttyd] zmodem consume: `, e); + this.reconnect = 0.5; socket.close(); - setTimeout(() => openTerminal(), 500); } break; case Command.SET_WINDOW_TITLE: @@ -295,8 +295,8 @@ export class Xterm extends Component { }); break; case Command.SET_RECONNECT: - this.autoReconnect = Number(textDecoder.decode(data)); - console.log(`[ttyd] enabling reconnect: ${this.autoReconnect} seconds`); + this.reconnect = Number(textDecoder.decode(data)); + console.log(`[ttyd] enabling reconnect: ${this.reconnect} seconds`); break; default: console.warn(`[ttyd] unknown command: ${cmd}`); diff --git a/src/index.html b/src/index.html index 3b6cbe1..a85fee1 100644 --- a/src/index.html +++ b/src/index.html @@ -1 +1 @@ -ttyd - Terminal \ No newline at end of file +ttyd - Terminal \ No newline at end of file