2023-01-03 19:55:46 +00:00
|
|
|
// Copyright 2020 Signal Messenger, LLC
|
2020-10-30 20:34:04 +00:00
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2021-05-20 21:54:03 +00:00
|
|
|
import { ipcRenderer } from 'electron';
|
2022-02-08 19:18:51 +00:00
|
|
|
import type { ThunkAction, ThunkDispatch } from 'redux-thunk';
|
2021-05-20 21:54:03 +00:00
|
|
|
import {
|
|
|
|
hasScreenCapturePermission,
|
|
|
|
openSystemPreferences,
|
|
|
|
} from 'mac-screen-capture-permissions';
|
2020-11-06 17:36:37 +00:00
|
|
|
import { has, omit } from 'lodash';
|
2023-01-13 20:07:26 +00:00
|
|
|
import type { ReadonlyDeep } from 'type-fest';
|
2020-11-06 17:36:37 +00:00
|
|
|
import { getOwn } from '../../util/getOwn';
|
2021-10-18 23:14:24 +00:00
|
|
|
import * as Errors from '../../types/errors';
|
2021-05-20 21:54:03 +00:00
|
|
|
import { getPlatform } from '../selectors/user';
|
2021-09-02 22:34:38 +00:00
|
|
|
import { isConversationTooBigToRing } from '../../conversations/isConversationTooBigToRing';
|
2020-11-13 19:57:55 +00:00
|
|
|
import { missingCaseError } from '../../util/missingCaseError';
|
2020-08-27 00:03:42 +00:00
|
|
|
import { calling } from '../../services/calling';
|
2022-05-19 03:28:51 +00:00
|
|
|
import { truncateAudioLevel } from '../../calling/truncateAudioLevel';
|
2021-10-26 19:15:33 +00:00
|
|
|
import type { StateType as RootStateType } from '../reducer';
|
|
|
|
import type {
|
|
|
|
ChangeIODevicePayloadType,
|
|
|
|
GroupCallVideoRequest,
|
|
|
|
MediaDeviceSettings,
|
|
|
|
PresentedSource,
|
|
|
|
PresentableSource,
|
|
|
|
} from '../../types/Calling';
|
2020-08-27 00:03:42 +00:00
|
|
|
import {
|
2023-08-09 00:53:06 +00:00
|
|
|
CallEndedReason,
|
2020-12-02 18:14:03 +00:00
|
|
|
CallingDeviceType,
|
2020-11-13 19:57:55 +00:00
|
|
|
CallMode,
|
2022-05-25 18:03:27 +00:00
|
|
|
CallViewMode,
|
2020-08-27 00:03:42 +00:00
|
|
|
CallState,
|
2020-11-13 19:57:55 +00:00
|
|
|
GroupCallConnectionState,
|
|
|
|
GroupCallJoinState,
|
2020-08-27 00:03:42 +00:00
|
|
|
} from '../../types/Calling';
|
2020-06-04 18:16:19 +00:00
|
|
|
import { callingTones } from '../../util/callingTones';
|
|
|
|
import { requestCameraPermissions } from '../../util/callingPermissions';
|
2021-09-07 16:20:13 +00:00
|
|
|
import { isGroupCallOutboundRingEnabled } from '../../util/isGroupCallOutboundRingEnabled';
|
2020-11-20 17:19:28 +00:00
|
|
|
import { sleep } from '../../util/sleep';
|
|
|
|
import { LatestQueue } from '../../util/LatestQueue';
|
2023-08-10 16:43:33 +00:00
|
|
|
import type { AciString } from '../../types/ServiceId';
|
2022-02-08 19:18:51 +00:00
|
|
|
import type {
|
|
|
|
ConversationChangedActionType,
|
|
|
|
ConversationRemovedActionType,
|
|
|
|
} from './conversations';
|
2023-09-27 19:42:38 +00:00
|
|
|
import { getConversationCallMode, updateLastMessage } from './conversations';
|
2021-09-17 18:27:53 +00:00
|
|
|
import * as log from '../../logging/log';
|
2022-01-07 18:01:23 +00:00
|
|
|
import { strictAssert } from '../../util/assert';
|
2022-02-08 19:18:51 +00:00
|
|
|
import { waitForOnline } from '../../util/waitForOnline';
|
2022-05-19 03:28:51 +00:00
|
|
|
import * as mapUtil from '../../util/mapUtil';
|
2022-12-06 17:31:44 +00:00
|
|
|
import { isCallSafe } from '../../util/isCallSafe';
|
|
|
|
import { isDirectConversation } from '../../util/whatTypeOfConversation';
|
2022-12-15 00:48:36 +00:00
|
|
|
import { SHOW_TOAST } from './toast';
|
|
|
|
import { ToastType } from '../../types/Toast';
|
2022-12-06 17:31:44 +00:00
|
|
|
import type { ShowToastActionType } from './toast';
|
2023-01-19 19:56:02 +00:00
|
|
|
import type { BoundActionCreatorsMapObject } from '../../hooks/useBoundActions';
|
|
|
|
import { useBoundActions } from '../../hooks/useBoundActions';
|
2023-07-18 23:57:38 +00:00
|
|
|
import { isAnybodyElseInGroupCall } from './callingHelpers';
|
2023-09-06 00:34:51 +00:00
|
|
|
import { SafetyNumberChangeSource } from '../../components/SafetyNumberChangeDialog';
|
2020-06-04 18:16:19 +00:00
|
|
|
|
|
|
|
// State
|
|
|
|
|
2023-01-13 20:07:26 +00:00
|
|
|
export type GroupCallPeekInfoType = ReadonlyDeep<{
|
2023-08-10 16:43:33 +00:00
|
|
|
acis: Array<AciString>;
|
|
|
|
creatorAci?: AciString;
|
2020-11-20 17:19:28 +00:00
|
|
|
eraId?: string;
|
|
|
|
maxDevices: number;
|
|
|
|
deviceCount: number;
|
2023-01-13 20:07:26 +00:00
|
|
|
}>;
|
2020-11-20 17:19:28 +00:00
|
|
|
|
2023-01-13 20:07:26 +00:00
|
|
|
// eslint-disable-next-line local-rules/type-alias-readonlydeep
|
2021-01-14 18:07:05 +00:00
|
|
|
export type GroupCallParticipantInfoType = {
|
2023-08-10 16:43:33 +00:00
|
|
|
aci: AciString;
|
2020-11-17 15:07:53 +00:00
|
|
|
demuxId: number;
|
|
|
|
hasRemoteAudio: boolean;
|
|
|
|
hasRemoteVideo: boolean;
|
2021-05-20 21:54:03 +00:00
|
|
|
presenting: boolean;
|
|
|
|
sharingScreen: boolean;
|
2020-12-01 23:52:09 +00:00
|
|
|
speakerTime?: number;
|
2020-11-17 15:07:53 +00:00
|
|
|
videoAspectRatio: number;
|
2021-01-14 18:07:05 +00:00
|
|
|
};
|
2020-11-17 15:07:53 +00:00
|
|
|
|
2023-01-13 20:07:26 +00:00
|
|
|
// eslint-disable-next-line local-rules/type-alias-readonlydeep
|
2021-01-14 18:07:05 +00:00
|
|
|
export type DirectCallStateType = {
|
2020-11-13 19:57:55 +00:00
|
|
|
callMode: CallMode.Direct;
|
2020-11-06 17:36:37 +00:00
|
|
|
conversationId: string;
|
|
|
|
callState?: CallState;
|
|
|
|
callEndedReason?: CallEndedReason;
|
2020-06-04 18:16:19 +00:00
|
|
|
isIncoming: boolean;
|
2021-05-20 21:54:03 +00:00
|
|
|
isSharingScreen?: boolean;
|
2020-06-04 18:16:19 +00:00
|
|
|
isVideoCall: boolean;
|
2020-11-06 17:36:37 +00:00
|
|
|
hasRemoteVideo?: boolean;
|
2021-01-14 18:07:05 +00:00
|
|
|
};
|
2020-07-24 01:35:32 +00:00
|
|
|
|
2023-01-13 20:07:26 +00:00
|
|
|
type GroupCallRingStateType = ReadonlyDeep<
|
2021-08-20 16:06:15 +00:00
|
|
|
| {
|
|
|
|
ringId?: undefined;
|
2023-08-10 16:43:33 +00:00
|
|
|
ringerAci?: undefined;
|
2021-08-20 16:06:15 +00:00
|
|
|
}
|
|
|
|
| {
|
|
|
|
ringId: bigint;
|
2023-08-10 16:43:33 +00:00
|
|
|
ringerAci: AciString;
|
2023-01-13 20:07:26 +00:00
|
|
|
}
|
|
|
|
>;
|
2021-08-20 16:06:15 +00:00
|
|
|
|
2023-01-13 20:07:26 +00:00
|
|
|
// eslint-disable-next-line local-rules/type-alias-readonlydeep
|
2021-01-14 18:07:05 +00:00
|
|
|
export type GroupCallStateType = {
|
2020-11-13 19:57:55 +00:00
|
|
|
callMode: CallMode.Group;
|
|
|
|
conversationId: string;
|
|
|
|
connectionState: GroupCallConnectionState;
|
|
|
|
joinState: GroupCallJoinState;
|
2022-02-08 19:18:51 +00:00
|
|
|
peekInfo?: GroupCallPeekInfoType;
|
2020-11-17 15:07:53 +00:00
|
|
|
remoteParticipants: Array<GroupCallParticipantInfoType>;
|
2022-05-19 03:28:51 +00:00
|
|
|
remoteAudioLevels?: Map<number, number>;
|
2021-08-20 16:06:15 +00:00
|
|
|
} & GroupCallRingStateType;
|
2020-11-13 19:57:55 +00:00
|
|
|
|
2023-01-13 20:07:26 +00:00
|
|
|
// eslint-disable-next-line local-rules/type-alias-readonlydeep
|
2021-01-14 18:07:05 +00:00
|
|
|
export type ActiveCallStateType = {
|
2020-11-06 17:36:37 +00:00
|
|
|
conversationId: string;
|
2020-06-04 18:16:19 +00:00
|
|
|
hasLocalAudio: boolean;
|
|
|
|
hasLocalVideo: boolean;
|
2022-05-19 03:28:51 +00:00
|
|
|
localAudioLevel: number;
|
2022-05-25 18:03:27 +00:00
|
|
|
viewMode: CallViewMode;
|
2023-11-13 14:56:48 +00:00
|
|
|
viewModeBeforePresentation?: CallViewMode;
|
2023-09-20 14:00:01 +00:00
|
|
|
joinedAt: number | null;
|
2021-08-25 21:42:51 +00:00
|
|
|
outgoingRing: boolean;
|
2020-10-01 00:43:05 +00:00
|
|
|
pip: boolean;
|
2021-05-20 21:54:03 +00:00
|
|
|
presentingSource?: PresentedSource;
|
|
|
|
presentingSourcesAvailable?: Array<PresentableSource>;
|
2023-08-10 16:43:33 +00:00
|
|
|
safetyNumberChangedAcis: Array<AciString>;
|
2021-01-08 22:57:54 +00:00
|
|
|
settingsDialogOpen: boolean;
|
2021-05-20 21:54:03 +00:00
|
|
|
showNeedsScreenRecordingPermissionsWarning?: boolean;
|
2020-12-08 19:37:04 +00:00
|
|
|
showParticipantsList: boolean;
|
2021-01-14 18:07:05 +00:00
|
|
|
};
|
2020-11-06 17:36:37 +00:00
|
|
|
|
2023-01-13 20:07:26 +00:00
|
|
|
// eslint-disable-next-line local-rules/type-alias-readonlydeep
|
2021-01-14 18:07:05 +00:00
|
|
|
export type CallsByConversationType = {
|
2020-12-02 18:11:54 +00:00
|
|
|
[conversationId: string]: DirectCallStateType | GroupCallStateType;
|
2021-01-14 18:07:05 +00:00
|
|
|
};
|
2020-12-02 18:11:54 +00:00
|
|
|
|
2023-01-13 20:07:26 +00:00
|
|
|
// eslint-disable-next-line local-rules/type-alias-readonlydeep
|
2020-11-06 17:36:37 +00:00
|
|
|
export type CallingStateType = MediaDeviceSettings & {
|
2020-12-02 18:11:54 +00:00
|
|
|
callsByConversation: CallsByConversationType;
|
2020-11-06 17:36:37 +00:00
|
|
|
activeCallState?: ActiveCallStateType;
|
2020-06-04 18:16:19 +00:00
|
|
|
};
|
|
|
|
|
2023-01-13 20:07:26 +00:00
|
|
|
export type AcceptCallType = ReadonlyDeep<{
|
2020-11-06 17:36:37 +00:00
|
|
|
conversationId: string;
|
2020-06-04 18:16:19 +00:00
|
|
|
asVideoCall: boolean;
|
2023-01-13 20:07:26 +00:00
|
|
|
}>;
|
2020-06-04 18:16:19 +00:00
|
|
|
|
2023-01-13 20:07:26 +00:00
|
|
|
export type CallStateChangeType = ReadonlyDeep<{
|
2020-11-06 17:36:37 +00:00
|
|
|
conversationId: string;
|
2023-09-20 14:00:01 +00:00
|
|
|
acceptedTime: number | null;
|
2020-06-04 18:16:19 +00:00
|
|
|
callState: CallState;
|
2020-10-01 19:09:15 +00:00
|
|
|
callEndedReason?: CallEndedReason;
|
2023-01-13 20:07:26 +00:00
|
|
|
}>;
|
2020-06-04 18:16:19 +00:00
|
|
|
|
2023-01-13 20:07:26 +00:00
|
|
|
export type CancelCallType = ReadonlyDeep<{
|
2020-11-13 19:57:55 +00:00
|
|
|
conversationId: string;
|
2023-01-13 20:07:26 +00:00
|
|
|
}>;
|
2020-11-13 19:57:55 +00:00
|
|
|
|
2023-01-13 20:07:26 +00:00
|
|
|
type CancelIncomingGroupCallRingType = ReadonlyDeep<{
|
2021-08-20 16:06:15 +00:00
|
|
|
conversationId: string;
|
|
|
|
ringId: bigint;
|
2023-01-13 20:07:26 +00:00
|
|
|
}>;
|
2021-08-20 16:06:15 +00:00
|
|
|
|
2023-01-13 20:07:26 +00:00
|
|
|
export type DeclineCallType = ReadonlyDeep<{
|
2020-11-06 17:36:37 +00:00
|
|
|
conversationId: string;
|
2023-01-13 20:07:26 +00:00
|
|
|
}>;
|
2020-06-04 18:16:19 +00:00
|
|
|
|
2023-01-13 20:07:26 +00:00
|
|
|
// eslint-disable-next-line local-rules/type-alias-readonlydeep
|
2020-11-20 17:19:28 +00:00
|
|
|
type GroupCallStateChangeArgumentType = {
|
2020-11-13 19:57:55 +00:00
|
|
|
connectionState: GroupCallConnectionState;
|
2020-11-20 17:19:28 +00:00
|
|
|
conversationId: string;
|
2020-11-13 19:57:55 +00:00
|
|
|
hasLocalAudio: boolean;
|
|
|
|
hasLocalVideo: boolean;
|
2020-11-20 17:19:28 +00:00
|
|
|
joinState: GroupCallJoinState;
|
2020-12-02 18:14:03 +00:00
|
|
|
peekInfo?: GroupCallPeekInfoType;
|
2020-11-17 15:07:53 +00:00
|
|
|
remoteParticipants: Array<GroupCallParticipantInfoType>;
|
2020-11-13 19:57:55 +00:00
|
|
|
};
|
|
|
|
|
2023-01-13 20:07:26 +00:00
|
|
|
// eslint-disable-next-line local-rules/type-alias-readonlydeep
|
2021-11-11 22:43:05 +00:00
|
|
|
type GroupCallStateChangeActionPayloadType =
|
|
|
|
GroupCallStateChangeArgumentType & {
|
2023-08-10 16:43:33 +00:00
|
|
|
ourAci: AciString;
|
2021-11-11 22:43:05 +00:00
|
|
|
};
|
2020-11-20 17:19:28 +00:00
|
|
|
|
2023-01-13 20:07:26 +00:00
|
|
|
type HangUpActionPayloadType = ReadonlyDeep<{
|
2020-11-06 17:36:37 +00:00
|
|
|
conversationId: string;
|
2023-01-13 20:07:26 +00:00
|
|
|
}>;
|
2020-06-04 18:16:19 +00:00
|
|
|
|
2023-01-13 20:07:26 +00:00
|
|
|
type KeyChangedType = ReadonlyDeep<{
|
2023-08-10 16:43:33 +00:00
|
|
|
aci: AciString;
|
2023-01-13 20:07:26 +00:00
|
|
|
}>;
|
2020-12-08 19:37:04 +00:00
|
|
|
|
2023-01-13 20:07:26 +00:00
|
|
|
export type KeyChangeOkType = ReadonlyDeep<{
|
2020-12-08 19:37:04 +00:00
|
|
|
conversationId: string;
|
2023-01-13 20:07:26 +00:00
|
|
|
}>;
|
2020-12-08 19:37:04 +00:00
|
|
|
|
2023-01-13 20:07:26 +00:00
|
|
|
export type IncomingDirectCallType = ReadonlyDeep<{
|
2020-11-06 17:36:37 +00:00
|
|
|
conversationId: string;
|
|
|
|
isVideoCall: boolean;
|
2023-01-13 20:07:26 +00:00
|
|
|
}>;
|
2020-06-04 18:16:19 +00:00
|
|
|
|
2023-01-13 20:07:26 +00:00
|
|
|
type IncomingGroupCallType = ReadonlyDeep<{
|
2021-08-20 16:06:15 +00:00
|
|
|
conversationId: string;
|
|
|
|
ringId: bigint;
|
2023-08-10 16:43:33 +00:00
|
|
|
ringerAci: AciString;
|
2023-01-13 20:07:26 +00:00
|
|
|
}>;
|
2021-08-20 16:06:15 +00:00
|
|
|
|
2023-01-13 20:07:26 +00:00
|
|
|
type PeekNotConnectedGroupCallType = ReadonlyDeep<{
|
2020-11-20 17:19:28 +00:00
|
|
|
conversationId: string;
|
2023-01-13 20:07:26 +00:00
|
|
|
}>;
|
2020-11-20 17:19:28 +00:00
|
|
|
|
2023-01-13 20:07:26 +00:00
|
|
|
type StartDirectCallType = ReadonlyDeep<{
|
2020-11-06 17:36:37 +00:00
|
|
|
conversationId: string;
|
|
|
|
hasLocalAudio: boolean;
|
|
|
|
hasLocalVideo: boolean;
|
2023-01-13 20:07:26 +00:00
|
|
|
}>;
|
2020-11-13 19:57:55 +00:00
|
|
|
|
2023-01-13 20:07:26 +00:00
|
|
|
export type StartCallType = ReadonlyDeep<
|
|
|
|
StartDirectCallType & {
|
|
|
|
callMode: CallMode.Direct | CallMode.Group;
|
|
|
|
}
|
|
|
|
>;
|
2020-06-04 18:16:19 +00:00
|
|
|
|
2023-01-13 20:07:26 +00:00
|
|
|
export type RemoteVideoChangeType = ReadonlyDeep<{
|
2020-11-06 17:36:37 +00:00
|
|
|
conversationId: string;
|
|
|
|
hasVideo: boolean;
|
2023-01-13 20:07:26 +00:00
|
|
|
}>;
|
2020-06-04 18:16:19 +00:00
|
|
|
|
2023-01-13 20:07:26 +00:00
|
|
|
type RemoteSharingScreenChangeType = ReadonlyDeep<{
|
2021-05-20 21:54:03 +00:00
|
|
|
conversationId: string;
|
|
|
|
isSharingScreen: boolean;
|
2023-01-13 20:07:26 +00:00
|
|
|
}>;
|
2021-05-20 21:54:03 +00:00
|
|
|
|
2023-01-13 20:07:26 +00:00
|
|
|
export type SetLocalAudioType = ReadonlyDeep<{
|
2020-06-04 18:16:19 +00:00
|
|
|
enabled: boolean;
|
2023-01-13 20:07:26 +00:00
|
|
|
}>;
|
2020-06-04 18:16:19 +00:00
|
|
|
|
2023-01-13 20:07:26 +00:00
|
|
|
export type SetLocalVideoType = ReadonlyDeep<{
|
2020-06-04 18:16:19 +00:00
|
|
|
enabled: boolean;
|
2023-01-13 20:07:26 +00:00
|
|
|
}>;
|
2020-06-04 18:16:19 +00:00
|
|
|
|
2023-01-13 20:07:26 +00:00
|
|
|
export type SetGroupCallVideoRequestType = ReadonlyDeep<{
|
2020-12-02 01:52:01 +00:00
|
|
|
conversationId: string;
|
|
|
|
resolutions: Array<GroupCallVideoRequest>;
|
2022-09-07 15:52:55 +00:00
|
|
|
speakerHeight: number;
|
2023-01-13 20:07:26 +00:00
|
|
|
}>;
|
2020-12-02 01:52:01 +00:00
|
|
|
|
2023-01-13 20:07:26 +00:00
|
|
|
export type StartCallingLobbyType = ReadonlyDeep<{
|
2020-12-07 20:43:19 +00:00
|
|
|
conversationId: string;
|
|
|
|
isVideoCall: boolean;
|
2023-01-13 20:07:26 +00:00
|
|
|
}>;
|
2020-12-07 20:43:19 +00:00
|
|
|
|
2023-01-13 20:07:26 +00:00
|
|
|
// eslint-disable-next-line local-rules/type-alias-readonlydeep
|
2022-01-07 18:01:23 +00:00
|
|
|
type StartCallingLobbyPayloadType =
|
2020-11-13 19:57:55 +00:00
|
|
|
| {
|
|
|
|
callMode: CallMode.Direct;
|
|
|
|
conversationId: string;
|
|
|
|
hasLocalAudio: boolean;
|
|
|
|
hasLocalVideo: boolean;
|
|
|
|
}
|
|
|
|
| {
|
|
|
|
callMode: CallMode.Group;
|
|
|
|
conversationId: string;
|
|
|
|
connectionState: GroupCallConnectionState;
|
|
|
|
joinState: GroupCallJoinState;
|
|
|
|
hasLocalAudio: boolean;
|
|
|
|
hasLocalVideo: boolean;
|
2021-09-02 22:34:38 +00:00
|
|
|
isConversationTooBigToRing: boolean;
|
2020-12-02 18:14:03 +00:00
|
|
|
peekInfo?: GroupCallPeekInfoType;
|
2020-11-17 15:07:53 +00:00
|
|
|
remoteParticipants: Array<GroupCallParticipantInfoType>;
|
2020-11-13 19:57:55 +00:00
|
|
|
};
|
2020-11-06 17:36:37 +00:00
|
|
|
|
2023-01-13 20:07:26 +00:00
|
|
|
// eslint-disable-next-line local-rules/type-alias-readonlydeep
|
2020-08-27 00:03:42 +00:00
|
|
|
export type SetLocalPreviewType = {
|
|
|
|
element: React.RefObject<HTMLVideoElement> | undefined;
|
2020-06-04 18:16:19 +00:00
|
|
|
};
|
|
|
|
|
2023-01-13 20:07:26 +00:00
|
|
|
// eslint-disable-next-line local-rules/type-alias-readonlydeep
|
2020-08-27 00:03:42 +00:00
|
|
|
export type SetRendererCanvasType = {
|
|
|
|
element: React.RefObject<HTMLCanvasElement> | undefined;
|
2020-06-04 18:16:19 +00:00
|
|
|
};
|
|
|
|
|
2020-10-30 17:52:21 +00:00
|
|
|
// Helpers
|
|
|
|
|
2020-11-13 19:57:55 +00:00
|
|
|
export const getActiveCall = ({
|
|
|
|
activeCallState,
|
|
|
|
callsByConversation,
|
|
|
|
}: CallingStateType): undefined | DirectCallStateType | GroupCallStateType =>
|
|
|
|
activeCallState &&
|
|
|
|
getOwn(callsByConversation, activeCallState.conversationId);
|
|
|
|
|
2021-08-20 16:06:15 +00:00
|
|
|
const getGroupCallRingState = (
|
|
|
|
call: Readonly<undefined | GroupCallStateType>
|
|
|
|
): GroupCallRingStateType =>
|
|
|
|
call?.ringId === undefined
|
|
|
|
? {}
|
2023-08-10 16:43:33 +00:00
|
|
|
: { ringId: call.ringId, ringerAci: call.ringerAci };
|
2021-08-20 16:06:15 +00:00
|
|
|
|
2022-02-08 19:18:51 +00:00
|
|
|
// We might call this function many times in rapid succession (for example, if lots of
|
|
|
|
// people are joining and leaving at once). We want to make sure to update eventually
|
|
|
|
// (if people join and leave for an hour, we don't want you to have to wait an hour to
|
|
|
|
// get an update), and we also don't want to update too often. That's why we use a
|
|
|
|
// "latest queue".
|
|
|
|
const peekQueueByConversation = new Map<string, LatestQueue>();
|
|
|
|
const doGroupCallPeek = (
|
|
|
|
conversationId: string,
|
|
|
|
dispatch: ThunkDispatch<
|
|
|
|
RootStateType,
|
|
|
|
unknown,
|
|
|
|
PeekGroupCallFulfilledActionType
|
|
|
|
>,
|
|
|
|
getState: () => RootStateType
|
|
|
|
) => {
|
|
|
|
const conversation = getOwn(
|
|
|
|
getState().conversations.conversationLookup,
|
|
|
|
conversationId
|
|
|
|
);
|
|
|
|
if (
|
|
|
|
!conversation ||
|
|
|
|
getConversationCallMode(conversation) !== CallMode.Group
|
|
|
|
) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let queue = peekQueueByConversation.get(conversationId);
|
|
|
|
if (!queue) {
|
|
|
|
queue = new LatestQueue();
|
|
|
|
queue.onceEmpty(() => {
|
|
|
|
peekQueueByConversation.delete(conversationId);
|
|
|
|
});
|
|
|
|
peekQueueByConversation.set(conversationId, queue);
|
|
|
|
}
|
|
|
|
|
|
|
|
queue.add(async () => {
|
|
|
|
const state = getState();
|
|
|
|
|
|
|
|
// We make sure we're not trying to peek at a connected (or connecting, or
|
|
|
|
// reconnecting) call. Because this is asynchronous, it's possible that the call
|
|
|
|
// will connect by the time we dispatch, so we also need to do a similar check in
|
|
|
|
// the reducer.
|
|
|
|
const existingCall = getOwn(
|
|
|
|
state.calling.callsByConversation,
|
|
|
|
conversationId
|
|
|
|
);
|
|
|
|
if (
|
2023-08-28 16:30:47 +00:00
|
|
|
existingCall != null &&
|
|
|
|
existingCall.callMode === CallMode.Group &&
|
2022-02-08 19:18:51 +00:00
|
|
|
existingCall.connectionState !== GroupCallConnectionState.NotConnected
|
|
|
|
) {
|
2023-08-28 16:30:47 +00:00
|
|
|
log.info(
|
|
|
|
`doGroupCallPeek/groupv2: Not peeking because the connection state is ${existingCall.connectionState}`
|
|
|
|
);
|
2022-02-08 19:18:51 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we peek right after receiving the message, we may get outdated information.
|
|
|
|
// This is most noticeable when someone leaves. We add a delay and then make sure
|
|
|
|
// to only be peeking once.
|
|
|
|
await Promise.all([sleep(1000), waitForOnline(navigator, window)]);
|
|
|
|
|
2023-08-09 00:53:06 +00:00
|
|
|
let peekInfo = null;
|
2022-02-08 19:18:51 +00:00
|
|
|
try {
|
|
|
|
peekInfo = await calling.peekGroupCall(conversationId);
|
|
|
|
} catch (err) {
|
|
|
|
log.error('Group call peeking failed', Errors.toLogFormat(err));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!peekInfo) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-04-01 01:06:56 +00:00
|
|
|
log.info(
|
|
|
|
`doGroupCallPeek/groupv2(${conversation.groupId}): Found ${peekInfo.deviceCount} devices`
|
|
|
|
);
|
|
|
|
|
2023-08-23 17:07:29 +00:00
|
|
|
const joinState =
|
|
|
|
existingCall?.callMode === CallMode.Group ? existingCall.joinState : null;
|
|
|
|
|
2023-08-28 16:30:47 +00:00
|
|
|
try {
|
|
|
|
await calling.updateCallHistoryForGroupCall(
|
|
|
|
conversationId,
|
|
|
|
joinState,
|
|
|
|
peekInfo
|
|
|
|
);
|
|
|
|
} catch (error) {
|
|
|
|
log.error(
|
|
|
|
'doGroupCallPeek/groupv2: Failed to update call history',
|
|
|
|
Errors.toLogFormat(error)
|
|
|
|
);
|
|
|
|
}
|
2022-02-08 19:18:51 +00:00
|
|
|
|
|
|
|
const formattedPeekInfo = calling.formatGroupCallPeekInfoForRedux(peekInfo);
|
|
|
|
|
|
|
|
dispatch({
|
|
|
|
type: PEEK_GROUP_CALL_FULFILLED,
|
|
|
|
payload: {
|
|
|
|
conversationId,
|
|
|
|
peekInfo: formattedPeekInfo,
|
|
|
|
},
|
|
|
|
});
|
2023-09-27 19:42:38 +00:00
|
|
|
|
|
|
|
dispatch(updateLastMessage(conversationId));
|
2022-02-08 19:18:51 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2020-06-04 18:16:19 +00:00
|
|
|
// Actions
|
|
|
|
|
2020-11-04 17:47:50 +00:00
|
|
|
const ACCEPT_CALL_PENDING = 'calling/ACCEPT_CALL_PENDING';
|
2020-10-08 01:25:33 +00:00
|
|
|
const CANCEL_CALL = 'calling/CANCEL_CALL';
|
2021-08-20 16:06:15 +00:00
|
|
|
const CANCEL_INCOMING_GROUP_CALL_RING =
|
|
|
|
'calling/CANCEL_INCOMING_GROUP_CALL_RING';
|
2023-11-13 14:56:48 +00:00
|
|
|
const CHANGE_CALL_VIEW = 'calling/CHANGE_CALL_VIEW';
|
2022-01-07 18:01:23 +00:00
|
|
|
const START_CALLING_LOBBY = 'calling/START_CALLING_LOBBY';
|
2020-07-10 16:55:23 +00:00
|
|
|
const CALL_STATE_CHANGE_FULFILLED = 'calling/CALL_STATE_CHANGE_FULFILLED';
|
2020-08-27 00:03:42 +00:00
|
|
|
const CHANGE_IO_DEVICE_FULFILLED = 'calling/CHANGE_IO_DEVICE_FULFILLED';
|
2020-10-01 19:09:15 +00:00
|
|
|
const CLOSE_NEED_PERMISSION_SCREEN = 'calling/CLOSE_NEED_PERMISSION_SCREEN';
|
2021-08-20 16:06:15 +00:00
|
|
|
const DECLINE_DIRECT_CALL = 'calling/DECLINE_DIRECT_CALL';
|
2022-02-08 18:30:33 +00:00
|
|
|
const GROUP_CALL_AUDIO_LEVELS_CHANGE = 'calling/GROUP_CALL_AUDIO_LEVELS_CHANGE';
|
2020-11-13 19:57:55 +00:00
|
|
|
const GROUP_CALL_STATE_CHANGE = 'calling/GROUP_CALL_STATE_CHANGE';
|
2020-06-04 18:16:19 +00:00
|
|
|
const HANG_UP = 'calling/HANG_UP';
|
2021-08-20 16:06:15 +00:00
|
|
|
const INCOMING_DIRECT_CALL = 'calling/INCOMING_DIRECT_CALL';
|
|
|
|
const INCOMING_GROUP_CALL = 'calling/INCOMING_GROUP_CALL';
|
2020-12-08 19:37:04 +00:00
|
|
|
const MARK_CALL_TRUSTED = 'calling/MARK_CALL_TRUSTED';
|
|
|
|
const MARK_CALL_UNTRUSTED = 'calling/MARK_CALL_UNTRUSTED';
|
2020-06-04 18:16:19 +00:00
|
|
|
const OUTGOING_CALL = 'calling/OUTGOING_CALL';
|
2022-02-08 19:18:51 +00:00
|
|
|
const PEEK_GROUP_CALL_FULFILLED = 'calling/PEEK_GROUP_CALL_FULFILLED';
|
2020-08-27 00:03:42 +00:00
|
|
|
const REFRESH_IO_DEVICES = 'calling/REFRESH_IO_DEVICES';
|
2021-05-20 21:54:03 +00:00
|
|
|
const REMOTE_SHARING_SCREEN_CHANGE = 'calling/REMOTE_SHARING_SCREEN_CHANGE';
|
2020-06-04 18:16:19 +00:00
|
|
|
const REMOTE_VIDEO_CHANGE = 'calling/REMOTE_VIDEO_CHANGE';
|
2020-12-07 20:43:19 +00:00
|
|
|
const RETURN_TO_ACTIVE_CALL = 'calling/RETURN_TO_ACTIVE_CALL';
|
2020-11-06 17:36:37 +00:00
|
|
|
const SET_LOCAL_AUDIO_FULFILLED = 'calling/SET_LOCAL_AUDIO_FULFILLED';
|
2020-06-04 18:16:19 +00:00
|
|
|
const SET_LOCAL_VIDEO_FULFILLED = 'calling/SET_LOCAL_VIDEO_FULFILLED';
|
2021-08-25 21:42:51 +00:00
|
|
|
const SET_OUTGOING_RING = 'calling/SET_OUTGOING_RING';
|
2021-05-20 21:54:03 +00:00
|
|
|
const SET_PRESENTING = 'calling/SET_PRESENTING';
|
|
|
|
const SET_PRESENTING_SOURCES = 'calling/SET_PRESENTING_SOURCES';
|
|
|
|
const TOGGLE_NEEDS_SCREEN_RECORDING_PERMISSIONS =
|
|
|
|
'calling/TOGGLE_NEEDS_SCREEN_RECORDING_PERMISSIONS';
|
2020-11-13 19:57:55 +00:00
|
|
|
const START_DIRECT_CALL = 'calling/START_DIRECT_CALL';
|
2020-10-08 01:25:33 +00:00
|
|
|
const TOGGLE_PARTICIPANTS = 'calling/TOGGLE_PARTICIPANTS';
|
2020-10-01 00:43:05 +00:00
|
|
|
const TOGGLE_PIP = 'calling/TOGGLE_PIP';
|
2020-08-27 00:03:42 +00:00
|
|
|
const TOGGLE_SETTINGS = 'calling/TOGGLE_SETTINGS';
|
2022-05-25 18:03:27 +00:00
|
|
|
const SWITCH_TO_PRESENTATION_VIEW = 'calling/SWITCH_TO_PRESENTATION_VIEW';
|
|
|
|
const SWITCH_FROM_PRESENTATION_VIEW = 'calling/SWITCH_FROM_PRESENTATION_VIEW';
|
2020-06-04 18:16:19 +00:00
|
|
|
|
2023-01-13 20:07:26 +00:00
|
|
|
type AcceptCallPendingActionType = ReadonlyDeep<{
|
2020-11-04 17:47:50 +00:00
|
|
|
type: 'calling/ACCEPT_CALL_PENDING';
|
2020-06-04 18:16:19 +00:00
|
|
|
payload: AcceptCallType;
|
2023-01-13 20:07:26 +00:00
|
|
|
}>;
|
2020-06-04 18:16:19 +00:00
|
|
|
|
2023-01-13 20:07:26 +00:00
|
|
|
type CancelCallActionType = ReadonlyDeep<{
|
2020-10-08 01:25:33 +00:00
|
|
|
type: 'calling/CANCEL_CALL';
|
2023-01-13 20:07:26 +00:00
|
|
|
}>;
|
2020-10-08 01:25:33 +00:00
|
|
|
|
2023-01-13 20:07:26 +00:00
|
|
|
type CancelIncomingGroupCallRingActionType = ReadonlyDeep<{
|
2021-08-20 16:06:15 +00:00
|
|
|
type: 'calling/CANCEL_INCOMING_GROUP_CALL_RING';
|
|
|
|
payload: CancelIncomingGroupCallRingType;
|
2023-01-13 20:07:26 +00:00
|
|
|
}>;
|
2021-08-20 16:06:15 +00:00
|
|
|
|
2023-01-13 20:07:26 +00:00
|
|
|
// eslint-disable-next-line local-rules/type-alias-readonlydeep
|
2022-01-07 18:01:23 +00:00
|
|
|
type StartCallingLobbyActionType = {
|
|
|
|
type: 'calling/START_CALLING_LOBBY';
|
|
|
|
payload: StartCallingLobbyPayloadType;
|
2020-10-08 01:25:33 +00:00
|
|
|
};
|
|
|
|
|
2023-01-13 20:07:26 +00:00
|
|
|
type CallStateChangeFulfilledActionType = ReadonlyDeep<{
|
2020-07-10 16:55:23 +00:00
|
|
|
type: 'calling/CALL_STATE_CHANGE_FULFILLED';
|
2020-06-04 18:16:19 +00:00
|
|
|
payload: CallStateChangeType;
|
2023-01-13 20:07:26 +00:00
|
|
|
}>;
|
2020-06-04 18:16:19 +00:00
|
|
|
|
2023-01-13 20:07:26 +00:00
|
|
|
type ChangeIODeviceFulfilledActionType = ReadonlyDeep<{
|
2020-08-27 00:03:42 +00:00
|
|
|
type: 'calling/CHANGE_IO_DEVICE_FULFILLED';
|
|
|
|
payload: ChangeIODevicePayloadType;
|
2023-01-13 20:07:26 +00:00
|
|
|
}>;
|
2020-08-27 00:03:42 +00:00
|
|
|
|
2023-01-13 20:07:26 +00:00
|
|
|
type CloseNeedPermissionScreenActionType = ReadonlyDeep<{
|
2020-10-01 19:09:15 +00:00
|
|
|
type: 'calling/CLOSE_NEED_PERMISSION_SCREEN';
|
|
|
|
payload: null;
|
2023-01-13 20:07:26 +00:00
|
|
|
}>;
|
2020-10-01 19:09:15 +00:00
|
|
|
|
2023-01-13 20:07:26 +00:00
|
|
|
type DeclineCallActionType = ReadonlyDeep<{
|
2021-08-20 16:06:15 +00:00
|
|
|
type: 'calling/DECLINE_DIRECT_CALL';
|
2020-06-04 18:16:19 +00:00
|
|
|
payload: DeclineCallType;
|
2023-01-13 20:07:26 +00:00
|
|
|
}>;
|
2020-06-04 18:16:19 +00:00
|
|
|
|
2023-01-13 20:07:26 +00:00
|
|
|
type GroupCallAudioLevelsChangeActionPayloadType = ReadonlyDeep<{
|
2022-02-08 18:30:33 +00:00
|
|
|
conversationId: string;
|
2022-02-25 15:24:05 +00:00
|
|
|
localAudioLevel: number;
|
2022-02-08 18:30:33 +00:00
|
|
|
remoteDeviceStates: ReadonlyArray<{ audioLevel: number; demuxId: number }>;
|
|
|
|
}>;
|
|
|
|
|
2023-01-13 20:07:26 +00:00
|
|
|
type GroupCallAudioLevelsChangeActionType = ReadonlyDeep<{
|
2022-02-08 18:30:33 +00:00
|
|
|
type: 'calling/GROUP_CALL_AUDIO_LEVELS_CHANGE';
|
|
|
|
payload: GroupCallAudioLevelsChangeActionPayloadType;
|
2023-01-13 20:07:26 +00:00
|
|
|
}>;
|
2022-02-08 18:30:33 +00:00
|
|
|
|
2023-01-13 20:07:26 +00:00
|
|
|
// eslint-disable-next-line local-rules/type-alias-readonlydeep
|
2020-11-20 17:19:28 +00:00
|
|
|
export type GroupCallStateChangeActionType = {
|
2020-11-13 19:57:55 +00:00
|
|
|
type: 'calling/GROUP_CALL_STATE_CHANGE';
|
2020-11-20 17:19:28 +00:00
|
|
|
payload: GroupCallStateChangeActionPayloadType;
|
2020-11-13 19:57:55 +00:00
|
|
|
};
|
|
|
|
|
2023-01-13 20:07:26 +00:00
|
|
|
type HangUpActionType = ReadonlyDeep<{
|
2020-06-04 18:16:19 +00:00
|
|
|
type: 'calling/HANG_UP';
|
2022-02-08 19:18:51 +00:00
|
|
|
payload: HangUpActionPayloadType;
|
2023-01-13 20:07:26 +00:00
|
|
|
}>;
|
2020-06-04 18:16:19 +00:00
|
|
|
|
2023-01-13 20:07:26 +00:00
|
|
|
type IncomingDirectCallActionType = ReadonlyDeep<{
|
2021-08-20 16:06:15 +00:00
|
|
|
type: 'calling/INCOMING_DIRECT_CALL';
|
|
|
|
payload: IncomingDirectCallType;
|
2023-01-13 20:07:26 +00:00
|
|
|
}>;
|
2021-08-20 16:06:15 +00:00
|
|
|
|
2023-01-13 20:07:26 +00:00
|
|
|
type IncomingGroupCallActionType = ReadonlyDeep<{
|
2021-08-20 16:06:15 +00:00
|
|
|
type: 'calling/INCOMING_GROUP_CALL';
|
|
|
|
payload: IncomingGroupCallType;
|
2023-01-13 20:07:26 +00:00
|
|
|
}>;
|
2020-06-04 18:16:19 +00:00
|
|
|
|
2023-01-13 20:07:26 +00:00
|
|
|
// eslint-disable-next-line local-rules/type-alias-readonlydeep
|
2020-12-08 19:37:04 +00:00
|
|
|
type KeyChangedActionType = {
|
|
|
|
type: 'calling/MARK_CALL_UNTRUSTED';
|
|
|
|
payload: {
|
2023-08-10 16:43:33 +00:00
|
|
|
safetyNumberChangedAcis: Array<AciString>;
|
2020-12-08 19:37:04 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2023-01-13 20:07:26 +00:00
|
|
|
type KeyChangeOkActionType = ReadonlyDeep<{
|
2020-12-08 19:37:04 +00:00
|
|
|
type: 'calling/MARK_CALL_TRUSTED';
|
|
|
|
payload: null;
|
2023-01-13 20:07:26 +00:00
|
|
|
}>;
|
2020-12-08 19:37:04 +00:00
|
|
|
|
2023-01-13 20:07:26 +00:00
|
|
|
type OutgoingCallActionType = ReadonlyDeep<{
|
2020-06-04 18:16:19 +00:00
|
|
|
type: 'calling/OUTGOING_CALL';
|
2020-11-13 19:57:55 +00:00
|
|
|
payload: StartDirectCallType;
|
2023-01-13 20:07:26 +00:00
|
|
|
}>;
|
2020-06-04 18:16:19 +00:00
|
|
|
|
2023-01-13 20:07:26 +00:00
|
|
|
export type PeekGroupCallFulfilledActionType = ReadonlyDeep<{
|
2022-02-08 19:18:51 +00:00
|
|
|
type: 'calling/PEEK_GROUP_CALL_FULFILLED';
|
2020-11-20 17:19:28 +00:00
|
|
|
payload: {
|
|
|
|
conversationId: string;
|
|
|
|
peekInfo: GroupCallPeekInfoType;
|
|
|
|
};
|
2023-01-13 20:07:26 +00:00
|
|
|
}>;
|
2020-11-20 17:19:28 +00:00
|
|
|
|
2023-01-13 20:07:26 +00:00
|
|
|
// eslint-disable-next-line local-rules/type-alias-readonlydeep
|
2020-08-27 00:03:42 +00:00
|
|
|
type RefreshIODevicesActionType = {
|
|
|
|
type: 'calling/REFRESH_IO_DEVICES';
|
|
|
|
payload: MediaDeviceSettings;
|
|
|
|
};
|
|
|
|
|
2023-01-13 20:07:26 +00:00
|
|
|
type RemoteSharingScreenChangeActionType = ReadonlyDeep<{
|
2021-05-20 21:54:03 +00:00
|
|
|
type: 'calling/REMOTE_SHARING_SCREEN_CHANGE';
|
|
|
|
payload: RemoteSharingScreenChangeType;
|
2023-01-13 20:07:26 +00:00
|
|
|
}>;
|
2021-05-20 21:54:03 +00:00
|
|
|
|
2023-01-13 20:07:26 +00:00
|
|
|
type RemoteVideoChangeActionType = ReadonlyDeep<{
|
2020-06-04 18:16:19 +00:00
|
|
|
type: 'calling/REMOTE_VIDEO_CHANGE';
|
|
|
|
payload: RemoteVideoChangeType;
|
2023-01-13 20:07:26 +00:00
|
|
|
}>;
|
2020-06-04 18:16:19 +00:00
|
|
|
|
2023-01-13 20:07:26 +00:00
|
|
|
type ReturnToActiveCallActionType = ReadonlyDeep<{
|
2020-12-07 20:43:19 +00:00
|
|
|
type: 'calling/RETURN_TO_ACTIVE_CALL';
|
2023-01-13 20:07:26 +00:00
|
|
|
}>;
|
2020-12-07 20:43:19 +00:00
|
|
|
|
2023-01-13 20:07:26 +00:00
|
|
|
type SetLocalAudioActionType = ReadonlyDeep<{
|
2020-11-06 17:36:37 +00:00
|
|
|
type: 'calling/SET_LOCAL_AUDIO_FULFILLED';
|
2020-06-04 18:16:19 +00:00
|
|
|
payload: SetLocalAudioType;
|
2023-01-13 20:07:26 +00:00
|
|
|
}>;
|
2020-06-04 18:16:19 +00:00
|
|
|
|
2023-01-13 20:07:26 +00:00
|
|
|
type SetLocalVideoFulfilledActionType = ReadonlyDeep<{
|
2020-06-04 18:16:19 +00:00
|
|
|
type: 'calling/SET_LOCAL_VIDEO_FULFILLED';
|
|
|
|
payload: SetLocalVideoType;
|
2023-01-13 20:07:26 +00:00
|
|
|
}>;
|
2020-06-04 18:16:19 +00:00
|
|
|
|
2023-01-13 20:07:26 +00:00
|
|
|
type SetPresentingFulfilledActionType = ReadonlyDeep<{
|
2021-05-20 21:54:03 +00:00
|
|
|
type: 'calling/SET_PRESENTING';
|
|
|
|
payload?: PresentedSource;
|
2023-01-13 20:07:26 +00:00
|
|
|
}>;
|
2021-05-20 21:54:03 +00:00
|
|
|
|
2023-01-13 20:07:26 +00:00
|
|
|
// eslint-disable-next-line local-rules/type-alias-readonlydeep
|
2021-05-20 21:54:03 +00:00
|
|
|
type SetPresentingSourcesActionType = {
|
|
|
|
type: 'calling/SET_PRESENTING_SOURCES';
|
|
|
|
payload: Array<PresentableSource>;
|
|
|
|
};
|
|
|
|
|
2023-01-13 20:07:26 +00:00
|
|
|
type SetOutgoingRingActionType = ReadonlyDeep<{
|
2021-08-25 21:42:51 +00:00
|
|
|
type: 'calling/SET_OUTGOING_RING';
|
|
|
|
payload: boolean;
|
2023-01-13 20:07:26 +00:00
|
|
|
}>;
|
2021-08-25 21:42:51 +00:00
|
|
|
|
2023-01-13 20:07:26 +00:00
|
|
|
type StartDirectCallActionType = ReadonlyDeep<{
|
2020-11-13 19:57:55 +00:00
|
|
|
type: 'calling/START_DIRECT_CALL';
|
|
|
|
payload: StartDirectCallType;
|
2023-01-13 20:07:26 +00:00
|
|
|
}>;
|
2020-10-08 01:25:33 +00:00
|
|
|
|
2023-01-13 20:07:26 +00:00
|
|
|
type ToggleNeedsScreenRecordingPermissionsActionType = ReadonlyDeep<{
|
2021-05-20 21:54:03 +00:00
|
|
|
type: 'calling/TOGGLE_NEEDS_SCREEN_RECORDING_PERMISSIONS';
|
2023-01-13 20:07:26 +00:00
|
|
|
}>;
|
2021-05-20 21:54:03 +00:00
|
|
|
|
2023-01-13 20:07:26 +00:00
|
|
|
type ToggleParticipantsActionType = ReadonlyDeep<{
|
2020-10-08 01:25:33 +00:00
|
|
|
type: 'calling/TOGGLE_PARTICIPANTS';
|
2023-01-13 20:07:26 +00:00
|
|
|
}>;
|
2020-10-08 01:25:33 +00:00
|
|
|
|
2023-01-13 20:07:26 +00:00
|
|
|
type TogglePipActionType = ReadonlyDeep<{
|
2020-10-01 00:43:05 +00:00
|
|
|
type: 'calling/TOGGLE_PIP';
|
2023-01-13 20:07:26 +00:00
|
|
|
}>;
|
2020-10-01 00:43:05 +00:00
|
|
|
|
2023-01-13 20:07:26 +00:00
|
|
|
type ToggleSettingsActionType = ReadonlyDeep<{
|
2020-08-27 00:03:42 +00:00
|
|
|
type: 'calling/TOGGLE_SETTINGS';
|
2023-01-13 20:07:26 +00:00
|
|
|
}>;
|
2020-08-27 00:03:42 +00:00
|
|
|
|
2023-11-13 14:56:48 +00:00
|
|
|
type ChangeCallViewActionType = ReadonlyDeep<{
|
|
|
|
type: 'calling/CHANGE_CALL_VIEW';
|
|
|
|
viewMode: CallViewMode;
|
2023-01-13 20:07:26 +00:00
|
|
|
}>;
|
2021-01-08 22:57:54 +00:00
|
|
|
|
2023-01-13 20:07:26 +00:00
|
|
|
type SwitchToPresentationViewActionType = ReadonlyDeep<{
|
2022-05-25 18:03:27 +00:00
|
|
|
type: 'calling/SWITCH_TO_PRESENTATION_VIEW';
|
2023-01-13 20:07:26 +00:00
|
|
|
}>;
|
2022-05-25 18:03:27 +00:00
|
|
|
|
2023-01-13 20:07:26 +00:00
|
|
|
type SwitchFromPresentationViewActionType = ReadonlyDeep<{
|
2022-05-25 18:03:27 +00:00
|
|
|
type: 'calling/SWITCH_FROM_PRESENTATION_VIEW';
|
2023-01-13 20:07:26 +00:00
|
|
|
}>;
|
2022-05-25 18:03:27 +00:00
|
|
|
|
2023-01-13 20:07:26 +00:00
|
|
|
// eslint-disable-next-line local-rules/type-alias-readonlydeep
|
2020-06-04 18:16:19 +00:00
|
|
|
export type CallingActionType =
|
2020-11-04 17:47:50 +00:00
|
|
|
| AcceptCallPendingActionType
|
2020-10-08 01:25:33 +00:00
|
|
|
| CancelCallActionType
|
2021-08-20 16:06:15 +00:00
|
|
|
| CancelIncomingGroupCallRingActionType
|
2023-11-13 14:56:48 +00:00
|
|
|
| ChangeCallViewActionType
|
2022-01-07 18:01:23 +00:00
|
|
|
| StartCallingLobbyActionType
|
2020-07-10 16:55:23 +00:00
|
|
|
| CallStateChangeFulfilledActionType
|
2020-08-27 00:03:42 +00:00
|
|
|
| ChangeIODeviceFulfilledActionType
|
2020-10-01 19:09:15 +00:00
|
|
|
| CloseNeedPermissionScreenActionType
|
2021-09-02 22:34:38 +00:00
|
|
|
| ConversationChangedActionType
|
2022-02-08 19:18:51 +00:00
|
|
|
| ConversationRemovedActionType
|
2020-06-04 18:16:19 +00:00
|
|
|
| DeclineCallActionType
|
2022-02-08 18:30:33 +00:00
|
|
|
| GroupCallAudioLevelsChangeActionType
|
2020-11-13 19:57:55 +00:00
|
|
|
| GroupCallStateChangeActionType
|
2020-06-04 18:16:19 +00:00
|
|
|
| HangUpActionType
|
2021-08-20 16:06:15 +00:00
|
|
|
| IncomingDirectCallActionType
|
|
|
|
| IncomingGroupCallActionType
|
2020-12-08 19:37:04 +00:00
|
|
|
| KeyChangedActionType
|
|
|
|
| KeyChangeOkActionType
|
2020-06-04 18:16:19 +00:00
|
|
|
| OutgoingCallActionType
|
2022-02-08 19:18:51 +00:00
|
|
|
| PeekGroupCallFulfilledActionType
|
2020-08-27 00:03:42 +00:00
|
|
|
| RefreshIODevicesActionType
|
2021-05-20 21:54:03 +00:00
|
|
|
| RemoteSharingScreenChangeActionType
|
2020-06-04 18:16:19 +00:00
|
|
|
| RemoteVideoChangeActionType
|
2020-12-07 20:43:19 +00:00
|
|
|
| ReturnToActiveCallActionType
|
2020-06-04 18:16:19 +00:00
|
|
|
| SetLocalAudioActionType
|
2020-08-27 00:03:42 +00:00
|
|
|
| SetLocalVideoFulfilledActionType
|
2021-05-20 21:54:03 +00:00
|
|
|
| SetPresentingSourcesActionType
|
2021-08-25 21:42:51 +00:00
|
|
|
| SetOutgoingRingActionType
|
2020-11-13 19:57:55 +00:00
|
|
|
| StartDirectCallActionType
|
2021-05-20 21:54:03 +00:00
|
|
|
| ToggleNeedsScreenRecordingPermissionsActionType
|
2020-10-08 01:25:33 +00:00
|
|
|
| ToggleParticipantsActionType
|
2020-10-01 00:43:05 +00:00
|
|
|
| TogglePipActionType
|
2021-05-20 21:54:03 +00:00
|
|
|
| SetPresentingFulfilledActionType
|
2021-01-08 22:57:54 +00:00
|
|
|
| ToggleSettingsActionType
|
2022-05-25 18:03:27 +00:00
|
|
|
| SwitchToPresentationViewActionType
|
|
|
|
| SwitchFromPresentationViewActionType;
|
2020-06-04 18:16:19 +00:00
|
|
|
|
|
|
|
// Action Creators
|
|
|
|
|
|
|
|
function acceptCall(
|
|
|
|
payload: AcceptCallType
|
2020-11-04 17:47:50 +00:00
|
|
|
): ThunkAction<void, RootStateType, unknown, AcceptCallPendingActionType> {
|
2021-08-20 16:06:15 +00:00
|
|
|
return async (dispatch, getState) => {
|
|
|
|
const { conversationId, asVideoCall } = payload;
|
|
|
|
|
|
|
|
const call = getOwn(getState().calling.callsByConversation, conversationId);
|
|
|
|
if (!call) {
|
2021-09-17 18:27:53 +00:00
|
|
|
log.error('Trying to accept a non-existent call');
|
2021-08-20 16:06:15 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (call.callMode) {
|
|
|
|
case CallMode.Direct:
|
|
|
|
await calling.acceptDirectCall(conversationId, asVideoCall);
|
|
|
|
break;
|
|
|
|
case CallMode.Group:
|
2021-09-28 16:35:40 +00:00
|
|
|
await calling.joinGroupCall(conversationId, true, asVideoCall, false);
|
2021-08-20 16:06:15 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
throw missingCaseError(call);
|
|
|
|
}
|
|
|
|
|
2020-11-04 17:47:50 +00:00
|
|
|
dispatch({
|
|
|
|
type: ACCEPT_CALL_PENDING,
|
|
|
|
payload,
|
|
|
|
});
|
2020-06-04 18:16:19 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function callStateChange(
|
|
|
|
payload: CallStateChangeType
|
2020-11-04 17:47:50 +00:00
|
|
|
): ThunkAction<
|
|
|
|
void,
|
|
|
|
RootStateType,
|
|
|
|
unknown,
|
|
|
|
CallStateChangeFulfilledActionType
|
|
|
|
> {
|
|
|
|
return async dispatch => {
|
2023-08-09 00:53:06 +00:00
|
|
|
const { callState, acceptedTime, callEndedReason } = payload;
|
2023-01-10 00:52:01 +00:00
|
|
|
|
2020-11-04 17:47:50 +00:00
|
|
|
if (callState === CallState.Ended) {
|
2021-05-20 21:54:03 +00:00
|
|
|
ipcRenderer.send('close-screen-share-controller');
|
2020-11-04 17:47:50 +00:00
|
|
|
}
|
|
|
|
|
2023-01-10 00:52:01 +00:00
|
|
|
const wasAccepted = acceptedTime != null;
|
|
|
|
const isEnded = callState === CallState.Ended && callEndedReason != null;
|
|
|
|
|
|
|
|
const isLocalHangup = callEndedReason === CallEndedReason.LocalHangup;
|
|
|
|
const isRemoteHangup = callEndedReason === CallEndedReason.RemoteHangup;
|
|
|
|
|
2023-06-13 00:26:46 +00:00
|
|
|
// Play the hangup noise if:
|
|
|
|
if (
|
|
|
|
// 1. I hungup (or declined)
|
|
|
|
(isEnded && isLocalHangup) ||
|
|
|
|
// 2. I answered and then the call ended
|
|
|
|
(isEnded && wasAccepted) ||
|
|
|
|
// 3. I called and they declined
|
|
|
|
(isEnded && !wasAccepted && isRemoteHangup)
|
|
|
|
) {
|
|
|
|
await callingTones.playEndCall();
|
|
|
|
}
|
|
|
|
|
2020-11-04 17:47:50 +00:00
|
|
|
dispatch({
|
|
|
|
type: CALL_STATE_CHANGE_FULFILLED,
|
|
|
|
payload,
|
|
|
|
});
|
2020-07-10 16:55:23 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-08-27 00:03:42 +00:00
|
|
|
function changeIODevice(
|
|
|
|
payload: ChangeIODevicePayloadType
|
2020-11-04 17:47:50 +00:00
|
|
|
): ThunkAction<
|
|
|
|
void,
|
|
|
|
RootStateType,
|
|
|
|
unknown,
|
|
|
|
ChangeIODeviceFulfilledActionType
|
|
|
|
> {
|
|
|
|
return async dispatch => {
|
|
|
|
// Only `setPreferredCamera` returns a Promise.
|
|
|
|
if (payload.type === CallingDeviceType.CAMERA) {
|
|
|
|
await calling.setPreferredCamera(payload.selectedDevice);
|
|
|
|
} else if (payload.type === CallingDeviceType.MICROPHONE) {
|
|
|
|
calling.setPreferredMicrophone(payload.selectedDevice);
|
|
|
|
} else if (payload.type === CallingDeviceType.SPEAKER) {
|
|
|
|
calling.setPreferredSpeaker(payload.selectedDevice);
|
|
|
|
}
|
|
|
|
dispatch({
|
|
|
|
type: CHANGE_IO_DEVICE_FULFILLED,
|
|
|
|
payload,
|
|
|
|
});
|
2020-08-27 00:03:42 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-10-01 19:09:15 +00:00
|
|
|
function closeNeedPermissionScreen(): CloseNeedPermissionScreenActionType {
|
|
|
|
return {
|
|
|
|
type: CLOSE_NEED_PERMISSION_SCREEN,
|
|
|
|
payload: null,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-11-13 19:57:55 +00:00
|
|
|
function cancelCall(payload: CancelCallType): CancelCallActionType {
|
|
|
|
calling.stopCallingLobby(payload.conversationId);
|
2020-10-08 01:25:33 +00:00
|
|
|
|
|
|
|
return {
|
|
|
|
type: CANCEL_CALL,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-08-20 16:06:15 +00:00
|
|
|
function cancelIncomingGroupCallRing(
|
|
|
|
payload: CancelIncomingGroupCallRingType
|
|
|
|
): CancelIncomingGroupCallRingActionType {
|
2020-06-04 18:16:19 +00:00
|
|
|
return {
|
2021-08-20 16:06:15 +00:00
|
|
|
type: CANCEL_INCOMING_GROUP_CALL_RING,
|
2020-06-04 18:16:19 +00:00
|
|
|
payload,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-08-20 16:06:15 +00:00
|
|
|
function declineCall(
|
|
|
|
payload: DeclineCallType
|
|
|
|
): ThunkAction<
|
|
|
|
void,
|
|
|
|
RootStateType,
|
|
|
|
unknown,
|
|
|
|
CancelIncomingGroupCallRingActionType | DeclineCallActionType
|
|
|
|
> {
|
|
|
|
return (dispatch, getState) => {
|
|
|
|
const { conversationId } = payload;
|
|
|
|
|
|
|
|
const call = getOwn(getState().calling.callsByConversation, conversationId);
|
|
|
|
if (!call) {
|
2021-09-17 18:27:53 +00:00
|
|
|
log.error('Trying to decline a non-existent call');
|
2021-08-20 16:06:15 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (call.callMode) {
|
|
|
|
case CallMode.Direct:
|
|
|
|
calling.declineDirectCall(conversationId);
|
|
|
|
dispatch({
|
|
|
|
type: DECLINE_DIRECT_CALL,
|
|
|
|
payload,
|
|
|
|
});
|
|
|
|
break;
|
|
|
|
case CallMode.Group: {
|
|
|
|
const { ringId } = call;
|
|
|
|
if (ringId === undefined) {
|
2021-09-17 18:27:53 +00:00
|
|
|
log.error('Trying to decline a group call without a ring ID');
|
2021-08-20 16:06:15 +00:00
|
|
|
} else {
|
|
|
|
calling.declineGroupCall(conversationId, ringId);
|
|
|
|
dispatch({
|
|
|
|
type: CANCEL_INCOMING_GROUP_CALL_RING,
|
|
|
|
payload: { conversationId, ringId },
|
|
|
|
});
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
throw missingCaseError(call);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-05-20 21:54:03 +00:00
|
|
|
function getPresentingSources(): ThunkAction<
|
|
|
|
void,
|
|
|
|
RootStateType,
|
|
|
|
unknown,
|
|
|
|
| SetPresentingSourcesActionType
|
|
|
|
| ToggleNeedsScreenRecordingPermissionsActionType
|
|
|
|
> {
|
|
|
|
return async (dispatch, getState) => {
|
|
|
|
// We check if the user has permissions first before calling desktopCapturer
|
|
|
|
// Next we call getPresentingSources so that one gets the prompt for permissions,
|
|
|
|
// if necessary.
|
|
|
|
// Finally, we have the if statement which shows the modal, if needed.
|
|
|
|
// It is in this exact order so that during first-time-use one will be
|
|
|
|
// prompted for permissions and if they so happen to deny we can still
|
|
|
|
// capture that state correctly.
|
|
|
|
const platform = getPlatform(getState());
|
|
|
|
const needsPermission =
|
|
|
|
platform === 'darwin' && !hasScreenCapturePermission();
|
|
|
|
|
|
|
|
const sources = await calling.getPresentingSources();
|
|
|
|
|
|
|
|
if (needsPermission) {
|
|
|
|
dispatch({
|
|
|
|
type: TOGGLE_NEEDS_SCREEN_RECORDING_PERMISSIONS,
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
dispatch({
|
|
|
|
type: SET_PRESENTING_SOURCES,
|
|
|
|
payload: sources,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-02-08 18:30:33 +00:00
|
|
|
function groupCallAudioLevelsChange(
|
|
|
|
payload: GroupCallAudioLevelsChangeActionPayloadType
|
|
|
|
): GroupCallAudioLevelsChangeActionType {
|
|
|
|
return { type: GROUP_CALL_AUDIO_LEVELS_CHANGE, payload };
|
|
|
|
}
|
|
|
|
|
2020-11-13 19:57:55 +00:00
|
|
|
function groupCallStateChange(
|
2020-11-20 17:19:28 +00:00
|
|
|
payload: GroupCallStateChangeArgumentType
|
|
|
|
): ThunkAction<void, RootStateType, unknown, GroupCallStateChangeActionType> {
|
2021-05-20 21:54:03 +00:00
|
|
|
return async (dispatch, getState) => {
|
|
|
|
let didSomeoneStartPresenting: boolean;
|
|
|
|
const activeCall = getActiveCall(getState().calling);
|
|
|
|
if (activeCall?.callMode === CallMode.Group) {
|
|
|
|
const wasSomeonePresenting = activeCall.remoteParticipants.some(
|
|
|
|
participant => participant.presenting
|
|
|
|
);
|
|
|
|
const isSomeonePresenting = payload.remoteParticipants.some(
|
|
|
|
participant => participant.presenting
|
|
|
|
);
|
|
|
|
didSomeoneStartPresenting = !wasSomeonePresenting && isSomeonePresenting;
|
|
|
|
} else {
|
|
|
|
didSomeoneStartPresenting = false;
|
|
|
|
}
|
|
|
|
|
2023-08-10 16:43:33 +00:00
|
|
|
const { ourAci } = getState().user;
|
|
|
|
strictAssert(ourAci, 'groupCallStateChange failed to fetch our ACI');
|
2022-02-23 18:48:40 +00:00
|
|
|
|
2023-08-28 16:30:47 +00:00
|
|
|
log.info(
|
|
|
|
'groupCallStateChange:',
|
|
|
|
payload.conversationId,
|
|
|
|
GroupCallConnectionState[payload.connectionState],
|
|
|
|
GroupCallJoinState[payload.joinState]
|
|
|
|
);
|
2020-11-20 17:19:28 +00:00
|
|
|
dispatch({
|
|
|
|
type: GROUP_CALL_STATE_CHANGE,
|
|
|
|
payload: {
|
|
|
|
...payload,
|
2023-08-10 16:43:33 +00:00
|
|
|
ourAci,
|
2020-11-20 17:19:28 +00:00
|
|
|
},
|
|
|
|
});
|
2021-05-20 21:54:03 +00:00
|
|
|
|
|
|
|
if (didSomeoneStartPresenting) {
|
2022-12-21 18:41:48 +00:00
|
|
|
void callingTones.someonePresenting();
|
2021-05-20 21:54:03 +00:00
|
|
|
}
|
2021-06-01 19:47:55 +00:00
|
|
|
|
|
|
|
if (payload.connectionState === GroupCallConnectionState.NotConnected) {
|
|
|
|
ipcRenderer.send('close-screen-share-controller');
|
|
|
|
}
|
2020-11-13 19:57:55 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-08-16 23:52:09 +00:00
|
|
|
function hangUpActiveCall(
|
|
|
|
reason: string
|
|
|
|
): ThunkAction<void, RootStateType, unknown, HangUpActionType> {
|
2022-02-08 19:18:51 +00:00
|
|
|
return async (dispatch, getState) => {
|
2022-01-24 20:32:09 +00:00
|
|
|
const state = getState();
|
|
|
|
|
|
|
|
const activeCall = getActiveCall(state.calling);
|
|
|
|
if (!activeCall) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const { conversationId } = activeCall;
|
|
|
|
|
2022-08-16 23:52:09 +00:00
|
|
|
calling.hangup(conversationId, reason);
|
2022-02-08 19:18:51 +00:00
|
|
|
|
2022-01-24 20:32:09 +00:00
|
|
|
dispatch({
|
|
|
|
type: HANG_UP,
|
|
|
|
payload: {
|
|
|
|
conversationId,
|
|
|
|
},
|
|
|
|
});
|
2022-02-08 19:18:51 +00:00
|
|
|
|
|
|
|
if (activeCall.callMode === CallMode.Group) {
|
|
|
|
// We want to give the group call time to disconnect.
|
|
|
|
await sleep(1000);
|
|
|
|
doGroupCallPeek(conversationId, dispatch, getState);
|
|
|
|
}
|
2022-01-24 20:32:09 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-12-08 19:37:04 +00:00
|
|
|
function keyChanged(
|
|
|
|
payload: KeyChangedType
|
|
|
|
): ThunkAction<void, RootStateType, unknown, KeyChangedActionType> {
|
|
|
|
return (dispatch, getState) => {
|
|
|
|
const state = getState();
|
|
|
|
const { activeCallState } = state.calling;
|
|
|
|
|
|
|
|
const activeCall = getActiveCall(state.calling);
|
|
|
|
if (!activeCall || !activeCallState) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (activeCall.callMode === CallMode.Group) {
|
2023-08-10 16:43:33 +00:00
|
|
|
const acisChanged = new Set(activeCallState.safetyNumberChangedAcis);
|
2020-12-08 19:37:04 +00:00
|
|
|
|
2023-08-16 20:54:39 +00:00
|
|
|
// Iterate over each participant to ensure that the service id passed in
|
2020-12-08 19:37:04 +00:00
|
|
|
// matches one of the participants in the group call.
|
|
|
|
activeCall.remoteParticipants.forEach(participant => {
|
2023-08-10 16:43:33 +00:00
|
|
|
if (participant.aci === payload.aci) {
|
|
|
|
acisChanged.add(participant.aci);
|
2020-12-08 19:37:04 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2023-08-10 16:43:33 +00:00
|
|
|
const safetyNumberChangedAcis = Array.from(acisChanged);
|
2020-12-08 19:37:04 +00:00
|
|
|
|
2023-08-10 16:43:33 +00:00
|
|
|
if (safetyNumberChangedAcis.length) {
|
2020-12-08 19:37:04 +00:00
|
|
|
dispatch({
|
|
|
|
type: MARK_CALL_UNTRUSTED,
|
|
|
|
payload: {
|
2023-08-10 16:43:33 +00:00
|
|
|
safetyNumberChangedAcis,
|
2020-12-08 19:37:04 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function keyChangeOk(
|
|
|
|
payload: KeyChangeOkType
|
|
|
|
): ThunkAction<void, RootStateType, unknown, KeyChangeOkActionType> {
|
|
|
|
return dispatch => {
|
|
|
|
calling.resendGroupCallMediaKeys(payload.conversationId);
|
|
|
|
|
|
|
|
dispatch({
|
|
|
|
type: MARK_CALL_TRUSTED,
|
|
|
|
payload: null,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-08-20 16:06:15 +00:00
|
|
|
function receiveIncomingDirectCall(
|
|
|
|
payload: IncomingDirectCallType
|
2023-07-28 00:29:10 +00:00
|
|
|
): ThunkAction<void, RootStateType, unknown, IncomingDirectCallActionType> {
|
|
|
|
return (dispatch, getState) => {
|
|
|
|
const callState = getState().calling;
|
|
|
|
|
|
|
|
if (
|
|
|
|
callState.activeCallState &&
|
|
|
|
callState.activeCallState.conversationId === payload.conversationId
|
|
|
|
) {
|
|
|
|
calling.stopCallingLobby();
|
|
|
|
}
|
|
|
|
|
|
|
|
dispatch({
|
|
|
|
type: INCOMING_DIRECT_CALL,
|
|
|
|
payload,
|
|
|
|
});
|
2021-08-20 16:06:15 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function receiveIncomingGroupCall(
|
|
|
|
payload: IncomingGroupCallType
|
|
|
|
): IncomingGroupCallActionType {
|
2020-06-04 18:16:19 +00:00
|
|
|
return {
|
2021-08-20 16:06:15 +00:00
|
|
|
type: INCOMING_GROUP_CALL,
|
2020-06-04 18:16:19 +00:00
|
|
|
payload,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-05-20 21:54:03 +00:00
|
|
|
function openSystemPreferencesAction(): ThunkAction<
|
|
|
|
void,
|
|
|
|
RootStateType,
|
|
|
|
unknown,
|
|
|
|
never
|
|
|
|
> {
|
|
|
|
return () => {
|
2022-12-21 18:41:48 +00:00
|
|
|
void openSystemPreferences();
|
2021-05-20 21:54:03 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-11-13 19:57:55 +00:00
|
|
|
function outgoingCall(payload: StartDirectCallType): OutgoingCallActionType {
|
2020-06-04 18:16:19 +00:00
|
|
|
return {
|
|
|
|
type: OUTGOING_CALL,
|
|
|
|
payload,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-02-08 19:18:51 +00:00
|
|
|
function peekGroupCallForTheFirstTime(
|
|
|
|
conversationId: string
|
|
|
|
): ThunkAction<void, RootStateType, unknown, PeekGroupCallFulfilledActionType> {
|
|
|
|
return (dispatch, getState) => {
|
|
|
|
const call = getOwn(getState().calling.callsByConversation, conversationId);
|
|
|
|
const shouldPeek =
|
|
|
|
!call || (call.callMode === CallMode.Group && !call.peekInfo);
|
|
|
|
if (shouldPeek) {
|
|
|
|
doGroupCallPeek(conversationId, dispatch, getState);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-04-01 01:06:56 +00:00
|
|
|
function peekGroupCallIfItHasMembers(
|
|
|
|
conversationId: string
|
|
|
|
): ThunkAction<void, RootStateType, unknown, PeekGroupCallFulfilledActionType> {
|
|
|
|
return (dispatch, getState) => {
|
|
|
|
const call = getOwn(getState().calling.callsByConversation, conversationId);
|
|
|
|
const shouldPeek =
|
|
|
|
call &&
|
|
|
|
call.callMode === CallMode.Group &&
|
|
|
|
call.joinState === GroupCallJoinState.NotJoined &&
|
|
|
|
call.peekInfo &&
|
|
|
|
call.peekInfo.deviceCount > 0;
|
|
|
|
if (shouldPeek) {
|
|
|
|
doGroupCallPeek(conversationId, dispatch, getState);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-11-20 17:19:28 +00:00
|
|
|
function peekNotConnectedGroupCall(
|
|
|
|
payload: PeekNotConnectedGroupCallType
|
2022-02-08 19:18:51 +00:00
|
|
|
): ThunkAction<void, RootStateType, unknown, PeekGroupCallFulfilledActionType> {
|
2020-11-20 17:19:28 +00:00
|
|
|
return (dispatch, getState) => {
|
|
|
|
const { conversationId } = payload;
|
2022-02-08 19:18:51 +00:00
|
|
|
doGroupCallPeek(conversationId, dispatch, getState);
|
2020-11-20 17:19:28 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-08-27 00:03:42 +00:00
|
|
|
function refreshIODevices(
|
|
|
|
payload: MediaDeviceSettings
|
|
|
|
): RefreshIODevicesActionType {
|
|
|
|
return {
|
|
|
|
type: REFRESH_IO_DEVICES,
|
|
|
|
payload,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-05-20 21:54:03 +00:00
|
|
|
function remoteSharingScreenChange(
|
|
|
|
payload: RemoteSharingScreenChangeType
|
|
|
|
): RemoteSharingScreenChangeActionType {
|
|
|
|
return {
|
|
|
|
type: REMOTE_SHARING_SCREEN_CHANGE,
|
|
|
|
payload,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-06-04 18:16:19 +00:00
|
|
|
function remoteVideoChange(
|
|
|
|
payload: RemoteVideoChangeType
|
|
|
|
): RemoteVideoChangeActionType {
|
|
|
|
return {
|
|
|
|
type: REMOTE_VIDEO_CHANGE,
|
|
|
|
payload,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-12-07 20:43:19 +00:00
|
|
|
function returnToActiveCall(): ReturnToActiveCallActionType {
|
|
|
|
return {
|
|
|
|
type: RETURN_TO_ACTIVE_CALL,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-09-28 19:00:22 +00:00
|
|
|
function setIsCallActive(
|
|
|
|
isCallActive: boolean
|
|
|
|
): ThunkAction<void, RootStateType, unknown, never> {
|
|
|
|
return () => {
|
|
|
|
window.SignalContext.setIsCallActive(isCallActive);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-11-04 17:47:50 +00:00
|
|
|
function setLocalPreview(
|
|
|
|
payload: SetLocalPreviewType
|
|
|
|
): ThunkAction<void, RootStateType, unknown, never> {
|
|
|
|
return () => {
|
|
|
|
calling.videoCapturer.setLocalPreview(payload.element);
|
2020-06-04 18:16:19 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-11-04 17:47:50 +00:00
|
|
|
function setRendererCanvas(
|
|
|
|
payload: SetRendererCanvasType
|
|
|
|
): ThunkAction<void, RootStateType, unknown, never> {
|
|
|
|
return () => {
|
|
|
|
calling.videoRenderer.setCanvas(payload.element);
|
2020-06-04 18:16:19 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-11-06 17:36:37 +00:00
|
|
|
function setLocalAudio(
|
|
|
|
payload: SetLocalAudioType
|
|
|
|
): ThunkAction<void, RootStateType, unknown, SetLocalAudioActionType> {
|
|
|
|
return (dispatch, getState) => {
|
2020-11-13 19:57:55 +00:00
|
|
|
const activeCall = getActiveCall(getState().calling);
|
|
|
|
if (!activeCall) {
|
2021-09-17 18:27:53 +00:00
|
|
|
log.warn('Trying to set local audio when no call is active');
|
2020-11-13 19:57:55 +00:00
|
|
|
return;
|
2020-11-06 17:36:37 +00:00
|
|
|
}
|
2020-06-04 18:16:19 +00:00
|
|
|
|
2020-11-13 19:57:55 +00:00
|
|
|
calling.setOutgoingAudio(activeCall.conversationId, payload.enabled);
|
|
|
|
|
2020-11-06 17:36:37 +00:00
|
|
|
dispatch({
|
|
|
|
type: SET_LOCAL_AUDIO_FULFILLED,
|
|
|
|
payload,
|
|
|
|
});
|
2020-06-04 18:16:19 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-11-04 17:47:50 +00:00
|
|
|
function setLocalVideo(
|
|
|
|
payload: SetLocalVideoType
|
|
|
|
): ThunkAction<void, RootStateType, unknown, SetLocalVideoFulfilledActionType> {
|
2020-11-06 17:36:37 +00:00
|
|
|
return async (dispatch, getState) => {
|
2020-11-13 19:57:55 +00:00
|
|
|
const activeCall = getActiveCall(getState().calling);
|
|
|
|
if (!activeCall) {
|
2021-09-17 18:27:53 +00:00
|
|
|
log.warn('Trying to set local video when no call is active');
|
2020-11-13 19:57:55 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-11-04 17:47:50 +00:00
|
|
|
let enabled: boolean;
|
|
|
|
if (await requestCameraPermissions()) {
|
2020-11-13 19:57:55 +00:00
|
|
|
if (
|
|
|
|
activeCall.callMode === CallMode.Group ||
|
|
|
|
(activeCall.callMode === CallMode.Direct && activeCall.callState)
|
|
|
|
) {
|
|
|
|
calling.setOutgoingVideo(activeCall.conversationId, payload.enabled);
|
2020-11-04 17:47:50 +00:00
|
|
|
} else if (payload.enabled) {
|
|
|
|
calling.enableLocalCamera();
|
|
|
|
} else {
|
2021-05-20 21:54:03 +00:00
|
|
|
calling.disableLocalVideo();
|
2020-11-04 17:47:50 +00:00
|
|
|
}
|
|
|
|
({ enabled } = payload);
|
|
|
|
} else {
|
|
|
|
enabled = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
dispatch({
|
|
|
|
type: SET_LOCAL_VIDEO_FULFILLED,
|
|
|
|
payload: {
|
|
|
|
...payload,
|
|
|
|
enabled,
|
|
|
|
},
|
|
|
|
});
|
2020-06-04 18:16:19 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-12-02 01:52:01 +00:00
|
|
|
function setGroupCallVideoRequest(
|
|
|
|
payload: SetGroupCallVideoRequestType
|
|
|
|
): ThunkAction<void, RootStateType, unknown, never> {
|
|
|
|
return () => {
|
|
|
|
calling.setGroupCallVideoRequest(
|
|
|
|
payload.conversationId,
|
|
|
|
payload.resolutions.map(resolution => ({
|
|
|
|
...resolution,
|
|
|
|
// The `framerate` property in RingRTC has to be set, even if it's set to
|
|
|
|
// `undefined`.
|
|
|
|
framerate: undefined,
|
2022-09-07 15:52:55 +00:00
|
|
|
})),
|
|
|
|
payload.speakerHeight
|
2020-12-02 01:52:01 +00:00
|
|
|
);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-05-20 21:54:03 +00:00
|
|
|
function setPresenting(
|
|
|
|
sourceToPresent?: PresentedSource
|
|
|
|
): ThunkAction<void, RootStateType, unknown, SetPresentingFulfilledActionType> {
|
|
|
|
return async (dispatch, getState) => {
|
|
|
|
const callingState = getState().calling;
|
|
|
|
const { activeCallState } = callingState;
|
|
|
|
const activeCall = getActiveCall(callingState);
|
|
|
|
if (!activeCall || !activeCallState) {
|
2021-09-17 18:27:53 +00:00
|
|
|
log.warn('Trying to present when no call is active');
|
2021-05-20 21:54:03 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-08-01 16:06:29 +00:00
|
|
|
await calling.setPresenting(
|
2021-05-20 21:54:03 +00:00
|
|
|
activeCall.conversationId,
|
|
|
|
activeCallState.hasLocalVideo,
|
|
|
|
sourceToPresent
|
|
|
|
);
|
|
|
|
|
|
|
|
dispatch({
|
|
|
|
type: SET_PRESENTING,
|
|
|
|
payload: sourceToPresent,
|
|
|
|
});
|
|
|
|
|
|
|
|
if (sourceToPresent) {
|
|
|
|
await callingTones.someonePresenting();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-08-25 21:42:51 +00:00
|
|
|
function setOutgoingRing(payload: boolean): SetOutgoingRingActionType {
|
|
|
|
return {
|
|
|
|
type: SET_OUTGOING_RING,
|
|
|
|
payload,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-12-06 17:31:44 +00:00
|
|
|
function onOutgoingVideoCallInConversation(
|
|
|
|
conversationId: string
|
|
|
|
): ThunkAction<
|
|
|
|
void,
|
|
|
|
RootStateType,
|
|
|
|
unknown,
|
|
|
|
StartCallingLobbyActionType | ShowToastActionType
|
|
|
|
> {
|
|
|
|
return async (dispatch, getState) => {
|
|
|
|
const conversation = window.ConversationController.get(conversationId);
|
|
|
|
if (!conversation) {
|
|
|
|
throw new Error(
|
|
|
|
`onOutgoingVideoCallInConversation: No conversation found for conversation ${conversationId}`
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
log.info('onOutgoingVideoCallInConversation: about to start a video call');
|
|
|
|
|
2023-09-06 00:34:51 +00:00
|
|
|
const call = getOwn(getState().calling.callsByConversation, conversationId);
|
2022-12-06 17:31:44 +00:00
|
|
|
|
2023-09-06 00:34:51 +00:00
|
|
|
// Technically not necessary, but isAnybodyElseInGroupCall requires it
|
|
|
|
const ourAci = window.storage.user.getCheckedAci();
|
|
|
|
const isOngoingGroupCall =
|
|
|
|
call &&
|
|
|
|
ourAci &&
|
|
|
|
call.callMode === CallMode.Group &&
|
|
|
|
call.peekInfo &&
|
|
|
|
isAnybodyElseInGroupCall(call.peekInfo, ourAci);
|
2022-12-06 17:31:44 +00:00
|
|
|
|
2023-09-06 00:34:51 +00:00
|
|
|
// If it's a group call on an announcementsOnly group, only allow join if the call
|
|
|
|
// has already been started (presumably by the admin)
|
|
|
|
if (conversation.get('announcementsOnly') && !conversation.areWeAdmin()) {
|
2022-12-06 17:31:44 +00:00
|
|
|
if (!isOngoingGroupCall) {
|
|
|
|
dispatch({
|
|
|
|
type: SHOW_TOAST,
|
|
|
|
payload: {
|
|
|
|
toastType: ToastType.CannotStartGroupCall,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-06 00:34:51 +00:00
|
|
|
const source = isOngoingGroupCall
|
|
|
|
? SafetyNumberChangeSource.JoinCall
|
|
|
|
: SafetyNumberChangeSource.InitiateCall;
|
|
|
|
|
|
|
|
if (await isCallSafe(conversation.attributes, source)) {
|
2022-12-06 17:31:44 +00:00
|
|
|
log.info(
|
|
|
|
'onOutgoingVideoCallInConversation: call is deemed "safe". Making call'
|
|
|
|
);
|
2023-08-09 00:53:06 +00:00
|
|
|
dispatch(
|
|
|
|
startCallingLobby({
|
|
|
|
conversationId,
|
|
|
|
isVideoCall: true,
|
|
|
|
})
|
|
|
|
);
|
2022-12-06 17:31:44 +00:00
|
|
|
log.info('onOutgoingVideoCallInConversation: started the call');
|
|
|
|
} else {
|
|
|
|
log.info(
|
|
|
|
'onOutgoingVideoCallInConversation: call is deemed "unsafe". Stopping'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function onOutgoingAudioCallInConversation(
|
|
|
|
conversationId: string
|
|
|
|
): ThunkAction<void, RootStateType, unknown, StartCallingLobbyActionType> {
|
|
|
|
return async (dispatch, getState) => {
|
|
|
|
const conversation = window.ConversationController.get(conversationId);
|
|
|
|
if (!conversation) {
|
|
|
|
throw new Error(
|
|
|
|
`onOutgoingAudioCallInConversation: No conversation found for conversation ${conversationId}`
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!isDirectConversation(conversation.attributes)) {
|
|
|
|
throw new Error(
|
|
|
|
`onOutgoingAudioCallInConversation: Conversation ${conversation.idForLogging()} is not 1:1`
|
|
|
|
);
|
|
|
|
}
|
2023-09-06 00:34:51 +00:00
|
|
|
// Because audio calls are currently restricted to 1:1 conversations, this will always
|
|
|
|
// be a new call we are initiating.
|
|
|
|
const source = SafetyNumberChangeSource.InitiateCall;
|
2022-12-06 17:31:44 +00:00
|
|
|
|
|
|
|
log.info('onOutgoingAudioCallInConversation: about to start an audio call');
|
|
|
|
|
2023-09-06 00:34:51 +00:00
|
|
|
if (await isCallSafe(conversation.attributes, source)) {
|
2022-12-06 17:31:44 +00:00
|
|
|
log.info(
|
|
|
|
'onOutgoingAudioCallInConversation: call is deemed "safe". Making call'
|
|
|
|
);
|
|
|
|
startCallingLobby({
|
|
|
|
conversationId,
|
|
|
|
isVideoCall: false,
|
|
|
|
})(dispatch, getState, undefined);
|
|
|
|
log.info('onOutgoingAudioCallInConversation: started the call');
|
|
|
|
} else {
|
|
|
|
log.info(
|
|
|
|
'onOutgoingAudioCallInConversation: call is deemed "unsafe". Stopping'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-01-07 18:01:23 +00:00
|
|
|
function startCallingLobby({
|
|
|
|
conversationId,
|
|
|
|
isVideoCall,
|
|
|
|
}: StartCallingLobbyType): ThunkAction<
|
|
|
|
void,
|
|
|
|
RootStateType,
|
|
|
|
unknown,
|
|
|
|
StartCallingLobbyActionType
|
|
|
|
> {
|
|
|
|
return async (dispatch, getState) => {
|
|
|
|
const state = getState();
|
|
|
|
const conversation = getOwn(
|
|
|
|
state.conversations.conversationLookup,
|
|
|
|
conversationId
|
|
|
|
);
|
|
|
|
strictAssert(
|
|
|
|
conversation,
|
|
|
|
"startCallingLobby: can't start lobby without a conversation"
|
|
|
|
);
|
2020-12-07 20:43:19 +00:00
|
|
|
|
2022-02-16 18:33:52 +00:00
|
|
|
strictAssert(
|
|
|
|
!state.calling.activeCallState,
|
|
|
|
"startCallingLobby: can't start lobby if a call is active"
|
|
|
|
);
|
|
|
|
|
2022-01-07 18:01:23 +00:00
|
|
|
// The group call device count is considered 0 for a direct call.
|
|
|
|
const groupCall = getGroupCall(conversationId, state.calling);
|
|
|
|
const groupCallDeviceCount =
|
2022-02-08 19:18:51 +00:00
|
|
|
groupCall?.peekInfo?.deviceCount ||
|
2022-01-07 18:01:23 +00:00
|
|
|
groupCall?.remoteParticipants.length ||
|
|
|
|
0;
|
|
|
|
|
|
|
|
const callLobbyData = await calling.startCallingLobby({
|
|
|
|
conversation,
|
|
|
|
hasLocalAudio: groupCallDeviceCount < 8,
|
|
|
|
hasLocalVideo: isVideoCall,
|
|
|
|
});
|
|
|
|
if (!callLobbyData) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
dispatch({
|
|
|
|
type: START_CALLING_LOBBY,
|
|
|
|
payload: {
|
|
|
|
...callLobbyData,
|
|
|
|
conversationId,
|
|
|
|
isConversationTooBigToRing: isConversationTooBigToRing(conversation),
|
|
|
|
},
|
|
|
|
});
|
2020-10-08 01:25:33 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-11-13 19:57:55 +00:00
|
|
|
function startCall(
|
|
|
|
payload: StartCallType
|
|
|
|
): ThunkAction<void, RootStateType, unknown, StartDirectCallActionType> {
|
2021-09-28 16:35:40 +00:00
|
|
|
return async (dispatch, getState) => {
|
2020-11-13 19:57:55 +00:00
|
|
|
switch (payload.callMode) {
|
|
|
|
case CallMode.Direct:
|
2022-04-01 01:06:35 +00:00
|
|
|
await calling.startOutgoingDirectCall(
|
2020-11-13 19:57:55 +00:00
|
|
|
payload.conversationId,
|
|
|
|
payload.hasLocalAudio,
|
|
|
|
payload.hasLocalVideo
|
|
|
|
);
|
|
|
|
dispatch({
|
|
|
|
type: START_DIRECT_CALL,
|
|
|
|
payload,
|
|
|
|
});
|
|
|
|
break;
|
2021-08-25 21:42:51 +00:00
|
|
|
case CallMode.Group: {
|
2021-09-02 22:34:38 +00:00
|
|
|
let outgoingRing: boolean;
|
|
|
|
|
|
|
|
const state = getState();
|
|
|
|
const { activeCallState } = state.calling;
|
2021-09-07 16:20:13 +00:00
|
|
|
if (isGroupCallOutboundRingEnabled() && activeCallState?.outgoingRing) {
|
2021-09-02 22:34:38 +00:00
|
|
|
const conversation = getOwn(
|
|
|
|
state.conversations.conversationLookup,
|
|
|
|
activeCallState.conversationId
|
|
|
|
);
|
|
|
|
outgoingRing = Boolean(
|
|
|
|
conversation && !isConversationTooBigToRing(conversation)
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
outgoingRing = false;
|
|
|
|
}
|
|
|
|
|
2021-09-28 16:35:40 +00:00
|
|
|
await calling.joinGroupCall(
|
2020-11-13 19:57:55 +00:00
|
|
|
payload.conversationId,
|
|
|
|
payload.hasLocalAudio,
|
2021-08-25 21:42:51 +00:00
|
|
|
payload.hasLocalVideo,
|
|
|
|
outgoingRing
|
2020-11-13 19:57:55 +00:00
|
|
|
);
|
|
|
|
// The calling service should already be wired up to Redux so we don't need to
|
|
|
|
// dispatch anything here.
|
|
|
|
break;
|
2021-08-25 21:42:51 +00:00
|
|
|
}
|
2020-11-13 19:57:55 +00:00
|
|
|
default:
|
|
|
|
throw missingCaseError(payload.callMode);
|
|
|
|
}
|
2020-10-08 01:25:33 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function toggleParticipants(): ToggleParticipantsActionType {
|
|
|
|
return {
|
|
|
|
type: TOGGLE_PARTICIPANTS,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-10-01 00:43:05 +00:00
|
|
|
function togglePip(): TogglePipActionType {
|
|
|
|
return {
|
|
|
|
type: TOGGLE_PIP,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-05-20 21:54:03 +00:00
|
|
|
function toggleScreenRecordingPermissionsDialog(): ToggleNeedsScreenRecordingPermissionsActionType {
|
|
|
|
return {
|
|
|
|
type: TOGGLE_NEEDS_SCREEN_RECORDING_PERMISSIONS,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-08-27 00:03:42 +00:00
|
|
|
function toggleSettings(): ToggleSettingsActionType {
|
|
|
|
return {
|
|
|
|
type: TOGGLE_SETTINGS,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-11-13 14:56:48 +00:00
|
|
|
function changeCallView(mode: CallViewMode): ChangeCallViewActionType {
|
2021-01-08 22:57:54 +00:00
|
|
|
return {
|
2023-11-13 14:56:48 +00:00
|
|
|
type: CHANGE_CALL_VIEW,
|
|
|
|
viewMode: mode,
|
2021-01-08 22:57:54 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-05-25 18:03:27 +00:00
|
|
|
function switchToPresentationView(): SwitchToPresentationViewActionType {
|
|
|
|
return {
|
|
|
|
type: SWITCH_TO_PRESENTATION_VIEW,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function switchFromPresentationView(): SwitchFromPresentationViewActionType {
|
|
|
|
return {
|
|
|
|
type: SWITCH_FROM_PRESENTATION_VIEW,
|
|
|
|
};
|
|
|
|
}
|
2020-06-04 18:16:19 +00:00
|
|
|
export const actions = {
|
|
|
|
acceptCall,
|
|
|
|
callStateChange,
|
2021-05-20 21:54:03 +00:00
|
|
|
cancelCall,
|
2021-08-20 16:06:15 +00:00
|
|
|
cancelIncomingGroupCallRing,
|
2023-11-13 14:56:48 +00:00
|
|
|
changeCallView,
|
2020-08-27 00:03:42 +00:00
|
|
|
changeIODevice,
|
2020-10-01 19:09:15 +00:00
|
|
|
closeNeedPermissionScreen,
|
2020-06-04 18:16:19 +00:00
|
|
|
declineCall,
|
2021-05-20 21:54:03 +00:00
|
|
|
getPresentingSources,
|
2022-02-08 18:30:33 +00:00
|
|
|
groupCallAudioLevelsChange,
|
2020-11-13 19:57:55 +00:00
|
|
|
groupCallStateChange,
|
2022-01-24 20:32:09 +00:00
|
|
|
hangUpActiveCall,
|
2020-12-08 19:37:04 +00:00
|
|
|
keyChangeOk,
|
2021-05-20 21:54:03 +00:00
|
|
|
keyChanged,
|
2022-12-06 17:31:44 +00:00
|
|
|
onOutgoingVideoCallInConversation,
|
|
|
|
onOutgoingAudioCallInConversation,
|
2021-05-20 21:54:03 +00:00
|
|
|
openSystemPreferencesAction,
|
2020-06-04 18:16:19 +00:00
|
|
|
outgoingCall,
|
2022-02-08 19:18:51 +00:00
|
|
|
peekGroupCallForTheFirstTime,
|
2022-04-01 01:06:56 +00:00
|
|
|
peekGroupCallIfItHasMembers,
|
2020-11-20 17:19:28 +00:00
|
|
|
peekNotConnectedGroupCall,
|
2021-08-20 16:06:15 +00:00
|
|
|
receiveIncomingDirectCall,
|
|
|
|
receiveIncomingGroupCall,
|
2020-08-27 00:03:42 +00:00
|
|
|
refreshIODevices,
|
2021-05-20 21:54:03 +00:00
|
|
|
remoteSharingScreenChange,
|
2020-06-04 18:16:19 +00:00
|
|
|
remoteVideoChange,
|
2020-12-07 20:43:19 +00:00
|
|
|
returnToActiveCall,
|
2021-05-20 21:54:03 +00:00
|
|
|
setGroupCallVideoRequest,
|
2021-09-28 19:00:22 +00:00
|
|
|
setIsCallActive,
|
2020-06-04 18:16:19 +00:00
|
|
|
setLocalAudio,
|
2021-05-20 21:54:03 +00:00
|
|
|
setLocalPreview,
|
2020-06-04 18:16:19 +00:00
|
|
|
setLocalVideo,
|
2023-11-13 14:56:48 +00:00
|
|
|
setOutgoingRing,
|
2021-05-20 21:54:03 +00:00
|
|
|
setPresenting,
|
|
|
|
setRendererCanvas,
|
2020-10-08 01:25:33 +00:00
|
|
|
startCall,
|
2021-05-20 21:54:03 +00:00
|
|
|
startCallingLobby,
|
2022-05-25 18:03:27 +00:00
|
|
|
switchToPresentationView,
|
|
|
|
switchFromPresentationView,
|
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,
|
2020-06-04 18:16:19 +00:00
|
|
|
};
|
|
|
|
|
2023-01-19 19:56:02 +00:00
|
|
|
export const useCallingActions = (): BoundActionCreatorsMapObject<
|
|
|
|
typeof actions
|
|
|
|
> => useBoundActions(actions);
|
|
|
|
|
2023-01-13 20:07:26 +00:00
|
|
|
export type ActionsType = ReadonlyDeep<typeof actions>;
|
2020-06-04 18:16:19 +00:00
|
|
|
|
|
|
|
// Reducer
|
|
|
|
|
2020-10-30 17:52:21 +00:00
|
|
|
export function getEmptyState(): CallingStateType {
|
2020-06-04 18:16:19 +00:00
|
|
|
return {
|
2020-08-27 00:03:42 +00:00
|
|
|
availableCameras: [],
|
|
|
|
availableMicrophones: [],
|
|
|
|
availableSpeakers: [],
|
|
|
|
selectedCamera: undefined,
|
|
|
|
selectedMicrophone: undefined,
|
|
|
|
selectedSpeaker: undefined,
|
2020-11-06 17:36:37 +00:00
|
|
|
|
|
|
|
callsByConversation: {},
|
|
|
|
activeCallState: undefined,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-08-20 16:06:15 +00:00
|
|
|
function getGroupCall(
|
2020-12-02 18:14:03 +00:00
|
|
|
conversationId: string,
|
2021-08-20 16:06:15 +00:00
|
|
|
state: Readonly<CallingStateType>
|
|
|
|
): undefined | GroupCallStateType {
|
|
|
|
const call = getOwn(state.callsByConversation, conversationId);
|
|
|
|
return call?.callMode === CallMode.Group ? call : undefined;
|
2020-12-02 18:14:03 +00:00
|
|
|
}
|
|
|
|
|
2020-11-06 17:36:37 +00:00
|
|
|
function removeConversationFromState(
|
2020-12-14 19:47:21 +00:00
|
|
|
state: Readonly<CallingStateType>,
|
2020-11-06 17:36:37 +00:00
|
|
|
conversationId: string
|
|
|
|
): CallingStateType {
|
|
|
|
return {
|
|
|
|
...(conversationId === state.activeCallState?.conversationId
|
|
|
|
? omit(state, 'activeCallState')
|
|
|
|
: state),
|
|
|
|
callsByConversation: omit(state.callsByConversation, conversationId),
|
2020-06-04 18:16:19 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export function reducer(
|
2020-12-14 19:47:21 +00:00
|
|
|
state: Readonly<CallingStateType> = getEmptyState(),
|
|
|
|
action: Readonly<CallingActionType>
|
2020-06-04 18:16:19 +00:00
|
|
|
): CallingStateType {
|
2020-11-06 17:36:37 +00:00
|
|
|
const { callsByConversation } = state;
|
|
|
|
|
2022-01-07 18:01:23 +00:00
|
|
|
if (action.type === START_CALLING_LOBBY) {
|
2021-08-20 16:06:15 +00:00
|
|
|
const { conversationId } = action.payload;
|
|
|
|
|
2020-11-13 19:57:55 +00:00
|
|
|
let call: DirectCallStateType | GroupCallStateType;
|
2021-08-25 21:42:51 +00:00
|
|
|
let outgoingRing: boolean;
|
2020-11-13 19:57:55 +00:00
|
|
|
switch (action.payload.callMode) {
|
|
|
|
case CallMode.Direct:
|
|
|
|
call = {
|
|
|
|
callMode: CallMode.Direct,
|
2021-08-20 16:06:15 +00:00
|
|
|
conversationId,
|
2020-11-13 19:57:55 +00:00
|
|
|
isIncoming: false,
|
|
|
|
isVideoCall: action.payload.hasLocalVideo,
|
|
|
|
};
|
2021-08-25 21:42:51 +00:00
|
|
|
outgoingRing = true;
|
2020-11-13 19:57:55 +00:00
|
|
|
break;
|
2021-08-20 16:06:15 +00:00
|
|
|
case CallMode.Group: {
|
2020-11-13 19:57:55 +00:00
|
|
|
// We expect to be in this state briefly. The Calling service should update the
|
|
|
|
// call state shortly.
|
2021-08-20 16:06:15 +00:00
|
|
|
const existingCall = getGroupCall(conversationId, state);
|
2021-09-02 22:34:38 +00:00
|
|
|
const ringState = getGroupCallRingState(existingCall);
|
2020-11-13 19:57:55 +00:00
|
|
|
call = {
|
|
|
|
callMode: CallMode.Group,
|
2021-08-20 16:06:15 +00:00
|
|
|
conversationId,
|
2020-11-13 19:57:55 +00:00
|
|
|
connectionState: action.payload.connectionState,
|
|
|
|
joinState: action.payload.joinState,
|
2020-12-02 18:14:03 +00:00
|
|
|
peekInfo: action.payload.peekInfo ||
|
2021-08-20 16:06:15 +00:00
|
|
|
existingCall?.peekInfo || {
|
2023-08-10 16:43:33 +00:00
|
|
|
acis: action.payload.remoteParticipants.map(({ aci }) => aci),
|
2020-12-02 18:14:03 +00:00
|
|
|
maxDevices: Infinity,
|
|
|
|
deviceCount: action.payload.remoteParticipants.length,
|
|
|
|
},
|
2020-11-13 19:57:55 +00:00
|
|
|
remoteParticipants: action.payload.remoteParticipants,
|
2021-09-02 22:34:38 +00:00
|
|
|
...ringState,
|
2020-11-13 19:57:55 +00:00
|
|
|
};
|
2021-08-25 21:42:51 +00:00
|
|
|
outgoingRing =
|
2021-09-07 16:20:13 +00:00
|
|
|
isGroupCallOutboundRingEnabled() &&
|
2021-09-02 22:34:38 +00:00
|
|
|
!ringState.ringId &&
|
2023-08-10 16:43:33 +00:00
|
|
|
!call.peekInfo?.acis.length &&
|
2021-09-02 22:34:38 +00:00
|
|
|
!call.remoteParticipants.length &&
|
|
|
|
!action.payload.isConversationTooBigToRing;
|
2020-11-13 19:57:55 +00:00
|
|
|
break;
|
2021-08-20 16:06:15 +00:00
|
|
|
}
|
2020-11-13 19:57:55 +00:00
|
|
|
default:
|
|
|
|
throw missingCaseError(action.payload);
|
|
|
|
}
|
|
|
|
|
2020-10-08 01:25:33 +00:00
|
|
|
return {
|
|
|
|
...state,
|
2020-11-06 17:36:37 +00:00
|
|
|
callsByConversation: {
|
|
|
|
...callsByConversation,
|
2020-11-13 19:57:55 +00:00
|
|
|
[action.payload.conversationId]: call,
|
2020-11-06 17:36:37 +00:00
|
|
|
},
|
|
|
|
activeCallState: {
|
|
|
|
conversationId: action.payload.conversationId,
|
2020-11-13 19:57:55 +00:00
|
|
|
hasLocalAudio: action.payload.hasLocalAudio,
|
|
|
|
hasLocalVideo: action.payload.hasLocalVideo,
|
2022-05-19 03:28:51 +00:00
|
|
|
localAudioLevel: 0,
|
2023-11-13 14:56:48 +00:00
|
|
|
viewMode: CallViewMode.Paginated,
|
2020-11-06 17:36:37 +00:00
|
|
|
pip: false,
|
2023-08-10 16:43:33 +00:00
|
|
|
safetyNumberChangedAcis: [],
|
2020-11-06 17:36:37 +00:00
|
|
|
settingsDialogOpen: false,
|
2020-12-08 19:37:04 +00:00
|
|
|
showParticipantsList: false,
|
2021-08-25 21:42:51 +00:00
|
|
|
outgoingRing,
|
2023-09-20 14:00:01 +00:00
|
|
|
joinedAt: null,
|
2020-11-06 17:36:37 +00:00
|
|
|
},
|
2020-10-08 01:25:33 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-11-13 19:57:55 +00:00
|
|
|
if (action.type === START_DIRECT_CALL) {
|
2020-10-08 01:25:33 +00:00
|
|
|
return {
|
|
|
|
...state,
|
2020-11-06 17:36:37 +00:00
|
|
|
callsByConversation: {
|
|
|
|
...callsByConversation,
|
|
|
|
[action.payload.conversationId]: {
|
2020-11-13 19:57:55 +00:00
|
|
|
callMode: CallMode.Direct,
|
2020-11-06 17:36:37 +00:00
|
|
|
conversationId: action.payload.conversationId,
|
|
|
|
callState: CallState.Prering,
|
|
|
|
isIncoming: false,
|
|
|
|
isVideoCall: action.payload.hasLocalVideo,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
activeCallState: {
|
|
|
|
conversationId: action.payload.conversationId,
|
|
|
|
hasLocalAudio: action.payload.hasLocalAudio,
|
|
|
|
hasLocalVideo: action.payload.hasLocalVideo,
|
2022-05-19 03:28:51 +00:00
|
|
|
localAudioLevel: 0,
|
2023-11-13 14:56:48 +00:00
|
|
|
viewMode: CallViewMode.Paginated,
|
2020-11-06 17:36:37 +00:00
|
|
|
pip: false,
|
2023-08-10 16:43:33 +00:00
|
|
|
safetyNumberChangedAcis: [],
|
2020-11-06 17:36:37 +00:00
|
|
|
settingsDialogOpen: false,
|
2020-12-08 19:37:04 +00:00
|
|
|
showParticipantsList: false,
|
2021-08-25 21:42:51 +00:00
|
|
|
outgoingRing: true,
|
2023-09-20 14:00:01 +00:00
|
|
|
joinedAt: null,
|
2020-11-06 17:36:37 +00:00
|
|
|
},
|
2020-10-08 01:25:33 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-11-04 17:47:50 +00:00
|
|
|
if (action.type === ACCEPT_CALL_PENDING) {
|
2020-11-06 17:36:37 +00:00
|
|
|
if (!has(state.callsByConversation, action.payload.conversationId)) {
|
2021-09-17 18:27:53 +00:00
|
|
|
log.warn('Unable to accept a non-existent call');
|
2020-11-06 17:36:37 +00:00
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
2020-06-04 18:16:19 +00:00
|
|
|
return {
|
|
|
|
...state,
|
2020-11-06 17:36:37 +00:00
|
|
|
activeCallState: {
|
|
|
|
conversationId: action.payload.conversationId,
|
|
|
|
hasLocalAudio: true,
|
|
|
|
hasLocalVideo: action.payload.asVideoCall,
|
2022-05-19 03:28:51 +00:00
|
|
|
localAudioLevel: 0,
|
2023-11-13 14:56:48 +00:00
|
|
|
viewMode: CallViewMode.Paginated,
|
2020-11-06 17:36:37 +00:00
|
|
|
pip: false,
|
2023-08-10 16:43:33 +00:00
|
|
|
safetyNumberChangedAcis: [],
|
2020-11-06 17:36:37 +00:00
|
|
|
settingsDialogOpen: false,
|
2020-12-08 19:37:04 +00:00
|
|
|
showParticipantsList: false,
|
2021-08-25 21:42:51 +00:00
|
|
|
outgoingRing: false,
|
2023-09-20 14:00:01 +00:00
|
|
|
joinedAt: null,
|
2020-11-06 17:36:37 +00:00
|
|
|
},
|
2020-06-04 18:16:19 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-10-01 19:09:15 +00:00
|
|
|
if (
|
2020-10-08 01:25:33 +00:00
|
|
|
action.type === CANCEL_CALL ||
|
2020-10-01 19:09:15 +00:00
|
|
|
action.type === HANG_UP ||
|
|
|
|
action.type === CLOSE_NEED_PERMISSION_SCREEN
|
|
|
|
) {
|
2020-11-13 19:57:55 +00:00
|
|
|
const activeCall = getActiveCall(state);
|
|
|
|
if (!activeCall) {
|
2021-09-17 18:27:53 +00:00
|
|
|
log.warn('No active call to remove');
|
2020-11-06 17:36:37 +00:00
|
|
|
return state;
|
|
|
|
}
|
2020-11-13 19:57:55 +00:00
|
|
|
switch (activeCall.callMode) {
|
|
|
|
case CallMode.Direct:
|
|
|
|
return removeConversationFromState(state, activeCall.conversationId);
|
|
|
|
case CallMode.Group:
|
|
|
|
return omit(state, 'activeCallState');
|
|
|
|
default:
|
|
|
|
throw missingCaseError(activeCall);
|
|
|
|
}
|
2020-11-06 17:36:37 +00:00
|
|
|
}
|
|
|
|
|
2021-08-20 16:06:15 +00:00
|
|
|
if (action.type === CANCEL_INCOMING_GROUP_CALL_RING) {
|
|
|
|
const { conversationId, ringId } = action.payload;
|
|
|
|
|
|
|
|
const groupCall = getGroupCall(conversationId, state);
|
|
|
|
if (!groupCall || groupCall.ringId !== ringId) {
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
callsByConversation: {
|
|
|
|
...callsByConversation,
|
2023-08-10 16:43:33 +00:00
|
|
|
[conversationId]: omit(groupCall, ['ringId', 'ringerAci']),
|
2021-08-20 16:06:15 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-09-02 22:34:38 +00:00
|
|
|
if (action.type === 'CONVERSATION_CHANGED') {
|
|
|
|
const activeCall = getActiveCall(state);
|
|
|
|
const { activeCallState } = state;
|
|
|
|
if (
|
|
|
|
!activeCallState?.outgoingRing ||
|
|
|
|
activeCallState.conversationId !== action.payload.id ||
|
|
|
|
activeCall?.callMode !== CallMode.Group ||
|
|
|
|
activeCall.joinState !== GroupCallJoinState.NotJoined ||
|
|
|
|
!isConversationTooBigToRing(action.payload.data)
|
|
|
|
) {
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
activeCallState: { ...activeCallState, outgoingRing: false },
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-02-08 19:18:51 +00:00
|
|
|
if (action.type === 'CONVERSATION_REMOVED') {
|
|
|
|
return removeConversationFromState(state, action.payload.id);
|
|
|
|
}
|
|
|
|
|
2021-08-20 16:06:15 +00:00
|
|
|
if (action.type === DECLINE_DIRECT_CALL) {
|
2020-11-06 17:36:37 +00:00
|
|
|
return removeConversationFromState(state, action.payload.conversationId);
|
2020-06-04 18:16:19 +00:00
|
|
|
}
|
|
|
|
|
2021-08-20 16:06:15 +00:00
|
|
|
if (action.type === INCOMING_DIRECT_CALL) {
|
2020-06-04 18:16:19 +00:00
|
|
|
return {
|
|
|
|
...state,
|
2020-11-06 17:36:37 +00:00
|
|
|
callsByConversation: {
|
|
|
|
...callsByConversation,
|
|
|
|
[action.payload.conversationId]: {
|
2020-11-13 19:57:55 +00:00
|
|
|
callMode: CallMode.Direct,
|
2020-11-06 17:36:37 +00:00
|
|
|
conversationId: action.payload.conversationId,
|
|
|
|
callState: CallState.Prering,
|
|
|
|
isIncoming: true,
|
|
|
|
isVideoCall: action.payload.isVideoCall,
|
|
|
|
},
|
|
|
|
},
|
2020-06-04 18:16:19 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-08-20 16:06:15 +00:00
|
|
|
if (action.type === INCOMING_GROUP_CALL) {
|
2023-08-10 16:43:33 +00:00
|
|
|
const { conversationId, ringId, ringerAci } = action.payload;
|
2021-08-20 16:06:15 +00:00
|
|
|
|
|
|
|
let groupCall: GroupCallStateType;
|
|
|
|
const existingGroupCall = getGroupCall(conversationId, state);
|
|
|
|
if (existingGroupCall) {
|
2023-08-10 16:43:33 +00:00
|
|
|
if (existingGroupCall.ringerAci) {
|
2021-09-17 18:27:53 +00:00
|
|
|
log.info('Group call was already ringing');
|
2021-08-20 16:06:15 +00:00
|
|
|
return state;
|
|
|
|
}
|
|
|
|
if (existingGroupCall.joinState !== GroupCallJoinState.NotJoined) {
|
2021-09-17 18:27:53 +00:00
|
|
|
log.info("Got a ring for a call we're already in");
|
2021-08-20 16:06:15 +00:00
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
|
|
|
groupCall = {
|
|
|
|
...existingGroupCall,
|
|
|
|
ringId,
|
2023-08-10 16:43:33 +00:00
|
|
|
ringerAci,
|
2021-08-20 16:06:15 +00:00
|
|
|
};
|
|
|
|
} else {
|
|
|
|
groupCall = {
|
|
|
|
callMode: CallMode.Group,
|
|
|
|
conversationId,
|
|
|
|
connectionState: GroupCallConnectionState.NotConnected,
|
|
|
|
joinState: GroupCallJoinState.NotJoined,
|
|
|
|
peekInfo: {
|
2023-08-10 16:43:33 +00:00
|
|
|
acis: [],
|
2021-08-20 16:06:15 +00:00
|
|
|
maxDevices: Infinity,
|
|
|
|
deviceCount: 0,
|
|
|
|
},
|
|
|
|
remoteParticipants: [],
|
|
|
|
ringId,
|
2023-08-10 16:43:33 +00:00
|
|
|
ringerAci,
|
2021-08-20 16:06:15 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
callsByConversation: {
|
|
|
|
...callsByConversation,
|
|
|
|
[conversationId]: groupCall,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-06-04 18:16:19 +00:00
|
|
|
if (action.type === OUTGOING_CALL) {
|
|
|
|
return {
|
|
|
|
...state,
|
2020-11-06 17:36:37 +00:00
|
|
|
callsByConversation: {
|
|
|
|
...callsByConversation,
|
|
|
|
[action.payload.conversationId]: {
|
2020-11-13 19:57:55 +00:00
|
|
|
callMode: CallMode.Direct,
|
2020-11-06 17:36:37 +00:00
|
|
|
conversationId: action.payload.conversationId,
|
|
|
|
callState: CallState.Prering,
|
|
|
|
isIncoming: false,
|
|
|
|
isVideoCall: action.payload.hasLocalVideo,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
activeCallState: {
|
|
|
|
conversationId: action.payload.conversationId,
|
|
|
|
hasLocalAudio: action.payload.hasLocalAudio,
|
|
|
|
hasLocalVideo: action.payload.hasLocalVideo,
|
2022-05-19 03:28:51 +00:00
|
|
|
localAudioLevel: 0,
|
2023-11-13 14:56:48 +00:00
|
|
|
viewMode: CallViewMode.Paginated,
|
2020-11-06 17:36:37 +00:00
|
|
|
pip: false,
|
2023-08-10 16:43:33 +00:00
|
|
|
safetyNumberChangedAcis: [],
|
2020-11-06 17:36:37 +00:00
|
|
|
settingsDialogOpen: false,
|
2020-12-08 19:37:04 +00:00
|
|
|
showParticipantsList: false,
|
2021-08-25 21:42:51 +00:00
|
|
|
outgoingRing: true,
|
2023-09-20 14:00:01 +00:00
|
|
|
joinedAt: null,
|
2020-11-06 17:36:37 +00:00
|
|
|
},
|
2020-06-04 18:16:19 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-07-10 16:55:23 +00:00
|
|
|
if (action.type === CALL_STATE_CHANGE_FULFILLED) {
|
2020-10-01 19:09:15 +00:00
|
|
|
// We want to keep the state around for ended calls if they resulted in a message
|
|
|
|
// request so we can show the "needs permission" screen.
|
|
|
|
if (
|
|
|
|
action.payload.callState === CallState.Ended &&
|
|
|
|
action.payload.callEndedReason !==
|
|
|
|
CallEndedReason.RemoteHangupNeedPermission
|
|
|
|
) {
|
2020-11-06 17:36:37 +00:00
|
|
|
return removeConversationFromState(state, action.payload.conversationId);
|
2020-06-04 18:16:19 +00:00
|
|
|
}
|
2020-11-06 17:36:37 +00:00
|
|
|
|
|
|
|
const call = getOwn(
|
|
|
|
state.callsByConversation,
|
|
|
|
action.payload.conversationId
|
|
|
|
);
|
2020-11-13 19:57:55 +00:00
|
|
|
if (call?.callMode !== CallMode.Direct) {
|
2021-09-17 18:27:53 +00:00
|
|
|
log.warn('Cannot update state for a non-direct call');
|
2020-11-06 17:36:37 +00:00
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
|
|
|
let activeCallState: undefined | ActiveCallStateType;
|
|
|
|
if (
|
|
|
|
state.activeCallState?.conversationId === action.payload.conversationId
|
|
|
|
) {
|
|
|
|
activeCallState = {
|
|
|
|
...state.activeCallState,
|
2023-09-20 14:00:01 +00:00
|
|
|
joinedAt: action.payload.acceptedTime ?? null,
|
2020-11-06 17:36:37 +00:00
|
|
|
};
|
|
|
|
} else {
|
|
|
|
({ activeCallState } = state);
|
|
|
|
}
|
|
|
|
|
2020-06-04 18:16:19 +00:00
|
|
|
return {
|
|
|
|
...state,
|
2020-11-06 17:36:37 +00:00
|
|
|
callsByConversation: {
|
|
|
|
...callsByConversation,
|
|
|
|
[action.payload.conversationId]: {
|
|
|
|
...call,
|
|
|
|
callState: action.payload.callState,
|
|
|
|
callEndedReason: action.payload.callEndedReason,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
activeCallState,
|
2020-06-04 18:16:19 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-02-08 18:30:33 +00:00
|
|
|
if (action.type === GROUP_CALL_AUDIO_LEVELS_CHANGE) {
|
2022-05-19 03:28:51 +00:00
|
|
|
const { conversationId, remoteDeviceStates } = action.payload;
|
2022-02-08 18:30:33 +00:00
|
|
|
|
2022-02-25 15:24:05 +00:00
|
|
|
const { activeCallState } = state;
|
2022-02-08 18:30:33 +00:00
|
|
|
const existingCall = getGroupCall(conversationId, state);
|
2022-02-25 15:24:05 +00:00
|
|
|
|
|
|
|
// The PiP check is an optimization. We don't need to update audio levels if the user
|
|
|
|
// cannot see them.
|
|
|
|
if (!activeCallState || activeCallState.pip || !existingCall) {
|
2022-02-08 18:30:33 +00:00
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
2022-05-19 03:28:51 +00:00
|
|
|
const localAudioLevel = truncateAudioLevel(action.payload.localAudioLevel);
|
2022-02-25 15:24:05 +00:00
|
|
|
|
2022-05-19 03:28:51 +00:00
|
|
|
const remoteAudioLevels = new Map<number, number>();
|
2022-02-08 18:30:33 +00:00
|
|
|
remoteDeviceStates.forEach(({ audioLevel, demuxId }) => {
|
|
|
|
// We expect `audioLevel` to be a number but have this check just in case.
|
2022-05-19 03:28:51 +00:00
|
|
|
if (typeof audioLevel !== 'number') {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const graded = truncateAudioLevel(audioLevel);
|
|
|
|
if (graded > 0) {
|
|
|
|
remoteAudioLevels.set(demuxId, graded);
|
2022-02-08 18:30:33 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// This action is dispatched frequently. This equality check helps avoid re-renders.
|
2022-05-19 03:28:51 +00:00
|
|
|
const oldLocalAudioLevel = activeCallState.localAudioLevel;
|
|
|
|
const oldRemoteAudioLevels = existingCall.remoteAudioLevels;
|
2022-02-08 18:30:33 +00:00
|
|
|
if (
|
2022-05-19 03:28:51 +00:00
|
|
|
oldLocalAudioLevel === localAudioLevel &&
|
|
|
|
oldRemoteAudioLevels &&
|
|
|
|
mapUtil.isEqual(oldRemoteAudioLevels, remoteAudioLevels)
|
2022-02-08 18:30:33 +00:00
|
|
|
) {
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
...state,
|
2022-05-19 03:28:51 +00:00
|
|
|
activeCallState: { ...activeCallState, localAudioLevel },
|
2022-02-08 18:30:33 +00:00
|
|
|
callsByConversation: {
|
|
|
|
...callsByConversation,
|
2022-05-19 03:28:51 +00:00
|
|
|
[conversationId]: { ...existingCall, remoteAudioLevels },
|
2022-02-08 18:30:33 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-11-13 19:57:55 +00:00
|
|
|
if (action.type === GROUP_CALL_STATE_CHANGE) {
|
|
|
|
const {
|
|
|
|
connectionState,
|
2020-11-20 17:19:28 +00:00
|
|
|
conversationId,
|
2020-11-13 19:57:55 +00:00
|
|
|
hasLocalAudio,
|
|
|
|
hasLocalVideo,
|
2020-11-20 17:19:28 +00:00
|
|
|
joinState,
|
2023-08-10 16:43:33 +00:00
|
|
|
ourAci,
|
2020-11-20 17:19:28 +00:00
|
|
|
peekInfo,
|
2020-11-13 19:57:55 +00:00
|
|
|
remoteParticipants,
|
|
|
|
} = action.payload;
|
|
|
|
|
2021-08-20 16:06:15 +00:00
|
|
|
const existingCall = getGroupCall(conversationId, state);
|
|
|
|
const existingRingState = getGroupCallRingState(existingCall);
|
|
|
|
|
2020-12-02 18:14:03 +00:00
|
|
|
const newPeekInfo = peekInfo ||
|
2021-08-20 16:06:15 +00:00
|
|
|
existingCall?.peekInfo || {
|
2023-08-10 16:43:33 +00:00
|
|
|
acis: remoteParticipants.map(({ aci }) => aci),
|
2020-12-02 18:14:03 +00:00
|
|
|
maxDevices: Infinity,
|
|
|
|
deviceCount: remoteParticipants.length,
|
|
|
|
};
|
|
|
|
|
2020-11-20 17:19:28 +00:00
|
|
|
let newActiveCallState: ActiveCallStateType | undefined;
|
2022-02-08 19:18:51 +00:00
|
|
|
if (state.activeCallState?.conversationId === conversationId) {
|
2020-11-20 17:19:28 +00:00
|
|
|
newActiveCallState =
|
2022-02-08 19:18:51 +00:00
|
|
|
connectionState === GroupCallConnectionState.NotConnected
|
2020-11-20 17:19:28 +00:00
|
|
|
? undefined
|
2022-02-08 19:18:51 +00:00
|
|
|
: {
|
2020-11-20 17:19:28 +00:00
|
|
|
...state.activeCallState,
|
|
|
|
hasLocalAudio,
|
|
|
|
hasLocalVideo,
|
2022-02-08 19:18:51 +00:00
|
|
|
};
|
|
|
|
} else {
|
|
|
|
newActiveCallState = state.activeCallState;
|
2020-11-13 19:57:55 +00:00
|
|
|
}
|
|
|
|
|
2021-08-25 21:42:51 +00:00
|
|
|
if (
|
|
|
|
newActiveCallState &&
|
|
|
|
newActiveCallState.outgoingRing &&
|
|
|
|
newActiveCallState.conversationId === conversationId &&
|
2023-08-10 16:43:33 +00:00
|
|
|
isAnybodyElseInGroupCall(newPeekInfo, ourAci)
|
2021-08-25 21:42:51 +00:00
|
|
|
) {
|
|
|
|
newActiveCallState = {
|
|
|
|
...newActiveCallState,
|
|
|
|
outgoingRing: false,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-08-20 16:06:15 +00:00
|
|
|
let newRingState: GroupCallRingStateType;
|
|
|
|
if (joinState === GroupCallJoinState.NotJoined) {
|
|
|
|
newRingState = existingRingState;
|
|
|
|
} else {
|
|
|
|
newRingState = {};
|
|
|
|
}
|
|
|
|
|
2020-11-13 19:57:55 +00:00
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
callsByConversation: {
|
|
|
|
...callsByConversation,
|
|
|
|
[conversationId]: {
|
|
|
|
callMode: CallMode.Group,
|
|
|
|
conversationId,
|
|
|
|
connectionState,
|
|
|
|
joinState,
|
2020-12-02 18:14:03 +00:00
|
|
|
peekInfo: newPeekInfo,
|
2020-11-13 19:57:55 +00:00
|
|
|
remoteParticipants,
|
2021-08-20 16:06:15 +00:00
|
|
|
...newRingState,
|
2020-11-13 19:57:55 +00:00
|
|
|
},
|
|
|
|
},
|
2020-11-20 17:19:28 +00:00
|
|
|
activeCallState: newActiveCallState,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-02-08 19:18:51 +00:00
|
|
|
if (action.type === PEEK_GROUP_CALL_FULFILLED) {
|
|
|
|
const { conversationId, peekInfo } = action.payload;
|
2020-11-20 17:19:28 +00:00
|
|
|
|
2021-08-20 16:06:15 +00:00
|
|
|
const existingCall: GroupCallStateType = getGroupCall(
|
|
|
|
conversationId,
|
|
|
|
state
|
|
|
|
) || {
|
2020-11-20 17:19:28 +00:00
|
|
|
callMode: CallMode.Group,
|
|
|
|
conversationId,
|
|
|
|
connectionState: GroupCallConnectionState.NotConnected,
|
|
|
|
joinState: GroupCallJoinState.NotJoined,
|
|
|
|
peekInfo: {
|
2023-08-10 16:43:33 +00:00
|
|
|
acis: [],
|
2020-11-20 17:19:28 +00:00
|
|
|
maxDevices: Infinity,
|
|
|
|
deviceCount: 0,
|
|
|
|
},
|
|
|
|
remoteParticipants: [],
|
|
|
|
};
|
|
|
|
|
|
|
|
// This action should only update non-connected group calls. It's not necessarily a
|
|
|
|
// mistake if this action is dispatched "over" a connected call. Here's a valid
|
|
|
|
// sequence of events:
|
|
|
|
//
|
|
|
|
// 1. We ask RingRTC to peek, kicking off an asynchronous operation.
|
|
|
|
// 2. The associated group call is joined.
|
|
|
|
// 3. The peek promise from step 1 resolves.
|
|
|
|
if (
|
|
|
|
existingCall.connectionState !== GroupCallConnectionState.NotConnected
|
|
|
|
) {
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
callsByConversation: {
|
|
|
|
...callsByConversation,
|
|
|
|
[conversationId]: {
|
|
|
|
...existingCall,
|
|
|
|
peekInfo,
|
|
|
|
},
|
|
|
|
},
|
2020-11-13 19:57:55 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-05-20 21:54:03 +00:00
|
|
|
if (action.type === REMOTE_SHARING_SCREEN_CHANGE) {
|
|
|
|
const { conversationId, isSharingScreen } = action.payload;
|
|
|
|
const call = getOwn(state.callsByConversation, conversationId);
|
|
|
|
if (call?.callMode !== CallMode.Direct) {
|
2021-09-17 18:27:53 +00:00
|
|
|
log.warn('Cannot update remote video for a non-direct call');
|
2021-05-20 21:54:03 +00:00
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
callsByConversation: {
|
|
|
|
...callsByConversation,
|
|
|
|
[conversationId]: {
|
|
|
|
...call,
|
|
|
|
isSharingScreen,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-06-04 18:16:19 +00:00
|
|
|
if (action.type === REMOTE_VIDEO_CHANGE) {
|
2020-11-06 17:36:37 +00:00
|
|
|
const { conversationId, hasVideo } = action.payload;
|
|
|
|
const call = getOwn(state.callsByConversation, conversationId);
|
2020-11-13 19:57:55 +00:00
|
|
|
if (call?.callMode !== CallMode.Direct) {
|
2021-09-17 18:27:53 +00:00
|
|
|
log.warn('Cannot update remote video for a non-direct call');
|
2020-11-06 17:36:37 +00:00
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
2020-06-04 18:16:19 +00:00
|
|
|
return {
|
|
|
|
...state,
|
2020-11-06 17:36:37 +00:00
|
|
|
callsByConversation: {
|
|
|
|
...callsByConversation,
|
|
|
|
[conversationId]: {
|
|
|
|
...call,
|
|
|
|
hasRemoteVideo: hasVideo,
|
|
|
|
},
|
|
|
|
},
|
2020-06-04 18:16:19 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-12-07 20:43:19 +00:00
|
|
|
if (action.type === RETURN_TO_ACTIVE_CALL) {
|
|
|
|
const { activeCallState } = state;
|
|
|
|
if (!activeCallState) {
|
2021-09-17 18:27:53 +00:00
|
|
|
log.warn('Cannot return to active call if there is no active call');
|
2020-12-07 20:43:19 +00:00
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
activeCallState: {
|
|
|
|
...activeCallState,
|
|
|
|
pip: false,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-11-06 17:36:37 +00:00
|
|
|
if (action.type === SET_LOCAL_AUDIO_FULFILLED) {
|
|
|
|
if (!state.activeCallState) {
|
2021-09-17 18:27:53 +00:00
|
|
|
log.warn('Cannot set local audio with no active call');
|
2020-11-06 17:36:37 +00:00
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
2020-06-04 18:16:19 +00:00
|
|
|
return {
|
|
|
|
...state,
|
2020-11-06 17:36:37 +00:00
|
|
|
activeCallState: {
|
|
|
|
...state.activeCallState,
|
|
|
|
hasLocalAudio: action.payload.enabled,
|
|
|
|
},
|
2020-06-04 18:16:19 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
if (action.type === SET_LOCAL_VIDEO_FULFILLED) {
|
2020-11-06 17:36:37 +00:00
|
|
|
if (!state.activeCallState) {
|
2021-09-17 18:27:53 +00:00
|
|
|
log.warn('Cannot set local video with no active call');
|
2020-11-06 17:36:37 +00:00
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
2020-06-04 18:16:19 +00:00
|
|
|
return {
|
|
|
|
...state,
|
2020-11-06 17:36:37 +00:00
|
|
|
activeCallState: {
|
|
|
|
...state.activeCallState,
|
|
|
|
hasLocalVideo: action.payload.enabled,
|
|
|
|
},
|
2020-06-04 18:16:19 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-08-27 00:03:42 +00:00
|
|
|
if (action.type === CHANGE_IO_DEVICE_FULFILLED) {
|
|
|
|
const { selectedDevice } = action.payload;
|
|
|
|
const nextState = Object.create(null);
|
|
|
|
|
|
|
|
if (action.payload.type === CallingDeviceType.CAMERA) {
|
|
|
|
nextState.selectedCamera = selectedDevice;
|
|
|
|
} else if (action.payload.type === CallingDeviceType.MICROPHONE) {
|
|
|
|
nextState.selectedMicrophone = selectedDevice;
|
|
|
|
} else if (action.payload.type === CallingDeviceType.SPEAKER) {
|
|
|
|
nextState.selectedSpeaker = selectedDevice;
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
...nextState,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
if (action.type === REFRESH_IO_DEVICES) {
|
|
|
|
const {
|
|
|
|
availableMicrophones,
|
|
|
|
selectedMicrophone,
|
|
|
|
availableSpeakers,
|
|
|
|
selectedSpeaker,
|
|
|
|
availableCameras,
|
|
|
|
selectedCamera,
|
|
|
|
} = action.payload;
|
|
|
|
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
availableMicrophones,
|
|
|
|
selectedMicrophone,
|
|
|
|
availableSpeakers,
|
|
|
|
selectedSpeaker,
|
|
|
|
availableCameras,
|
|
|
|
selectedCamera,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
if (action.type === TOGGLE_SETTINGS) {
|
2020-11-06 17:36:37 +00:00
|
|
|
const { activeCallState } = state;
|
|
|
|
if (!activeCallState) {
|
2021-09-17 18:27:53 +00:00
|
|
|
log.warn('Cannot toggle settings when there is no active call');
|
2020-11-06 17:36:37 +00:00
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
2020-08-27 00:03:42 +00:00
|
|
|
return {
|
|
|
|
...state,
|
2020-11-06 17:36:37 +00:00
|
|
|
activeCallState: {
|
|
|
|
...activeCallState,
|
|
|
|
settingsDialogOpen: !activeCallState.settingsDialogOpen,
|
|
|
|
},
|
2020-08-27 00:03:42 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-10-08 01:25:33 +00:00
|
|
|
if (action.type === TOGGLE_PARTICIPANTS) {
|
2020-11-06 17:36:37 +00:00
|
|
|
const { activeCallState } = state;
|
|
|
|
if (!activeCallState) {
|
2021-09-17 18:27:53 +00:00
|
|
|
log.warn('Cannot toggle participants list when there is no active call');
|
2020-11-06 17:36:37 +00:00
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
2020-10-08 01:25:33 +00:00
|
|
|
return {
|
|
|
|
...state,
|
2020-11-06 17:36:37 +00:00
|
|
|
activeCallState: {
|
|
|
|
...activeCallState,
|
2020-11-17 15:07:53 +00:00
|
|
|
showParticipantsList: !activeCallState.showParticipantsList,
|
2020-11-06 17:36:37 +00:00
|
|
|
},
|
2020-10-08 01:25:33 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-10-01 00:43:05 +00:00
|
|
|
if (action.type === TOGGLE_PIP) {
|
2020-11-06 17:36:37 +00:00
|
|
|
const { activeCallState } = state;
|
|
|
|
if (!activeCallState) {
|
2021-09-17 18:27:53 +00:00
|
|
|
log.warn('Cannot toggle PiP when there is no active call');
|
2020-11-06 17:36:37 +00:00
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
2020-10-01 00:43:05 +00:00
|
|
|
return {
|
|
|
|
...state,
|
2020-11-06 17:36:37 +00:00
|
|
|
activeCallState: {
|
|
|
|
...activeCallState,
|
|
|
|
pip: !activeCallState.pip,
|
|
|
|
},
|
2020-10-01 00:43:05 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-05-20 21:54:03 +00:00
|
|
|
if (action.type === SET_PRESENTING) {
|
|
|
|
const { activeCallState } = state;
|
|
|
|
if (!activeCallState) {
|
2021-09-17 18:27:53 +00:00
|
|
|
log.warn('Cannot toggle presenting when there is no active call');
|
2021-05-20 21:54:03 +00:00
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
activeCallState: {
|
|
|
|
...activeCallState,
|
|
|
|
presentingSource: action.payload,
|
|
|
|
presentingSourcesAvailable: undefined,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
if (action.type === SET_PRESENTING_SOURCES) {
|
|
|
|
const { activeCallState } = state;
|
|
|
|
if (!activeCallState) {
|
2021-09-17 18:27:53 +00:00
|
|
|
log.warn('Cannot set presenting sources when there is no active call');
|
2021-05-20 21:54:03 +00:00
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
activeCallState: {
|
|
|
|
...activeCallState,
|
|
|
|
presentingSourcesAvailable: action.payload,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-08-25 21:42:51 +00:00
|
|
|
if (action.type === SET_OUTGOING_RING) {
|
|
|
|
const { activeCallState } = state;
|
|
|
|
if (!activeCallState) {
|
2021-09-17 18:27:53 +00:00
|
|
|
log.warn('Cannot set outgoing ring when there is no active call');
|
2021-08-25 21:42:51 +00:00
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
activeCallState: {
|
|
|
|
...activeCallState,
|
|
|
|
outgoingRing: action.payload,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-05-20 21:54:03 +00:00
|
|
|
if (action.type === TOGGLE_NEEDS_SCREEN_RECORDING_PERMISSIONS) {
|
|
|
|
const { activeCallState } = state;
|
|
|
|
if (!activeCallState) {
|
2021-09-17 18:27:53 +00:00
|
|
|
log.warn('Cannot set presenting sources when there is no active call');
|
2021-05-20 21:54:03 +00:00
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
activeCallState: {
|
|
|
|
...activeCallState,
|
2021-11-11 22:43:05 +00:00
|
|
|
showNeedsScreenRecordingPermissionsWarning:
|
|
|
|
!activeCallState.showNeedsScreenRecordingPermissionsWarning,
|
2021-05-20 21:54:03 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-11-13 14:56:48 +00:00
|
|
|
if (action.type === CHANGE_CALL_VIEW) {
|
2021-01-08 22:57:54 +00:00
|
|
|
const { activeCallState } = state;
|
|
|
|
if (!activeCallState) {
|
2023-11-13 14:56:48 +00:00
|
|
|
log.warn('Cannot change call view when there is no active call');
|
2021-01-08 22:57:54 +00:00
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
2023-11-13 14:56:48 +00:00
|
|
|
if (activeCallState.viewMode === action.viewMode) {
|
|
|
|
return state;
|
2022-05-25 18:03:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
activeCallState: {
|
|
|
|
...activeCallState,
|
2023-11-13 14:56:48 +00:00
|
|
|
viewMode: action.viewMode,
|
|
|
|
viewModeBeforePresentation:
|
|
|
|
action.viewMode === CallViewMode.Presentation
|
|
|
|
? activeCallState.viewMode
|
|
|
|
: undefined,
|
2022-05-25 18:03:27 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
if (action.type === SWITCH_TO_PRESENTATION_VIEW) {
|
|
|
|
const { activeCallState } = state;
|
|
|
|
if (!activeCallState) {
|
|
|
|
log.warn('Cannot switch to speaker view when there is no active call');
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
2023-11-13 14:56:48 +00:00
|
|
|
if (activeCallState.viewMode === CallViewMode.Presentation) {
|
2022-05-25 18:03:27 +00:00
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
activeCallState: {
|
|
|
|
...activeCallState,
|
|
|
|
viewMode: CallViewMode.Presentation,
|
2023-11-13 14:56:48 +00:00
|
|
|
viewModeBeforePresentation: activeCallState.viewMode,
|
2022-05-25 18:03:27 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
if (action.type === SWITCH_FROM_PRESENTATION_VIEW) {
|
|
|
|
const { activeCallState } = state;
|
|
|
|
if (!activeCallState) {
|
|
|
|
log.warn('Cannot switch to speaker view when there is no active call');
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (activeCallState.viewMode !== CallViewMode.Presentation) {
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
2021-01-08 22:57:54 +00:00
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
activeCallState: {
|
|
|
|
...activeCallState,
|
2023-11-13 14:56:48 +00:00
|
|
|
viewMode:
|
|
|
|
activeCallState.viewModeBeforePresentation ?? CallViewMode.Paginated,
|
2021-01-08 22:57:54 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-12-08 19:37:04 +00:00
|
|
|
if (action.type === MARK_CALL_UNTRUSTED) {
|
|
|
|
const { activeCallState } = state;
|
|
|
|
if (!activeCallState) {
|
2021-09-17 18:27:53 +00:00
|
|
|
log.warn('Cannot mark call as untrusted when there is no active call');
|
2020-12-08 19:37:04 +00:00
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
2023-08-10 16:43:33 +00:00
|
|
|
const { safetyNumberChangedAcis } = action.payload;
|
2020-12-08 19:37:04 +00:00
|
|
|
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
activeCallState: {
|
|
|
|
...activeCallState,
|
|
|
|
pip: false,
|
2023-08-10 16:43:33 +00:00
|
|
|
safetyNumberChangedAcis,
|
2020-12-08 19:37:04 +00:00
|
|
|
settingsDialogOpen: false,
|
|
|
|
showParticipantsList: false,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
if (action.type === MARK_CALL_TRUSTED) {
|
|
|
|
const { activeCallState } = state;
|
|
|
|
if (!activeCallState) {
|
2021-09-17 18:27:53 +00:00
|
|
|
log.warn('Cannot mark call as trusted when there is no active call');
|
2020-12-08 19:37:04 +00:00
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
activeCallState: {
|
|
|
|
...activeCallState,
|
2023-08-10 16:43:33 +00:00
|
|
|
safetyNumberChangedAcis: [],
|
2020-12-08 19:37:04 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-06-04 18:16:19 +00:00
|
|
|
return state;
|
|
|
|
}
|