bitwarden-estensione-browser/common/src/services/broadcaster.service.ts

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

29 lines
752 B
TypeScript
Raw Normal View History

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;
}
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
}