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 { boolean, select } from '@storybook/addon-knobs';
|
|
|
|
import { action } from '@storybook/addon-actions';
|
|
|
|
|
2020-11-19 18:13:36 +00:00
|
|
|
import {
|
|
|
|
CallMode,
|
|
|
|
CallState,
|
|
|
|
GroupCallRemoteParticipantType,
|
|
|
|
} from '../types/Calling';
|
2020-11-17 15:07:53 +00:00
|
|
|
import { Colors } from '../types/Colors';
|
|
|
|
import {
|
|
|
|
DirectCallStateType,
|
|
|
|
GroupCallStateType,
|
|
|
|
} from '../state/ducks/calling';
|
2020-10-08 01:25:33 +00:00
|
|
|
import { CallScreen, PropsType } from './CallScreen';
|
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-19 18:13:36 +00:00
|
|
|
function getGroupCallState(): GroupCallStateType {
|
2020-11-17 15:07:53 +00:00
|
|
|
return {
|
|
|
|
callMode: CallMode.Group,
|
|
|
|
conversationId: '3051234567',
|
|
|
|
connectionState: 2,
|
|
|
|
joinState: 2,
|
2020-11-19 18:13:36 +00:00
|
|
|
remoteParticipants: [],
|
2020-11-17 15:07:53 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function getDirectCallState(
|
2020-11-13 19:57:55 +00:00
|
|
|
overrideProps: {
|
|
|
|
callState?: CallState;
|
|
|
|
hasRemoteVideo?: boolean;
|
|
|
|
} = {}
|
2020-11-17 15:07:53 +00:00
|
|
|
): DirectCallStateType {
|
|
|
|
return {
|
|
|
|
callMode: CallMode.Direct,
|
2020-11-13 19:57:55 +00:00
|
|
|
conversationId: '3051234567',
|
|
|
|
callState: select(
|
|
|
|
'callState',
|
|
|
|
CallState,
|
|
|
|
overrideProps.callState || CallState.Accepted
|
|
|
|
),
|
|
|
|
hasRemoteVideo: boolean(
|
|
|
|
'hasRemoteVideo',
|
2020-11-17 15:07:53 +00:00
|
|
|
Boolean(overrideProps.hasRemoteVideo)
|
2020-11-13 19:57:55 +00:00
|
|
|
),
|
2020-11-17 15:07:53 +00:00
|
|
|
isIncoming: false,
|
|
|
|
isVideoCall: true,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
const createProps = (
|
|
|
|
overrideProps: {
|
|
|
|
callState?: CallState;
|
|
|
|
callTypeState?: DirectCallStateType | GroupCallStateType;
|
2020-11-19 18:13:36 +00:00
|
|
|
groupCallParticipants?: Array<GroupCallRemoteParticipantType>;
|
2020-11-17 15:07:53 +00:00
|
|
|
hasLocalAudio?: boolean;
|
|
|
|
hasLocalVideo?: boolean;
|
|
|
|
hasRemoteVideo?: boolean;
|
|
|
|
} = {}
|
|
|
|
): PropsType => ({
|
2020-11-19 18:13:36 +00:00
|
|
|
activeCall: {
|
|
|
|
activeCallState: {
|
|
|
|
conversationId: '123',
|
|
|
|
hasLocalAudio: true,
|
|
|
|
hasLocalVideo: true,
|
|
|
|
pip: false,
|
|
|
|
settingsDialogOpen: false,
|
|
|
|
showParticipantsList: true,
|
|
|
|
},
|
|
|
|
call: overrideProps.callTypeState || getDirectCallState(overrideProps),
|
|
|
|
conversation: {
|
|
|
|
id: '3051234567',
|
|
|
|
avatarPath: undefined,
|
|
|
|
color: Colors[0],
|
|
|
|
title: 'Rick Sanchez',
|
|
|
|
name: 'Rick Sanchez',
|
|
|
|
phoneNumber: '3051234567',
|
|
|
|
profileName: 'Rick Sanchez',
|
|
|
|
markedUnread: false,
|
|
|
|
type: 'direct',
|
|
|
|
lastUpdated: Date.now(),
|
|
|
|
},
|
|
|
|
groupCallParticipants: overrideProps.groupCallParticipants || [],
|
2020-11-06 17:36:37 +00:00
|
|
|
},
|
2020-11-17 19:49:48 +00:00
|
|
|
// We allow `any` here because this is fake and actually comes from RingRTC, which we
|
2020-11-13 19:57:55 +00:00
|
|
|
// can't import.
|
2020-11-17 19:49:48 +00:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
2020-11-13 19:57:55 +00:00
|
|
|
getGroupCallVideoFrameSource: noop as any,
|
2020-06-04 18:16:19 +00:00
|
|
|
hangUp: action('hang-up'),
|
2020-10-08 01:25:33 +00:00
|
|
|
hasLocalAudio: boolean('hasLocalAudio', overrideProps.hasLocalAudio || false),
|
|
|
|
hasLocalVideo: boolean('hasLocalVideo', overrideProps.hasLocalVideo || false),
|
2020-06-04 18:16:19 +00:00
|
|
|
i18n,
|
2020-11-06 17:36:37 +00:00
|
|
|
joinedAt: Date.now(),
|
2020-11-04 19:56:03 +00:00
|
|
|
me: {
|
2020-11-17 15:07:53 +00:00
|
|
|
color: Colors[1],
|
2020-11-04 19:56:03 +00:00
|
|
|
name: 'Morty Smith',
|
|
|
|
profileName: 'Morty Smith',
|
|
|
|
title: 'Morty Smith',
|
|
|
|
},
|
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-11-17 15:07:53 +00:00
|
|
|
stickyControls: boolean('stickyControls', false),
|
|
|
|
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-10-08 01:25:33 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
const story = storiesOf('Components/CallScreen', module);
|
|
|
|
|
|
|
|
story.add('Default', () => {
|
|
|
|
return <CallScreen {...createProps()} />;
|
|
|
|
});
|
|
|
|
|
|
|
|
story.add('Pre-Ring', () => {
|
2020-11-17 15:07:53 +00:00
|
|
|
return (
|
|
|
|
<CallScreen
|
|
|
|
{...createProps({
|
|
|
|
callState: CallState.Prering,
|
|
|
|
})}
|
|
|
|
/>
|
|
|
|
);
|
2020-10-08 01:25:33 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
story.add('Ringing', () => {
|
2020-11-17 15:07:53 +00:00
|
|
|
return (
|
|
|
|
<CallScreen
|
|
|
|
{...createProps({
|
|
|
|
callState: CallState.Ringing,
|
|
|
|
})}
|
|
|
|
/>
|
|
|
|
);
|
2020-10-08 01:25:33 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
story.add('Reconnecting', () => {
|
2020-11-17 15:07:53 +00:00
|
|
|
return (
|
|
|
|
<CallScreen
|
|
|
|
{...createProps({
|
|
|
|
callState: CallState.Reconnecting,
|
|
|
|
})}
|
|
|
|
/>
|
|
|
|
);
|
2020-10-08 01:25:33 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
story.add('Ended', () => {
|
2020-11-17 15:07:53 +00:00
|
|
|
return (
|
|
|
|
<CallScreen
|
|
|
|
{...createProps({
|
|
|
|
callState: CallState.Ended,
|
|
|
|
})}
|
|
|
|
/>
|
|
|
|
);
|
2020-10-08 01:25:33 +00:00
|
|
|
});
|
2020-06-04 18:16:19 +00:00
|
|
|
|
2020-10-08 01:25:33 +00:00
|
|
|
story.add('hasLocalAudio', () => {
|
|
|
|
return <CallScreen {...createProps({ hasLocalAudio: true })} />;
|
|
|
|
});
|
2020-06-04 18:16:19 +00:00
|
|
|
|
2020-10-08 01:25:33 +00:00
|
|
|
story.add('hasLocalVideo', () => {
|
|
|
|
return <CallScreen {...createProps({ hasLocalVideo: true })} />;
|
|
|
|
});
|
2020-06-04 18:16:19 +00:00
|
|
|
|
2020-10-08 01:25:33 +00:00
|
|
|
story.add('hasRemoteVideo', () => {
|
|
|
|
return <CallScreen {...createProps({ hasRemoteVideo: true })} />;
|
|
|
|
});
|
2020-11-17 15:07:53 +00:00
|
|
|
|
|
|
|
story.add('Group call - 1', () => (
|
|
|
|
<CallScreen
|
|
|
|
{...createProps({
|
2020-11-19 18:13:36 +00:00
|
|
|
callTypeState: getGroupCallState(),
|
|
|
|
groupCallParticipants: [
|
2020-11-17 15:07:53 +00:00
|
|
|
{
|
|
|
|
demuxId: 0,
|
|
|
|
hasRemoteAudio: true,
|
|
|
|
hasRemoteVideo: true,
|
|
|
|
isSelf: false,
|
2020-11-19 18:13:36 +00:00
|
|
|
title: 'Tyler',
|
2020-11-17 15:07:53 +00:00
|
|
|
videoAspectRatio: 1.3,
|
|
|
|
},
|
2020-11-19 18:13:36 +00:00
|
|
|
],
|
2020-11-17 15:07:53 +00:00
|
|
|
})}
|
|
|
|
/>
|
|
|
|
));
|
|
|
|
|
|
|
|
story.add('Group call - Many', () => (
|
|
|
|
<CallScreen
|
|
|
|
{...createProps({
|
2020-11-19 18:13:36 +00:00
|
|
|
callTypeState: getGroupCallState(),
|
|
|
|
groupCallParticipants: [
|
2020-11-17 15:07:53 +00:00
|
|
|
{
|
|
|
|
demuxId: 0,
|
|
|
|
hasRemoteAudio: true,
|
|
|
|
hasRemoteVideo: true,
|
|
|
|
isSelf: false,
|
2020-11-19 18:13:36 +00:00
|
|
|
title: 'Amy',
|
2020-11-17 15:07:53 +00:00
|
|
|
videoAspectRatio: 1.3,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
demuxId: 1,
|
|
|
|
hasRemoteAudio: true,
|
|
|
|
hasRemoteVideo: true,
|
|
|
|
isSelf: true,
|
2020-11-19 18:13:36 +00:00
|
|
|
title: 'Bob',
|
2020-11-17 15:07:53 +00:00
|
|
|
videoAspectRatio: 1.3,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
demuxId: 2,
|
|
|
|
hasRemoteAudio: true,
|
|
|
|
hasRemoteVideo: true,
|
|
|
|
isSelf: false,
|
2020-11-19 18:13:36 +00:00
|
|
|
title: 'Alice',
|
2020-11-17 15:07:53 +00:00
|
|
|
videoAspectRatio: 1.3,
|
|
|
|
},
|
2020-11-19 18:13:36 +00:00
|
|
|
],
|
2020-11-17 15:07:53 +00:00
|
|
|
})}
|
|
|
|
/>
|
|
|
|
));
|