mirror of
https://github.com/vector-im/element-call.git
synced 2026-08-29 21:15:19 +00:00
Merge disconnectReason$ into combined$; rename HomeserverDisconnectReason items
This commit is contained in:
@@ -29,7 +29,6 @@ import { logger as rootLogger } from "matrix-js-sdk/lib/logger";
|
||||
import { Config } from "../../../config/Config";
|
||||
import { type ObservableScope } from "../../ObservableScope";
|
||||
import { type Behavior } from "../../Behavior";
|
||||
import { and$ } from "../../../utils/observable";
|
||||
import { type NodeStyleEventEmitter } from "../../../utils/test";
|
||||
|
||||
/**
|
||||
@@ -37,25 +36,26 @@ import { type NodeStyleEventEmitter } from "../../../utils/test";
|
||||
*/
|
||||
const logger = rootLogger.getChild("[HomeserverConnected]");
|
||||
|
||||
export type HomeserverDisconnectReason =
|
||||
| "syncing"
|
||||
| "membershipConnected"
|
||||
| "certainlyConnected";
|
||||
export type HomeserverDisconnectReason = "sync" | "membership" | "probablyLeft";
|
||||
|
||||
export interface HomeserverConnected {
|
||||
combined$: Behavior<boolean>;
|
||||
/**
|
||||
* Emits `null` when the homeserver connection is healthy, or the reason for
|
||||
* disconnection when one of the three sub-conditions fails.
|
||||
*/
|
||||
combined$: Behavior<HomeserverDisconnectReason | null>;
|
||||
rtsSession$: Behavior<Status>;
|
||||
disconnectReason$: Behavior<HomeserverDisconnectReason | null>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Behavior representing whether we consider ourselves connected to the Matrix homeserver
|
||||
* for the purposes of a MatrixRTC session.
|
||||
*
|
||||
* Becomes FALSE if ANY sub-condition is fulfilled:
|
||||
* 1. Sync loop is not in SyncState.Syncing (after grace period)
|
||||
* 2. membershipStatus !== Status.Connected
|
||||
* 3. probablyLeft === true
|
||||
* `combined$` 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"
|
||||
* 3. probablyLeft === true → "probablyLeft"
|
||||
*
|
||||
* @param scope - The observable scope for lifecycle management.
|
||||
* @param client - The Matrix client to monitor sync state.
|
||||
@@ -116,24 +116,18 @@ export function createHomeserverConnected$(
|
||||
);
|
||||
|
||||
const combined$ = scope.behavior(
|
||||
and$(syncing$, membershipConnected$, certainlyConnected$).pipe(
|
||||
tap((connected) => {
|
||||
logger.info(`Homeserver connected update: ${connected}`);
|
||||
}),
|
||||
),
|
||||
);
|
||||
|
||||
const disconnectReason$ = scope.behavior(
|
||||
combineLatest([syncing$, membershipConnected$, certainlyConnected$]).pipe(
|
||||
map(([syncing, membership, certainly]) => {
|
||||
if (!syncing) return "syncing" as const;
|
||||
if (!membership) return "membershipConnected" as const;
|
||||
if (!certainly) return "certainlyConnected" as const;
|
||||
if (!syncing) return "sync" as const;
|
||||
if (!membership) return "membership" as const;
|
||||
if (!certainly) return "probablyLeft" as const;
|
||||
return null;
|
||||
}),
|
||||
tap((reason) => {
|
||||
logger.info(`Homeserver connected update: ${reason ?? "connected"}`);
|
||||
}),
|
||||
),
|
||||
null,
|
||||
);
|
||||
|
||||
return { combined$, rtsSession$, disconnectReason$ };
|
||||
return { combined$, rtsSession$ };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user