2019-01-22 22:12:34 +01:00
|
|
|
import { BroadcasterService as BroadcasterServiceAbstraction } from "../abstractions/broadcaster.service";
|
|
|
|
|
|
|
|
export class BroadcasterService implements BroadcasterServiceAbstraction {
|
|
|
|
subscribers: Map<string, (message: any) => any> = new Map<string, (message: any) => any>();
|
|
|
|
|
|
|
|
send(message: any, id?: string) {
|
|
|
|
if (id != null) {
|
|
|
|
if (this.subscribers.has(id)) {
|
|
|
|
this.subscribers.get(id)(message);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-02-04 16:49:23 +01:00
|
|
|
this.subscribers.forEach((value) => {
|
2019-01-22 22:12:34 +01:00
|
|
|
value(message);
|
2021-12-16 13:36:21 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-01-22 22:12:34 +01:00
|
|
|
subscribe(id: string, messageCallback: (message: any) => any) {
|
|
|
|
this.subscribers.set(id, messageCallback);
|
|
|
|
}
|
|
|
|
|
|
|
|
unsubscribe(id: string) {
|
|
|
|
if (this.subscribers.has(id)) {
|
|
|
|
this.subscribers.delete(id);
|
|
|
|
}
|
2021-12-16 13:36:21 +01:00
|
|
|
}
|
2019-01-22 22:12:34 +01:00
|
|
|
}
|