signal-desktop/ts/components/CallManager.tsx

209 lines
5.3 KiB
TypeScript
Raw Normal View History

2020-10-30 15:34:04 -05:00
// Copyright 2020 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
2020-06-04 11:16:19 -07:00
import React from 'react';
2020-09-30 20:43:05 -04:00
import { CallingPip } from './CallingPip';
2020-10-01 14:09:15 -05:00
import { CallNeedPermissionScreen } from './CallNeedPermissionScreen';
2020-10-07 21:25:33 -04:00
import { CallingLobby } from './CallingLobby';
import { CallScreen } from './CallScreen';
import { IncomingCallBar } from './IncomingCallBar';
2020-10-01 14:09:15 -05:00
import { CallState, CallEndedReason } from '../types/Calling';
import {
ActiveCallStateType,
AcceptCallType,
DeclineCallType,
DirectCallStateType,
StartCallType,
SetLocalAudioType,
HangUpType,
SetLocalPreviewType,
SetLocalVideoType,
SetRendererCanvasType,
} from '../state/ducks/calling';
import { LocalizerType } from '../types/Util';
import { ColorType } from '../types/Colors';
2020-06-04 11:16:19 -07:00
interface PropsType {
activeCall?: {
call: DirectCallStateType;
activeCallState: ActiveCallStateType;
conversation: {
id: string;
avatarPath?: string;
color?: ColorType;
title: string;
name?: string;
phoneNumber?: string;
profileName?: string;
};
};
availableCameras: Array<MediaDeviceInfo>;
2020-10-07 21:25:33 -04:00
cancelCall: () => void;
2020-10-01 14:09:15 -05:00
closeNeedPermissionScreen: () => void;
incomingCall?: {
call: DirectCallStateType;
conversation: {
id: string;
avatarPath?: string;
color?: ColorType;
title: string;
name?: string;
phoneNumber?: string;
profileName?: string;
};
};
2020-08-26 20:03:42 -04:00
renderDeviceSelection: () => JSX.Element;
startCall: (payload: StartCallType) => void;
2020-10-07 21:25:33 -04:00
toggleParticipants: () => void;
acceptCall: (_: AcceptCallType) => void;
declineCall: (_: DeclineCallType) => void;
i18n: LocalizerType;
me: {
avatarPath?: string;
color?: ColorType;
name?: string;
phoneNumber?: string;
profileName?: string;
title: string;
};
setLocalAudio: (_: SetLocalAudioType) => void;
setLocalVideo: (_: SetLocalVideoType) => void;
setLocalPreview: (_: SetLocalPreviewType) => void;
setRendererCanvas: (_: SetRendererCanvasType) => void;
hangUp: (_: HangUpType) => void;
togglePip: () => void;
toggleSettings: () => void;
}
2020-06-04 11:16:19 -07:00
export const CallManager = ({
acceptCall,
activeCall,
availableCameras,
2020-10-07 21:25:33 -04:00
cancelCall,
2020-10-01 14:09:15 -05:00
closeNeedPermissionScreen,
2020-06-04 11:16:19 -07:00
declineCall,
hangUp,
i18n,
incomingCall,
me,
2020-08-26 20:03:42 -04:00
renderDeviceSelection,
2020-06-04 11:16:19 -07:00
setLocalAudio,
2020-08-26 20:03:42 -04:00
setLocalPreview,
2020-06-04 11:16:19 -07:00
setLocalVideo,
2020-08-26 20:03:42 -04:00
setRendererCanvas,
2020-10-07 21:25:33 -04:00
startCall,
toggleParticipants,
2020-09-30 20:43:05 -04:00
togglePip,
2020-08-26 20:03:42 -04:00
toggleSettings,
2020-06-04 11:16:19 -07:00
}: PropsType): JSX.Element | null => {
if (activeCall) {
const { call, activeCallState, conversation } = activeCall;
const { callState, callEndedReason } = call;
const {
joinedAt,
hasLocalAudio,
hasLocalVideo,
settingsDialogOpen,
pip,
} = activeCallState;
const ended = callState === CallState.Ended;
if (ended) {
if (callEndedReason === CallEndedReason.RemoteHangupNeedPermission) {
return (
<CallNeedPermissionScreen
close={closeNeedPermissionScreen}
conversation={conversation}
i18n={i18n}
/>
);
}
}
2020-10-01 14:09:15 -05:00
if (!callState) {
2020-10-01 14:09:15 -05:00
return (
<>
<CallingLobby
availableCameras={availableCameras}
conversation={conversation}
hasLocalAudio={hasLocalAudio}
hasLocalVideo={hasLocalVideo}
i18n={i18n}
isGroupCall={false}
me={me}
onCallCanceled={cancelCall}
onJoinCall={() => {
startCall({
conversationId: conversation.id,
hasLocalAudio,
hasLocalVideo,
});
}}
setLocalPreview={setLocalPreview}
setLocalAudio={setLocalAudio}
setLocalVideo={setLocalVideo}
toggleParticipants={toggleParticipants}
toggleSettings={toggleSettings}
/>
{settingsDialogOpen && renderDeviceSelection()}
</>
2020-10-01 14:09:15 -05:00
);
}
2020-06-04 11:16:19 -07:00
const hasRemoteVideo = Boolean(call.hasRemoteVideo);
2020-10-07 21:25:33 -04:00
2020-09-30 20:43:05 -04:00
if (pip) {
return (
<CallingPip
conversation={conversation}
2020-09-30 20:43:05 -04:00
hangUp={hangUp}
hasLocalVideo={hasLocalVideo}
hasRemoteVideo={hasRemoteVideo}
i18n={i18n}
setLocalPreview={setLocalPreview}
setRendererCanvas={setRendererCanvas}
togglePip={togglePip}
/>
);
}
2020-06-04 11:16:19 -07:00
return (
2020-08-26 20:03:42 -04:00
<>
<CallScreen
conversation={conversation}
2020-08-26 20:03:42 -04:00
callState={callState}
hangUp={hangUp}
hasLocalAudio={hasLocalAudio}
hasLocalVideo={hasLocalVideo}
i18n={i18n}
joinedAt={joinedAt}
me={me}
2020-08-26 20:03:42 -04:00
hasRemoteVideo={hasRemoteVideo}
setLocalPreview={setLocalPreview}
setRendererCanvas={setRendererCanvas}
setLocalAudio={setLocalAudio}
setLocalVideo={setLocalVideo}
2020-09-30 20:43:05 -04:00
togglePip={togglePip}
2020-08-26 20:03:42 -04:00
toggleSettings={toggleSettings}
/>
{settingsDialogOpen && renderDeviceSelection()}
</>
2020-06-04 11:16:19 -07:00
);
}
// In the future, we may want to show the incoming call bar when a call is active.
if (incomingCall) {
2020-06-04 11:16:19 -07:00
return (
<IncomingCallBar
acceptCall={acceptCall}
declineCall={declineCall}
i18n={i18n}
call={incomingCall.call}
conversation={incomingCall.conversation}
2020-06-04 11:16:19 -07:00
/>
);
}
return null;
};