mirror of
https://github.com/vector-im/element-call.git
synced 2026-10-16 23:45:50 +00:00
- session -> matrixrtc (folder) - move MatrixRtcClient to top level of sdk - RtcTransport -> Transport - backend -> media-backend
38 lines
1.3 KiB
TypeScript
38 lines
1.3 KiB
TypeScript
/*
|
|
Copyright 2026 Element Creations Ltd.
|
|
|
|
SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
|
|
Please see LICENSE in the repository root for full details.
|
|
*/
|
|
|
|
import { type MatrixRTCError, type ConnectionStatus } from "../api";
|
|
import { type LocalMemberState, TransportState } from "./LocalMember";
|
|
|
|
/** The local member's state, collapsed to what a host shows. */
|
|
export function sessionStatus(
|
|
state: LocalMemberState,
|
|
joinRequested: boolean,
|
|
connected: boolean,
|
|
reconnecting: boolean,
|
|
): ConnectionStatus {
|
|
if (fatalError(state) !== null) return "disconnected";
|
|
if (state === TransportState.Waiting) return "waitingForTransport";
|
|
if (connected) return "connected";
|
|
if (reconnecting) return "reconnecting";
|
|
return joinRequested ? "connecting" : "disconnected";
|
|
}
|
|
|
|
/** The error that stops the session, if the state holds one. */
|
|
export function fatalError(state: LocalMemberState): MatrixRTCError | null {
|
|
if (state === TransportState.Waiting) return null;
|
|
if (state instanceof Error) return state;
|
|
if (state.matrix instanceof Error) return state.matrix;
|
|
if (
|
|
typeof state.media === "object" &&
|
|
"connection" in state.media &&
|
|
state.media.connection instanceof Error
|
|
)
|
|
return state.media.connection;
|
|
return null;
|
|
}
|