|
@@ -17,12 +17,14 @@ import com.facebook.react.bridge.WritableMap;
|
17
|
17
|
import com.facebook.react.modules.core.DeviceEventManagerModule;
|
18
|
18
|
|
19
|
19
|
|
|
20
|
+import java.nio.charset.Charset;
|
20
|
21
|
import java.util.ArrayList;
|
21
|
22
|
import java.util.HashMap;
|
22
|
23
|
import java.util.Map;
|
23
|
24
|
|
24
|
25
|
import io.agora.rtc.Constants;
|
25
|
26
|
import io.agora.rtc.IAudioEffectManager;
|
|
27
|
+import io.agora.rtc.IMetadataObserver;
|
26
|
28
|
import io.agora.rtc.IRtcEngineEventHandler;
|
27
|
29
|
import io.agora.rtc.RtcEngine;
|
28
|
30
|
import io.agora.rtc.internal.LastmileProbeConfig;
|
|
@@ -285,6 +287,11 @@ public class AgoraModule extends ReactContextBaseJavaModule {
|
285
|
287
|
private final static String AGUserEnableVideo = "userEnableVideo";
|
286
|
288
|
private final static String AGUserEnableLocalVideo = "userEnableLocalVideo";
|
287
|
289
|
private final static String AGVideoSizeChanged = "videoSizeChanged";
|
|
290
|
+ private final static String AGRtmpStreamingStateChanged = "rtmpStreamingStateChanged";
|
|
291
|
+ private final static String AGNetworkTypeChanged = "networkTypeChanged";
|
|
292
|
+ private final static String AGFirstRemoteAudioDecoded = "firstRemoteAudioDecoded";
|
|
293
|
+ private final static String AGMediaMetaDataReceived = "mediaMetaDataReceived";
|
|
294
|
+ private final static String AGLocalVideoChanged = "localVideoChanged";
|
288
|
295
|
private final static String AGRemoteVideoStateChanged = "remoteVideoStateChanged";
|
289
|
296
|
private final static String AGLocalPublishFallbackToAudioOnly = "localPublishFallbackToAudioOnly";
|
290
|
297
|
private final static String AGRemoteSubscribeFallbackToAudioOnly = "remoteSubscribeFallbackToAudioOnly";
|
|
@@ -303,10 +310,10 @@ public class AgoraModule extends ReactContextBaseJavaModule {
|
303
|
310
|
private final static String AGAudioTransportStatsOfUid = "audioTransportStatsOfUid";
|
304
|
311
|
private final static String AGVideoTransportStatsOfUid = "videoTransportStatsOfUid";
|
305
|
312
|
|
306
|
|
- private final static String AGLocalAudioMixingFinish = "localAudioMixingFinish";
|
307
|
313
|
private final static String AGRemoteAudioMixingStart = "remoteAudioMixingStart";
|
308
|
314
|
private final static String AGRemoteAudioMixingFinish = "remoteAudioMixingFinish";
|
309
|
315
|
private final static String AGAudioEffectFinish = "audioEffectFinish";
|
|
316
|
+ private final static String AGAudioMixingStateChanged = "audioMixingStateChanged";
|
310
|
317
|
|
311
|
318
|
private final static String AGStreamPublished = "streamPublished";
|
312
|
319
|
private final static String AGStreamUnpublish = "streamUnpublish";
|
|
@@ -322,6 +329,8 @@ public class AgoraModule extends ReactContextBaseJavaModule {
|
322
|
329
|
private final static String AGLastmileProbeResult = "lastmileProbeTestResult";
|
323
|
330
|
// private final static String AGIntervalTest = "startEchoTestWithInterval";
|
324
|
331
|
|
|
332
|
+ private MediaObserver mediaObserver = null;
|
|
333
|
+
|
325
|
334
|
private IRtcEngineEventHandler mRtcEventHandler = new IRtcEngineEventHandler() {
|
326
|
335
|
|
327
|
336
|
@Override
|
|
@@ -415,6 +424,8 @@ public class AgoraModule extends ReactContextBaseJavaModule {
|
415
|
424
|
statsMap.putInt("userCount", stats.users);
|
416
|
425
|
statsMap.putDouble("cpuAppUsage", stats.cpuAppUsage);
|
417
|
426
|
statsMap.putDouble("cpuTotalUsage", stats.cpuTotalUsage);
|
|
427
|
+ statsMap.putInt("txPacketLossRate", stats.txPacketLossRate);
|
|
428
|
+ statsMap.putInt("rxPacketLossRate", stats.rxPacketLossRate);
|
418
|
429
|
|
419
|
430
|
WritableMap map = Arguments.createMap();
|
420
|
431
|
map.putMap("stats", statsMap);
|
|
@@ -584,18 +595,6 @@ public class AgoraModule extends ReactContextBaseJavaModule {
|
584
|
595
|
});
|
585
|
596
|
}
|
586
|
597
|
|
587
|
|
- @Override
|
588
|
|
- public void onVideoStopped() {
|
589
|
|
- runOnUiThread(new Runnable() {
|
590
|
|
- @Override
|
591
|
|
- public void run() {
|
592
|
|
- WritableMap map = Arguments.createMap();
|
593
|
|
- map.putString("message", "VideoStopped");
|
594
|
|
- sendEvent(getReactApplicationContext(), AGVideoStopped, map);
|
595
|
|
- }
|
596
|
|
- });
|
597
|
|
- }
|
598
|
|
-
|
599
|
598
|
@Override
|
600
|
599
|
public void onFirstLocalVideoFrame(final int width, final int height, final int elapsed) {
|
601
|
600
|
runOnUiThread(new Runnable() {
|
|
@@ -710,6 +709,45 @@ public class AgoraModule extends ReactContextBaseJavaModule {
|
710
|
709
|
});
|
711
|
710
|
}
|
712
|
711
|
|
|
712
|
+ @Override
|
|
713
|
+ public void onRtmpStreamingStateChanged(final String url, final int state, final int errCode) {
|
|
714
|
+ runOnUiThread(new Runnable() {
|
|
715
|
+ @Override
|
|
716
|
+ public void run() {
|
|
717
|
+ WritableMap map = Arguments.createMap();
|
|
718
|
+ map.putString("url", url);
|
|
719
|
+ map.putInt("state", state);
|
|
720
|
+ map.putInt("errorCode", errCode);
|
|
721
|
+ sendEvent(getReactApplicationContext(), AGRtmpStreamingStateChanged, map);
|
|
722
|
+ }
|
|
723
|
+ });
|
|
724
|
+ }
|
|
725
|
+
|
|
726
|
+ @Override
|
|
727
|
+ public void onNetworkTypeChanged(final int type) {
|
|
728
|
+ runOnUiThread(new Runnable() {
|
|
729
|
+ @Override
|
|
730
|
+ public void run() {
|
|
731
|
+ WritableMap map = Arguments.createMap();
|
|
732
|
+ map.putInt("type", type);
|
|
733
|
+ sendEvent(getReactApplicationContext(), AGNetworkTypeChanged, map);
|
|
734
|
+ }
|
|
735
|
+ });
|
|
736
|
+ }
|
|
737
|
+
|
|
738
|
+ @Override
|
|
739
|
+ public void onFirstRemoteAudioDecoded(final int uid, final int elapsed) {
|
|
740
|
+ runOnUiThread(new Runnable() {
|
|
741
|
+ @Override
|
|
742
|
+ public void run() {
|
|
743
|
+ WritableMap map = Arguments.createMap();
|
|
744
|
+ map.putInt("uid", uid);
|
|
745
|
+ map.putInt("elapsed", elapsed);
|
|
746
|
+ sendEvent(getReactApplicationContext(), AGFirstRemoteAudioDecoded, map);
|
|
747
|
+ }
|
|
748
|
+ });
|
|
749
|
+ }
|
|
750
|
+
|
713
|
751
|
@Override
|
714
|
752
|
public void onRemoteVideoStateChanged(final int uid, final int state) {
|
715
|
753
|
runOnUiThread(new Runnable() {
|
|
@@ -760,18 +798,6 @@ public class AgoraModule extends ReactContextBaseJavaModule {
|
760
|
798
|
});
|
761
|
799
|
}
|
762
|
800
|
|
763
|
|
- @Override
|
764
|
|
- public void onCameraReady() {
|
765
|
|
- runOnUiThread(new Runnable() {
|
766
|
|
- @Override
|
767
|
|
- public void run() {
|
768
|
|
- WritableMap map = Arguments.createMap();
|
769
|
|
- map.putString("message", "CameraDidReady");
|
770
|
|
- sendEvent(getReactApplicationContext(), AGCameraReady, map);
|
771
|
|
- }
|
772
|
|
- });
|
773
|
|
- }
|
774
|
|
-
|
775
|
801
|
@Override
|
776
|
802
|
public void onCameraFocusAreaChanged(final Rect rect) {
|
777
|
803
|
runOnUiThread(new Runnable() {
|
|
@@ -841,6 +867,8 @@ public class AgoraModule extends ReactContextBaseJavaModule {
|
841
|
867
|
statsMap.putInt("userCount", stats.users);
|
842
|
868
|
statsMap.putDouble("cpuAppUsage", stats.cpuAppUsage);
|
843
|
869
|
statsMap.putDouble("cpuTotalUsage", stats.cpuTotalUsage);
|
|
870
|
+ statsMap.putInt("txPacketLossRate", stats.txPacketLossRate);
|
|
871
|
+ statsMap.putInt("rxPacketLossRate", stats.rxPacketLossRate);
|
844
|
872
|
|
845
|
873
|
WritableMap map = Arguments.createMap();
|
846
|
874
|
map.putMap("stats", statsMap);
|
|
@@ -884,7 +912,8 @@ public class AgoraModule extends ReactContextBaseJavaModule {
|
884
|
912
|
WritableMap statsMap = Arguments.createMap();
|
885
|
913
|
statsMap.putInt("sentBitrate", stats.sentBitrate);
|
886
|
914
|
statsMap.putInt("sentFrameRate", stats.sentFrameRate);
|
887
|
|
-
|
|
915
|
+ statsMap.putInt("encoderOutputFrameRate", stats.encoderOutputFrameRate);
|
|
916
|
+ statsMap.putInt("rendererOutputFrameRate", stats.rendererOutputFrameRate);
|
888
|
917
|
WritableMap map = Arguments.createMap();
|
889
|
918
|
map.putMap("stats", statsMap);
|
890
|
919
|
sendEvent(getReactApplicationContext(), AGLocalVideoStats, map);
|
|
@@ -902,7 +931,7 @@ public class AgoraModule extends ReactContextBaseJavaModule {
|
902
|
931
|
statsMap.putInt("width", stats.width);
|
903
|
932
|
statsMap.putInt("height", stats.height);
|
904
|
933
|
statsMap.putInt("receivedBitrate", stats.receivedBitrate);
|
905
|
|
- statsMap.putInt("receivedFrameRate", stats.receivedFrameRate);
|
|
934
|
+ statsMap.putInt("rendererOutputFrameRate", stats.rendererOutputFrameRate);
|
906
|
935
|
statsMap.putInt("rxStreamType", stats.rxStreamType);
|
907
|
936
|
WritableMap map = Arguments.createMap();
|
908
|
937
|
map.putMap("stats", statsMap);
|
|
@@ -952,13 +981,14 @@ public class AgoraModule extends ReactContextBaseJavaModule {
|
952
|
981
|
}
|
953
|
982
|
|
954
|
983
|
@Override
|
955
|
|
- public void onAudioMixingFinished() {
|
|
984
|
+ public void onAudioMixingStateChanged(final int state, final int errorCode) {
|
956
|
985
|
runOnUiThread(new Runnable() {
|
957
|
986
|
@Override
|
958
|
987
|
public void run() {
|
959
|
988
|
WritableMap map = Arguments.createMap();
|
960
|
|
- map.putString("message", "LocalAudioMixingSucceedFinish");
|
961
|
|
- sendEvent(getReactApplicationContext(), AGLocalAudioMixingFinish, map);
|
|
989
|
+ map.putInt("state", state);
|
|
990
|
+ map.putInt("errorCode", errorCode);
|
|
991
|
+ sendEvent(getReactApplicationContext(), AGAudioMixingStateChanged, map);
|
962
|
992
|
}
|
963
|
993
|
});
|
964
|
994
|
}
|
|
@@ -1034,7 +1064,7 @@ public class AgoraModule extends ReactContextBaseJavaModule {
|
1034
|
1064
|
runOnUiThread(new Runnable() {
|
1035
|
1065
|
@Override
|
1036
|
1066
|
public void run() {
|
1037
|
|
- String msg = new String(data);
|
|
1067
|
+ String msg = new String(data, Charset.forName("UTF-8"));
|
1038
|
1068
|
WritableMap map = Arguments.createMap();
|
1039
|
1069
|
map.putInt("uid", uid);
|
1040
|
1070
|
map.putInt("streamId", streamId);
|
|
@@ -1096,6 +1126,20 @@ public class AgoraModule extends ReactContextBaseJavaModule {
|
1096
|
1126
|
}
|
1097
|
1127
|
});
|
1098
|
1128
|
}
|
|
1129
|
+
|
|
1130
|
+ @Override
|
|
1131
|
+ public void onLocalVideoStateChanged(final int localVideoState, final int error) {
|
|
1132
|
+ super.onLocalVideoStateChanged(localVideoState, error);
|
|
1133
|
+ runOnUiThread(new Runnable() {
|
|
1134
|
+ @Override
|
|
1135
|
+ public void run() {
|
|
1136
|
+ WritableMap map = Arguments.createMap();
|
|
1137
|
+ map.putString("message", "LocalVideoChanged");
|
|
1138
|
+ map.putInt("state", localVideoState);
|
|
1139
|
+ sendEvent(getReactApplicationContext(), AGLocalVideoChanged, map);
|
|
1140
|
+ }
|
|
1141
|
+ });
|
|
1142
|
+ }
|
1099
|
1143
|
};
|
1100
|
1144
|
|
1101
|
1145
|
@ReactMethod
|
|
@@ -1713,6 +1757,34 @@ public class AgoraModule extends ReactContextBaseJavaModule {
|
1713
|
1757
|
}
|
1714
|
1758
|
}
|
1715
|
1759
|
|
|
1760
|
+ @ReactMethod
|
|
1761
|
+ public void getAudioMixingPlayoutVolume(Promise promise) {
|
|
1762
|
+ try {
|
|
1763
|
+ int res = AgoraManager.getInstance().mRtcEngine.getAudioMixingPlayoutVolume();
|
|
1764
|
+ if (res < 0) throw new ReactNativeAgoraException("getAudioMixingPlayoutVolume Failed", res);
|
|
1765
|
+ WritableMap map = Arguments.createMap();
|
|
1766
|
+ map.putBoolean("success", true);
|
|
1767
|
+ map.putInt("value", res);
|
|
1768
|
+ promise.resolve(map);
|
|
1769
|
+ } catch (Exception e) {
|
|
1770
|
+ promise.reject("-1", e);
|
|
1771
|
+ }
|
|
1772
|
+ }
|
|
1773
|
+
|
|
1774
|
+ @ReactMethod
|
|
1775
|
+ public void getAudioMixingPublishVolume(Promise promise) {
|
|
1776
|
+ try {
|
|
1777
|
+ int res = AgoraManager.getInstance().mRtcEngine.getAudioMixingPlayoutVolume();
|
|
1778
|
+ if (res < 0) throw new ReactNativeAgoraException("getAudioMixingPublishVolume Failed", res);
|
|
1779
|
+ WritableMap map = Arguments.createMap();
|
|
1780
|
+ map.putBoolean("success", true);
|
|
1781
|
+ map.putInt("value", res);
|
|
1782
|
+ promise.resolve(map);
|
|
1783
|
+ } catch (Exception e) {
|
|
1784
|
+ promise.reject("-1", e);
|
|
1785
|
+ }
|
|
1786
|
+ }
|
|
1787
|
+
|
1716
|
1788
|
@ReactMethod
|
1717
|
1789
|
public void getAudioMixingDuration(Promise promise) {
|
1718
|
1790
|
try {
|
|
@@ -1723,7 +1795,7 @@ public class AgoraModule extends ReactContextBaseJavaModule {
|
1723
|
1795
|
map.putInt("value", res);
|
1724
|
1796
|
promise.resolve(map);
|
1725
|
1797
|
} catch (Exception e) {
|
1726
|
|
- promise.reject("131004", e);
|
|
1798
|
+ promise.reject("-1", e);
|
1727
|
1799
|
}
|
1728
|
1800
|
}
|
1729
|
1801
|
|
|
@@ -2007,7 +2079,37 @@ public class AgoraModule extends ReactContextBaseJavaModule {
|
2007
|
2079
|
map.putInt("value", res);
|
2008
|
2080
|
promise.resolve(map);
|
2009
|
2081
|
} catch (Exception e) {
|
2010
|
|
- promise.reject("131030", e);
|
|
2082
|
+ promise.reject("-1", e);
|
|
2083
|
+ }
|
|
2084
|
+ }
|
|
2085
|
+
|
|
2086
|
+ @ReactMethod
|
|
2087
|
+ public void sendMediaData(String data, final Promise promise) {
|
|
2088
|
+ if (null == mediaObserver) {
|
|
2089
|
+ promise.reject("-1", "sendMediaData failed");
|
|
2090
|
+ } else {
|
|
2091
|
+ mediaObserver.setMetadata(data.getBytes(Charset.forName("UTF-8")));
|
|
2092
|
+ WritableMap map = Arguments.createMap();
|
|
2093
|
+ map.putBoolean("success", true);
|
|
2094
|
+ promise.resolve(map);
|
|
2095
|
+ }
|
|
2096
|
+ }
|
|
2097
|
+
|
|
2098
|
+ @ReactMethod
|
|
2099
|
+ public void registerMediaMetadataObserver(final Promise promise) {
|
|
2100
|
+ try {
|
|
2101
|
+ mediaObserver = new MediaObserver(getReactApplicationContext());
|
|
2102
|
+ int res = AgoraManager.getInstance().mRtcEngine
|
|
2103
|
+ .registerMediaMetadataObserver(mediaObserver, IMetadataObserver.VIDEO_METADATA);
|
|
2104
|
+ if (res < 0) {
|
|
2105
|
+ new ReactNativeAgoraException("registerMediaMetadataObserver Failed", res);
|
|
2106
|
+ }
|
|
2107
|
+ WritableMap map = Arguments.createMap();
|
|
2108
|
+ map.putBoolean("success", true);
|
|
2109
|
+ map.putInt("value", res);
|
|
2110
|
+ promise.resolve(map);
|
|
2111
|
+ } catch (Exception e) {
|
|
2112
|
+ promise.reject("-1", e);
|
2011
|
2113
|
}
|
2012
|
2114
|
}
|
2013
|
2115
|
|
|
@@ -2443,7 +2545,7 @@ public class AgoraModule extends ReactContextBaseJavaModule {
|
2443
|
2545
|
String data = options.getString("data");
|
2444
|
2546
|
int streamID = AgoraManager.getInstance().mRtcEngine.createDataStream(reliable, ordered);
|
2445
|
2547
|
if (streamID < 0) throw new ReactNativeAgoraException("createDataStream Failed", streamID);
|
2446
|
|
- int res = AgoraManager.getInstance().mRtcEngine.sendStreamMessage(streamID, data.getBytes("utf8"));
|
|
2548
|
+ int res = AgoraManager.getInstance().mRtcEngine.sendStreamMessage(streamID, data.getBytes(Charset.forName("UTF-8")));
|
2447
|
2549
|
if (res != 0) throw new ReactNativeAgoraException("sendStreamMessage Failed", res);
|
2448
|
2550
|
WritableMap map = Arguments.createMap();
|
2449
|
2551
|
map.putBoolean("success", true);
|
|
@@ -2635,7 +2737,6 @@ public class AgoraModule extends ReactContextBaseJavaModule {
|
2635
|
2737
|
}
|
2636
|
2738
|
|
2637
|
2739
|
|
2638
|
|
-
|
2639
|
2740
|
@ReactMethod
|
2640
|
2741
|
|
2641
|
2742
|
private void sendEvent(ReactContext reactContext,
|
|
@@ -2645,5 +2746,4 @@ public class AgoraModule extends ReactContextBaseJavaModule {
|
2645
|
2746
|
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
|
2646
|
2747
|
.emit(eventName, params);
|
2647
|
2748
|
}
|
2648
|
|
-
|
2649
|
2749
|
}
|