Skip to content

Commit 91e1934

Browse files
[DTMF DIaler] Fix Dialpad bugs (#4062)
* Fix Dialpad bugs * Change files * Duplicate change files for beta release * fix tab away sound keeps playing * fix cc * use correct key values * fix tests * use Call start time to track the call timer * fix lint * fix build
1 parent 823db51 commit 91e1934

8 files changed

Lines changed: 50 additions & 5 deletions

File tree

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"type": "prerelease",
3+
"area": "fix",
4+
"workstream": "DTMF Dialer",
5+
"comment": "Fix Dialpad bugs",
6+
"packageName": "@azure/communication-react",
7+
"email": "94866715+dmceachernmsft@users.noreply.github.com",
8+
"dependentChangeType": "patch"
9+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"type": "prerelease",
3+
"area": "fix",
4+
"workstream": "DTMF Dialer",
5+
"comment": "Fix Dialpad bugs",
6+
"packageName": "@azure/communication-react",
7+
"email": "94866715+dmceachernmsft@users.noreply.github.com",
8+
"dependentChangeType": "patch"
9+
}

packages/react-components/src/components/Dialpad/Dialpad.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,15 @@ const DialpadButton = (props: {
220220
setButtonPressed(true);
221221
return;
222222
}
223+
if (
224+
e.key === 'Tab' ||
225+
e.key === 'ArrowLeft' ||
226+
e.key === 'ArrowRight' ||
227+
e.key === 'ArrowUp' ||
228+
e.key === 'ArrowDown'
229+
) {
230+
dtmfToneSound.current.stop();
231+
}
223232
longPressHandlers.onKeyDown();
224233
}}
225234
onKeyUp={(e) => {

packages/react-components/src/components/utils/useLongPress.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,11 @@ export default function useLongPress(props: {
9090
}, [startPressTimer]);
9191

9292
const handleOnTouchEnd = useCallback(() => {
93+
if (!isLongPress && onClick) {
94+
onClick();
95+
}
9396
timerRef.current && clearTimeout(timerRef.current);
94-
}, []);
97+
}, [onClick, isLongPress]);
9598

9699
const handleOnTouchMove = useCallback(() => {
97100
timerRef.current && clearTimeout(timerRef.current);

packages/react-composites/src/composites/CallComposite/CallComposite.test.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ import { _MockCallAdapter } from './MockCallAdapter';
77
import { CallComposite } from './CallComposite';
88
import { render } from '@testing-library/react';
99

10+
window.AudioContext = jest.fn().mockImplementation(() => {
11+
return {};
12+
});
13+
1014
describe('CallComposite device permission test for different roles', () => {
1115
let audioDevicePermissionRequests = 0;
1216
let videoDevicePermissionRequests = 0;

packages/react-composites/src/composites/CallComposite/pages/DtmfDialpadPage.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,16 @@ import { MobileChatSidePaneTabHeaderProps } from '../../common/TabHeader';
66
import { CallCompositeOptions } from '../CallComposite';
77
import { SidePaneRenderer } from '../components/SidePane/SidePaneProvider';
88
import { CapabilitiesChangeNotificationBarProps } from '../components/CapabilitiesChangedNotificationBar';
9-
import React, { useEffect, useRef, useState } from 'react';
9+
import React, { useEffect, useMemo, useState } from 'react';
1010
import { useAdapter } from '../adapter/CallAdapterProvider';
1111
import { CommonCallAdapter } from '../adapter';
1212
import { Stack, Text, useTheme } from '@fluentui/react';
1313
import { getReadableTime } from '../utils/timerUtils';
1414
import { DtmfDialpadContentTimerStyles } from '../styles/DtmfDialpadPage.styles';
1515
import { RemoteParticipantState } from '@internal/calling-stateful-client';
1616
import { isPhoneNumberIdentifier } from '@azure/communication-common';
17+
import { useSelector } from '../hooks/useSelector';
18+
import { getStartTime } from '../selectors/baseSelectors';
1719

1820
/**
1921
* @internal
@@ -65,6 +67,7 @@ const DtmfDialpadPageContent = (props: DialpadPageContentProps): JSX.Element =>
6567
/* @conditional-compile-remove(dtmf-dialer) */
6668
await adapter.sendDtmfTone(tone);
6769
}}
70+
isMobile={props.mobileView}
6871
dialpadMode={'dtmf'}
6972
></Dialpad>
7073
</Stack>
@@ -75,11 +78,14 @@ const DtmfDialpadPageContent = (props: DialpadPageContentProps): JSX.Element =>
7578
const DtmfDialerContentTimer = (): JSX.Element => {
7679
const [time, setTime] = useState<number>(0);
7780
const elapsedTime = getReadableTime(time);
78-
const startTime = useRef(performance.now());
81+
const statefulStartTime = useSelector(getStartTime);
82+
const startTime = useMemo(() => {
83+
return statefulStartTime ?? new Date(Date.now());
84+
}, [statefulStartTime]);
7985

8086
useEffect(() => {
8187
const interval = setInterval(() => {
82-
setTime(performance.now() - startTime.current);
88+
setTime(new Date(Date.now()).getTime() - startTime?.getTime() ?? 0);
8389
}, 10);
8490
return () => {
8591
clearInterval(interval);

packages/react-composites/src/composites/CallComposite/selectors/baseSelectors.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,3 +219,8 @@ export const getLatestCapabilitiesChangedInfo = (state: CallAdapterState): Capab
219219
* @private
220220
*/
221221
export const getTargetCallees = (state: CallAdapterState): CommunicationIdentifier[] | undefined => state.targetCallees;
222+
223+
/**
224+
* @private
225+
*/
226+
export const getStartTime = (state: CallAdapterState): Date | undefined => state.call?.startTime;

packages/react-composites/src/composites/common/AddPeopleDropdown.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ export const AddPeopleDropdown = (props: AddPeopleDropdownProps): JSX.Element =>
149149
)}
150150
{alternateCallerId && (
151151
<CallingDialpad
152-
isMobile
152+
isMobile={true}
153153
strings={strings}
154154
showDialpad={showDialpad}
155155
onDismissDialpad={onDismissDialpad}

0 commit comments

Comments
 (0)