Merge branch 'main' into dbkr/postmessage_ptt_2

This commit is contained in:
David Baker
2022-07-11 14:35:18 +01:00
4 changed files with 61 additions and 28 deletions

View File

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

View File

@@ -61,7 +61,10 @@ export function GroupCallView({
useEffect(() => { useEffect(() => {
window.groupCall = groupCall; window.groupCall = groupCall;
}, [groupCall]);
// In embedded mode, bypass the lobby and just enter the call straight away
if (isEmbedded) groupCall.enter();
}, [groupCall, isEmbedded]);
useSentryGroupCallHandler(groupCall); useSentryGroupCallHandler(groupCall);
@@ -128,24 +131,32 @@ export function GroupCallView({
} else if (left) { } else if (left) {
return <CallEndedView client={client} />; return <CallEndedView client={client} />;
} else { } else {
return ( if (isEmbedded) {
<LobbyView return (
client={client} <FullScreenView>
groupCall={groupCall} <h1>Loading room...</h1>
hasLocalParticipant={hasLocalParticipant} </FullScreenView>
roomName={groupCall.room.name} );
avatarUrl={avatarUrl} } else {
state={state} return (
onInitLocalCallFeed={initLocalCallFeed} <LobbyView
localCallFeed={localCallFeed} client={client}
onEnter={enter} groupCall={groupCall}
microphoneMuted={microphoneMuted} hasLocalParticipant={hasLocalParticipant}
localVideoMuted={localVideoMuted} roomName={groupCall.room.name}
toggleLocalVideoMuted={toggleLocalVideoMuted} avatarUrl={avatarUrl}
toggleMicrophoneMuted={toggleMicrophoneMuted} state={state}
roomId={roomId} onInitLocalCallFeed={initLocalCallFeed}
isEmbedded={isEmbedded} localCallFeed={localCallFeed}
/> onEnter={enter}
); microphoneMuted={microphoneMuted}
localVideoMuted={localVideoMuted}
toggleLocalVideoMuted={toggleLocalVideoMuted}
toggleMicrophoneMuted={toggleMicrophoneMuted}
roomId={roomId}
isEmbedded={isEmbedded}
/>
);
}
} }
} }

View File

@@ -29,9 +29,13 @@ export function RoomPage() {
const { roomId: maybeRoomId } = useParams(); const { roomId: maybeRoomId } = useParams();
const { hash, search } = useLocation(); const { hash, search } = useLocation();
const [viaServers, isEmbedded] = useMemo(() => { const [viaServers, isEmbedded, isPtt] = useMemo(() => {
const params = new URLSearchParams(search); const params = new URLSearchParams(search);
return [params.getAll("via"), params.has("embed")]; return [
params.getAll("via"),
params.has("embed"),
params.get("ptt") === "true",
];
}, [search]); }, [search]);
const roomId = (maybeRoomId || hash || "").toLowerCase(); const roomId = (maybeRoomId || hash || "").toLowerCase();
@@ -49,7 +53,12 @@ export function RoomPage() {
return ( return (
<MediaHandlerProvider client={client}> <MediaHandlerProvider client={client}>
<GroupCallLoader client={client} roomId={roomId} viaServers={viaServers}> <GroupCallLoader
client={client}
roomId={roomId}
viaServers={viaServers}
createPtt={isPtt}
>
{(groupCall) => ( {(groupCall) => (
<GroupCallView <GroupCallView
client={client} 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({ const [state, setState] = useState({
loading: true, loading: true,
error: undefined, error: undefined,
@@ -79,7 +85,7 @@ export function useLoadGroupCall(client, roomId, viaServers, createIfNotFound) {
isLocalRoomId(roomId) isLocalRoomId(roomId)
) { ) {
const roomName = roomNameFromRoomId(roomId); const roomName = roomNameFromRoomId(roomId);
await createRoom(client, roomName); await createRoom(client, roomName, createPtt);
const groupCall = await fetchGroupCall( const groupCall = await fetchGroupCall(
client, client,
roomId, roomId,
@@ -102,7 +108,7 @@ export function useLoadGroupCall(client, roomId, viaServers, createIfNotFound) {
.catch((error) => .catch((error) =>
setState((prevState) => ({ ...prevState, loading: false, error })) setState((prevState) => ({ ...prevState, loading: false, error }))
); );
}, [client, roomId, state.reloadId, createIfNotFound, viaServers]); }, [client, roomId, state.reloadId, createIfNotFound, viaServers, createPtt]);
return state; return state;
} }