Make the room Picks transparent up to the component.

This commit is contained in:
Timo K. committed 2026-11-20 00:11:06 +01:00
1 parent ab7d2d3893
commit f934cd158f
9 files changed
+134 -46

No files matched your search

+37 -2
View File
@@ -50,6 +50,7 @@ import {
} from "react";
import { logger } from "matrix-js-sdk/lib/logger";
import { MatrixRTCSession } from "matrix-js-sdk/lib/matrixrtc";
import { type Room } from "matrix-js-sdk";
import { I18nextProvider } from "react-i18next";
import { TooltipProvider } from "@vector-im/compound-web";
import { ErrorBoundary } from "@sentry/react";
@@ -205,7 +206,41 @@ export const ElementCall: FC<ElementCallProps> = ({
};
}, [controlledAudioDevices, callIntent]);
const room = client.getRoom(roomId);
// The host's `Room`, from the host's copy of matrix-js-sdk: only the parts
// listed here are what we rely on.
// So only breaking changes in those methods/props would break Compoenent EC.
const room = client.getRoom(roomId) as Pick<
Room,
// Everywhere: the RTC session, analytics, e2ee keys, invite link, RTC slot,
// call view model
| "roomId"
// RTC session: memberships from the timeline and room state
| "getLiveTimeline"
| "hasMembershipState"
| "getVersion"
// RTC session and call view model: sticky memberships and call
// notifications
| "_unstable_getStickyEvents"
// Room name for the header and invite link
| "name"
// Room avatar for the header
| "getMxcAvatarUrl"
// `matrixInfo.roomAlias`
| "getCanonicalAlias"
// Room state for the avatar and join rule hooks
| "currentState"
// Joined and invited members, for the RTC slot and the call view model
| "getMembersWithMembership"
// `on`/`off`, to listen for:
// - the RTC session's room events
// - `RoomEvent.Name` (room name)
// - `RoomEvent.CurrentStateUpdated` (avatar and join rule hooks)
// - `RoomStateEvent.Events` (RTC slot status)
// - `RoomStateEvent.Members` (RTC slot and call view model members)
// - `RoomEvent.Timeline` and `RoomStickyEventsEvent.Update` (call notifications)
| "on"
| "off"
> | null;
// A session of our own rather than `client.matrixRTC.getRoomSession`: the
// client is the host's, built from the host's copy of matrix-js-sdk, so the
@@ -220,7 +255,7 @@ export const ElementCall: FC<ElementCallProps> = ({
};
// It is important we create a session from the js-sdk and dont inherit from
// the host passed client.
const session = MatrixRTCSession.sessionForSlot(client, room, slot);
const session = new MatrixRTCSession(client, room, slot);
setRtcSession(session);
return (): void => {
setRtcSession(null);
+7 -1
View File
@@ -48,6 +48,8 @@ import {
} from "./matrixrtc/Members";
import { createTransportRegistry } from "./matrixrtc/Transports";
/**
* Takes the whole `MatrixClient` rather than a slice of it. The js-sdk is the
* MatrixRTC implementation today; when the rust-rtc crate replaces it, the SDK
@@ -61,7 +63,11 @@ import { createTransportRegistry } from "./matrixrtc/Transports";
export function createRTCSlot(
scope: ObservableScope,
client: MatrixClient,
room: Room,
// The parts of the Matrix room a slot reads. `on` and `off` are only there for
// `fromEvent`, which listens on the room for:
// - `RoomStateEvent.Events`, to update the slot status;
// - `RoomStateEvent.Members`, to update the members' display names and avatars.
room: Pick<Room, "roomId" | "getMembersWithMembership" | "on" | "off">,
options: RTCSlotOptions,
jsSdkSession: JsSdkRTCSession,
): RTCSlot {
+5 -2
View File
@@ -23,7 +23,9 @@ export type RoomMemberMap = Map<
string,
Pick<RoomMember, "userId" | "getMxcAvatarUrl" | "rawDisplayName">
>;
export function roomToMembersMap(matrixRoom: MatrixRoom): RoomMemberMap {
export function roomToMembersMap(
matrixRoom: Pick<MatrixRoom, "getMembersWithMembership">,
): RoomMemberMap {
const members = matrixRoom
.getMembersWithMembership(KnownMembership.Join)
.concat(matrixRoom.getMembersWithMembership(KnownMembership.Invite));
@@ -37,9 +39,10 @@ export function roomToMembersMap(matrixRoom: MatrixRoom): RoomMemberMap {
}, new Map());
}
/** Listens for `RoomStateEvent.Members` on the room. */
export function createRoomMembers$(
scope: ObservableScope,
matrixRoom: MatrixRoom,
matrixRoom: Pick<MatrixRoom, "getMembersWithMembership" | "on" | "off">,
): Behavior<RoomMemberMap> {
return scope.behavior(
fromEvent(matrixRoom, RoomStateEvent.Members).pipe(
+26 -13
View File
@@ -92,11 +92,32 @@ interface Props {
* 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 room to call in. */
room: Pick<
Room,
// Everywhere: analytics, e2ee keys, invite link, RTC slot, call view model
| "roomId"
// Room name for the header and invite link
| "name"
// Room avatar for the header
| "getMxcAvatarUrl"
// `matrixInfo.roomAlias`
| "getCanonicalAlias"
// Room state for the avatar and join rule hooks
| "currentState"
// Joined and invited members, for the RTC slot and the call view model
| "getMembersWithMembership"
// Call notifications, for the call view model
| "_unstable_getStickyEvents"
// `on`/`off`, to listen for:
// - `RoomEvent.Name` (room name)
// - `RoomEvent.CurrentStateUpdated` (avatar and join rule hooks)
// - `RoomStateEvent.Events` (RTC slot status)
// - `RoomStateEvent.Members` (RTC slot and call view model members)
// - `RoomEvent.Timeline` and `RoomStickyEventsEvent.Update` (call notifications)
| "on"
| "off"
>;
/** The call to join. */
rtcSession: MatrixRTCSession;
/**
@@ -240,14 +261,6 @@ const LoadedCallView: FC<LoadedProps> = ({
},
);
useEffect(() => {
// Sanity check the room object
if (client.getRoom(room.roomId) !== room)
logger.warn(
`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, room]);
const { displayName, avatarUrl } = useProfile(client);
const roomName = useRoomName(room);
const roomAvatar = useRoomAvatar(room);
+15 -2
View File
@@ -138,8 +138,21 @@ export interface ActiveCallProps extends Omit<
> {
/** Whole, because {@link createRTCSlot} takes the whole client. */
client: MatrixClient;
/** Whole, because {@link createRTCSlot} takes the whole room. */
matrixRoom: MatrixRoom;
matrixRoom: Pick<
MatrixRoom,
// RTC slot and call view model
| "roomId"
// Joined and invited members, for the RTC slot and the call view model
| "getMembersWithMembership"
// Call notifications, for the call view model
| "_unstable_getStickyEvents"
// `on`/`off`, to listen for:
// - `RoomStateEvent.Events` (RTC slot status)
// - `RoomStateEvent.Members` (RTC slot and call view model members)
// - `RoomEvent.Timeline` and `RoomStickyEventsEvent.Update` (call notifications)
| "on"
| "off"
>;
e2eeSystem: EncryptionSystem;
/** The tracks the lobby opened, for the join to publish. */
media: LocalMedia;
+15 -3
View File
@@ -51,9 +51,9 @@ export const RoomPage: FC = (): ReactNode => {
// The page title is the page's to set, not the call's: a host embedding the
// call has a title of its own. So it is set here, for whichever room we have
// got as far as knowing about.
const roomName = useRoomName(
groupCallState.kind === "loaded" ? groupCallState.rtcSession.room : null,
);
const loadedRoom =
groupCallState.kind === "loaded" ? groupCallState.rtcSession.room : null;
const roomName = useRoomName(loadedRoom);
usePageTitle(
roomName ??
(groupCallState.kind === "canKnock" ||
@@ -90,6 +90,18 @@ export const RoomPage: FC = (): ReactNode => {
if (optInAnalytics === null && setOptInAnalytics) setOptInAnalytics(true);
}, [optInAnalytics, setOptInAnalytics]);
useEffect(() => {
// Sanity check the room object
if (
client &&
loadedRoom !== null &&
client.getRoom(loadedRoom.roomId) !== loadedRoom
)
logger.warn(
`We've ended up with multiple rooms for the same ID (${loadedRoom.roomId}). This indicates a bug in the group call loading code, and may lead to incomplete room state.`,
);
}, [client, loadedRoom]);
const wasInWaitForInviteState = useRef<boolean>(false);
useEffect(() => {
+11 -2
View File
@@ -8,10 +8,19 @@ Please see LICENSE in the repository root for full details.
import { useCallback } from "react";
import { type Room } from "matrix-js-sdk";
import { type RoomStateParts, useRoomState } from "./useRoomState";
import { useRoomState } from "./useRoomState";
export function useRoomAvatar(
room: RoomStateParts & Pick<Room, "getMxcAvatarUrl">,
room: Pick<
Room,
// The avatar itself
| "getMxcAvatarUrl"
// Room state, and `on`/`off` for `RoomEvent.CurrentStateUpdated`, for
// `useRoomState`
| "currentState"
| "on"
| "off"
>,
): string | null {
return useRoomState(
room,
@@ -75,35 +75,32 @@ export function createSentCallNotification$(
}
export function createReceivedDecline$(
matrixRoom: Pick<
MatrixRoom,
"_unstable_getStickyEvents" | "addListener" | "removeListener"
>,
matrixRoom: Pick<MatrixRoom, "_unstable_getStickyEvents" | "on" | "off">,
): Observable<MatrixEvent> {
// A decline is sticky, so after a gappy sync it arrives only in the sticky
// section, which never reaches the timeline. Racing for the first outcome
// makes a decline seen in both places harmless.
const timeline$ = (
fromEvent(matrixRoom, RoomEvent.Timeline) as Observable<
Parameters<EventTimelineSetHandlerMap[RoomEvent.Timeline]>
>
).pipe(map(([event]) => event));
const timeline$ = fromEvent(
matrixRoom,
RoomEvent.Timeline,
(...[event]: Parameters<EventTimelineSetHandlerMap[RoomEvent.Timeline]>) =>
event,
);
// The decline can arrive via sync before the send of our notification
// resolves, which is when we start listening. To guard against this, we
// include what is already in the sticky section.
const currentSticky$ = defer(() =>
from(matrixRoom._unstable_getStickyEvents()),
);
const sticky$ = (
fromEvent(matrixRoom, RoomStickyEventsEvent.Update) as Observable<
Parameters<RoomStickyEventsMap[RoomStickyEventsEvent.Update]>
>
).pipe(
mergeMap(([added, updated]) => [
...added,
...updated.map(({ current }) => current),
]),
);
const sticky$ = fromEvent(
matrixRoom,
RoomStickyEventsEvent.Update,
(
...[added, updated]: Parameters<
RoomStickyEventsMap[RoomStickyEventsEvent.Update]
>
) => [...added, ...updated.map(({ current }) => current)],
).pipe(mergeMap((events) => events));
return merge(currentSticky$, sticky$, timeline$).pipe(
filter((event) => event.getType() === EventType.RTCDecline),
);
+2 -2
View File
@@ -199,8 +199,8 @@ export interface CallViewModelProps {
| "roomId"
| "getMembersWithMembership"
| "_unstable_getStickyEvents"
| "addListener"
| "removeListener"
| "on"
| "off"
>;
client: Pick<MatrixClient, "getUserId" | "getDeviceId">;
mediaDevices: MediaDevices;