Actually leave the MatrixRTC session again

This commit is contained in:
Robin
2025-10-03 21:00:45 -04:00
parent 1820cac3f6
commit 1fff71ace1
3 changed files with 116 additions and 80 deletions

View File

@@ -7,7 +7,10 @@ Please see LICENSE in the repository root for full details.
import {
BehaviorSubject,
catchError,
distinctUntilChanged,
EMPTY,
endWith,
filter,
type Observable,
share,
@@ -95,6 +98,41 @@ export class ObservableScope {
)
.subscribe(callback);
}
// TODO-MULTI-SFU Dear Future Robin, please document this. Love, Past Robin.
public reconcile<T>(
value$: Behavior<T>,
callback: (value: T) => Promise<(() => Promise<void>) | undefined>,
): void {
let latestValue: T | typeof nothing = nothing;
let reconciledValue: T | typeof nothing = nothing;
let cleanUp: (() => Promise<void>) | undefined = undefined;
let callbackPromise: Promise<(() => Promise<void>) | undefined>;
value$
.pipe(
catchError(() => EMPTY),
this.bind(),
endWith(nothing),
)
.subscribe((value) => {
void (async (): Promise<void> => {
if (latestValue === nothing) {
latestValue = value;
while (latestValue !== reconciledValue) {
await cleanUp?.();
reconciledValue = latestValue;
if (latestValue !== nothing) {
callbackPromise = callback(latestValue);
cleanUp = await callbackPromise;
}
}
latestValue = nothing;
} else {
latestValue = value;
}
})();
});
}
}
/**