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

150 lines
4.3 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-01 00:43:05 +00:00
import * as React from 'react';
import { times } from 'lodash';
2020-10-01 00:43:05 +00:00
import { action } from '@storybook/addon-actions';
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 './CallingPip';
import { CallingPip } from './CallingPip';
2022-11-18 00:45:19 +00:00
import type { ActiveDirectCallType } from '../types/Calling';
2020-11-17 15:07:53 +00:00
import {
CallMode,
CallViewMode,
2020-11-17 15:07:53 +00:00
CallState,
GroupCallConnectionState,
GroupCallJoinState,
} from '../types/Calling';
2021-05-07 22:21:10 +00:00
import { getDefaultConversation } from '../test-both/helpers/getDefaultConversation';
2021-01-08 18:58:28 +00:00
import { fakeGetGroupCallVideoFrameSource } from '../test-both/helpers/fakeGetGroupCallVideoFrameSource';
2021-09-18 00:30:08 +00:00
import { setupI18n } from '../util/setupI18n';
2020-10-01 00:43:05 +00:00
import enMessages from '../../_locales/en/messages.json';
const i18n = setupI18n('en', enMessages);
2021-05-07 22:21:10 +00:00
const conversation: ConversationType = getDefaultConversation({
2020-10-08 01:25:33 +00:00
id: '3051234567',
2020-10-01 00:43:05 +00:00
avatarPath: undefined,
2021-05-28 16:15:17 +00:00
color: AvatarColors[0],
2020-10-01 00:43:05 +00:00
title: 'Rick Sanchez',
name: 'Rick Sanchez',
phoneNumber: '3051234567',
profileName: 'Rick Sanchez',
2021-05-07 22:21:10 +00:00
});
2020-11-17 15:07:53 +00:00
type Overrides = {
hasLocalAudio?: boolean;
hasLocalVideo?: boolean;
localAudioLevel?: number;
viewMode?: CallViewMode;
};
const getCommonActiveCallData = (overrides: Overrides) => ({
2020-12-02 18:14:03 +00:00
conversation,
hasLocalAudio: overrides.hasLocalAudio ?? true,
hasLocalVideo: overrides.hasLocalVideo ?? false,
localAudioLevel: overrides.localAudioLevel ?? 0,
viewMode: overrides.viewMode ?? CallViewMode.Paginated,
2020-12-02 18:14:03 +00:00
joinedAt: Date.now(),
outgoingRing: true,
2020-12-02 18:14:03 +00:00
pip: true,
settingsDialogOpen: false,
showParticipantsList: false,
});
const getDefaultCall = (overrides: Overrides): ActiveDirectCallType => {
return {
...getCommonActiveCallData(overrides),
callMode: CallMode.Direct as CallMode.Direct,
callState: CallState.Accepted,
peekedParticipants: [],
remoteParticipants: [
{ hasRemoteVideo: true, presenting: false, title: 'Arsene' },
],
};
2020-10-01 00:43:05 +00:00
};
2022-06-07 00:48:02 +00:00
export default {
title: 'Components/CallingPip',
argTypes: {
hasLocalVideo: { control: { type: 'boolean' } },
},
args: {
activeCall: getDefaultCall({}),
getGroupCallVideoFrameSource: fakeGetGroupCallVideoFrameSource,
hangUpActiveCall: action('hang-up-active-call'),
hasLocalVideo: false,
i18n,
setGroupCallVideoRequest: action('set-group-call-video-request'),
setLocalPreview: action('set-local-preview'),
setRendererCanvas: action('set-renderer-canvas'),
switchFromPresentationView: action('switch-to-presentation-view'),
switchToPresentationView: action('switch-to-presentation-view'),
togglePip: action('toggle-pip'),
},
} satisfies Meta<PropsType>;
2020-10-01 00:43:05 +00:00
export function Default(args: PropsType): JSX.Element {
return <CallingPip {...args} />;
2022-11-18 00:45:19 +00:00
}
2020-10-08 01:25:33 +00:00
export function ContactWithAvatarAndNoVideo(args: PropsType): JSX.Element {
return (
<CallingPip
{...args}
activeCall={{
...getDefaultCall({}),
conversation: {
...conversation,
avatarPath: 'https://www.fillmurray.com/64/64',
},
remoteParticipants: [
{ hasRemoteVideo: false, presenting: false, title: 'Julian' },
],
}}
/>
);
2022-11-18 00:45:19 +00:00
}
2022-06-07 00:48:02 +00:00
export function ContactNoColor(args: PropsType): JSX.Element {
return (
<CallingPip
{...args}
activeCall={{
...getDefaultCall({}),
conversation: {
...conversation,
color: undefined,
},
}}
/>
);
2022-11-18 00:45:19 +00:00
}
2022-06-07 00:48:02 +00:00
export function GroupCall(args: PropsType): JSX.Element {
return (
<CallingPip
{...args}
activeCall={{
...getCommonActiveCallData({}),
callMode: CallMode.Group as CallMode.Group,
connectionState: GroupCallConnectionState.Connected,
conversationsWithSafetyNumberChanges: [],
2023-11-16 19:55:35 +00:00
conversationsByDemuxId: new Map<number, ConversationType>(),
groupMembers: times(3, () => getDefaultConversation()),
isConversationTooBigToRing: false,
joinState: GroupCallJoinState.Joined,
2023-11-16 19:55:35 +00:00
localDemuxId: 1,
maxDevices: 5,
deviceCount: 0,
peekedParticipants: [],
2023-12-06 21:52:29 +00:00
raisedHands: new Set<number>(),
remoteParticipants: [],
remoteAudioLevels: new Map<number, number>(),
}}
/>
);
2022-11-18 00:45:19 +00:00
}