Browse Source

Added the listeners localVideoStats, remoteVideoStats, rtcEngineConnectionLost, networkQuality, lastmileQuality and joinChannelWithToken;

HaroldoTeruya 5 years ago
parent
commit
e5f1bf0d49

+ 11
- 2
RtcEngine.js View File

@@ -13,7 +13,10 @@ export default {
13 13
         Agora.init(options);
14 14
     },
15 15
     joinChannel(channelName = '00001', uid = 0){
16
-        Agora.joinChannel(channelName, uid)
16
+        Agora.joinChannel(channelName, uid);
17
+    },
18
+    joinChannelWithToken(token, channelName = '00001', uid = 0){
19
+        Agora.joinChannelWithToken(token, channelName, uid);
17 20
     },
18 21
     eventEmitter(fnConf) {
19 22
         //there are no `removeListener` for NativeAppEventEmitter & DeviceEventEmitter
@@ -24,5 +27,11 @@ export default {
24 27
     },
25 28
     removeEmitter() {
26 29
         this.listener && this.listener.remove();
27
-    }
30
+    },
31
+    enableLastmileTest() {
32
+        Agora.enableLastmileTest();
33
+    },
34
+    disableLastmileTest() {
35
+        Agora.disableLastmileTest();
36
+    },
28 37
 };

+ 2
- 2
android/build.gradle View File

@@ -22,6 +22,6 @@ android {
22 22
 }
23 23
 
24 24
 dependencies {
25
-    compile "com.facebook.react:react-native:+"
26
-    compile fileTree(dir: 'libs', include: ['*.jar'])
25
+    implementation "com.facebook.react:react-native:+"
26
+    implementation fileTree(dir: 'libs', include: ['*.jar'])
27 27
 }

+ 16
- 1
android/src/main/java/com/syan/agora/AgoraManager.java View File

@@ -95,6 +95,21 @@ public class AgoraManager {
95 95
         return this;
96 96
     }
97 97
 
98
+    public AgoraManager joinChannelWithToken(String token, String channel, int uid) {
99
+        mRtcEngine.joinChannel(token, channel, null, uid);
100
+        return this;
101
+    }
102
+
103
+    public AgoraManager enableLastmileTest() {
104
+        mRtcEngine.enableLastmileTest();
105
+        return this;
106
+    }
107
+
108
+    public AgoraManager disableLastmileTest() {
109
+        mRtcEngine.disableLastmileTest();
110
+        return this;
111
+    }
112
+
98 113
     public void startPreview() {
99 114
         mRtcEngine.startPreview();
100 115
     }
@@ -129,4 +144,4 @@ public class AgoraManager {
129 144
     }
130 145
 
131 146
 
132
-}
147
+}

+ 85
- 0
android/src/main/java/com/syan/agora/AgoraModule.java View File

@@ -253,6 +253,76 @@ public class AgoraModule extends ReactContextBaseJavaModule {
253 253
                 }
254 254
             });
255 255
         }
