|
@@ -4,6 +4,7 @@ import android.support.annotation.Nullable;
|
4
|
4
|
import android.util.Log;
|
5
|
5
|
|
6
|
6
|
import com.facebook.react.bridge.Arguments;
|
|
7
|
+import com.facebook.react.bridge.Callback;
|
7
|
8
|
import com.facebook.react.bridge.ReactApplicationContext;
|
8
|
9
|
import com.facebook.react.bridge.ReactContext;
|
9
|
10
|
import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
|
@@ -13,6 +14,7 @@ import com.facebook.react.bridge.WritableMap;
|
13
|
14
|
import com.facebook.react.modules.core.DeviceEventManagerModule;
|
14
|
15
|
|
15
|
16
|
import io.agora.rtc.IRtcEngineEventHandler;
|
|
17
|
+import io.agora.rtc.RtcEngine;
|
16
|
18
|
|
17
|
19
|
import static com.facebook.react.bridge.UiThreadUtil.runOnUiThread;
|
18
|
20
|
|
|
@@ -51,7 +53,7 @@ public class AgoraModule extends ReactContextBaseJavaModule {
|
51
|
53
|
* 加入频道成功的回调
|
52
|
54
|
*/
|
53
|
55
|
@Override
|
54
|
|
- public void onJoinChannelSuccess(final String channel,final int uid, int elapsed) {
|
|
56
|
+ public void onJoinChannelSuccess(final String channel, final int uid, int elapsed) {
|
55
|
57
|
|
56
|
58
|
Log.i("Agora", "加入房间成功---");
|
57
|
59
|
|
|
@@ -138,7 +140,6 @@ public class AgoraModule extends ReactContextBaseJavaModule {
|
138
|
140
|
}
|
139
|
141
|
};
|
140
|
142
|
|
141
|
|
-
|
142
|
143
|
@ReactMethod
|
143
|
144
|
public void init(ReadableMap options) {
|
144
|
145
|
AgoraManager.getInstance().init(getReactApplicationContext(), mRtcEventHandler, options);
|
|
@@ -157,6 +158,96 @@ public class AgoraModule extends ReactContextBaseJavaModule {
|
157
|
158
|
AgoraManager.getInstance().leaveChannel();
|
158
|
159
|
}
|
159
|
160
|
|
|
161
|
+ //打开音频
|
|
162
|
+ @ReactMethod
|
|
163
|
+ public void enableAudio() {
|
|
164
|
+ AgoraManager.getInstance().mRtcEngine.enableAudio();
|
|
165
|
+ }
|
|
166
|
+
|
|
167
|
+ //关闭音频
|
|
168
|
+ @ReactMethod
|
|
169
|
+ public void disableAudio() {
|
|
170
|
+ AgoraManager.getInstance().mRtcEngine.disableAudio();
|
|
171
|
+ }
|
|
172
|
+
|
|
173
|
+ //打开视频
|
|
174
|
+ @ReactMethod
|
|
175
|
+ public void enableVideo() {
|
|
176
|
+ AgoraManager.getInstance().mRtcEngine.enableVideo();
|
|
177
|
+ }
|
|
178
|
+
|
|
179
|
+ //关闭视频
|
|
180
|
+ @ReactMethod
|
|
181
|
+ public void disableVideo() {
|
|
182
|
+ AgoraManager.getInstance().mRtcEngine.disableVideo();
|
|
183
|
+ }
|
|
184
|
+
|
|
185
|
+ //切换前置/后置摄像头
|
|
186
|
+ @ReactMethod
|
|
187
|
+ public void switchCamera() {
|
|
188
|
+ AgoraManager.getInstance().mRtcEngine.switchCamera();
|
|
189
|
+ }
|
|
190
|
+
|
|
191
|
+ //打开扬声器
|
|
192
|
+ @ReactMethod
|
|
193
|
+ public void setEnableSpeakerphone(boolean enabled) {
|
|
194
|
+ AgoraManager.getInstance().mRtcEngine.setEnableSpeakerphone(enabled);
|
|
195
|
+ }
|
|
196
|
+
|
|
197
|
+ //将自己静音
|
|
198
|
+ @ReactMethod
|
|
199
|
+ public void muteLocalAudioStream(boolean muted) {
|
|
200
|
+ AgoraManager.getInstance().mRtcEngine.muteLocalAudioStream(muted);
|
|
201
|
+ }
|
|
202
|
+
|
|
203
|
+ //静音所有远端音频
|
|
204
|
+ @ReactMethod
|
|
205
|
+ public void muteAllRemoteAudioStreams(boolean muted) {
|
|
206
|
+ AgoraManager.getInstance().mRtcEngine.muteAllRemoteAudioStreams(muted);
|
|
207
|
+ }
|
|
208
|
+
|
|
209
|
+ //静音指定用户音频
|
|
210
|
+ @ReactMethod
|
|
211
|
+ public void muteRemoteAudioStream(int uid, boolean muted) {
|
|
212
|
+ AgoraManager.getInstance().mRtcEngine.muteRemoteAudioStream(uid, muted);
|
|
213
|
+ }
|
|
214
|
+
|
|
215
|
+ //禁用本地视频功能
|
|
216
|
+ @ReactMethod
|
|
217
|
+ public void enableLocalVideo(boolean enabled) {
|
|
218
|
+ AgoraManager.getInstance().mRtcEngine.enableLocalVideo(enabled);
|
|
219
|
+ }
|
|
220
|
+
|
|
221
|
+ //暂停本地视频流
|
|
222
|
+ @ReactMethod
|
|
223
|
+ public void muteLocalVideoStream(boolean muted) {
|
|
224
|
+ AgoraManager.getInstance().mRtcEngine.muteLocalVideoStream(muted);
|
|
225
|
+ }
|
|
226
|
+
|
|
227
|
+ //暂停所有远端视频流
|
|
228
|
+ @ReactMethod
|
|
229
|
+ public void muteAllRemoteVideoStreams(boolean muted) {
|
|
230
|
+ AgoraManager.getInstance().mRtcEngine.muteAllRemoteVideoStreams(muted);
|
|
231
|
+ }
|
|
232
|
+
|
|
233
|
+ //暂停指定远端视频流
|
|
234
|
+ @ReactMethod
|
|
235
|
+ public void muteRemoteVideoStream(int uid, boolean muted) {
|
|
236
|
+ AgoraManager.getInstance().mRtcEngine.muteRemoteVideoStream(uid, muted);
|
|
237
|
+ }
|
|
238
|
+
|
|
239
|
+ //销毁引擎实例
|
|
240
|
+ @ReactMethod
|
|
241
|
+ public void destroy() {
|
|
242
|
+ RtcEngine.destroy();
|
|
243
|
+ }
|
|
244
|
+
|
|
245
|
+ //查询 SDK 版本号
|
|
246
|
+ @ReactMethod
|
|
247
|
+ public void getSdkVersion(Callback callback) {
|
|
248
|
+ callback.invoke( RtcEngine.getSdkVersion());
|
|
249
|
+ }
|
|
250
|
+
|
160
|
251
|
private void commonEvent(WritableMap map) {
|
161
|
252
|
sendEvent(getReactApplicationContext(), "agoraEvent", map);
|
162
|
253
|
}
|