-
Notifications
You must be signed in to change notification settings - Fork 78
Expand file tree
/
Copy pathDtmfDialpadPage.tsx
More file actions
126 lines (113 loc) · 4.43 KB
/
DtmfDialpadPage.tsx
File metadata and controls
126 lines (113 loc) · 4.43 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
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
import { ActiveErrorMessage, Dialpad, DtmfTone, ErrorBar } from '@internal/react-components';
import { MobileChatSidePaneTabHeaderProps } from '../../common/TabHeader';
import { CallCompositeOptions } from '../CallComposite';
import { SidePaneRenderer } from '../components/SidePane/SidePaneProvider';
import { CapabilitiesChangeNotificationBarProps } from '../components/CapabilitiesChangedNotificationBar';
import { usePropsFor } from '../hooks/usePropsFor';
import { useLocale } from '../../localization';
import { disableCallControls, reduceCallControlsForMobile } from '../utils';
import React, { useRef, useState } from 'react';
import { useAdapter } from '../adapter/CallAdapterProvider';
import { CallArrangement } from '../components/CallArrangement';
import { CommonCallAdapter } from '../adapter';
import { Stack, Text, useTheme } from '@fluentui/react';
import { getReadableTime } from '../utils/timerUtils';
import { DtmfDialpadContentTimerStyles } from '../styles/DtmfDialpadPage.styles';
/**
* @internal
*/
export interface DialpadPageProps {
mobileView: boolean;
options?: CallCompositeOptions;
modalLayerHostId: string;
updateSidePaneRenderer: (renderer: SidePaneRenderer | undefined) => void;
mobileChatTabHeader?: MobileChatSidePaneTabHeaderProps;
latestErrors: ActiveErrorMessage[];
onDismissError: (error: ActiveErrorMessage) => void;
/* @conditional-compile-remove(capabilities) */
capabilitiesChangedNotificationBarProps?: CapabilitiesChangeNotificationBarProps;
onSetDialpadPage: () => void;
}
interface DialpadPageContentProps {
mobileView: boolean;
adapter: CommonCallAdapter;
}
const DtmfDialpadPageContent = (props: DialpadPageContentProps): JSX.Element => {
const { adapter } = props;
const [time, setTime] = useState<number>(0);
const elapsedTime = getReadableTime(time);
const startTime = useRef(performance.now());
const adapterState = adapter.getState();
const theme = useTheme();
const calleeId = adapterState.targetCallees?.[0];
const remoteParticipants = adapterState.call?.remoteParticipants;
let calleeName;
if (remoteParticipants) {
calleeName = Object.values(remoteParticipants).find((p) => p.identifier === calleeId);
}
React.useEffect(() => {
const interval = setInterval(() => {
setTime(performance.now() - startTime.current);
}, 10);
return () => {
clearInterval(interval);
};
}, [startTime]);
return (
<Stack style={{ height: '100%', width: '100%', background: theme.palette.white }}>
<Stack style={{ margin: 'auto' }}>
<Text styles={DtmfDialpadContentTimerStyles}>{elapsedTime}</Text>
<Text>{calleeName !== 'Unnamed participant' ? calleeName : ''}</Text>
<Dialpad
onSendDtmfTone={async (tone: DtmfTone) => {
/* @conditional-compile-remove(dtmf-dialer) */
await adapter.sendDtmfTone(tone);
}}
enableInputEditing={false}
></Dialpad>
</Stack>
</Stack>
);
};
/**
* @internal
*/
export const DtmfDialpadPage = (props: DialpadPageProps): JSX.Element => {
const errorBarProps = usePropsFor(ErrorBar);
const strings = useLocale().strings.call;
const adapter = useAdapter();
let callControlOptions = props.mobileView
? reduceCallControlsForMobile(props.options?.callControls)
: props.options?.callControls;
callControlOptions = disableCallControls(callControlOptions, [
'cameraButton',
'microphoneButton',
'devicesButton',
'screenShareButton',
/* @conditional-compile-remove(PSTN-calls) */
/* @conditional-compile-remove(one-to-n-calling) */
'holdButton'
]);
return (
<CallArrangement
complianceBannerProps={{ strings }}
errorBarProps={props.options?.errorBar !== false && errorBarProps}
callControlProps={{
options: callControlOptions,
increaseFlyoutItemSize: props.mobileView
}}
mobileView={props.mobileView}
modalLayerHostId={props.modalLayerHostId}
onRenderGalleryContent={() => <DtmfDialpadPageContent adapter={adapter} mobileView={props.mobileView} />}
dataUiId={'hold-page'}
updateSidePaneRenderer={props.updateSidePaneRenderer}
mobileChatTabHeader={props.mobileChatTabHeader}
latestErrors={props.latestErrors}
onDismissError={props.onDismissError}
/* @conditional-compile-remove(dtmf-dialer) */
onSetDialpadPage={props.onSetDialpadPage}
/>
);
};