Merge pull request #463 from vector-im/dbkr/create_room_ptt

Add ptt URL param to control what mode rooms are created in
This commit is contained in:
David Baker 2022-07-11 14:34:42 +01:00 committed by GitHub
commit a3e4d6998f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 8 deletions

View File

@ -19,12 +19,19 @@ import { useLoadGroupCall } from "./useLoadGroupCall";
import { ErrorView, FullScreenView } from "../FullScreenView";
import { usePageTitle } from "../usePageTitle";
export function GroupCallLoader({ client, roomId, viaServers, children }) {
export function GroupCallLoader({
client,
roomId,
viaServers,
createPtt,
children,
}) {
const { loading, error, groupCall } = useLoadGroupCall(
client,
roomId,
viaServers,
true
true,
createPtt
);
usePageTitle(groupCall ? groupCall.room.name : "Loading...");

View File

@ -29,9 +29,13 @@ export function RoomPage() {
const { roomId: maybeRoomId } = useParams();
const { hash, search } = useLocation();
const [viaServers, isEmbedded] = useMemo(() => {
const [viaServers, isEmbedded, isPtt] = useMemo(() => {
const params = new URLSearchParams(search);
return [params.getAll("via"), params.has("embed")];
return [
params.getAll("via"),
params.has("embed"),
params.get("ptt") === "true",
];
}, [search]);
const roomId = (maybeRoomId || hash || "").toLowerCase();
@ -49,7 +53,12 @@ export function RoomPage() {
return (
<MediaHandlerProvider client={client}>
<GroupCallLoader client={client} roomId={roomId} viaServers={viaServers}>
<GroupCallLoader
client={client}
roomId={roomId}
viaServers={viaServers}
createPtt={isPtt}
>
{(groupCall) => (
<GroupCallView
client={client}

View File

@ -53,7 +53,13 @@ async function fetchGroupCall(
});
}
export function useLoadGroupCall(client, roomId, viaServers, createIfNotFound) {
export function useLoadGroupCall(
client,
roomId,
viaServers,
createIfNotFound,
createPtt
) {
const [state, setState] = useState({
loading: true,
error: undefined,
@ -79,7 +85,7 @@ export function useLoadGroupCall(client, roomId, viaServers, createIfNotFound) {
isLocalRoomId(roomId)
) {
const roomName = roomNameFromRoomId(roomId);
await createRoom(client, roomName);
await createRoom(client, roomName, createPtt);
const groupCall = await fetchGroupCall(
client,
roomId,
@ -102,7 +108,7 @@ export function useLoadGroupCall(client, roomId, viaServers, createIfNotFound) {
.catch((error) =>
setState((prevState) => ({ ...prevState, loading: false, error }))
);
}, [client, roomId, state.reloadId, createIfNotFound, viaServers]);
}, [client, roomId, state.reloadId, createIfNotFound, viaServers, createPtt]);
return state;
}