signal-desktop/ts/components/DirectCallRemoteParticipant.tsx

96 lines
2.4 KiB
TypeScript
Raw Normal View History

2023-01-03 19:55:46 +00:00
// Copyright 2020 Signal Messenger, LLC
2020-11-13 19:57:55 +00:00
// SPDX-License-Identifier: AGPL-3.0-only
import React, { useRef, useEffect } from 'react';
import classNames from 'classnames';
import type { SetRendererCanvasType } from '../state/ducks/calling';
import type { ConversationType } from '../state/ducks/conversations';
import type { LocalizerType } from '../types/Util';
2021-08-06 00:17:05 +00:00
import { AvatarColors } from '../types/Colors';
2022-12-09 20:37:45 +00:00
import { Avatar, AvatarSize } from './Avatar';
2023-10-30 20:31:54 +00:00
import { CallBackgroundBlur } from './CallBackgroundBlur';
2020-11-13 19:57:55 +00:00
type PropsType = {
2020-11-13 19:57:55 +00:00
conversation: ConversationType;
hasRemoteVideo: boolean;
i18n: LocalizerType;
isReconnecting: boolean;
2020-11-13 19:57:55 +00:00
setRendererCanvas: (_: SetRendererCanvasType) => void;
};
2020-11-13 19:57:55 +00:00
2022-11-18 00:45:19 +00:00
export function DirectCallRemoteParticipant({
2020-11-13 19:57:55 +00:00
conversation,
hasRemoteVideo,
i18n,
isReconnecting,
2020-11-13 19:57:55 +00:00
setRendererCanvas,
2022-11-18 00:45:19 +00:00
}: PropsType): JSX.Element {
2020-11-13 19:57:55 +00:00
const remoteVideoRef = useRef<HTMLCanvasElement | null>(null);
useEffect(() => {
setRendererCanvas({ element: remoteVideoRef });
return () => {
setRendererCanvas({ element: undefined });
};
}, [setRendererCanvas]);
return hasRemoteVideo ? (
<canvas
className={classNames(
'module-ongoing-call__remote-video-enabled',
isReconnecting &&
'module-ongoing-call__remote-video-enabled--reconnecting'
)}
2020-11-13 19:57:55 +00:00
ref={remoteVideoRef}
/>
) : (
renderAvatar(i18n, conversation)
);
2022-11-18 00:45:19 +00:00
}
2020-11-13 19:57:55 +00:00
function renderAvatar(
i18n: LocalizerType,
{
2021-05-07 22:21:10 +00:00
acceptedMessageRequest,
2020-11-13 19:57:55 +00:00
avatarPath,
color,
2021-05-07 22:21:10 +00:00
isMe,
2020-11-13 19:57:55 +00:00
phoneNumber,
profileName,
2021-05-07 22:21:10 +00:00
sharedGroupNames,
2020-11-13 19:57:55 +00:00
title,
2021-05-07 22:21:10 +00:00
}: Pick<
ConversationType,
| 'acceptedMessageRequest'
| 'avatarPath'
| 'color'
| 'isMe'
| 'phoneNumber'
| 'profileName'
| 'sharedGroupNames'
| 'title'
>
2020-11-13 19:57:55 +00:00
): JSX.Element {
return (
<div className="module-ongoing-call__remote-video-disabled">
2023-10-30 20:31:54 +00:00
<CallBackgroundBlur avatarPath={avatarPath} color={color}>
<Avatar
acceptedMessageRequest={acceptedMessageRequest}
avatarPath={avatarPath}
badge={undefined}
color={color || AvatarColors[0]}
noteToSelf={false}
conversationType="direct"
i18n={i18n}
isMe={isMe}
phoneNumber={phoneNumber}
profileName={profileName}
title={title}
sharedGroupNames={sharedGroupNames}
size={AvatarSize.EIGHTY}
/>
</CallBackgroundBlur>
2020-11-13 19:57:55 +00:00
</div>
);
}