|
|
|
|
@ -1,5 +1,5 @@ |
|
|
|
|
import type * as UiKit from '@rocket.chat/ui-kit'; |
|
|
|
|
import { useTranslation, useUserId } from '@rocket.chat/ui-contexts'; |
|
|
|
|
import type * as UiKit from '@rocket.chat/ui-kit'; |
|
|
|
|
import { |
|
|
|
|
VideoConfMessageSkeleton, |
|
|
|
|
VideoConfMessage, |
|
|
|
|
@ -17,10 +17,10 @@ import { |
|
|
|
|
import type { MouseEventHandler, ReactElement } from 'react'; |
|
|
|
|
import { useContext, memo } from 'react'; |
|
|
|
|
|
|
|
|
|
import { kitContext } from '../..'; |
|
|
|
|
import { useSurfaceType } from '../../contexts/SurfaceContext'; |
|
|
|
|
import type { BlockProps } from '../../utils/BlockProps'; |
|
|
|
|
import { useVideoConfDataStream } from './hooks/useVideoConfDataStream'; |
|
|
|
|
import { kitContext } from '../..'; |
|
|
|
|
|
|
|
|
|
type VideoConferenceBlockProps = BlockProps<UiKit.VideoConferenceBlock>; |
|
|
|
|
|
|
|
|
|
@ -37,11 +37,11 @@ const VideoConferenceBlock = ({ |
|
|
|
|
const { action, viewId, rid } = useContext(kitContext); |
|
|
|
|
|
|
|
|
|
if (surfaceType !== 'message') { |
|
|
|
|
return <></>; |
|
|
|
|
throw new Error('VideoConferenceBlock cannot be rendered outside message'); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (!callId || !rid) { |
|
|
|
|
return <></>; |
|
|
|
|
if (!rid) { |
|
|
|
|
throw new Error('VideoConferenceBlock cannot be rendered without rid'); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const result = useVideoConfDataStream({ rid, callId }); |
|
|
|
|
@ -85,109 +85,110 @@ const VideoConferenceBlock = ({ |
|
|
|
|
); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
if (result.isSuccess) { |
|
|
|
|
const { data } = result; |
|
|
|
|
const isUserCaller = data.createdBy._id === userId; |
|
|
|
|
|
|
|
|
|
if ('endedAt' in data) { |
|
|
|
|
return ( |
|
|
|
|
<VideoConfMessage> |
|
|
|
|
<VideoConfMessageRow> |
|
|
|
|
<VideoConfMessageContent> |
|
|
|
|
<VideoConfMessageIcon /> |
|
|
|
|
<VideoConfMessageText>{t('Call_ended')}</VideoConfMessageText> |
|
|
|
|
</VideoConfMessageContent> |
|
|
|
|
<VideoConfMessageActions> |
|
|
|
|
<VideoConfMessageAction icon='info' onClick={openCallInfo} /> |
|
|
|
|
</VideoConfMessageActions> |
|
|
|
|
</VideoConfMessageRow> |
|
|
|
|
<VideoConfMessageFooter> |
|
|
|
|
{data.type === 'direct' && ( |
|
|
|
|
<> |
|
|
|
|
<VideoConfMessageButton onClick={callAgainHandler}> |
|
|
|
|
{isUserCaller ? t('Call_again') : t('Call_back')} |
|
|
|
|
</VideoConfMessageButton> |
|
|
|
|
<VideoConfMessageFooterText> |
|
|
|
|
{t('Call_was_not_answered')} |
|
|
|
|
</VideoConfMessageFooterText> |
|
|
|
|
</> |
|
|
|
|
)} |
|
|
|
|
{data.type !== 'direct' && |
|
|
|
|
(data.users.length ? ( |
|
|
|
|
<> |
|
|
|
|
<VideoConfMessageUserStack users={data.users} /> |
|
|
|
|
<VideoConfMessageFooterText> |
|
|
|
|
{data.users.length > MAX_USERS |
|
|
|
|
? t('__usersCount__member_joined', { |
|
|
|
|
usersCount: data.users.length - MAX_USERS, |
|
|
|
|
}) |
|
|
|
|
: t('joined')} |
|
|
|
|
</VideoConfMessageFooterText> |
|
|
|
|
</> |
|
|
|
|
) : ( |
|
|
|
|
<VideoConfMessageFooterText> |
|
|
|
|
{t('Call_was_not_answered')} |
|
|
|
|
</VideoConfMessageFooterText> |
|
|
|
|
))} |
|
|
|
|
</VideoConfMessageFooter> |
|
|
|
|
</VideoConfMessage> |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (data.type === 'direct' && data.status === 0) { |
|
|
|
|
return ( |
|
|
|
|
<VideoConfMessage> |
|
|
|
|
<VideoConfMessageRow> |
|
|
|
|
<VideoConfMessageContent> |
|
|
|
|
<VideoConfMessageIcon variant='incoming' /> |
|
|
|
|
<VideoConfMessageText>{t('Calling')}</VideoConfMessageText> |
|
|
|
|
</VideoConfMessageContent> |
|
|
|
|
<VideoConfMessageActions> |
|
|
|
|
<VideoConfMessageAction icon='info' onClick={openCallInfo} /> |
|
|
|
|
</VideoConfMessageActions> |
|
|
|
|
</VideoConfMessageRow> |
|
|
|
|
<VideoConfMessageFooter> |
|
|
|
|
<VideoConfMessageFooterText> |
|
|
|
|
{t('Waiting_for_answer')} |
|
|
|
|
</VideoConfMessageFooterText> |
|
|
|
|
</VideoConfMessageFooter> |
|
|
|
|
</VideoConfMessage> |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
if (result.isLoading || result.isError) { |
|
|
|
|
// TODO: error handling
|
|
|
|
|
return <VideoConfMessageSkeleton />; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const { data } = result; |
|
|
|
|
const isUserCaller = data.createdBy._id === userId; |
|
|
|
|
|
|
|
|
|
if ('endedAt' in data) { |
|
|
|
|
return ( |
|
|
|
|
<VideoConfMessage> |
|
|
|
|
<VideoConfMessageRow> |
|
|
|
|
<VideoConfMessageContent> |
|
|
|
|
<VideoConfMessageIcon variant='outgoing' /> |
|
|
|
|
<VideoConfMessageText>{t('Call_ongoing')}</VideoConfMessageText> |
|
|
|
|
<VideoConfMessageIcon /> |
|
|
|
|
<VideoConfMessageText>{t('Call_ended')}</VideoConfMessageText> |
|
|
|
|
</VideoConfMessageContent> |
|
|
|
|
<VideoConfMessageActions> |
|
|
|
|
<VideoConfMessageAction icon='info' onClick={openCallInfo} /> |
|
|
|
|
</VideoConfMessageActions> |
|
|
|
|
</VideoConfMessageRow> |
|
|
|
|
<VideoConfMessageFooter> |
|
|
|
|
<VideoConfMessageButton primary onClick={joinHandler}> |
|
|
|
|
{t('Join')} |
|
|
|
|
</VideoConfMessageButton> |
|
|
|
|
{Boolean(data.users.length) && ( |
|
|
|
|
{data.type === 'direct' && ( |
|
|
|
|
<> |
|
|
|
|
<VideoConfMessageUserStack users={data.users} /> |
|
|
|
|
<VideoConfMessageButton onClick={callAgainHandler}> |
|
|
|
|
{isUserCaller ? t('Call_again') : t('Call_back')} |
|
|
|
|
</VideoConfMessageButton> |
|
|
|
|
<VideoConfMessageFooterText> |
|
|
|
|
{data.users.length > MAX_USERS |
|
|
|
|
? t('__usersCount__member_joined', { |
|
|
|
|
usersCount: data.users.length - MAX_USERS, |
|
|
|
|
}) |
|
|
|
|
: t('joined')} |
|
|
|
|
{t('Call_was_not_answered')} |
|
|
|
|
</VideoConfMessageFooterText> |
|
|
|
|
</> |
|
|
|
|
)} |
|
|
|
|
{data.type !== 'direct' && |
|
|
|
|
(data.users.length ? ( |
|
|
|
|
<> |
|
|
|
|
<VideoConfMessageUserStack users={data.users} /> |
|
|
|
|
<VideoConfMessageFooterText> |
|
|
|
|
{data.users.length > MAX_USERS |
|
|
|
|
? t('__usersCount__member_joined', { |
|
|
|
|
usersCount: data.users.length - MAX_USERS, |
|
|
|
|
}) |
|
|
|
|
: t('joined')} |
|
|
|
|
</VideoConfMessageFooterText> |
|
|
|
|
</> |
|
|
|
|
) : ( |
|
|
|
|
<VideoConfMessageFooterText> |
|
|
|
|
{t('Call_was_not_answered')} |
|
|
|
|
</VideoConfMessageFooterText> |
|
|
|
|
))} |
|
|
|
|
</VideoConfMessageFooter> |
|
|
|
|
</VideoConfMessage> |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (data.type === 'direct' && data.status === 0) { |
|
|
|
|
return ( |
|
|
|
|
<VideoConfMessage> |
|
|
|
|
<VideoConfMessageRow> |
|
|
|
|
<VideoConfMessageContent> |
|
|
|
|
<VideoConfMessageIcon variant='incoming' /> |
|
|
|
|
<VideoConfMessageText>{t('Calling')}</VideoConfMessageText> |
|
|
|
|
</VideoConfMessageContent> |
|
|
|
|
<VideoConfMessageActions> |
|
|
|
|
<VideoConfMessageAction icon='info' onClick={openCallInfo} /> |
|
|
|
|
</VideoConfMessageActions> |
|
|
|
|
</VideoConfMessageRow> |
|
|
|
|
<VideoConfMessageFooter> |
|
|
|
|
<VideoConfMessageFooterText> |
|
|
|
|
{t('Waiting_for_answer')} |
|
|
|
|
</VideoConfMessageFooterText> |
|
|
|
|
</VideoConfMessageFooter> |
|
|
|
|
</VideoConfMessage> |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return <VideoConfMessageSkeleton />; |
|
|
|
|
return ( |
|
|
|
|
<VideoConfMessage> |
|
|
|
|
<VideoConfMessageRow> |
|
|
|
|
<VideoConfMessageContent> |
|
|
|
|
<VideoConfMessageIcon variant='outgoing' /> |
|
|
|
|
<VideoConfMessageText>{t('Call_ongoing')}</VideoConfMessageText> |
|
|
|
|
</VideoConfMessageContent> |
|
|
|
|
<VideoConfMessageActions> |
|
|
|
|
<VideoConfMessageAction icon='info' onClick={openCallInfo} /> |
|
|
|
|
</VideoConfMessageActions> |
|
|
|
|
</VideoConfMessageRow> |
|
|
|
|
<VideoConfMessageFooter> |
|
|
|
|
<VideoConfMessageButton primary onClick={joinHandler}> |
|
|
|
|
{t('Join')} |
|
|
|
|
</VideoConfMessageButton> |
|
|
|
|
{Boolean(data.users.length) && ( |
|
|
|
|
<> |
|
|
|
|
<VideoConfMessageUserStack users={data.users} /> |
|
|
|
|
<VideoConfMessageFooterText> |
|
|
|
|
{data.users.length > MAX_USERS |
|
|
|
|
? t('__usersCount__member_joined', { |
|
|
|
|
usersCount: data.users.length - MAX_USERS, |
|
|
|
|
}) |
|
|
|
|
: t('joined')} |
|
|
|
|
</VideoConfMessageFooterText> |
|
|
|
|
</> |
|
|
|
|
)} |
|
|
|
|
</VideoConfMessageFooter> |
|
|
|
|
</VideoConfMessage> |
|
|
|
|
); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
export default memo(VideoConferenceBlock); |
|
|
|
|
|