-
Notifications
You must be signed in to change notification settings - Fork 18
/
OutgoingCall.tsx
162 lines (153 loc) · 4.25 KB
/
OutgoingCall.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
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
import React from 'react';
import { StyleSheet, Text, View, ViewStyle } from 'react-native';
import { UserInfo } from './UserInfo';
import { Z_INDEX } from '../../../constants';
import { useCallStateHooks, useI18n } from '@stream-io/video-react-bindings';
import { MediaStream, RTCView } from '@stream-io/react-native-webrtc';
import { useTheme } from '../../../contexts/ThemeContext';
import {
OutgoingCallControls as DefaultOutgoingCallControls,
OutgoingCallControlsProps,
} from '../CallControls';
import {
CallTopView as DefaultCallTopView,
CallTopViewProps,
} from '../CallTopView';
import { useCallMediaStreamCleanup } from '../../../hooks/internal/useCallMediaStreamCleanup';
import { useApplyDefaultMediaStreamSettings } from '../../../hooks/useApplyDefaultMediaStreamSettings';
/**
* Props for the OutgoingCall Component.
*/
export type OutgoingCallProps = OutgoingCallControlsProps & {
/**
* Prop to customize the CallTopView component in the IncomingCall component.
*/
CallTopView?: React.ComponentType<CallTopViewProps> | null;
/**
* Prop to customize the OutgoingCall controls.
*/
OutgoingCallControls?: React.ComponentType<OutgoingCallControlsProps> | null;
/**
* Check if device is in landscape mode.
* This will apply the landscape mode styles to the component.
*/
landscape?: boolean;
};
/**
* An outgoing call with the callee's avatar, name, caller's camera in background, reject and mute buttons.
* Used after the user has initiated a call.
*/
export const OutgoingCall = ({
CallTopView = DefaultCallTopView,
OutgoingCallControls = DefaultOutgoingCallControls,
landscape,
}: OutgoingCallProps) => {
const {
theme: { colors, typefaces, outgoingCall },
} = useTheme();
const { t } = useI18n();
useApplyDefaultMediaStreamSettings();
useCallMediaStreamCleanup();
const landscapeContentStyles: ViewStyle = {
flexDirection: landscape ? 'row' : 'column',
};
return (
<>
<View
style={[
StyleSheet.absoluteFill,
styles.container,
outgoingCall.container,
]}
>
{CallTopView && <CallTopView />}
<View
style={[styles.content, landscapeContentStyles, outgoingCall.content]}
>
<View style={[styles.topContainer, outgoingCall.topContainer]}>
<UserInfo />
<Text
style={[
styles.callingText,
{ color: colors.static_white },
typefaces.heading6,
outgoingCall.callingText,
]}
>
{t('Calling...')}
</Text>
</View>
<View style={[styles.bottomContainer, outgoingCall.bottomContainer]}>
<View
style={[
styles.outgoingCallControls,
outgoingCall.outgoingCallControls,
]}
>
{OutgoingCallControls && <OutgoingCallControls />}
</View>
</View>
</View>
</View>
<Background />
</>
);
};
const Background = () => {
const {
theme: { colors, outgoingCall },
} = useTheme();
const { useCameraState } = useCallStateHooks();
const { isMute, camera } = useCameraState();
const localVideoStream = camera.state.mediaStream as unknown as
| MediaStream
| undefined;
if (isMute || !localVideoStream) {
return (
<View
style={[
styles.background,
{ backgroundColor: colors.static_grey },
outgoingCall.background,
]}
/>
);
}
return (
<View
style={[
styles.background,
{ backgroundColor: colors.static_grey },
outgoingCall.background,
]}
>
<RTCView
streamURL={localVideoStream.toURL()}
zOrder={Z_INDEX.IN_BACK}
style={StyleSheet.absoluteFill}
mirror
objectFit="cover"
/>
</View>
);
};
const styles = StyleSheet.create({
background: {
flex: 1,
},
container: {
zIndex: Z_INDEX.IN_MIDDLE,
},
topContainer: { flex: 1 },
content: {
flex: 1,
},
callingText: {
marginTop: 16,
textAlign: 'center',
},
bottomContainer: { flex: 1, alignSelf: 'center', justifyContent: 'center' },
outgoingCallControls: {
justifyContent: 'center',
},
});