Files
element-call-Github/src/state/initialMuteState.ts
T
Timo K. 273ee3b632 add allowJoinUnmutedViaIntent to the bridge
This allows us to control to never start unmuted in spa but be able to
start unmuted in widget and component mode.
2026-09-08 18:12:40 +02:00

50 lines
1.7 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 { logger } from "matrix-js-sdk/lib/logger";
import { type RTCCallIntent } from "matrix-js-sdk/lib/matrixrtc";
/**
* Calculates the initial mute state for media devices based on configuration.
*
* It is not always possible to start the call with audio/video unmuted due to
* privacy concerns. This function encapsulates the logic to determine the
* appropriate initial state.
*
* @param allowJoinUnmutedViaIntent Whether the host vouches for the intent
* enough to start the user unmuted without a lobby (see
* `HostBridge.allowJoinUnmutedViaIntent`).
*/
export function calculateInitialMuteState(
skipLobby: boolean,
callIntent: RTCCallIntent | undefined,
allowJoinUnmutedViaIntent: boolean,
): { audioEnabled: boolean; videoEnabled: boolean } {
logger.debug(
`calculateInitialMuteState: skipLobby=${skipLobby}, callIntent=${callIntent} allowJoinUnmutedViaIntent=${allowJoinUnmutedViaIntent}`,
);
if (skipLobby && !allowJoinUnmutedViaIntent) {
// The lobby is skipped, so the user gets no chance to adjust their devices
// before joining, and nobody has vouched for the intent: default to muted
// to protect their privacy.
return {
audioEnabled: false,
videoEnabled: false,
};
}
// A host that vouches for the intent is a trusted environment, so it allows
// unmuted by default. Same for when showing a lobby, as users can adjust
// their settings there. Additionally, if the call intent is "audio", we
// disable video by default.
return {
audioEnabled: true,
videoEnabled: callIntent != "audio",
};
}