-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.tsx
267 lines (228 loc) · 7.45 KB
/
App.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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
import React, { useEffect, useState } from 'react';
import {
StyleSheet,
View,
Button,
Text,
Alert,
useColorScheme,
NativeEventEmitter,
Platform,
} from 'react-native';
import ZoomUs, { ZoomEmitter, ZoomUsVideoView } from 'react-native-zoom-us';
import { type NativeLayoutUnit } from 'react-native-zoom-us/native';
import * as sdkJwtTokenJson from './api/sdk.jwt.json';
import * as startMeetingJson from './api/api.startMeeting.json';
// 1. `TODO`: Go to https://marketplace.zoom.us/develop/create and Create SDK App then fill `sdkKey` and `sdkSecret`
// There are TWO options to initialize zoom sdk: without jwt token OR with jwt token
// 1a. without jwt token (quick start while developing)
const sdkKey = 'ET8FHFjMROGRzd4g8K3-hw';
const sdkSecret = 'TGGnpmlCMBVZ41ROty800RymTD9v0fVHS36E';
// 1b. with jwt token (should be used in production)
// - Replace you sdkKey and sdkSecret and run the following in the terminal:
// SDK_KEY=sdkKey SDK_SECRET=sdkSecret yarn run sdk:get-jwt
// This will fill up ./api/sdk.jwt.json that will be used instead of sdkKey and sdkSecret
const sdkJwtToken = sdkJwtTokenJson.jwtToken;
// 2a. `TODO` Fill in start meeting data:
// Replace userId, meetingNumber, zoomAccessToken in `./api/api.zak.json` manually
// OR follow these instructions for getting data automatically for starting you personal meeting:
// - Go to https://marketplace.zoom.us/develop/create and Create JWT App to get apiKey and apiSecret
// - Replace your apiKey and apiSecret and run the following in the terminal:
// API_KEY=apiKey API_SECRET=apiSecret yarn run api:get-jwt
// This will create JWT token in `./api/api.jwt.json` that you can use for the step of getting your personal meeting data.
// - Run the following in the terminal:
// yarn run api:get-startPersonalMeeting
const exampleStartMeeting = {
userId: startMeetingJson.userId,
meetingNumber: startMeetingJson.meetingNumber,
zoomAccessToken: startMeetingJson.zoomAccessToken,
};
type CustomViewerProps = {
leaveMeeting: () => void;
};
const CustomViewer = ({ leaveMeeting }: CustomViewerProps) => {
const [showScreenShare, setShowScreenShare] = useState(false);
const activeConfig: NativeLayoutUnit = {
kind: 'active',
x: 0,
y: 0,
width: 1,
height: 1,
};
const activeShareConfig: NativeLayoutUnit = {
kind: 'active-share',
x: 0,
y: 0,
width: 1,
height: 1,
};
return (
<View style={StyleSheet.absoluteFillObject}>
<Button onPress={leaveMeeting} title="Leave meeting" />
<Button onPress={() => ZoomUs.startShareScreen()} title="Share screen" />
<Button
onPress={() => setShowScreenShare(!showScreenShare)}
title={!showScreenShare ? 'Show screen' : 'Show video'}
/>
<ZoomUsVideoView
style={styles.customViewer}
layout={[
// TODO: check why showing both at the same time does not work
showScreenShare ? activeShareConfig : activeConfig,
// Selfcamera preview
{
kind: 'preview',
// The percent of video view (required)
x: 0.73,
y: 0.73,
width: 0.25,
height: 0.2,
// Enable border (optional)
border: true,
// Disable show user name (optional)
showUsername: false,
// Show audio off (optional)
showAudioOff: true,
// Background color (optional)
background: '#ccc',
},
/*
// share video
{
kind: 'share',
// The index of user list (required)
userIndex: 0,
},
// Specify attendee
{
kind: 'attendee',
// The index of user list (required)
userIndex: 0,
},
{
kind: 'attendee',
userIndex: 1,
},
*/
]}
/>
</View>
);
};
// 3. `TODO` Enable custom view (android only)
const enableCustomizedMeetingUI = false;
const App = () => {
const isDarkMode = useColorScheme() === 'dark';
const [isInitialized, setIsInitialized] = useState(false);
const [isMeetingOngoing, setIsMeetingOngoing] = useState(false);
console.log({ isDarkMode });
useEffect(() => {
(async () => {
try {
const initializeResult = await ZoomUs.initialize(
{ clientKey: sdkKey, clientSecret: sdkSecret },
{
enableCustomizedMeetingUI,
},
);
console.log({ initializeResult });
setIsInitialized(true);
} catch (e) {
Alert.alert('Error', 'Could not execute initialize');
console.error('ERR', e);
}
})();
}, []);
useEffect(() => {
if (!isInitialized) {
return;
}
// For more see https://github.com/mieszko4/react-native-zoom-us/blob/master/docs/EVENTS.md
const zoomEmitter = new NativeEventEmitter(ZoomEmitter);
const eventListener = zoomEmitter.addListener(
'MeetingEvent',
({ event, status, ...params }) => {
console.log({ event, status, params }); //e.g. "endedByHost" (see more: https://github.com/mieszko4/react-native-zoom-us/blob/master/docs/EVENTS.md)
if (status === 'MEETING_STATUS_CONNECTING') {
setIsMeetingOngoing(true);
}
if (status === 'MEETING_STATUS_DISCONNECTING') {
// Once it is set it is good to render
setIsMeetingOngoing(false);
}
},
);
return () => eventListener.remove();
}, [isInitialized]);
const startMeeting = async () => {
try {
const startMeetingResult = await ZoomUs.startMeeting({
userName: 'John',
meetingNumber: exampleStartMeeting.meetingNumber,
userId: exampleStartMeeting.userId,
zoomAccessToken: exampleStartMeeting.zoomAccessToken,
noMeetingErrorMessage: true, // Set this to be able to show Alert.alert
});
console.log({ startMeetingResult });
} catch (e) {
Alert.alert('Error', 'Could not execute startMeeting');
console.error('ERR', e);
}
};
const joinMeeting = async () => {
try {
const joinMeetingResult = await ZoomUs.joinMeeting({
autoConnectAudio: true,
userName: `Sohan`,
meetingNumber: '88970751208',
password: 'Wg9DVT',
noMeetingErrorMessage: true, // Set this to be able to show Alert.alert
});
console.log({ joinMeetingResult });
} catch (e) {
Alert.alert('Error', 'Could not execute joinMeeting');
console.error('ERR', e);
}
};
const leaveMeeting = async () => {
try {
const leaveMeetingResult = await ZoomUs.leaveMeeting();
console.log({ leaveMeetingResult });
} catch (e) {
Alert.alert('Error', 'Could not execute leaveMeeting');
console.error('ERR', e);
}
};
return (
<>
<View style={styles.container}>
{/* <Button
onPress={() => startMeeting()}
title="Start example meeting"
disabled={!isInitialized}
/> */}
<Text>-------</Text>
<Button
onPress={() => joinMeeting()}
title="Join example meeting"
/>
</View>
{enableCustomizedMeetingUI && isMeetingOngoing && (
<CustomViewer leaveMeeting={leaveMeeting} />
)}
</>
);
};
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
customViewer: {
width: '100%',
flex: 1,
},
});
export default App;