2023-01-03 19:55:46 +00:00
|
|
|
// Copyright 2020 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 { action } from '@storybook/addon-actions';
|
2023-10-11 19:06:43 +00:00
|
|
|
import type { Meta } from '@storybook/react';
|
2021-10-26 19:15:33 +00:00
|
|
|
import type { PropsType } from './CallManager';
|
|
|
|
import { CallManager } from './CallManager';
|
2020-11-13 19:57:55 +00:00
|
|
|
import {
|
|
|
|
CallEndedReason,
|
|
|
|
CallMode,
|
|
|
|
CallState,
|
2022-05-25 18:03:27 +00:00
|
|
|
CallViewMode,
|
2020-11-13 19:57:55 +00:00
|
|
|
GroupCallConnectionState,
|
|
|
|
GroupCallJoinState,
|
|
|
|
} from '../types/Calling';
|
2021-10-26 19:15:33 +00:00
|
|
|
import type { ConversationTypeType } from '../state/ducks/conversations';
|
|
|
|
import { AvatarColors } from '../types/Colors';
|
2023-08-10 16:43:33 +00:00
|
|
|
import { generateAci } from '../types/ServiceId';
|
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';
|
2021-09-18 00:30:08 +00:00
|
|
|
import { setupI18n } from '../util/setupI18n';
|
2022-03-02 18:24:28 +00:00
|
|
|
import type { SafetyNumberProps } from './SafetyNumberChangeDialog';
|
2020-06-04 18:16:19 +00:00
|
|
|
import enMessages from '../../_locales/en/messages.json';
|
2021-11-17 21:58:34 +00:00
|
|
|
import { ThemeType } from '../types/Util';
|
2022-11-19 08:31:18 +00:00
|
|
|
import { StorySendMode } from '../types/Stories';
|
2020-06-04 18:16:19 +00:00
|
|
|
|
|
|
|
const i18n = setupI18n('en', enMessages);
|
|
|
|
|
2021-05-07 22:21:10 +00:00
|
|
|
const getConversation = () =>
|
|
|
|
getDefaultConversation({
|
|
|
|
id: '3051234567',
|
|
|
|
avatarPath: undefined,
|
2023-10-11 19:06:43 +00:00
|
|
|
color: AvatarColors[0],
|
|
|
|
title: 'Rick Sanchez',
|
|
|
|
name: 'Rick Sanchez',
|
2021-05-07 22:21:10 +00:00
|
|
|
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(),
|
2023-10-11 19:06:43 +00:00
|
|
|
hasLocalAudio: true,
|
|
|
|
hasLocalVideo: false,
|
|
|
|
localAudioLevel: 0,
|
|
|
|
viewMode: CallViewMode.Grid,
|
|
|
|
outgoingRing: true,
|
|
|
|
pip: false,
|
|
|
|
settingsDialogOpen: false,
|
|
|
|
showParticipantsList: false,
|
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'),
|
2021-08-20 16:06:15 +00:00
|
|
|
bounceAppIconStart: action('bounce-app-icon-start'),
|
|
|
|
bounceAppIconStop: action('bounce-app-icon-stop'),
|
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-11-17 21:58:34 +00:00
|
|
|
getPreferredBadge: () => undefined,
|
2021-05-20 21:54:03 +00:00
|
|
|
getPresentingSources: action('get-presenting-sources'),
|
2022-02-08 19:18:51 +00:00
|
|
|
hangUpActiveCall: action('hang-up-active-call'),
|
2020-06-04 18:16:19 +00:00
|
|
|
i18n,
|
2021-08-25 21:42:51 +00:00
|
|
|
isGroupCallOutboundRingEnabled: true,
|
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({
|
2023-10-11 19:06:43 +00:00
|
|
|
color: AvatarColors[0],
|
|
|
|
title: 'Morty Smith',
|
2020-12-08 19:37:04 +00:00
|
|
|
}),
|
2023-08-16 20:54:39 +00:00
|
|
|
serviceId: generateAci(),
|
2020-11-04 19:56:03 +00:00
|
|
|
},
|
2021-08-20 16:06:15 +00:00
|
|
|
notifyForCall: action('notify-for-call'),
|
2021-05-20 21:54:03 +00:00
|
|
|
openSystemPreferencesAction: action('open-system-preferences-action'),
|
2021-08-20 16:06:15 +00:00
|
|
|
playRingtone: action('play-ringtone'),
|
2020-08-27 00:03:42 +00:00
|
|
|
renderDeviceSelection: () => <div />,
|
2022-03-02 18:24:28 +00:00
|
|
|
renderSafetyNumberViewer: (_: SafetyNumberProps) => <div />,
|
2020-12-02 01:52:01 +00:00
|
|
|
setGroupCallVideoRequest: action('set-group-call-video-request'),
|
2021-09-28 19:00:22 +00:00
|
|
|
setIsCallActive: action('set-is-call-active'),
|
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'),
|
2021-08-25 21:42:51 +00:00
|
|
|
setOutgoingRing: action('set-outgoing-ring'),
|
2020-10-08 01:25:33 +00:00
|
|
|
startCall: action('start-call'),
|
2021-08-20 16:06:15 +00:00
|
|
|
stopRingtone: action('stop-ringtone'),
|
2022-05-25 18:03:27 +00:00
|
|
|
switchToPresentationView: action('switch-to-presentation-view'),
|
|
|
|
switchFromPresentationView: action('switch-from-presentation-view'),
|
2021-11-17 21:58:34 +00:00
|
|
|
theme: ThemeType.light,
|
2020-10-08 01:25:33 +00:00
|
|
|
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'),
|
2022-12-20 02:10:51 +00:00
|
|
|
isConversationTooBigToRing: false,
|
2023-02-24 23:18:57 +00:00
|
|
|
pauseVoiceNotePlayer: action('pause-audio-player'),
|
2020-11-17 15:07:53 +00:00
|
|
|
});
|
2020-06-04 18:16:19 +00:00
|
|
|
|
2022-06-07 00:48:02 +00:00
|
|
|
export default {
|
|
|
|
title: 'Components/CallManager',
|
2023-10-11 19:06:43 +00:00
|
|
|
argTypes: {},
|
|
|
|
args: {},
|
|
|
|
} satisfies Meta<PropsType>;
|
2020-11-17 15:07:53 +00:00
|
|
|
|
2022-11-18 00:45:19 +00:00
|
|
|
export function NoCall(): JSX.Element {
|
|
|
|
return <CallManager {...createProps()} />;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function OngoingDirectCall(): JSX.Element {
|
|
|
|
return (
|
|
|
|
<CallManager
|
|
|
|
{...createProps({
|
|
|
|
activeCall: {
|
|
|
|
...getCommonActiveCallData(),
|
|
|
|
callMode: CallMode.Direct,
|
|
|
|
callState: CallState.Accepted,
|
|
|
|
peekedParticipants: [],
|
|
|
|
remoteParticipants: [
|
|
|
|
{ hasRemoteVideo: true, presenting: false, title: 'Remy' },
|
|
|
|
],
|
|
|
|
},
|
|
|
|
})}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export function OngoingGroupCall(): JSX.Element {
|
|
|
|
return (
|
|
|
|
<CallManager
|
|
|
|
{...createProps({
|
|
|
|
activeCall: {
|
|
|
|
...getCommonActiveCallData(),
|
|
|
|
callMode: CallMode.Group,
|
|
|
|
connectionState: GroupCallConnectionState.Connected,
|
|
|
|
conversationsWithSafetyNumberChanges: [],
|
|
|
|
deviceCount: 0,
|
|
|
|
joinState: GroupCallJoinState.Joined,
|
|
|
|
maxDevices: 5,
|
|
|
|
groupMembers: [],
|
|
|
|
isConversationTooBigToRing: false,
|
|
|
|
peekedParticipants: [],
|
|
|
|
remoteParticipants: [],
|
|
|
|
remoteAudioLevels: new Map<number, number>(),
|
|
|
|
},
|
|
|
|
})}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export function RingingDirectCall(): JSX.Element {
|
|
|
|
return (
|
|
|
|
<CallManager
|
|
|
|
{...createProps({
|
|
|
|
incomingCall: {
|
|
|
|
callMode: CallMode.Direct as const,
|
|
|
|
conversation: getConversation(),
|
|
|
|
isVideoCall: true,
|
|
|
|
},
|
|
|
|
})}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
2021-08-20 16:06:15 +00:00
|
|
|
|
2022-11-18 00:45:19 +00:00
|
|
|
export function RingingGroupCall(): JSX.Element {
|
|
|
|
return (
|
|
|
|
<CallManager
|
|
|
|
{...createProps({
|
|
|
|
incomingCall: {
|
|
|
|
callMode: CallMode.Group as const,
|
|
|
|
conversation: {
|
|
|
|
...getConversation(),
|
|
|
|
type: 'group',
|
|
|
|
title: 'Tahoe Trip',
|
2022-11-19 08:31:18 +00:00
|
|
|
acknowledgedGroupNameCollisions: {},
|
|
|
|
storySendMode: StorySendMode.IfActive,
|
2022-11-18 00:45:19 +00:00
|
|
|
},
|
|
|
|
otherMembersRung: [
|
|
|
|
{ firstName: 'Morty', title: 'Morty Smith' },
|
|
|
|
{ firstName: 'Summer', title: 'Summer Smith' },
|
|
|
|
],
|
|
|
|
ringer: { firstName: 'Rick', title: 'Rick Sanchez' },
|
2021-08-20 16:06:15 +00:00
|
|
|
},
|
2022-11-18 00:45:19 +00:00
|
|
|
})}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
2022-06-07 00:48:02 +00:00
|
|
|
|
2022-11-18 00:45:19 +00:00
|
|
|
export function CallRequestNeeded(): JSX.Element {
|
|
|
|
return (
|
|
|
|
<CallManager
|
|
|
|
{...createProps({
|
|
|
|
activeCall: {
|
|
|
|
...getCommonActiveCallData(),
|
|
|
|
callEndedReason: CallEndedReason.RemoteHangupNeedPermission,
|
|
|
|
callMode: CallMode.Direct,
|
|
|
|
callState: CallState.Accepted,
|
|
|
|
peekedParticipants: [],
|
|
|
|
remoteParticipants: [
|
|
|
|
{ hasRemoteVideo: true, presenting: false, title: 'Mike' },
|
|
|
|
],
|
|
|
|
},
|
|
|
|
})}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export function GroupCallSafetyNumberChanged(): JSX.Element {
|
|
|
|
return (
|
|
|
|
<CallManager
|
|
|
|
{...createProps({
|
|
|
|
activeCall: {
|
|
|
|
...getCommonActiveCallData(),
|
|
|
|
callMode: CallMode.Group,
|
|
|
|
connectionState: GroupCallConnectionState.Connected,
|
|
|
|
conversationsWithSafetyNumberChanges: [
|
|
|
|
{
|
|
|
|
...getDefaultConversation({
|
|
|
|
title: 'Aaron',
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
],
|
|
|
|
deviceCount: 0,
|
|
|
|
joinState: GroupCallJoinState.Joined,
|
|
|
|
maxDevices: 5,
|
|
|
|
groupMembers: [],
|
|
|
|
isConversationTooBigToRing: false,
|
|
|
|
peekedParticipants: [],
|
|
|
|
remoteParticipants: [],
|
|
|
|
remoteAudioLevels: new Map<number, number>(),
|
|
|
|
},
|
|
|
|
})}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|