256
+
257
+        @Override
258
+        public void onLocalVideoStats(final LocalVideoStats stats) {
259
+            runOnUiThread(new Runnable() {
260
+                @Override
261
+                public void run() {
262
+                    WritableMap map = Arguments.createMap();
263
+                    map.putString("type", "onLocalVideoStats");
264
+                    map.putInt("sentBitrate", stats.sentBitrate);
265
+                    map.putInt("sentFrameRate", stats.sentFrameRate);
266
+                    commonEvent(map);
267
+                }
268
+            });
269
+        }
270
+
271
+        @Override
272
+        public void onRemoteVideoStats(final RemoteVideoStats stats) {
273
+            runOnUiThread(new Runnable() {
274
+                @Override
275
+                public void run() {
276
+                    WritableMap map = Arguments.createMap();
277
+                    map.putString("type", "onRemoteVideoStats");
278
+                    map.putInt("delay", stats.delay);
279
+                    map.putInt("receivedBitrate", stats.receivedBitrate);
280
+                    map.putInt("receivedFrameRate", stats.receivedFrameRate);
281
+                    map.putInt("rxStreamType", stats.rxStreamType);
282
+                    commonEvent(map);
283
+                }
284
+            });
285
+        }
286
+
287
+        @Override
288
+        public void onConnectionLost() {
289
+            runOnUiThread(new Runnable() {
290
+                @Override
291
+                public void run() {
292
+                    WritableMap map = Arguments.createMap();
293
+                    map.putString("type", "onConnectionLost");
294
+                    commonEvent(map);
295
+                }
296
+            });
297
+        }
298
+
299
+        @Override
300
+        public void onNetworkQuality(final int uid, final int txQuality, final int rxQuality) {
301
+            runOnUiThread(new Runnable() {
302
+                @Override
303
+                public void run() {
304
+                    WritableMap map = Arguments.createMap();
305
+                    map.putString("type", "onNetworkQuality");
306
+                    map.putInt("uid", uid);
307
+                    map.putInt("txQuality", txQuality);
308
+                    map.putInt("rxQuality", rxQuality);
309
+                    commonEvent(map);
310
+                }
311
+            });
312
+        }
313
+
314
+        @Override
315
+        public void onLastmileQuality(final int quality) {
316
+            runOnUiThread(new Runnable() {
317
+                @Override
318
+                public void run() {
319
+                    WritableMap map = Arguments.createMap();
320
+                    map.putString("type", "onLastmileQuality");
321
+                    map.putInt("quality", quality);
322
+                    commonEvent(map);
323
+                }
324
+            });
325
+        }
256 326
     };
257 327
 
258 328
     @ReactMethod
@@ -260,12 +330,27 @@ public class AgoraModule extends ReactContextBaseJavaModule {
260 330
         AgoraManager.getInstance().init(getReactApplicationContext(), mRtcEventHandler, options);
261 331
     }
262 332
 
333
+    @ReactMethod
334
+    public void enableLastmileTest() {
335
+        AgoraManager.getInstance().enableLastmileTest();
336
+    }
337
+
338
+    @ReactMethod
339
+    public void disableLastmileTest() {
340
+        AgoraManager.getInstance().disableLastmileTest();
341
+    }
342
+
263 343
     //进入房间
264 344
     @ReactMethod
265 345
     public void joinChannel(String channelName, int uid) {
266 346
         AgoraManager.getInstance().joinChannel(channelName, uid);
267 347
     }
268 348
 
349
+    @ReactMethod
350
+    public void joinChannelWithToken(String token, String channelName, int uid) {
351
+        AgoraManager.getInstance().joinChannelWithToken(token, channelName, uid);
352
+    }
353
+
269 354
     //退出
270 355
     @ReactMethod
