element-call/src/room/GroupCallView.jsx

144 lines
4 KiB
React
Raw Normal View History

2022-01-05 23:35:12 +00:00
import React, { useCallback, useEffect, useState } from "react";
import { useHistory } from "react-router-dom";
import { GroupCallState } from "matrix-js-sdk/src/webrtc/groupCall";
2022-04-07 21:22:36 +00:00
import { useGroupCall } from "./useGroupCall";
2022-01-05 23:35:12 +00:00
import { ErrorView, FullScreenView } from "../FullScreenView";
import { LobbyView } from "./LobbyView";
import { InCallView } from "./InCallView";
2022-04-23 01:05:48 +00:00
import { PTTCallView } from "./PTTCallView";
2022-01-05 23:35:12 +00:00
import { CallEndedView } from "./CallEndedView";
import { useSentryGroupCallHandler } from "./useSentryGroupCallHandler";
import { useLocationNavigation } from "../useLocationNavigation";
2022-01-05 23:35:12 +00:00
export function GroupCallView({
client,
isPasswordlessUser,
roomId,
groupCall,
}) {
2022-01-14 21:40:02 +00:00
const [showInspector, setShowInspector] = useState(
() => !!localStorage.getItem("matrix-group-call-inspector")
);
const onChangeShowInspector = useCallback((show) => {
setShowInspector(show);
if (show) {
localStorage.setItem("matrix-group-call-inspector", "true");
} else {
localStorage.removeItem("matrix-group-call-inspector");
}
}, []);
2022-01-05 23:35:12 +00:00
const {
state,
error,
activeSpeaker,
userMediaFeeds,
microphoneMuted,
localVideoMuted,
localCallFeed,
initLocalCallFeed,
enter,
leave,
toggleLocalVideoMuted,
toggleMicrophoneMuted,
toggleScreensharing,
requestingScreenshare,
2022-01-05 23:35:12 +00:00
isScreensharing,
localScreenshareFeed,
screenshareFeeds,
hasLocalParticipant,
2022-04-23 01:05:48 +00:00
participants,
2022-01-05 23:35:12 +00:00
} = useGroupCall(groupCall);
useEffect(() => {
window.groupCall = groupCall;
}, [groupCall]);
useSentryGroupCallHandler(groupCall);
useLocationNavigation(requestingScreenshare);
2022-01-05 23:35:12 +00:00
const [left, setLeft] = useState(false);
const history = useHistory();
const onLeave = useCallback(() => {
setLeft(true);
2022-01-05 23:35:12 +00:00
leave();
if (!isPasswordlessUser) {
history.push("/");
}
}, [leave, history]);
if (error) {
return <ErrorView error={error} />;
} else if (state === GroupCallState.Entered) {
2022-04-23 01:05:48 +00:00
if (groupCall.isPtt) {
return (
<PTTCallView
client={client}
2022-04-29 00:44:50 +00:00
roomId={roomId}
2022-04-23 01:05:48 +00:00
roomName={groupCall.room.name}
2022-04-29 00:44:50 +00:00
groupCall={groupCall}
participants={participants}
2022-04-23 01:05:48 +00:00
userMediaFeeds={userMediaFeeds}
onLeave={onLeave}
setShowInspector={onChangeShowInspector}
showInspector={showInspector}
/>
);
} else {
return (
<InCallView
groupCall={groupCall}
client={client}
roomName={groupCall.room.name}
microphoneMuted={microphoneMuted}
localVideoMuted={localVideoMuted}
toggleLocalVideoMuted={toggleLocalVideoMuted}
toggleMicrophoneMuted={toggleMicrophoneMuted}
userMediaFeeds={userMediaFeeds}
activeSpeaker={activeSpeaker}
onLeave={onLeave}
toggleScreensharing={toggleScreensharing}
isScreensharing={isScreensharing}
localScreenshareFeed={localScreenshareFeed}
screenshareFeeds={screenshareFeeds}
setShowInspector={onChangeShowInspector}
showInspector={showInspector}
roomId={roomId}
/>
);
}
2022-01-05 23:35:12 +00:00
} else if (state === GroupCallState.Entering) {
return (
<FullScreenView>
<h1>Entering room...</h1>
</FullScreenView>
);
} else if (left) {
return <CallEndedView client={client} />;
} else {
return (
<LobbyView
client={client}
2022-04-27 22:18:55 +00:00
groupCall={groupCall}
2022-01-05 23:35:12 +00:00
hasLocalParticipant={hasLocalParticipant}
roomName={groupCall.room.name}
state={state}
onInitLocalCallFeed={initLocalCallFeed}
localCallFeed={localCallFeed}
onEnter={enter}
microphoneMuted={microphoneMuted}
localVideoMuted={localVideoMuted}
toggleLocalVideoMuted={toggleLocalVideoMuted}
toggleMicrophoneMuted={toggleMicrophoneMuted}
2022-01-14 21:40:02 +00:00
setShowInspector={onChangeShowInspector}
2022-01-05 23:35:12 +00:00
showInspector={showInspector}
roomId={roomId}
/>
);
}
}