mirror of
				https://github.com/avatao-content/frontend-tutorial-framework
				synced 2025-11-04 12:12:55 +00:00 
			
		
		
		
	Fix terminal race condition (afterViewInit vs WS connection)
This commit is contained in:
		@@ -7,6 +7,7 @@ import * as terminado from 'xterm/lib/addons/terminado/terminado';
 | 
			
		||||
export class TerminadoService {
 | 
			
		||||
  xterm: Terminal;
 | 
			
		||||
  ws: WebSocket;
 | 
			
		||||
  attached = false;
 | 
			
		||||
 | 
			
		||||
  constructor() {
 | 
			
		||||
    Terminal.applyAddon(fit);
 | 
			
		||||
@@ -47,6 +48,7 @@ export class TerminadoService {
 | 
			
		||||
      this.xterm.open(element);
 | 
			
		||||
      this.fit();
 | 
			
		||||
      this.xterm.blur();
 | 
			
		||||
      this.attached = true;
 | 
			
		||||
    };
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
@@ -54,9 +56,12 @@ export class TerminadoService {
 | 
			
		||||
    (<any>this.xterm).terminadoDetach(this.ws);
 | 
			
		||||
    this.xterm.destroy();
 | 
			
		||||
    this.ws.close();
 | 
			
		||||
    this.attached = false;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  fit() {
 | 
			
		||||
    (<any>this.xterm).fit();
 | 
			
		||||
    if (this.attached) {
 | 
			
		||||
      (<any>this.xterm).fit();
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user