-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.tsx
104 lines (100 loc) · 3.48 KB
/
index.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
import {JoinCallScreenProps} from '../../types/navigation';
import {Text, View} from 'react-native';
import React, {useEffect, useState} from 'react';
import {useGlobalStore} from '../../store';
import {Meeting, ParticipantDetails} from '../../types/general';
import {log} from '../../utils';
import {notifyServer} from '../../api';
import {DyteProvider, useDyteClient} from '@dytesdk/react-native-core';
import {DyteMeeting, DyteUIProvider} from '@dytesdk/react-native-ui-kit';
export default function JoinCall({route, navigation}: JoinCallScreenProps) {
const {contact, activeMeeting, caller} = route.params;
const createMeeting = useGlobalStore(s => s.createMeeting);
const addParticipant = useGlobalStore(s => s.addParticipant);
const localUsername = useGlobalStore(s => s._username);
const localFullName = useGlobalStore(s => s._fullName);
const [meeting, setMeeting] = useState<Meeting>();
const [participant, setParticipant] = useState<ParticipantDetails>();
const [client, initClient] = useDyteClient();
useEffect(() => {
if (activeMeeting?.id) {
log('active meeting info:-', activeMeeting);
setMeeting(activeMeeting);
return;
}
createMeeting().then(meetInfo => {
log('meeting info:-', meetInfo);
setMeeting(meetInfo);
});
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [activeMeeting]);
useEffect(() => {
if (!meeting?.id) {
return;
}
addParticipant(meeting.id, localUsername, localFullName).then(
participantInfo => {
log('participant info:-', participantInfo);
if (participantInfo?.token) {
initClient({
authToken: participantInfo?.token,
defaults: {
audio: true,
video: true,
},
});
}
setParticipant(participantInfo);
},
);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [meeting, localUsername, localFullName, contact, navigation]);
useEffect(() => {
const onInitMeeting = async (_meeting: Meeting) => {
log('received meeting:-', _meeting);
if (!meeting?.id) {
return;
}
if (!client) {
return;
}
client.self.on('roomLeft', () => {
setParticipant(undefined);
navigation.goBack();
});
notifyServer({
meeting,
contact,
caller: {username: localUsername, name: localFullName, icon: ''},
});
};
if (meeting) {
onInitMeeting(meeting);
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [meeting, client]);
return (
// eslint-disable-next-line react-native/no-inline-styles
<View className="bg-black" style={{flex: 1}}>
<Text className="text-white text-xl bg-[#141414] p-4">
Meeting with {activeMeeting?.id ? caller?.name : contact.name}
</Text>
{client && participant?.token && meeting?.title ? (
// eslint-disable-next-line react-native/no-inline-styles
<View style={{flex: 1}}>
<DyteProvider value={client}>
<DyteUIProvider>
<DyteMeeting meeting={client} />
</DyteUIProvider>
</DyteProvider>
</View>
) : (
// eslint-disable-next-line react-native/no-inline-styles
<View style={{flex: 1, alignItems: 'center', justifyContent: 'center'}}>
{/* eslint-disable-next-line react-native/no-inline-styles */}
<Text style={{color: 'white'}}>Loading...</Text>
</View>
)}
</View>
);
}