signal-desktop/ts/components/GroupCallRemoteParticipant.stories.tsx

147 lines
3.3 KiB
TypeScript
Raw Normal View History

2023-01-03 19:55:46 +00:00
// Copyright 2020 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import * as React from 'react';
import { memoize, noop } from 'lodash';
2022-05-19 03:28:51 +00:00
import { select } from '@storybook/addon-knobs';
import type { PropsType } from './GroupCallRemoteParticipant';
import { GroupCallRemoteParticipant } from './GroupCallRemoteParticipant';
import { getDefaultConversation } from '../test-both/helpers/getDefaultConversation';
import { FRAME_BUFFER_SIZE } from '../calling/constants';
2021-09-18 00:30:08 +00:00
import { setupI18n } from '../util/setupI18n';
import enMessages from '../../_locales/en/messages.json';
const i18n = setupI18n('en', enMessages);
2022-05-19 03:28:51 +00:00
type OverridePropsType = {
audioLevel?: number;
remoteParticipantsCount?: number;
2022-05-19 03:28:51 +00:00
} & (
| {
isInPip: true;
}
| {
isInPip: false;
height: number;
left: number;
top: number;
width: number;
2022-05-19 03:28:51 +00:00
}
);
const getFrameBuffer = memoize(() => Buffer.alloc(FRAME_BUFFER_SIZE));
const createProps = (
overrideProps: OverridePropsType,
2022-05-19 03:28:51 +00:00
{
isBlocked = false,
hasRemoteAudio = false,
presenting = false,
2022-05-19 03:28:51 +00:00
}: {
isBlocked?: boolean;
hasRemoteAudio?: boolean;
presenting?: boolean;
2022-05-19 03:28:51 +00:00
} = {}
): PropsType => ({
getFrameBuffer,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
getGroupCallVideoFrameSource: noop as any,
i18n,
2022-05-19 03:28:51 +00:00
audioLevel: 0,
remoteParticipant: {
demuxId: 123,
2022-05-19 03:28:51 +00:00
hasRemoteAudio,
hasRemoteVideo: true,
presenting,
sharingScreen: false,
videoAspectRatio: 1.3,
...getDefaultConversation({
isBlocked: Boolean(isBlocked),
title:
'Pablo Diego José Francisco de Paula Juan Nepomuceno María de los Remedios Cipriano de la Santísima Trinidad Ruiz y Picasso',
uuid: '992ed3b9-fc9b-47a9-bdb4-e0c7cbb0fda5',
}),
},
remoteParticipantsCount: 1,
isActiveSpeakerInSpeakerView: false,
...overrideProps,
});
2022-06-07 00:48:02 +00:00
export default {
title: 'Components/GroupCallRemoteParticipant',
};
2022-11-18 00:45:19 +00:00
export function Default(): JSX.Element {
return (
<GroupCallRemoteParticipant
{...createProps({
2022-05-19 03:28:51 +00:00
isInPip: false,
height: 120,
left: 0,
top: 0,
width: 120,
2022-11-18 00:45:19 +00:00
})}
/>
);
}
2022-05-19 03:28:51 +00:00
2022-11-18 00:45:19 +00:00
export function Speaking(): JSX.Element {
function createSpeakingProps(
index: number,
remoteParticipantsCount: number,
presenting: boolean
) {
return createProps(
{
isInPip: false,
height: 120,
left: (120 + 10) * index,
top: 0,
width: 120,
audioLevel: select('audioLevel', [0, 0.5, 1], 0.5),
remoteParticipantsCount,
},
{ hasRemoteAudio: true, presenting }
);
}
2022-11-18 00:45:19 +00:00
return (
<>
<GroupCallRemoteParticipant {...createSpeakingProps(0, 1, false)} />
<GroupCallRemoteParticipant {...createSpeakingProps(1, 2, false)} />
<GroupCallRemoteParticipant {...createSpeakingProps(2, 2, true)} />
</>
2022-11-18 00:45:19 +00:00
);
}
export function IsInPip(): JSX.Element {
return (
<GroupCallRemoteParticipant
{...createProps({
isInPip: true,
})}
/>
);
}
2022-06-07 00:48:02 +00:00
IsInPip.story = {
name: 'isInPip',
};
2022-11-18 00:45:19 +00:00
export function Blocked(): JSX.Element {
return (
<GroupCallRemoteParticipant
{...createProps(
{
isInPip: false,
height: 120,
left: 0,
top: 0,
width: 120,
},
{ isBlocked: true }
)}
/>
);
}