Fix terminal race condition (afterViewInit vs WS connection)

This commit is contained in:
Kristóf Tóth 2019-08-27 17:20:26 +02:00
parent 00e4c2f7b3
commit 4ac350d665

View File

@ -7,6 +7,7 @@ import * as terminado from 'xterm/lib/addons/terminado/terminado';
export class TerminadoService { export class TerminadoService {
xterm: Terminal; xterm: Terminal;
ws: WebSocket; ws: WebSocket;
attached = false;
constructor() { constructor() {
Terminal.applyAddon(fit); Terminal.applyAddon(fit);
@ -47,6 +48,7 @@ export class TerminadoService {
this.xterm.open(element); this.xterm.open(element);
this.fit(); this.fit();
this.xterm.blur(); this.xterm.blur();
this.attached = true;
}; };
} }
@ -54,9 +56,12 @@ export class TerminadoService {
(<any>this.xterm).terminadoDetach(this.ws); (<any>this.xterm).terminadoDetach(this.ws);
this.xterm.destroy(); this.xterm.destroy();
this.ws.close(); this.ws.close();
this.attached = false;
} }
fit() { fit() {
(<any>this.xterm).fit(); if (this.attached) {
(<any>this.xterm).fit();
}
} }
} }