Add room id routing

This commit is contained in:
Robert Long 2021-12-10 13:44:06 -08:00
parent 8c287ffcb0
commit c5728b2f66
5 changed files with 37 additions and 18 deletions

View file

@ -1,22 +1,23 @@
import React from "react"; import React, { useMemo } from "react";
import { Link } from "react-router-dom"; import { Link } from "react-router-dom";
import { CopyButton } from "./button"; import { CopyButton } from "./button";
import { Facepile } from "./Facepile"; import { Facepile } from "./Facepile";
import { Avatar } from "./Avatar"; import { Avatar } from "./Avatar";
import { ReactComponent as VideoIcon } from "./icons/Video.svg"; import { ReactComponent as VideoIcon } from "./icons/Video.svg";
import styles from "./CallList.module.css"; import styles from "./CallList.module.css";
import { getRoomUrl } from "./ConferenceCallManagerHooks";
export function CallList({ title, rooms }) { export function CallList({ title, rooms }) {
return ( return (
<> <>
<h3>{title}</h3> <h3>{title}</h3>
<div className={styles.callList}> <div className={styles.callList}>
{rooms.map(({ roomId, roomName, roomUrl, avatarUrl, participants }) => ( {rooms.map(({ roomId, roomName, avatarUrl, participants }) => (
<CallTile <CallTile
key={roomId} key={roomId}
name={roomName} name={roomName}
avatarUrl={avatarUrl} avatarUrl={avatarUrl}
roomUrl={roomUrl} roomId={roomId}
participants={participants} participants={participants}
/> />
))} ))}
@ -25,9 +26,9 @@ export function CallList({ title, rooms }) {
); );
} }
function CallTile({ name, avatarUrl, roomUrl, participants }) { function CallTile({ name, avatarUrl, roomId, participants }) {
return ( return (
<Link to={roomUrl} className={styles.callTile}> <Link to={`/room/${roomId}`} className={styles.callTile}>
<Avatar <Avatar
size="md" size="md"
bgKey={name} bgKey={name}
@ -37,13 +38,13 @@ function CallTile({ name, avatarUrl, roomUrl, participants }) {
/> />
<div className={styles.callInfo}> <div className={styles.callInfo}>
<h5>{name}</h5> <h5>{name}</h5>
<p>{roomUrl}</p> <p>{roomId}</p>
{participants && <Facepile participants={participants} />} {participants && <Facepile participants={participants} />}
</div> </div>
<CopyButton <CopyButton
className={styles.copyButton} className={styles.copyButton}
variant="icon" variant="icon"
value={roomUrl} value={getRoomUrl(roomId)}
/> />
</Link> </Link>
); );

View file

@ -519,10 +519,9 @@ export function useGroupCallRooms(client) {
const groupCall = client.getGroupCallForRoom(room.roomId); const groupCall = client.getGroupCallForRoom(room.roomId);
return { return {
roomId: room.roomId, roomId: room.getCanonicalAlias() || room.roomId,
roomName: room.name, roomName: room.name,
avatarUrl: null, avatarUrl: null,
roomUrl: `/room/${room.getCanonicalAlias() || room.roomId}`,
room, room,
groupCall, groupCall,
participants: [...groupCall.participants], participants: [...groupCall.participants],
@ -554,11 +553,10 @@ export function usePublicRooms(client, publicSpaceRoomId, maxRooms = 50) {
const filteredRooms = rooms const filteredRooms = rooms
.filter((room) => room.room_type !== "m.space") .filter((room) => room.room_type !== "m.space")
.map((room) => ({ .map((room) => ({
roomId: room.room_id, roomId: room.room_alias || room.room_id,
roomName: room.name, roomName: room.name,
avatarUrl: null, avatarUrl: null,
room, room,
roomUrl: `/room/${room.room_id}`,
participants: [], participants: [],
})); }));
@ -571,3 +569,17 @@ export function usePublicRooms(client, publicSpaceRoomId, maxRooms = 50) {
return rooms; return rooms;
} }
export function getRoomUrl(roomId) {
if (roomId.startsWith("#")) {
const [localPart, host] = roomId.replace("#", "").split(":");
if (host !== window.location.host) {
return `${window.location.host}/rooms/${roomId}`;
} else {
return `${window.location.host}/${localPart}`;
}
} else {
return `${window.location.host}/rooms/${roomId}`;
}
}

View file

@ -1,13 +1,14 @@
import React from "react"; import React from "react";
import { Modal, ModalContent } from "./Modal"; import { Modal, ModalContent } from "./Modal";
import { CopyButton } from "./button"; import { CopyButton } from "./button";
import { getRoomUrl } from "./ConferenceCallManagerHooks";
export function InviteModal({ roomUrl, ...rest }) { export function InviteModal({ roomId, ...rest }) {
return ( return (
<Modal title="Invite People" isDismissable {...rest}> <Modal title="Invite People" isDismissable {...rest}>
<ModalContent> <ModalContent>
<p>Copy and share this meeting link</p> <p>Copy and share this meeting link</p>
<CopyButton value={roomUrl} /> <CopyButton value={getRoomUrl(roomId)} />
</ModalContent> </ModalContent>
</Modal> </Modal>
); );

View file

@ -11,7 +11,7 @@ import { SettingsModal } from "./SettingsModal";
import { InviteModal } from "./InviteModal"; import { InviteModal } from "./InviteModal";
export function OverflowMenu({ export function OverflowMenu({
roomUrl, roomId,
setShowInspector, setShowInspector,
showInspector, showInspector,
client, client,
@ -63,7 +63,7 @@ export function OverflowMenu({
/> />
)} )}
{inviteModalState.isOpen && ( {inviteModalState.isOpen && (
<InviteModal roomUrl={roomUrl} {...inviteModalProps} /> <InviteModal roomId={roomId} {...inviteModalProps} />
)} )}
</> </>
); );

View file

@ -131,6 +131,7 @@ export function GroupCall({ client }) {
<div className={styles.room}> <div className={styles.room}>
<GroupCallView <GroupCallView
client={client} client={client}
roomId={roomId}
groupCall={groupCall} groupCall={groupCall}
simpleGrid={simpleGrid} simpleGrid={simpleGrid}
/> />
@ -138,7 +139,7 @@ export function GroupCall({ client }) {
); );
} }
export function GroupCallView({ client, groupCall, simpleGrid }) { export function GroupCallView({ client, roomId, groupCall, simpleGrid }) {
const [showInspector, setShowInspector] = useState(false); const [showInspector, setShowInspector] = useState(false);
const { const {
state, state,
@ -215,6 +216,7 @@ export function GroupCallView({ client, groupCall, simpleGrid }) {
simpleGrid={simpleGrid} simpleGrid={simpleGrid}
setShowInspector={setShowInspector} setShowInspector={setShowInspector}
showInspector={showInspector} showInspector={showInspector}
roomId={roomId}
/> />
); );
} else if (state === GroupCallState.Entering) { } else if (state === GroupCallState.Entering) {
@ -235,6 +237,7 @@ export function GroupCallView({ client, groupCall, simpleGrid }) {
toggleMicrophoneMuted={toggleMicrophoneMuted} toggleMicrophoneMuted={toggleMicrophoneMuted}
setShowInspector={setShowInspector} setShowInspector={setShowInspector}
showInspector={showInspector} showInspector={showInspector}
roomId={roomId}
/> />
); );
} }
@ -274,6 +277,7 @@ function RoomSetupView({
hasLocalParticipant, hasLocalParticipant,
setShowInspector, setShowInspector,
showInspector, showInspector,
roomId,
}) { }) {
const history = useHistory(); const history = useHistory();
const { stream } = useCallFeed(localCallFeed); const { stream } = useCallFeed(localCallFeed);
@ -332,7 +336,7 @@ function RoomSetupView({
onPress={toggleLocalVideoMuted} onPress={toggleLocalVideoMuted}
/> />
<OverflowMenu <OverflowMenu
roomUrl={window.location.href} roomId={roomId}
setShowInspector={setShowInspector} setShowInspector={setShowInspector}
showInspector={showInspector} showInspector={showInspector}
client={client} client={client}
@ -370,6 +374,7 @@ function InRoomView({
simpleGrid, simpleGrid,
setShowInspector, setShowInspector,
showInspector, showInspector,
roomId,
}) { }) {
const [layout, setLayout] = useVideoGridLayout(); const [layout, setLayout] = useVideoGridLayout();
@ -457,7 +462,7 @@ function InRoomView({
/> />
)} )}
<OverflowMenu <OverflowMenu
roomUrl={window.location.href} roomId={roomId}
setShowInspector={setShowInspector} setShowInspector={setShowInspector}
showInspector={showInspector} showInspector={showInspector}
client={client} client={client}