mirror of
https://github.com/bitwarden/browser
synced 2025-12-18 17:23:37 +00:00
generic broadcaster service
This commit is contained in:
@@ -1,33 +1,7 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
|
||||
import { BroadcasterService as BaseBroadcasterService } from '../../services/broadcaster.service';
|
||||
|
||||
@Injectable()
|
||||
export class BroadcasterService {
|
||||
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) => {
|
||||
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 {
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user