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

200 lines
5.9 KiB
TypeScript
Raw Normal View History

2023-01-03 19:55:46 +00:00
// Copyright 2020 Signal Messenger, LLC
2020-10-30 20:34:04 +00:00
// SPDX-License-Identifier: AGPL-3.0-only
2020-10-08 01:25:33 +00:00
import * as React from 'react';
import { times } from 'lodash';
2020-10-08 01:25:33 +00:00
import { action } from '@storybook/addon-actions';
import { v4 as generateUuid } from 'uuid';
2020-10-08 01:25:33 +00:00
import type { Meta } from '@storybook/react';
2021-05-28 16:15:17 +00:00
import { AvatarColors } from '../types/Colors';
import type { ConversationType } from '../state/ducks/conversations';
import type { PropsType } from './CallingLobby';
import { CallingLobby as UnwrappedCallingLobby } from './CallingLobby';
2021-09-18 00:30:08 +00:00
import { setupI18n } from '../util/setupI18n';
import { generateAci } from '../types/ServiceId';
2020-10-08 01:25:33 +00:00
import enMessages from '../../_locales/en/messages.json';
2021-10-26 22:59:08 +00:00
import {
getDefaultConversation,
2023-08-16 20:54:39 +00:00
getDefaultConversationWithServiceId,
2021-10-26 22:59:08 +00:00
} from '../test-both/helpers/getDefaultConversation';
import { CallingToastProvider } from './CallingToast';
2020-10-08 01:25:33 +00:00
const i18n = setupI18n('en', enMessages);
const camera = {
deviceId: 'dfbe6effe70b0611ba0fdc2a9ea3f39f6cb110e6687948f7e5f016c111b7329c',
groupId: '63ee218d2446869e40adfc958ff98263e51f74382b0143328ee4826f20a76f47',
kind: 'videoinput' as MediaDeviceKind,
label: 'FaceTime HD Camera (Built-in) (9fba:bced)',
toJSON() {
return '';
},
};
const createProps = (overrideProps: Partial<PropsType> = {}): PropsType => {
const isGroupCall = overrideProps.isGroupCall ?? false;
const conversation = isGroupCall
? getDefaultConversation({
title: 'Tahoe Trip',
type: 'group',
})
: getDefaultConversation();
return {
availableCameras: overrideProps.availableCameras || [camera],
conversation,
groupMembers:
overrideProps.groupMembers ||
(isGroupCall ? times(3, () => getDefaultConversation()) : undefined),
hasLocalAudio: overrideProps.hasLocalAudio ?? true,
hasLocalVideo: overrideProps.hasLocalVideo ?? false,
i18n,
isGroupCall,
isConversationTooBigToRing: false,
isCallFull: overrideProps.isCallFull ?? false,
me:
overrideProps.me ||
getDefaultConversation({
color: AvatarColors[0],
id: generateUuid(),
2023-08-16 20:54:39 +00:00
serviceId: generateAci(),
}),
onCallCanceled: action('on-call-canceled'),
onJoinCall: action('on-join-call'),
outgoingRing: overrideProps.outgoingRing ?? false,
peekedParticipants: overrideProps.peekedParticipants || [],
setLocalAudio: action('set-local-audio'),
setLocalPreview: action('set-local-preview'),
setLocalVideo: action('set-local-video'),
setOutgoingRing: action('set-outgoing-ring'),
showParticipantsList: overrideProps.showParticipantsList ?? false,
toggleParticipants: action('toggle-participants'),
toggleSettings: action('toggle-settings'),
};
};
2020-10-08 01:25:33 +00:00
function CallingLobby(props: ReturnType<typeof createProps>) {
return (
<CallingToastProvider i18n={i18n}>
<UnwrappedCallingLobby {...props} />
</CallingToastProvider>
);
}
2020-12-08 23:35:21 +00:00
const fakePeekedParticipant = (conversationProps: Partial<ConversationType>) =>
2023-08-16 20:54:39 +00:00
getDefaultConversationWithServiceId({
2020-12-08 23:35:21 +00:00
...conversationProps,
});
2020-12-02 18:14:03 +00:00
2022-06-07 00:48:02 +00:00
export default {
title: 'Components/CallingLobby',
argTypes: {},
args: {},
} satisfies Meta<PropsType>;
2020-10-08 01:25:33 +00:00
2022-11-18 00:45:19 +00:00
export function Default(): JSX.Element {
2020-10-08 01:25:33 +00:00
const props = createProps();
return <CallingLobby {...props} />;
2022-11-18 00:45:19 +00:00
}
2022-11-18 00:45:19 +00:00
export function NoCameraNoAvatar(): JSX.Element {
const props = createProps({
availableCameras: [],
});
return <CallingLobby {...props} />;
2022-11-18 00:45:19 +00:00
}
2022-06-07 00:48:02 +00:00
2022-11-18 00:45:19 +00:00
export function NoCameraLocalAvatar(): JSX.Element {
const props = createProps({
availableCameras: [],
me: getDefaultConversation({
avatarPath: '/fixtures/kitten-4-112-112.jpg',
2021-05-28 16:15:17 +00:00
color: AvatarColors[0],
id: generateUuid(),
2023-08-16 20:54:39 +00:00
serviceId: generateAci(),
}),
});
return <CallingLobby {...props} />;
2022-11-18 00:45:19 +00:00
}
2022-06-07 00:48:02 +00:00
2022-11-18 00:45:19 +00:00
export function LocalVideo(): JSX.Element {
const props = createProps({
hasLocalVideo: true,
});
return <CallingLobby {...props} />;
2022-11-18 00:45:19 +00:00
}
2022-11-18 00:45:19 +00:00
export function InitiallyMuted(): JSX.Element {
2020-10-08 01:25:33 +00:00
const props = createProps({
hasLocalAudio: false,
2020-10-08 01:25:33 +00:00
});
return <CallingLobby {...props} />;
2022-11-18 00:45:19 +00:00
}
2022-06-07 00:48:02 +00:00
export function GroupCallWithNoPeekedParticipants(): JSX.Element {
2020-12-02 18:14:03 +00:00
const props = createProps({ isGroupCall: true, peekedParticipants: [] });
2020-11-17 15:07:53 +00:00
return <CallingLobby {...props} />;
2022-11-18 00:45:19 +00:00
}
2020-11-17 15:07:53 +00:00
export function GroupCallWith1PeekedParticipant(): JSX.Element {
2020-12-02 18:14:03 +00:00
const props = createProps({
isGroupCall: true,
2020-12-08 23:35:21 +00:00
peekedParticipants: [{ title: 'Sam' }].map(fakePeekedParticipant),
});
return <CallingLobby {...props} />;
2022-11-18 00:45:19 +00:00
}
2020-12-08 23:35:21 +00:00
export function GroupCallWith1PeekedParticipantSelf(): JSX.Element {
2023-08-16 20:54:39 +00:00
const serviceId = generateAci();
2020-12-08 23:35:21 +00:00
const props = createProps({
isGroupCall: true,
me: getDefaultConversation({
id: generateUuid(),
2023-08-16 20:54:39 +00:00
serviceId,
}),
2023-08-16 20:54:39 +00:00
peekedParticipants: [fakePeekedParticipant({ title: 'Ash', serviceId })],
2020-12-02 18:14:03 +00:00
});
2020-11-17 15:07:53 +00:00
return <CallingLobby {...props} />;
2022-11-18 00:45:19 +00:00
}
2022-06-07 00:48:02 +00:00
export function GroupCallWith4PeekedParticipants(): JSX.Element {
2020-11-17 15:07:53 +00:00
const props = createProps({
isGroupCall: true,
2020-12-08 23:35:21 +00:00
peekedParticipants: ['Sam', 'Cayce', 'April', 'Logan', 'Carl'].map(title =>
fakePeekedParticipant({ title })
2020-12-02 18:14:03 +00:00
),
2020-11-17 15:07:53 +00:00
});
2020-10-08 01:25:33 +00:00
return <CallingLobby {...props} />;
2022-11-18 00:45:19 +00:00
}
2022-06-07 00:48:02 +00:00
export function GroupCallWith4PeekedParticipantsParticipantsList(): JSX.Element {
2020-11-20 19:39:50 +00:00
const props = createProps({
isGroupCall: true,
2020-12-08 23:35:21 +00:00
peekedParticipants: ['Sam', 'Cayce', 'April', 'Logan', 'Carl'].map(title =>
fakePeekedParticipant({ title })
2020-12-02 18:14:03 +00:00
),
2020-11-20 19:39:50 +00:00
showParticipantsList: true,
});
return <CallingLobby {...props} />;
2022-11-18 00:45:19 +00:00
}
export function GroupCallWithCallFull(): JSX.Element {
const props = createProps({
isGroupCall: true,
isCallFull: true,
2020-12-09 00:48:02 +00:00
peekedParticipants: ['Sam', 'Cayce'].map(title =>
fakePeekedParticipant({ title })
),
});
return <CallingLobby {...props} />;
2022-11-18 00:45:19 +00:00
}
2022-06-07 00:48:02 +00:00
export function GroupCallWith0PeekedParticipantsBigGroup(): JSX.Element {
const props = createProps({
isGroupCall: true,
groupMembers: times(100, () => getDefaultConversation()),
});
return <CallingLobby {...props} />;
2022-11-18 00:45:19 +00:00
}