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

118 lines
3.2 KiB
TypeScript
Raw Normal View History

2020-10-30 20:34:04 +00:00
// Copyright 2020 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
2020-10-01 00:43:05 +00:00
import * as React from 'react';
2020-11-17 15:07:53 +00:00
import { noop } 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';
import { ColorType } from '../types/Colors';
2020-11-17 15:07:53 +00:00
import { ConversationTypeType } from '../state/ducks/conversations';
2020-10-01 00:43:05 +00:00
import { CallingPip, PropsType } from './CallingPip';
2020-11-17 15:07:53 +00:00
import {
2020-12-02 18:14:03 +00:00
ActiveCallType,
2020-11-17 15:07:53 +00:00
CallMode,
CallState,
GroupCallConnectionState,
GroupCallJoinState,
} from '../types/Calling';
2020-10-01 00:43:05 +00:00
import { setup as setupI18n } from '../../js/modules/i18n';
import enMessages from '../../_locales/en/messages.json';
const i18n = setupI18n('en', enMessages);
const conversation = {
2020-10-08 01:25:33 +00:00
id: '3051234567',
2020-10-01 00:43:05 +00:00
avatarPath: undefined,
color: 'ultramarine' as ColorType,
title: 'Rick Sanchez',
name: 'Rick Sanchez',
phoneNumber: '3051234567',
profileName: 'Rick Sanchez',
2020-11-17 15:07:53 +00:00
markedUnread: false,
type: 'direct' as ConversationTypeType,
lastUpdated: Date.now(),
};
2020-12-02 18:14:03 +00:00
const getCommonActiveCallData = () => ({
conversation,
hasLocalAudio: boolean('hasLocalAudio', true),
hasLocalVideo: boolean('hasLocalVideo', false),
joinedAt: Date.now(),
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 }],
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,
2020-11-17 19:49:48 +00:00
// eslint-disable-next-line @typescript-eslint/no-explicit-any
2020-11-17 15:07:53 +00:00
getGroupCallVideoFrameSource: noop as any,
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'),
});
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
story.add('Contact (with avatar)', () => {
2020-12-02 18:14:03 +00:00
const props = createProps({
activeCall: {
...defaultCall,
conversation: {
...conversation,
avatarPath: 'https://www.fillmurray.com/64/64',
},
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: [],
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} />;
});