react-native-visit-rn-sdk 6.0.2 → 6.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +45 -14
- package/lib/commonjs/components/VideoCallComponent.js +11 -16
- package/lib/commonjs/components/VideoCallComponent.js.map +1 -1
- package/lib/commonjs/index.android.js +43 -13
- package/lib/commonjs/index.android.js.map +1 -1
- package/lib/commonjs/index.ios.js +73 -37
- package/lib/commonjs/index.ios.js.map +1 -1
- package/lib/commonjs/index.js +6 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/shims.d.js +2 -0
- package/lib/commonjs/shims.d.js.map +1 -0
- package/lib/commonjs/types.js +2 -0
- package/lib/commonjs/types.js.map +1 -0
- package/lib/module/components/VideoCallComponent.js +11 -16
- package/lib/module/components/VideoCallComponent.js.map +1 -1
- package/lib/module/index.android.js +44 -14
- package/lib/module/index.android.js.map +1 -1
- package/lib/module/index.ios.js +74 -38
- package/lib/module/index.ios.js.map +1 -1
- package/lib/module/index.js +2 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/shims.d.js +2 -0
- package/lib/module/shims.d.js.map +1 -0
- package/lib/module/types.js +2 -0
- package/lib/module/types.js.map +1 -0
- package/lib/typescript/components/VideoCallComponent.d.ts +77 -2
- package/lib/typescript/components/VideoCallComponent.d.ts.map +1 -1
- package/lib/typescript/index.android.d.ts +3 -11
- package/lib/typescript/index.android.d.ts.map +1 -1
- package/lib/typescript/index.d.ts +17 -0
- package/lib/typescript/index.d.ts.map +1 -0
- package/lib/typescript/index.ios.d.ts +3 -11
- package/lib/typescript/index.ios.d.ts.map +1 -1
- package/lib/typescript/types.d.ts +24 -0
- package/lib/typescript/types.d.ts.map +1 -0
- package/package.json +11 -7
- package/src/components/VideoCallComponent.tsx +1484 -0
- package/src/index.android.tsx +459 -0
- package/src/index.ios.tsx +238 -0
- package/src/index.tsx +25 -0
- package/src/shims.d.ts +49 -0
- package/src/types.ts +25 -0
- package/src/components/VideoCallComponent.js +0 -1305
- package/src/index.android.js +0 -362
- package/src/index.ios.js +0 -157
|
@@ -1,1305 +0,0 @@
|
|
|
1
|
-
import React, {
|
|
2
|
-
forwardRef,
|
|
3
|
-
useCallback,
|
|
4
|
-
useEffect,
|
|
5
|
-
useImperativeHandle,
|
|
6
|
-
useRef,
|
|
7
|
-
useState,
|
|
8
|
-
} from 'react';
|
|
9
|
-
import {
|
|
10
|
-
Alert,
|
|
11
|
-
Animated,
|
|
12
|
-
Dimensions,
|
|
13
|
-
Image,
|
|
14
|
-
LayoutAnimation,
|
|
15
|
-
Linking,
|
|
16
|
-
PanResponder,
|
|
17
|
-
PermissionsAndroid,
|
|
18
|
-
Platform,
|
|
19
|
-
Pressable,
|
|
20
|
-
StatusBar,
|
|
21
|
-
StyleSheet,
|
|
22
|
-
Text,
|
|
23
|
-
TouchableOpacity,
|
|
24
|
-
UIManager,
|
|
25
|
-
View,
|
|
26
|
-
} from 'react-native';
|
|
27
|
-
import {
|
|
28
|
-
TwilioVideo,
|
|
29
|
-
TwilioVideoLocalView,
|
|
30
|
-
TwilioVideoParticipantView,
|
|
31
|
-
} from '@twilio/video-react-native-sdk';
|
|
32
|
-
|
|
33
|
-
const { width: SCREEN_WIDTH, height: SCREEN_HEIGHT } = Dimensions.get('screen');
|
|
34
|
-
const LOCAL_PREVIEW_WIDTH = 120;
|
|
35
|
-
const LOCAL_PREVIEW_HEIGHT = 180;
|
|
36
|
-
const LOCAL_PREVIEW_SIDE_MARGIN = 16;
|
|
37
|
-
const LOCAL_PREVIEW_MAX_BOTTOM_OFFSET = 224;
|
|
38
|
-
const LOCAL_PREVIEW_BOTTOM_DRAG_ALLOWANCE = 56;
|
|
39
|
-
const VIDEO_CALL_ERROR_STATUS = Object.freeze({
|
|
40
|
-
MISSING_ROOM_NAME_OR_ACCESS_TOKEN: 'MISSING_ROOM_NAME_OR_ACCESS_TOKEN',
|
|
41
|
-
PERMISSIONS_REQUIRED: 'PERMISSIONS_REQUIRED',
|
|
42
|
-
PERMISSION_CHECK_FAILED: 'PERMISSION_CHECK_FAILED',
|
|
43
|
-
INVALID_OR_EXPIRED_TOKEN: 'INVALID_OR_EXPIRED_TOKEN',
|
|
44
|
-
CONNECT_FAILED: 'CONNECT_FAILED',
|
|
45
|
-
});
|
|
46
|
-
const ICONS = {
|
|
47
|
-
mute: require('../assets/video-call/mic-off.png'),
|
|
48
|
-
videoOff: require('../assets/video-call/video-off.png'),
|
|
49
|
-
flip: require('../assets/video-call/switch-camera.png'),
|
|
50
|
-
end: require('../assets/video-call/end-call.png'),
|
|
51
|
-
connecting: require('../assets/video-call/connecting-lottie.gif'),
|
|
52
|
-
reconnecting: require('../assets/video-call/reconnecting.gif'),
|
|
53
|
-
toggleUp: require('../assets/video-call/toggle-up.png'),
|
|
54
|
-
toggleDown: require('../assets/video-call/toggle-down.png'),
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
const initialCallState = {
|
|
58
|
-
isVisible: false,
|
|
59
|
-
loading: false,
|
|
60
|
-
status: 'idle',
|
|
61
|
-
roomName: '',
|
|
62
|
-
accessToken: '',
|
|
63
|
-
remoteTrackSid: '',
|
|
64
|
-
remoteTrackIdentifier: null,
|
|
65
|
-
participantVideoEnabled: false,
|
|
66
|
-
participantAudioEnabled: true,
|
|
67
|
-
isMuted: false,
|
|
68
|
-
isVideoEnabled: true,
|
|
69
|
-
isFrontCameraEnabled: true,
|
|
70
|
-
signalStrength: null,
|
|
71
|
-
participantSignalStrength: null,
|
|
72
|
-
showLowSignalStrengthMessage: false,
|
|
73
|
-
showParticipantReconnectingScreen: false,
|
|
74
|
-
showUserReconnectingScreen: false,
|
|
75
|
-
showBottomBar: true,
|
|
76
|
-
durationMins: '00',
|
|
77
|
-
durationSecs: '00',
|
|
78
|
-
doctorName: '',
|
|
79
|
-
visibleDoctorName: '',
|
|
80
|
-
userName: '',
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
const VideoCallComponent = forwardRef(
|
|
84
|
-
(
|
|
85
|
-
{
|
|
86
|
-
onCallConnected,
|
|
87
|
-
onCallEnded,
|
|
88
|
-
onError,
|
|
89
|
-
onLowNetworkQuality,
|
|
90
|
-
onStateChange,
|
|
91
|
-
style,
|
|
92
|
-
},
|
|
93
|
-
ref
|
|
94
|
-
) => {
|
|
95
|
-
const twilioVideoRef = useRef(null);
|
|
96
|
-
const durationTimerRef = useRef(null);
|
|
97
|
-
const timerRunningRef = useRef(false);
|
|
98
|
-
const reconnectingTimerRef = useRef(null);
|
|
99
|
-
const localPreviewRefreshTimeoutRef = useRef(null);
|
|
100
|
-
const localPreviewSecondRefreshTimeoutRef = useRef(null);
|
|
101
|
-
const localPreviewDrag = useRef(new Animated.ValueXY({ x: 0, y: 0 })).current;
|
|
102
|
-
const localPreviewDragOffsetRef = useRef({ x: 0, y: 0 });
|
|
103
|
-
const callRef = useRef({ roomJoined: false, unmounted: false });
|
|
104
|
-
callRef.current.onCallEnded = onCallEnded;
|
|
105
|
-
const [state, setState] = useState(initialCallState);
|
|
106
|
-
const [localPreviewRefreshKey, setLocalPreviewRefreshKey] = useState(0);
|
|
107
|
-
|
|
108
|
-
const maxHorizontalDrag = SCREEN_WIDTH - LOCAL_PREVIEW_WIDTH - LOCAL_PREVIEW_SIDE_MARGIN * 2;
|
|
109
|
-
const maxUpwardDrag = Math.max(
|
|
110
|
-
0,
|
|
111
|
-
SCREEN_HEIGHT - LOCAL_PREVIEW_HEIGHT - LOCAL_PREVIEW_MAX_BOTTOM_OFFSET
|
|
112
|
-
);
|
|
113
|
-
const maxDownwardDrag = LOCAL_PREVIEW_BOTTOM_DRAG_ALLOWANCE;
|
|
114
|
-
const clampDrag = useCallback((value, min, max) => Math.min(Math.max(value, min), max), []);
|
|
115
|
-
|
|
116
|
-
const localPreviewPanResponder = useRef(
|
|
117
|
-
PanResponder.create({
|
|
118
|
-
onMoveShouldSetPanResponder: (_, gestureState) =>
|
|
119
|
-
Math.abs(gestureState.dx) > 2 || Math.abs(gestureState.dy) > 2,
|
|
120
|
-
onPanResponderMove: (_, gestureState) => {
|
|
121
|
-
const nextX = clampDrag(
|
|
122
|
-
localPreviewDragOffsetRef.current.x + gestureState.dx,
|
|
123
|
-
-maxHorizontalDrag,
|
|
124
|
-
0
|
|
125
|
-
);
|
|
126
|
-
const nextY = clampDrag(
|
|
127
|
-
localPreviewDragOffsetRef.current.y + gestureState.dy,
|
|
128
|
-
-maxUpwardDrag,
|
|
129
|
-
maxDownwardDrag
|
|
130
|
-
);
|
|
131
|
-
localPreviewDrag.setValue({ x: nextX, y: nextY });
|
|
132
|
-
},
|
|
133
|
-
onPanResponderRelease: (_, gestureState) => {
|
|
134
|
-
const nextX = clampDrag(
|
|
135
|
-
localPreviewDragOffsetRef.current.x + gestureState.dx,
|
|
136
|
-
-maxHorizontalDrag,
|
|
137
|
-
0
|
|
138
|
-
);
|
|
139
|
-
const nextY = clampDrag(
|
|
140
|
-
localPreviewDragOffsetRef.current.y + gestureState.dy,
|
|
141
|
-
-maxUpwardDrag,
|
|
142
|
-
maxDownwardDrag
|
|
143
|
-
);
|
|
144
|
-
localPreviewDragOffsetRef.current = { x: nextX, y: nextY };
|
|
145
|
-
localPreviewDrag.setValue(localPreviewDragOffsetRef.current);
|
|
146
|
-
},
|
|
147
|
-
})
|
|
148
|
-
).current;
|
|
149
|
-
|
|
150
|
-
useEffect(() => {
|
|
151
|
-
if (Platform.OS === 'android' && UIManager.setLayoutAnimationEnabledExperimental) {
|
|
152
|
-
UIManager.setLayoutAnimationEnabledExperimental(true);
|
|
153
|
-
}
|
|
154
|
-
}, []);
|
|
155
|
-
|
|
156
|
-
const clearDurationTimer = useCallback(() => {
|
|
157
|
-
timerRunningRef.current = false;
|
|
158
|
-
if (durationTimerRef.current) {
|
|
159
|
-
clearInterval(durationTimerRef.current);
|
|
160
|
-
durationTimerRef.current = null;
|
|
161
|
-
}
|
|
162
|
-
}, []);
|
|
163
|
-
|
|
164
|
-
const clearReconnectTimer = useCallback(() => {
|
|
165
|
-
if (reconnectingTimerRef.current) {
|
|
166
|
-
clearInterval(reconnectingTimerRef.current);
|
|
167
|
-
reconnectingTimerRef.current = null;
|
|
168
|
-
}
|
|
169
|
-
}, []);
|
|
170
|
-
|
|
171
|
-
const clearLocalPreviewRefreshTimers = useCallback(() => {
|
|
172
|
-
if (localPreviewRefreshTimeoutRef.current) {
|
|
173
|
-
clearTimeout(localPreviewRefreshTimeoutRef.current);
|
|
174
|
-
localPreviewRefreshTimeoutRef.current = null;
|
|
175
|
-
}
|
|
176
|
-
if (localPreviewSecondRefreshTimeoutRef.current) {
|
|
177
|
-
clearTimeout(localPreviewSecondRefreshTimeoutRef.current);
|
|
178
|
-
localPreviewSecondRefreshTimeoutRef.current = null;
|
|
179
|
-
}
|
|
180
|
-
}, []);
|
|
181
|
-
|
|
182
|
-
const refreshLocalPreview = useCallback(() => {
|
|
183
|
-
setLocalPreviewRefreshKey((prev) => prev + 1);
|
|
184
|
-
}, []);
|
|
185
|
-
|
|
186
|
-
const emitState = useCallback(
|
|
187
|
-
(nextState) => {
|
|
188
|
-
if (onStateChange) {
|
|
189
|
-
onStateChange(nextState);
|
|
190
|
-
}
|
|
191
|
-
},
|
|
192
|
-
[onStateChange]
|
|
193
|
-
);
|
|
194
|
-
|
|
195
|
-
const emitErrorStatus = useCallback(
|
|
196
|
-
(status, error, metadata = {}) => {
|
|
197
|
-
if (!onError) {
|
|
198
|
-
return;
|
|
199
|
-
}
|
|
200
|
-
onError({
|
|
201
|
-
status,
|
|
202
|
-
error,
|
|
203
|
-
metadata,
|
|
204
|
-
});
|
|
205
|
-
},
|
|
206
|
-
[onError]
|
|
207
|
-
);
|
|
208
|
-
|
|
209
|
-
const updateState = useCallback(
|
|
210
|
-
(updater) => {
|
|
211
|
-
setState((prev) => {
|
|
212
|
-
const next =
|
|
213
|
-
typeof updater === 'function' ? updater(prev) : { ...prev, ...updater };
|
|
214
|
-
emitState(next);
|
|
215
|
-
return next;
|
|
216
|
-
});
|
|
217
|
-
},
|
|
218
|
-
[emitState]
|
|
219
|
-
);
|
|
220
|
-
|
|
221
|
-
const resetToInitial = useCallback(() => {
|
|
222
|
-
clearDurationTimer();
|
|
223
|
-
clearReconnectTimer();
|
|
224
|
-
clearLocalPreviewRefreshTimers();
|
|
225
|
-
setState(initialCallState);
|
|
226
|
-
emitState(initialCallState);
|
|
227
|
-
}, [clearDurationTimer, clearReconnectTimer, clearLocalPreviewRefreshTimers, emitState]);
|
|
228
|
-
|
|
229
|
-
const leaveVideo = useCallback(
|
|
230
|
-
(reason, error) => {
|
|
231
|
-
clearDurationTimer();
|
|
232
|
-
clearReconnectTimer();
|
|
233
|
-
clearLocalPreviewRefreshTimers();
|
|
234
|
-
if (callRef.current.unmounted) {
|
|
235
|
-
return;
|
|
236
|
-
}
|
|
237
|
-
callRef.current.roomJoined = false;
|
|
238
|
-
setState((prev) => {
|
|
239
|
-
const finalState = JSON.parse(JSON.stringify(initialCallState));
|
|
240
|
-
emitState(finalState);
|
|
241
|
-
return finalState;
|
|
242
|
-
});
|
|
243
|
-
if (onCallEnded) {
|
|
244
|
-
onCallEnded({ reason, error });
|
|
245
|
-
}
|
|
246
|
-
},
|
|
247
|
-
[
|
|
248
|
-
clearDurationTimer,
|
|
249
|
-
clearReconnectTimer,
|
|
250
|
-
clearLocalPreviewRefreshTimers,
|
|
251
|
-
emitState,
|
|
252
|
-
onCallEnded,
|
|
253
|
-
]
|
|
254
|
-
);
|
|
255
|
-
|
|
256
|
-
const startDurationTimer = useCallback(() => {
|
|
257
|
-
timerRunningRef.current = true;
|
|
258
|
-
if (durationTimerRef.current) {
|
|
259
|
-
return;
|
|
260
|
-
}
|
|
261
|
-
durationTimerRef.current = setInterval(() => {
|
|
262
|
-
if (!timerRunningRef.current) {
|
|
263
|
-
return;
|
|
264
|
-
}
|
|
265
|
-
updateState((prev) => {
|
|
266
|
-
let secs = parseInt(prev.durationSecs, 10) + 1;
|
|
267
|
-
let mins = parseInt(prev.durationMins, 10);
|
|
268
|
-
if (secs >= 60) {
|
|
269
|
-
mins += 1;
|
|
270
|
-
secs = 0;
|
|
271
|
-
}
|
|
272
|
-
return {
|
|
273
|
-
...prev,
|
|
274
|
-
durationMins: mins < 10 ? `0${mins}` : String(mins),
|
|
275
|
-
durationSecs: secs < 10 ? `0${secs}` : String(secs),
|
|
276
|
-
};
|
|
277
|
-
});
|
|
278
|
-
}, 1000);
|
|
279
|
-
}, [updateState]);
|
|
280
|
-
|
|
281
|
-
const checkAndroidVideoPermissions = useCallback(async () => {
|
|
282
|
-
if (Platform.OS !== 'android') {
|
|
283
|
-
return true;
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
try {
|
|
287
|
-
const cameraPermission = PermissionsAndroid.PERMISSIONS.CAMERA;
|
|
288
|
-
const micPermission = PermissionsAndroid.PERMISSIONS.RECORD_AUDIO;
|
|
289
|
-
|
|
290
|
-
const hasCamera = await PermissionsAndroid.check(cameraPermission);
|
|
291
|
-
const hasMic = await PermissionsAndroid.check(micPermission);
|
|
292
|
-
if (hasCamera && hasMic) {
|
|
293
|
-
return true;
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
const permissionResults = await PermissionsAndroid.requestMultiple([
|
|
297
|
-
cameraPermission,
|
|
298
|
-
micPermission,
|
|
299
|
-
]);
|
|
300
|
-
const isCameraGranted =
|
|
301
|
-
permissionResults[cameraPermission] === PermissionsAndroid.RESULTS.GRANTED;
|
|
302
|
-
const isMicGranted =
|
|
303
|
-
permissionResults[micPermission] === PermissionsAndroid.RESULTS.GRANTED;
|
|
304
|
-
if (isCameraGranted && isMicGranted) {
|
|
305
|
-
return true;
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
const missing = [];
|
|
309
|
-
if (!isCameraGranted) {
|
|
310
|
-
missing.push('camera');
|
|
311
|
-
}
|
|
312
|
-
if (!isMicGranted) {
|
|
313
|
-
missing.push('microphone');
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
Alert.alert(
|
|
317
|
-
'Permissions required',
|
|
318
|
-
`Please allow ${missing.join(' and ')} access to start a video call. You can enable this in Settings.`,
|
|
319
|
-
[
|
|
320
|
-
{ text: 'Cancel', style: 'cancel' },
|
|
321
|
-
{ text: 'Open Settings', onPress: () => Linking.openSettings() },
|
|
322
|
-
]
|
|
323
|
-
);
|
|
324
|
-
|
|
325
|
-
emitErrorStatus(
|
|
326
|
-
VIDEO_CALL_ERROR_STATUS.PERMISSIONS_REQUIRED,
|
|
327
|
-
new Error('Camera and microphone permissions are required to start a video call.')
|
|
328
|
-
);
|
|
329
|
-
return false;
|
|
330
|
-
} catch (error) {
|
|
331
|
-
Alert.alert(
|
|
332
|
-
'Permission error',
|
|
333
|
-
'Unable to check camera and microphone permissions. Please try again or open Settings to grant access.',
|
|
334
|
-
[
|
|
335
|
-
{ text: 'Cancel', style: 'cancel' },
|
|
336
|
-
{ text: 'Open Settings', onPress: () => Linking.openSettings() },
|
|
337
|
-
]
|
|
338
|
-
);
|
|
339
|
-
emitErrorStatus(
|
|
340
|
-
VIDEO_CALL_ERROR_STATUS.PERMISSION_CHECK_FAILED,
|
|
341
|
-
error,
|
|
342
|
-
{
|
|
343
|
-
message: 'Unable to check camera and microphone permissions.',
|
|
344
|
-
}
|
|
345
|
-
);
|
|
346
|
-
return false;
|
|
347
|
-
}
|
|
348
|
-
}, [emitErrorStatus]);
|
|
349
|
-
|
|
350
|
-
const connectToRoom = useCallback(
|
|
351
|
-
async ({
|
|
352
|
-
roomName,
|
|
353
|
-
accessToken,
|
|
354
|
-
doctorName,
|
|
355
|
-
visibleDoctorName,
|
|
356
|
-
userName,
|
|
357
|
-
}) => {
|
|
358
|
-
if (!roomName || !accessToken) {
|
|
359
|
-
const err = new Error('roomName and accessToken are required');
|
|
360
|
-
emitErrorStatus(VIDEO_CALL_ERROR_STATUS.MISSING_ROOM_NAME_OR_ACCESS_TOKEN, err);
|
|
361
|
-
return;
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
const canStartCall = await checkAndroidVideoPermissions();
|
|
365
|
-
if (!canStartCall) {
|
|
366
|
-
return;
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
callRef.current.roomJoined = false;
|
|
370
|
-
callRef.current.unmounted = false;
|
|
371
|
-
localPreviewDragOffsetRef.current = { x: 0, y: 0 };
|
|
372
|
-
localPreviewDrag.setValue({ x: 0, y: 0 });
|
|
373
|
-
refreshLocalPreview();
|
|
374
|
-
const visible =
|
|
375
|
-
visibleDoctorName != null && visibleDoctorName !== ''
|
|
376
|
-
? visibleDoctorName
|
|
377
|
-
: doctorName || '';
|
|
378
|
-
updateState((prev) => ({
|
|
379
|
-
...prev,
|
|
380
|
-
isVisible: true,
|
|
381
|
-
loading: true,
|
|
382
|
-
status: 'connecting',
|
|
383
|
-
roomName,
|
|
384
|
-
accessToken,
|
|
385
|
-
doctorName: doctorName || '',
|
|
386
|
-
visibleDoctorName: visible,
|
|
387
|
-
userName: userName || '',
|
|
388
|
-
durationMins: '00',
|
|
389
|
-
durationSecs: '00',
|
|
390
|
-
}));
|
|
391
|
-
setTimeout(() => {
|
|
392
|
-
twilioVideoRef.current?.connect({
|
|
393
|
-
accessToken,
|
|
394
|
-
roomName,
|
|
395
|
-
cameraType: 'front',
|
|
396
|
-
enableNetworkQualityReporting: true,
|
|
397
|
-
});
|
|
398
|
-
}, 600);
|
|
399
|
-
},
|
|
400
|
-
[
|
|
401
|
-
localPreviewDrag,
|
|
402
|
-
refreshLocalPreview,
|
|
403
|
-
checkAndroidVideoPermissions,
|
|
404
|
-
updateState,
|
|
405
|
-
emitErrorStatus,
|
|
406
|
-
]
|
|
407
|
-
);
|
|
408
|
-
|
|
409
|
-
const endCall = useCallback(() => {
|
|
410
|
-
twilioVideoRef.current?.disconnect();
|
|
411
|
-
leaveVideo('ended-by-user');
|
|
412
|
-
}, [leaveVideo]);
|
|
413
|
-
|
|
414
|
-
useImperativeHandle(
|
|
415
|
-
ref,
|
|
416
|
-
() => ({
|
|
417
|
-
startVideoCall: ({
|
|
418
|
-
roomName,
|
|
419
|
-
accessToken,
|
|
420
|
-
doctorName,
|
|
421
|
-
visibleDoctorName,
|
|
422
|
-
userName,
|
|
423
|
-
}) =>
|
|
424
|
-
connectToRoom({
|
|
425
|
-
roomName,
|
|
426
|
-
accessToken,
|
|
427
|
-
doctorName,
|
|
428
|
-
visibleDoctorName,
|
|
429
|
-
userName,
|
|
430
|
-
}),
|
|
431
|
-
endCall,
|
|
432
|
-
isConnected: () => state.isVisible,
|
|
433
|
-
}),
|
|
434
|
-
[connectToRoom, endCall, state.isVisible]
|
|
435
|
-
);
|
|
436
|
-
|
|
437
|
-
useEffect(() => {
|
|
438
|
-
callRef.current.unmounted = false;
|
|
439
|
-
return () => {
|
|
440
|
-
const wasJoined = callRef.current.roomJoined;
|
|
441
|
-
callRef.current.unmounted = true;
|
|
442
|
-
callRef.current.roomJoined = false;
|
|
443
|
-
clearDurationTimer();
|
|
444
|
-
clearReconnectTimer();
|
|
445
|
-
clearLocalPreviewRefreshTimers();
|
|
446
|
-
twilioVideoRef.current?.disconnect();
|
|
447
|
-
if (wasJoined) {
|
|
448
|
-
callRef.current.onCallEnded?.({ reason: 'component-unmount' });
|
|
449
|
-
}
|
|
450
|
-
};
|
|
451
|
-
}, [clearDurationTimer, clearReconnectTimer, clearLocalPreviewRefreshTimers]);
|
|
452
|
-
|
|
453
|
-
const onRoomDidConnect = ({ roomName }) => {
|
|
454
|
-
console.log('onRoomDidConnect', roomName);
|
|
455
|
-
callRef.current.roomJoined = true;
|
|
456
|
-
updateState((prev) => ({
|
|
457
|
-
...prev,
|
|
458
|
-
loading: false,
|
|
459
|
-
status: 'connected',
|
|
460
|
-
showUserReconnectingScreen: false,
|
|
461
|
-
}));
|
|
462
|
-
clearReconnectTimer();
|
|
463
|
-
if (onCallConnected) {
|
|
464
|
-
onCallConnected({ roomName });
|
|
465
|
-
}
|
|
466
|
-
|
|
467
|
-
// Twilio local preview can miss the first bind on some Android devices.
|
|
468
|
-
// Force a couple of refresh passes right after connect.
|
|
469
|
-
clearLocalPreviewRefreshTimers();
|
|
470
|
-
refreshLocalPreview();
|
|
471
|
-
localPreviewRefreshTimeoutRef.current = setTimeout(() => {
|
|
472
|
-
twilioVideoRef.current?.setLocalVideoEnabled(true);
|
|
473
|
-
refreshLocalPreview();
|
|
474
|
-
}, 220);
|
|
475
|
-
localPreviewSecondRefreshTimeoutRef.current = setTimeout(() => {
|
|
476
|
-
refreshLocalPreview();
|
|
477
|
-
}, 700);
|
|
478
|
-
};
|
|
479
|
-
|
|
480
|
-
const onRoomDidDisconnect = ({ error }) => {
|
|
481
|
-
leaveVideo('room-disconnected', error);
|
|
482
|
-
};
|
|
483
|
-
|
|
484
|
-
const onRoomDidFailToConnect = (error) => {
|
|
485
|
-
const errorMessage = String(error?.error || error?.message || '');
|
|
486
|
-
|
|
487
|
-
const hasTokenError = errorMessage?.toLowerCase()?.includes('token');
|
|
488
|
-
if (hasTokenError) {
|
|
489
|
-
Alert.alert(
|
|
490
|
-
'Unable to join call',
|
|
491
|
-
'Your video session token is invalid or has expired.',
|
|
492
|
-
[{ text: 'OK' }]
|
|
493
|
-
);
|
|
494
|
-
emitErrorStatus(VIDEO_CALL_ERROR_STATUS.INVALID_OR_EXPIRED_TOKEN, error);
|
|
495
|
-
leaveVideo('connect-failed', error);
|
|
496
|
-
return;
|
|
497
|
-
}
|
|
498
|
-
emitErrorStatus(VIDEO_CALL_ERROR_STATUS.CONNECT_FAILED, error);
|
|
499
|
-
leaveVideo('connect-failed', error);
|
|
500
|
-
};
|
|
501
|
-
|
|
502
|
-
const onParticipantAddedVideoTrack = ({ participant, track }) => {
|
|
503
|
-
updateState((prev) => {
|
|
504
|
-
if (prev.remoteTrackSid) {
|
|
505
|
-
return prev;
|
|
506
|
-
}
|
|
507
|
-
return {
|
|
508
|
-
...prev,
|
|
509
|
-
remoteTrackSid: track.trackSid,
|
|
510
|
-
remoteTrackIdentifier: {
|
|
511
|
-
participantSid: participant.sid,
|
|
512
|
-
videoTrackSid: track.trackSid,
|
|
513
|
-
},
|
|
514
|
-
participantVideoEnabled: !!track.enabled,
|
|
515
|
-
loading: false,
|
|
516
|
-
status: 'connected',
|
|
517
|
-
};
|
|
518
|
-
});
|
|
519
|
-
startDurationTimer();
|
|
520
|
-
};
|
|
521
|
-
|
|
522
|
-
const onParticipantRemovedVideoTrack = ({ track }) => {
|
|
523
|
-
updateState((prev) => {
|
|
524
|
-
if (track.trackSid !== prev.remoteTrackSid) {
|
|
525
|
-
return prev;
|
|
526
|
-
}
|
|
527
|
-
timerRunningRef.current = false;
|
|
528
|
-
return {
|
|
529
|
-
...prev,
|
|
530
|
-
remoteTrackSid: '',
|
|
531
|
-
remoteTrackIdentifier: null,
|
|
532
|
-
status: 'participantDisconnected',
|
|
533
|
-
};
|
|
534
|
-
});
|
|
535
|
-
};
|
|
536
|
-
|
|
537
|
-
const onParticipantDisabledVideoTrack = (event) => {
|
|
538
|
-
updateState((prev) => ({
|
|
539
|
-
...prev,
|
|
540
|
-
participantVideoEnabled: !!event.track?.enabled,
|
|
541
|
-
}));
|
|
542
|
-
};
|
|
543
|
-
|
|
544
|
-
const onParticipantEnabledVideoTrack = (event) => {
|
|
545
|
-
updateState((prev) => ({
|
|
546
|
-
...prev,
|
|
547
|
-
participantVideoEnabled: !!event.track?.enabled,
|
|
548
|
-
}));
|
|
549
|
-
};
|
|
550
|
-
|
|
551
|
-
const onParticipantAudioToggled = (event) => {
|
|
552
|
-
updateState((prev) => ({
|
|
553
|
-
...prev,
|
|
554
|
-
participantAudioEnabled: !!event.track?.enabled,
|
|
555
|
-
}));
|
|
556
|
-
};
|
|
557
|
-
|
|
558
|
-
const onNetworkQualityLevelsChanged = (payload) => {
|
|
559
|
-
if (payload.isLocalUser) {
|
|
560
|
-
const isLow = payload.quality > 0 && payload.quality < 3;
|
|
561
|
-
updateState((prev) => ({
|
|
562
|
-
...prev,
|
|
563
|
-
signalStrength: payload.quality,
|
|
564
|
-
showLowSignalStrengthMessage: isLow,
|
|
565
|
-
showUserReconnectingScreen: false,
|
|
566
|
-
}));
|
|
567
|
-
if (isLow && onLowNetworkQuality) {
|
|
568
|
-
onLowNetworkQuality({ quality: payload.quality, participant: 'local' });
|
|
569
|
-
}
|
|
570
|
-
} else {
|
|
571
|
-
updateState((prev) => ({
|
|
572
|
-
...prev,
|
|
573
|
-
participantSignalStrength: payload.quality,
|
|
574
|
-
showParticipantReconnectingScreen: payload.quality <= 1,
|
|
575
|
-
}));
|
|
576
|
-
}
|
|
577
|
-
};
|
|
578
|
-
|
|
579
|
-
const onMuteButtonPress = () => {
|
|
580
|
-
twilioVideoRef.current?.setLocalAudioEnabled(state.isMuted).then((enabled) => {
|
|
581
|
-
updateState((prev) => ({ ...prev, isMuted: !enabled }));
|
|
582
|
-
});
|
|
583
|
-
};
|
|
584
|
-
|
|
585
|
-
const onVideoToggle = () => {
|
|
586
|
-
twilioVideoRef.current
|
|
587
|
-
?.setLocalVideoEnabled(!state.isVideoEnabled)
|
|
588
|
-
.then((enabled) => {
|
|
589
|
-
console.log('onVideoToggle', enabled);
|
|
590
|
-
updateState((prev) => ({ ...prev, isVideoEnabled: enabled }));
|
|
591
|
-
})
|
|
592
|
-
.catch((error) => {
|
|
593
|
-
console.error('Error toggling video:', error);
|
|
594
|
-
});
|
|
595
|
-
};
|
|
596
|
-
|
|
597
|
-
const onFlipButtonPress = () => {
|
|
598
|
-
twilioVideoRef.current?.flipCamera();
|
|
599
|
-
updateState((prev) => ({
|
|
600
|
-
...prev,
|
|
601
|
-
isFrontCameraEnabled: !prev.isFrontCameraEnabled,
|
|
602
|
-
}));
|
|
603
|
-
};
|
|
604
|
-
|
|
605
|
-
const onRoomReconnectingWithError = () => {
|
|
606
|
-
updateState((prev) => ({
|
|
607
|
-
...prev,
|
|
608
|
-
showUserReconnectingScreen: true,
|
|
609
|
-
}));
|
|
610
|
-
clearReconnectTimer();
|
|
611
|
-
reconnectingTimerRef.current = setInterval(() => {
|
|
612
|
-
const { accessToken, roomName, isMuted, isVideoEnabled } = state;
|
|
613
|
-
if (!accessToken || !roomName) {
|
|
614
|
-
return;
|
|
615
|
-
}
|
|
616
|
-
twilioVideoRef.current?.connect({
|
|
617
|
-
accessToken,
|
|
618
|
-
roomName,
|
|
619
|
-
enableAudio: !isMuted,
|
|
620
|
-
enableVideo: isVideoEnabled,
|
|
621
|
-
enableNetworkQualityReporting: true,
|
|
622
|
-
});
|
|
623
|
-
}, 3000);
|
|
624
|
-
};
|
|
625
|
-
|
|
626
|
-
if (!state.isVisible) {
|
|
627
|
-
return (
|
|
628
|
-
<TwilioVideo
|
|
629
|
-
ref={twilioVideoRef}
|
|
630
|
-
onRoomDidConnect={onRoomDidConnect}
|
|
631
|
-
onRoomDidDisconnect={onRoomDidDisconnect}
|
|
632
|
-
onRoomDidFailToConnect={onRoomDidFailToConnect}
|
|
633
|
-
onParticipantAddedVideoTrack={onParticipantAddedVideoTrack}
|
|
634
|
-
onParticipantDisabledVideoTrack={onParticipantDisabledVideoTrack}
|
|
635
|
-
onParticipantEnabledVideoTrack={onParticipantEnabledVideoTrack}
|
|
636
|
-
onParticipantRemovedVideoTrack={onParticipantRemovedVideoTrack}
|
|
637
|
-
onParticipantAddedAudioTrack={onParticipantAudioToggled}
|
|
638
|
-
onParticipantEnabledAudioTrack={onParticipantAudioToggled}
|
|
639
|
-
onParticipantDisabledAudioTrack={onParticipantAudioToggled}
|
|
640
|
-
onNetworkQualityLevelsChanged={onNetworkQualityLevelsChanged}
|
|
641
|
-
onRoomReconnectingWithError={onRoomReconnectingWithError}
|
|
642
|
-
onRoomParticipantIsReconnecting={() =>
|
|
643
|
-
updateState((prev) => ({
|
|
644
|
-
...prev,
|
|
645
|
-
showParticipantReconnectingScreen: true,
|
|
646
|
-
}))
|
|
647
|
-
}
|
|
648
|
-
onRoomParticipantReconnected={() =>
|
|
649
|
-
updateState((prev) => ({
|
|
650
|
-
...prev,
|
|
651
|
-
showParticipantReconnectingScreen: false,
|
|
652
|
-
}))
|
|
653
|
-
}
|
|
654
|
-
/>
|
|
655
|
-
);
|
|
656
|
-
}
|
|
657
|
-
|
|
658
|
-
const isReconnecting =
|
|
659
|
-
state.showParticipantReconnectingScreen || state.showUserReconnectingScreen;
|
|
660
|
-
const isConnecting = state.loading || state.status === 'connecting';
|
|
661
|
-
const showDoctorInitial =
|
|
662
|
-
state.status === 'participantDisconnected' || (!isReconnecting && !isConnecting);
|
|
663
|
-
|
|
664
|
-
return (
|
|
665
|
-
<View style={[styles.container, style]}>
|
|
666
|
-
<StatusBar barStyle="light-content" />
|
|
667
|
-
<View style={styles.topHeader}>
|
|
668
|
-
<View style={styles.headerTitleWrap}>
|
|
669
|
-
<Text style={styles.nameText}>
|
|
670
|
-
{state.doctorName || 'Doctor'}
|
|
671
|
-
</Text>
|
|
672
|
-
<Text style={styles.timerText}>
|
|
673
|
-
{state.durationMins}:{state.durationSecs}
|
|
674
|
-
</Text>
|
|
675
|
-
</View>
|
|
676
|
-
{(state.signalStrength !== null || state.participantSignalStrength !== null) && (
|
|
677
|
-
<View style={styles.signalHeaderRow}>
|
|
678
|
-
{state.participantSignalStrength !== null ? (
|
|
679
|
-
<SignalStrengthIndicator
|
|
680
|
-
strength={state.participantSignalStrength}
|
|
681
|
-
participantLabel="Doctor"
|
|
682
|
-
/>
|
|
683
|
-
) : null}
|
|
684
|
-
{state.signalStrength !== null ? (
|
|
685
|
-
<View style={styles.signalItemSpacer}>
|
|
686
|
-
<SignalStrengthIndicator
|
|
687
|
-
strength={state.signalStrength}
|
|
688
|
-
participantLabel="Patient"
|
|
689
|
-
/>
|
|
690
|
-
</View>
|
|
691
|
-
) : null}
|
|
692
|
-
</View>
|
|
693
|
-
)}
|
|
694
|
-
</View>
|
|
695
|
-
|
|
696
|
-
{state.remoteTrackIdentifier &&
|
|
697
|
-
state.participantVideoEnabled &&
|
|
698
|
-
!state.showParticipantReconnectingScreen &&
|
|
699
|
-
!state.showUserReconnectingScreen ? (
|
|
700
|
-
<TwilioVideoParticipantView
|
|
701
|
-
style={styles.remoteVideo}
|
|
702
|
-
key={state?.remoteTrackSid}
|
|
703
|
-
trackIdentifier={state.remoteTrackIdentifier}
|
|
704
|
-
/>
|
|
705
|
-
) : (
|
|
706
|
-
<View style={styles.remotePlaceholder}>
|
|
707
|
-
{isReconnecting || isConnecting ? (
|
|
708
|
-
<View
|
|
709
|
-
style={[
|
|
710
|
-
styles.connectingView,
|
|
711
|
-
{ backgroundColor: 'rgba(164, 171, 180, 0.36)', },
|
|
712
|
-
]}
|
|
713
|
-
>
|
|
714
|
-
<Image
|
|
715
|
-
style={styles.connectingGif}
|
|
716
|
-
source={isReconnecting ? ICONS.reconnecting : ICONS.connecting}
|
|
717
|
-
/>
|
|
718
|
-
<Text style={styles.connectingText}>
|
|
719
|
-
{isReconnecting ? 'Reconnecting...' : 'Connecting...'}
|
|
720
|
-
</Text>
|
|
721
|
-
</View>
|
|
722
|
-
) : (
|
|
723
|
-
<Text
|
|
724
|
-
style={[
|
|
725
|
-
styles.placeholderText,
|
|
726
|
-
showDoctorInitial ? styles.placeholderInitialText : null,
|
|
727
|
-
]}
|
|
728
|
-
>
|
|
729
|
-
{(state.visibleDoctorName || state.doctorName || 'Doctor')
|
|
730
|
-
.trim()
|
|
731
|
-
.charAt(0)
|
|
732
|
-
.toUpperCase()}
|
|
733
|
-
</Text>
|
|
734
|
-
)}
|
|
735
|
-
</View>
|
|
736
|
-
)}
|
|
737
|
-
|
|
738
|
-
{!isConnecting ? (
|
|
739
|
-
<Animated.View
|
|
740
|
-
style={[
|
|
741
|
-
styles.localPreview,
|
|
742
|
-
state.showLowSignalStrengthMessage
|
|
743
|
-
? state.showBottomBar
|
|
744
|
-
? styles.localPreviewAboveLowSignalExpanded
|
|
745
|
-
: styles.localPreviewAboveLowSignalCollapsed
|
|
746
|
-
: state.showBottomBar
|
|
747
|
-
? styles.localPreviewAboveControls
|
|
748
|
-
: styles.localPreviewAboveCollapsedControls,
|
|
749
|
-
{ transform: localPreviewDrag.getTranslateTransform() },
|
|
750
|
-
]}
|
|
751
|
-
{...localPreviewPanResponder.panHandlers}
|
|
752
|
-
>
|
|
753
|
-
<View style={styles.localPreviewInner}>
|
|
754
|
-
{state.isVideoEnabled ? (
|
|
755
|
-
<TwilioVideoLocalView
|
|
756
|
-
key={`local-preview-${localPreviewRefreshKey}`}
|
|
757
|
-
enabled
|
|
758
|
-
style={styles.localVideo}
|
|
759
|
-
/>
|
|
760
|
-
) : (
|
|
761
|
-
<View style={[styles.localVideo, styles.localVideoOff]}>
|
|
762
|
-
<Text style={styles.localVideoOffText}>
|
|
763
|
-
{(state.userName || 'Patient').charAt(0).toUpperCase()}
|
|
764
|
-
</Text>
|
|
765
|
-
</View>
|
|
766
|
-
)}
|
|
767
|
-
</View>
|
|
768
|
-
</Animated.View>
|
|
769
|
-
) : null}
|
|
770
|
-
|
|
771
|
-
{!state.participantAudioEnabled && !state.showLowSignalStrengthMessage ? (
|
|
772
|
-
<View
|
|
773
|
-
style={[
|
|
774
|
-
styles.participantMicOffBadge,
|
|
775
|
-
state.showBottomBar
|
|
776
|
-
? styles.participantMicOffBadgeAboveControls
|
|
777
|
-
: styles.participantMicOffBadgeAboveCollapsed,
|
|
778
|
-
]}
|
|
779
|
-
>
|
|
780
|
-
<Image source={ICONS.mute} style={styles.participantMicOffIcon} resizeMode="contain" />
|
|
781
|
-
</View>
|
|
782
|
-
) : null}
|
|
783
|
-
|
|
784
|
-
{state.showLowSignalStrengthMessage ? (
|
|
785
|
-
<View
|
|
786
|
-
style={[
|
|
787
|
-
styles.lowSignalBanner,
|
|
788
|
-
state.showBottomBar
|
|
789
|
-
? styles.lowSignalBannerAboveControls
|
|
790
|
-
: styles.lowSignalBannerAboveCollapsed,
|
|
791
|
-
]}
|
|
792
|
-
>
|
|
793
|
-
<Text style={styles.lowSignalText}>
|
|
794
|
-
Poor connection detected. Try moving for better signal.
|
|
795
|
-
</Text>
|
|
796
|
-
<Pressable
|
|
797
|
-
onPress={() =>
|
|
798
|
-
updateState((prev) => ({
|
|
799
|
-
...prev,
|
|
800
|
-
showLowSignalStrengthMessage: false,
|
|
801
|
-
}))
|
|
802
|
-
}
|
|
803
|
-
>
|
|
804
|
-
<Text style={styles.lowSignalDismiss}>Dismiss</Text>
|
|
805
|
-
</Pressable>
|
|
806
|
-
</View>
|
|
807
|
-
) : null}
|
|
808
|
-
|
|
809
|
-
<View style={styles.bottomBarContainer}>
|
|
810
|
-
<View
|
|
811
|
-
style={[styles.controls, !state.showBottomBar ? styles.controlsCollapsed : null]}
|
|
812
|
-
>
|
|
813
|
-
<TouchableOpacity
|
|
814
|
-
activeOpacity={0.8}
|
|
815
|
-
style={styles.controlsTopLineTouch}
|
|
816
|
-
onPress={() => {
|
|
817
|
-
LayoutAnimation.configureNext(LayoutAnimation.Presets.easeInEaseOut);
|
|
818
|
-
updateState((prev) => ({
|
|
819
|
-
...prev,
|
|
820
|
-
showBottomBar: !prev.showBottomBar,
|
|
821
|
-
}));
|
|
822
|
-
}}
|
|
823
|
-
>
|
|
824
|
-
<View style={styles.controlsTogglePill}>
|
|
825
|
-
<Image
|
|
826
|
-
source={state.showBottomBar ? ICONS.toggleDown : ICONS.toggleUp}
|
|
827
|
-
style={styles.controlsToggleIcon}
|
|
828
|
-
resizeMode="contain"
|
|
829
|
-
/>
|
|
830
|
-
</View>
|
|
831
|
-
</TouchableOpacity>
|
|
832
|
-
|
|
833
|
-
{state.showBottomBar ? (
|
|
834
|
-
<>
|
|
835
|
-
<ControlButton
|
|
836
|
-
label="Mute"
|
|
837
|
-
icon={ICONS.mute}
|
|
838
|
-
onPress={onMuteButtonPress}
|
|
839
|
-
active={state.isMuted}
|
|
840
|
-
/>
|
|
841
|
-
<ControlButton
|
|
842
|
-
label="Video on"
|
|
843
|
-
icon={ICONS.videoOff}
|
|
844
|
-
onPress={onVideoToggle}
|
|
845
|
-
active={!state.isVideoEnabled}
|
|
846
|
-
/>
|
|
847
|
-
<ControlButton
|
|
848
|
-
label="Flip Camera"
|
|
849
|
-
icon={ICONS.flip}
|
|
850
|
-
onPress={onFlipButtonPress}
|
|
851
|
-
useTouchableOpacity
|
|
852
|
-
/>
|
|
853
|
-
<ControlButton
|
|
854
|
-
label="End Call"
|
|
855
|
-
icon={ICONS.end}
|
|
856
|
-
onPress={endCall}
|
|
857
|
-
danger
|
|
858
|
-
iconSize={18}
|
|
859
|
-
useTouchableOpacity
|
|
860
|
-
/>
|
|
861
|
-
</>
|
|
862
|
-
) : null}
|
|
863
|
-
</View>
|
|
864
|
-
</View>
|
|
865
|
-
|
|
866
|
-
<TwilioVideo
|
|
867
|
-
ref={twilioVideoRef}
|
|
868
|
-
onRoomDidConnect={onRoomDidConnect}
|
|
869
|
-
onRoomDidDisconnect={onRoomDidDisconnect}
|
|
870
|
-
onRoomDidFailToConnect={onRoomDidFailToConnect}
|
|
871
|
-
onParticipantAddedVideoTrack={onParticipantAddedVideoTrack}
|
|
872
|
-
onParticipantDisabledVideoTrack={onParticipantDisabledVideoTrack}
|
|
873
|
-
onParticipantEnabledVideoTrack={onParticipantEnabledVideoTrack}
|
|
874
|
-
onParticipantRemovedVideoTrack={onParticipantRemovedVideoTrack}
|
|
875
|
-
onParticipantAddedAudioTrack={onParticipantAudioToggled}
|
|
876
|
-
onParticipantEnabledAudioTrack={onParticipantAudioToggled}
|
|
877
|
-
onParticipantDisabledAudioTrack={onParticipantAudioToggled}
|
|
878
|
-
onNetworkQualityLevelsChanged={onNetworkQualityLevelsChanged}
|
|
879
|
-
onRoomReconnectingWithError={onRoomReconnectingWithError}
|
|
880
|
-
onRoomParticipantIsReconnecting={() =>
|
|
881
|
-
updateState((prev) => ({
|
|
882
|
-
...prev,
|
|
883
|
-
showParticipantReconnectingScreen: true,
|
|
884
|
-
}))
|
|
885
|
-
}
|
|
886
|
-
onRoomParticipantReconnected={() =>
|
|
887
|
-
updateState((prev) => ({
|
|
888
|
-
...prev,
|
|
889
|
-
showParticipantReconnectingScreen: false,
|
|
890
|
-
}))
|
|
891
|
-
}
|
|
892
|
-
/>
|
|
893
|
-
</View>
|
|
894
|
-
);
|
|
895
|
-
}
|
|
896
|
-
);
|
|
897
|
-
|
|
898
|
-
const SignalStrengthIndicator = ({ strength, participantLabel }) => {
|
|
899
|
-
const bars = [1, 2, 3, 4, 5];
|
|
900
|
-
const barColor =
|
|
901
|
-
strength <= 1
|
|
902
|
-
? '#f04d5a'
|
|
903
|
-
: strength === 2
|
|
904
|
-
? '#f48f31'
|
|
905
|
-
: strength === 3
|
|
906
|
-
? '#f9ca24'
|
|
907
|
-
: '#5dd670';
|
|
908
|
-
|
|
909
|
-
return (
|
|
910
|
-
<View style={styles.signalContainer}>
|
|
911
|
-
<View style={styles.signalBars}>
|
|
912
|
-
{bars.map((bar, idx) => (
|
|
913
|
-
<View
|
|
914
|
-
key={`bar-${bar}`}
|
|
915
|
-
style={[
|
|
916
|
-
styles.signalBar,
|
|
917
|
-
{
|
|
918
|
-
backgroundColor: strength >= bar ? barColor : '#6f6f6f',
|
|
919
|
-
height: idx === 0 ? 2 : idx * 4,
|
|
920
|
-
marginRight: idx === 4 ? 0 : 3,
|
|
921
|
-
},
|
|
922
|
-
]}
|
|
923
|
-
/>
|
|
924
|
-
))}
|
|
925
|
-
</View>
|
|
926
|
-
<Text style={styles.signalLabel}>{participantLabel}</Text>
|
|
927
|
-
</View>
|
|
928
|
-
);
|
|
929
|
-
};
|
|
930
|
-
|
|
931
|
-
const ControlButton = ({
|
|
932
|
-
label,
|
|
933
|
-
onPress,
|
|
934
|
-
danger,
|
|
935
|
-
icon,
|
|
936
|
-
customIconText,
|
|
937
|
-
active,
|
|
938
|
-
iconSize,
|
|
939
|
-
useTouchableOpacity,
|
|
940
|
-
}) => {
|
|
941
|
-
const content = (
|
|
942
|
-
<View
|
|
943
|
-
style={[
|
|
944
|
-
styles.controlIconShell,
|
|
945
|
-
active ? styles.controlIconShellActive : null,
|
|
946
|
-
danger ? styles.controlButtonDanger : null,
|
|
947
|
-
]}
|
|
948
|
-
>
|
|
949
|
-
{icon ? (
|
|
950
|
-
<Image
|
|
951
|
-
source={icon}
|
|
952
|
-
style={[
|
|
953
|
-
styles.controlButtonIcon,
|
|
954
|
-
iconSize ? { width: iconSize, height: iconSize } : null,
|
|
955
|
-
active ? styles.controlButtonIconActive : null,
|
|
956
|
-
danger ? styles.controlButtonIconDanger : null,
|
|
957
|
-
]}
|
|
958
|
-
resizeMode="contain"
|
|
959
|
-
/>
|
|
960
|
-
) : (
|
|
961
|
-
<Text
|
|
962
|
-
style={[
|
|
963
|
-
styles.controlFallbackIcon,
|
|
964
|
-
active ? styles.controlFallbackIconActive : null,
|
|
965
|
-
]}
|
|
966
|
-
>
|
|
967
|
-
{customIconText || '?'}
|
|
968
|
-
</Text>
|
|
969
|
-
)}
|
|
970
|
-
</View>
|
|
971
|
-
);
|
|
972
|
-
|
|
973
|
-
if (useTouchableOpacity) {
|
|
974
|
-
return (
|
|
975
|
-
<TouchableOpacity style={styles.controlButton} onPress={onPress} activeOpacity={0.65}>
|
|
976
|
-
{content}
|
|
977
|
-
</TouchableOpacity>
|
|
978
|
-
);
|
|
979
|
-
}
|
|
980
|
-
|
|
981
|
-
return (
|
|
982
|
-
<Pressable style={styles.controlButton} onPress={onPress}>
|
|
983
|
-
{content}
|
|
984
|
-
</Pressable>
|
|
985
|
-
);
|
|
986
|
-
};
|
|
987
|
-
|
|
988
|
-
const styles = StyleSheet.create({
|
|
989
|
-
container: {
|
|
990
|
-
position: 'absolute',
|
|
991
|
-
top: 0,
|
|
992
|
-
left: 0,
|
|
993
|
-
right: 0,
|
|
994
|
-
bottom: 0,
|
|
995
|
-
zIndex: 99,
|
|
996
|
-
backgroundColor: '#000',
|
|
997
|
-
justifyContent: 'space-between',
|
|
998
|
-
},
|
|
999
|
-
topHeader: {
|
|
1000
|
-
position: 'absolute',
|
|
1001
|
-
top: 0,
|
|
1002
|
-
left: 0,
|
|
1003
|
-
right: 0,
|
|
1004
|
-
zIndex: 10,
|
|
1005
|
-
flexDirection: 'row',
|
|
1006
|
-
justifyContent: 'space-between',
|
|
1007
|
-
alignItems: 'flex-end',
|
|
1008
|
-
paddingHorizontal: 16,
|
|
1009
|
-
paddingTop: 56,
|
|
1010
|
-
},
|
|
1011
|
-
headerTitleWrap: {
|
|
1012
|
-
flex: 1,
|
|
1013
|
-
paddingRight: 12,
|
|
1014
|
-
},
|
|
1015
|
-
nameText: {
|
|
1016
|
-
color: '#fff',
|
|
1017
|
-
fontSize: 24,
|
|
1018
|
-
fontWeight: '700',
|
|
1019
|
-
},
|
|
1020
|
-
timerText: {
|
|
1021
|
-
color: '#fff',
|
|
1022
|
-
marginTop: 4,
|
|
1023
|
-
fontSize: 13,
|
|
1024
|
-
},
|
|
1025
|
-
closeButton: {
|
|
1026
|
-
paddingVertical: 8,
|
|
1027
|
-
paddingHorizontal: 12,
|
|
1028
|
-
borderRadius: 16,
|
|
1029
|
-
backgroundColor: 'rgba(255,255,255,0.2)',
|
|
1030
|
-
},
|
|
1031
|
-
closeButtonText: {
|
|
1032
|
-
color: '#fff',
|
|
1033
|
-
fontWeight: '700',
|
|
1034
|
-
},
|
|
1035
|
-
remoteVideo: {
|
|
1036
|
-
position: 'absolute',
|
|
1037
|
-
top: 0,
|
|
1038
|
-
left: 0,
|
|
1039
|
-
right: 0,
|
|
1040
|
-
bottom: 0,
|
|
1041
|
-
width: SCREEN_WIDTH,
|
|
1042
|
-
height: SCREEN_HEIGHT,
|
|
1043
|
-
},
|
|
1044
|
-
remotePlaceholder: {
|
|
1045
|
-
flex: 1,
|
|
1046
|
-
alignItems: 'center',
|
|
1047
|
-
justifyContent: 'center',
|
|
1048
|
-
paddingHorizontal: 32,
|
|
1049
|
-
},
|
|
1050
|
-
placeholderText: {
|
|
1051
|
-
color: '#fff',
|
|
1052
|
-
fontSize: 18,
|
|
1053
|
-
textAlign: 'center',
|
|
1054
|
-
},
|
|
1055
|
-
placeholderInitialText: {
|
|
1056
|
-
fontSize: 40,
|
|
1057
|
-
fontWeight: '700',
|
|
1058
|
-
width: 120,
|
|
1059
|
-
height: 120,
|
|
1060
|
-
lineHeight: 120,
|
|
1061
|
-
textAlign: 'center',
|
|
1062
|
-
textAlignVertical: 'center',
|
|
1063
|
-
includeFontPadding: false,
|
|
1064
|
-
borderRadius: 60,
|
|
1065
|
-
backgroundColor: 'rgb(113, 79, 255)',
|
|
1066
|
-
overflow: 'hidden',
|
|
1067
|
-
},
|
|
1068
|
-
connectingView: {
|
|
1069
|
-
minHeight: 200,
|
|
1070
|
-
width: 271,
|
|
1071
|
-
borderRadius: 16,
|
|
1072
|
-
paddingVertical: 32,
|
|
1073
|
-
paddingHorizontal: 24,
|
|
1074
|
-
alignItems: 'center',
|
|
1075
|
-
justifyContent: 'center',
|
|
1076
|
-
alignSelf: 'center',
|
|
1077
|
-
position: 'absolute',
|
|
1078
|
-
top: 0.35 * SCREEN_HEIGHT,
|
|
1079
|
-
},
|
|
1080
|
-
connectingGif: {
|
|
1081
|
-
width: 108,
|
|
1082
|
-
height: 108,
|
|
1083
|
-
},
|
|
1084
|
-
connectingText: {
|
|
1085
|
-
marginTop: 14,
|
|
1086
|
-
color: '#fff',
|
|
1087
|
-
fontSize: 16,
|
|
1088
|
-
fontWeight: '600',
|
|
1089
|
-
textAlign: 'center',
|
|
1090
|
-
},
|
|
1091
|
-
localPreview: {
|
|
1092
|
-
position: 'absolute',
|
|
1093
|
-
top: 'auto',
|
|
1094
|
-
right: 16,
|
|
1095
|
-
width: LOCAL_PREVIEW_WIDTH,
|
|
1096
|
-
height: LOCAL_PREVIEW_HEIGHT,
|
|
1097
|
-
zIndex: 999,
|
|
1098
|
-
},
|
|
1099
|
-
localPreviewInner: {
|
|
1100
|
-
flex: 1,
|
|
1101
|
-
backgroundColor: '#1b1b1b',
|
|
1102
|
-
},
|
|
1103
|
-
localPreviewAboveControls: {
|
|
1104
|
-
bottom: 140,
|
|
1105
|
-
},
|
|
1106
|
-
localPreviewAboveCollapsedControls: {
|
|
1107
|
-
bottom: 78,
|
|
1108
|
-
},
|
|
1109
|
-
localPreviewAboveLowSignalExpanded: {
|
|
1110
|
-
bottom: 224,
|
|
1111
|
-
},
|
|
1112
|
-
localPreviewAboveLowSignalCollapsed: {
|
|
1113
|
-
bottom: 162,
|
|
1114
|
-
},
|
|
1115
|
-
localVideo: {
|
|
1116
|
-
width: '100%',
|
|
1117
|
-
height: '100%',
|
|
1118
|
-
backgroundColor: '#1b1b1b',
|
|
1119
|
-
},
|
|
1120
|
-
localVideoOff: {
|
|
1121
|
-
alignItems: 'center',
|
|
1122
|
-
justifyContent: 'center',
|
|
1123
|
-
},
|
|
1124
|
-
localVideoOffText: {
|
|
1125
|
-
color: '#fff',
|
|
1126
|
-
fontSize: 28,
|
|
1127
|
-
fontWeight: '700',
|
|
1128
|
-
width: 60,
|
|
1129
|
-
height: 60,
|
|
1130
|
-
lineHeight: 60,
|
|
1131
|
-
textAlign: 'center',
|
|
1132
|
-
textAlignVertical: 'center',
|
|
1133
|
-
includeFontPadding: false,
|
|
1134
|
-
borderRadius: 40,
|
|
1135
|
-
backgroundColor: 'rgb(113, 79, 255)',
|
|
1136
|
-
overflow: 'hidden',
|
|
1137
|
-
},
|
|
1138
|
-
controls: {
|
|
1139
|
-
zIndex: 20,
|
|
1140
|
-
flexDirection: 'row',
|
|
1141
|
-
justifyContent: 'space-around',
|
|
1142
|
-
alignItems: 'flex-start',
|
|
1143
|
-
width: SCREEN_WIDTH,
|
|
1144
|
-
paddingHorizontal: 10,
|
|
1145
|
-
paddingBottom: 20,
|
|
1146
|
-
paddingTop: 30,
|
|
1147
|
-
marginBottom: 0,
|
|
1148
|
-
borderTopLeftRadius: 24,
|
|
1149
|
-
borderTopRightRadius: 24,
|
|
1150
|
-
borderWidth: 0.5,
|
|
1151
|
-
borderColor: 'rgba(129, 186, 255, 0.18)',
|
|
1152
|
-
backgroundColor: 'rgba(164, 171, 180, 0.36)',
|
|
1153
|
-
},
|
|
1154
|
-
controlsCollapsed: {
|
|
1155
|
-
paddingTop: 16,
|
|
1156
|
-
paddingBottom: 24,
|
|
1157
|
-
},
|
|
1158
|
-
bottomBarContainer: {
|
|
1159
|
-
position: 'absolute',
|
|
1160
|
-
left: 0,
|
|
1161
|
-
right: 0,
|
|
1162
|
-
bottom: 0,
|
|
1163
|
-
zIndex: 20,
|
|
1164
|
-
alignItems: 'center',
|
|
1165
|
-
justifyContent: 'flex-end',
|
|
1166
|
-
pointerEvents: 'box-none',
|
|
1167
|
-
},
|
|
1168
|
-
controlsTopLineTouch: {
|
|
1169
|
-
position: 'absolute',
|
|
1170
|
-
top: 6,
|
|
1171
|
-
alignSelf: 'center',
|
|
1172
|
-
width: 72,
|
|
1173
|
-
height: 16,
|
|
1174
|
-
alignItems: 'center',
|
|
1175
|
-
justifyContent: 'center',
|
|
1176
|
-
zIndex: 5,
|
|
1177
|
-
},
|
|
1178
|
-
controlsTogglePill: {
|
|
1179
|
-
width: 40,
|
|
1180
|
-
height: 24,
|
|
1181
|
-
borderRadius: 12,
|
|
1182
|
-
alignItems: 'center',
|
|
1183
|
-
justifyContent: 'center',
|
|
1184
|
-
},
|
|
1185
|
-
controlsToggleIcon: {
|
|
1186
|
-
width: 20,
|
|
1187
|
-
height: 20,
|
|
1188
|
-
tintColor: '#fff',
|
|
1189
|
-
},
|
|
1190
|
-
controlButton: {
|
|
1191
|
-
alignItems: 'center',
|
|
1192
|
-
width: 72,
|
|
1193
|
-
},
|
|
1194
|
-
controlButtonDanger: {
|
|
1195
|
-
backgroundColor: '#f04d5a',
|
|
1196
|
-
},
|
|
1197
|
-
controlIconShell: {
|
|
1198
|
-
width: 64,
|
|
1199
|
-
height: 64,
|
|
1200
|
-
borderRadius: 32,
|
|
1201
|
-
alignItems: 'center',
|
|
1202
|
-
justifyContent: 'center',
|
|
1203
|
-
backgroundColor: 'rgba(255,255,255,0.25)',
|
|
1204
|
-
},
|
|
1205
|
-
controlIconShellActive: {
|
|
1206
|
-
backgroundColor: '#ffffff',
|
|
1207
|
-
},
|
|
1208
|
-
controlButtonIcon: {
|
|
1209
|
-
width: 30,
|
|
1210
|
-
height: 30,
|
|
1211
|
-
tintColor: '#ffffff',
|
|
1212
|
-
},
|
|
1213
|
-
controlButtonIconActive: {
|
|
1214
|
-
tintColor: 'rgba(70,70,70,0.8)',
|
|
1215
|
-
},
|
|
1216
|
-
controlButtonIconDanger: {
|
|
1217
|
-
tintColor: '#ffffff',
|
|
1218
|
-
},
|
|
1219
|
-
controlFallbackIcon: {
|
|
1220
|
-
color: '#fff',
|
|
1221
|
-
fontSize: 28,
|
|
1222
|
-
fontWeight: '700',
|
|
1223
|
-
},
|
|
1224
|
-
controlFallbackIconActive: {
|
|
1225
|
-
color: 'rgba(70,70,70,0.8)',
|
|
1226
|
-
},
|
|
1227
|
-
signalHeaderRow: {
|
|
1228
|
-
flexDirection: 'row',
|
|
1229
|
-
alignItems: 'flex-end',
|
|
1230
|
-
marginTop: 0,
|
|
1231
|
-
},
|
|
1232
|
-
signalContainer: {
|
|
1233
|
-
alignItems: 'center',
|
|
1234
|
-
},
|
|
1235
|
-
signalItemSpacer: {
|
|
1236
|
-
marginLeft: 10,
|
|
1237
|
-
},
|
|
1238
|
-
signalBars: {
|
|
1239
|
-
flexDirection: 'row',
|
|
1240
|
-
alignItems: 'flex-end',
|
|
1241
|
-
},
|
|
1242
|
-
signalBar: {
|
|
1243
|
-
width: 3,
|
|
1244
|
-
borderRadius: 2,
|
|
1245
|
-
},
|
|
1246
|
-
signalLabel: {
|
|
1247
|
-
color: '#fff',
|
|
1248
|
-
fontSize: 10,
|
|
1249
|
-
marginTop: 3,
|
|
1250
|
-
textAlign: 'center',
|
|
1251
|
-
width: '100%',
|
|
1252
|
-
},
|
|
1253
|
-
participantMicOffBadge: {
|
|
1254
|
-
position: 'absolute',
|
|
1255
|
-
alignSelf: 'center',
|
|
1256
|
-
zIndex: 21,
|
|
1257
|
-
width: 52,
|
|
1258
|
-
height: 52,
|
|
1259
|
-
alignItems: 'center',
|
|
1260
|
-
justifyContent: 'center',
|
|
1261
|
-
},
|
|
1262
|
-
participantMicOffBadgeAboveControls: {
|
|
1263
|
-
bottom: 118,
|
|
1264
|
-
},
|
|
1265
|
-
participantMicOffBadgeAboveCollapsed: {
|
|
1266
|
-
bottom: 58,
|
|
1267
|
-
},
|
|
1268
|
-
participantMicOffIcon: {
|
|
1269
|
-
width: 22,
|
|
1270
|
-
height: 22,
|
|
1271
|
-
tintColor: '#fff',
|
|
1272
|
-
},
|
|
1273
|
-
lowSignalBanner: {
|
|
1274
|
-
position: 'absolute',
|
|
1275
|
-
left: 16,
|
|
1276
|
-
right: 16,
|
|
1277
|
-
zIndex: 20,
|
|
1278
|
-
borderRadius: 12,
|
|
1279
|
-
backgroundColor: 'rgba(0,0,0,0.6)',
|
|
1280
|
-
paddingHorizontal: 12,
|
|
1281
|
-
paddingVertical: 10,
|
|
1282
|
-
flexDirection: 'row',
|
|
1283
|
-
alignItems: 'center',
|
|
1284
|
-
justifyContent: 'space-between',
|
|
1285
|
-
},
|
|
1286
|
-
lowSignalBannerAboveControls: {
|
|
1287
|
-
bottom: 130,
|
|
1288
|
-
},
|
|
1289
|
-
lowSignalBannerAboveCollapsed: {
|
|
1290
|
-
bottom: 68,
|
|
1291
|
-
},
|
|
1292
|
-
lowSignalText: {
|
|
1293
|
-
color: '#fff',
|
|
1294
|
-
fontSize: 12,
|
|
1295
|
-
flex: 1,
|
|
1296
|
-
paddingRight: 8,
|
|
1297
|
-
},
|
|
1298
|
-
lowSignalDismiss: {
|
|
1299
|
-
color: '#7ec8ff',
|
|
1300
|
-
fontWeight: '700',
|
|
1301
|
-
fontSize: 12,
|
|
1302
|
-
},
|
|
1303
|
-
});
|
|
1304
|
-
|
|
1305
|
-
export default VideoCallComponent;
|