|
@@ -47,13 +47,13 @@ RCT_EXPORT_MODULE();
|
47
|
47
|
* @return 0 when executed successfully. return negative value if failed.
|
48
|
48
|
*/
|
49
|
49
|
RCT_EXPORT_METHOD(init:(NSDictionary *)options) {
|
50
|
|
-
|
|
50
|
+
|
51
|
51
|
[AgoraConst share].appid = options[@"appid"];
|
52
|
|
-
|
|
52
|
+
|
53
|
53
|
self.rtcEngine = [AgoraRtcEngineKit sharedEngineWithAppId:options[@"appid"] delegate:self];
|
54
|
|
-
|
|
54
|
+
|
55
|
55
|
[AgoraConst share].rtcEngine = self.rtcEngine;
|
56
|
|
-
|
|
56
|
+
|
57
|
57
|
//频道模式
|
58
|
58
|
[self.rtcEngine setChannelProfile:[options[@"channelProfile"] integerValue]];
|
59
|
59
|
//启用双流模式
|
|
@@ -61,10 +61,10 @@ RCT_EXPORT_METHOD(init:(NSDictionary *)options) {
|
61
|
61
|
[self.rtcEngine enableVideo];
|
62
|
62
|
[self.rtcEngine setVideoProfile:[options[@"videoProfile"] integerValue]swapWidthAndHeight:[options[@"swapWidthAndHeight"]boolValue]];
|
63
|
63
|
[self.rtcEngine setClientRole:[options[@"clientRole"] integerValue] withKey:nil];
|
64
|
|
-
|
|
64
|
+
|
65
|
65
|
//Agora Native SDK 与 Agora Web SDK 间的互通
|
66
|
66
|
[self.rtcEngine enableWebSdkInteroperability:YES];
|
67
|
|
-
|
|
67
|
+
|
68
|
68
|
}
|
69
|
69
|
|
70
|
70
|
//加入房间
|
|
@@ -79,7 +79,7 @@ RCT_EXPORT_METHOD(leaveChannel){
|
79
|
79
|
[self.rtcEngine leaveChannel:^(AgoraRtcStats *stat) {
|
80
|
80
|
NSMutableDictionary *params = @{}.mutableCopy;
|
81
|
81
|
params[@"type"] = @"onLeaveChannel";
|
82
|
|
-
|
|
82
|
+
|
83
|
83
|
[self sendEvent:params];
|
84
|
84
|
}];
|
85
|
85
|
}
|
|
@@ -117,7 +117,7 @@ RCT_EXPORT_METHOD(startPreview){
|
117
|
117
|
//主播必须在加入频道前调用本章 API
|
118
|
118
|
RCT_EXPORT_METHOD(configPublisher:(NSDictionary *)config){
|
119
|
119
|
AgoraPublisherConfiguration *apc = [AgoraPublisherConfiguration new];
|
120
|
|
-
|
|
120
|
+
|
121
|
121
|
apc.width = [config[@"width"] integerValue]; //旁路直播的输出码流的宽度
|
122
|
122
|
apc.height = [config[@"height"] integerValue]; //旁路直播的输出码流的高度
|
123
|
123
|
apc.framerate = [config[@"framerate"] integerValue]; //旁路直播的输出码率帧率
|
|
@@ -128,7 +128,7 @@ RCT_EXPORT_METHOD(configPublisher:(NSDictionary *)config){
|
128
|
128
|
apc.rawStreamUrl = config[@"rawStreamUrl"]; //单流地址
|
129
|
129
|
apc.extraInfo = config[@"extraInfo"]; //其他信息
|
130
|
130
|
apc.owner = [config[@"owner"] boolValue]; //是否将当前主播设为该 RTMP 流的主人
|
131
|
|
-
|
|
131
|
+
|
132
|
132
|
[self.rtcEngine configPublisher:apc];
|
133
|
133
|
}
|
134
|
134
|
|
|
@@ -237,6 +237,23 @@ RCT_EXPORT_METHOD(stopRecordingService:(NSString*)recordingKey){
|
237
|
237
|
[self.rtcEngine stopRecordingService:recordingKey];
|
238
|
238
|
}
|
239
|
239
|
|
|
240
|
+/*
|
|
241
|
+创建数据流
|
|
242
|
+*/
|
|
243
|
+RCT_EXPORT_METHOD(createDataStream:(BOOL)reliable ordered:(BOOL)ordered callback:(RCTResponseSenderBlock)callback){
|
|
244
|
+ NSInteger streamId = 0;
|
|
245
|
+ [self.rtcEngine createDataStream:&streamId reliable:reliable ordered:ordered];
|
|
246
|
+ callback(@[[NSNumber numberWithInteger:streamId]]);
|
|
247
|
+}
|
|
248
|
+
|
|
249
|
+/*
|
|
250
|
+发送数据流
|
|
251
|
+*/
|
|
252
|
+RCT_EXPORT_METHOD(sendStreamMessage:(NSInteger)streamId data:(NSData*)data callback:(RCTResponseSenderBlock)callback){
|
|
253
|
+ int err = [self.rtcEngine sendStreamMessage:(streamId > 0 ? streamId : defaultDataStreamId) data:data];
|
|
254
|
+ callback(@[[NSNumber numberWithInteger:err]]);
|
|
255
|
+}
|
|
256
|
+
|
240
|
257
|
//获取版本号
|
241
|
258
|
RCT_EXPORT_METHOD(getSdkVersion:(RCTResponseSenderBlock)callback){
|
242
|
259
|
callback(@[[AgoraRtcEngineKit getSdkVersion]]);
|
|
@@ -252,7 +269,7 @@ RCT_EXPORT_METHOD(getSdkVersion:(RCTResponseSenderBlock)callback){
|
252
|
269
|
NSMutableDictionary *params = @{}.mutableCopy;
|
253
|
270
|
params[@"type"] = @"onError";
|
254
|
271
|
params[@"err"] = [NSNumber numberWithInteger:errorCode];;
|
255
|
|
-
|
|
272
|
+
|
256
|
273
|
[self sendEvent:params];
|
257
|
274
|
}
|
258
|
275
|
|
|
@@ -263,7 +280,7 @@ RCT_EXPORT_METHOD(getSdkVersion:(RCTResponseSenderBlock)callback){
|
263
|
280
|
NSMutableDictionary *params = @{}.mutableCopy;
|
264
|
281
|
params[@"type"] = @"onWarning";
|
265
|
282
|
params[@"err"] = [NSNumber numberWithInteger:warningCode];;
|
266
|
|
-
|
|
283
|
+
|
267
|
284
|
[self sendEvent:params];
|
268
|
285
|
}
|
269
|
286
|
|
|
@@ -277,7 +294,7 @@ RCT_EXPORT_METHOD(getSdkVersion:(RCTResponseSenderBlock)callback){
|
277
|
294
|
params[@"type"] = @"onJoinChannelSuccess";
|
278
|
295
|
params[@"uid"] = [NSNumber numberWithInteger:uid];
|
279
|
296
|
params[@"channel"] = channel;
|
280
|
|
-
|
|
297
|
+
|
281
|
298
|
[self sendEvent:params];
|
282
|
299
|
}
|
283
|
300
|
|
|
@@ -285,11 +302,11 @@ RCT_EXPORT_METHOD(getSdkVersion:(RCTResponseSenderBlock)callback){
|
285
|
302
|
远端首帧视频接收解码回调
|
286
|
303
|
*/
|
287
|
304
|
- (void)rtcEngine:(AgoraRtcEngineKit *)engine firstRemoteVideoDecodedOfUid:(NSUInteger)uid size:(CGSize)size elapsed:(NSInteger)elapsed {
|
288
|
|
-
|
|
305
|
+
|
289
|
306
|
NSMutableDictionary *params = @{}.mutableCopy;
|
290
|
307
|
params[@"type"] = @"onFirstRemoteVideoDecoded";
|
291
|
308
|
params[@"uid"] = [NSNumber numberWithInteger:uid];
|
292
|
|
-
|
|
309
|
+
|
293
|
310
|
[self sendEvent:params];
|
294
|
311
|
|
295
|
312
|
}
|
|
@@ -301,7 +318,7 @@ RCT_EXPORT_METHOD(getSdkVersion:(RCTResponseSenderBlock)callback){
|
301
|
318
|
NSMutableDictionary *params = @{}.mutableCopy;
|
302
|
319
|
params[@"type"] = @"onUserJoined";
|
303
|
320
|
params[@"uid"] = [NSNumber numberWithInteger:uid];
|
304
|
|
-
|
|
321
|
+
|
305
|
322
|
[self sendEvent:params];
|
306
|
323
|
}
|
307
|
324
|
|
|
@@ -312,7 +329,7 @@ RCT_EXPORT_METHOD(getSdkVersion:(RCTResponseSenderBlock)callback){
|
312
|
329
|
NSMutableDictionary *params = @{}.mutableCopy;
|
313
|
330
|
params[@"type"] = @"onUserOffline";
|
314
|
331
|
params[@"uid"] = [NSNumber numberWithInteger:uid];
|
315
|
|
-
|
|
332
|
+
|
316
|
333
|
[self sendEvent:params];
|
317
|
334
|
}
|
318
|
335
|
|
|
@@ -323,18 +340,44 @@ RCT_EXPORT_METHOD(getSdkVersion:(RCTResponseSenderBlock)callback){
|
323
|
340
|
- (void)rtcEngine:(AgoraRtcEngineKit *)engine reportAudioVolumeIndicationOfSpeakers:(NSArray*)speakers totalVolume:(NSInteger)totalVolume {
|
324
|
341
|
NSMutableDictionary *params = @{}.mutableCopy;
|
325
|
342
|
params[@"type"] = @"onAudioVolumeIndication";
|
326
|
|
-
|
|
343
|
+
|
327
|
344
|
NSMutableArray *arr = [NSMutableArray array];
|
328
|
345
|
for (AgoraRtcAudioVolumeInfo *obj in speakers) {
|
329
|
346
|
[arr addObject:@{@"uid":[NSNumber numberWithInteger:obj.uid], @"volume":[NSNumber numberWithInteger:obj.volume]}];
|
330
|
347
|
}
|
331
|
|
-
|
|
348
|
+
|
332
|
349
|
params[@"speakers"] = arr;
|
333
|
350
|
params[@"totalVolume"] = [NSNumber numberWithInteger:totalVolume];
|
334
|
|
-
|
|
351
|
+
|
335
|
352
|
[self sendEvent:params];
|
336
|
353
|
}
|
337
|
354
|
|
|
355
|
+/*
|
|
356
|
+接受数据流
|
|
357
|
+*/
|
|
358
|
+
|
|
359
|
+- (void)rtcEngine:(AgoraRtcEngineKit * _Nonnull)engine receiveStreamMessageFromUid:(NSUInteger)uid streamId:(NSInteger)streamId data:(NSData * _Nonnull)data{
|
|
360
|
+ NSMutableDictionary *params = @{}.mutableCopy;
|
|
361
|
+ params[@"type"] = @"onStreamMessage";
|
|
362
|
+ params[@"uid"] = [NSNumber numberWithInteger:uid];
|
|
363
|
+ params[@"streamId"] = [NSNumber numberWithInteger:streamId];
|
|
364
|
+ params[@"data"] = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
|
|
365
|
+
|
|
366
|
+ [self sendEvent:params];
|
|
367
|
+}
|
|
368
|
+
|
|
369
|
+- (void)rtcEngine:(AgoraRtcEngineKit *)engine didOccurStreamMessageErrorFromUid:(NSUInteger)uid streamId:(NSInteger)streamId error:(NSInteger)error missed:(NSInteger)missed cached:(NSInteger)cached{
|
|
370
|
+ NSMutableDictionary *params = @{}.mutableCopy;
|
|
371
|
+ params[@"type"] = @"onStreamMessageError";
|
|
372
|
+ params[@"uid"] = [NSNumber numberWithInteger:uid];
|
|
373
|
+ params[@"streamId"] = [NSNumber numberWithInteger:streamId];
|
|
374
|
+ params[@"error"] = [NSNumber numberWithInteger:error];
|
|
375
|
+ params[@"missed"] = [NSNumber numberWithInteger:missed];
|
|
376
|
+ params[@"cached"] = [NSNumber numberWithInteger:cached];
|
|
377
|
+
|
|
378
|
+ [self sendEvent:params];
|
|
379
|
+}
|
|
380
|
+
|
338
|
381
|
- (void)sendEvent:(NSDictionary *)params {
|
339
|
382
|
[_bridge.eventDispatcher sendDeviceEventWithName:@"agoraEvent" body:params];
|
340
|
383
|
}
|
|
@@ -344,10 +387,10 @@ RCT_EXPORT_METHOD(getSdkVersion:(RCTResponseSenderBlock)callback){
|
344
|
387
|
}
|
345
|
388
|
|
346
|
389
|
//RCT_EXPORT_METHOD(getViewWithTag:(nonnull NSNumber *)reactTag) {
|
347
|
|
-//
|
|
390
|
+//
|
348
|
391
|
// UIView *view = [self.bridge.uiManager viewForReactTag:reactTag];
|
349
|
392
|
// NSLog(@"%@",view);
|
350
|
|
-//
|
|
393
|
+//
|
351
|
394
|
//}
|
352
|
395
|
|
353
|
396
|
@end
|