|
@@ -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,10 @@ 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 AGMediaMetaDataRecevied = "mediaMetaDataRecevied";
|
288
|
294
|
private final static String AGRemoteVideoStateChanged = "remoteVideoStateChanged";
|
289
|
295
|
private final static String AGLocalPublishFallbackToAudioOnly = "localPublishFallbackToAudioOnly";
|
290
|
296
|
private final static String AGRemoteSubscribeFallbackToAudioOnly = "remoteSubscribeFallbackToAudioOnly";
|
|
@@ -415,6 +421,8 @@ public class AgoraModule extends ReactContextBaseJavaModule {
|
415
|
421
|
statsMap.putInt("userCount", stats.users);
|
416
|
422
|
statsMap.putDouble("cpuAppUsage", stats.cpuAppUsage);
|
417
|
423
|
statsMap.putDouble("cpuTotalUsage", stats.cpuTotalUsage);
|
|
424
|
+ statsMap.putInt("txPacketLossRate", stats.txPacketLossRate);
|
|
425
|
+ statsMap.putInt("rxPacketLossRate", stats.rxPacketLossRate);
|
418
|
426
|
|
419
|
427
|
WritableMap map = Arguments.createMap();
|
420
|
428
|
map.putMap("stats", statsMap);
|
|
@@ -584,17 +592,17 @@ public class AgoraModule extends ReactContextBaseJavaModule {
|
584
|
592
|
});
|
585
|
593
|
}
|
586
|
594
|
|
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
|
|
- }
|
|
595
|
+// @Override
|
|
596
|
+// public void onVideoStopped() {
|
|
597
|
+// runOnUiThread(new Runnable() {
|
|
598
|
+// @Override
|
|
599
|
+// public void run() {
|
|
600
|
+// WritableMap map = Arguments.createMap();
|
|
601
|
+// map.putString("message", "VideoStopped");
|
|
602
|
+// sendEvent(getReactApplicationContext(), AGVideoStopped, map);
|
|
603
|
+// }
|
|
604
|
+// });
|
|
605
|
+// }
|
598
|
606
|
|
599
|
607
|
@Override
|
600
|
608
|
public void onFirstLocalVideoFrame(final int width, final int height, final int elapsed) {
|
|
@@ -710,6 +718,45 @@ public class AgoraModule extends ReactContextBaseJavaModule {
|
710
|
718
|
});
|
711
|
719
|
}
|
712
|
720
|
|
|
721
|
+ @Override
|
|
722
|
+ public void onRtmpStreamingStateChanged(final String url, final int state, final int errCode) {
|
|
723
|
+ runOnUiThread(new Runnable() {
|
|
724
|
+ @Override
|
|
725
|
+ public void run() {
|
|
726
|
+ WritableMap map = Arguments.createMap();
|
|
727
|
+ map.putString("url", url);
|
|
728
|
+ map.putInt("state", state);
|
|
729
|
+ map.putInt("errorCode", errCode);
|
|
730
|
+ sendEvent(getReactApplicationContext(), AGRtmpStreamingStateChanged, map);
|
|
731
|
+ }
|
|
732
|
+ });
|
|
733
|
+ }
|
|
734
|
+
|
|
735
|
+ @Override
|
|
736
|
+ public void onNetworkTypeChanged(final int type) {
|
|
737
|
+ runOnUiThread(new Runnable() {
|
|
738
|
+ @Override
|
|
739
|
+ public void run() {
|
|
740
|
+ WritableMap map = Arguments.createMap();
|
|
741
|
+ map.putInt("type", type);
|
|
742
|
+ sendEvent(getReactApplicationContext(), AGNetworkTypeChanged, map);
|
|
743
|
+ }
|
|
744
|
+ });
|
|
745
|
+ }
|
|
746
|
+
|
|
747
|
+ @Override
|
|
748
|
+ public void onFirstRemoteAudioDecoded(final int uid, final int elapsed) {
|
|
749
|
+ runOnUiThread(new Runnable() {
|
|
750
|
+ @Override
|
|
751
|
+ public void run() {
|
|
752
|
+ WritableMap map = Arguments.createMap();
|
|
753
|
+ map.putInt("uid", uid);
|
|
754
|
+ map.putInt("elapsed", elapsed);
|
|
755
|
+ sendEvent(getReactApplicationContext(), AGFirstRemoteAudioDecoded, map);
|
|
756
|
+ }
|
|
757
|
+ });
|
|
758
|
+ }
|
|
759
|
+
|
713
|
760
|
@Override
|
714
|
761
|
public void onRemoteVideoStateChanged(final int uid, final int state) {
|
715
|
762
|
runOnUiThread(new Runnable() {
|
|
@@ -884,7 +931,8 @@ public class AgoraModule extends ReactContextBaseJavaModule {
|
884
|
931
|
WritableMap statsMap = Arguments.createMap();
|
885
|
932
|
statsMap.putInt("sentBitrate", stats.sentBitrate);
|
886
|
933
|
statsMap.putInt("sentFrameRate", stats.sentFrameRate);
|
887
|
|
-
|
|
934
|
+ statsMap.putInt("encoderOutputFrameRate", stats.encoderOutputFrameRate);
|
|
935
|
+ statsMap.putInt("rendererOutputFrameRate", stats.rendererOutputFrameRate);
|
888
|
936
|
WritableMap map = Arguments.createMap();
|
889
|
937
|
map.putMap("stats", statsMap);
|
890
|
938
|
sendEvent(getReactApplicationContext(), AGLocalVideoStats, map);
|
|
@@ -902,7 +950,7 @@ public class AgoraModule extends ReactContextBaseJavaModule {
|
902
|
950
|
statsMap.putInt("width", stats.width);
|
903
|
951
|
statsMap.putInt("height", stats.height);
|
904
|
952
|
statsMap.putInt("receivedBitrate", stats.receivedBitrate);
|
905
|
|
- statsMap.putInt("receivedFrameRate", stats.receivedFrameRate);
|
|
953
|
+ statsMap.putInt("rendererOutputFrameRate", stats.rendererOutputFrameRate);
|
906
|
954
|
statsMap.putInt("rxStreamType", stats.rxStreamType);
|
907
|
955
|
WritableMap map = Arguments.createMap();
|
908
|
956
|
map.putMap("stats", statsMap);
|
|
@@ -1034,7 +1082,7 @@ public class AgoraModule extends ReactContextBaseJavaModule {
|
1034
|
1082
|
runOnUiThread(new Runnable() {
|
1035
|
1083
|
@Override
|
1036
|
1084
|
public void run() {
|
1037
|
|
- String msg = new String(data);
|
|
1085
|
+ String msg = new String(data, Charset.forName("UTF-8"));
|
1038
|
1086
|
WritableMap map = Arguments.createMap();
|
1039
|
1087
|
map.putInt("uid", uid);
|
1040
|
1088
|
map.putInt("streamId", streamId);
|
|
@@ -1713,6 +1761,33 @@ public class AgoraModule extends ReactContextBaseJavaModule {
|
1713
|
1761
|
}
|
1714
|
1762
|
}
|
1715
|
1763
|
|
|
1764
|
+ @ReactMethod
|
|
1765
|
+ public void getAudioMixingPlayoutVolume(Promise promise) {
|
|
1766
|
+ try {
|
|
1767
|
+ int res = AgoraManager.getInstance().mRtcEngine.getAudioMixingPlayoutVolume();
|
|
1768
|
+ if (res < 0) throw new ReactNativeAgoraException("getAudioMixingPlayoutVolume Failed", res);
|
|
1769
|
+ WritableMap map = Arguments.createMap();
|
|
1770
|
+ map.putString("volume", Integer.toString(res));
|
|
1771
|
+ promise.resolve(map);
|
|
1772
|
+ } catch (Exception e) {
|
|
1773
|
+ promise.reject("-1", e);
|
|
1774
|
+ }
|
|
1775
|
+ }
|
|
1776
|
+
|
|
1777
|
+ @ReactMethod
|
|
1778
|
+ public void getAudioMixingPublishVolume(Promise promise) {
|
|
1779
|
+ try {
|
|
1780
|
+ int res = AgoraManager.getInstance().mRtcEngine.getAudioMixingPlayoutVolume();
|
|
1781
|
+ if (res < 0) throw new ReactNativeAgoraException("getAudioMixingPublishVolume Failed", res);
|
|
1782
|
+ WritableMap map = Arguments.createMap();
|
|
1783
|
+ map.putBoolean("success", true);
|
|
1784
|
+ map.putInt("value", res);
|
|
1785
|
+ promise.resolve(map);
|
|
1786
|
+ } catch (Exception e) {
|
|
1787
|
+ promise.reject("-1", e);
|
|
1788
|
+ }
|
|
1789
|
+ }
|
|
1790
|
+
|
1716
|
1791
|
@ReactMethod
|
1717
|
1792
|
public void getAudioMixingDuration(Promise promise) {
|
1718
|
1793
|
try {
|
|
@@ -1723,7 +1798,7 @@ public class AgoraModule extends ReactContextBaseJavaModule {
|
1723
|
1798
|
map.putInt("value", res);
|
1724
|
1799
|
promise.resolve(map);
|
1725
|
1800
|
} catch (Exception e) {
|
1726
|
|
- promise.reject("131004", e);
|
|
1801
|
+ promise.reject("-1", e);
|
1727
|
1802
|
}
|
1728
|
1803
|
}
|
1729
|
1804
|
|
|
@@ -2007,7 +2082,57 @@ public class AgoraModule extends ReactContextBaseJavaModule {
|
2007
|
2082
|
map.putInt("value", res);
|
2008
|
2083
|
promise.resolve(map);
|
2009
|
2084
|
} catch (Exception e) {
|
2010
|
|
- promise.reject("131030", e);
|
|
2085
|
+ promise.reject("-1", e);
|
|
2086
|
+ }
|
|
2087
|
+ }
|
|
2088
|
+
|
|
2089
|
+ private static final Integer MAX_META_DATA = 1024;
|
|
2090
|
+
|
|
2091
|
+ private byte[] metadata = null;
|
|
2092
|
+
|
|
2093
|
+ @ReactMethod
|
|
2094
|
+ public void sendMediaData(String data) {
|
|
2095
|
+ metadata = data.getBytes(Charset.forName("UTF-8"));
|
|
2096
|
+ }
|
|
2097
|
+
|
|
2098
|
+ @ReactMethod
|
|
2099
|
+ public void registerMediaMetadataObserver(final Promise promise) {
|
|
2100
|
+ try {
|
|
2101
|
+ int res = AgoraManager.getInstance().mRtcEngine.registerMediaMetadataObserver(new IMetadataObserver() {
|
|
2102
|
+ @Override
|
|
2103
|
+ public int getMaxMetadataSize() { return MAX_META_DATA; }
|
|
2104
|
+
|
|
2105
|
+ @Override
|
|
2106
|
+ public byte[] onReadyToSendMetadata(long timeStampMs) {
|
|
2107
|
+ if (metadata == null) {
|
|
2108
|
+ return null;
|
|
2109
|
+ }
|
|
2110
|
+ byte[] toSend = metadata;
|
|
2111
|
+ if (toSend.length > MAX_META_DATA) {
|
|
2112
|
+ return null;
|
|
2113
|
+ }
|
|
2114
|
+ metadata = null;
|
|
2115
|
+ return toSend;
|
|
2116
|
+ }
|
|
2117
|
+
|
|
2118
|
+ @Override
|
|
2119
|
+ public void onMetadataReceived(byte[] buffer, int uid, long timeStampMs) {
|
|
2120
|
+ WritableMap map = Arguments.createMap();
|
|
2121
|
+ map.putString("data", new String(buffer, Charset.forName("UTF-8")));
|
|
2122
|
+ map.putString("uid", Integer.toString(uid));
|
|
2123
|
+ map.putString("ts", Long.toString(timeStampMs));
|
|
2124
|
+ sendEvent(getReactApplicationContext(), AGMediaMetaDataRecevied, map);
|
|
2125
|
+ }
|
|
2126
|
+ }, IMetadataObserver.VIDEO_METADATA);
|
|
2127
|
+ if (res < 0) {
|
|
2128
|
+ new ReactNativeAgoraException("setRemoteDefaultVideoStreamType Failed", res);
|
|
2129
|
+ }
|
|
2130
|
+ WritableMap map = Arguments.createMap();
|
|
2131
|
+ map.putBoolean("success", true);
|
|
2132
|
+ map.putInt("value", res);
|
|
2133
|
+ promise.resolve(map);
|
|
2134
|
+ } catch (Exception e) {
|
|
2135
|
+ promise.reject("-1", e);
|
2011
|
2136
|
}
|
2012
|
2137
|
}
|
2013
|
2138
|
|
|
@@ -2443,7 +2568,7 @@ public class AgoraModule extends ReactContextBaseJavaModule {
|
2443
|
2568
|
String data = options.getString("data");
|
2444
|
2569
|
int streamID = AgoraManager.getInstance().mRtcEngine.createDataStream(reliable, ordered);
|
2445
|
2570
|
if (streamID < 0) throw new ReactNativeAgoraException("createDataStream Failed", streamID);
|
2446
|
|
- int res = AgoraManager.getInstance().mRtcEngine.sendStreamMessage(streamID, data.getBytes("utf8"));
|
|
2571
|
+ int res = AgoraManager.getInstance().mRtcEngine.sendStreamMessage(streamID, data.getBytes(Charset.forName("UTF-8")));
|
2447
|
2572
|
if (res != 0) throw new ReactNativeAgoraException("sendStreamMessage Failed", res);
|
2448
|
2573
|
WritableMap map = Arguments.createMap();
|
2449
|
2574
|
map.putBoolean("success", true);
|