Update web-console-full-window.component.ts

This commit is contained in:
piotrpekala7
2020-05-05 17:05:12 +02:00
parent 467cf2b1d8
commit 626769aa61

View File

@ -18,7 +18,7 @@ import { NodeService } from '../../services/node.service';
templateUrl: './web-console-full-window.component.html', templateUrl: './web-console-full-window.component.html',
styleUrls: ['../../../../node_modules/xterm/css/xterm.css'] styleUrls: ['../../../../node_modules/xterm/css/xterm.css']
}) })
export class WebConsoleFullWindowComponent implements OnInit, AfterViewInit { export class WebConsoleFullWindowComponent implements OnInit {
private serverId: string; private serverId: string;
private projectId: string; private projectId: string;
private nodeId: string; private nodeId: string;
@ -53,13 +53,15 @@ export class WebConsoleFullWindowComponent implements OnInit, AfterViewInit {
this.nodeService.getNodeById(this.server, this.projectId, this.nodeId).subscribe((node: Node) => { this.nodeService.getNodeById(this.server, this.projectId, this.nodeId).subscribe((node: Node) => {
this.node = node; this.node = node;
this.title.setTitle(this.node.name); this.title.setTitle(this.node.name);
this.openTerminal();
}); });
}) })
} }
async ngAfterViewInit() { openTerminal() {
setTimeout(() => {
this.term.open(this.terminal.nativeElement); this.term.open(this.terminal.nativeElement);
const socket = new WebSocket(await this.getUrl()); const socket = new WebSocket(this.getUrl());
socket.onerror = ((event) => { socket.onerror = ((event) => {
this.term.write("Connection lost" + "\r\n"); this.term.write("Connection lost" + "\r\n");
@ -88,9 +90,10 @@ export class WebConsoleFullWindowComponent implements OnInit, AfterViewInit {
let numberOfColumns = Math.round(window.innerWidth / this.consoleService.getLineWidth()); let numberOfColumns = Math.round(window.innerWidth / this.consoleService.getLineWidth());
let numberOfRows = Math.round(window.innerHeight / this.consoleService.getLineHeight()); let numberOfRows = Math.round(window.innerHeight / this.consoleService.getLineHeight());
this.term.resize(numberOfColumns, numberOfRows); this.term.resize(numberOfColumns, numberOfRows);
}, 0 );
} }
async getUrl() { getUrl() {
return `ws://${this.server.host}:${this.server.port}/v2/projects/${this.projectId}/nodes/${this.nodeId}/console/ws` return `ws://${this.server.host}:${this.server.port}/v2/projects/${this.projectId}/nodes/${this.nodeId}/console/ws`
} }
} }