signal-desktop/ts/components/DirectCallRemoteParticipant.tsx

87 lines
2 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 { SetRendererCanvasType } from '../state/ducks/calling';
import { ConversationType } from '../state/ducks/conversations';
import { LocalizerType } from '../types/Util';
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}
color={color || 'ultramarine'}
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>
);
}