mirror of
https://github.com/GNS3/gns3-web-ui.git
synced 2025-02-21 10:01:44 +00:00
Update project-web-service-handler
This commit is contained in:
parent
d11413d10e
commit
430107c065
@ -50,6 +50,7 @@ import { InterfaceLabelWidget } from '../../cartography/widgets/interface-label'
|
||||
import { LabelWidget } from '../../cartography/widgets/label';
|
||||
import { MapLinkNodeToLinkNodeConverter } from '../../cartography/converters/map/map-link-node-to-link-node-converter';
|
||||
import { ProjectMapMenuComponent } from './project-map-menu/project-map-menu.component';
|
||||
import { ToasterService } from '../../services/toaster.service';
|
||||
|
||||
|
||||
@Component({
|
||||
@ -65,7 +66,7 @@ export class ProjectMapComponent implements OnInit, OnDestroy {
|
||||
public symbols: Symbol[] = [];
|
||||
public project: Project;
|
||||
public server: Server;
|
||||
private ws: Subject<any>;
|
||||
private ws: WebSocket;
|
||||
public isProjectMapMenuVisible: boolean = false;
|
||||
|
||||
tools = {
|
||||
@ -113,7 +114,8 @@ export class ProjectMapComponent implements OnInit, OnDestroy {
|
||||
private recentlyOpenedProjectService: RecentlyOpenedProjectService,
|
||||
private movingEventSource: MovingEventSource,
|
||||
private mapScaleService: MapScaleService,
|
||||
private nodeCreatedLabelStylesFixer: NodeCreatedLabelStylesFixer
|
||||
private nodeCreatedLabelStylesFixer: NodeCreatedLabelStylesFixer,
|
||||
private toasterService: ToasterService
|
||||
) {}
|
||||
|
||||
ngOnInit() {
|
||||
@ -228,9 +230,15 @@ export class ProjectMapComponent implements OnInit, OnDestroy {
|
||||
}
|
||||
|
||||
setUpWS(project: Project) {
|
||||
this.ws = webSocket(this.projectService.notificationsPath(this.server, project.project_id));
|
||||
this.ws = new WebSocket(this.projectService.notificationsPath(this.server, project.project_id));
|
||||
|
||||
this.subscriptions.push(this.projectWebServiceHandler.connect(this.ws));
|
||||
this.ws.onmessage = (ev: MessageEvent) => {
|
||||
this.projectWebServiceHandler.handleMessage(ev);
|
||||
};
|
||||
|
||||
this.ws.onerror = (ev: MessageEvent) => {
|
||||
this.toasterService.error('Connection to host lost.');
|
||||
};
|
||||
}
|
||||
|
||||
setUpMapCallbacks() {
|
||||
@ -405,8 +413,8 @@ export class ProjectMapComponent implements OnInit, OnDestroy {
|
||||
this.nodesDataSource.clear();
|
||||
this.linksDataSource.clear();
|
||||
|
||||
if (this.ws) {
|
||||
this.ws.unsubscribe();
|
||||
if (this.ws.OPEN) {
|
||||
this.ws.close();
|
||||
}
|
||||
this.subscriptions.forEach((subscription: Subscription) => subscription.unsubscribe());
|
||||
}
|
||||
|
@ -21,36 +21,36 @@ export class ProjectWebServiceHandler {
|
||||
private drawingsDataSource: DrawingsDataSource
|
||||
) {}
|
||||
|
||||
public connect(ws: Subject<WebServiceMessage>) {
|
||||
const subscription = ws.subscribe((message: WebServiceMessage) => {
|
||||
if (message.action === 'node.updated') {
|
||||
this.nodesDataSource.update(message.event as Node);
|
||||
}
|
||||
if (message.action === 'node.created') {
|
||||
this.nodesDataSource.add(message.event as Node);
|
||||
}
|
||||
if (message.action === 'node.deleted') {
|
||||
this.nodesDataSource.remove(message.event as Node);
|
||||
}
|
||||
if (message.action === 'link.created') {
|
||||
this.linksDataSource.add(message.event as Link);
|
||||
}
|
||||
if (message.action === 'link.updated') {
|
||||
this.linksDataSource.update(message.event as Link);
|
||||
}
|
||||
if (message.action === 'link.deleted') {
|
||||
this.linksDataSource.remove(message.event as Link);
|
||||
}
|
||||
if (message.action === 'drawing.created') {
|
||||
this.drawingsDataSource.add(message.event as Drawing);
|
||||
}
|
||||
if (message.action === 'drawing.updated') {
|
||||
this.drawingsDataSource.update(message.event as Drawing);
|
||||
}
|
||||
if (message.action === 'drawing.deleted') {
|
||||
this.drawingsDataSource.remove(message.event as Drawing);
|
||||
}
|
||||
});
|
||||
return subscription;
|
||||
public handleMessage(event: MessageEvent) {
|
||||
console.log(event);
|
||||
let message = event.data;
|
||||
if (message.action === 'node.updated') {
|
||||
console.log('should work');
|
||||
this.nodesDataSource.update(message.event as Node);
|
||||
}
|
||||
if (message.action === 'node.created') {
|
||||
this.nodesDataSource.add(message.event as Node);
|
||||
}
|
||||
if (message.action === 'node.deleted') {
|
||||
this.nodesDataSource.remove(message.event as Node);
|
||||
}
|
||||
if (message.action === 'link.created') {
|
||||
this.linksDataSource.add(message.event as Link);
|
||||
}
|
||||
if (message.action === 'link.updated') {
|
||||
this.linksDataSource.update(message.event as Link);
|
||||
}
|
||||
if (message.action === 'link.deleted') {
|
||||
this.linksDataSource.remove(message.event as Link);
|
||||
}
|
||||
if (message.action === 'drawing.created') {
|
||||
this.drawingsDataSource.add(message.event as Drawing);
|
||||
}
|
||||
if (message.action === 'drawing.updated') {
|
||||
this.drawingsDataSource.update(message.event as Drawing);
|
||||
}
|
||||
if (message.action === 'drawing.deleted') {
|
||||
this.drawingsDataSource.remove(message.event as Drawing);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user