| 
									
										
										
										
											2023-01-03 11:55:46 -08:00
										 |  |  | // Copyright 2020 Signal Messenger, LLC
 | 
					
						
							| 
									
										
										
										
											2020-10-30 15:34:04 -05:00
										 |  |  | // SPDX-License-Identifier: AGPL-3.0-only
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-07 21:25:33 -04:00
										 |  |  | import * as React from 'react'; | 
					
						
							| 
									
										
										
										
											2021-08-17 16:45:18 -05:00
										 |  |  | import { times } from 'lodash'; | 
					
						
							| 
									
										
										
										
											2020-10-07 21:25:33 -04:00
										 |  |  | import { action } from '@storybook/addon-actions'; | 
					
						
							| 
									
										
										
										
											2023-08-10 18:43:33 +02:00
										 |  |  | import { v4 as generateUuid } from 'uuid'; | 
					
						
							| 
									
										
										
										
											2020-10-07 21:25:33 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-11 12:06:43 -07:00
										 |  |  | import type { Meta } from '@storybook/react'; | 
					
						
							| 
									
										
										
										
											2021-05-28 12:15:17 -04:00
										 |  |  | import { AvatarColors } from '../types/Colors'; | 
					
						
							| 
									
										
										
										
											2021-10-26 14:15:33 -05:00
										 |  |  | import type { ConversationType } from '../state/ducks/conversations'; | 
					
						
							|  |  |  | import type { PropsType } from './CallingLobby'; | 
					
						
							| 
									
										
										
										
											2023-10-19 14:59:21 -04:00
										 |  |  | import { CallingLobby as UnwrappedCallingLobby } from './CallingLobby'; | 
					
						
							| 
									
										
										
										
											2021-09-17 20:30:08 -04:00
										 |  |  | import { setupI18n } from '../util/setupI18n'; | 
					
						
							| 
									
										
										
										
											2023-08-10 18:43:33 +02:00
										 |  |  | import { generateAci } from '../types/ServiceId'; | 
					
						
							| 
									
										
										
										
											2020-10-07 21:25:33 -04:00
										 |  |  | import enMessages from '../../_locales/en/messages.json'; | 
					
						
							| 
									
										
										
										
											2021-10-26 15:59:08 -07:00
										 |  |  | import { | 
					
						
							|  |  |  |   getDefaultConversation, | 
					
						
							| 
									
										
										
										
											2023-08-16 22:54:39 +02:00
										 |  |  |   getDefaultConversationWithServiceId, | 
					
						
							| 
									
										
										
										
											2021-10-26 15:59:08 -07:00
										 |  |  | } from '../test-both/helpers/getDefaultConversation'; | 
					
						
							| 
									
										
										
										
											2023-10-19 14:59:21 -04:00
										 |  |  | import { CallingToastProvider } from './CallingToast'; | 
					
						
							| 
									
										
										
										
											2020-10-07 21:25:33 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | const i18n = setupI18n('en', enMessages); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-14 12:30:50 -04:00
										 |  |  | const camera = { | 
					
						
							|  |  |  |   deviceId: 'dfbe6effe70b0611ba0fdc2a9ea3f39f6cb110e6687948f7e5f016c111b7329c', | 
					
						
							|  |  |  |   groupId: '63ee218d2446869e40adfc958ff98263e51f74382b0143328ee4826f20a76f47', | 
					
						
							|  |  |  |   kind: 'videoinput' as MediaDeviceKind, | 
					
						
							|  |  |  |   label: 'FaceTime HD Camera (Built-in) (9fba:bced)', | 
					
						
							|  |  |  |   toJSON() { | 
					
						
							|  |  |  |     return ''; | 
					
						
							|  |  |  |   }, | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-17 16:45:18 -05:00
										 |  |  | const createProps = (overrideProps: Partial<PropsType> = {}): PropsType => { | 
					
						
							| 
									
										
										
										
											2023-10-11 12:06:43 -07:00
										 |  |  |   const isGroupCall = overrideProps.isGroupCall ?? false; | 
					
						
							| 
									
										
										
										
											2021-08-17 16:45:18 -05:00
										 |  |  |   const conversation = isGroupCall | 
					
						
							|  |  |  |     ? getDefaultConversation({ | 
					
						
							|  |  |  |         title: 'Tahoe Trip', | 
					
						
							|  |  |  |         type: 'group', | 
					
						
							|  |  |  |       }) | 
					
						
							|  |  |  |     : getDefaultConversation(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return { | 
					
						
							|  |  |  |     availableCameras: overrideProps.availableCameras || [camera], | 
					
						
							|  |  |  |     conversation, | 
					
						
							| 
									
										
										
										
											2021-08-25 16:42:51 -05:00
										 |  |  |     groupMembers: | 
					
						
							|  |  |  |       overrideProps.groupMembers || | 
					
						
							|  |  |  |       (isGroupCall ? times(3, () => getDefaultConversation()) : undefined), | 
					
						
							| 
									
										
										
										
											2023-10-11 12:06:43 -07:00
										 |  |  |     hasLocalAudio: overrideProps.hasLocalAudio ?? true, | 
					
						
							|  |  |  |     hasLocalVideo: overrideProps.hasLocalVideo ?? false, | 
					
						
							| 
									
										
										
										
											2021-08-17 16:45:18 -05:00
										 |  |  |     i18n, | 
					
						
							|  |  |  |     isGroupCall, | 
					
						
							| 
									
										
										
										
											2022-10-24 13:46:36 -07:00
										 |  |  |     isConversationTooBigToRing: false, | 
					
						
							| 
									
										
										
										
											2023-10-11 12:06:43 -07:00
										 |  |  |     isCallFull: overrideProps.isCallFull ?? false, | 
					
						
							| 
									
										
										
										
											2022-02-23 10:48:40 -08:00
										 |  |  |     me: | 
					
						
							|  |  |  |       overrideProps.me || | 
					
						
							|  |  |  |       getDefaultConversation({ | 
					
						
							|  |  |  |         color: AvatarColors[0], | 
					
						
							| 
									
										
										
										
											2023-08-10 18:43:33 +02:00
										 |  |  |         id: generateUuid(), | 
					
						
							| 
									
										
										
										
											2023-08-16 22:54:39 +02:00
										 |  |  |         serviceId: generateAci(), | 
					
						
							| 
									
										
										
										
											2022-02-23 10:48:40 -08:00
										 |  |  |       }), | 
					
						
							| 
									
										
										
										
											2021-08-17 16:45:18 -05:00
										 |  |  |     onCallCanceled: action('on-call-canceled'), | 
					
						
							|  |  |  |     onJoinCall: action('on-join-call'), | 
					
						
							| 
									
										
										
										
											2023-10-11 12:06:43 -07:00
										 |  |  |     outgoingRing: overrideProps.outgoingRing ?? false, | 
					
						
							| 
									
										
										
										
											2021-08-17 16:45:18 -05:00
										 |  |  |     peekedParticipants: overrideProps.peekedParticipants || [], | 
					
						
							|  |  |  |     setLocalAudio: action('set-local-audio'), | 
					
						
							|  |  |  |     setLocalPreview: action('set-local-preview'), | 
					
						
							|  |  |  |     setLocalVideo: action('set-local-video'), | 
					
						
							| 
									
										
										
										
											2021-08-25 16:42:51 -05:00
										 |  |  |     setOutgoingRing: action('set-outgoing-ring'), | 
					
						
							| 
									
										
										
										
											2023-10-11 12:06:43 -07:00
										 |  |  |     showParticipantsList: overrideProps.showParticipantsList ?? false, | 
					
						
							| 
									
										
										
										
											2021-08-17 16:45:18 -05:00
										 |  |  |     toggleParticipants: action('toggle-participants'), | 
					
						
							|  |  |  |     toggleSettings: action('toggle-settings'), | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  | }; | 
					
						
							| 
									
										
										
										
											2020-10-07 21:25:33 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-19 14:59:21 -04:00
										 |  |  | function CallingLobby(props: ReturnType<typeof createProps>) { | 
					
						
							|  |  |  |   return ( | 
					
						
							|  |  |  |     <CallingToastProvider i18n={i18n}> | 
					
						
							|  |  |  |       <UnwrappedCallingLobby {...props} /> | 
					
						
							|  |  |  |     </CallingToastProvider> | 
					
						
							|  |  |  |   ); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-08 18:35:21 -05:00
										 |  |  | const fakePeekedParticipant = (conversationProps: Partial<ConversationType>) => | 
					
						
							| 
									
										
										
										
											2023-08-16 22:54:39 +02:00
										 |  |  |   getDefaultConversationWithServiceId({ | 
					
						
							| 
									
										
										
										
											2020-12-08 18:35:21 -05:00
										 |  |  |     ...conversationProps, | 
					
						
							| 
									
										
										
										
											2020-12-08 14:37:04 -05:00
										 |  |  |   }); | 
					
						
							| 
									
										
										
										
											2020-12-02 12:14:03 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-06-06 20:48:02 -04:00
										 |  |  | export default { | 
					
						
							|  |  |  |   title: 'Components/CallingLobby', | 
					
						
							| 
									
										
										
										
											2023-10-11 12:06:43 -07:00
										 |  |  |   argTypes: {}, | 
					
						
							|  |  |  |   args: {}, | 
					
						
							|  |  |  | } satisfies Meta<PropsType>; | 
					
						
							| 
									
										
										
										
											2020-10-07 21:25:33 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-17 16:45:19 -08:00
										 |  |  | export function Default(): JSX.Element { | 
					
						
							| 
									
										
										
										
											2020-10-07 21:25:33 -04:00
										 |  |  |   const props = createProps(); | 
					
						
							| 
									
										
										
										
											2020-11-09 12:56:20 -06:00
										 |  |  |   return <CallingLobby {...props} />; | 
					
						
							| 
									
										
										
										
											2022-11-17 16:45:19 -08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2020-11-09 12:56:20 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-17 16:45:19 -08:00
										 |  |  | export function NoCameraNoAvatar(): JSX.Element { | 
					
						
							| 
									
										
										
										
											2020-11-09 12:56:20 -06:00
										 |  |  |   const props = createProps({ | 
					
						
							|  |  |  |     availableCameras: [], | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  |   return <CallingLobby {...props} />; | 
					
						
							| 
									
										
										
										
											2022-11-17 16:45:19 -08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2022-06-06 20:48:02 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-17 16:45:19 -08:00
										 |  |  | export function NoCameraLocalAvatar(): JSX.Element { | 
					
						
							| 
									
										
										
										
											2020-10-14 12:30:50 -04:00
										 |  |  |   const props = createProps({ | 
					
						
							|  |  |  |     availableCameras: [], | 
					
						
							| 
									
										
										
										
											2022-02-23 10:48:40 -08:00
										 |  |  |     me: getDefaultConversation({ | 
					
						
							| 
									
										
										
										
											2020-11-09 12:56:20 -06:00
										 |  |  |       avatarPath: '/fixtures/kitten-4-112-112.jpg', | 
					
						
							| 
									
										
										
										
											2021-05-28 12:15:17 -04:00
										 |  |  |       color: AvatarColors[0], | 
					
						
							| 
									
										
										
										
											2023-08-10 18:43:33 +02:00
										 |  |  |       id: generateUuid(), | 
					
						
							| 
									
										
										
										
											2023-08-16 22:54:39 +02:00
										 |  |  |       serviceId: generateAci(), | 
					
						
							| 
									
										
										
										
											2022-02-23 10:48:40 -08:00
										 |  |  |     }), | 
					
						
							| 
									
										
										
										
											2020-10-14 12:30:50 -04:00
										 |  |  |   }); | 
					
						
							|  |  |  |   return <CallingLobby {...props} />; | 
					
						
							| 
									
										
										
										
											2022-11-17 16:45:19 -08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2022-06-06 20:48:02 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-17 16:45:19 -08:00
										 |  |  | export function LocalVideo(): JSX.Element { | 
					
						
							| 
									
										
										
										
											2020-10-14 12:30:50 -04:00
										 |  |  |   const props = createProps({ | 
					
						
							|  |  |  |     hasLocalVideo: true, | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  |   return <CallingLobby {...props} />; | 
					
						
							| 
									
										
										
										
											2022-11-17 16:45:19 -08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2020-10-14 12:30:50 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-17 16:45:19 -08:00
										 |  |  | export function InitiallyMuted(): JSX.Element { | 
					
						
							| 
									
										
										
										
											2020-10-07 21:25:33 -04:00
										 |  |  |   const props = createProps({ | 
					
						
							| 
									
										
										
										
											2022-01-07 12:01:23 -06:00
										 |  |  |     hasLocalAudio: false, | 
					
						
							| 
									
										
										
										
											2020-10-07 21:25:33 -04:00
										 |  |  |   }); | 
					
						
							|  |  |  |   return <CallingLobby {...props} />; | 
					
						
							| 
									
										
										
										
											2022-11-17 16:45:19 -08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2022-06-06 20:48:02 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-11 12:06:43 -07:00
										 |  |  | export function GroupCallWithNoPeekedParticipants(): JSX.Element { | 
					
						
							| 
									
										
										
										
											2020-12-02 12:14:03 -06:00
										 |  |  |   const props = createProps({ isGroupCall: true, peekedParticipants: [] }); | 
					
						
							| 
									
										
										
										
											2020-11-17 10:07:53 -05:00
										 |  |  |   return <CallingLobby {...props} />; | 
					
						
							| 
									
										
										
										
											2022-11-17 16:45:19 -08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2020-11-17 10:07:53 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-11 12:06:43 -07:00
										 |  |  | export function GroupCallWith1PeekedParticipant(): JSX.Element { | 
					
						
							| 
									
										
										
										
											2020-12-02 12:14:03 -06:00
										 |  |  |   const props = createProps({ | 
					
						
							|  |  |  |     isGroupCall: true, | 
					
						
							| 
									
										
										
										
											2020-12-08 18:35:21 -05:00
										 |  |  |     peekedParticipants: [{ title: 'Sam' }].map(fakePeekedParticipant), | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  |   return <CallingLobby {...props} />; | 
					
						
							| 
									
										
										
										
											2022-11-17 16:45:19 -08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2020-12-08 18:35:21 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-11 12:06:43 -07:00
										 |  |  | export function GroupCallWith1PeekedParticipantSelf(): JSX.Element { | 
					
						
							| 
									
										
										
										
											2023-08-16 22:54:39 +02:00
										 |  |  |   const serviceId = generateAci(); | 
					
						
							| 
									
										
										
										
											2020-12-08 18:35:21 -05:00
										 |  |  |   const props = createProps({ | 
					
						
							|  |  |  |     isGroupCall: true, | 
					
						
							| 
									
										
										
										
											2022-02-23 10:48:40 -08:00
										 |  |  |     me: getDefaultConversation({ | 
					
						
							| 
									
										
										
										
											2023-08-10 18:43:33 +02:00
										 |  |  |       id: generateUuid(), | 
					
						
							| 
									
										
										
										
											2023-08-16 22:54:39 +02:00
										 |  |  |       serviceId, | 
					
						
							| 
									
										
										
										
											2022-02-23 10:48:40 -08:00
										 |  |  |     }), | 
					
						
							| 
									
										
										
										
											2023-08-16 22:54:39 +02:00
										 |  |  |     peekedParticipants: [fakePeekedParticipant({ title: 'Ash', serviceId })], | 
					
						
							| 
									
										
										
										
											2020-12-02 12:14:03 -06:00
										 |  |  |   }); | 
					
						
							| 
									
										
										
										
											2020-11-17 10:07:53 -05:00
										 |  |  |   return <CallingLobby {...props} />; | 
					
						
							| 
									
										
										
										
											2022-11-17 16:45:19 -08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2022-06-06 20:48:02 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-11 12:06:43 -07:00
										 |  |  | export function GroupCallWith4PeekedParticipants(): JSX.Element { | 
					
						
							| 
									
										
										
										
											2020-11-17 10:07:53 -05:00
										 |  |  |   const props = createProps({ | 
					
						
							|  |  |  |     isGroupCall: true, | 
					
						
							| 
									
										
										
										
											2020-12-08 18:35:21 -05:00
										 |  |  |     peekedParticipants: ['Sam', 'Cayce', 'April', 'Logan', 'Carl'].map(title => | 
					
						
							|  |  |  |       fakePeekedParticipant({ title }) | 
					
						
							| 
									
										
										
										
											2020-12-02 12:14:03 -06:00
										 |  |  |     ), | 
					
						
							| 
									
										
										
										
											2020-11-17 10:07:53 -05:00
										 |  |  |   }); | 
					
						
							| 
									
										
										
										
											2020-10-07 21:25:33 -04:00
										 |  |  |   return <CallingLobby {...props} />; | 
					
						
							| 
									
										
										
										
											2022-11-17 16:45:19 -08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2022-06-06 20:48:02 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-11 12:06:43 -07:00
										 |  |  | export function GroupCallWith4PeekedParticipantsParticipantsList(): JSX.Element { | 
					
						
							| 
									
										
										
										
											2020-11-20 14:39:50 -05:00
										 |  |  |   const props = createProps({ | 
					
						
							|  |  |  |     isGroupCall: true, | 
					
						
							| 
									
										
										
										
											2020-12-08 18:35:21 -05:00
										 |  |  |     peekedParticipants: ['Sam', 'Cayce', 'April', 'Logan', 'Carl'].map(title => | 
					
						
							|  |  |  |       fakePeekedParticipant({ title }) | 
					
						
							| 
									
										
										
										
											2020-12-02 12:14:03 -06:00
										 |  |  |     ), | 
					
						
							| 
									
										
										
										
											2020-11-20 14:39:50 -05:00
										 |  |  |     showParticipantsList: true, | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  |   return <CallingLobby {...props} />; | 
					
						
							| 
									
										
										
										
											2022-11-17 16:45:19 -08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2020-12-08 16:28:44 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-11 12:06:43 -07:00
										 |  |  | export function GroupCallWithCallFull(): JSX.Element { | 
					
						
							| 
									
										
										
										
											2020-12-08 16:28:44 -06:00
										 |  |  |   const props = createProps({ | 
					
						
							|  |  |  |     isGroupCall: true, | 
					
						
							|  |  |  |     isCallFull: true, | 
					
						
							| 
									
										
										
										
											2020-12-08 19:48:02 -05:00
										 |  |  |     peekedParticipants: ['Sam', 'Cayce'].map(title => | 
					
						
							|  |  |  |       fakePeekedParticipant({ title }) | 
					
						
							|  |  |  |     ), | 
					
						
							| 
									
										
										
										
											2020-12-08 16:28:44 -06:00
										 |  |  |   }); | 
					
						
							|  |  |  |   return <CallingLobby {...props} />; | 
					
						
							| 
									
										
										
										
											2022-11-17 16:45:19 -08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2022-06-06 20:48:02 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-11 12:06:43 -07:00
										 |  |  | export function GroupCallWith0PeekedParticipantsBigGroup(): JSX.Element { | 
					
						
							| 
									
										
										
										
											2021-08-25 16:42:51 -05:00
										 |  |  |   const props = createProps({ | 
					
						
							|  |  |  |     isGroupCall: true, | 
					
						
							|  |  |  |     groupMembers: times(100, () => getDefaultConversation()), | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  |   return <CallingLobby {...props} />; | 
					
						
							| 
									
										
										
										
											2022-11-17 16:45:19 -08:00
										 |  |  | } |