271 356
     public void leaveChannel() {

+ 60
- 2
ios/RCTAgora/RCTAgora.m View File

@@ -67,6 +67,14 @@ RCT_EXPORT_METHOD(init:(NSDictionary *)options) {
67 67
 
68 68
 }
69 69
 
70
+RCT_EXPORT_METHOD(enableLastmileTest) {
71
+    [self.rtcEngine enableLastmileTest];
72
+}
73
+
74
+RCT_EXPORT_METHOD(disableLastmileTest) {
75
+    [self.rtcEngine disableLastmileTest];
76
+}
77
+
70 78
 //加入房间
71 79
 RCT_EXPORT_METHOD(joinChannel:(NSString *)channelName uid:(NSInteger)uid) {
72 80
     //保存一下uid 在自定义视图使用
@@ -74,6 +82,12 @@ RCT_EXPORT_METHOD(joinChannel:(NSString *)channelName uid:(NSInteger)uid) {
74 82
     [self.rtcEngine joinChannelByKey:nil channelName:channelName info:nil uid:uid joinSuccess:NULL];
75 83
 }
76 84
 
85
+RCT_EXPORT_METHOD(joinChannelWithToken:(NSString *)token channelName:(NSString *)channelName uid:(NSInteger)uid) {
86
+    //保存一下uid 在自定义视图使用
87
+    [AgoraConst share].localUid = uid;
88
+    [self.rtcEngine joinChannelByKey:token channelName:channelName info:nil uid:uid joinSuccess:NULL];
89
+}
90
+
77 91
 //离开频道
78 92
 RCT_EXPORT_METHOD(leaveChannel){
79 93
     [self.rtcEngine leaveChannel:^(AgoraRtcStats *stat) {
@@ -352,12 +366,57 @@ RCT_EXPORT_METHOD(getSdkVersion:(RCTResponseSenderBlock)callback){
352 366
 - (void)rtcEngine:(AgoraRtcEngineKit *)engine didVideoMuted:(BOOL)muted byUid:(NSUInteger)uid {
353 367
     NSMutableDictionary *params = @{}.mutableCopy;
354 368
     params[@"type"] = @"onUserMuteVideo";
355
-    params[@"uid"] = [NSNumber numberWithInteger:uid];;
369
+    params[@"uid"] = [NSNumber numberWithInteger:uid];
356 370
     params[@"muted"] = @(muted);
357 371
 
358 372
     [self sendEvent:params];
359 373
 }
360 374
 
375
+- (void)rtcEngine:(AgoraRtcEngineKit *)engine localVideoStats:(AgoraRtcLocalVideoStats *)stats {
376
+    NSMutableDictionary *params = @{}.mutableCopy;
377
+    params[@"type"] = @"onLocalVideoStats";
378
+    params[@"sentBitrate"] = @(stats.sentBitrate);
379
+    params[@"sentFrameRate"] = @(stats.sentFrameRate);
380
+
381
+    [self sendEvent:params];
382
+}
383
+
384
+- (void)rtcEngine:(AgoraRtcEngineKit *)engine remoteVideoStats:(AgoraRtcRemoteVideoStats *)stats {
385
+    NSMutableDictionary *params = @{}.mutableCopy;
386
+    params[@"type"] = @"onRemoteVideoStats";
387
+    params[@"delay"] = @(stats.delay);
388
+    params[@"reivedBitrate"] = @(stats.receivedBitrate);
389
+    params[@"receivedFrameRate"] = @(stats.receivedFrameRate);
390
+    params[@"rxStreamType"] = @(stats.rxStreamType);
391
+
392
+    [self sendEvent:params];
393
+}
394
+
395
+- (void)rtcEngineConnectionDidLost:(AgoraRtcEngineKit *)engine {
396
+    NSMutableDictionary *params = @{}.mutableCopy;
397
+    params[@"type"] = @"onConnectionLost";
398
+
399
+    [self sendEvent:params];
400
+}
401
+
402
+- (void)rtcEngine:(AgoraRtcEngineKit *)engine networkQuality:(NSUInteger)uid txQuality:(AgoraRtcQuality)txQuality rxQuality:(AgoraRtcQuality)rxQuality {
403
+    NSMutableDictionary *params = @{}.mutableCopy;
404
+    params[@"type"] = @"onNetworkQuality";
405
+    params[@"uid"] = @(uid);
406
+    params[@"txQuality"] = @(txQuality);
407
+    params[@"rxQuality"] = @(rxQuality);
408
+
409
+    [self sendEvent:params];
410
+}
411
+
412
+- (void)rtcEngine:(AgoraRtcEngineKit *)engine lastmileQuality:(AgoraRtcQuality)quality {
413
+    NSMutableDictionary *params = @{}.mutableCopy;
414
+    params[@"type"] = @"onLastmileQuality";
415
+    params[@"quality"] = @(quality);
416
+
417
+    [self sendEvent:params];
418
+}
419
+
361 420
 /*
362 421
  音量提示回调
363 422
  需要开启enableAudioVolumeIndication
@@ -419,4 +478,3 @@ RCT_EXPORT_METHOD(getSdkVersion:(RCTResponseSenderBlock)callback){
419 478
 //}
420 479
 
421 480
 @end
422
-