signal-desktop/ts/components/CallManager.tsx

104 lines
2.5 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-06-04 18:16:19 +00:00
import { CallScreen, PropsType as CallScreenPropsType } from './CallScreen';
import {
IncomingCallBar,
PropsType as IncomingCallBarPropsType,
} from './IncomingCallBar';
import { CallState } from '../types/Calling';
import { CallDetailsType } from '../state/ducks/calling';
type CallManagerPropsType = {
callDetails?: CallDetailsType;
callState?: CallState;
2020-10-01 00:43:05 +00:00
pip: boolean;
2020-08-27 00:03:42 +00:00
renderDeviceSelection: () => JSX.Element;
settingsDialogOpen: boolean;
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,
callDetails,
callState,
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-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 => {
if (!callDetails || !callState) {
return null;
}
const incoming = callDetails.isIncoming;
const outgoing = !incoming;
const ongoing =
callState === CallState.Accepted || callState === CallState.Reconnecting;
const ringing = callState === CallState.Ringing;
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}
/>
);
}
// Ended || (Incoming && Prering)
return null;
};