| 
									
										
										
										
											2023-01-03 11:55:46 -08:00
										 |  |  | // Copyright 2020 Signal Messenger, LLC
 | 
					
						
							| 
									
										
										
										
											2020-11-19 18:31:04 -05:00
										 |  |  | // SPDX-License-Identifier: AGPL-3.0-only
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import * as React from 'react'; | 
					
						
							| 
									
										
										
										
											2023-10-11 12:06:43 -07:00
										 |  |  | import { memoize } from 'lodash'; | 
					
						
							|  |  |  | import type { Meta } from '@storybook/react'; | 
					
						
							| 
									
										
										
										
											2021-10-26 14:15:33 -05:00
										 |  |  | import type { PropsType } from './GroupCallRemoteParticipant'; | 
					
						
							|  |  |  | import { GroupCallRemoteParticipant } from './GroupCallRemoteParticipant'; | 
					
						
							| 
									
										
										
										
											2020-12-18 13:16:44 -06:00
										 |  |  | import { getDefaultConversation } from '../test-both/helpers/getDefaultConversation'; | 
					
						
							| 
									
										
										
										
											2021-01-08 11:32:49 -06:00
										 |  |  | import { FRAME_BUFFER_SIZE } from '../calling/constants'; | 
					
						
							| 
									
										
										
										
											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-11-19 18:31:04 -05:00
										 |  |  | import enMessages from '../../_locales/en/messages.json'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const i18n = setupI18n('en', enMessages); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-05-18 20:28:51 -07:00
										 |  |  | type OverridePropsType = { | 
					
						
							|  |  |  |   audioLevel?: number; | 
					
						
							| 
									
										
										
										
											2023-03-22 10:53:13 -07:00
										 |  |  |   remoteParticipantsCount?: number; | 
					
						
							| 
									
										
										
										
											2022-05-18 20:28:51 -07:00
										 |  |  | } & ( | 
					
						
							| 
									
										
										
										
											2020-12-04 11:30:46 -06:00
										 |  |  |   | { | 
					
						
							|  |  |  |       isInPip: true; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   | { | 
					
						
							|  |  |  |       isInPip: false; | 
					
						
							|  |  |  |       height: number; | 
					
						
							|  |  |  |       left: number; | 
					
						
							|  |  |  |       top: number; | 
					
						
							|  |  |  |       width: number; | 
					
						
							| 
									
										
										
										
											2022-05-18 20:28:51 -07:00
										 |  |  |     } | 
					
						
							|  |  |  | ); | 
					
						
							| 
									
										
										
										
											2020-12-04 11:30:46 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-12-10 16:21:28 -08:00
										 |  |  | const getFrameBuffer = memoize(() => Buffer.alloc(FRAME_BUFFER_SIZE)); | 
					
						
							| 
									
										
										
										
											2021-01-08 11:32:49 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-01 20:30:25 -05:00
										 |  |  | const createProps = ( | 
					
						
							| 
									
										
										
										
											2020-12-04 11:30:46 -06:00
										 |  |  |   overrideProps: OverridePropsType, | 
					
						
							| 
									
										
										
										
											2022-05-18 20:28:51 -07:00
										 |  |  |   { | 
					
						
							| 
									
										
										
										
											2024-01-23 11:08:21 -08:00
										 |  |  |     addedTime, | 
					
						
							| 
									
										
										
										
											2022-05-18 20:28:51 -07:00
										 |  |  |     isBlocked = false, | 
					
						
							| 
									
										
										
										
											2024-01-23 11:08:21 -08:00
										 |  |  |     isHandRaised = false, | 
					
						
							| 
									
										
										
										
											2022-05-18 20:28:51 -07:00
										 |  |  |     hasRemoteAudio = false, | 
					
						
							| 
									
										
										
										
											2024-01-23 11:08:21 -08:00
										 |  |  |     mediaKeysReceived = true, | 
					
						
							| 
									
										
										
										
											2023-03-22 10:53:13 -07:00
										 |  |  |     presenting = false, | 
					
						
							| 
									
										
										
										
											2022-05-18 20:28:51 -07:00
										 |  |  |   }: { | 
					
						
							| 
									
										
										
										
											2024-01-23 11:08:21 -08:00
										 |  |  |     addedTime?: number; | 
					
						
							| 
									
										
										
										
											2022-05-18 20:28:51 -07:00
										 |  |  |     isBlocked?: boolean; | 
					
						
							|  |  |  |     hasRemoteAudio?: boolean; | 
					
						
							| 
									
										
										
										
											2024-01-23 11:08:21 -08:00
										 |  |  |     mediaKeysReceived?: boolean; | 
					
						
							| 
									
										
										
										
											2023-03-22 10:53:13 -07:00
										 |  |  |     presenting?: boolean; | 
					
						
							| 
									
										
										
										
											2023-12-06 13:52:29 -08:00
										 |  |  |     isHandRaised?: boolean; | 
					
						
							| 
									
										
										
										
											2022-05-18 20:28:51 -07:00
										 |  |  |   } = {} | 
					
						
							| 
									
										
										
										
											2020-12-04 11:30:46 -06:00
										 |  |  | ): PropsType => ({ | 
					
						
							| 
									
										
										
										
											2021-01-08 11:32:49 -06:00
										 |  |  |   getFrameBuffer, | 
					
						
							| 
									
										
										
										
											2023-10-11 12:06:43 -07:00
										 |  |  |   getGroupCallVideoFrameSource: () => { | 
					
						
							|  |  |  |     return { receiveVideoFrame: () => undefined }; | 
					
						
							|  |  |  |   }, | 
					
						
							| 
									
										
										
										
											2020-11-19 18:31:04 -05:00
										 |  |  |   i18n, | 
					
						
							| 
									
										
										
										
											2022-05-18 20:28:51 -07:00
										 |  |  |   audioLevel: 0, | 
					
						
							| 
									
										
										
										
											2020-11-19 18:31:04 -05:00
										 |  |  |   remoteParticipant: { | 
					
						
							| 
									
										
										
										
											2023-08-30 14:34:58 -07:00
										 |  |  |     aci: generateAci(), | 
					
						
							| 
									
										
										
										
											2024-01-23 11:08:21 -08:00
										 |  |  |     addedTime, | 
					
						
							| 
									
										
										
										
											2020-11-19 18:31:04 -05:00
										 |  |  |     demuxId: 123, | 
					
						
							| 
									
										
										
										
											2022-05-18 20:28:51 -07:00
										 |  |  |     hasRemoteAudio, | 
					
						
							| 
									
										
										
										
											2020-11-19 18:31:04 -05:00
										 |  |  |     hasRemoteVideo: true, | 
					
						
							| 
									
										
										
										
											2023-12-06 13:52:29 -08:00
										 |  |  |     isHandRaised, | 
					
						
							| 
									
										
										
										
											2024-01-23 11:08:21 -08:00
										 |  |  |     mediaKeysReceived, | 
					
						
							| 
									
										
										
										
											2023-03-22 10:53:13 -07:00
										 |  |  |     presenting, | 
					
						
							| 
									
										
										
										
											2021-05-20 17:54:03 -04:00
										 |  |  |     sharingScreen: false, | 
					
						
							| 
									
										
										
										
											2020-11-19 18:31:04 -05:00
										 |  |  |     videoAspectRatio: 1.3, | 
					
						
							| 
									
										
										
										
											2020-12-08 14:37:04 -05:00
										 |  |  |     ...getDefaultConversation({ | 
					
						
							|  |  |  |       isBlocked: Boolean(isBlocked), | 
					
						
							|  |  |  |       title: | 
					
						
							|  |  |  |         'Pablo Diego José Francisco de Paula Juan Nepomuceno María de los Remedios Cipriano de la Santísima Trinidad Ruiz y Picasso', | 
					
						
							| 
									
										
										
										
											2023-08-16 22:54:39 +02:00
										 |  |  |       serviceId: generateAci(), | 
					
						
							| 
									
										
										
										
											2020-12-08 14:37:04 -05:00
										 |  |  |     }), | 
					
						
							| 
									
										
										
										
											2020-11-19 18:31:04 -05:00
										 |  |  |   }, | 
					
						
							| 
									
										
										
										
											2023-03-22 10:53:13 -07:00
										 |  |  |   remoteParticipantsCount: 1, | 
					
						
							| 
									
										
										
										
											2023-03-22 14:54:11 -07:00
										 |  |  |   isActiveSpeakerInSpeakerView: false, | 
					
						
							| 
									
										
										
										
											2023-10-16 13:58:51 -04:00
										 |  |  |   isCallReconnecting: false, | 
					
						
							| 
									
										
										
										
											2020-11-19 18:31:04 -05:00
										 |  |  |   ...overrideProps, | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-06-06 20:48:02 -04:00
										 |  |  | export default { | 
					
						
							|  |  |  |   title: 'Components/GroupCallRemoteParticipant', | 
					
						
							| 
									
										
										
										
											2023-10-11 12:06:43 -07:00
										 |  |  |   argTypes: {}, | 
					
						
							|  |  |  |   args: {}, | 
					
						
							|  |  |  | } satisfies Meta<PropsType>; | 
					
						
							| 
									
										
										
										
											2020-11-19 18:31:04 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-17 16:45:19 -08:00
										 |  |  | export function Default(): JSX.Element { | 
					
						
							|  |  |  |   return ( | 
					
						
							|  |  |  |     <GroupCallRemoteParticipant | 
					
						
							|  |  |  |       {...createProps({ | 
					
						
							| 
									
										
										
										
											2022-05-18 20:28:51 -07:00
										 |  |  |         isInPip: false, | 
					
						
							|  |  |  |         height: 120, | 
					
						
							|  |  |  |         left: 0, | 
					
						
							|  |  |  |         top: 0, | 
					
						
							|  |  |  |         width: 120, | 
					
						
							| 
									
										
										
										
											2022-11-17 16:45:19 -08:00
										 |  |  |       })} | 
					
						
							|  |  |  |     /> | 
					
						
							|  |  |  |   ); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2022-05-18 20:28:51 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-17 16:45:19 -08:00
										 |  |  | export function Speaking(): JSX.Element { | 
					
						
							| 
									
										
										
										
											2023-03-22 10:53:13 -07:00
										 |  |  |   function createSpeakingProps( | 
					
						
							|  |  |  |     index: number, | 
					
						
							|  |  |  |     remoteParticipantsCount: number, | 
					
						
							|  |  |  |     presenting: boolean | 
					
						
							|  |  |  |   ) { | 
					
						
							|  |  |  |     return createProps( | 
					
						
							|  |  |  |       { | 
					
						
							|  |  |  |         isInPip: false, | 
					
						
							|  |  |  |         height: 120, | 
					
						
							|  |  |  |         left: (120 + 10) * index, | 
					
						
							|  |  |  |         top: 0, | 
					
						
							|  |  |  |         width: 120, | 
					
						
							| 
									
										
										
										
											2023-10-11 12:06:43 -07:00
										 |  |  |         audioLevel: 0.5, | 
					
						
							| 
									
										
										
										
											2023-03-22 10:53:13 -07:00
										 |  |  |         remoteParticipantsCount, | 
					
						
							|  |  |  |       }, | 
					
						
							|  |  |  |       { hasRemoteAudio: true, presenting } | 
					
						
							|  |  |  |     ); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2022-11-17 16:45:19 -08:00
										 |  |  |   return ( | 
					
						
							| 
									
										
										
										
											2023-03-22 10:53:13 -07:00
										 |  |  |     <> | 
					
						
							|  |  |  |       <GroupCallRemoteParticipant {...createSpeakingProps(0, 1, false)} /> | 
					
						
							|  |  |  |       <GroupCallRemoteParticipant {...createSpeakingProps(1, 2, false)} /> | 
					
						
							|  |  |  |       <GroupCallRemoteParticipant {...createSpeakingProps(2, 2, true)} /> | 
					
						
							|  |  |  |     </> | 
					
						
							| 
									
										
										
										
											2022-11-17 16:45:19 -08:00
										 |  |  |   ); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-12-06 13:52:29 -08:00
										 |  |  | export function HandRaised(): JSX.Element { | 
					
						
							|  |  |  |   return ( | 
					
						
							|  |  |  |     <GroupCallRemoteParticipant | 
					
						
							|  |  |  |       {...createProps( | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |           isInPip: false, | 
					
						
							|  |  |  |           height: 120, | 
					
						
							|  |  |  |           left: 0, | 
					
						
							|  |  |  |           top: 0, | 
					
						
							|  |  |  |           width: 120, | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |         { isHandRaised: true } | 
					
						
							|  |  |  |       )} | 
					
						
							|  |  |  |     /> | 
					
						
							|  |  |  |   ); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-17 16:45:19 -08:00
										 |  |  | export function IsInPip(): JSX.Element { | 
					
						
							|  |  |  |   return ( | 
					
						
							|  |  |  |     <GroupCallRemoteParticipant | 
					
						
							|  |  |  |       {...createProps({ | 
					
						
							|  |  |  |         isInPip: true, | 
					
						
							|  |  |  |       })} | 
					
						
							|  |  |  |     /> | 
					
						
							|  |  |  |   ); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2020-12-01 20:30:25 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-17 16:45:19 -08:00
										 |  |  | export function Blocked(): JSX.Element { | 
					
						
							|  |  |  |   return ( | 
					
						
							|  |  |  |     <GroupCallRemoteParticipant | 
					
						
							|  |  |  |       {...createProps( | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |           isInPip: false, | 
					
						
							|  |  |  |           height: 120, | 
					
						
							|  |  |  |           left: 0, | 
					
						
							|  |  |  |           top: 0, | 
					
						
							|  |  |  |           width: 120, | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |         { isBlocked: true } | 
					
						
							|  |  |  |       )} | 
					
						
							|  |  |  |     /> | 
					
						
							|  |  |  |   ); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2024-01-23 11:08:21 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | export function NoMediaKeys(): JSX.Element { | 
					
						
							|  |  |  |   return ( | 
					
						
							|  |  |  |     <GroupCallRemoteParticipant | 
					
						
							|  |  |  |       {...createProps( | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |           isInPip: false, | 
					
						
							|  |  |  |           height: 120, | 
					
						
							|  |  |  |           left: 0, | 
					
						
							|  |  |  |           top: 0, | 
					
						
							|  |  |  |           width: 120, | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |           addedTime: Date.now() - 60 * 1000, | 
					
						
							|  |  |  |           hasRemoteAudio: true, | 
					
						
							|  |  |  |           mediaKeysReceived: false, | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       )} | 
					
						
							|  |  |  |     /> | 
					
						
							|  |  |  |   ); | 
					
						
							|  |  |  | } |