2022-02-08 18:30:33 +00:00
|
|
|
// Copyright 2020-2022 Signal Messenger, LLC
|
2020-10-30 20:34:04 +00:00
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2021-08-20 16:06:15 +00:00
|
|
|
import React, { useCallback, useEffect } from 'react';
|
|
|
|
import { noop } from 'lodash';
|
2021-09-28 16:37:03 +00:00
|
|
|
import type { VideoFrameSource } from 'ringrtc';
|
2020-10-01 19:09:15 +00:00
|
|
|
import { CallNeedPermissionScreen } from './CallNeedPermissionScreen';
|
2020-11-06 17:36:37 +00:00
|
|
|
import { CallScreen } from './CallScreen';
|
2020-11-17 15:07:53 +00:00
|
|
|
import { CallingLobby } from './CallingLobby';
|
|
|
|
import { CallingParticipantsList } from './CallingParticipantsList';
|
2021-05-20 21:54:03 +00:00
|
|
|
import { CallingSelectPresentingSourcesModal } from './CallingSelectPresentingSourcesModal';
|
2020-11-17 15:07:53 +00:00
|
|
|
import { CallingPip } from './CallingPip';
|
2020-11-06 17:36:37 +00:00
|
|
|
import { IncomingCallBar } from './IncomingCallBar';
|
2021-10-26 19:15:33 +00:00
|
|
|
import type { SafetyNumberProps } from './SafetyNumberChangeDialog';
|
|
|
|
import { SafetyNumberChangeDialog } from './SafetyNumberChangeDialog';
|
|
|
|
import type {
|
2020-12-02 18:14:03 +00:00
|
|
|
ActiveCallType,
|
2021-10-26 19:15:33 +00:00
|
|
|
GroupCallVideoRequest,
|
|
|
|
PresentedSource,
|
|
|
|
} from '../types/Calling';
|
|
|
|
import {
|
2020-11-17 15:07:53 +00:00
|
|
|
CallEndedReason,
|
2020-11-13 19:57:55 +00:00
|
|
|
CallMode,
|
|
|
|
CallState,
|
2021-08-25 21:42:51 +00:00
|
|
|
GroupCallConnectionState,
|
2020-11-13 19:57:55 +00:00
|
|
|
GroupCallJoinState,
|
|
|
|
} from '../types/Calling';
|
2021-10-26 19:15:33 +00:00
|
|
|
import type { ConversationType } from '../state/ducks/conversations';
|
2021-11-17 21:58:34 +00:00
|
|
|
import type { PreferredBadgeSelectorType } from '../state/selectors/badges';
|
2021-10-26 19:15:33 +00:00
|
|
|
import type {
|
2020-11-06 17:36:37 +00:00
|
|
|
AcceptCallType,
|
2020-11-13 19:57:55 +00:00
|
|
|
CancelCallType,
|
2020-11-06 17:36:37 +00:00
|
|
|
DeclineCallType,
|
2020-12-08 19:37:04 +00:00
|
|
|
KeyChangeOkType,
|
2020-12-02 01:52:01 +00:00
|
|
|
SetGroupCallVideoRequestType,
|
2020-11-13 19:57:55 +00:00
|
|
|
SetLocalAudioType,
|
2020-11-06 17:36:37 +00:00
|
|
|
SetLocalPreviewType,
|
|
|
|
SetLocalVideoType,
|
|
|
|
SetRendererCanvasType,
|
2020-11-13 19:57:55 +00:00
|
|
|
StartCallType,
|
2020-11-06 17:36:37 +00:00
|
|
|
} from '../state/ducks/calling';
|
2021-11-17 21:58:34 +00:00
|
|
|
import type { LocalizerType, ThemeType } from '../types/Util';
|
2020-11-13 19:57:55 +00:00
|
|
|
import { missingCaseError } from '../util/missingCaseError';
|
2020-06-04 18:16:19 +00:00
|
|
|
|
2021-08-25 21:42:51 +00:00
|
|
|
const GROUP_CALL_RING_DURATION = 60 * 1000;
|
|
|
|
|
2021-01-14 18:07:05 +00:00
|
|
|
export type PropsType = {
|
2020-11-13 19:57:55 +00:00
|
|
|
activeCall?: ActiveCallType;
|
2020-10-14 16:30:50 +00:00
|
|
|
availableCameras: Array<MediaDeviceInfo>;
|
2020-11-13 19:57:55 +00:00
|
|
|
cancelCall: (_: CancelCallType) => void;
|
2020-10-01 19:09:15 +00:00
|
|
|
closeNeedPermissionScreen: () => void;
|
2020-11-13 19:57:55 +00:00
|
|
|
getGroupCallVideoFrameSource: (
|
|
|
|
conversationId: string,
|
|
|
|
demuxId: number
|
|
|
|
) => VideoFrameSource;
|
2021-11-17 21:58:34 +00:00
|
|
|
getPreferredBadge: PreferredBadgeSelectorType;
|
2021-05-20 21:54:03 +00:00
|
|
|
getPresentingSources: () => void;
|
2021-08-20 16:06:15 +00:00
|
|
|
incomingCall?:
|
|
|
|
| {
|
|
|
|
callMode: CallMode.Direct;
|
|
|
|
conversation: ConversationType;
|
|
|
|
isVideoCall: boolean;
|
|
|
|
}
|
|
|
|
| {
|
|
|
|
callMode: CallMode.Group;
|
|
|
|
conversation: ConversationType;
|
|
|
|
otherMembersRung: Array<Pick<ConversationType, 'firstName' | 'title'>>;
|
|
|
|
ringer: Pick<ConversationType, 'firstName' | 'title'>;
|
|
|
|
};
|
2020-12-08 19:37:04 +00:00
|
|
|
keyChangeOk: (_: KeyChangeOkType) => void;
|
2020-08-27 00:03:42 +00:00
|
|
|
renderDeviceSelection: () => JSX.Element;
|
2020-12-08 19:37:04 +00:00
|
|
|
renderSafetyNumberViewer: (props: SafetyNumberProps) => JSX.Element;
|
2020-11-06 17:36:37 +00:00
|
|
|
startCall: (payload: StartCallType) => void;
|
2020-10-08 01:25:33 +00:00
|
|
|
toggleParticipants: () => void;
|
2020-11-06 17:36:37 +00:00
|
|
|
acceptCall: (_: AcceptCallType) => void;
|
2021-08-20 16:06:15 +00:00
|
|
|
bounceAppIconStart: () => unknown;
|
|
|
|
bounceAppIconStop: () => unknown;
|
2020-11-06 17:36:37 +00:00
|
|
|
declineCall: (_: DeclineCallType) => void;
|
|
|
|
i18n: LocalizerType;
|
2021-08-25 21:42:51 +00:00
|
|
|
isGroupCallOutboundRingEnabled: boolean;
|
2022-02-23 18:48:40 +00:00
|
|
|
me: ConversationType;
|
2021-08-20 16:06:15 +00:00
|
|
|
notifyForCall: (title: string, isVideoCall: boolean) => unknown;
|
2021-05-20 21:54:03 +00:00
|
|
|
openSystemPreferencesAction: () => unknown;
|
2021-08-20 16:06:15 +00:00
|
|
|
playRingtone: () => unknown;
|
2020-12-02 01:52:01 +00:00
|
|
|
setGroupCallVideoRequest: (_: SetGroupCallVideoRequestType) => void;
|
2021-09-28 19:00:22 +00:00
|
|
|
setIsCallActive: (_: boolean) => void;
|
2020-11-06 17:36:37 +00:00
|
|
|
setLocalAudio: (_: SetLocalAudioType) => void;
|
|
|
|
setLocalVideo: (_: SetLocalVideoType) => void;
|
|
|
|
setLocalPreview: (_: SetLocalPreviewType) => void;
|
2021-08-25 21:42:51 +00:00
|
|
|
setOutgoingRing: (_: boolean) => void;
|
2021-05-20 21:54:03 +00:00
|
|
|
setPresenting: (_?: PresentedSource) => void;
|
2020-11-06 17:36:37 +00:00
|
|
|
setRendererCanvas: (_: SetRendererCanvasType) => void;
|
2021-08-20 16:06:15 +00:00
|
|
|
stopRingtone: () => unknown;
|
2022-02-08 19:18:51 +00:00
|
|
|
hangUpActiveCall: () => void;
|
2021-11-17 21:58:34 +00:00
|
|
|
theme: ThemeType;
|
2020-11-06 17:36:37 +00:00
|
|
|
togglePip: () => void;
|
2021-05-20 21:54:03 +00:00
|
|
|
toggleScreenRecordingPermissionsDialog: () => unknown;
|
2020-11-06 17:36:37 +00:00
|
|
|
toggleSettings: () => void;
|
2021-01-08 22:57:54 +00:00
|
|
|
toggleSpeakerView: () => void;
|
2021-01-14 18:07:05 +00:00
|
|
|
};
|
2020-06-04 18:16:19 +00:00
|
|
|
|
2021-01-14 18:07:05 +00:00
|
|
|
type ActiveCallManagerPropsType = PropsType & {
|
2020-11-13 19:57:55 +00:00
|
|
|
activeCall: ActiveCallType;
|
2021-01-14 18:07:05 +00:00
|
|
|
};
|
2020-11-13 19:57:55 +00:00
|
|
|
|
|
|
|
const ActiveCallManager: React.FC<ActiveCallManagerPropsType> = ({
|
2020-11-06 17:36:37 +00:00
|
|
|
activeCall,
|
2020-10-14 16:30:50 +00:00
|
|
|
availableCameras,
|
2020-10-08 01:25:33 +00:00
|
|
|
cancelCall,
|
2020-10-01 19:09:15 +00:00
|
|
|
closeNeedPermissionScreen,
|
2022-02-08 19:18:51 +00:00
|
|
|
hangUpActiveCall,
|
2020-06-04 18:16:19 +00:00
|
|
|
i18n,
|
2021-08-25 21:42:51 +00:00
|
|
|
isGroupCallOutboundRingEnabled,
|
2020-12-08 19:37:04 +00:00
|
|
|
keyChangeOk,
|
2020-11-13 19:57:55 +00:00
|
|
|
getGroupCallVideoFrameSource,
|
2021-11-17 21:58:34 +00:00
|
|
|
getPreferredBadge,
|
2021-05-20 21:54:03 +00:00
|
|
|
getPresentingSources,
|
2020-11-04 19:56:03 +00:00
|
|
|
me,
|
2021-05-20 21:54:03 +00:00
|
|
|
openSystemPreferencesAction,
|
2020-08-27 00:03:42 +00:00
|
|
|
renderDeviceSelection,
|
2020-12-08 19:37:04 +00:00
|
|
|
renderSafetyNumberViewer,
|
2020-12-02 01:52:01 +00:00
|
|
|
setGroupCallVideoRequest,
|
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,
|
2021-05-20 21:54:03 +00:00
|
|
|
setPresenting,
|
2020-08-27 00:03:42 +00:00
|
|
|
setRendererCanvas,
|
2021-08-25 21:42:51 +00:00
|
|
|
setOutgoingRing,
|
2020-10-08 01:25:33 +00:00
|
|
|
startCall,
|
2021-11-17 21:58:34 +00:00
|
|
|
theme,
|
2020-10-08 01:25:33 +00:00
|
|
|
toggleParticipants,
|
2020-10-01 00:43:05 +00:00
|
|
|
togglePip,
|
2021-05-20 21:54:03 +00:00
|
|
|
toggleScreenRecordingPermissionsDialog,
|
2020-08-27 00:03:42 +00:00
|
|
|
toggleSettings,
|
2021-01-08 22:57:54 +00:00
|
|
|
toggleSpeakerView,
|
2020-11-13 19:57:55 +00:00
|
|
|
}) => {
|
|
|
|
const {
|
2020-11-17 15:07:53 +00:00
|
|
|
conversation,
|
2020-11-13 19:57:55 +00:00
|
|
|
hasLocalAudio,
|
|
|
|
hasLocalVideo,
|
2020-11-17 15:07:53 +00:00
|
|
|
joinedAt,
|
2020-12-02 18:14:03 +00:00
|
|
|
peekedParticipants,
|
2020-11-13 19:57:55 +00:00
|
|
|
pip,
|
2021-05-20 21:54:03 +00:00
|
|
|
presentingSourcesAvailable,
|
2020-11-17 15:07:53 +00:00
|
|
|
settingsDialogOpen,
|
|
|
|
showParticipantsList,
|
2021-08-25 21:42:51 +00:00
|
|
|
outgoingRing,
|
2020-12-02 18:14:03 +00:00
|
|
|
} = activeCall;
|
2020-11-13 19:57:55 +00:00
|
|
|
|
|
|
|
const cancelActiveCall = useCallback(() => {
|
|
|
|
cancelCall({ conversationId: conversation.id });
|
|
|
|
}, [cancelCall, conversation.id]);
|
|
|
|
|
|
|
|
const joinActiveCall = useCallback(() => {
|
|
|
|
startCall({
|
2020-12-02 18:14:03 +00:00
|
|
|
callMode: activeCall.callMode,
|
2020-11-13 19:57:55 +00:00
|
|
|
conversationId: conversation.id,
|
2020-11-06 17:36:37 +00:00
|
|
|
hasLocalAudio,
|
|
|
|
hasLocalVideo,
|
2020-11-13 19:57:55 +00:00
|
|
|
});
|
2020-12-02 18:14:03 +00:00
|
|
|
}, [
|
|
|
|
startCall,
|
|
|
|
activeCall.callMode,
|
|
|
|
conversation.id,
|
|
|
|
hasLocalAudio,
|
|
|
|
hasLocalVideo,
|
|
|
|
]);
|
2020-11-13 19:57:55 +00:00
|
|
|
|
|
|
|
const getGroupCallVideoFrameSourceForActiveCall = useCallback(
|
|
|
|
(demuxId: number) => {
|
|
|
|
return getGroupCallVideoFrameSource(conversation.id, demuxId);
|
|
|
|
},
|
|
|
|
[getGroupCallVideoFrameSource, conversation.id]
|
|
|
|
);
|
|
|
|
|
2020-12-02 01:52:01 +00:00
|
|
|
const setGroupCallVideoRequestForConversation = useCallback(
|
|
|
|
(resolutions: Array<GroupCallVideoRequest>) => {
|
|
|
|
setGroupCallVideoRequest({
|
|
|
|
conversationId: conversation.id,
|
|
|
|
resolutions,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
[setGroupCallVideoRequest, conversation.id]
|
|
|
|
);
|
|
|
|
|
2020-12-02 18:14:03 +00:00
|
|
|
let isCallFull: boolean;
|
2020-11-13 19:57:55 +00:00
|
|
|
let showCallLobby: boolean;
|
2021-08-17 21:45:18 +00:00
|
|
|
let groupMembers:
|
|
|
|
| undefined
|
2021-08-25 21:42:51 +00:00
|
|
|
| Array<Pick<ConversationType, 'id' | 'firstName' | 'title'>>;
|
2020-11-06 17:36:37 +00:00
|
|
|
|
2020-12-02 18:14:03 +00:00
|
|
|
switch (activeCall.callMode) {
|
2020-11-13 19:57:55 +00:00
|
|
|
case CallMode.Direct: {
|
2020-12-02 18:14:03 +00:00
|
|
|
const { callState, callEndedReason } = activeCall;
|
2020-11-13 19:57:55 +00:00
|
|
|
const ended = callState === CallState.Ended;
|
|
|
|
if (
|
|
|
|
ended &&
|
|
|
|
callEndedReason === CallEndedReason.RemoteHangupNeedPermission
|
|
|
|
) {
|
2020-11-06 17:36:37 +00:00
|
|
|
return (
|
|
|
|
<CallNeedPermissionScreen
|
|
|
|
close={closeNeedPermissionScreen}
|
|
|
|
conversation={conversation}
|
|
|
|
i18n={i18n}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
2020-11-13 19:57:55 +00:00
|
|
|
showCallLobby = !callState;
|
2020-12-02 18:14:03 +00:00
|
|
|
isCallFull = false;
|
2021-08-17 21:45:18 +00:00
|
|
|
groupMembers = undefined;
|
2020-11-13 19:57:55 +00:00
|
|
|
break;
|
2020-11-06 17:36:37 +00:00
|
|
|
}
|
2020-11-13 19:57:55 +00:00
|
|
|
case CallMode.Group: {
|
2020-12-02 18:14:03 +00:00
|
|
|
showCallLobby = activeCall.joinState === GroupCallJoinState.NotJoined;
|
|
|
|
isCallFull = activeCall.deviceCount >= activeCall.maxDevices;
|
2021-08-17 21:45:18 +00:00
|
|
|
({ groupMembers } = activeCall);
|
2020-11-13 19:57:55 +00:00
|
|
|
break;
|
2020-10-01 00:43:05 +00:00
|
|
|
}
|
2020-11-13 19:57:55 +00:00
|
|
|
default:
|
2020-12-02 18:14:03 +00:00
|
|
|
throw missingCaseError(activeCall);
|
2020-11-13 19:57:55 +00:00
|
|
|
}
|
2020-10-01 00:43:05 +00:00
|
|
|
|
2020-11-13 19:57:55 +00:00
|
|
|
if (showCallLobby) {
|
2020-06-04 18:16:19 +00:00
|
|
|
return (
|
2020-08-27 00:03:42 +00:00
|
|
|
<>
|
2020-11-13 19:57:55 +00:00
|
|
|
<CallingLobby
|
|
|
|
availableCameras={availableCameras}
|
2020-11-06 17:36:37 +00:00
|
|
|
conversation={conversation}
|
2021-08-17 21:45:18 +00:00
|
|
|
groupMembers={groupMembers}
|
2020-08-27 00:03:42 +00:00
|
|
|
hasLocalAudio={hasLocalAudio}
|
|
|
|
hasLocalVideo={hasLocalVideo}
|
|
|
|
i18n={i18n}
|
2020-12-02 18:14:03 +00:00
|
|
|
isGroupCall={activeCall.callMode === CallMode.Group}
|
2021-08-25 21:42:51 +00:00
|
|
|
isGroupCallOutboundRingEnabled={isGroupCallOutboundRingEnabled}
|
2020-11-20 20:14:07 +00:00
|
|
|
isCallFull={isCallFull}
|
2020-11-04 19:56:03 +00:00
|
|
|
me={me}
|
2020-11-13 19:57:55 +00:00
|
|
|
onCallCanceled={cancelActiveCall}
|
|
|
|
onJoinCall={joinActiveCall}
|
2021-08-25 21:42:51 +00:00
|
|
|
outgoingRing={outgoingRing}
|
2020-12-02 18:14:03 +00:00
|
|
|
peekedParticipants={peekedParticipants}
|
2020-08-27 00:03:42 +00:00
|
|
|
setLocalPreview={setLocalPreview}
|
|
|
|
setLocalAudio={setLocalAudio}
|
|
|
|
setLocalVideo={setLocalVideo}
|
2021-08-25 21:42:51 +00:00
|
|
|
setOutgoingRing={setOutgoingRing}
|
2020-11-20 19:39:50 +00:00
|
|
|
showParticipantsList={showParticipantsList}
|
2020-11-13 19:57:55 +00:00
|
|
|
toggleParticipants={toggleParticipants}
|
2020-08-27 00:03:42 +00:00
|
|
|
toggleSettings={toggleSettings}
|
|
|
|
/>
|
|
|
|
{settingsDialogOpen && renderDeviceSelection()}
|
2020-12-02 18:14:03 +00:00
|
|
|
{showParticipantsList && activeCall.callMode === CallMode.Group ? (
|
2020-11-17 15:07:53 +00:00
|
|
|
<CallingParticipantsList
|
|
|
|
i18n={i18n}
|
|
|
|
onClose={toggleParticipants}
|
2020-12-08 19:37:04 +00:00
|
|
|
ourUuid={me.uuid}
|
2020-12-02 18:14:03 +00:00
|
|
|
participants={peekedParticipants}
|
2020-11-17 15:07:53 +00:00
|
|
|
/>
|
|
|
|
) : null}
|
2020-08-27 00:03:42 +00:00
|
|
|
</>
|
2020-06-04 18:16:19 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-11-17 15:07:53 +00:00
|
|
|
if (pip) {
|
2020-11-13 19:57:55 +00:00
|
|
|
return (
|
|
|
|
<CallingPip
|
2020-11-19 18:13:36 +00:00
|
|
|
activeCall={activeCall}
|
2020-11-17 15:07:53 +00:00
|
|
|
getGroupCallVideoFrameSource={getGroupCallVideoFrameSourceForActiveCall}
|
2022-02-08 19:18:51 +00:00
|
|
|
hangUpActiveCall={hangUpActiveCall}
|
2020-11-13 19:57:55 +00:00
|
|
|
hasLocalVideo={hasLocalVideo}
|
|
|
|
i18n={i18n}
|
2020-12-02 01:52:01 +00:00
|
|
|
setGroupCallVideoRequest={setGroupCallVideoRequestForConversation}
|
2020-11-13 19:57:55 +00:00
|
|
|
setLocalPreview={setLocalPreview}
|
|
|
|
setRendererCanvas={setRendererCanvas}
|
|
|
|
togglePip={togglePip}
|
2021-10-07 18:56:27 +00:00
|
|
|
toggleSpeakerView={toggleSpeakerView}
|
2020-11-13 19:57:55 +00:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-12-02 18:14:03 +00:00
|
|
|
const groupCallParticipantsForParticipantsList =
|
|
|
|
activeCall.callMode === CallMode.Group
|
|
|
|
? [
|
|
|
|
...activeCall.remoteParticipants.map(participant => ({
|
|
|
|
...participant,
|
2021-05-20 21:54:03 +00:00
|
|
|
hasRemoteAudio: participant.hasRemoteAudio,
|
|
|
|
hasRemoteVideo: participant.hasRemoteVideo,
|
|
|
|
presenting: participant.presenting,
|
2020-12-02 18:14:03 +00:00
|
|
|
})),
|
|
|
|
{
|
|
|
|
...me,
|
2021-05-20 21:54:03 +00:00
|
|
|
hasRemoteAudio: hasLocalAudio,
|
|
|
|
hasRemoteVideo: hasLocalVideo,
|
|
|
|
presenting: Boolean(activeCall.presentingSource),
|
2020-12-02 18:14:03 +00:00
|
|
|
},
|
|
|
|
]
|
|
|
|
: [];
|
|
|
|
|
2020-11-13 19:57:55 +00:00
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<CallScreen
|
2020-11-19 18:13:36 +00:00
|
|
|
activeCall={activeCall}
|
2021-05-20 21:54:03 +00:00
|
|
|
getPresentingSources={getPresentingSources}
|
2020-11-13 19:57:55 +00:00
|
|
|
getGroupCallVideoFrameSource={getGroupCallVideoFrameSourceForActiveCall}
|
2021-08-25 21:42:51 +00:00
|
|
|
groupMembers={groupMembers}
|
2022-02-08 19:18:51 +00:00
|
|
|
hangUpActiveCall={hangUpActiveCall}
|
2020-11-13 19:57:55 +00:00
|
|
|
i18n={i18n}
|
|
|
|
joinedAt={joinedAt}
|
|
|
|
me={me}
|
2021-05-20 21:54:03 +00:00
|
|
|
openSystemPreferencesAction={openSystemPreferencesAction}
|
2020-12-02 01:52:01 +00:00
|
|
|
setGroupCallVideoRequest={setGroupCallVideoRequestForConversation}
|
2020-11-13 19:57:55 +00:00
|
|
|
setLocalPreview={setLocalPreview}
|
|
|
|
setRendererCanvas={setRendererCanvas}
|
|
|
|
setLocalAudio={setLocalAudio}
|
|
|
|
setLocalVideo={setLocalVideo}
|
2021-05-20 21:54:03 +00:00
|
|
|
setPresenting={setPresenting}
|
2020-11-17 15:07:53 +00:00
|
|
|
stickyControls={showParticipantsList}
|
2021-05-20 21:54:03 +00:00
|
|
|
toggleScreenRecordingPermissionsDialog={
|
|
|
|
toggleScreenRecordingPermissionsDialog
|
|
|
|
}
|
2020-11-17 15:07:53 +00:00
|
|
|
toggleParticipants={toggleParticipants}
|
2020-11-13 19:57:55 +00:00
|
|
|
togglePip={togglePip}
|
|
|
|
toggleSettings={toggleSettings}
|
2021-01-08 22:57:54 +00:00
|
|
|
toggleSpeakerView={toggleSpeakerView}
|
2020-11-13 19:57:55 +00:00
|
|
|
/>
|
2021-05-20 21:54:03 +00:00
|
|
|
{presentingSourcesAvailable && presentingSourcesAvailable.length ? (
|
|
|
|
<CallingSelectPresentingSourcesModal
|
|
|
|
i18n={i18n}
|
|
|
|
presentingSourcesAvailable={presentingSourcesAvailable}
|
|
|
|
setPresenting={setPresenting}
|
|
|
|
/>
|
|
|
|
) : null}
|
2020-11-13 19:57:55 +00:00
|
|
|
{settingsDialogOpen && renderDeviceSelection()}
|
2020-12-02 18:14:03 +00:00
|
|
|
{showParticipantsList && activeCall.callMode === CallMode.Group ? (
|
2020-11-17 15:07:53 +00:00
|
|
|
<CallingParticipantsList
|
|
|
|
i18n={i18n}
|
|
|
|
onClose={toggleParticipants}
|
2020-12-08 19:37:04 +00:00
|
|
|
ourUuid={me.uuid}
|
2020-12-02 18:14:03 +00:00
|
|
|
participants={groupCallParticipantsForParticipantsList}
|
2020-11-17 15:07:53 +00:00
|
|
|
/>
|
|
|
|
) : null}
|
2020-12-08 19:37:04 +00:00
|
|
|
{activeCall.callMode === CallMode.Group &&
|
|
|
|
activeCall.conversationsWithSafetyNumberChanges.length ? (
|
|
|
|
<SafetyNumberChangeDialog
|
|
|
|
confirmText={i18n('continueCall')}
|
|
|
|
contacts={activeCall.conversationsWithSafetyNumberChanges}
|
2021-11-17 21:58:34 +00:00
|
|
|
getPreferredBadge={getPreferredBadge}
|
2020-12-08 19:37:04 +00:00
|
|
|
i18n={i18n}
|
2022-02-08 19:18:51 +00:00
|
|
|
onCancel={hangUpActiveCall}
|
2020-12-08 19:37:04 +00:00
|
|
|
onConfirm={() => {
|
|
|
|
keyChangeOk({ conversationId: activeCall.conversation.id });
|
|
|
|
}}
|
|
|
|
renderSafetyNumber={renderSafetyNumberViewer}
|
2021-11-17 21:58:34 +00:00
|
|
|
theme={theme}
|
2020-12-08 19:37:04 +00:00
|
|
|
/>
|
|
|
|
) : null}
|
2020-11-13 19:57:55 +00:00
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export const CallManager: React.FC<PropsType> = props => {
|
2021-08-20 16:06:15 +00:00
|
|
|
const {
|
|
|
|
acceptCall,
|
|
|
|
activeCall,
|
|
|
|
bounceAppIconStart,
|
|
|
|
bounceAppIconStop,
|
|
|
|
declineCall,
|
|
|
|
i18n,
|
|
|
|
incomingCall,
|
|
|
|
notifyForCall,
|
|
|
|
playRingtone,
|
|
|
|
stopRingtone,
|
2021-09-28 19:00:22 +00:00
|
|
|
setIsCallActive,
|
2021-08-25 21:42:51 +00:00
|
|
|
setOutgoingRing,
|
2021-08-20 16:06:15 +00:00
|
|
|
} = props;
|
|
|
|
|
2021-09-28 19:00:22 +00:00
|
|
|
const isCallActive = Boolean(activeCall);
|
|
|
|
useEffect(() => {
|
|
|
|
setIsCallActive(isCallActive);
|
|
|
|
}, [isCallActive, setIsCallActive]);
|
|
|
|
|
2021-08-20 16:06:15 +00:00
|
|
|
const shouldRing = getShouldRing(props);
|
|
|
|
useEffect(() => {
|
|
|
|
if (shouldRing) {
|
|
|
|
playRingtone();
|
|
|
|
return () => {
|
|
|
|
stopRingtone();
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
stopRingtone();
|
|
|
|
return noop;
|
|
|
|
}, [shouldRing, playRingtone, stopRingtone]);
|
2020-11-13 19:57:55 +00:00
|
|
|
|
2021-09-09 21:15:05 +00:00
|
|
|
const mightBeRingingOutgoingGroupCall =
|
|
|
|
activeCall?.callMode === CallMode.Group &&
|
|
|
|
activeCall.outgoingRing &&
|
|
|
|
activeCall.joinState !== GroupCallJoinState.NotJoined;
|
2021-08-25 21:42:51 +00:00
|
|
|
useEffect(() => {
|
2021-09-09 21:15:05 +00:00
|
|
|
if (!mightBeRingingOutgoingGroupCall) {
|
2021-08-25 21:42:51 +00:00
|
|
|
return noop;
|
|
|
|
}
|
|
|
|
|
|
|
|
const timeout = setTimeout(() => {
|
|
|
|
setOutgoingRing(false);
|
|
|
|
}, GROUP_CALL_RING_DURATION);
|
|
|
|
return () => {
|
|
|
|
clearTimeout(timeout);
|
|
|
|
};
|
2021-09-09 21:15:05 +00:00
|
|
|
}, [mightBeRingingOutgoingGroupCall, setOutgoingRing]);
|
2021-08-25 21:42:51 +00:00
|
|
|
|
2020-11-13 19:57:55 +00:00
|
|
|
if (activeCall) {
|
|
|
|
// `props` should logically have an `activeCall` at this point, but TypeScript can't
|
|
|
|
// figure that out, so we pass it in again.
|
|
|
|
return <ActiveCallManager {...props} activeCall={activeCall} />;
|
|
|
|
}
|
|
|
|
|
2020-11-06 17:36:37 +00:00
|
|
|
// In the future, we may want to show the incoming call bar when a call is active.
|
|
|
|
if (incomingCall) {
|
2020-06-04 18:16:19 +00:00
|
|
|
return (
|
|
|
|
<IncomingCallBar
|
|
|
|
acceptCall={acceptCall}
|
2021-08-20 16:06:15 +00:00
|
|
|
bounceAppIconStart={bounceAppIconStart}
|
|
|
|
bounceAppIconStop={bounceAppIconStop}
|
2020-06-04 18:16:19 +00:00
|
|
|
declineCall={declineCall}
|
|
|
|
i18n={i18n}
|
2021-08-20 16:06:15 +00:00
|
|
|
notifyForCall={notifyForCall}
|
|
|
|
{...incomingCall}
|
2020-06-04 18:16:19 +00:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
};
|
2021-08-20 16:06:15 +00:00
|
|
|
|
|
|
|
function getShouldRing({
|
|
|
|
activeCall,
|
|
|
|
incomingCall,
|
|
|
|
}: Readonly<Pick<PropsType, 'activeCall' | 'incomingCall'>>): boolean {
|
|
|
|
if (incomingCall) {
|
|
|
|
return !activeCall;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!activeCall) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (activeCall.callMode) {
|
|
|
|
case CallMode.Direct:
|
|
|
|
return (
|
|
|
|
activeCall.callState === CallState.Prering ||
|
|
|
|
activeCall.callState === CallState.Ringing
|
|
|
|
);
|
|
|
|
case CallMode.Group:
|
2021-08-25 21:42:51 +00:00
|
|
|
return (
|
|
|
|
activeCall.outgoingRing &&
|
|
|
|
(activeCall.connectionState === GroupCallConnectionState.Connecting ||
|
|
|
|
activeCall.connectionState === GroupCallConnectionState.Connected) &&
|
|
|
|
activeCall.joinState !== GroupCallJoinState.NotJoined &&
|
|
|
|
!activeCall.remoteParticipants.length &&
|
|
|
|
(activeCall.conversation.sortedGroupMembers || []).length >= 2
|
|
|
|
);
|
2021-08-20 16:06:15 +00:00
|
|
|
default:
|
|
|
|
throw missingCaseError(activeCall);
|
|
|
|
}
|
|
|
|
}
|