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

126 lines
3.7 KiB
TypeScript
Raw Normal View History

2021-01-08 18:58:28 +00:00
// Copyright 2020-2021 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 { storiesOf } from '@storybook/react';
import { boolean } from '@storybook/addon-knobs';
import { action } from '@storybook/addon-actions';
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';
import type { ActiveCallType } from '../types/Calling';
2020-11-17 15:07:53 +00:00
import {
CallMode,
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
2020-12-02 18:14:03 +00:00
const getCommonActiveCallData = () => ({
conversation,
hasLocalAudio: boolean('hasLocalAudio', true),
hasLocalVideo: boolean('hasLocalVideo', false),
2021-01-08 22:57:54 +00:00
isInSpeakerView: boolean('isInSpeakerView', false),
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 defaultCall: ActiveCallType = {
...getCommonActiveCallData(),
2020-11-17 15:07:53 +00:00
callMode: CallMode.Direct as CallMode.Direct,
callState: CallState.Accepted,
2020-12-02 18:14:03 +00:00
peekedParticipants: [],
remoteParticipants: [
{ hasRemoteVideo: true, presenting: false, title: 'Arsene' },
],
2020-10-01 00:43:05 +00:00
};
2020-12-02 18:14:03 +00:00
const createProps = (overrideProps: Partial<PropsType> = {}): PropsType => ({
activeCall: overrideProps.activeCall || defaultCall,
2021-01-08 18:58:28 +00:00
getGroupCallVideoFrameSource: fakeGetGroupCallVideoFrameSource,
2020-10-01 00:43:05 +00:00
hangUp: action('hang-up'),
hasLocalVideo: boolean('hasLocalVideo', overrideProps.hasLocalVideo || false),
i18n,
setGroupCallVideoRequest: action('set-group-call-video-request'),
2020-10-01 00:43:05 +00:00
setLocalPreview: action('set-local-preview'),
setRendererCanvas: action('set-renderer-canvas'),
togglePip: action('toggle-pip'),
toggleSpeakerView: action('toggleSpeakerView'),
2020-10-01 00:43:05 +00:00
});
const story = storiesOf('Components/CallingPip', module);
story.add('Default', () => {
const props = createProps({});
2020-10-01 00:43:05 +00:00
return <CallingPip {...props} />;
});
2020-10-08 01:25:33 +00:00
2021-05-07 22:21:10 +00:00
story.add('Contact (with avatar and no video)', () => {
2020-12-02 18:14:03 +00:00
const props = createProps({
activeCall: {
...defaultCall,
conversation: {
...conversation,
avatarPath: 'https://www.fillmurray.com/64/64',
},
remoteParticipants: [
{ hasRemoteVideo: false, presenting: false, title: 'Julian' },
],
2020-12-02 18:14:03 +00:00
},
});
2020-10-08 01:25:33 +00:00
return <CallingPip {...props} />;
});
story.add('Contact (no color)', () => {
2020-12-02 18:14:03 +00:00
const props = createProps({
activeCall: {
...defaultCall,
conversation: {
...conversation,
color: undefined,
},
2020-12-02 18:14:03 +00:00
},
});
2020-10-08 01:25:33 +00:00
return <CallingPip {...props} />;
});
2020-11-17 15:07:53 +00:00
story.add('Group Call', () => {
2020-12-02 18:14:03 +00:00
const props = createProps({
activeCall: {
...getCommonActiveCallData(),
callMode: CallMode.Group as CallMode.Group,
connectionState: GroupCallConnectionState.Connected,
conversationsWithSafetyNumberChanges: [],
groupMembers: times(3, () => getDefaultConversation()),
2020-12-02 18:14:03 +00:00
joinState: GroupCallJoinState.Joined,
maxDevices: 5,
deviceCount: 0,
peekedParticipants: [],
remoteParticipants: [],
},
});
2020-11-17 15:07:53 +00:00
return <CallingPip {...props} />;
});