| 
									
										
										
										
											2023-01-03 11:55:46 -08:00
										 |  |  | // Copyright 2021 Signal Messenger, LLC
 | 
					
						
							| 
									
										
										
										
											2021-01-08 12:58:28 -06:00
										 |  |  | // SPDX-License-Identifier: AGPL-3.0-only
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-26 14:15:33 -05:00
										 |  |  | import React from 'react'; | 
					
						
							| 
									
										
										
										
											2021-01-08 12:58:28 -06:00
										 |  |  | import { memoize, times } from 'lodash'; | 
					
						
							| 
									
										
										
										
											2021-12-06 17:06:13 -06:00
										 |  |  | import { action } from '@storybook/addon-actions'; | 
					
						
							| 
									
										
										
										
											2023-10-11 12:06:43 -07:00
										 |  |  | import type { Meta } from '@storybook/react'; | 
					
						
							|  |  |  | import type { PropsType } from './GroupCallOverflowArea'; | 
					
						
							| 
									
										
										
										
											2021-01-08 12:58:28 -06:00
										 |  |  | import { GroupCallOverflowArea } from './GroupCallOverflowArea'; | 
					
						
							| 
									
										
										
										
											2021-09-17 20:30:08 -04:00
										 |  |  | import { setupI18n } from '../util/setupI18n'; | 
					
						
							| 
									
										
										
										
											2023-08-16 22:54:39 +02:00
										 |  |  | import { getDefaultConversationWithServiceId } from '../test-both/helpers/getDefaultConversation'; | 
					
						
							| 
									
										
										
										
											2021-01-08 12:58:28 -06:00
										 |  |  | import { fakeGetGroupCallVideoFrameSource } from '../test-both/helpers/fakeGetGroupCallVideoFrameSource'; | 
					
						
							|  |  |  | import { FRAME_BUFFER_SIZE } from '../calling/constants'; | 
					
						
							|  |  |  | import enMessages from '../../_locales/en/messages.json'; | 
					
						
							| 
									
										
										
										
											2023-08-30 14:34:58 -07:00
										 |  |  | import { generateAci } from '../types/ServiceId'; | 
					
						
							| 
									
										
										
										
											2024-05-07 11:21:57 -07:00
										 |  |  | import type { CallingImageDataCache } from './CallManager'; | 
					
						
							| 
									
										
										
										
											2021-01-08 12:58:28 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | const MAX_PARTICIPANTS = 32; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const i18n = setupI18n('en', enMessages); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const allRemoteParticipants = times(MAX_PARTICIPANTS).map(index => ({ | 
					
						
							| 
									
										
										
										
											2023-08-30 14:34:58 -07:00
										 |  |  |   aci: generateAci(), | 
					
						
							| 
									
										
										
										
											2021-01-08 12:58:28 -06:00
										 |  |  |   demuxId: index, | 
					
						
							|  |  |  |   hasRemoteAudio: index % 3 !== 0, | 
					
						
							|  |  |  |   hasRemoteVideo: index % 4 !== 0, | 
					
						
							| 
									
										
										
										
											2023-12-06 13:52:29 -08:00
										 |  |  |   isHandRaised: (index - 2) % 8 === 0, | 
					
						
							| 
									
										
										
										
											2024-01-23 11:08:21 -08:00
										 |  |  |   mediaKeysReceived: (index + 1) % 20 !== 0, | 
					
						
							| 
									
										
										
										
											2021-05-20 17:54:03 -04:00
										 |  |  |   presenting: false, | 
					
						
							|  |  |  |   sharingScreen: false, | 
					
						
							| 
									
										
										
										
											2021-01-08 12:58:28 -06:00
										 |  |  |   videoAspectRatio: 1.3, | 
					
						
							| 
									
										
										
										
											2023-08-16 22:54:39 +02:00
										 |  |  |   ...getDefaultConversationWithServiceId({ | 
					
						
							| 
									
										
										
										
											2021-01-08 12:58:28 -06:00
										 |  |  |     isBlocked: index === 10 || index === MAX_PARTICIPANTS - 1, | 
					
						
							|  |  |  |     title: `Participant ${index + 1}`, | 
					
						
							|  |  |  |   }), | 
					
						
							|  |  |  | })); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-06-06 20:48:02 -04:00
										 |  |  | export default { | 
					
						
							|  |  |  |   title: 'Components/GroupCallOverflowArea', | 
					
						
							| 
									
										
										
										
											2023-10-11 12:06:43 -07:00
										 |  |  |   argTypes: {}, | 
					
						
							|  |  |  |   args: {}, | 
					
						
							|  |  |  | } satisfies Meta<PropsType>; | 
					
						
							| 
									
										
										
										
											2021-01-08 12:58:28 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | const defaultProps = { | 
					
						
							| 
									
										
										
										
											2021-12-10 16:21:28 -08:00
										 |  |  |   getFrameBuffer: memoize(() => Buffer.alloc(FRAME_BUFFER_SIZE)), | 
					
						
							| 
									
										
										
										
											2024-05-07 11:21:57 -07:00
										 |  |  |   getCallingImageDataCache: memoize(() => new Map()), | 
					
						
							| 
									
										
										
										
											2021-01-08 12:58:28 -06:00
										 |  |  |   getGroupCallVideoFrameSource: fakeGetGroupCallVideoFrameSource, | 
					
						
							| 
									
										
										
										
											2024-05-07 11:21:57 -07:00
										 |  |  |   imageDataCache: React.createRef<CallingImageDataCache>(), | 
					
						
							| 
									
										
										
										
											2021-01-08 12:58:28 -06:00
										 |  |  |   i18n, | 
					
						
							| 
									
										
										
										
											2023-10-16 13:58:51 -04:00
										 |  |  |   isCallReconnecting: false, | 
					
						
							| 
									
										
										
										
											2021-12-06 17:06:13 -06:00
										 |  |  |   onParticipantVisibilityChanged: action('onParticipantVisibilityChanged'), | 
					
						
							| 
									
										
										
										
											2022-05-18 20:28:51 -07:00
										 |  |  |   remoteAudioLevels: new Map<number, number>(), | 
					
						
							| 
									
										
										
										
											2023-03-22 10:53:13 -07:00
										 |  |  |   remoteParticipantsCount: 1, | 
					
						
							| 
									
										
										
										
											2021-01-08 12:58:28 -06:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // This component is usually rendered on a call screen.
 | 
					
						
							| 
									
										
										
										
											2022-11-17 16:45:19 -08:00
										 |  |  | function Container({ children }: { children: JSX.Element }): JSX.Element { | 
					
						
							|  |  |  |   return ( | 
					
						
							|  |  |  |     <div | 
					
						
							|  |  |  |       style={{ | 
					
						
							|  |  |  |         background: 'black', | 
					
						
							|  |  |  |         display: 'inline-flex', | 
					
						
							|  |  |  |         height: '80vh', | 
					
						
							|  |  |  |       }} | 
					
						
							|  |  |  |     > | 
					
						
							|  |  |  |       {children} | 
					
						
							|  |  |  |     </div> | 
					
						
							|  |  |  |   ); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export function NoOverflowedParticipants(): JSX.Element { | 
					
						
							|  |  |  |   return ( | 
					
						
							|  |  |  |     <Container> | 
					
						
							|  |  |  |       <GroupCallOverflowArea {...defaultProps} overflowedParticipants={[]} /> | 
					
						
							|  |  |  |     </Container> | 
					
						
							|  |  |  |   ); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2022-06-06 20:48:02 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-17 16:45:19 -08:00
										 |  |  | export function OneOverflowedParticipant(): JSX.Element { | 
					
						
							|  |  |  |   return ( | 
					
						
							|  |  |  |     <Container> | 
					
						
							|  |  |  |       <GroupCallOverflowArea | 
					
						
							|  |  |  |         {...defaultProps} | 
					
						
							|  |  |  |         overflowedParticipants={allRemoteParticipants.slice(0, 1)} | 
					
						
							|  |  |  |       /> | 
					
						
							|  |  |  |     </Container> | 
					
						
							|  |  |  |   ); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2022-06-06 20:48:02 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-17 16:45:19 -08:00
										 |  |  | export function ThreeOverflowedParticipants(): JSX.Element { | 
					
						
							|  |  |  |   return ( | 
					
						
							|  |  |  |     <Container> | 
					
						
							|  |  |  |       <GroupCallOverflowArea | 
					
						
							|  |  |  |         {...defaultProps} | 
					
						
							|  |  |  |         overflowedParticipants={allRemoteParticipants.slice(0, 3)} | 
					
						
							|  |  |  |       /> | 
					
						
							|  |  |  |     </Container> | 
					
						
							|  |  |  |   ); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2022-06-06 20:48:02 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-17 16:45:19 -08:00
										 |  |  | export function ManyOverflowedParticipants(): JSX.Element { | 
					
						
							|  |  |  |   return ( | 
					
						
							|  |  |  |     <Container> | 
					
						
							|  |  |  |       <GroupCallOverflowArea | 
					
						
							|  |  |  |         {...defaultProps} | 
					
						
							|  |  |  |         overflowedParticipants={allRemoteParticipants.slice( | 
					
						
							|  |  |  |           0, | 
					
						
							| 
									
										
										
										
											2023-10-11 12:06:43 -07:00
										 |  |  |           MAX_PARTICIPANTS | 
					
						
							| 
									
										
										
										
											2022-11-17 16:45:19 -08:00
										 |  |  |         )} | 
					
						
							|  |  |  |       /> | 
					
						
							|  |  |  |     </Container> | 
					
						
							|  |  |  |   ); | 
					
						
							|  |  |  | } |