-
Notifications
You must be signed in to change notification settings - Fork 78
Expand file tree
/
Copy pathCallComposite.tsx
More file actions
742 lines (711 loc) · 28.3 KB
/
CallComposite.tsx
File metadata and controls
742 lines (711 loc) · 28.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
import { _isInCall } from '@internal/calling-component-bindings';
import { ActiveErrorMessage, ErrorBar, ParticipantMenuItemsCallback, useTheme } from '@internal/react-components';
/* @conditional-compile-remove(end-of-call-survey) */
import { CallSurveyImprovementSuggestions } from '@internal/react-components';
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
import { AvatarPersonaDataCallback } from '../common/AvatarPersona';
import { BaseProvider, BaseCompositeProps } from '../common/BaseComposite';
import { CallCompositeIcons } from '../common/icons';
import { useLocale } from '../localization';
import { CommonCallAdapter } from './adapter/CallAdapter';
import { CallAdapterProvider, useAdapter } from './adapter/CallAdapterProvider';
import { CallPage } from './pages/CallPage';
import { ConfigurationPage } from './pages/ConfigurationPage';
import { NoticePage } from './pages/NoticePage';
import { useSelector } from './hooks/useSelector';
import { getEndedCall, getPage } from './selectors/baseSelectors';
import { LobbyPage } from './pages/LobbyPage';
/* @conditional-compile-remove(call-transfer) */
import { TransferPage } from './pages/TransferPage';
import {
leavingPageStyle,
mainScreenContainerStyleDesktop,
mainScreenContainerStyleMobile
} from './styles/CallComposite.styles';
import { CallControlOptions } from './types/CallControlOptions';
import { LayerHost, mergeStyles } from '@fluentui/react';
import { modalLayerHostStyle } from '../common/styles/ModalLocalAndRemotePIP.styles';
import { useId } from '@fluentui/react-hooks';
/* @conditional-compile-remove(one-to-n-calling) */ /* @conditional-compile-remove(PSTN-calls) */
import { HoldPage } from './pages/HoldPage';
/* @conditional-compile-remove(unsupported-browser) */
import { UnsupportedBrowserPage } from './pages/UnsupportedBrowser';
/* @conditional-compile-remove(end-of-call-survey) */
import { CallSurvey } from '@azure/communication-calling';
import { PermissionConstraints } from '@azure/communication-calling';
/* @conditional-compile-remove(rooms) */
import { ParticipantRole } from '@azure/communication-calling';
import { MobileChatSidePaneTabHeaderProps } from '../common/TabHeader';
import { InjectedSidePaneProps, SidePaneProvider, SidePaneRenderer } from './components/SidePane/SidePaneProvider';
import {
filterLatestErrors,
getEndedCallPageProps,
trackErrorAsDismissed,
updateTrackedErrorsWithActiveErrors
} from './utils';
import { TrackedErrors } from './types/ErrorTracking';
import { usePropsFor } from './hooks/usePropsFor';
import { deviceCountSelector } from './selectors/deviceCountSelector';
/* @conditional-compile-remove(gallery-layouts) */
import { VideoGalleryLayout } from '@internal/react-components';
/* @conditional-compile-remove(capabilities) */
import { capabilitiesChangedInfoAndRoleSelector } from './selectors/capabilitiesChangedInfoAndRoleSelector';
/* @conditional-compile-remove(capabilities) */
import { useTrackedCapabilityChangedNotifications } from './utils/TrackCapabilityChangedNotifications';
import { useEndedCallConsoleErrors } from './utils/useConsoleErrors';
/* @conditional-compile-remove(dtmf-dialer) */
import { DtmfDialpadPage } from './pages/DtmfDialpadPage';
/**
* Props for {@link CallComposite}.
*
* @public
*/
export interface CallCompositeProps extends BaseCompositeProps<CallCompositeIcons> {
/**
* An adapter provides logic and data to the composite.
* Composite can also be controlled using the adapter.
*/
adapter: CommonCallAdapter;
/**
* Optimizes the composite form factor for either desktop or mobile.
* @remarks `mobile` is currently only optimized for Portrait mode on mobile devices and does not support landscape.
* @defaultValue 'desktop'
*/
formFactor?: 'desktop' | 'mobile';
/**
* URL to invite new participants to the current call. If this is supplied, a button appears in the Participants
* Button flyout menu.
*/
callInvitationUrl?: string;
/**
* Flags to enable/disable or customize UI elements of the {@link CallComposite}.
*/
options?: CallCompositeOptions;
}
/* @conditional-compile-remove(call-readiness) */
/**
* Device Checks.
* Choose whether or not to block starting a call depending on camera and microphone permission options.
*
* @beta
*/
export interface DeviceCheckOptions {
/**
* Camera Permission prompts for your call.
* 'required' - requires the permission to be allowed before permitting the user join the call.
* 'optional' - permission can be disallowed and the user is still permitted to join the call.
* 'doNotPrompt' - permission is not required and the user is not prompted to allow the permission.
*/
camera: 'required' | 'optional' | 'doNotPrompt';
/**
* Microphone permission prompts for your call.
* 'required' - requires the permission to be allowed before permitting the user join the call.
* 'optional' - permission can be disallowed and the user is still permitted to join the call.
* 'doNotPrompt' - permission is not required and the user is not prompted to allow the permission.
*/
microphone: 'required' | 'optional' | 'doNotPrompt';
}
/* @conditional-compile-remove(pinned-participants) */
/**
* Menu options for remote video tiles in {@link VideoGallery}.
*
* @public
*/
export interface RemoteVideoTileMenuOptions {
/**
* If set to true, remote video tiles in the VideoGallery will not have menu options
*
* @defaultValue false
*/
isHidden?: boolean;
}
/* @conditional-compile-remove(click-to-call) */ /* @conditional-compile-remove(rooms) */ /* @conditional-compile-remove(vertical-gallery) */
/**
* Options for the local video tile in the Call composite.
*
* @beta
*/
export interface LocalVideoTileOptions {
/**
* Position of the local video tile. If unset will render the local tile in the floating local position.
*
* @defaultValue 'floating'
* @remarks 'grid' - local video tile will be rendered in the grid view of the videoGallery.
* 'floating' - local video tile will be rendered in the floating position and will observe overflow gallery
* local video tile rules and be docked in the bottom corner.
* This does not affect the Configuration screen or the side pane Picture in Picture in Picture view.
*/
position?: 'grid' | 'floating';
}
/**
* Optional features of the {@link CallComposite}.
*
* @public
*/
export type CallCompositeOptions = {
/**
* Surface Azure Communication Services backend errors in the UI with {@link @azure/communication-react#ErrorBar}.
* Hide or show the error bar.
* @defaultValue true
*/
errorBar?: boolean;
/**
* Hide or Customize the control bar element.
* Can be customized by providing an object of type {@link @azure/communication-react#CallControlOptions}.
* @defaultValue true
*/
callControls?: boolean | CallControlOptions;
/* @conditional-compile-remove(call-readiness) */
/**
* Device permissions check options for your call.
* Here you can choose what device permissions you prompt the user for,
* as well as what device permissions must be accepted before starting a call.
*/
deviceChecks?: DeviceCheckOptions;
/* @conditional-compile-remove(call-readiness) */
/**
* Callback you may provide to supply users with further steps to troubleshoot why they have been
* unable to grant your site the required permissions for the call.
*
* @example
* ```ts
* onPermissionsTroubleshootingClick: () =>
* window.open('https://contoso.com/permissions-troubleshooting', '_blank');
* ```
*
* @remarks
* if this is not supplied, the composite will not show a 'further troubleshooting' link.
*/
onPermissionsTroubleshootingClick?: (permissionsState: {
camera: PermissionState;
microphone: PermissionState;
}) => void;
/* @conditional-compile-remove(call-readiness) */
/**
* Callback you may provide to supply users with further steps to troubleshoot why they have been
* having network issues when connecting to the call.
*
* @example
* ```ts
* onNetworkingTroubleShootingClick?: () =>
* window.open('https://contoso.com/network-troubleshooting', '_blank');
* ```
*
* @remarks
* if this is not supplied, the composite will not show a 'network troubleshooting' link.
*/
onNetworkingTroubleShootingClick?: () => void;
/* @conditional-compile-remove(unsupported-browser) */
/**
* Callback you may provide to supply users with a provided page to showcase supported browsers by ACS.
*
* @example
* ```ts
* onBrowserTroubleShootingClick?: () =>
* window.open('https://contoso.com/browser-troubleshooting', '_blank');
* ```
*
* @remarks
* if this is not supplied, the composite will not show a unsupported browser page.
*/
onEnvironmentInfoTroubleshootingClick?: () => void;
/* @conditional-compile-remove(pinned-participants) */
/**
* Remote participant video tile menu options
*/
remoteVideoTileMenuOptions?: RemoteVideoTileMenuOptions;
/* @conditional-compile-remove(click-to-call) */
/**
* Options for controlling the local video tile.
*
* @remarks if 'false' the local video tile will not be rendered.
*/
localVideoTile?: boolean | LocalVideoTileOptions;
/* @conditional-compile-remove(gallery-layouts) */
/**
* Options for controlling the starting layout of the composite's video gallery
*/
galleryOptions?: {
/**
* Layout for the gallery when the call starts
*/
layout?: VideoGalleryLayout;
};
/* @conditional-compile-remove(end-of-call-survey) */
/**
* Options for end of call survey
*/
surveyOptions?: {
/**
* Disable call survey at the end of a call.
* @defaultValue false
*/
disableSurvey?: boolean;
/* @conditional-compile-remove(end-of-call-survey-self-host) */
/**
* Optional callback to add extra logic when survey is dismissed. For self-host only
*/
onSurveyDismissed?: () => void;
/**
* Optional callback to handle survey data including free form text response
* Note that free form text response survey option is only going to be enabled when this callback is provided
* User will need to handle all free form text response on their own
*/
onSurveySubmitted?: (
callId: string,
surveyId: string,
/**
* This is the survey results containing star survey data and API tag survey data.
* This part of the result will always be sent to the calling sdk
* This callback provides user with the ability to gain access to survey data
*/
submittedSurvey: CallSurvey,
/**
* This is the survey results containing free form text
* This part of the result will not be handled by composites
* User will need to collect and handle this information 100% on their own
* Free form text survey is not going to show in the UI if onSurveySubmitted is not populated
*/
improvementSuggestions: CallSurveyImprovementSuggestions
) => Promise<void>;
};
/* @conditional-compile-remove(custom-branding) */
/**
* Options for setting additional customizations related to personalized branding.
*/
branding?: {
/**
* Logo displayed on the configuration page.
*/
logo?: {
/**
* URL for the logo image.
*
* @remarks
* Recommended size is 80x80 pixels.
*/
url: string;
/**
* Alt text for the logo image.
*/
alt?: string;
/**
* The logo can be displayed as a circle.
*
* @defaultValue 'unset'
*/
shape?: 'unset' | 'circle';
};
/* @conditional-compile-remove(custom-branding) */
/**
* Background image displayed on the configuration page.
*/
backgroundImage?: {
/**
* URL for the background image.
*
* @remarks
* Background image should be larger than 576x567 pixels and smaller than 2048x2048 pixels pixels.
*/
url: string;
};
};
};
type MainScreenProps = {
mobileView: boolean;
modalLayerHostId: string;
callInvitationUrl?: string;
onFetchAvatarPersonaData?: AvatarPersonaDataCallback;
onFetchParticipantMenuItems?: ParticipantMenuItemsCallback;
options?: CallCompositeOptions;
overrideSidePane?: InjectedSidePaneProps;
onSidePaneIdChange?: (sidePaneId: string | undefined) => void;
mobileChatTabHeader?: MobileChatSidePaneTabHeaderProps;
onCloseChatPane?: () => void;
};
const isShowing = (overrideSidePane?: InjectedSidePaneProps): boolean => {
return !!overrideSidePane?.isActive;
};
const MainScreen = (props: MainScreenProps): JSX.Element => {
const adapter = useAdapter();
const { camerasCount, microphonesCount } = useSelector(deviceCountSelector);
const hasCameras = camerasCount > 0;
const hasMicrophones = microphonesCount > 0;
useEffect(() => {
(async () => {
const constrain = getQueryOptions({
/* @conditional-compile-remove(rooms) */ role: adapter.getState().call?.role
});
await adapter.askDevicePermission(constrain);
adapter.queryCameras();
adapter.queryMicrophones();
adapter.querySpeakers();
})();
}, [
adapter,
// Ensure we re-ask for permissions if the number of devices goes from 0 -> n during a call
// as we cannot request permissions when there are no devices.
hasCameras,
hasMicrophones
]);
const { callInvitationUrl, onFetchAvatarPersonaData, onFetchParticipantMenuItems } = props;
const page = useSelector(getPage);
const endedCall = useSelector(getEndedCall);
const [sidePaneRenderer, setSidePaneRenderer] = React.useState<SidePaneRenderer | undefined>();
const [injectedSidePaneProps, setInjectedSidePaneProps] = React.useState<InjectedSidePaneProps>();
/* @conditional-compile-remove(dtmf-dialer) */
const [dialpadScreen, setDialpadScreen] = useState<boolean>(false);
/* @conditional-compile-remove(gallery-layouts) */
const [userSetGalleryLayout, setUserSetGalleryLayout] = useState<VideoGalleryLayout>(
props.options?.galleryOptions?.layout ?? 'floatingLocalVideo'
);
/* @conditional-compile-remove(gallery-layouts) */
const [userSetOverflowGalleryPosition, setUserSetOverflowGalleryPosition] = useState<'Responsive' | 'horizontalTop'>(
'Responsive'
);
const overridePropsRef = useRef<InjectedSidePaneProps | undefined>(props.overrideSidePane);
useEffect(() => {
setInjectedSidePaneProps(props.overrideSidePane);
// When the injected side pane is opened, clear the previous side pane active state.
// this ensures when the injected side pane is "closed", the previous side pane is not "re-opened".
if (!isShowing(overridePropsRef.current) && isShowing(props.overrideSidePane)) {
setSidePaneRenderer(undefined);
}
overridePropsRef.current = props.overrideSidePane;
}, [props.overrideSidePane]);
const onSidePaneIdChange = props.onSidePaneIdChange;
useEffect(() => {
onSidePaneIdChange?.(sidePaneRenderer?.id);
}, [sidePaneRenderer?.id, onSidePaneIdChange]);
// When the call ends ensure the side pane is set to closed to prevent the side pane being open if the call is re-joined.
useEffect(() => {
const closeSidePane = (): void => {
setSidePaneRenderer(undefined);
};
adapter.on('callEnded', closeSidePane);
return () => {
adapter.off('callEnded', closeSidePane);
};
}, [adapter]);
/* @conditional-compile-remove(capabilities) */
const capabilitiesChangedInfoAndRole = useSelector(capabilitiesChangedInfoAndRoleSelector);
/* @conditional-compile-remove(capabilities) */
const capabilitiesChangedNotificationBarProps =
useTrackedCapabilityChangedNotifications(capabilitiesChangedInfoAndRole);
// Track the last dismissed errors of any error kind to prevent errors from re-appearing on subsequent page navigation
// This works by tracking the most recent timestamp of any active error type.
// And then tracking when that error type was last dismissed.
const activeErrors = usePropsFor(ErrorBar).activeErrorMessages;
const [trackedErrors, setTrackedErrors] = useState<TrackedErrors>({} as TrackedErrors);
useEffect(() => {
setTrackedErrors((prev) => updateTrackedErrorsWithActiveErrors(prev, activeErrors));
}, [activeErrors]);
const onDismissError = useCallback((error: ActiveErrorMessage) => {
setTrackedErrors((prev) => trackErrorAsDismissed(error.type, prev));
}, []);
const latestErrors = useMemo(() => filterLatestErrors(activeErrors, trackedErrors), [activeErrors, trackedErrors]);
const locale = useLocale();
const palette = useTheme().palette;
const leavePageStyle = useMemo(() => leavingPageStyle(palette), [palette]);
let pageElement: JSX.Element | undefined;
switch (page) {
case 'configuration':
pageElement = (
<ConfigurationPage
mobileView={props.mobileView}
startCallHandler={(): void => {
adapter.joinCall({
microphoneOn: 'keep',
cameraOn: 'keep'
});
}}
updateSidePaneRenderer={setSidePaneRenderer}
latestErrors={latestErrors}
onDismissError={onDismissError}
modalLayerHostId={props.modalLayerHostId}
/* @conditional-compile-remove(call-readiness) */
deviceChecks={props.options?.deviceChecks}
/* @conditional-compile-remove(call-readiness) */
onPermissionsTroubleshootingClick={props.options?.onPermissionsTroubleshootingClick}
/* @conditional-compile-remove(call-readiness) */
onNetworkingTroubleShootingClick={props.options?.onNetworkingTroubleShootingClick}
/* @conditional-compile-remove(capabilities) */
capabilitiesChangedNotificationBarProps={capabilitiesChangedNotificationBarProps}
/* @conditional-compile-remove(custom-branding) */
logo={props.options?.branding?.logo}
/* @conditional-compile-remove(custom-branding) */
backgroundImage={props.options?.branding?.backgroundImage}
/>
);
break;
case 'accessDeniedTeamsMeeting':
pageElement = (
<NoticePage
iconName="NoticePageAccessDeniedTeamsMeeting"
title={locale.strings.call.failedToJoinTeamsMeetingReasonAccessDeniedTitle}
moreDetails={locale.strings.call.failedToJoinTeamsMeetingReasonAccessDeniedMoreDetails}
dataUiId={'access-denied-teams-meeting-page'}
/* @conditional-compile-remove(end-of-call-survey) */
surveyOptions={{ disableSurvey: true }}
/>
);
break;
case 'removedFromCall':
pageElement = (
<NoticePage
iconName="NoticePageRemovedFromCall"
title={locale.strings.call.removedFromCallTitle}
moreDetails={locale.strings.call.removedFromCallMoreDetails}
dataUiId={'removed-from-call-page'}
/* @conditional-compile-remove(end-of-call-survey) */
surveyOptions={{ disableSurvey: true }}
/>
);
break;
case 'joinCallFailedDueToNoNetwork':
pageElement = (
<NoticePage
iconName="NoticePageJoinCallFailedDueToNoNetwork"
title={locale.strings.call.failedToJoinCallDueToNoNetworkTitle}
moreDetails={locale.strings.call.failedToJoinCallDueToNoNetworkMoreDetails}
dataUiId={'join-call-failed-due-to-no-network-page'}
/* @conditional-compile-remove(end-of-call-survey) */
surveyOptions={{ disableSurvey: true }}
/>
);
break;
case 'leaving':
pageElement = (
<NoticePage
title={locale.strings.call.leavingCallTitle ?? 'Leaving...'}
dataUiId={'leaving-page'}
pageStyle={leavePageStyle}
disableStartCallButton={true}
/* @conditional-compile-remove(end-of-call-survey) */
surveyOptions={{ disableSurvey: true }}
/>
);
break;
case 'leftCall': {
const { title, moreDetails, disableStartCallButton, iconName } = getEndedCallPageProps(locale, endedCall);
pageElement = (
<NoticePage
iconName={iconName}
title={title}
moreDetails={moreDetails}
dataUiId={'left-call-page'}
disableStartCallButton={disableStartCallButton}
/* @conditional-compile-remove(end-of-call-survey) */
surveyOptions={props.options?.surveyOptions}
/>
);
break;
}
case 'lobby':
pageElement = (
<LobbyPage
mobileView={props.mobileView}
modalLayerHostId={props.modalLayerHostId}
options={props.options}
updateSidePaneRenderer={setSidePaneRenderer}
mobileChatTabHeader={props.mobileChatTabHeader}
latestErrors={latestErrors}
onDismissError={onDismissError}
/* @conditional-compile-remove(capabilities) */
capabilitiesChangedNotificationBarProps={capabilitiesChangedNotificationBarProps}
/>
);
break;
/* @conditional-compile-remove(call-transfer) */
case 'transferring':
pageElement = (
<TransferPage
mobileView={props.mobileView}
modalLayerHostId={props.modalLayerHostId}
options={props.options}
updateSidePaneRenderer={setSidePaneRenderer}
mobileChatTabHeader={props.mobileChatTabHeader}
onFetchAvatarPersonaData={onFetchAvatarPersonaData}
latestErrors={latestErrors}
onDismissError={onDismissError}
/* @conditional-compile-remove(capabilities) */
capabilitiesChangedNotificationBarProps={capabilitiesChangedNotificationBarProps}
/>
);
break;
case 'call':
pageElement = (
<CallPage
callInvitationURL={callInvitationUrl}
onFetchAvatarPersonaData={onFetchAvatarPersonaData}
onFetchParticipantMenuItems={onFetchParticipantMenuItems}
mobileView={props.mobileView}
modalLayerHostId={props.modalLayerHostId}
options={props.options}
updateSidePaneRenderer={setSidePaneRenderer}
mobileChatTabHeader={props.mobileChatTabHeader}
onCloseChatPane={props.onCloseChatPane}
latestErrors={latestErrors}
onDismissError={onDismissError}
/* @conditional-compile-remove(gallery-layouts) */
galleryLayout={userSetGalleryLayout}
/* @conditional-compile-remove(gallery-layouts) */
onUserSetGalleryLayoutChange={setUserSetGalleryLayout}
/* @conditional-compile-remove(gallery-layouts) */
onSetUserSetOverflowGalleryPosition={setUserSetOverflowGalleryPosition}
/* @conditional-compile-remove(gallery-layouts) */
userSetOverflowGalleryPosition={userSetOverflowGalleryPosition}
/* @conditional-compile-remove(capabilities) */
capabilitiesChangedNotificationBarProps={capabilitiesChangedNotificationBarProps}
/* @conditional-compile-remove(dtmf-dialer) */
onSetDialpadPage={() => setDialpadScreen(!dialpadScreen)}
/>
);
break;
/* @conditional-compile-remove(PSTN-calls) */ /* @conditional-compile-remove(one-to-n-calling) */
case 'hold':
pageElement = (
<>
{
<HoldPage
mobileView={props.mobileView}
modalLayerHostId={props.modalLayerHostId}
options={props.options}
updateSidePaneRenderer={setSidePaneRenderer}
mobileChatTabHeader={props.mobileChatTabHeader}
latestErrors={latestErrors}
onDismissError={onDismissError}
/* @conditional-compile-remove(capabilities) */
capabilitiesChangedNotificationBarProps={capabilitiesChangedNotificationBarProps}
/>
}
</>
);
break;
}
useEndedCallConsoleErrors(endedCall);
/* @conditional-compile-remove(unsupported-browser) */
switch (page) {
case 'unsupportedEnvironment':
pageElement = (
<>
{
/* @conditional-compile-remove(unsupported-browser) */
<UnsupportedBrowserPage
onTroubleshootingClick={props.options?.onEnvironmentInfoTroubleshootingClick}
environmentInfo={adapter.getState().environmentInfo}
/>
}
</>
);
break;
}
/* @conditional-compile-remove(dtmf-dialer) */
if (dialpadScreen) {
pageElement = (
<>
<DtmfDialpadPage
mobileView={props.mobileView}
modalLayerHostId={props.modalLayerHostId}
options={props.options}
updateSidePaneRenderer={setSidePaneRenderer}
mobileChatTabHeader={props.mobileChatTabHeader}
latestErrors={latestErrors}
onDismissError={onDismissError}
/* @conditional-compile-remove(capabilities) */
capabilitiesChangedNotificationBarProps={capabilitiesChangedNotificationBarProps}
onSetDialpadPage={() => setDialpadScreen(!dialpadScreen)}
/>
</>
);
}
if (!pageElement) {
throw new Error('Invalid call composite page');
}
return (
<SidePaneProvider sidePaneRenderer={sidePaneRenderer} overrideSidePane={injectedSidePaneProps}>
{pageElement}
</SidePaneProvider>
);
};
/**
* A customizable UI composite for calling experience.
*
* @remarks Call composite min width/height are as follow:
* - mobile: 17.5rem x 21rem (280px x 336px, with default rem at 16px)
* - desktop: 30rem x 22rem (480px x 352px, with default rem at 16px)
*
* @public
*/
export const CallComposite = (props: CallCompositeProps): JSX.Element => <CallCompositeInner {...props} />;
/**
* @private
*/
export interface InternalCallCompositeProps {
overrideSidePane?: InjectedSidePaneProps;
onSidePaneIdChange?: (sidePaneId: string | undefined) => void;
onCloseChatPane?: () => void;
// legacy property to avoid breaking change
mobileChatTabHeader?: MobileChatSidePaneTabHeaderProps;
}
/** @private */
export const CallCompositeInner = (props: CallCompositeProps & InternalCallCompositeProps): JSX.Element => {
const {
adapter,
callInvitationUrl,
onFetchAvatarPersonaData,
onFetchParticipantMenuItems,
options,
formFactor = 'desktop'
} = props;
const mobileView = formFactor === 'mobile';
const modalLayerHostId = useId('modalLayerhost');
const mainScreenContainerClassName = useMemo(() => {
return mobileView ? mainScreenContainerStyleMobile : mainScreenContainerStyleDesktop;
}, [mobileView]);
return (
<div className={mainScreenContainerClassName}>
<BaseProvider {...props}>
<CallAdapterProvider adapter={adapter}>
<MainScreen
callInvitationUrl={callInvitationUrl}
onFetchAvatarPersonaData={onFetchAvatarPersonaData}
onFetchParticipantMenuItems={onFetchParticipantMenuItems}
mobileView={mobileView}
modalLayerHostId={modalLayerHostId}
options={options}
onSidePaneIdChange={props.onSidePaneIdChange}
overrideSidePane={props.overrideSidePane}
mobileChatTabHeader={props.mobileChatTabHeader}
onCloseChatPane={props.onCloseChatPane}
/>
{
// This layer host is for ModalLocalAndRemotePIP in SidePane. This LayerHost cannot be inside the SidePane
// because when the SidePane is hidden, ie. style property display is 'none', it takes up no space. This causes problems when dragging
// the Modal because the draggable bounds thinks it has no space and will always return to its initial position after dragging.
// Additionally, this layer host cannot be in the Call Arrangement as it needs to be rendered before useMinMaxDragPosition() in
// common/utils useRef is called.
// Warning: this is fragile and works because the call arrangement page is only rendered after the call has connected and thus this
// LayerHost will be guaranteed to have rendered (and subsequently mounted in the DOM). This ensures the DOM element will be available
// before the call to `document.getElementById(modalLayerHostId)` is made.
<LayerHost id={modalLayerHostId} className={mergeStyles(modalLayerHostStyle)} />
}
</CallAdapterProvider>
</BaseProvider>
</div>
);
};
const getQueryOptions = (options: {
/* @conditional-compile-remove(rooms) */ role?: ParticipantRole;
}): PermissionConstraints => {
/* @conditional-compile-remove(rooms) */
if (options.role === 'Consumer') {
return {
video: false,
audio: true
};
}
return { video: true, audio: true };
};