From: Shuanglei Tao Date: Sun, 23 Jun 2019 10:37:33 +0000 (+0800) Subject: html: polish zmodem code X-Git-Url: http://git.prime8.dev/?a=commitdiff_plain;h=70f16a7a4169ce3148cad9ea696aa3c1d20b9dd6;p=ttyd.git html: polish zmodem code --- diff --git a/html/src/components/terminal/index.tsx b/html/src/components/terminal/index.tsx index a0f9b8a..f9618e3 100644 --- a/html/src/components/terminal/index.tsx +++ b/html/src/components/terminal/index.tsx @@ -61,7 +61,7 @@ export class Xterm extends Component { this.overlayAddon = new OverlayAddon(); this.sentry = new Zmodem.Sentry({ to_terminal: (octets: ArrayBuffer) => this.zmodemWrite(octets), - sender: (octets: number[]) => this.zmodemSend(octets), + sender: (octets: ArrayLike) => this.zmodemSend(octets), on_retract: () => {}, on_detect: (detection: any) => this.zmodemDetect(detection), }); @@ -106,12 +106,12 @@ export class Xterm extends Component { } @bind - private zmodemSend(data: number[]): void { + private zmodemSend(data: ArrayLike): void { const { socket } = this; - const buffer = new Uint8Array(data.length + 1); - buffer[0] = Command.INPUT.charCodeAt(0); - buffer.set(data, 1); - socket.send(buffer); + const payload = new Uint8Array(data.length + 1); + payload[0] = Command.INPUT.charCodeAt(0); + payload.set(data, 1); + socket.send(payload); } @bind @@ -140,12 +140,16 @@ export class Xterm extends Component { } Zmodem.Browser.send_files(session, files, { - on_progress: (_, xfer) => writeProgress(xfer), + on_progress: (_, xfer: any) => writeProgress(xfer), on_file_complete: () => {}, - }).then(() => { - session.close(); - terminal.setOption('disableStdin', false); - }); + }) + .then(() => { + session.close(); + terminal.setOption('disableStdin', false); + }) + .catch(e => { + console.log(`[ttyd] zmodem send: `, e); + }); } @bind @@ -268,7 +272,7 @@ export class Xterm extends Component { @bind private onSocketData(event: MessageEvent) { - const { terminal, textDecoder, socket, openTerminal } = this; + const { terminal, textDecoder, socket } = this; const rawData = event.data as ArrayBuffer; const cmd = String.fromCharCode(new Uint8Array(rawData)[0]); const data = rawData.slice(1); diff --git a/src/index.html b/src/index.html index a85fee1..64b5cbf 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