2023-01-03 19:55:46 +00:00
|
|
|
// Copyright 2020 Signal Messenger, LLC
|
2020-11-17 15:07:53 +00:00
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2020-12-02 01:52:01 +00:00
|
|
|
import React, { useMemo, useEffect } from 'react';
|
2022-05-23 17:16:13 +00:00
|
|
|
import { clamp, maxBy } from 'lodash';
|
2023-01-09 18:38:57 +00:00
|
|
|
import type { VideoFrameSource } from '@signalapp/ringrtc';
|
2022-12-09 20:37:45 +00:00
|
|
|
import { Avatar, AvatarSize } from './Avatar';
|
2020-11-17 15:07:53 +00:00
|
|
|
import { CallBackgroundBlur } from './CallBackgroundBlur';
|
|
|
|
import { DirectCallRemoteParticipant } from './DirectCallRemoteParticipant';
|
|
|
|
import { GroupCallRemoteParticipant } from './GroupCallRemoteParticipant';
|
2021-10-26 19:15:33 +00:00
|
|
|
import type { LocalizerType } from '../types/Util';
|
|
|
|
import type {
|
2020-12-02 18:14:03 +00:00
|
|
|
ActiveCallType,
|
2020-12-01 23:52:09 +00:00
|
|
|
GroupCallRemoteParticipantType,
|
2020-12-02 01:52:01 +00:00
|
|
|
GroupCallVideoRequest,
|
2020-12-01 23:52:09 +00:00
|
|
|
} from '../types/Calling';
|
2021-10-26 19:15:33 +00:00
|
|
|
import { CallMode } from '../types/Calling';
|
2021-08-06 00:17:05 +00:00
|
|
|
import { AvatarColors } from '../types/Colors';
|
2021-10-26 19:15:33 +00:00
|
|
|
import type { SetRendererCanvasType } from '../state/ducks/calling';
|
2021-01-08 17:32:49 +00:00
|
|
|
import { useGetCallingFrameBuffer } from '../calling/useGetCallingFrameBuffer';
|
2022-05-23 17:16:13 +00:00
|
|
|
import { MAX_FRAME_WIDTH } from '../calling/constants';
|
2021-09-17 22:24:21 +00:00
|
|
|
import { usePageVisibility } from '../hooks/usePageVisibility';
|
2021-03-03 17:23:00 +00:00
|
|
|
import { missingCaseError } from '../util/missingCaseError';
|
2020-12-02 01:52:01 +00:00
|
|
|
import { nonRenderedRemoteParticipant } from '../util/ringrtc/nonRenderedRemoteParticipant';
|
2023-10-16 17:58:51 +00:00
|
|
|
import { isReconnecting } from '../util/callingIsReconnecting';
|
2020-12-02 01:52:01 +00:00
|
|
|
|
2022-05-23 17:16:13 +00:00
|
|
|
// This value should be kept in sync with the hard-coded CSS height. It should also be
|
|
|
|
// less than `MAX_FRAME_HEIGHT`.
|
2020-12-02 01:52:01 +00:00
|
|
|
const PIP_VIDEO_HEIGHT_PX = 120;
|
2020-11-17 15:07:53 +00:00
|
|
|
|
2022-11-18 00:45:19 +00:00
|
|
|
function NoVideo({
|
2020-11-19 23:31:04 +00:00
|
|
|
activeCall,
|
|
|
|
i18n,
|
|
|
|
}: {
|
|
|
|
activeCall: ActiveCallType;
|
|
|
|
i18n: LocalizerType;
|
2022-11-18 00:45:19 +00:00
|
|
|
}): JSX.Element {
|
2020-11-19 23:31:04 +00:00
|
|
|
const {
|
2021-05-07 22:21:10 +00:00
|
|
|
acceptedMessageRequest,
|
2020-11-19 23:31:04 +00:00
|
|
|
avatarPath,
|
|
|
|
color,
|
2021-05-07 22:21:10 +00:00
|
|
|
isMe,
|
2020-11-19 23:31:04 +00:00
|
|
|
phoneNumber,
|
|
|
|
profileName,
|
2021-05-07 22:21:10 +00:00
|
|
|
sharedGroupNames,
|
2020-11-19 23:31:04 +00:00
|
|
|
title,
|
|
|
|
} = activeCall.conversation;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="module-calling-pip__video--remote">
|
|
|
|
<CallBackgroundBlur avatarPath={avatarPath} color={color}>
|
|
|
|
<div className="module-calling-pip__video--avatar">
|
|
|
|
<Avatar
|
2021-05-07 22:21:10 +00:00
|
|
|
acceptedMessageRequest={acceptedMessageRequest}
|
2020-11-19 23:31:04 +00:00
|
|
|
avatarPath={avatarPath}
|
2021-12-01 17:24:00 +00:00
|
|
|
badge={undefined}
|
2021-08-06 00:17:05 +00:00
|
|
|
color={color || AvatarColors[0]}
|
2020-11-19 23:31:04 +00:00
|
|
|
noteToSelf={false}
|
|
|
|
conversationType="direct"
|
|
|
|
i18n={i18n}
|
2021-05-07 22:21:10 +00:00
|
|
|
isMe={isMe}
|
2020-11-19 23:31:04 +00:00
|
|
|
phoneNumber={phoneNumber}
|
|
|
|
profileName={profileName}
|
|
|
|
title={title}
|
2022-12-09 20:37:45 +00:00
|
|
|
size={AvatarSize.FORTY_EIGHT}
|
2021-05-07 22:21:10 +00:00
|
|
|
sharedGroupNames={sharedGroupNames}
|
2020-11-19 23:31:04 +00:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</CallBackgroundBlur>
|
|
|
|
</div>
|
|
|
|
);
|
2022-11-18 00:45:19 +00:00
|
|
|
}
|
2020-11-19 23:31:04 +00:00
|
|
|
|
2021-01-14 18:07:05 +00:00
|
|
|
export type PropsType = {
|
2020-11-19 18:13:36 +00:00
|
|
|
activeCall: ActiveCallType;
|
2020-11-17 15:07:53 +00:00
|
|
|
getGroupCallVideoFrameSource: (demuxId: number) => VideoFrameSource;
|
|
|
|
i18n: LocalizerType;
|
2022-09-07 15:52:55 +00:00
|
|
|
setGroupCallVideoRequest: (
|
|
|
|
_: Array<GroupCallVideoRequest>,
|
|
|
|
speakerHeight: number
|
|
|
|
) => void;
|
2020-11-17 15:07:53 +00:00
|
|
|
setRendererCanvas: (_: SetRendererCanvasType) => void;
|
2021-01-14 18:07:05 +00:00
|
|
|
};
|
2020-11-17 15:07:53 +00:00
|
|
|
|
2022-11-18 00:45:19 +00:00
|
|
|
export function CallingPipRemoteVideo({
|
2020-11-19 18:13:36 +00:00
|
|
|
activeCall,
|
2020-11-17 15:07:53 +00:00
|
|
|
getGroupCallVideoFrameSource,
|
|
|
|
i18n,
|
2020-12-02 01:52:01 +00:00
|
|
|
setGroupCallVideoRequest,
|
2020-11-17 15:07:53 +00:00
|
|
|
setRendererCanvas,
|
2022-11-18 00:45:19 +00:00
|
|
|
}: PropsType): JSX.Element {
|
2020-12-02 18:14:03 +00:00
|
|
|
const { conversation } = activeCall;
|
2020-12-01 23:52:09 +00:00
|
|
|
|
2021-01-08 17:32:49 +00:00
|
|
|
const getGroupCallFrameBuffer = useGetCallingFrameBuffer();
|
|
|
|
|
2020-12-02 01:52:01 +00:00
|
|
|
const isPageVisible = usePageVisibility();
|
|
|
|
|
2021-11-11 22:43:05 +00:00
|
|
|
const activeGroupCallSpeaker: undefined | GroupCallRemoteParticipantType =
|
|
|
|
useMemo(() => {
|
|
|
|
if (activeCall.callMode !== CallMode.Group) {
|
|
|
|
return undefined;
|
|
|
|
}
|
2020-12-01 23:52:09 +00:00
|
|
|
|
2021-11-11 22:43:05 +00:00
|
|
|
return maxBy(activeCall.remoteParticipants, participant =>
|
|
|
|
participant.presenting ? Infinity : participant.speakerTime || -Infinity
|
|
|
|
);
|
|
|
|
}, [activeCall.callMode, activeCall.remoteParticipants]);
|
2020-11-19 18:13:36 +00:00
|
|
|
|
2020-12-02 01:52:01 +00:00
|
|
|
useEffect(() => {
|
2020-12-02 18:14:03 +00:00
|
|
|
if (activeCall.callMode !== CallMode.Group) {
|
2020-12-02 01:52:01 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isPageVisible) {
|
|
|
|
setGroupCallVideoRequest(
|
2020-12-02 18:14:03 +00:00
|
|
|
activeCall.remoteParticipants.map(participant => {
|
2022-05-23 17:16:13 +00:00
|
|
|
if (participant === activeGroupCallSpeaker) {
|
2020-12-02 01:52:01 +00:00
|
|
|
return {
|
|
|
|
demuxId: participant.demuxId,
|
2022-05-23 17:16:13 +00:00
|
|
|
width: clamp(
|
|
|
|
Math.floor(PIP_VIDEO_HEIGHT_PX * participant.videoAspectRatio),
|
|
|
|
1,
|
|
|
|
MAX_FRAME_WIDTH
|
2020-12-02 01:52:01 +00:00
|
|
|
),
|
|
|
|
height: PIP_VIDEO_HEIGHT_PX,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
return nonRenderedRemoteParticipant(participant);
|
2022-09-07 15:52:55 +00:00
|
|
|
}),
|
|
|
|
PIP_VIDEO_HEIGHT_PX
|
2020-12-02 01:52:01 +00:00
|
|
|
);
|
|
|
|
} else {
|
|
|
|
setGroupCallVideoRequest(
|
2022-09-07 15:52:55 +00:00
|
|
|
activeCall.remoteParticipants.map(nonRenderedRemoteParticipant),
|
|
|
|
0
|
2020-12-02 01:52:01 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}, [
|
2020-12-02 18:14:03 +00:00
|
|
|
activeCall.callMode,
|
|
|
|
activeCall.remoteParticipants,
|
2020-12-02 01:52:01 +00:00
|
|
|
activeGroupCallSpeaker,
|
|
|
|
isPageVisible,
|
|
|
|
setGroupCallVideoRequest,
|
|
|
|
]);
|
|
|
|
|
2021-03-03 17:23:00 +00:00
|
|
|
switch (activeCall.callMode) {
|
|
|
|
case CallMode.Direct: {
|
|
|
|
const { hasRemoteVideo } = activeCall.remoteParticipants[0];
|
|
|
|
if (!hasRemoteVideo) {
|
|
|
|
return <NoVideo activeCall={activeCall} i18n={i18n} />;
|
|
|
|
}
|
|
|
|
return (
|
|
|
|
<div className="module-calling-pip__video--remote">
|
|
|
|
<DirectCallRemoteParticipant
|
|
|
|
conversation={conversation}
|
|
|
|
hasRemoteVideo={hasRemoteVideo}
|
|
|
|
i18n={i18n}
|
2023-10-16 17:58:51 +00:00
|
|
|
isReconnecting={isReconnecting(activeCall)}
|
2021-03-03 17:23:00 +00:00
|
|
|
setRendererCanvas={setRendererCanvas}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
);
|
2020-11-19 23:31:04 +00:00
|
|
|
}
|
2021-03-03 17:23:00 +00:00
|
|
|
case CallMode.Group:
|
|
|
|
if (!activeGroupCallSpeaker) {
|
|
|
|
return <NoVideo activeCall={activeCall} i18n={i18n} />;
|
|
|
|
}
|
|
|
|
return (
|
|
|
|
<div className="module-calling-pip__video--remote">
|
|
|
|
<GroupCallRemoteParticipant
|
|
|
|
getFrameBuffer={getGroupCallFrameBuffer}
|
|
|
|
getGroupCallVideoFrameSource={getGroupCallVideoFrameSource}
|
|
|
|
i18n={i18n}
|
|
|
|
isInPip
|
|
|
|
remoteParticipant={activeGroupCallSpeaker}
|
2023-03-22 17:53:13 +00:00
|
|
|
remoteParticipantsCount={activeCall.remoteParticipants.length}
|
2023-03-22 21:54:11 +00:00
|
|
|
isActiveSpeakerInSpeakerView={false}
|
2023-10-16 17:58:51 +00:00
|
|
|
isCallReconnecting={isReconnecting(activeCall)}
|
2021-03-03 17:23:00 +00:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
default:
|
|
|
|
throw missingCaseError(activeCall);
|
2020-11-17 15:07:53 +00:00
|
|
|
}
|
2022-11-18 00:45:19 +00:00
|
|
|
}
|