|
@@ -290,7 +290,7 @@ public class AgoraModule extends ReactContextBaseJavaModule {
|
290
|
290
|
private final static String AGRtmpStreamingStateChanged = "rtmpStreamingStateChanged";
|
291
|
291
|
private final static String AGNetworkTypeChanged = "networkTypeChanged";
|
292
|
292
|
private final static String AGFirstRemoteAudioDecoded = "firstRemoteAudioDecoded";
|
293
|
|
- private final static String AGMediaMetaDataRecevied = "mediaMetaDataRecevied";
|
|
293
|
+ private final static String AGMediaMetaDataReceived = "mediaMetaDataReceived";
|
294
|
294
|
private final static String AGRemoteVideoStateChanged = "remoteVideoStateChanged";
|
295
|
295
|
private final static String AGLocalPublishFallbackToAudioOnly = "localPublishFallbackToAudioOnly";
|
296
|
296
|
private final static String AGRemoteSubscribeFallbackToAudioOnly = "remoteSubscribeFallbackToAudioOnly";
|
|
@@ -328,6 +328,8 @@ public class AgoraModule extends ReactContextBaseJavaModule {
|
328
|
328
|
private final static String AGLastmileProbeResult = "lastmileProbeTestResult";
|
329
|
329
|
// private final static String AGIntervalTest = "startEchoTestWithInterval";
|
330
|
330
|
|
|
331
|
+ private MediaObserver mediaObserver = null;
|
|
332
|
+
|
331
|
333
|
private IRtcEngineEventHandler mRtcEventHandler = new IRtcEngineEventHandler() {
|
332
|
334
|
|
333
|
335
|
@Override
|
|
@@ -2086,46 +2088,26 @@ public class AgoraModule extends ReactContextBaseJavaModule {
|
2086
|
2088
|
}
|
2087
|
2089
|
}
|
2088
|
2090
|
|
2089
|
|
- private static final Integer MAX_META_DATA = 1024;
|
2090
|
|
-
|
2091
|
|
- private byte[] metadata = null;
|
2092
|
|
-
|
2093
|
2091
|
@ReactMethod
|
2094
|
|
- public void sendMediaData(String data) {
|
2095
|
|
- metadata = data.getBytes(Charset.forName("UTF-8"));
|
|
2092
|
+ public void sendMediaData(String data, final Promise promise) {
|
|
2093
|
+ if (null == mediaObserver) {
|
|
2094
|
+ promise.reject("-1", "sendMediaData failed");
|
|
2095
|
+ } else {
|
|
2096
|
+ mediaObserver.setMetadata(data.getBytes(Charset.forName("UTF-8")));
|
|
2097
|
+ WritableMap map = Arguments.createMap();
|
|
2098
|
+ map.putBoolean("success", true);
|
|
2099
|
+ promise.resolve(map);
|
|
2100
|
+ }
|
2096
|
2101
|
}
|
2097
|
2102
|
|
2098
|
2103
|
@ReactMethod
|
2099
|
2104
|
public void registerMediaMetadataObserver(final Promise promise) {
|
2100
|
2105
|
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);
|
|
2106
|
+ mediaObserver = new MediaObserver(getReactApplicationContext());
|
|
2107
|
+ int res = AgoraManager.getInstance().mRtcEngine
|
|
2108
|
+ .registerMediaMetadataObserver(mediaObserver, IMetadataObserver.VIDEO_METADATA);
|
2127
|
2109
|
if (res < 0) {
|
2128
|
|
- new ReactNativeAgoraException("setRemoteDefaultVideoStreamType Failed", res);
|
|
2110
|
+ new ReactNativeAgoraException("registerMediaMetadataObserver Failed", res);
|
2129
|
2111
|
}
|
2130
|
2112
|
WritableMap map = Arguments.createMap();
|
2131
|
2113
|
map.putBoolean("success", true);
|
|
@@ -2760,7 +2742,6 @@ public class AgoraModule extends ReactContextBaseJavaModule {
|
2760
|
2742
|
}
|
2761
|
2743
|
|
2762
|
2744
|
|
2763
|
|
-
|
2764
|
2745
|
@ReactMethod
|
2765
|
2746
|
|
2766
|
2747
|
private void sendEvent(ReactContext reactContext,
|
|
@@ -2770,5 +2751,4 @@ public class AgoraModule extends ReactContextBaseJavaModule {
|
2770
|
2751
|
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
|
2771
|
2752
|
.emit(eventName, params);
|
2772
|
2753
|
}
|
2773
|
|
-
|
2774
|
2754
|
}
|