import React from 'react'; import { CallingPip } from './CallingPip'; import { CallNeedPermissionScreen } from './CallNeedPermissionScreen'; import { CallingLobby } from './CallingLobby'; import { CallScreen, PropsType as CallScreenPropsType } from './CallScreen'; import { IncomingCallBar, PropsType as IncomingCallBarPropsType, } from './IncomingCallBar'; import { CallState, CallEndedReason } from '../types/Calling'; import { CallDetailsType, OutgoingCallType } from '../state/ducks/calling'; type CallManagerPropsType = { availableCameras: Array; callDetails?: CallDetailsType; callEndedReason?: CallEndedReason; callState?: CallState; cancelCall: () => void; pip: boolean; closeNeedPermissionScreen: () => void; renderDeviceSelection: () => JSX.Element; settingsDialogOpen: boolean; startCall: (payload: OutgoingCallType) => void; toggleParticipants: () => void; }; type PropsType = IncomingCallBarPropsType & CallScreenPropsType & CallManagerPropsType; export const CallManager = ({ acceptCall, availableCameras, callDetails, callState, callEndedReason, cancelCall, closeNeedPermissionScreen, declineCall, hangUp, hasLocalAudio, hasLocalVideo, hasRemoteVideo, i18n, pip, renderDeviceSelection, setLocalAudio, setLocalPreview, setLocalVideo, setRendererCanvas, settingsDialogOpen, startCall, toggleParticipants, togglePip, toggleSettings, }: PropsType): JSX.Element | null => { if (!callDetails) { return null; } const incoming = callDetails.isIncoming; const outgoing = !incoming; const ongoing = callState === CallState.Accepted || callState === CallState.Reconnecting; const ringing = callState === CallState.Ringing; const ended = callState === CallState.Ended; if (ended) { if (callEndedReason === CallEndedReason.RemoteHangupNeedPermission) { return ( ); } return null; } if (!callState) { return ( <> { startCall({ callDetails }); }} setLocalPreview={setLocalPreview} setLocalAudio={setLocalAudio} setLocalVideo={setLocalVideo} toggleParticipants={toggleParticipants} toggleSettings={toggleSettings} /> {settingsDialogOpen && renderDeviceSelection()} ); } if (outgoing || ongoing) { if (pip) { return ( ); } return ( <> {settingsDialogOpen && renderDeviceSelection()} ); } if (incoming && ringing) { return ( ); } // Incoming && Prering return null; };