Fixed minor issues in sdc-pubusb
[sdc/sdc-pubsub.git] / src / plugin-pubsub.ts
1 import { BasePubSub } from './base-pubsub';
2
3 declare const window: Window;
4
5 export class PluginPubSub extends BasePubSub {
6
7     constructor(pluginId: string, parentUrl: string, eventsToWait?: string[]) {
8         super(pluginId);
9         this.register('sdc-hub', window.parent, parentUrl);
10         this.subscribe(eventsToWait);
11     }
12
13     public subscribe(eventsToWait?: string[]) {
14         const registerData = {
15             pluginId: this.clientId,
16             eventsToWait: eventsToWait || []
17         };
18
19         this.notify('PLUGIN_REGISTER', registerData);
20     }
21
22     public unsubscribe() {
23         const unregisterData = {
24             pluginId: this.clientId
25         };
26
27         this.notify('PLUGIN_UNREGISTER', unregisterData);
28     }
29 }