diff --git a/src/abstractions/broadcaster.service.ts b/src/abstractions/broadcaster.service.ts new file mode 100644 index 0000000000..9d0c8de950 --- /dev/null +++ b/src/abstractions/broadcaster.service.ts @@ -0,0 +1,5 @@ +export abstract class BroadcasterService { + send: (message: any, id?: string) => void; + subscribe: (id: string, messageCallback: (message: any) => any) => void; + unsubscribe: (id: string) => void; +} diff --git a/src/angular/services/broadcaster.service.ts b/src/angular/services/broadcaster.service.ts index fe747e7b0b..3b61a7e463 100644 --- a/src/angular/services/broadcaster.service.ts +++ b/src/angular/services/broadcaster.service.ts @@ -1,33 +1,7 @@ import { Injectable } from '@angular/core'; +import { BroadcasterService as BaseBroadcasterService } from '../../services/broadcaster.service'; + @Injectable() -export class BroadcasterService { - subscribers: Map any> = new Map any>(); - - send(message: any, id?: string) { - if (id != null) { - if (this.subscribers.has(id)) { - this.subscribers.get(id)(message); - } - return; - } - - this.subscribers.forEach((value) => { - value(message); - }); - } - - subscribe(id: string, messageCallback: (message: any) => any) { - if (this.subscribers.has(id)) { - return; - } - - this.subscribers.set(id, messageCallback); - } - - unsubscribe(id: string) { - if (this.subscribers.has(id)) { - this.subscribers.delete(id); - } - } +export class BroadcasterService extends BaseBroadcasterService { } diff --git a/src/services/broadcaster.service.ts b/src/services/broadcaster.service.ts new file mode 100644 index 0000000000..9f46ccc6f3 --- /dev/null +++ b/src/services/broadcaster.service.ts @@ -0,0 +1,32 @@ +import { BroadcasterService as BroadcasterServiceAbstraction } from '../abstractions/broadcaster.service'; + +export class BroadcasterService implements BroadcasterServiceAbstraction { + subscribers: Map any> = new Map any>(); + + send(message: any, id?: string) { + if (id != null) { + if (this.subscribers.has(id)) { + this.subscribers.get(id)(message); + } + return; + } + + this.subscribers.forEach((value) => { + value(message); + }); + } + + subscribe(id: string, messageCallback: (message: any) => any) { + if (this.subscribers.has(id)) { + return; + } + + this.subscribers.set(id, messageCallback); + } + + unsubscribe(id: string) { + if (this.subscribers.has(id)) { + this.subscribers.delete(id); + } + } +}