-
Notifications
You must be signed in to change notification settings - Fork 18
/
RejectCallButton.tsx
75 lines (72 loc) · 1.95 KB
/
RejectCallButton.tsx
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
import { useCall, useCallStateHooks } from '@stream-io/video-react-bindings';
import React from 'react';
import { CallControlsButton } from './CallControlsButton';
import { PhoneDown } from '../../../icons';
import { CallingState, getLogger } from '@stream-io/video-client';
import { useTheme } from '../../../contexts/ThemeContext';
/**
* The props for the Reject Call button.
*/
type RejectCallButtonProps = {
/**
* Handler to be called when the accept call button is pressed.
* @returns void
*/
onPressHandler?: () => void;
/**
* Handler to be called when the reject call button is pressed.
*
* Note: If the `onPressHandler` is passed this handler will not be executed.
*/
onRejectCallHandler?: () => void;
};
/**
* Button to reject a call.
*
* Mostly calls call.leave({ reject: true }) internally.
*/
export const RejectCallButton = ({
onPressHandler,
onRejectCallHandler,
}: RejectCallButtonProps) => {
const call = useCall();
const { useCallCallingState } = useCallStateHooks();
const callingState = useCallCallingState();
const {
theme: {
colors,
rejectCallButton,
variants: { buttonSizes },
},
} = useTheme();
const rejectCallHandler = async () => {
if (onPressHandler) {
onPressHandler();
return;
}
try {
if (callingState === CallingState.LEFT) {
return;
}
await call?.leave({ reject: true });
if (onRejectCallHandler) {
onRejectCallHandler();
}
} catch (error) {
const logger = getLogger(['RejectCallButton']);
logger('error', 'Error rejecting Call', error);
}
};
return (
<CallControlsButton
onPress={rejectCallHandler}
color={colors.error}
size={buttonSizes.lg}
// TODO: check what to do about this random style prop
// svgContainerStyle={theme.icon.lg}
style={rejectCallButton}
>
<PhoneDown color={colors.static_white} />
</CallControlsButton>
);
};