signal-desktop/ts/components/DirectCallRemoteParticipant.tsx

89 lines
2.1 KiB
TypeScript
Raw Normal View History

// Copyright 2020-2021 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 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';
2020-11-13 19:57:55 +00:00
import { Avatar } from './Avatar';
type PropsType = {
2020-11-13 19:57:55 +00:00
conversation: ConversationType;
hasRemoteVideo: boolean;
i18n: LocalizerType;
setRendererCanvas: (_: SetRendererCanvasType) => void;
};
2020-11-13 19:57:55 +00:00
export const DirectCallRemoteParticipant: React.FC<PropsType> = ({
conversation,
hasRemoteVideo,
i18n,
setRendererCanvas,
}) => {
const remoteVideoRef = useRef<HTMLCanvasElement | null>(null);
useEffect(() => {
setRendererCanvas({ element: remoteVideoRef });
return () => {
setRendererCanvas({ element: undefined });
};
}, [setRendererCanvas]);
return hasRemoteVideo ? (
<canvas
className="module-ongoing-call__remote-video-enabled"
ref={remoteVideoRef}
/>
) : (
renderAvatar(i18n, conversation)
);
};
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
name,
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'
| 'name'
| 'phoneNumber'
| 'profileName'
| 'sharedGroupNames'
| 'title'
>
2020-11-13 19:57:55 +00:00
): JSX.Element {
return (
<div className="module-ongoing-call__remote-video-disabled">
<Avatar
2021-05-07 22:21:10 +00:00
acceptedMessageRequest={acceptedMessageRequest}
2020-11-13 19:57:55 +00:00
avatarPath={avatarPath}
badge={undefined}
2021-08-06 00:17:05 +00:00
color={color || AvatarColors[0]}
2020-11-13 19:57:55 +00:00
noteToSelf={false}
conversationType="direct"
i18n={i18n}
2021-05-07 22:21:10 +00:00
isMe={isMe}
2020-11-13 19:57:55 +00:00
name={name}
phoneNumber={phoneNumber}
profileName={profileName}
title={title}
2021-05-07 22:21:10 +00:00
sharedGroupNames={sharedGroupNames}
2020-11-13 19:57:55 +00:00
size={112}
/>
</div>
);
}