Skip to content

Commit

Permalink
html: add disableReconnect client option
Browse files Browse the repository at this point in the history
  • Loading branch information
tsl0922 committed Dec 27, 2020
1 parent e3335bd commit 61a9bcd
Show file tree
Hide file tree
Showing 2 changed files with 199 additions and 188 deletions.
16 changes: 12 additions & 4 deletions html/src/components/terminal/index.tsx
Expand Up @@ -63,8 +63,10 @@ export class Xterm extends Component<Props> {
private titleFixed: string;
private resizeTimeout: number;
private resizeOverlay = true;

private backoff: backoff.Backoff;
private backoffLock = false;
private doBackoff = true;
private reconnect = false;

constructor(props: Props) {
Expand Down Expand Up @@ -233,6 +235,12 @@ export class Xterm extends Component<Props> {
this.resizeOverlay = false;
}
break;
case 'disableReconnect':
if (value) {
console.log(`[ttyd] Reconnect disabled`);
this.doBackoff = false;
}
break;
case 'titleFixed':
if (!value || value === '') return;
console.log(`[ttyd] setting fixed title: ${value}`);
Expand Down Expand Up @@ -276,20 +284,20 @@ export class Xterm extends Component<Props> {
private onSocketClose(event: CloseEvent) {
console.log(`[ttyd] websocket connection closed with code: ${event.code}`);

const { backoff, backoffLock, overlayAddon } = this;
const { backoff, doBackoff, backoffLock, overlayAddon } = this;
overlayAddon.showOverlay('Connection Closed', null);

// 1000: CLOSE_NORMAL
if (event.code !== 1000 && !backoffLock) {
if (event.code !== 1000 && doBackoff && !backoffLock) {
backoff.backoff();
}
}

@bind
private onSocketError(event: Event) {
console.error('[ttyd] websocket connection error: ', event);
const { backoff, backoffLock } = this;
if (!backoffLock) {
const { backoff, doBackoff, backoffLock } = this;
if (doBackoff && !backoffLock) {
backoff.backoff();
}
}
Expand Down

0 comments on commit 61a9bcd

Please sign in to comment.