Stop publisher in a less brittle way

This commit is contained in:
Robin
2025-12-08 23:33:41 -05:00
parent e4404e5bb1
commit d8b9568400

View File

@@ -323,12 +323,14 @@ export const createLocalMembership$ = ({
// - overwrite current publisher
scope.reconcile(localConnection$, async (connection) => {
if (connection !== null) {
publisher$.next(createPublisherFactory(connection));
const publisher = createPublisherFactory(connection);
publisher$.next(publisher);
// Clean-up callback
return Promise.resolve(async (): Promise<void> => {
await publisher.stopPublishing();
publisher.stopTracks();
});
}
return Promise.resolve(async (): Promise<void> => {
await publisher$?.value?.stopPublishing();
publisher$?.value?.stopTracks();
});
});
// Use reconcile here to not run concurrent createAndSetupTracks calls