Skip to content

Commit

Permalink
html: polish zmodem code
Browse files Browse the repository at this point in the history
  • Loading branch information
tsl0922 committed Jun 23, 2019
1 parent 9762993 commit 70f16a7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
28 changes: 16 additions & 12 deletions html/src/components/terminal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export class Xterm extends Component<Props, State> {
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<number>) => this.zmodemSend(octets),
on_retract: () => {},
on_detect: (detection: any) => this.zmodemDetect(detection),
});
Expand Down Expand Up @@ -106,12 +106,12 @@ export class Xterm extends Component<Props, State> {
}

@bind
private zmodemSend(data: number[]): void {
private zmodemSend(data: ArrayLike<number>): 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
Expand Down Expand Up @@ -140,12 +140,16 @@ export class Xterm extends Component<Props, State> {
}

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
Expand Down Expand Up @@ -268,7 +272,7 @@ export class Xterm extends Component<Props, State> {

@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);
Expand Down
2 changes: 1 addition & 1 deletion src/index.html

Large diffs are not rendered by default.

0 comments on commit 70f16a7

Please sign in to comment.