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

114 lines
3.2 KiB
TypeScript
Raw Normal View History

2023-01-03 19:55:46 +00:00
// Copyright 2021 Signal Messenger, LLC
2021-01-08 18:58:28 +00:00
// SPDX-License-Identifier: AGPL-3.0-only
import React from 'react';
2021-01-08 18:58:28 +00:00
import { memoize, times } from 'lodash';
import { action } from '@storybook/addon-actions';
import type { Meta } from '@storybook/react';
import type { PropsType } from './GroupCallOverflowArea';
2021-01-08 18:58:28 +00:00
import { GroupCallOverflowArea } from './GroupCallOverflowArea';
2021-09-18 00:30:08 +00:00
import { setupI18n } from '../util/setupI18n';
2023-08-16 20:54:39 +00:00
import { getDefaultConversationWithServiceId } from '../test-both/helpers/getDefaultConversation';
2021-01-08 18:58:28 +00:00
import { fakeGetGroupCallVideoFrameSource } from '../test-both/helpers/fakeGetGroupCallVideoFrameSource';
import { FRAME_BUFFER_SIZE } from '../calling/constants';
import enMessages from '../../_locales/en/messages.json';
import { generateAci } from '../types/ServiceId';
import type { CallingImageDataCache } from './CallManager';
2021-01-08 18:58:28 +00:00
const MAX_PARTICIPANTS = 32;
const i18n = setupI18n('en', enMessages);
const allRemoteParticipants = times(MAX_PARTICIPANTS).map(index => ({
aci: generateAci(),
2021-01-08 18:58:28 +00:00
demuxId: index,
hasRemoteAudio: index % 3 !== 0,
hasRemoteVideo: index % 4 !== 0,
2023-12-06 21:52:29 +00:00
isHandRaised: (index - 2) % 8 === 0,
2024-01-23 19:08:21 +00:00
mediaKeysReceived: (index + 1) % 20 !== 0,
presenting: false,
sharingScreen: false,
2021-01-08 18:58:28 +00:00
videoAspectRatio: 1.3,
2023-08-16 20:54:39 +00:00
...getDefaultConversationWithServiceId({
2021-01-08 18:58:28 +00:00
isBlocked: index === 10 || index === MAX_PARTICIPANTS - 1,
title: `Participant ${index + 1}`,
}),
}));
2022-06-07 00:48:02 +00:00
export default {
title: 'Components/GroupCallOverflowArea',
argTypes: {},
args: {},
} satisfies Meta<PropsType>;
2021-01-08 18:58:28 +00:00
const defaultProps = {
getFrameBuffer: memoize(() => Buffer.alloc(FRAME_BUFFER_SIZE)),
getCallingImageDataCache: memoize(() => new Map()),
2021-01-08 18:58:28 +00:00
getGroupCallVideoFrameSource: fakeGetGroupCallVideoFrameSource,
imageDataCache: React.createRef<CallingImageDataCache>(),
2021-01-08 18:58:28 +00:00
i18n,
isCallReconnecting: false,
onParticipantVisibilityChanged: action('onParticipantVisibilityChanged'),
2022-05-19 03:28:51 +00:00
remoteAudioLevels: new Map<number, number>(),
remoteParticipantsCount: 1,
2021-01-08 18:58:28 +00:00
};
// This component is usually rendered on a call screen.
2022-11-18 00:45:19 +00:00
function Container({ children }: { children: JSX.Element }): JSX.Element {
return (
<div
style={{
background: 'black',
display: 'inline-flex',
height: '80vh',
}}
>
{children}
</div>
);
}
export function NoOverflowedParticipants(): JSX.Element {
return (
<Container>
<GroupCallOverflowArea {...defaultProps} overflowedParticipants={[]} />
</Container>
);
}
2022-06-07 00:48:02 +00:00
2022-11-18 00:45:19 +00:00
export function OneOverflowedParticipant(): JSX.Element {
return (
<Container>
<GroupCallOverflowArea
{...defaultProps}
overflowedParticipants={allRemoteParticipants.slice(0, 1)}
/>
</Container>
);
}
2022-06-07 00:48:02 +00:00
2022-11-18 00:45:19 +00:00
export function ThreeOverflowedParticipants(): JSX.Element {
return (
<Container>
<GroupCallOverflowArea
{...defaultProps}
overflowedParticipants={allRemoteParticipants.slice(0, 3)}
/>
</Container>
);
}
2022-06-07 00:48:02 +00:00
2022-11-18 00:45:19 +00:00
export function ManyOverflowedParticipants(): JSX.Element {
return (
<Container>
<GroupCallOverflowArea
{...defaultProps}
overflowedParticipants={allRemoteParticipants.slice(
0,
MAX_PARTICIPANTS
2022-11-18 00:45:19 +00:00
)}
/>
</Container>
);
}