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-06-04 18:16:19 +00:00
|
|
|
import * as React from 'react';
|
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';
|
2021-05-28 16:15:17 +00:00
|
|
|
import { AvatarColors, AvatarColorType } from '../types/Colors';
|
2020-12-18 19:16:44 +00:00
|
|
|
import { getDefaultConversation } from '../test-both/helpers/getDefaultConversation';
|
2021-01-08 18:58:28 +00:00
|
|
|
import { fakeGetGroupCallVideoFrameSource } from '../test-both/helpers/fakeGetGroupCallVideoFrameSource';
|
2020-06-04 18:16:19 +00:00
|
|
|
import { setup as setupI18n } from '../../js/modules/i18n';
|
2020-12-08 19:37:04 +00:00
|
|
|
import { Props as SafetyNumberViewerProps } from '../state/smart/SafetyNumberViewer';
|
2020-06-04 18:16:19 +00:00
|
|
|
import enMessages from '../../_locales/en/messages.json';
|
|
|
|
|
|
|
|
const i18n = setupI18n('en', enMessages);
|
|
|
|
|
2021-05-07 22:21:10 +00:00
|
|
|
const getConversation = () =>
|
|
|
|
getDefaultConversation({
|
|
|
|
id: '3051234567',
|
|
|
|
avatarPath: undefined,
|
2021-05-28 16:15:17 +00:00
|
|
|
color: select(
|
|
|
|
'Callee color',
|
|
|
|
AvatarColors,
|
|
|
|
'ultramarine' as AvatarColorType
|
|
|
|
),
|
2021-05-07 22:21:10 +00:00
|
|
|
title: text('Callee Title', 'Rick Sanchez'),
|
|
|
|
name: text('Callee Name', 'Rick Sanchez'),
|
|
|
|
phoneNumber: '3051234567',
|
|
|
|
profileName: 'Rick Sanchez',
|
|
|
|
markedUnread: false,
|
|
|
|
type: 'direct' as ConversationTypeType,
|
|
|
|
lastUpdated: Date.now(),
|
|
|
|
});
|
2020-11-17 15:07:53 +00:00
|
|
|
|
2020-12-02 18:14:03 +00:00
|
|
|
const getCommonActiveCallData = () => ({
|
|
|
|
conversation: getConversation(),
|
2020-11-17 15:07:53 +00:00
|
|
|
joinedAt: Date.now(),
|
|
|
|
hasLocalAudio: boolean('hasLocalAudio', true),
|
|
|
|
hasLocalVideo: boolean('hasLocalVideo', false),
|
2021-01-08 22:57:54 +00:00
|
|
|
isInSpeakerView: boolean('isInSpeakerView', false),
|
2020-11-17 15:07:53 +00:00
|
|
|
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,
|
2020-10-14 16:30:50 +00:00
|
|
|
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'),
|
2021-01-08 18:58:28 +00:00
|
|
|
getGroupCallVideoFrameSource: (_: string, demuxId: number) =>
|
|
|
|
fakeGetGroupCallVideoFrameSource(demuxId),
|
2021-05-20 21:54:03 +00:00
|
|
|
getPresentingSources: action('get-presenting-sources'),
|
2020-06-04 18:16:19 +00:00
|
|
|
hangUp: action('hang-up'),
|
|
|
|
i18n,
|
2020-12-08 19:37:04 +00:00
|
|
|
keyChangeOk: action('key-change-ok'),
|
2020-11-04 19:56:03 +00:00
|
|
|
me: {
|
2020-12-08 19:37:04 +00:00
|
|
|
...getDefaultConversation({
|
2021-05-28 16:15:17 +00:00
|
|
|
color: select(
|
|
|
|
'Caller color',
|
|
|
|
AvatarColors,
|
|
|
|
'ultramarine' as AvatarColorType
|
|
|
|
),
|
2020-12-08 19:37:04 +00:00
|
|
|
title: text('Caller Title', 'Morty Smith'),
|
|
|
|
}),
|
2020-12-02 18:14:03 +00:00
|
|
|
uuid: 'cb0dd0c8-7393-41e9-a0aa-d631c4109541',
|
2020-11-04 19:56:03 +00:00
|
|
|
},
|
2021-05-20 21:54:03 +00:00
|
|
|
openSystemPreferencesAction: action('open-system-preferences-action'),
|
2020-08-27 00:03:42 +00:00
|
|
|
renderDeviceSelection: () => <div />,
|
2020-12-08 19:37:04 +00:00
|
|
|
renderSafetyNumberViewer: (_: SafetyNumberViewerProps) => <div />,
|
2020-12-02 01:52:01 +00:00
|
|
|
setGroupCallVideoRequest: action('set-group-call-video-request'),
|
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'),
|
2021-05-20 21:54:03 +00:00
|
|
|
setPresenting: action('toggle-presenting'),
|
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'),
|
2021-05-20 21:54:03 +00:00
|
|
|
toggleScreenRecordingPermissionsDialog: action(
|
|
|
|
'toggle-screen-recording-permissions-dialog'
|
|
|
|
),
|
2020-08-27 00:03:42 +00:00
|
|
|
toggleSettings: action('toggle-settings'),
|
2021-01-08 22:57:54 +00:00
|
|
|
toggleSpeakerView: action('toggle-speaker-view'),
|
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({
|
2020-11-06 17:36:37 +00:00
|
|
|
activeCall: {
|
2020-12-02 18:14:03 +00:00
|
|
|
...getCommonActiveCallData(),
|
|
|
|
callMode: CallMode.Direct,
|
|
|
|
callState: CallState.Accepted,
|
|
|
|
peekedParticipants: [],
|
2021-05-20 21:54:03 +00:00
|
|
|
remoteParticipants: [
|
|
|
|
{ hasRemoteVideo: true, presenting: false, title: 'Remy' },
|
|
|
|
],
|
2020-11-06 17:36:37 +00:00
|
|
|
},
|
2020-11-17 15:07:53 +00:00
|
|
|
})}
|
|
|
|
/>
|
|
|
|
));
|
|
|
|
|
|
|
|
story.add('Ongoing Group Call', () => (
|
|
|
|
<CallManager
|
|
|
|
{...createProps({
|
2020-11-13 19:57:55 +00:00
|
|
|
activeCall: {
|
2020-12-02 18:14:03 +00:00
|
|
|
...getCommonActiveCallData(),
|
|
|
|
callMode: CallMode.Group,
|
|
|
|
connectionState: GroupCallConnectionState.Connected,
|
2020-12-08 19:37:04 +00:00
|
|
|
conversationsWithSafetyNumberChanges: [],
|
2020-12-02 18:14:03 +00:00
|
|
|
deviceCount: 0,
|
|
|
|
joinState: GroupCallJoinState.Joined,
|
|
|
|
maxDevices: 5,
|
2021-08-17 21:45:18 +00:00
|
|
|
groupMembers: [],
|
2020-12-02 18:14:03 +00:00
|
|
|
peekedParticipants: [],
|
|
|
|
remoteParticipants: [],
|
2020-11-13 19:57:55 +00:00
|
|
|
},
|
2020-11-17 15:07:53 +00:00
|
|
|
})}
|
|
|
|
/>
|
|
|
|
));
|
|
|
|
|
|
|
|
story.add('Ringing', () => (
|
|
|
|
<CallManager
|
|
|
|
{...createProps({
|
2020-11-06 17:36:37 +00:00
|
|
|
incomingCall: {
|
2020-11-17 15:07:53 +00:00
|
|
|
call: getIncomingCallState(),
|
|
|
|
conversation: getConversation(),
|
2020-11-06 17:36:37 +00:00
|
|
|
},
|
2020-11-17 15:07:53 +00:00
|
|
|
})}
|
|
|
|
/>
|
|
|
|
));
|
|
|
|
|
|
|
|
story.add('Call Request Needed', () => (
|
|
|
|
<CallManager
|
|
|
|
{...createProps({
|
2020-11-06 17:36:37 +00:00
|
|
|
activeCall: {
|
2020-12-02 18:14:03 +00:00
|
|
|
...getCommonActiveCallData(),
|
|
|
|
callEndedReason: CallEndedReason.RemoteHangupNeedPermission,
|
|
|
|
callMode: CallMode.Direct,
|
|
|
|
callState: CallState.Accepted,
|
|
|
|
peekedParticipants: [],
|
2021-05-20 21:54:03 +00:00
|
|
|
remoteParticipants: [
|
|
|
|
{ hasRemoteVideo: true, presenting: false, title: 'Mike' },
|
|
|
|
],
|
2020-11-06 17:36:37 +00:00
|
|
|
},
|
2020-11-17 15:07:53 +00:00
|
|
|
})}
|
|
|
|
/>
|
|
|
|
));
|
2020-12-08 19:37:04 +00:00
|
|
|
|
|
|
|
story.add('Group call - Safety Number Changed', () => (
|
|
|
|
<CallManager
|
|
|
|
{...createProps({
|
|
|
|
activeCall: {
|
|
|
|
...getCommonActiveCallData(),
|
|
|
|
callMode: CallMode.Group,
|
|
|
|
connectionState: GroupCallConnectionState.Connected,
|
|
|
|
conversationsWithSafetyNumberChanges: [
|
|
|
|
{
|
|
|
|
...getDefaultConversation({
|
|
|
|
title: 'Aaron',
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
],
|
|
|
|
deviceCount: 0,
|
|
|
|
joinState: GroupCallJoinState.Joined,
|
|
|
|
maxDevices: 5,
|
2021-08-17 21:45:18 +00:00
|
|
|
groupMembers: [],
|
2020-12-08 19:37:04 +00:00
|
|
|
peekedParticipants: [],
|
|
|
|
remoteParticipants: [],
|
|
|
|
},
|
|
|
|
})}
|
|
|
|
/>
|
|
|
|
));
|