1
0
mirror of https://github.com/bitwarden/browser synced 2026-01-02 16:43:19 +00:00
Files
browser/libs/common/src/platform/services/default-broadcaster.service.ts
Justin Baur a6df923416 [PM-8292] Fixup ForegroundSyncService (#9292)
* 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>
2024-05-29 12:12:58 -04:00

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