Get url for console sockets moved to NodeConsoleService

This commit is contained in:
piotrpekala7 2021-04-16 12:05:58 +02:00
parent f5296dd1fb
commit 700eff76eb
6 changed files with 34 additions and 24 deletions

View File

@ -235,11 +235,11 @@ export class ProjectMapComponent implements OnInit, OnDestroy {
nodes.forEach(async (node: Node) => {
node.symbol_url = `${this.server.protocol}//${this.server.host}:${this.server.port}/v2/symbols/${node.symbol}/raw`;
if (node.width == 0 && node.height == 0) {
let symbolDimensions = await this.symbolService.getDimensions(this.server, node.symbol).toPromise();
node.width = symbolDimensions.width;
node.height = symbolDimensions.height;
}
// if (node.width == 0 && node.height == 0) {
// let symbolDimensions = await this.symbolService.getDimensions(this.server, node.symbol).toPromise();
// node.width = symbolDimensions.width;
// node.height = symbolDimensions.height;
// }
});
this.nodes = nodes;
@ -425,7 +425,7 @@ export class ProjectMapComponent implements OnInit, OnDestroy {
}
setUpProjectWS(project: Project) {
this.projectws = new WebSocket(this.projectService.notificationsPath(this.server, project.project_id));
this.projectws = new WebSocket(this.notificationService.projectNotificationsPath(this.server, project.project_id));
this.projectws.onmessage = (event: MessageEvent) => {
this.projectWebServiceHandler.handleMessage(JSON.parse(event.data));

View File

@ -53,7 +53,7 @@ export class WebConsoleComponent implements OnInit, AfterViewInit {
if (this.isLightThemeEnabled)
this.term.setOption('theme', { background: 'white', foreground: 'black', cursor: 'black' });
const socket = new WebSocket(this.getUrl());
const socket = new WebSocket(this.consoleService.getUrl(this.server, this.node));
socket.onerror = (event) => {
this.term.write('Connection lost');
@ -78,8 +78,4 @@ export class WebConsoleComponent implements OnInit, AfterViewInit {
return true;
});
}
getUrl() {
return `ws://${this.server.host}:${this.server.port}/v2/projects/${this.node.project_id}/nodes/${this.node.node_id}/console/ws`;
}
}

View File

@ -72,7 +72,7 @@ export class WebConsoleFullWindowComponent implements OnInit {
openTerminal() {
setTimeout(() => {
this.term.open(this.terminal.nativeElement);
const socket = new WebSocket(this.getUrl());
const socket = new WebSocket(this.consoleService.getUrl(this.server, this.node));
socket.onerror = (event) => {
this.term.write('Connection lost' + '\r\n');
@ -103,8 +103,4 @@ export class WebConsoleFullWindowComponent implements OnInit {
this.term.resize(numberOfColumns, numberOfRows);
}, 0);
}
getUrl() {
return `ws://${this.server.host}:${this.server.port}/v2/projects/${this.projectId}/nodes/${this.nodeId}/console/ws`;
}
}

View File

@ -1,4 +1,5 @@
import { EventEmitter, Injectable } from '@angular/core';
import { Server } from '../models/server';
import { Subject } from 'rxjs';
import { Node } from '../cartography/models/node';
@ -55,6 +56,15 @@ export class NodeConsoleService {
getLineHeight() {
return this.defaultConsoleHeight / this.defaultNumberOfRows;
}
getUrl(server: Server, node: Node) {
let protocol:string = "ws"
if (server.protocol === "https:") {
protocol = "wss"
}
return `${protocol}://${server.host}:${server.port}/v2/projects/${node.project_id}/nodes/${node.node_id}/console/ws`
}
}
export interface ConsoleResizedEvent {

View File

@ -1,12 +1,24 @@
import { Injectable } from '@angular/core';
import { Server } from '../models/server';
import { HttpServer } from './http-server.service';
@Injectable()
export class NotificationService {
constructor(private httpServer: HttpServer) {}
notificationsPath(server: Server): string {
return `ws://${server.host}:${server.port}/v2/notifications/ws`;
let protocol:string = "ws"
if (server.protocol === "https:") {
protocol = "wss"
}
return `${protocol}://${server.host}:${server.port}/v2/notifications/ws`;
}
projectNotificationsPath(server: Server, project_id: string): string {
let protocol:string = "ws"
if (server.protocol === "https:") {
protocol = "wss"
}
return `${protocol}://${server.host}:${server.port}/v2/projects/${project_id}/notifications/ws`;
}
}

View File

@ -94,10 +94,6 @@ export class ProjectService {
return this.httpServer.post(server, `/projects/${project_id}/duplicate`, { name: project_name });
}
notificationsPath(server: Server, project_id: string): string {
return `ws://${server.host}:${server.port}/v2/projects/${project_id}/notifications/ws`;
}
isReadOnly(project: Project) {
if (project.readonly) {
return project.readonly;