-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.js
285 lines (239 loc) · 7.26 KB
/
index.js
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
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
import {
DeviceEventEmitter,
NativeModules,
Platform
} from 'react-native'
import JMRTCView from './jmrtcview';
const JMRTCModule = NativeModules.JMRTCModule
const CallOutgoing = 'JMRTC.CallOutgoing'
const CallReceiveInvite = 'JMRTC.CallReceiveInvite'
const CallConnecting = 'JMRTC.CallConnecting'
const CallConnected = 'JMRTC.CallConnected'
const CallMemberJoin = 'JMRTC.CallMemberJoin'
const CallDisconnect = 'JMRTC.CallDisconnect'
const CallMemberLeave = 'JMRTC.CallMemberLeave'
const CallOtherUserInvited = 'JMRTC.CallOtherUserInvited'
const CallError = 'JMRTC.CallError'
const CallUserVideoStreamEnabled = 'JMRTC.CallUserVideoStreamEnabled'
const listeners = {}
export default class JMRTCViewController {
/**
* 初始化音视频引擎,初始化完成会回调 cb 函数。
* @param {Function} success = (res) => { }
* @param {Function} fail = (error) => { }
*/
static initEngine(success, fail) {
JMRTCModule.initEngine(success,fail)
}
/**
* 获取权限后重新初始化引擎(Android only)。
* @param {Function} success = (res) => { }
* @param {Function} fail = (error) => { }
*/
static reinitEngine(success, fail) {
if (Platform.OS == "android") {
JMRTCModule.reinitEngine(success, fail);
}
}
/**
* 释放音视频引擎
*/
static releaseEngine() {
JMRTCModule.releaseEngine();
}
/**
* @abstract 发起一个通话
* @param params = {usernames: [String], type = 'video' | 'voice'}
* @param success = () => {} 成功回调
* @param fail = () => {} 失败回调
*/
static startCallUsers(params, success, fail) {
JMRTCModule.startCallUsers(params, success, fail)
}
/**
* 设置实时视频的展示视图
* @param {Object} params = {username: string}
*/
static setVideoView(params) {
JMRTCModule.setVideoView(params)
}
/**
* @abstract 设置视频输出的编码属性
*
* @param params = {profile: '240p' | '360p' | '480p' | '720p'} 视频编码属性,不调用这个接口默认是 '360p'
*
* ### 建议在发起通话之前,调用此接口设置,避免在通话过程中调用此接口
*
* @discussion 注意:多人视频通话期间设置此接口可能会失效
*/
static setVideoProfile(params) {
JMRTCModule.setVideoProfile(params)
}
/**
* @abstract 设置视频输出的编码属性
* callback = (res) => {} , res = {profile: '240p' | '360p' | '480p' | '720p'}
*/
static getVideoProfile(callback) {
JMRTCModule.getVideoProfile(callback)
}
/**
* @abstract 设置视频输出的编码属性
* callback = (res) => {} , res = {profile: '240p' | '360p' | '480p' | '720p'}
*/
static switchCamera() {
JMRTCModule.switchCamera()
}
// 实例方法
/**
* @abstract 接听来电
* @param success = () => {} 成功回调
* @param fail = () => {} 失败回调
*/
static accept(success, fail) {
JMRTCModule.accept(success, fail)
}
/**
* @abstract 挂断通话
* @param success = () => {} 成功回调
* @param fail = () => {} 失败回调
*/
static hangup(success, fail) {
JMRTCModule.hangup(success, fail)
}
/**
* @abstract 拒绝通话
* @param success = () => {} 成功回调
* @param fail = () => {} 失败回调
*/
static refuse(success, fail) {
JMRTCModule.refuse(success, fail)
}
/**
* @abstract 邀请其他用户加入通话
* @param params = {usernames: [String]}
* @param success = () => {} 成功回调
* @param fail = () => {} 失败回调
*/
static inviteUsers(params, success, fail) {
JMRTCModule.inviteUsers(params, success, fail)
}
/**
*
* @param {Function} callback = (boolean) => {}
*/
static isMuted(callback) {
JMRTCModule.isMuted(callback)
}
static setIsMuted(params) {
JMRTCModule.setIsMuted(params)
}
/**
*
* @param {Function} callback = (boolean) => {}
*/
static isSpeakerphoneEnabled(callback) {
JMRTCModule.isSpeakerphoneEnabled(callback)
}
static setIsSpeakerphoneEnabled(params) {
JMRTCModule.setIsSpeakerphoneEnabled(params)
}
/**
*
* @param {Function} callback = (boolean) => {}
*/
static isVideoStreamEnabled(callback) {
JMRTCModule.isVideoStreamEnabled(callback)
}
static setIsVideoStreamEnabled(params) {
JMRTCModule.setIsVideoStreamEnabled(params)
}
// 事件
static addCallOutgoingListener(callback) {
listeners[callback] = DeviceEventEmitter.addListener(CallOutgoing, map => {
callback(map)
})
}
static addCallReceiveInviteListener(callback) {
if (!listeners[callback]) {
console.warn('函数被重复用于监听,可能会出现未预期的问题!')
}
listeners[callback] = DeviceEventEmitter.addListener(CallReceiveInvite, map => {
callback(map)
})
}
static addCallConnectingListener(callback) {
if (!listeners[callback]) {
console.warn('函数被重复用于监听,可能会出现未预期的问题!')
}
listeners[callback] = DeviceEventEmitter.addListener(CallConnecting, map => {
callback(map)
})
}
static addCallConnectedListener(callback) {
if (!listeners[callback]) {
console.warn('函数被重复用于监听,可能会出现未预期的问题!')
}
listeners[callback] = DeviceEventEmitter.addListener(CallConnected, map => {
callback(map)
})
}
static addCallMemberJoinListener(callback) {
if (!listeners[callback]) {
console.warn('函数被重复用于监听,可能会出现未预期的问题!')
}
listeners[callback] = DeviceEventEmitter.addListener(CallMemberJoin, map => {
callback(map)
})
}
static addCallDisconnectListener(callback) {
if (!listeners[callback]) {
console.warn('函数被重复用于监听,可能会出现未预期的问题!')
}
listeners[callback] = DeviceEventEmitter.addListener(CallDisconnect, map => {
callback(map)
})
}
static addCallMemberLeaveListener(callback) {
if (!listeners[callback]) {
console.warn('函数被重复用于监听,可能会出现未预期的问题!')
}
listeners[callback] = DeviceEventEmitter.addListener(CallMemberLeave, map => {
callback(map)
})
}
static addCallOtherUserInvitedListener(callback) {
if (!listeners[callback]) {
console.warn('函数被重复用于监听,可能会出现未预期的问题!')
}
listeners[callback] = DeviceEventEmitter.addListener(CallOtherUserInvited, map => {
callback(map)
})
}
static addCallErrorListener(callback) {
if (!listeners[callback]) {
console.warn('函数被重复用于监听,可能会出现未预期的问题!')
}
listeners[callback] = DeviceEventEmitter.addListener(CallError, map => {
callback(map)
})
}
static addCallUserVideoStreamEnabledListener(callback) {
if (!listeners[callback]) {
console.warn('函数被重复用于监听,可能会出现未预期的问题!')
}
listeners[callback] = DeviceEventEmitter.addListener(CallUserVideoStreamEnabled, map => {
callback(map)
})
}
static removeListener(callback) {
if (!listeners[callback]) {
return
}
listeners[callback].remove()
listeners[callback] = null
}
}
module.exports = {
JMRTCViewController,
JMRTCView
}