forked from mieszko4/react-native-zoom-us
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
267 lines (223 loc) · 6.68 KB
/
index.ts
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 { NativeModule, Platform } from 'react-native'
import invariant from 'invariant'
import { RNZoomUs } from './native'
if (!RNZoomUs) console.error('RNZoomUs native module is not linked.')
const DEFAULT_USER_TYPE = 2
type Language = 'de' | 'ja' | 'en' | 'zh-Hant' | 'es' | 'zh-Hans' | 'it' | 'ko' | 'vi' | 'ru' | 'pt-PT' | 'fr';
const applyLanguageMapping = (language: Language): string => {
const androidLanguageMapping = {
'zh-Hans': 'zh-CN',
'zh-Hant': 'zh-TW',
};
if (Platform.OS === 'android') {
return androidLanguageMapping[language] || language;
}
return language;
}
interface RNZoomUsInitializeCommonParams {
domain?: string;
iosAppGroupId?: string;
iosScreenShareExtensionId?: string;
}
export interface RNZoomUsInitializeParams extends RNZoomUsInitializeCommonParams {
clientKey: string;
clientSecret: string;
}
export interface RNZoomUsSDKInitParams extends RNZoomUsInitializeCommonParams {
jwtToken: string;
// we don't care for the rest, for now
}
type InitializeSettings = {
language?: Language;
enableCustomizedMeetingUI?: boolean;
disableShowVideoPreviewWhenJoinMeeting?: boolean;
};
async function initialize(
{
domain = 'zoom.us',
...params
}: RNZoomUsInitializeParams|RNZoomUsSDKInitParams,
{
language = 'en',
enableCustomizedMeetingUI = false,
// ios only
// more details inside: https://github.com/mieszko4/react-native-zoom-us/issues/28
disableShowVideoPreviewWhenJoinMeeting = true
}: InitializeSettings = {},
): Promise<string> {
invariant(typeof params === 'object',
'ZoomUs.initialize expects object param. Consider to check migration docs. ' +
'Check Link: https://github.com/mieszko4/react-native-zoom-us/blob/master/docs/UPGRADING.md',
)
if ('jwtToken' in params) {
invariant(params.jwtToken, 'ZoomUs.initialize requires jwtToken')
} else {
invariant(params.clientKey, 'ZoomUs.initialize requires clientKey')
invariant(params.clientSecret, 'ZoomUs.initialize requires clientSecret')
}
const mappedSettings = {
language: applyLanguageMapping(language),
enableCustomizedMeetingUI,
disableShowVideoPreviewWhenJoinMeeting
};
const mappedParams = {
domain,
...params,
};
return RNZoomUs.initialize(mappedParams, mappedSettings)
}
function isInitialized(): Promise<boolean> {
return RNZoomUs.isInitialized()
}
export interface RNZoomUsJoinMeetingParams {
userName: string
meetingNumber: string | number
password?: string
autoConnectAudio?: boolean
noAudio?: boolean
noVideo?: boolean
noButtonLeave?: boolean
noButtonMore?: boolean
noButtonParticipants?: boolean
noButtonShare?: boolean
noTextMeetingId?: boolean
noTextPassword?: boolean
webinarToken?: string
// android only fields:
noInvite?: boolean
noBottomToolbar?: boolean
noPhoneDialIn?: boolean
noPhoneDialOut?: boolean
noMeetingEndMessage?: boolean
noMeetingErrorMessage?: boolean
noShare?: boolean
noTitlebar?: boolean
noDrivingMode?: boolean
noDisconnectAudio?: boolean
noRecord?: boolean
noUnmuteConfirmDialog?: boolean
noWebinarRegisterDialog?: boolean
noChatMsgToast?: boolean
// ios only fields:
zoomAccessToken?: string
}
async function joinMeeting(params: RNZoomUsJoinMeetingParams) {
let { meetingNumber, noAudio = false, noVideo = false, autoConnectAudio = false } = params
invariant(meetingNumber, 'ZoomUs.joinMeeting requires meetingNumber')
if (typeof meetingNumber !== 'string') meetingNumber = meetingNumber.toString()
// without noAudio, noVideo fields SDK can stack on joining meeting room for release build
return RNZoomUs.joinMeeting({
...params,
meetingNumber,
noAudio: !!noAudio, // required
noVideo: !!noVideo, // required
autoConnectAudio, // required
})
}
async function joinMeetingWithPassword(
userName: RNZoomUsJoinMeetingParams['userName'],
meetingNumber: NonNullable<RNZoomUsJoinMeetingParams['meetingNumber']>,
password: NonNullable<RNZoomUsJoinMeetingParams['password']>,
) {
console.warn("ZoomUs.joinMeetingWithPassword is deprecated. Use joinMeeting({ password: 'xxx', ... })")
return joinMeeting({
userName,
meetingNumber,
password,
})
}
export interface RNZoomUsStartMeetingParams {
userName: string
meetingNumber: string | number
userId: string
userType?: number // looks like can be different for IOS and Android
zoomAccessToken: string
// android only fields:
noInvite?: boolean
noShare?: boolean
noButtonLeave?: boolean
noButtonMore?: boolean
noButtonParticipants?: boolean
noButtonShare?: boolean
noTextMeetingId?: boolean
noTextPassword?: boolean
}
async function startMeeting(params: RNZoomUsStartMeetingParams) {
let { userType = DEFAULT_USER_TYPE, meetingNumber } = params
invariant(meetingNumber, 'ZoomUs.startMeeting requires meetingNumber')
if (typeof meetingNumber !== 'string') meetingNumber = meetingNumber.toString()
return RNZoomUs.startMeeting({ userType, ...params, meetingNumber })
}
async function leaveMeeting() {
return RNZoomUs.leaveMeeting()
}
async function connectAudio() {
return RNZoomUs.connectAudio()
}
async function isMeetingConnected() {
return RNZoomUs.isMeetingConnected()
}
async function isMeetingHost() {
return RNZoomUs.isMeetingHost()
}
async function getInMeetingUserIdList() {
return RNZoomUs.getInMeetingUserIdList()
}
async function rotateMyVideo(rotation: number) {
if (Platform.OS === 'android') {
return RNZoomUs.rotateMyVideo(rotation)
} else {
throw new Error('Only support android')
}
}
async function muteMyVideo(muted: boolean) {
return RNZoomUs.muteMyVideo(muted)
}
async function muteMyAudio(muted: boolean) {
return RNZoomUs.muteMyAudio(muted)
}
async function muteAttendee(userId: string, muted: boolean) {
return RNZoomUs.muteAttendee(userId, muted)
}
async function muteAllAttendee(allowUnmuteSelf: boolean) {
return RNZoomUs.muteAllAttendee(allowUnmuteSelf)
}
async function startShareScreen() {
return RNZoomUs.startShareScreen()
}
async function stopShareScreen() {
return RNZoomUs.stopShareScreen()
}
async function switchCamera() {
return RNZoomUs.switchCamera()
}
async function raiseMyHand() {
return RNZoomUs.raiseMyHand()
}
async function lowerMyHand() {
return RNZoomUs.lowerMyHand()
}
export const ZoomEmitter = RNZoomUs as NativeModule;
export { default as ZoomUsVideoView } from './video-view'
export default {
initialize,
joinMeeting,
joinMeetingWithPassword,
startMeeting,
leaveMeeting,
connectAudio,
isInitialized,
isMeetingHost,
isMeetingConnected,
getInMeetingUserIdList,
rotateMyVideo,
muteMyVideo,
muteMyAudio,
muteAttendee,
muteAllAttendee,
startShareScreen,
stopShareScreen,
switchCamera,
raiseMyHand,
lowerMyHand,
}