diff --git a/component/index.tsx b/component/index.tsx index 2b96272e3..094151dcc 100644 --- a/component/index.tsx +++ b/component/index.tsx @@ -220,7 +220,8 @@ export const ElementCall: FC = ({ // is told that Element Call has loaded, as the widget tells its client once // its own initialisation is over. Once per mount, however often the pieces // are later swapped out. - const ready = container !== null && rtcSession !== null && vm !== null; + const ready = + container !== null && room !== null && rtcSession !== null && vm !== null; const announcedLoaded = useRef(false); useEffect(() => { if (!ready || announcedLoaded.current) return; @@ -257,6 +258,7 @@ export const ElementCall: FC = ({ > ; + +export function useProfile(client: ProfileClientParts | undefined): UseProfile { const [{ success, loading, displayName, avatarUrl, error }, setState] = useState(() => { let user: User | undefined = undefined; diff --git a/src/room/CallEndedView.tsx b/src/room/CallEndedView.tsx index 58417c38a..2700e754d 100644 --- a/src/room/CallEndedView.tsx +++ b/src/room/CallEndedView.tsx @@ -6,13 +6,12 @@ Please see LICENSE in the repository root for full details. */ import { type FC, type FormEventHandler, useCallback, useState } from "react"; -import { type MatrixClient } from "matrix-js-sdk"; import { Trans, useTranslation } from "react-i18next"; import { Button, Heading, Text } from "@vector-im/compound-web"; import styles from "./CallEndedView.module.css"; import feedbackStyle from "../input/FeedbackInput.module.css"; -import { useProfile } from "../profile/useProfile"; +import { type ProfileClientParts, useProfile } from "../profile/useProfile"; import { Header, HeaderLogo, LeftNav, RightNav } from "../Header"; import { PosthogAnalytics } from "../analytics/PosthogAnalytics"; import { FieldRow, InputField } from "../input/Input"; @@ -22,7 +21,7 @@ import { LeaveToHomeLink } from "../button/LeaveToHomeLink"; import { useLeaveToHome } from "../LeaveToHomeContext"; interface Props { - client: MatrixClient; + client: ProfileClientParts; isPasswordlessUser: boolean; hideHeader: boolean; confineToRoom: boolean; diff --git a/src/room/CallView.test.tsx b/src/room/CallView.test.tsx index ed747c56c..432c10bc1 100644 --- a/src/room/CallView.test.tsx +++ b/src/room/CallView.test.tsx @@ -184,6 +184,7 @@ function createCallView( const callView = ( = ({ client, + room, isPasswordlessUser, confineToRoom, preload, @@ -233,13 +242,12 @@ const LoadedCallView: FC = ({ useEffect(() => { // Sanity check the room object - if (client.getRoom(rtcSession.room.roomId) !== rtcSession.room) + if (client.getRoom(room.roomId) !== room) logger.warn( - `We've ended up with multiple rooms for the same ID (${rtcSession.room.roomId}). This indicates a bug in the group call loading code, and may lead to incomplete room state.`, + `We've ended up with multiple rooms for the same ID (${room.roomId}). This indicates a bug in the group call loading code, and may lead to incomplete room state.`, ); - }, [client, rtcSession.room]); + }, [client, room]); - const room = rtcSession.room as Room; const { displayName, avatarUrl } = useProfile(client); const roomName = useRoomName(room); const roomAvatar = useRoomAvatar(room); @@ -553,7 +561,7 @@ const LoadedCallView: FC = ({ if (isPasswordlessUser || PosthogAnalytics.instance.isEnabled()) { body = ( { + /** Whole, because {@link createRTCSlot} takes the whole client. */ + client: MatrixClient; + /** Whole, because {@link createRTCSlot} takes the whole room. */ + matrixRoom: MatrixRoom; e2eeSystem: EncryptionSystem; /** The tracks the lobby opened, for the join to publish. */ media: LocalMedia; @@ -281,13 +289,13 @@ export const ActiveCall: FC = (props) => { }; export interface InCallViewProps { - client: MatrixClient; + client: SettingsClientParts; vm: CallViewModel; footerVm: ViewModel; developerSettingsVm: ViewModel; matrixInfo: MatrixInfo; rtcSession: MatrixRTCSession; - matrixRoom: MatrixRoom; + matrixRoom: Pick; muteStates: MuteStates; onShareClick: (() => void) | null; } diff --git a/src/room/InviteModal.tsx b/src/room/InviteModal.tsx index 759dce302..e22595351 100644 --- a/src/room/InviteModal.tsx +++ b/src/room/InviteModal.tsx @@ -29,7 +29,7 @@ import { useRoomEncryptionSystem } from "../e2ee/sharedKeyManagement"; import { QrCode } from "../QrCode"; interface Props { - room: Room; + room: Pick; open: boolean; onDismiss: () => void; } diff --git a/src/room/LobbyView.tsx b/src/room/LobbyView.tsx index 89cd05b2c..6794e5ab7 100644 --- a/src/room/LobbyView.tsx +++ b/src/room/LobbyView.tsx @@ -7,7 +7,6 @@ Please see LICENSE in the repository root for full details. import { type FC, useCallback, useState, type JSX, useEffect } from "react"; import { useTranslation } from "react-i18next"; -import { type MatrixClient } from "matrix-js-sdk"; import { Button } from "@vector-im/compound-web"; import classNames from "classnames"; import { logger } from "matrix-js-sdk/lib/logger"; @@ -23,7 +22,11 @@ import { Header, LeftNav, RightNav, RoomHeaderInfo } from "../Header"; import { type MatrixInfo, VideoPreview } from "./VideoPreview"; import { type MuteStates } from "../state/MuteStates"; import { InviteButton } from "../button/InviteButton"; -import { SettingsModal, defaultSettingsTab } from "../settings/SettingsModal"; +import { + SettingsModal, + type SettingsClientParts, + defaultSettingsTab, +} from "../settings/SettingsModal"; import { useRootSizeMatches } from "../useRootSize"; import { E2eeType } from "../e2ee/e2eeType"; import { LeaveToHomeLink } from "../button/LeaveToHomeLink"; @@ -46,7 +49,7 @@ import { captureSettings } from "./InCallView"; const noVideoTrack = constant(null); interface Props { - client: MatrixClient; + client: SettingsClientParts; matrixInfo: MatrixInfo; /** The media to open the devices on; the join takes it over. */ media: LocalMedia; diff --git a/src/room/RoomPage.tsx b/src/room/RoomPage.tsx index 71bceea76..a1ca6c5ed 100644 --- a/src/room/RoomPage.tsx +++ b/src/room/RoomPage.tsx @@ -104,6 +104,7 @@ export const RoomPage: FC = (): ReactNode => { return ( state.getJoinRule(), []), diff --git a/src/room/useRoomAvatar.ts b/src/room/useRoomAvatar.ts index 7287c6521..32d7b1055 100644 --- a/src/room/useRoomAvatar.ts +++ b/src/room/useRoomAvatar.ts @@ -8,9 +8,11 @@ Please see LICENSE in the repository root for full details. import { useCallback } from "react"; import { type Room } from "matrix-js-sdk"; -import { useRoomState } from "./useRoomState"; +import { type RoomStateParts, useRoomState } from "./useRoomState"; -export function useRoomAvatar(room: Room): string | null { +export function useRoomAvatar( + room: RoomStateParts & Pick, +): string | null { return useRoomState( room, useCallback(() => room.getMxcAvatarUrl(), [room]), diff --git a/src/room/useRoomName.ts b/src/room/useRoomName.ts index f20b3b2a8..b6abe6735 100644 --- a/src/room/useRoomName.ts +++ b/src/room/useRoomName.ts @@ -12,9 +12,11 @@ import { useCallback, useSyncExternalStore } from "react"; * The room's name, kept up to date. Null when there is no room yet, for a * caller that only sometimes has one. */ -export function useRoomName(room: Room): string; -export function useRoomName(room: Room | null): string | null; -export function useRoomName(room: Room | null): string | null { +type RoomNameParts = Pick; + +export function useRoomName(room: RoomNameParts): string; +export function useRoomName(room: RoomNameParts | null): string | null; +export function useRoomName(room: RoomNameParts | null): string | null { const subscribe = useCallback( (onChange: () => void) => { if (room === null) return (): void => {}; diff --git a/src/room/useRoomState.ts b/src/room/useRoomState.ts index ad08f7a21..e80cdfdf2 100644 --- a/src/room/useRoomState.ts +++ b/src/room/useRoomState.ts @@ -15,13 +15,18 @@ import { import { useTypedEventEmitterState } from "../useEvents"; +export type RoomStateParts = Pick; + /** * A React hook for values computed from room state. * @param room The room. * @param f A mapping from the current room state to the computed value. * @returns The computed value. */ -export function useRoomState(room: Room, f: (state: RoomState) => T): T { +export function useRoomState( + room: RoomStateParts, + f: (state: RoomState) => T, +): T { // TODO: matrix-js-sdk says that Room.currentState is deprecated, but it's not // clear how to reactively track the current state of the room without it const currentState = useTypedEventEmitterState( diff --git a/src/settings/DeveloperSettingsTab.tsx b/src/settings/DeveloperSettingsTab.tsx index e303a4d0b..b664886b9 100644 --- a/src/settings/DeveloperSettingsTab.tsx +++ b/src/settings/DeveloperSettingsTab.tsx @@ -68,6 +68,7 @@ import { Slider } from "../Slider"; import { useUrlParams } from "../UrlParams"; import { authenticateWithTransport, + type AuthenticateWithTransportParams, type TransportMetadata, } from "@element-hq/matrixrtc-sdk"; import { useBehavior } from "../useBehavior"; @@ -111,8 +112,18 @@ const KeyRotationStatus: FC<{ info: KeyRotationInfo }> = ({ info }) => (

); +export type DeveloperSettingsClientParts = Pick< + MatrixClient, + | "doesServerSupportUnstableFeature" + | "getCrypto" + | "getUserId" + | "getDeviceId" + | "getDomain" +> & + AuthenticateWithTransportParams["client"]; + interface Props { - client: MatrixClient; + client: DeveloperSettingsClientParts; roomId?: string; /** The transports the client is connected to, while in a call. */ transports?: TransportInfo[]; diff --git a/src/settings/ProfileSettingsTab.tsx b/src/settings/ProfileSettingsTab.tsx index 7a4ac0770..905ed93a7 100644 --- a/src/settings/ProfileSettingsTab.tsx +++ b/src/settings/ProfileSettingsTab.tsx @@ -6,17 +6,16 @@ Please see LICENSE in the repository root for full details. */ import { type FC, useCallback, useEffect, useMemo, useRef } from "react"; -import { type MatrixClient } from "matrix-js-sdk"; import { useTranslation } from "react-i18next"; import { logger } from "matrix-js-sdk/lib/logger"; -import { useProfile } from "../profile/useProfile"; +import { type ProfileClientParts, useProfile } from "../profile/useProfile"; import { FieldRow, InputField, ErrorMessage } from "../input/Input"; import { AvatarInputField } from "../input/AvatarInputField"; import styles from "./ProfileSettingsTab.module.css"; interface Props { - client: MatrixClient; + client: ProfileClientParts; } export const ProfileSettingsTab: FC = ({ client }) => { const { t } = useTranslation(); diff --git a/src/settings/SettingsModal.tsx b/src/settings/SettingsModal.tsx index 773c886e8..248794808 100644 --- a/src/settings/SettingsModal.tsx +++ b/src/settings/SettingsModal.tsx @@ -7,13 +7,13 @@ Please see LICENSE in the repository root for full details. import { type FC, type ReactNode, useEffect, useState } from "react"; import { useTranslation } from "react-i18next"; -import { type MatrixClient } from "matrix-js-sdk"; import { Button, Root as Form, Separator } from "@vector-im/compound-web"; import { Modal } from "../Modal"; import styles from "./SettingsModal.module.css"; import { type Tab, TabContainer } from "../tabs/Tabs"; import { ProfileSettingsTab } from "./ProfileSettingsTab"; +import { type ProfileClientParts } from "../profile/useProfile"; import { FeedbackSettingsTab } from "./FeedbackSettingsTab"; import { iosDeviceMenu$ } from "../state/MediaDevices"; import { useMediaDevices } from "../MediaDevicesContext"; @@ -34,6 +34,7 @@ import { } from "../tracks/backgroundEffectCatalog"; import { DeveloperSettingsTab, + type DeveloperSettingsClientParts, type DeveloperSettingsSnapshot, type TransportInfo, } from "./DeveloperSettingsTab"; @@ -53,12 +54,15 @@ type SettingsTab = | "more" | "developer"; +export type SettingsClientParts = ProfileClientParts & + DeveloperSettingsClientParts; + interface Props { open: boolean; onDismiss: () => void; tab: SettingsTab; onTabChange: (tab: SettingsTab) => void; - client: MatrixClient; + client: SettingsClientParts; roomId?: string; /** The transports the client is connected to, while in a call. */ transports?: TransportInfo[]; diff --git a/src/useEvents.ts b/src/useEvents.ts index 3495cc574..69a169572 100644 --- a/src/useEvents.ts +++ b/src/useEvents.ts @@ -43,7 +43,7 @@ export function useTypedEventEmitter< Arguments extends ListenerMap, T extends Events, >( - emitter: TypedEventEmitter, + emitter: Pick, "on" | "off">, eventType: T, listener: Listener, ): void { @@ -66,7 +66,7 @@ export function useTypedEventEmitterState< T extends Events, State, >( - emitter: TypedEventEmitter, + emitter: Pick, "on" | "off">, eventType: T, getState: () => State, ): State {