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

537 lines
16 KiB
TypeScript
Raw Normal View History

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';
import type { Meta } from '@storybook/react';
import type { PropsType } from './CallManager';
import { CallManager } from './CallManager';
2020-11-13 19:57:55 +00:00
import {
CallEndedReason,
CallState,
CallViewMode,
2020-11-13 19:57:55 +00:00
GroupCallConnectionState,
GroupCallJoinState,
} from '../types/Calling';
import { CallMode } from '../types/CallDisposition';
import type {
ActiveGroupCallType,
GroupCallRemoteParticipantType,
} from '../types/Calling';
2023-11-16 19:55:35 +00:00
import type {
ConversationType,
ConversationTypeType,
} from '../state/ducks/conversations';
import { AvatarColors } from '../types/Colors';
import { generateAci } from '../types/ServiceId';
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';
2020-06-04 18:16:19 +00:00
import enMessages from '../../_locales/en/messages.json';
import { StorySendMode } from '../types/Stories';
import {
FAKE_CALL_LINK,
FAKE_CALL_LINK_WITH_ADMIN_KEY,
getDefaultCallLinkConversation,
} from '../test-both/helpers/fakeCallLink';
import { allRemoteParticipants } from './CallScreen.stories';
import { getPlaceholderContact } from '../state/selectors/conversations';
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',
2024-07-11 19:44:09 +00:00
avatarUrl: undefined,
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
const getUnknownContact = (): ConversationType => ({
...getPlaceholderContact(),
serviceId: generateAci(),
});
const getUnknownParticipant = (): GroupCallRemoteParticipantType => ({
...getPlaceholderContact(),
serviceId: generateAci(),
aci: generateAci(),
demuxId: Math.round(10000 * Math.random()),
hasRemoteAudio: true,
hasRemoteVideo: true,
isHandRaised: false,
mediaKeysReceived: false,
presenting: false,
sharingScreen: false,
videoAspectRatio: 1,
});
2020-12-02 18:14:03 +00:00
const getCommonActiveCallData = () => ({
conversation: getConversation(),
2020-11-17 15:07:53 +00:00
joinedAt: Date.now(),
hasLocalAudio: true,
hasLocalVideo: false,
localAudioLevel: 0,
viewMode: CallViewMode.Paginated,
outgoingRing: true,
pip: false,
settingsDialogOpen: false,
showParticipantsList: false,
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'),
approveUser: action('approve-user'),
batchUserAction: action('batch-user-action'),
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'),
changeCallView: action('change-call-view'),
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'),
denyUser: action('deny-user'),
2021-01-08 18:58:28 +00:00
getGroupCallVideoFrameSource: (_: string, demuxId: number) =>
fakeGetGroupCallVideoFrameSource(demuxId),
getIsSharingPhoneNumberWithEverybody: () => false,
getPresentingSources: action('get-presenting-sources'),
hangUpActiveCall: action('hang-up-active-call'),
hasInitialLoadCompleted: true,
2020-06-04 18:16:19 +00:00
i18n,
ringingCall: null,
callLink: storyProps.callLink ?? undefined,
me: {
...getDefaultConversation({
color: AvatarColors[0],
title: 'Morty Smith',
}),
2023-08-16 20:54:39 +00:00
serviceId: generateAci(),
},
2021-08-20 16:06:15 +00:00
notifyForCall: action('notify-for-call'),
openSystemPreferencesAction: action('open-system-preferences-action'),
2021-08-20 16:06:15 +00:00
playRingtone: action('play-ringtone'),
removeClient: action('remove-client'),
2024-06-29 00:13:20 +00:00
blockClient: action('block-client'),
2024-09-20 01:03:44 +00:00
cancelPresenting: action('cancel-presenting'),
2020-08-27 00:03:42 +00:00
renderDeviceSelection: () => <div />,
2023-11-16 19:55:35 +00:00
renderEmojiPicker: () => <>EmojiPicker</>,
renderReactionPicker: () => <div />,
2023-12-06 21:52:29 +00:00
sendGroupCallRaiseHand: action('send-group-call-raise-hand'),
2023-11-16 19:55:35 +00:00
sendGroupCallReaction: action('send-group-call-reaction'),
2024-09-20 01:03:44 +00:00
selectPresentingSource: action('select-presenting-source'),
setGroupCallVideoRequest: action('set-group-call-video-request'),
setIsCallActive: action('set-is-call-active'),
2020-06-04 18:16:19 +00:00
setLocalAudio: action('set-local-audio'),
setLocalPreviewContainer: action('set-local-preview-container'),
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'),
setOutgoingRing: action('set-outgoing-ring'),
showContactModal: action('show-contact-modal'),
showShareCallLinkViaSignal: action('show-share-call-link-via-signal'),
2020-10-08 01:25:33 +00:00
startCall: action('start-call'),
2021-08-20 16:06:15 +00:00
stopRingtone: action('stop-ringtone'),
switchToPresentationView: action('switch-to-presentation-view'),
switchFromPresentationView: action('switch-from-presentation-view'),
toggleCallLinkPendingParticipantModal: action(
'toggle-call-link-pending-participant-modal'
),
2020-10-08 01:25:33 +00:00
toggleParticipants: action('toggle-participants'),
2020-10-01 00:43:05 +00:00
togglePip: action('toggle-pip'),
toggleScreenRecordingPermissionsDialog: action(
'toggle-screen-recording-permissions-dialog'
),
2020-08-27 00:03:42 +00:00
toggleSettings: action('toggle-settings'),
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
const getActiveCallForCallLink = (
overrideProps: Partial<ActiveGroupCallType> = {}
): ActiveGroupCallType => {
return {
conversation: getDefaultCallLinkConversation(),
joinedAt: Date.now(),
hasLocalAudio: true,
hasLocalVideo: true,
localAudioLevel: 0,
viewMode: CallViewMode.Paginated,
outgoingRing: false,
pip: false,
settingsDialogOpen: false,
showParticipantsList: overrideProps.showParticipantsList ?? true,
callMode: CallMode.Adhoc,
connectionState:
overrideProps.connectionState ?? GroupCallConnectionState.NotConnected,
conversationsByDemuxId: new Map<number, ConversationType>(),
deviceCount: 0,
joinState: overrideProps.joinState ?? GroupCallJoinState.NotJoined,
localDemuxId: 1,
maxDevices: 5,
groupMembers: [],
isConversationTooBigToRing: false,
peekedParticipants:
overrideProps.peekedParticipants ?? allRemoteParticipants.slice(0, 3),
remoteParticipants: overrideProps.remoteParticipants ?? [],
pendingParticipants: overrideProps.pendingParticipants ?? [],
raisedHands: new Set<number>(),
remoteAudioLevels: new Map<number, number>(),
};
};
2022-06-07 00:48:02 +00:00
export default {
title: 'Components/CallManager',
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,
2023-11-16 19:55:35 +00:00
conversationsByDemuxId: new Map<number, ConversationType>(),
2022-11-18 00:45:19 +00:00
deviceCount: 0,
joinState: GroupCallJoinState.Joined,
2023-11-16 19:55:35 +00:00
localDemuxId: 1,
2022-11-18 00:45:19 +00:00
maxDevices: 5,
groupMembers: [],
isConversationTooBigToRing: false,
peekedParticipants: [],
pendingParticipants: [],
2023-12-06 21:52:29 +00:00
raisedHands: new Set<number>(),
2022-11-18 00:45:19 +00:00
remoteParticipants: [],
remoteAudioLevels: new Map<number, number>(),
},
})}
/>
);
}
export function RingingDirectCall(): JSX.Element {
return (
<CallManager
{...createProps({
ringingCall: {
2022-11-18 00:45:19 +00:00
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({
ringingCall: {
2022-11-18 00:45:19 +00:00
callMode: CallMode.Group as const,
connectionState: GroupCallConnectionState.NotConnected,
joinState: GroupCallJoinState.NotJoined,
2022-11-18 00:45:19 +00:00
conversation: {
...getConversation(),
type: 'group',
title: 'Tahoe Trip',
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' },
remoteParticipants: [],
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 CallLinkLobbyParticipantsKnown(): JSX.Element {
return (
<CallManager
{...createProps({
activeCall: getActiveCallForCallLink(),
callLink: FAKE_CALL_LINK,
})}
/>
);
}
export function CallLinkLobbyParticipants1Unknown(): JSX.Element {
return (
<CallManager
{...createProps({
activeCall: getActiveCallForCallLink({
peekedParticipants: [getPlaceholderContact()],
}),
callLink: FAKE_CALL_LINK,
})}
/>
);
}
export function CallLinkLobbyParticipants1Known1Unknown(): JSX.Element {
return (
<CallManager
{...createProps({
activeCall: getActiveCallForCallLink({
peekedParticipants: [allRemoteParticipants[0], getUnknownContact()],
}),
callLink: FAKE_CALL_LINK,
})}
/>
);
}
export function CallLinkLobbyParticipants1Known2Unknown(): JSX.Element {
return (
<CallManager
{...createProps({
activeCall: getActiveCallForCallLink({
peekedParticipants: [
getUnknownContact(),
allRemoteParticipants[0],
getUnknownContact(),
],
}),
callLink: FAKE_CALL_LINK,
})}
/>
);
}
export function CallLinkLobbyParticipants1Known12Unknown(): JSX.Element {
const peekedParticipants: Array<ConversationType> = [
allRemoteParticipants[0],
];
for (let n = 12; n > 0; n -= 1) {
peekedParticipants.push(getUnknownContact());
}
return (
<CallManager
{...createProps({
activeCall: getActiveCallForCallLink({
peekedParticipants,
}),
callLink: FAKE_CALL_LINK,
})}
/>
);
}
export function CallLinkLobbyParticipants3Unknown(): JSX.Element {
return (
<CallManager
{...createProps({
activeCall: getActiveCallForCallLink({
peekedParticipants: [
getUnknownContact(),
getUnknownContact(),
getUnknownContact(),
],
}),
callLink: FAKE_CALL_LINK,
})}
/>
);
}
export function CallLinkWithJoinRequestsOne(): JSX.Element {
return (
<CallManager
{...createProps({
activeCall: getActiveCallForCallLink({
connectionState: GroupCallConnectionState.Connected,
joinState: GroupCallJoinState.Joined,
peekedParticipants: [allRemoteParticipants[0]],
pendingParticipants: [allRemoteParticipants[1]],
showParticipantsList: false,
}),
callLink: FAKE_CALL_LINK_WITH_ADMIN_KEY,
})}
/>
);
}
export function CallLinkWithJoinRequestsTwo(): JSX.Element {
return (
<CallManager
{...createProps({
activeCall: getActiveCallForCallLink({
connectionState: GroupCallConnectionState.Connected,
joinState: GroupCallJoinState.Joined,
peekedParticipants: [allRemoteParticipants[0]],
pendingParticipants: allRemoteParticipants.slice(1, 3),
showParticipantsList: false,
}),
callLink: FAKE_CALL_LINK_WITH_ADMIN_KEY,
})}
/>
);
}
export function CallLinkWithJoinRequestsMany(): JSX.Element {
return (
<CallManager
{...createProps({
activeCall: getActiveCallForCallLink({
connectionState: GroupCallConnectionState.Connected,
joinState: GroupCallJoinState.Joined,
peekedParticipants: [allRemoteParticipants[0]],
pendingParticipants: allRemoteParticipants.slice(1, 11),
showParticipantsList: false,
}),
callLink: FAKE_CALL_LINK_WITH_ADMIN_KEY,
})}
/>
);
}
export function CallLinkWithJoinRequestUnknownContact(): JSX.Element {
return (
<CallManager
{...createProps({
activeCall: getActiveCallForCallLink({
connectionState: GroupCallConnectionState.Connected,
joinState: GroupCallJoinState.Joined,
peekedParticipants: [allRemoteParticipants[0]],
pendingParticipants: [
getUnknownContact(),
allRemoteParticipants[1],
allRemoteParticipants[2],
],
showParticipantsList: false,
}),
callLink: FAKE_CALL_LINK_WITH_ADMIN_KEY,
})}
/>
);
}
export function CallLinkWithJoinRequestsSystemContact(): JSX.Element {
return (
<CallManager
{...createProps({
activeCall: getActiveCallForCallLink({
connectionState: GroupCallConnectionState.Connected,
joinState: GroupCallJoinState.Joined,
peekedParticipants: [allRemoteParticipants[0]],
pendingParticipants: [
{ ...allRemoteParticipants[1], name: 'My System Contact Friend' },
],
showParticipantsList: false,
}),
callLink: FAKE_CALL_LINK_WITH_ADMIN_KEY,
})}
/>
);
}
export function CallLinkWithJoinRequestsSystemContactMany(): JSX.Element {
return (
<CallManager
{...createProps({
activeCall: getActiveCallForCallLink({
connectionState: GroupCallConnectionState.Connected,
joinState: GroupCallJoinState.Joined,
peekedParticipants: [allRemoteParticipants[0]],
pendingParticipants: [
{ ...allRemoteParticipants[1], name: 'My System Contact Friend' },
allRemoteParticipants[2],
allRemoteParticipants[3],
],
showParticipantsList: false,
}),
callLink: FAKE_CALL_LINK_WITH_ADMIN_KEY,
})}
/>
);
}
export function CallLinkWithJoinRequestsParticipantsOpen(): JSX.Element {
return (
<CallManager
{...createProps({
activeCall: getActiveCallForCallLink({
connectionState: GroupCallConnectionState.Connected,
joinState: GroupCallJoinState.Joined,
peekedParticipants: [allRemoteParticipants[0]],
pendingParticipants: allRemoteParticipants.slice(1, 4),
}),
callLink: FAKE_CALL_LINK_WITH_ADMIN_KEY,
})}
/>
);
}
export function CallLinkWithUnknownContacts(): JSX.Element {
return (
<CallManager
{...createProps({
activeCall: getActiveCallForCallLink({
connectionState: GroupCallConnectionState.Connected,
joinState: GroupCallJoinState.Joined,
remoteParticipants: [
allRemoteParticipants[0],
getUnknownParticipant(),
getUnknownParticipant(),
],
}),
callLink: FAKE_CALL_LINK_WITH_ADMIN_KEY,
})}
/>
);
}