| 
									
										
										
										
											2020-10-30 15:34:04 -05:00
										 |  |  | // Copyright 2020 Signal Messenger, LLC
 | 
					
						
							|  |  |  | // SPDX-License-Identifier: AGPL-3.0-only
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-04 11:16:19 -07:00
										 |  |  | import * as React from 'react'; | 
					
						
							| 
									
										
										
										
											2020-09-11 17:46:52 -07:00
										 |  |  | import { storiesOf } from '@storybook/react'; | 
					
						
							|  |  |  | import { action } from '@storybook/addon-actions'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-04 11:16:19 -07:00
										 |  |  | import { CallManager } from './CallManager'; | 
					
						
							| 
									
										
										
										
											2020-10-01 14:09:15 -05:00
										 |  |  | import { CallEndedReason, CallState } from '../types/Calling'; | 
					
						
							| 
									
										
										
										
											2020-08-13 13:53:45 -07:00
										 |  |  | import { ColorType } from '../types/Colors'; | 
					
						
							| 
									
										
										
										
											2020-06-04 11:16:19 -07:00
										 |  |  | import { setup as setupI18n } from '../../js/modules/i18n'; | 
					
						
							|  |  |  | import enMessages from '../../_locales/en/messages.json'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const i18n = setupI18n('en', enMessages); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const callDetails = { | 
					
						
							|  |  |  |   callId: 0, | 
					
						
							|  |  |  |   isIncoming: true, | 
					
						
							|  |  |  |   isVideoCall: true, | 
					
						
							| 
									
										
										
										
											2020-07-23 18:35:32 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-07 21:25:33 -04:00
										 |  |  |   id: '3051234567', | 
					
						
							| 
									
										
										
										
											2020-07-23 18:35:32 -07:00
										 |  |  |   avatarPath: undefined, | 
					
						
							|  |  |  |   color: 'ultramarine' as ColorType, | 
					
						
							|  |  |  |   title: 'Rick Sanchez', | 
					
						
							| 
									
										
										
										
											2020-06-04 11:16:19 -07:00
										 |  |  |   name: 'Rick Sanchez', | 
					
						
							|  |  |  |   phoneNumber: '3051234567', | 
					
						
							|  |  |  |   profileName: 'Rick Sanchez', | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const defaultProps = { | 
					
						
							| 
									
										
										
										
											2020-10-14 12:30:50 -04:00
										 |  |  |   availableCameras: [], | 
					
						
							| 
									
										
										
										
											2020-06-04 11:16:19 -07:00
										 |  |  |   acceptCall: action('accept-call'), | 
					
						
							|  |  |  |   callDetails, | 
					
						
							|  |  |  |   callState: CallState.Accepted, | 
					
						
							| 
									
										
										
										
											2020-10-07 21:25:33 -04:00
										 |  |  |   cancelCall: action('cancel-call'), | 
					
						
							| 
									
										
										
										
											2020-10-01 14:09:15 -05:00
										 |  |  |   closeNeedPermissionScreen: action('close-need-permission-screen'), | 
					
						
							| 
									
										
										
										
											2020-06-04 11:16:19 -07:00
										 |  |  |   declineCall: action('decline-call'), | 
					
						
							|  |  |  |   hangUp: action('hang-up'), | 
					
						
							|  |  |  |   hasLocalAudio: true, | 
					
						
							|  |  |  |   hasLocalVideo: true, | 
					
						
							|  |  |  |   hasRemoteVideo: true, | 
					
						
							|  |  |  |   i18n, | 
					
						
							| 
									
										
										
										
											2020-09-30 20:43:05 -04:00
										 |  |  |   pip: false, | 
					
						
							| 
									
										
										
										
											2020-08-26 20:03:42 -04:00
										 |  |  |   renderDeviceSelection: () => <div />, | 
					
						
							| 
									
										
										
										
											2020-06-04 11:16:19 -07:00
										 |  |  |   setLocalAudio: action('set-local-audio'), | 
					
						
							| 
									
										
										
										
											2020-08-26 20:03:42 -04:00
										 |  |  |   setLocalPreview: action('set-local-preview'), | 
					
						
							| 
									
										
										
										
											2020-06-04 11:16:19 -07:00
										 |  |  |   setLocalVideo: action('set-local-video'), | 
					
						
							| 
									
										
										
										
											2020-08-26 20:03:42 -04:00
										 |  |  |   setRendererCanvas: action('set-renderer-canvas'), | 
					
						
							|  |  |  |   settingsDialogOpen: false, | 
					
						
							| 
									
										
										
										
											2020-10-07 21:25:33 -04:00
										 |  |  |   startCall: action('start-call'), | 
					
						
							|  |  |  |   toggleParticipants: action('toggle-participants'), | 
					
						
							| 
									
										
										
										
											2020-09-30 20:43:05 -04:00
										 |  |  |   togglePip: action('toggle-pip'), | 
					
						
							| 
									
										
										
										
											2020-08-26 20:03:42 -04:00
										 |  |  |   toggleSettings: action('toggle-settings'), | 
					
						
							| 
									
										
										
										
											2020-06-04 11:16:19 -07:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const permutations = [ | 
					
						
							|  |  |  |   { | 
					
						
							|  |  |  |     title: 'Call Manager (ongoing)', | 
					
						
							|  |  |  |     props: {}, | 
					
						
							|  |  |  |   }, | 
					
						
							|  |  |  |   { | 
					
						
							|  |  |  |     title: 'Call Manager (ringing)', | 
					
						
							|  |  |  |     props: { | 
					
						
							|  |  |  |       callState: CallState.Ringing, | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |   }, | 
					
						
							| 
									
										
										
										
											2020-10-01 14:09:15 -05:00
										 |  |  |   { | 
					
						
							|  |  |  |     title: 'Call Manager (call request needed)', | 
					
						
							|  |  |  |     props: { | 
					
						
							|  |  |  |       callState: CallState.Ended, | 
					
						
							|  |  |  |       callEndedReason: CallEndedReason.RemoteHangupNeedPermission, | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |   }, | 
					
						
							| 
									
										
										
										
											2020-06-04 11:16:19 -07:00
										 |  |  | ]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | storiesOf('Components/CallManager', module).add('Iterations', () => { | 
					
						
							|  |  |  |   return permutations.map(({ props, title }) => ( | 
					
						
							|  |  |  |     <> | 
					
						
							|  |  |  |       <h3>{title}</h3> | 
					
						
							|  |  |  |       <CallManager {...defaultProps} {...props} /> | 
					
						
							|  |  |  |     </> | 
					
						
							|  |  |  |   )); | 
					
						
							|  |  |  | }); |