mirror of
https://github.com/bitwarden/browser
synced 2026-01-02 16:43:19 +00:00
* Change `object` to `Record<string, unknown>` * Change `object` to `Record<string, unknown>` Pt. 2 * Update ForegroundSyncService - Manage finish message in the listener to more gaurantee a message back - Make the timeout much longer - Allow it to throw if the background sync service threw --------- Co-authored-by: Cesar Gonzalez <cesar.a.gonzalezcs@gmail.com>
30 lines
890 B
TypeScript
30 lines
890 B
TypeScript
import { Subscription } from "rxjs";
|
|
|
|
import { BroadcasterService, MessageBase } from "../abstractions/broadcaster.service";
|
|
import { MessageListener } from "../messaging";
|
|
|
|
/**
|
|
* Temporary implementation that just delegates to the message sender and message listener
|
|
* and manages their subscriptions.
|
|
*/
|
|
export class DefaultBroadcasterService implements BroadcasterService {
|
|
subscriptions = new Map<string, Subscription>();
|
|
|
|
constructor(private readonly messageListener: MessageListener) {}
|
|
|
|
subscribe(id: string, messageCallback: (message: MessageBase) => void) {
|
|
this.subscriptions.set(
|
|
id,
|
|
this.messageListener.allMessages$.subscribe((message) => {
|
|
messageCallback(message);
|
|
}),
|
|
);
|
|
}
|
|
|
|
unsubscribe(id: string) {
|
|
const subscription = this.subscriptions.get(id);
|
|
subscription?.unsubscribe();
|
|
this.subscriptions.delete(id);
|
|
}
|
|
}
|