mirror of
https://github.com/vector-im/element-call.git
synced 2026-11-28 10:01:09 +08:00
Mark everything below the CallView with Pick<>
This commit is contained in:
+3
-1
@@ -220,7 +220,8 @@ export const ElementCall: FC<ElementCallProps> = ({
|
||||
// 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<ElementCallProps> = ({
|
||||
>
|
||||
<CallView
|
||||
client={client}
|
||||
room={room}
|
||||
rtcSession={rtcSession}
|
||||
isPasswordlessUser={false}
|
||||
confineToRoom={params.confineToRoom}
|
||||
|
||||
@@ -37,7 +37,12 @@ interface UseProfile extends ProfileLoadState {
|
||||
saveProfile: ProfileSaveCallback;
|
||||
}
|
||||
|
||||
export function useProfile(client: MatrixClient | undefined): UseProfile {
|
||||
export type ProfileClientParts = Pick<
|
||||
MatrixClient,
|
||||
"getUserId" | "getUser" | "setDisplayName" | "setAvatarUrl" | "uploadContent"
|
||||
>;
|
||||
|
||||
export function useProfile(client: ProfileClientParts | undefined): UseProfile {
|
||||
const [{ success, loading, displayName, avatarUrl, error }, setState] =
|
||||
useState<ProfileLoadState>(() => {
|
||||
let user: User | undefined = undefined;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -184,6 +184,7 @@ function createCallView(
|
||||
const callView = (
|
||||
<CallView
|
||||
client={client}
|
||||
room={room}
|
||||
isPasswordlessUser={false}
|
||||
confineToRoom={false}
|
||||
preload={options.preload ?? false}
|
||||
|
||||
+14
-6
@@ -87,8 +87,16 @@ declare global {
|
||||
}
|
||||
|
||||
interface Props {
|
||||
/** The client to place the call with. */
|
||||
/**
|
||||
* The client to place the call with. Whole, because the call's RTC slot
|
||||
* takes the whole client.
|
||||
*/
|
||||
client: MatrixClient;
|
||||
/**
|
||||
* The room to call in. Whole, because the call's RTC slot takes the whole
|
||||
* room.
|
||||
*/
|
||||
room: Room;
|
||||
/** The call to join. */
|
||||
rtcSession: MatrixRTCSession;
|
||||
/**
|
||||
@@ -149,6 +157,7 @@ interface LoadedProps extends Props {
|
||||
/** {@link CallView}, once it has the mute state everything below needs. */
|
||||
const LoadedCallView: FC<LoadedProps> = ({
|
||||
client,
|
||||
room,
|
||||
isPasswordlessUser,
|
||||
confineToRoom,
|
||||
preload,
|
||||
@@ -233,13 +242,12 @@ const LoadedCallView: FC<LoadedProps> = ({
|
||||
|
||||
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<LoadedProps> = ({
|
||||
if (isPasswordlessUser || PosthogAnalytics.instance.isEnabled()) {
|
||||
body = (
|
||||
<CallEndedView
|
||||
endedCallId={rtcSession.room.roomId}
|
||||
endedCallId={room.roomId}
|
||||
client={client}
|
||||
isPasswordlessUser={isPasswordlessUser}
|
||||
hideHeader={header === HeaderStyle.None}
|
||||
|
||||
+11
-3
@@ -31,7 +31,11 @@ import { useRootElement } from "../RootElementContext";
|
||||
import { observeElementSize$ } from "../utils/elementSize";
|
||||
import styles from "./InCallView.module.css";
|
||||
import { GridTile } from "../tile/GridTile";
|
||||
import { SettingsModal, defaultSettingsTab } from "../settings/SettingsModal";
|
||||
import {
|
||||
SettingsModal,
|
||||
type SettingsClientParts,
|
||||
defaultSettingsTab,
|
||||
} from "../settings/SettingsModal";
|
||||
import { useRageshakeRequestModal } from "../settings/submit-rageshake";
|
||||
import { RageshakeRequestModal } from "./RageshakeRequestModal";
|
||||
import { useWakeLock } from "../useWakeLock";
|
||||
@@ -132,6 +136,10 @@ export interface ActiveCallProps extends Omit<
|
||||
InCallViewProps,
|
||||
"vm" | "footerVm" | "developerSettingsVm"
|
||||
> {
|
||||
/** 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<ActiveCallProps> = (props) => {
|
||||
};
|
||||
|
||||
export interface InCallViewProps {
|
||||
client: MatrixClient;
|
||||
client: SettingsClientParts;
|
||||
vm: CallViewModel;
|
||||
footerVm: ViewModel<FooterSnapshot>;
|
||||
developerSettingsVm: ViewModel<DeveloperSettingsSnapshot>;
|
||||
matrixInfo: MatrixInfo;
|
||||
rtcSession: MatrixRTCSession;
|
||||
matrixRoom: MatrixRoom;
|
||||
matrixRoom: Pick<MatrixRoom, "roomId">;
|
||||
muteStates: MuteStates;
|
||||
onShareClick: (() => void) | null;
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ import { useRoomEncryptionSystem } from "../e2ee/sharedKeyManagement";
|
||||
import { QrCode } from "../QrCode";
|
||||
|
||||
interface Props {
|
||||
room: Room;
|
||||
room: Pick<Room, "roomId" | "name">;
|
||||
open: boolean;
|
||||
onDismiss: () => void;
|
||||
}
|
||||
|
||||
@@ -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<LocalVideoMediaTrack | null>(null);
|
||||
|
||||
interface Props {
|
||||
client: MatrixClient;
|
||||
client: SettingsClientParts;
|
||||
matrixInfo: MatrixInfo;
|
||||
/** The media to open the devices on; the join takes it over. */
|
||||
media: LocalMedia;
|
||||
|
||||
@@ -104,6 +104,7 @@ export const RoomPage: FC = (): ReactNode => {
|
||||
return (
|
||||
<CallView
|
||||
client={client!}
|
||||
room={groupCallState.rtcSession.room}
|
||||
rtcSession={groupCallState.rtcSession}
|
||||
isPasswordlessUser={passwordlessUser}
|
||||
confineToRoom={confineToRoom}
|
||||
|
||||
@@ -7,10 +7,10 @@ Please see LICENSE in the repository root for full details.
|
||||
|
||||
import { useCallback } from "react";
|
||||
|
||||
import type { JoinRule, Room } from "matrix-js-sdk";
|
||||
import { useRoomState } from "./useRoomState";
|
||||
import type { JoinRule } from "matrix-js-sdk";
|
||||
import { type RoomStateParts, useRoomState } from "./useRoomState";
|
||||
|
||||
export function useJoinRule(room: Room): JoinRule {
|
||||
export function useJoinRule(room: RoomStateParts): JoinRule {
|
||||
return useRoomState(
|
||||
room,
|
||||
useCallback((state) => state.getJoinRule(), []),
|
||||
|
||||
@@ -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<Room, "getMxcAvatarUrl">,
|
||||
): string | null {
|
||||
return useRoomState(
|
||||
room,
|
||||
useCallback(() => room.getMxcAvatarUrl(), [room]),
|
||||
|
||||
@@ -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<Room, "name" | "on" | "off">;
|
||||
|
||||
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 => {};
|
||||
|
||||
@@ -15,13 +15,18 @@ import {
|
||||
|
||||
import { useTypedEventEmitterState } from "../useEvents";
|
||||
|
||||
export type RoomStateParts = Pick<Room, "currentState" | "on" | "off">;
|
||||
|
||||
/**
|
||||
* 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<T>(room: Room, f: (state: RoomState) => T): T {
|
||||
export function useRoomState<T>(
|
||||
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(
|
||||
|
||||
@@ -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 }) => (
|
||||
</p>
|
||||
);
|
||||
|
||||
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[];
|
||||
|
||||
@@ -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<Props> = ({ client }) => {
|
||||
const { t } = useTranslation();
|
||||
|
||||
@@ -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[];
|
||||
|
||||
+2
-2
@@ -43,7 +43,7 @@ export function useTypedEventEmitter<
|
||||
Arguments extends ListenerMap<Events>,
|
||||
T extends Events,
|
||||
>(
|
||||
emitter: TypedEventEmitter<Events, Arguments>,
|
||||
emitter: Pick<TypedEventEmitter<Events, Arguments>, "on" | "off">,
|
||||
eventType: T,
|
||||
listener: Listener<Events, Arguments, T>,
|
||||
): void {
|
||||
@@ -66,7 +66,7 @@ export function useTypedEventEmitterState<
|
||||
T extends Events,
|
||||
State,
|
||||
>(
|
||||
emitter: TypedEventEmitter<Events, Arguments>,
|
||||
emitter: Pick<TypedEventEmitter<Events, Arguments>, "on" | "off">,
|
||||
eventType: T,
|
||||
getState: () => State,
|
||||
): State {
|
||||
|
||||
Reference in New Issue
Block a user