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

161 lines
4.6 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-06-04 18:16:19 +00:00
import * as React from 'react';
2020-11-13 19:57:55 +00:00
import { noop } from 'lodash';
2020-09-12 00:46:52 +00:00
import { storiesOf } from '@storybook/react';
import { action } from '@storybook/addon-actions';
2020-11-17 15:07:53 +00:00
import { boolean, select, text } from '@storybook/addon-knobs';
2020-09-12 00:46:52 +00:00
2020-11-13 19:57:55 +00:00
import { CallManager, PropsType } from './CallManager';
import {
CallEndedReason,
CallMode,
CallState,
GroupCallConnectionState,
GroupCallJoinState,
} from '../types/Calling';
import { ConversationTypeType } from '../state/ducks/conversations';
2020-11-17 15:07:53 +00:00
import { Colors, ColorType } from '../types/Colors';
2020-06-04 18:16:19 +00:00
import { setup as setupI18n } from '../../js/modules/i18n';
import enMessages from '../../_locales/en/messages.json';
const i18n = setupI18n('en', enMessages);
2020-11-17 15:07:53 +00:00
const getConversation = () => ({
2020-10-08 01:25:33 +00:00
id: '3051234567',
2020-07-24 01:35:32 +00:00
avatarPath: undefined,
2020-11-17 15:07:53 +00:00
color: select('Callee color', Colors, 'ultramarine' as ColorType),
title: text('Callee Title', 'Rick Sanchez'),
name: text('Callee Name', 'Rick Sanchez'),
2020-06-04 18:16:19 +00:00
phoneNumber: '3051234567',
profileName: 'Rick Sanchez',
2020-11-13 19:57:55 +00:00
markedUnread: false,
type: 'direct' as ConversationTypeType,
lastUpdated: Date.now(),
2020-11-17 15:07:53 +00:00
});
const getCallState = () => ({
conversationId: '3051234567',
joinedAt: Date.now(),
hasLocalAudio: boolean('hasLocalAudio', true),
hasLocalVideo: boolean('hasLocalVideo', false),
pip: boolean('pip', false),
settingsDialogOpen: boolean('settingsDialogOpen', false),
showParticipantsList: boolean('showParticipantsList', false),
});
const getIncomingCallState = (extraProps = {}) => ({
...extraProps,
callMode: CallMode.Direct as CallMode.Direct,
conversationId: '3051234567',
callState: CallState.Ringing,
isIncoming: true,
isVideoCall: boolean('isVideoCall', true),
hasRemoteVideo: true,
});
2020-06-04 18:16:19 +00:00
2020-11-17 15:07:53 +00:00
const createProps = (storyProps: Partial<PropsType> = {}): PropsType => ({
...storyProps,
availableCameras: [],
2020-06-04 18:16:19 +00:00
acceptCall: action('accept-call'),
2020-10-08 01:25:33 +00:00
cancelCall: action('cancel-call'),
2020-10-01 19:09:15 +00:00
closeNeedPermissionScreen: action('close-need-permission-screen'),
2020-06-04 18:16:19 +00:00
declineCall: action('decline-call'),
2020-11-13 19:57:55 +00:00
// We allow `any` here because these are fake and actually come from RingRTC, which we
// can't import.
/* eslint-disable @typescript-eslint/no-explicit-any */
createCanvasVideoRenderer: () =>
({
setCanvas: noop,
enable: noop,
disable: noop,
} as any),
getGroupCallVideoFrameSource: noop as any,
/* eslint-enable @typescript-eslint/no-explicit-any */
2020-06-04 18:16:19 +00:00
hangUp: action('hang-up'),
i18n,
me: {
2020-11-17 15:07:53 +00:00
color: select('Caller color', Colors, 'ultramarine' as ColorType),
title: text('Caller Title', 'Morty Smith'),
},
2020-08-27 00:03:42 +00:00
renderDeviceSelection: () => <div />,
2020-06-04 18:16:19 +00:00
setLocalAudio: action('set-local-audio'),
2020-08-27 00:03:42 +00:00
setLocalPreview: action('set-local-preview'),
2020-06-04 18:16:19 +00:00
setLocalVideo: action('set-local-video'),
2020-08-27 00:03:42 +00:00
setRendererCanvas: action('set-renderer-canvas'),
2020-10-08 01:25:33 +00:00
startCall: action('start-call'),
toggleParticipants: action('toggle-participants'),
2020-10-01 00:43:05 +00:00
togglePip: action('toggle-pip'),
2020-08-27 00:03:42 +00:00
toggleSettings: action('toggle-settings'),
2020-11-17 15:07:53 +00:00
});
2020-06-04 18:16:19 +00:00
2020-11-17 15:07:53 +00:00
const story = storiesOf('Components/CallManager', module);
story.add('No Call', () => <CallManager {...createProps()} />);
story.add('Ongoing Direct Call', () => (
<CallManager
{...createProps({
activeCall: {
call: {
2020-11-13 19:57:55 +00:00
callMode: CallMode.Direct as CallMode.Direct,
conversationId: '3051234567',
callState: CallState.Accepted,
isIncoming: false,
isVideoCall: true,
hasRemoteVideo: true,
},
2020-11-17 15:07:53 +00:00
activeCallState: getCallState(),
conversation: getConversation(),
groupCallParticipants: [],
},
2020-11-17 15:07:53 +00:00
})}
/>
));
story.add('Ongoing Group Call', () => (
<CallManager
{...createProps({
2020-11-13 19:57:55 +00:00
activeCall: {
call: {
callMode: CallMode.Group as CallMode.Group,
conversationId: '3051234567',
connectionState: GroupCallConnectionState.Connected,
joinState: GroupCallJoinState.Joined,
remoteParticipants: [],
},
2020-11-17 15:07:53 +00:00
activeCallState: getCallState(),
conversation: getConversation(),
groupCallParticipants: [],
2020-11-13 19:57:55 +00:00
},
2020-11-17 15:07:53 +00:00
})}
/>
));
story.add('Ringing', () => (
<CallManager
{...createProps({
incomingCall: {
2020-11-17 15:07:53 +00:00
call: getIncomingCallState(),
conversation: getConversation(),
},
2020-11-17 15:07:53 +00:00
})}
/>
));
story.add('Call Request Needed', () => (
<CallManager
{...createProps({
activeCall: {
2020-11-17 15:07:53 +00:00
call: getIncomingCallState({
callEndedReason: CallEndedReason.RemoteHangupNeedPermission,
2020-11-17 15:07:53 +00:00
}),
activeCallState: getCallState(),
conversation: getConversation(),
groupCallParticipants: [],
},
2020-11-17 15:07:53 +00:00
})}
/>
));