Merge pull request #1306 from vector-im/SimonBrandner/fix/auto-mute

This commit is contained in:
Šimon Brandner
2023-07-25 15:35:04 +02:00
committed by GitHub
4 changed files with 17 additions and 13 deletions

View File

@@ -37,6 +37,12 @@ import { findDeviceByName } from "../media-utils";
import { OpenIDLoader } from "../livekit/OpenIDLoader"; import { OpenIDLoader } from "../livekit/OpenIDLoader";
import { ActiveCall } from "./InCallView"; import { ActiveCall } from "./InCallView";
/**
* If there already is this many participants in the call, we automatically mute
* the user
*/
const MUTE_PARTICIPANT_COUNT = 8;
declare global { declare global {
interface Window { interface Window {
groupCall?: GroupCall; groupCall?: GroupCall;
@@ -229,6 +235,8 @@ export function GroupCallView({
groupCall.enter(); groupCall.enter();
}, [groupCall]); }, [groupCall]);
console.log("LOG participant size", participants.size);
if (error) { if (error) {
return <ErrorView error={error} />; return <ErrorView error={error} />;
} else if (state === GroupCallState.Entered && userChoices) { } else if (state === GroupCallState.Entered && userChoices) {
@@ -293,7 +301,7 @@ export function GroupCallView({
setUserChoices(choices); setUserChoices(choices);
enter(); enter();
}} }}
muteAudio={participants.size > 8} initWithMutedAudio={participants.size > MUTE_PARTICIPANT_COUNT}
isEmbedded={isEmbedded} isEmbedded={isEmbedded}
hideHeader={hideHeader} hideHeader={hideHeader}
/> />

View File

@@ -33,7 +33,7 @@ interface Props {
onEnter: (userChoices: UserChoices) => void; onEnter: (userChoices: UserChoices) => void;
isEmbedded: boolean; isEmbedded: boolean;
hideHeader: boolean; hideHeader: boolean;
muteAudio: boolean; initWithMutedAudio: boolean;
} }
export function LobbyView(props: Props) { export function LobbyView(props: Props) {
@@ -67,7 +67,7 @@ export function LobbyView(props: Props) {
<div className={styles.joinRoomContent}> <div className={styles.joinRoomContent}>
<VideoPreview <VideoPreview
matrixInfo={props.matrixInfo} matrixInfo={props.matrixInfo}
muteAudio={props.muteAudio} initWithMutedAudio={props.initWithMutedAudio}
onUserChoicesChanged={setUserChoices} onUserChoicesChanged={setUserChoices}
/> />
<Trans> <Trans>

View File

@@ -40,13 +40,13 @@ export type MatrixInfo = {
interface Props { interface Props {
matrixInfo: MatrixInfo; matrixInfo: MatrixInfo;
muteAudio: boolean; initWithMutedAudio: boolean;
onUserChoicesChanged: (choices: UserChoices) => void; onUserChoicesChanged: (choices: UserChoices) => void;
} }
export function VideoPreview({ export function VideoPreview({
matrixInfo, matrixInfo,
muteAudio, initWithMutedAudio,
onUserChoicesChanged, onUserChoicesChanged,
}: Props) { }: Props) {
const { client } = useClient(); const { client } = useClient();
@@ -69,13 +69,9 @@ export function VideoPreview({
// Create local media tracks. // Create local media tracks.
const [videoEnabled, setVideoEnabled] = useState<boolean>(true); const [videoEnabled, setVideoEnabled] = useState<boolean>(true);
const [audioEnabled, setAudioEnabled] = useState<boolean>(!muteAudio); const [audioEnabled, setAudioEnabled] = useState<boolean>(
!initWithMutedAudio
useEffect(() => { );
if (muteAudio) {
setAudioEnabled(false);
}
}, [muteAudio]);
// The settings are updated as soon as the device changes. We wrap the settings value in a ref to store their initial value. // The settings are updated as soon as the device changes. We wrap the settings value in a ref to store their initial value.
// Not changing the device options prohibits the usePreviewTracks hook to recreate the tracks. // Not changing the device options prohibits the usePreviewTracks hook to recreate the tracks.

View File

@@ -171,7 +171,7 @@ export function useGroupCall(
isScreensharing: false, isScreensharing: false,
screenshareFeeds: [], screenshareFeeds: [],
requestingScreenshare: false, requestingScreenshare: false,
participants: new Map(), participants: getParticipants(groupCall),
hasLocalParticipant: false, hasLocalParticipant: false,
}); });