From 94ff2d1d7dc28e3d2ee4298a38e118579c2ca0bc Mon Sep 17 00:00:00 2001 From: Timo K Date: Sun, 12 Oct 2025 19:33:45 +0200 Subject: [PATCH] Add call button to header Signed-off-by: Timo K --- src/app/features/room/RoomView.tsx | 2 +- src/app/features/room/RoomViewHeader.tsx | 39 ++++++++++++++++++++++-- src/app/hooks/useCallOngoing.ts | 29 ++++++++++++++++++ 3 files changed, 67 insertions(+), 3 deletions(-) create mode 100644 src/app/hooks/useCallOngoing.ts diff --git a/src/app/features/room/RoomView.tsx b/src/app/features/room/RoomView.tsx index 8e79b31d..9c30de3a 100644 --- a/src/app/features/room/RoomView.tsx +++ b/src/app/features/room/RoomView.tsx @@ -96,7 +96,7 @@ export function RoomView({ room, eventId }: { room: Room; eventId?: string }) { return ( - + setShowCall(true)} callJoined={callJoined} /> {showCall && ( (({ room, requestClose ); }); - -export function RoomViewHeader() { +interface RoomViewHeaderProps { + onCallClick?: () => void; + callJoined?: boolean; +} +export function RoomViewHeader({ onCallClick, callJoined }: RoomViewHeaderProps) { const navigate = useNavigate(); const mx = useMatrixClient(); const useAuthentication = useMediaAuthentication(); @@ -274,6 +278,7 @@ export function RoomViewHeader() { const avatarUrl = avatarMxc ? mxcUrlToHttp(mx, avatarMxc, useAuthentication, 96, 96, 'crop') ?? undefined : undefined; + const callOngoing = useCallOngoing(room); const [peopleDrawer, setPeopleDrawer] = useSetting(settingsAtom, 'isPeopleDrawer'); @@ -295,6 +300,9 @@ export function RoomViewHeader() { setPinMenuAnchor(evt.currentTarget.getBoundingClientRect()); }; + const notParticipatingState = callOngoing ? 'join' : 'start'; + const buttonState = callJoined ? 'participating' : notParticipatingState; + return ( @@ -387,6 +395,33 @@ export function RoomViewHeader() { )} )} + + + {buttonState === 'start' && Start Call} + {buttonState === 'join' && Join Call} + {buttonState === 'participating' && Call Ongoing} + + } + > + {(triggerRef) => ( + + {buttonState === 'join' && Join} + + + )} + + { + const [callOngoing, setCallOngoing] = useState( + room.client.matrixRTC.getRoomSession(room).memberships.length > 0 + ); + + useEffect(() => { + const start = (roomId: string) => { + if (roomId !== room.roomId) return; + setCallOngoing(true); + }; + const end = (roomId: string) => { + if (roomId !== room.roomId) return; + setCallOngoing(false); + }; + room.client.matrixRTC.on(MatrixRTCSessionManagerEvents.SessionStarted, start); + room.client.matrixRTC.on(MatrixRTCSessionManagerEvents.SessionEnded, end); + return () => { + room.client.matrixRTC.off(MatrixRTCSessionManagerEvents.SessionStarted, start); + room.client.matrixRTC.off(MatrixRTCSessionManagerEvents.SessionEnded, end); + }; + }, [room]); + + return callOngoing; +};