signal-desktop/ts/components/CallManager.tsx

158 lines
4 KiB
TypeScript
Raw Normal View History

2020-06-04 18:16:19 +00:00
import React from 'react';
2020-10-01 00:43:05 +00:00
import { CallingPip } from './CallingPip';
2020-10-01 19:09:15 +00:00
import { CallNeedPermissionScreen } from './CallNeedPermissionScreen';
2020-10-08 01:25:33 +00:00
import { CallingLobby } from './CallingLobby';
2020-06-04 18:16:19 +00:00
import { CallScreen, PropsType as CallScreenPropsType } from './CallScreen';
import {
IncomingCallBar,
PropsType as IncomingCallBarPropsType,
} from './IncomingCallBar';
2020-10-01 19:09:15 +00:00
import { CallState, CallEndedReason } from '../types/Calling';
2020-10-08 01:25:33 +00:00
import { CallDetailsType, OutgoingCallType } from '../state/ducks/calling';
2020-06-04 18:16:19 +00:00
type CallManagerPropsType = {
availableCameras: Array<MediaDeviceInfo>;
2020-06-04 18:16:19 +00:00
callDetails?: CallDetailsType;
2020-10-01 19:09:15 +00:00
callEndedReason?: CallEndedReason;
2020-10-08 01:25:33 +00:00
callState?: CallState;
cancelCall: () => void;
2020-10-01 00:43:05 +00:00
pip: boolean;
2020-10-01 19:09:15 +00:00
closeNeedPermissionScreen: () => void;
2020-08-27 00:03:42 +00:00
renderDeviceSelection: () => JSX.Element;
settingsDialogOpen: boolean;
2020-10-08 01:25:33 +00:00
startCall: (payload: OutgoingCallType) => void;
toggleParticipants: () => void;
2020-06-04 18:16:19 +00:00
};
2020-08-27 00:03:42 +00:00
2020-06-04 18:16:19 +00:00
type PropsType = IncomingCallBarPropsType &
CallScreenPropsType &
CallManagerPropsType;
export const CallManager = ({
acceptCall,
availableCameras,
2020-06-04 18:16:19 +00:00
callDetails,
callState,
2020-10-01 19:09:15 +00:00
callEndedReason,
2020-10-08 01:25:33 +00:00
cancelCall,
2020-10-01 19:09:15 +00:00
closeNeedPermissionScreen,
2020-06-04 18:16:19 +00:00
declineCall,
hangUp,
hasLocalAudio,
hasLocalVideo,
hasRemoteVideo,
i18n,
2020-10-01 00:43:05 +00:00
pip,
2020-08-27 00:03:42 +00:00
renderDeviceSelection,
2020-06-04 18:16:19 +00:00
setLocalAudio,
2020-08-27 00:03:42 +00:00
setLocalPreview,
2020-06-04 18:16:19 +00:00
setLocalVideo,
2020-08-27 00:03:42 +00:00
setRendererCanvas,
settingsDialogOpen,
2020-10-08 01:25:33 +00:00
startCall,
toggleParticipants,
2020-10-01 00:43:05 +00:00
togglePip,
2020-08-27 00:03:42 +00:00
toggleSettings,
2020-06-04 18:16:19 +00:00
}: PropsType): JSX.Element | null => {
2020-10-08 01:25:33 +00:00
if (!callDetails) {
2020-06-04 18:16:19 +00:00
return null;
}
const incoming = callDetails.isIncoming;
const outgoing = !incoming;
const ongoing =
callState === CallState.Accepted || callState === CallState.Reconnecting;
const ringing = callState === CallState.Ringing;
2020-10-01 19:09:15 +00:00
const ended = callState === CallState.Ended;
if (ended) {
if (callEndedReason === CallEndedReason.RemoteHangupNeedPermission) {
return (
<CallNeedPermissionScreen
close={closeNeedPermissionScreen}
callDetails={callDetails}
i18n={i18n}
/>
);
}
return null;
}
2020-06-04 18:16:19 +00:00
2020-10-08 01:25:33 +00:00
if (!callState) {
return (
<>
<CallingLobby
availableCameras={availableCameras}
2020-10-08 01:25:33 +00:00
callDetails={callDetails}
callState={callState}
hasLocalAudio={hasLocalAudio}
hasLocalVideo={hasLocalVideo}
i18n={i18n}
isGroupCall={false}
onCallCanceled={cancelCall}
onJoinCall={() => {
startCall({ callDetails });
}}
setLocalPreview={setLocalPreview}
setLocalAudio={setLocalAudio}
setLocalVideo={setLocalVideo}
toggleParticipants={toggleParticipants}
toggleSettings={toggleSettings}
/>
{settingsDialogOpen && renderDeviceSelection()}
</>
);
}
2020-06-04 18:16:19 +00:00
if (outgoing || ongoing) {
2020-10-01 00:43:05 +00:00
if (pip) {
return (
<CallingPip
callDetails={callDetails}
hangUp={hangUp}
hasLocalVideo={hasLocalVideo}
hasRemoteVideo={hasRemoteVideo}
i18n={i18n}
setLocalPreview={setLocalPreview}
setRendererCanvas={setRendererCanvas}
togglePip={togglePip}
/>
);
}
2020-06-04 18:16:19 +00:00
return (
2020-08-27 00:03:42 +00:00
<>
<CallScreen
callDetails={callDetails}
callState={callState}
hangUp={hangUp}
hasLocalAudio={hasLocalAudio}
hasLocalVideo={hasLocalVideo}
i18n={i18n}
hasRemoteVideo={hasRemoteVideo}
setLocalPreview={setLocalPreview}
setRendererCanvas={setRendererCanvas}
setLocalAudio={setLocalAudio}
setLocalVideo={setLocalVideo}
2020-10-01 00:43:05 +00:00
togglePip={togglePip}
2020-08-27 00:03:42 +00:00
toggleSettings={toggleSettings}
/>
{settingsDialogOpen && renderDeviceSelection()}
</>
2020-06-04 18:16:19 +00:00
);
}
if (incoming && ringing) {
return (
<IncomingCallBar
acceptCall={acceptCall}
callDetails={callDetails}
declineCall={declineCall}
i18n={i18n}
/>
);
}
2020-10-01 19:09:15 +00:00
// Incoming && Prering
2020-06-04 18:16:19 +00:00
return null;
};