2021-08-17 21:45:18 +00:00
|
|
|
// Copyright 2020-2021 Signal Messenger, LLC
|
2020-10-30 20:34:04 +00:00
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2021-08-17 21:45:18 +00:00
|
|
|
import React from 'react';
|
|
|
|
import classNames from 'classnames';
|
2020-10-08 01:25:33 +00:00
|
|
|
import {
|
|
|
|
SetLocalAudioType,
|
|
|
|
SetLocalPreviewType,
|
|
|
|
SetLocalVideoType,
|
|
|
|
} from '../state/ducks/calling';
|
2020-11-19 18:11:35 +00:00
|
|
|
import { CallingButton, CallingButtonType } from './CallingButton';
|
|
|
|
import { TooltipPlacement } from './Tooltip';
|
2020-10-08 01:25:33 +00:00
|
|
|
import { CallBackgroundBlur } from './CallBackgroundBlur';
|
2020-11-17 15:07:53 +00:00
|
|
|
import { CallingHeader } from './CallingHeader';
|
2021-08-25 21:42:51 +00:00
|
|
|
import { CallingPreCallInfo, RingMode } from './CallingPreCallInfo';
|
2021-08-17 21:45:18 +00:00
|
|
|
import {
|
|
|
|
CallingLobbyJoinButton,
|
|
|
|
CallingLobbyJoinButtonVariant,
|
|
|
|
} from './CallingLobbyJoinButton';
|
2021-05-28 16:15:17 +00:00
|
|
|
import { AvatarColorType } from '../types/Colors';
|
2020-11-17 15:07:53 +00:00
|
|
|
import { LocalizerType } from '../types/Util';
|
2021-10-19 13:53:11 +00:00
|
|
|
import { useIsOnline } from '../hooks/useIsOnline';
|
2021-09-29 21:20:52 +00:00
|
|
|
import * as KeyboardLayout from '../services/keyboardLayout';
|
2020-12-08 19:37:04 +00:00
|
|
|
import { ConversationType } from '../state/ducks/conversations';
|
2021-09-02 22:34:38 +00:00
|
|
|
import { isConversationTooBigToRing } from '../conversations/isConversationTooBigToRing';
|
2020-10-08 01:25:33 +00:00
|
|
|
|
|
|
|
export type PropsType = {
|
2020-10-14 16:30:50 +00:00
|
|
|
availableCameras: Array<MediaDeviceInfo>;
|
2021-08-17 21:45:18 +00:00
|
|
|
conversation: Pick<
|
|
|
|
ConversationType,
|
|
|
|
| 'acceptedMessageRequest'
|
|
|
|
| 'avatarPath'
|
|
|
|
| 'color'
|
|
|
|
| 'isMe'
|
2021-09-02 22:34:38 +00:00
|
|
|
| 'memberships'
|
2021-08-17 21:45:18 +00:00
|
|
|
| 'name'
|
|
|
|
| 'phoneNumber'
|
|
|
|
| 'profileName'
|
|
|
|
| 'sharedGroupNames'
|
|
|
|
| 'title'
|
|
|
|
| 'type'
|
|
|
|
| 'unblurredAvatarPath'
|
|
|
|
>;
|
2021-08-25 21:42:51 +00:00
|
|
|
groupMembers?: Array<Pick<ConversationType, 'id' | 'firstName' | 'title'>>;
|
2020-10-08 01:25:33 +00:00
|
|
|
hasLocalAudio: boolean;
|
|
|
|
hasLocalVideo: boolean;
|
|
|
|
i18n: LocalizerType;
|
|
|
|
isGroupCall: boolean;
|
2021-08-25 21:42:51 +00:00
|
|
|
isGroupCallOutboundRingEnabled: boolean;
|
2020-11-20 20:14:07 +00:00
|
|
|
isCallFull?: boolean;
|
2020-11-09 18:56:20 +00:00
|
|
|
me: {
|
|
|
|
avatarPath?: string;
|
2021-08-25 21:42:51 +00:00
|
|
|
id: string;
|
2021-05-28 16:15:17 +00:00
|
|
|
color?: AvatarColorType;
|
2020-12-08 19:37:04 +00:00
|
|
|
uuid: string;
|
2020-11-09 18:56:20 +00:00
|
|
|
};
|
2020-10-08 01:25:33 +00:00
|
|
|
onCallCanceled: () => void;
|
|
|
|
onJoinCall: () => void;
|
2021-08-25 21:42:51 +00:00
|
|
|
outgoingRing: boolean;
|
2020-12-08 19:37:04 +00:00
|
|
|
peekedParticipants: Array<ConversationType>;
|
2020-10-08 01:25:33 +00:00
|
|
|
setLocalAudio: (_: SetLocalAudioType) => void;
|
|
|
|
setLocalVideo: (_: SetLocalVideoType) => void;
|
|
|
|
setLocalPreview: (_: SetLocalPreviewType) => void;
|
2021-08-25 21:42:51 +00:00
|
|
|
setOutgoingRing: (_: boolean) => void;
|
2020-11-20 19:39:50 +00:00
|
|
|
showParticipantsList: boolean;
|
2020-10-08 01:25:33 +00:00
|
|
|
toggleParticipants: () => void;
|
|
|
|
toggleSettings: () => void;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const CallingLobby = ({
|
2020-10-14 16:30:50 +00:00
|
|
|
availableCameras,
|
2020-11-06 17:36:37 +00:00
|
|
|
conversation,
|
2021-08-17 21:45:18 +00:00
|
|
|
groupMembers,
|
2020-10-08 01:25:33 +00:00
|
|
|
hasLocalAudio,
|
|
|
|
hasLocalVideo,
|
|
|
|
i18n,
|
|
|
|
isGroupCall = false,
|
2021-08-25 21:42:51 +00:00
|
|
|
isGroupCallOutboundRingEnabled,
|
2020-11-20 20:14:07 +00:00
|
|
|
isCallFull = false,
|
2020-11-09 18:56:20 +00:00
|
|
|
me,
|
2020-10-08 01:25:33 +00:00
|
|
|
onCallCanceled,
|
|
|
|
onJoinCall,
|
2020-12-02 18:14:03 +00:00
|
|
|
peekedParticipants,
|
2020-10-08 01:25:33 +00:00
|
|
|
setLocalAudio,
|
|
|
|
setLocalPreview,
|
|
|
|
setLocalVideo,
|
2021-08-25 21:42:51 +00:00
|
|
|
setOutgoingRing,
|
2020-11-20 19:39:50 +00:00
|
|
|
showParticipantsList,
|
2020-10-08 01:25:33 +00:00
|
|
|
toggleParticipants,
|
|
|
|
toggleSettings,
|
2021-08-25 21:42:51 +00:00
|
|
|
outgoingRing,
|
2020-10-08 01:25:33 +00:00
|
|
|
}: PropsType): JSX.Element => {
|
2020-12-12 00:44:07 +00:00
|
|
|
const localVideoRef = React.useRef<null | HTMLVideoElement>(null);
|
2020-10-08 01:25:33 +00:00
|
|
|
|
2021-08-17 21:45:18 +00:00
|
|
|
const shouldShowLocalVideo = hasLocalVideo && availableCameras.length > 0;
|
|
|
|
|
2020-10-08 01:25:33 +00:00
|
|
|
const toggleAudio = React.useCallback((): void => {
|
|
|
|
setLocalAudio({ enabled: !hasLocalAudio });
|
2020-11-06 17:36:37 +00:00
|
|
|
}, [hasLocalAudio, setLocalAudio]);
|
2020-10-08 01:25:33 +00:00
|
|
|
|
|
|
|
const toggleVideo = React.useCallback((): void => {
|
|
|
|
setLocalVideo({ enabled: !hasLocalVideo });
|
2020-11-06 17:36:37 +00:00
|
|
|
}, [hasLocalVideo, setLocalVideo]);
|
2020-10-08 01:25:33 +00:00
|
|
|
|
2021-08-25 21:42:51 +00:00
|
|
|
const toggleOutgoingRing = React.useCallback((): void => {
|
|
|
|
setOutgoingRing(!outgoingRing);
|
|
|
|
}, [outgoingRing, setOutgoingRing]);
|
|
|
|
|
2020-10-08 01:25:33 +00:00
|
|
|
React.useEffect(() => {
|
|
|
|
setLocalPreview({ element: localVideoRef });
|
|
|
|
|
|
|
|
return () => {
|
|
|
|
setLocalPreview({ element: undefined });
|
|
|
|
};
|
|
|
|
}, [setLocalPreview]);
|
|
|
|
|
|
|
|
React.useEffect(() => {
|
|
|
|
function handleKeyDown(event: KeyboardEvent): void {
|
|
|
|
let eventHandled = false;
|
|
|
|
|
2021-09-29 21:20:52 +00:00
|
|
|
const key = KeyboardLayout.lookup(event);
|
|
|
|
if (event.shiftKey && (key === 'V' || key === 'v')) {
|
2020-10-08 01:25:33 +00:00
|
|
|
toggleVideo();
|
|
|
|
eventHandled = true;
|
2021-09-29 21:20:52 +00:00
|
|
|
} else if (event.shiftKey && (key === 'M' || key === 'm')) {
|
2020-10-08 01:25:33 +00:00
|
|
|
toggleAudio();
|
|
|
|
eventHandled = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (eventHandled) {
|
|
|
|
event.preventDefault();
|
|
|
|
event.stopPropagation();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
document.addEventListener('keydown', handleKeyDown);
|
|
|
|
|
|
|
|
return () => {
|
|
|
|
document.removeEventListener('keydown', handleKeyDown);
|
|
|
|
};
|
|
|
|
}, [toggleVideo, toggleAudio]);
|
|
|
|
|
2021-10-19 13:53:11 +00:00
|
|
|
const isOnline = useIsOnline();
|
|
|
|
|
2020-11-17 15:07:53 +00:00
|
|
|
const [isCallConnecting, setIsCallConnecting] = React.useState(false);
|
|
|
|
|
2020-10-14 16:30:50 +00:00
|
|
|
// eslint-disable-next-line no-nested-ternary
|
2020-10-08 01:25:33 +00:00
|
|
|
const videoButtonType = hasLocalVideo
|
|
|
|
? CallingButtonType.VIDEO_ON
|
2020-10-14 16:30:50 +00:00
|
|
|
: availableCameras.length === 0
|
|
|
|
? CallingButtonType.VIDEO_DISABLED
|
2020-10-08 01:25:33 +00:00
|
|
|
: CallingButtonType.VIDEO_OFF;
|
2021-08-25 21:42:51 +00:00
|
|
|
|
2020-10-08 01:25:33 +00:00
|
|
|
const audioButtonType = hasLocalAudio
|
|
|
|
? CallingButtonType.AUDIO_ON
|
|
|
|
: CallingButtonType.AUDIO_OFF;
|
|
|
|
|
2021-09-02 22:34:38 +00:00
|
|
|
const isGroupTooLargeToRing = isConversationTooBigToRing(conversation);
|
|
|
|
|
2021-08-25 21:42:51 +00:00
|
|
|
const isRingButtonVisible: boolean =
|
|
|
|
isGroupCall &&
|
|
|
|
isGroupCallOutboundRingEnabled &&
|
|
|
|
peekedParticipants.length === 0 &&
|
|
|
|
(groupMembers || []).length > 1;
|
|
|
|
|
2021-09-02 22:34:38 +00:00
|
|
|
let preCallInfoRingMode: RingMode;
|
|
|
|
if (isGroupCall) {
|
|
|
|
preCallInfoRingMode =
|
|
|
|
outgoingRing && !isGroupTooLargeToRing
|
|
|
|
? RingMode.WillRing
|
|
|
|
: RingMode.WillNotRing;
|
|
|
|
} else {
|
|
|
|
preCallInfoRingMode = RingMode.WillRing;
|
|
|
|
}
|
2021-08-25 21:42:51 +00:00
|
|
|
|
|
|
|
let ringButtonType:
|
|
|
|
| CallingButtonType.RING_DISABLED
|
|
|
|
| CallingButtonType.RING_ON
|
|
|
|
| CallingButtonType.RING_OFF;
|
|
|
|
if (isRingButtonVisible) {
|
2021-09-02 22:34:38 +00:00
|
|
|
if (isGroupTooLargeToRing) {
|
2021-08-25 21:42:51 +00:00
|
|
|
ringButtonType = CallingButtonType.RING_DISABLED;
|
|
|
|
} else if (outgoingRing) {
|
|
|
|
ringButtonType = CallingButtonType.RING_ON;
|
|
|
|
} else {
|
|
|
|
ringButtonType = CallingButtonType.RING_OFF;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
ringButtonType = CallingButtonType.RING_DISABLED;
|
|
|
|
}
|
|
|
|
|
2021-10-19 13:53:11 +00:00
|
|
|
const canJoin = !isCallFull && !isCallConnecting && isOnline;
|
2020-12-08 22:28:44 +00:00
|
|
|
|
2021-08-17 21:45:18 +00:00
|
|
|
let callingLobbyJoinButtonVariant: CallingLobbyJoinButtonVariant;
|
2020-11-20 20:14:07 +00:00
|
|
|
if (isCallFull) {
|
2021-08-17 21:45:18 +00:00
|
|
|
callingLobbyJoinButtonVariant = CallingLobbyJoinButtonVariant.CallIsFull;
|
2020-11-20 20:14:07 +00:00
|
|
|
} else if (isCallConnecting) {
|
2021-08-17 21:45:18 +00:00
|
|
|
callingLobbyJoinButtonVariant = CallingLobbyJoinButtonVariant.Loading;
|
2020-12-08 22:28:44 +00:00
|
|
|
} else if (peekedParticipants.length) {
|
2021-08-17 21:45:18 +00:00
|
|
|
callingLobbyJoinButtonVariant = CallingLobbyJoinButtonVariant.Join;
|
2020-11-20 20:14:07 +00:00
|
|
|
} else {
|
2021-08-17 21:45:18 +00:00
|
|
|
callingLobbyJoinButtonVariant = CallingLobbyJoinButtonVariant.Start;
|
2020-12-12 00:44:07 +00:00
|
|
|
}
|
|
|
|
|
2020-10-08 01:25:33 +00:00
|
|
|
return (
|
|
|
|
<div className="module-calling__container">
|
2021-08-17 21:45:18 +00:00
|
|
|
{shouldShowLocalVideo ? (
|
|
|
|
<video
|
2021-08-18 21:06:26 +00:00
|
|
|
className="module-CallingLobby__local-preview module-CallingLobby__local-preview--camera-is-on"
|
2021-08-17 21:45:18 +00:00
|
|
|
ref={localVideoRef}
|
|
|
|
autoPlay
|
|
|
|
/>
|
|
|
|
) : (
|
|
|
|
<CallBackgroundBlur
|
2021-08-18 21:06:26 +00:00
|
|
|
className="module-CallingLobby__local-preview module-CallingLobby__local-preview--camera-is-off"
|
2021-08-17 21:45:18 +00:00
|
|
|
avatarPath={me.avatarPath}
|
|
|
|
color={me.color}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
|
2020-11-17 15:07:53 +00:00
|
|
|
<CallingHeader
|
|
|
|
i18n={i18n}
|
|
|
|
isGroupCall={isGroupCall}
|
2020-12-02 18:14:03 +00:00
|
|
|
participantCount={peekedParticipants.length}
|
2020-11-20 19:39:50 +00:00
|
|
|
showParticipantsList={showParticipantsList}
|
2020-11-17 15:07:53 +00:00
|
|
|
toggleParticipants={toggleParticipants}
|
|
|
|
toggleSettings={toggleSettings}
|
2021-08-17 21:45:18 +00:00
|
|
|
onCancel={onCallCanceled}
|
2020-11-17 15:07:53 +00:00
|
|
|
/>
|
|
|
|
|
2021-08-17 21:45:18 +00:00
|
|
|
<CallingPreCallInfo
|
|
|
|
conversation={conversation}
|
|
|
|
groupMembers={groupMembers}
|
|
|
|
i18n={i18n}
|
|
|
|
isCallFull={isCallFull}
|
|
|
|
me={me}
|
|
|
|
peekedParticipants={peekedParticipants}
|
2021-08-25 21:42:51 +00:00
|
|
|
ringMode={preCallInfoRingMode}
|
2021-08-17 21:45:18 +00:00
|
|
|
/>
|
2020-10-08 01:25:33 +00:00
|
|
|
|
2021-08-17 21:45:18 +00:00
|
|
|
<div
|
|
|
|
className={classNames(
|
|
|
|
'module-CallingLobby__camera-is-off',
|
|
|
|
`module-CallingLobby__camera-is-off--${
|
|
|
|
shouldShowLocalVideo ? 'invisible' : 'visible'
|
|
|
|
}`
|
2020-12-12 00:44:07 +00:00
|
|
|
)}
|
2021-08-17 21:45:18 +00:00
|
|
|
>
|
|
|
|
{i18n('calling__your-video-is-off')}
|
|
|
|
</div>
|
2020-11-17 15:07:53 +00:00
|
|
|
|
2021-08-17 21:45:18 +00:00
|
|
|
<div className="module-calling__buttons module-calling__buttons--inline">
|
|
|
|
<CallingButton
|
|
|
|
buttonType={videoButtonType}
|
|
|
|
i18n={i18n}
|
|
|
|
onClick={toggleVideo}
|
|
|
|
tooltipDirection={TooltipPlacement.Top}
|
|
|
|
/>
|
|
|
|
<CallingButton
|
|
|
|
buttonType={audioButtonType}
|
|
|
|
i18n={i18n}
|
|
|
|
onClick={toggleAudio}
|
|
|
|
tooltipDirection={TooltipPlacement.Top}
|
|
|
|
/>
|
2021-08-25 21:42:51 +00:00
|
|
|
<CallingButton
|
|
|
|
buttonType={ringButtonType}
|
|
|
|
i18n={i18n}
|
|
|
|
isVisible={isRingButtonVisible}
|
|
|
|
onClick={toggleOutgoingRing}
|
|
|
|
tooltipDirection={TooltipPlacement.Top}
|
|
|
|
/>
|
2020-10-08 01:25:33 +00:00
|
|
|
</div>
|
2021-08-17 21:45:18 +00:00
|
|
|
|
|
|
|
<CallingLobbyJoinButton
|
|
|
|
disabled={!canJoin}
|
|
|
|
i18n={i18n}
|
|
|
|
onClick={() => {
|
|
|
|
setIsCallConnecting(true);
|
|
|
|
onJoinCall();
|
|
|
|
}}
|
|
|
|
variant={callingLobbyJoinButtonVariant}
|
|
|
|
/>
|
2020-10-08 01:25:33 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|