| 
									
										
										
										
											2020-10-30 15:34:04 -05:00
										 |  |  | // Copyright 2020 Signal Messenger, LLC
 | 
					
						
							|  |  |  | // SPDX-License-Identifier: AGPL-3.0-only
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-26 20:03:42 -04:00
										 |  |  | import * as React from 'react'; | 
					
						
							| 
									
										
										
										
											2020-09-11 17:46:52 -07:00
										 |  |  | import { action } from '@storybook/addon-actions'; | 
					
						
							|  |  |  | import { storiesOf } from '@storybook/react'; | 
					
						
							| 
									
										
										
										
											2020-08-26 20:03:42 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-26 14:15:33 -05:00
										 |  |  | import type { Props } from './CallingDeviceSelection'; | 
					
						
							|  |  |  | import { CallingDeviceSelection } from './CallingDeviceSelection'; | 
					
						
							| 
									
										
										
										
											2021-09-17 20:30:08 -04:00
										 |  |  | import { setupI18n } from '../util/setupI18n'; | 
					
						
							| 
									
										
										
										
											2020-08-26 20:03:42 -04:00
										 |  |  | import enMessages from '../../_locales/en/messages.json'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const i18n = setupI18n('en', enMessages); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const audioDevice = { | 
					
						
							|  |  |  |   name: '', | 
					
						
							|  |  |  |   index: 0, | 
					
						
							| 
									
										
										
										
											2020-08-27 12:21:10 -07:00
										 |  |  |   uniqueId: '', | 
					
						
							|  |  |  |   i18nKey: undefined, | 
					
						
							| 
									
										
										
										
											2020-08-26 20:03:42 -04:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const createProps = ({ | 
					
						
							|  |  |  |   availableMicrophones = [], | 
					
						
							|  |  |  |   availableSpeakers = [], | 
					
						
							|  |  |  |   selectedMicrophone = audioDevice, | 
					
						
							|  |  |  |   selectedSpeaker = audioDevice, | 
					
						
							|  |  |  |   availableCameras = [], | 
					
						
							|  |  |  |   selectedCamera = '', | 
					
						
							|  |  |  | }: Partial<Props> = {}): Props => ({ | 
					
						
							|  |  |  |   availableCameras, | 
					
						
							|  |  |  |   availableMicrophones, | 
					
						
							|  |  |  |   availableSpeakers, | 
					
						
							|  |  |  |   changeIODevice: action('change-io-device'), | 
					
						
							|  |  |  |   i18n, | 
					
						
							|  |  |  |   selectedCamera, | 
					
						
							|  |  |  |   selectedMicrophone, | 
					
						
							|  |  |  |   selectedSpeaker, | 
					
						
							|  |  |  |   toggleSettings: action('toggle-settings'), | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const stories = storiesOf('Components/CallingDeviceSelection', module); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | stories.add('Default', () => { | 
					
						
							|  |  |  |   return <CallingDeviceSelection {...createProps()} />; | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | stories.add('Some Devices', () => { | 
					
						
							|  |  |  |   const availableSpeakers = [ | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2020-08-27 12:21:10 -07:00
										 |  |  |       name: 'Default', | 
					
						
							| 
									
										
										
										
											2020-08-26 20:03:42 -04:00
										 |  |  |       index: 0, | 
					
						
							| 
									
										
										
										
											2020-08-27 12:21:10 -07:00
										 |  |  |       uniqueId: 'Default', | 
					
						
							|  |  |  |       i18nKey: 'default_communication_device', | 
					
						
							| 
									
										
										
										
											2020-08-26 20:03:42 -04:00
										 |  |  |     }, | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       name: "Natalie's Airpods (Bluetooth)", | 
					
						
							|  |  |  |       index: 1, | 
					
						
							| 
									
										
										
										
											2020-08-27 12:21:10 -07:00
										 |  |  |       uniqueId: 'aa', | 
					
						
							| 
									
										
										
										
											2020-08-26 20:03:42 -04:00
										 |  |  |     }, | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       name: 'UE Boom (Bluetooth)', | 
					
						
							|  |  |  |       index: 2, | 
					
						
							| 
									
										
										
										
											2020-08-27 12:21:10 -07:00
										 |  |  |       uniqueId: 'bb', | 
					
						
							| 
									
										
										
										
											2020-08-26 20:03:42 -04:00
										 |  |  |     }, | 
					
						
							|  |  |  |   ]; | 
					
						
							|  |  |  |   const selectedSpeaker = availableSpeakers[0]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   const props = createProps({ | 
					
						
							|  |  |  |     availableSpeakers, | 
					
						
							|  |  |  |     selectedSpeaker, | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return <CallingDeviceSelection {...props} />; | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-27 21:11:00 -04:00
										 |  |  | stories.add('Default Devices', () => { | 
					
						
							|  |  |  |   const availableSpeakers = [ | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       name: 'default (Headphones)', | 
					
						
							|  |  |  |       index: 0, | 
					
						
							|  |  |  |       uniqueId: 'Default', | 
					
						
							|  |  |  |       i18nKey: 'default_communication_device', | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |   ]; | 
					
						
							|  |  |  |   const selectedSpeaker = availableSpeakers[0]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   const availableMicrophones = [ | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       name: 'DefAuLt (Headphones)', | 
					
						
							|  |  |  |       index: 0, | 
					
						
							|  |  |  |       uniqueId: 'Default', | 
					
						
							|  |  |  |       i18nKey: 'default_communication_device', | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |   ]; | 
					
						
							|  |  |  |   const selectedMicrophone = availableMicrophones[0]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   const props = createProps({ | 
					
						
							|  |  |  |     availableMicrophones, | 
					
						
							|  |  |  |     availableSpeakers, | 
					
						
							|  |  |  |     selectedMicrophone, | 
					
						
							|  |  |  |     selectedSpeaker, | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return <CallingDeviceSelection {...props} />; | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-26 20:03:42 -04:00
										 |  |  | stories.add('All Devices', () => { | 
					
						
							|  |  |  |   const availableSpeakers = [ | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2020-08-27 12:21:10 -07:00
										 |  |  |       name: 'Default', | 
					
						
							| 
									
										
										
										
											2020-08-26 20:03:42 -04:00
										 |  |  |       index: 0, | 
					
						
							| 
									
										
										
										
											2020-08-27 12:21:10 -07:00
										 |  |  |       uniqueId: 'Default', | 
					
						
							|  |  |  |       i18nKey: 'default_communication_device', | 
					
						
							| 
									
										
										
										
											2020-08-26 20:03:42 -04:00
										 |  |  |     }, | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       name: "Natalie's Airpods (Bluetooth)", | 
					
						
							|  |  |  |       index: 1, | 
					
						
							| 
									
										
										
										
											2020-08-27 12:21:10 -07:00
										 |  |  |       uniqueId: 'aa', | 
					
						
							| 
									
										
										
										
											2020-08-26 20:03:42 -04:00
										 |  |  |     }, | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       name: 'UE Boom (Bluetooth)', | 
					
						
							|  |  |  |       index: 2, | 
					
						
							| 
									
										
										
										
											2020-08-27 12:21:10 -07:00
										 |  |  |       uniqueId: 'bb', | 
					
						
							| 
									
										
										
										
											2020-08-26 20:03:42 -04:00
										 |  |  |     }, | 
					
						
							|  |  |  |   ]; | 
					
						
							|  |  |  |   const selectedSpeaker = availableSpeakers[0]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   const availableMicrophones = [ | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2020-08-27 12:21:10 -07:00
										 |  |  |       name: 'Default', | 
					
						
							| 
									
										
										
										
											2020-08-26 20:03:42 -04:00
										 |  |  |       index: 0, | 
					
						
							| 
									
										
										
										
											2020-08-27 12:21:10 -07:00
										 |  |  |       uniqueId: 'Default', | 
					
						
							|  |  |  |       i18nKey: 'default_communication_device', | 
					
						
							| 
									
										
										
										
											2020-08-26 20:03:42 -04:00
										 |  |  |     }, | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       name: "Natalie's Airpods (Bluetooth)", | 
					
						
							|  |  |  |       index: 1, | 
					
						
							| 
									
										
										
										
											2020-08-27 12:21:10 -07:00
										 |  |  |       uniqueId: 'aa', | 
					
						
							| 
									
										
										
										
											2020-08-26 20:03:42 -04:00
										 |  |  |     }, | 
					
						
							|  |  |  |   ]; | 
					
						
							|  |  |  |   const selectedMicrophone = availableMicrophones[0]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   const availableCameras = [ | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       deviceId: | 
					
						
							|  |  |  |         'dfbe6effe70b0611ba0fdc2a9ea3f39f6cb110e6687948f7e5f016c111b7329c', | 
					
						
							|  |  |  |       groupId: | 
					
						
							|  |  |  |         '63ee218d2446869e40adfc958ff98263e51f74382b0143328ee4826f20a76f47', | 
					
						
							|  |  |  |       kind: 'videoinput' as MediaDeviceKind, | 
					
						
							|  |  |  |       label: 'FaceTime HD Camera (Built-in) (9fba:bced)', | 
					
						
							|  |  |  |       toJSON() { | 
					
						
							|  |  |  |         return ''; | 
					
						
							|  |  |  |       }, | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       deviceId: | 
					
						
							|  |  |  |         'e2db196a31d50ff9b135299dc0beea67f65b1a25a06d8a4ce76976751bb7a08d', | 
					
						
							|  |  |  |       groupId: | 
					
						
							|  |  |  |         '218ba7f00d7b1239cca15b9116769e5e7d30cc01104ebf84d667643661e0ecf9', | 
					
						
							|  |  |  |       kind: 'videoinput' as MediaDeviceKind, | 
					
						
							|  |  |  |       label: 'Logitech Webcam (4e72:9058)', | 
					
						
							|  |  |  |       toJSON() { | 
					
						
							|  |  |  |         return ''; | 
					
						
							|  |  |  |       }, | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |   ]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   const selectedCamera = | 
					
						
							|  |  |  |     'dfbe6effe70b0611ba0fdc2a9ea3f39f6cb110e6687948f7e5f016c111b7329c'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   const props = createProps({ | 
					
						
							|  |  |  |     availableCameras, | 
					
						
							|  |  |  |     availableMicrophones, | 
					
						
							|  |  |  |     availableSpeakers, | 
					
						
							|  |  |  |     selectedCamera, | 
					
						
							|  |  |  |     selectedMicrophone, | 
					
						
							|  |  |  |     selectedSpeaker, | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return <CallingDeviceSelection {...props} />; | 
					
						
							|  |  |  | }); |