[SDK] update state structure (less duplication, one state enum)

- remove media from LocalMembership file
This commit is contained in:
Timo K.
2026-10-08 13:53:57 +02:00
parent f49c1cd3d4
commit 3cdb452d5d
12 changed files with 500 additions and 497 deletions
+14 -26
View File
@@ -29,6 +29,7 @@ import { logger as rootLogger } from "matrix-js-sdk/lib/logger";
import { type ObservableScope } from "../reactive/ObservableScope";
import { type Behavior } from "../reactive/Behavior";
import { defaultSessionTimings } from "../config";
import { type MatrixDisconnectReason } from "../api";
type NodeEventHandler = (...args: unknown[]) => void;
@@ -37,22 +38,16 @@ interface NodeStyleEventEmitter {
removeListener(eventName: string | symbol, handler: NodeEventHandler): this;
}
export type HomeserverDisconnectReason = "sync" | "membership" | "probablyLeft";
export interface HomeserverConnected {
/**
* Emits `[true, null]` when the homeserver connection is healthy, or
* `[false, reason]` when one of the three sub-conditions fails.
*/
combined$: Behavior<[boolean, HomeserverDisconnectReason | null]>;
rtsSession$: Behavior<Status>;
/** Null while the homeserver connection is healthy, the first failing link otherwise. */
disconnectReason$: Behavior<MatrixDisconnectReason | null>;
}
/**
* Behavior representing whether we consider ourselves connected to the Matrix homeserver
* for the purposes of a MatrixRTC session.
*
* `combined$` emits `null` when all conditions are satisfied, or the first failing
* `disconnectReason$` emits `null` when all conditions are satisfied, or the first failing
* reason (priority: syncing > membershipConnected > certainlyConnected):
* 1. Sync loop is not in SyncState.Syncing (after grace period) → "sync"
* 2. membershipStatus !== Status.Connected → "membership"
@@ -118,26 +113,19 @@ export function createHomeserverConnected$(
map(() => matrixRTCSession.probablyLeft !== true),
);
const combined$ = scope.behavior(
const disconnectReason$ = scope.behavior(
combineLatest([syncing$, membershipConnected$, certainlyConnected$]).pipe(
map(
([syncing, membership, certainly]): [
boolean,
HomeserverDisconnectReason | null,
] => {
if (!syncing) return [false, "sync"];
if (!membership) return [false, "membership"];
if (!certainly) return [false, "probablyLeft"];
return [true, null];
},
),
tap(([connected, reason]) => {
logger.info(
`Homeserver connected update: ${connected ? "connected" : reason}`,
);
map(([syncing, membership, certainly]): MatrixDisconnectReason | null => {
if (!syncing) return "sync";
if (!membership) return "membership";
if (!certainly) return "probablyLeft";
return null;
}),
tap((reason) => {
logger.info(`Homeserver connected update: ${reason ?? "connected"}`);
}),
),
);
return { combined$, rtsSession$ };
return { disconnectReason$ };
}