From 71904f241cd3047054dc0a36c04120a3f53205ae Mon Sep 17 00:00:00 2001 From: Idan Amit Date: Tue, 13 Feb 2018 10:38:16 +0200 Subject: Plugin pubsub implementation Added implementation for sdc-hub and plugin pubsub classes Added timeout in the plugin head request health check Passing parentUrl in query params to each plugin Change-Id: Ie94aa4b398dd2fcfdf2d134f6c5785d3aa50d237 Issue-ID: SDC-1007 Signed-off-by: Idan Amit --- .../src/app/ng2/services/event-bus.service.ts | 39 ++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 catalog-ui/src/app/ng2/services/event-bus.service.ts (limited to 'catalog-ui/src/app/ng2/services/event-bus.service.ts') diff --git a/catalog-ui/src/app/ng2/services/event-bus.service.ts b/catalog-ui/src/app/ng2/services/event-bus.service.ts new file mode 100644 index 0000000000..7730a77f41 --- /dev/null +++ b/catalog-ui/src/app/ng2/services/event-bus.service.ts @@ -0,0 +1,39 @@ +import { Injectable } from '@angular/core'; +import {BasePubSub, IPubSubEvent} from "../../models/base-pubsub"; + +@Injectable() +export class EventBusService extends BasePubSub { + + constructor() { + super("sdc-hub"); + } + + protected handlePluginRegistration(eventData: IPubSubEvent, event: any) { + if (eventData.type === 'PLUGIN_REGISTER') { + this.register(eventData.data.pluginId, event.source, event.origin); + } else if (eventData.type === 'PLUGIN_UNREGISTER') { + this.unregister(eventData.data.pluginId); + } + } + + public unregister(pluginId: string) { + const unregisterData = { + pluginId: pluginId + }; + + this.notify('PLUGIN_CLOSE', unregisterData); + super.unregister(pluginId); + } + + protected onMessage(event: any) { + if (event.data.type === 'PLUGIN_REGISTER') { + this.handlePluginRegistration(event.data, event); + } + + super.onMessage(event); + + if (event.data.type === 'PLUGIN_UNREGISTER') { + this.handlePluginRegistration(event.data, event); + } + } +} -- cgit 1.2.3-korg