From fd19a57ec18ad0e6d3d962be7366439a0da3f1bd Mon Sep 17 00:00:00 2001 From: Timo Date: Mon, 11 Nov 2024 18:18:32 +0100 Subject: [PATCH] review --- public/locales/en-GB/app.json | 2 +- src/room/GroupCallView.tsx | 47 ++++++++++++++++------------------- src/room/RoomPage.tsx | 22 ++++------------ src/room/useLoadGroupCall.ts | 2 +- 4 files changed, 29 insertions(+), 44 deletions(-) diff --git a/public/locales/en-GB/app.json b/public/locales/en-GB/app.json index fc01bf1c..d64ea9dd 100644 --- a/public/locales/en-GB/app.json +++ b/public/locales/en-GB/app.json @@ -82,7 +82,7 @@ "failed_heading": "Failed to join", "failed_text": "Call not found or is not accessible.", "knock_reject_body": "Your request was declined.", - "knock_reject_heading": "Access Denied", + "knock_reject_heading": "Access denied", "reason": "Reason" }, "hangup_button_label": "End call", diff --git a/src/room/GroupCallView.tsx b/src/room/GroupCallView.tsx index 81895aa8..86feaaaa 100644 --- a/src/room/GroupCallView.tsx +++ b/src/room/GroupCallView.tsx @@ -134,13 +134,6 @@ export const GroupCallView: FC = ({ const latestMuteStates = useRef(); latestMuteStates.current = muteStates; - useEffect(() => { - // skip lobby if we are not in widget mode; - if (!widget && skipLobby) { - void enterRTCSession(rtcSession, perParticipantE2EE); - } - }, [perParticipantE2EE, rtcSession, skipLobby]); - useEffect(() => { const defaultDeviceSetup = async ( requestedDeviceData: JoinCallData, @@ -184,29 +177,33 @@ export const GroupCallView: FC = ({ } }; - if (widget && preload && skipLobby) { - // In preload mode without lobby we wait for a join action before entering - const onJoin = (ev: CustomEvent): void => { + if (skipLobby) { + if (widget && preload) { + // In preload mode without lobby we wait for a join action before entering + const onJoin = (ev: CustomEvent): void => { + (async (): Promise => { + await defaultDeviceSetup(ev.detail.data as unknown as JoinCallData); + await enterRTCSession(rtcSession, perParticipantE2EE); + widget!.api.transport.reply(ev.detail, {}); + })().catch((e) => { + logger.error("Error joining RTC session", e); + }); + }; + widget.lazyActions.on(ElementWidgetActions.JoinCall, onJoin); + return (): void => { + widget!.lazyActions.off(ElementWidgetActions.JoinCall, onJoin); + }; + } else if (widget && !preload) { + // No lobby and no preload: we enter the rtc session right away (async (): Promise => { - await defaultDeviceSetup(ev.detail.data as unknown as JoinCallData); + await defaultDeviceSetup({ audioInput: null, videoInput: null }); await enterRTCSession(rtcSession, perParticipantE2EE); - widget!.api.transport.reply(ev.detail, {}); })().catch((e) => { logger.error("Error joining RTC session", e); }); - }; - widget.lazyActions.on(ElementWidgetActions.JoinCall, onJoin); - return (): void => { - widget!.lazyActions.off(ElementWidgetActions.JoinCall, onJoin); - }; - } else if (widget && !preload && skipLobby) { - // No lobby and no preload: we enter the rtc session right away - (async (): Promise => { - await defaultDeviceSetup({ audioInput: null, videoInput: null }); - await enterRTCSession(rtcSession, perParticipantE2EE); - })().catch((e) => { - logger.error("Error joining RTC session", e); - }); + } else { + void enterRTCSession(rtcSession, perParticipantE2EE); + } } }, [rtcSession, preload, skipLobby, perParticipantE2EE]); diff --git a/src/room/RoomPage.tsx b/src/room/RoomPage.tsx index 11d5881e..002dbb6d 100644 --- a/src/room/RoomPage.tsx +++ b/src/room/RoomPage.tsx @@ -5,7 +5,7 @@ SPDX-License-Identifier: AGPL-3.0-only Please see LICENSE in the repository root for full details. */ -import { FC, useEffect, useState, useCallback, ReactNode, useRef } from "react"; +import { FC, useEffect, useState, ReactNode, useRef } from "react"; import { logger } from "matrix-js-sdk/src/logger"; import { useTranslation } from "react-i18next"; import { CheckIcon } from "@vector-im/compound-design-tokens/assets/web/icons"; @@ -55,7 +55,7 @@ export const RoomPage: FC = () => { useClientLegacy(); const { avatarUrl, displayName: userDisplayName } = useProfile(client); - const groupCallState = useLoadGroupCall(roomIdOrAlias, viaServers, client); + const groupCallState = useLoadGroupCall(client, roomIdOrAlias, viaServers); const muteStates = useMuteStates(); useEffect(() => { @@ -88,12 +88,12 @@ export const RoomPage: FC = () => { const wasInWaitForInviteState = useRef(false); useEffect(() => { - if (groupCallState.kind === "loaded" && wasInWaitForInviteState) { + if (groupCallState.kind === "loaded" && wasInWaitForInviteState.current) { logger.log("Play join sound 'Not yet implemented'"); } }, [groupCallState.kind]); - const groupCallView = useCallback((): JSX.Element => { + const groupCallView = (): JSX.Element => { switch (groupCallState.kind) { case "loaded": return ( @@ -190,19 +190,7 @@ export const RoomPage: FC = () => { default: return <> ; } - }, [ - groupCallState, - client, - passwordlessUser, - confineToRoom, - preload, - skipLobby, - hideHeader, - muteStates, - t, - userDisplayName, - avatarUrl, - ]); + }; let content: ReactNode; if (loading || isRegistering) { diff --git a/src/room/useLoadGroupCall.ts b/src/room/useLoadGroupCall.ts index 5fd4ad38..163571c8 100644 --- a/src/room/useLoadGroupCall.ts +++ b/src/room/useLoadGroupCall.ts @@ -117,9 +117,9 @@ export class CallTerminatedMessage extends Error { } export const useLoadGroupCall = ( + client: MatrixClient | undefined, roomIdOrAlias: string | null, viaServers: string[], - client?: MatrixClient, ): GroupCallStatus => { const [state, setState] = useState({ kind: "loading" }); const activeRoom = useRef();