Quellcode durchsuchen

安卓方法添加

邓博 vor 7 Jahren
Ursprung
Commit
00169451eb

+ 28
- 0
AgoraView.js Datei anzeigen

@@ -0,0 +1,28 @@
1
+/**
2
+ * Created by DB on 2017/6/23.
3
+ */
4
+
5
+import  React, {Component, PropTypes} from 'react'
6
+import {
7
+    requireNativeComponent,
8
+    View
9
+} from 'react-native'
10
+
11
+export default class AgoraView extends Component {
12
+
13
+    render() {
14
+        return (
15
+            <RCTAgoraView {...this.props}/>
16
+        )
17
+    }
18
+}
19
+
20
+AgoraView.propTypes = {
21
+    localUid: PropTypes.number,
22
+    remoteUid: PropTypes.number,
23
+    ...View.propTypes
24
+};
25
+
26
+// AgoraView.name = "AgoraView";
27
+
28
+const RCTAgoraView = requireNativeComponent("RCTAgoraView", AgoraView);

+ 1
- 1
android/src/main/java/com/syan/agora/AgoraManager.java Datei anzeigen

@@ -22,7 +22,7 @@ public class AgoraManager {
22 22
 
23 23
     public static AgoraManager sAgoraManager;
24 24
 
25
-    private RtcEngine mRtcEngine;
25
+    public RtcEngine mRtcEngine;
26 26
 
27 27
     private Context context;
28 28
 

+ 93
- 2
android/src/main/java/com/syan/agora/AgoraModule.java Datei anzeigen

@@ -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
     }

+ 11
- 9
android/src/main/java/com/syan/agora/AgoraVideoView.java Datei anzeigen

@@ -1,23 +1,25 @@
1 1
 package com.syan.agora;
2 2
 
3 3
 import android.content.Context;
4
-import android.widget.RelativeLayout;
5
-
6
-import com.facebook.react.uimanager.ThemedReactContext;
4
+import android.util.AttributeSet;
5
+import android.widget.LinearLayout;
7 6
 
8 7
 /**
9 8
  * Created by DB on 2017/6/27.
10 9
  */
11 10
 
12
-public class AgoraVideoView extends RelativeLayout {
13
-
14
-    Context context;
11
+public class AgoraVideoView extends LinearLayout {
15 12
 
16
-    public AgoraVideoView(ThemedReactContext context) {
13
+    public AgoraVideoView(Context context) {
17 14
         super(context);
15
+    }
18 16
 
19
-        this.context = context;
20
-
17
+    public AgoraVideoView(Context context, AttributeSet attrs) {
18
+        super(context, attrs);
21 19
     }
22 20
 
21
+
22
+    public AgoraVideoView(Context context, AttributeSet attrs, int defStyleAttr) {
23
+        super(context, attrs, defStyleAttr);
24
+    }
23 25
 }

+ 3
- 7
android/src/main/java/com/syan/agora/AgoraViewManage.java Datei anzeigen

@@ -13,22 +13,18 @@ import com.facebook.react.uimanager.annotations.ReactProp;
13 13
 
14 14
 public class AgoraViewManage extends SimpleViewManager<AgoraVideoView> {
15 15
 
16
-    ThemedReactContext context;
17
-
18
-    private AgoraVideoView agoraVideoView;
16
+    public static final String REACT_CLASS = "RCTAgoraView";
19 17
 
20 18
     @Override
21 19
     public String getName() {
22
-        return "AgoraView";
20
+        return REACT_CLASS;
23 21
     }
24 22
 
25 23
     @Override
26 24
     protected AgoraVideoView createViewInstance(ThemedReactContext reactContext) {
27
-        this.context = reactContext;
28 25
 
29
-        agoraVideoView = new AgoraVideoView(reactContext);
26
+        return new AgoraVideoView(reactContext);
30 27
 
31
-        return agoraVideoView;
32 28
     }
33 29
 
34 30
     @ReactProp(name = "localUid")

+ 1
- 1
package.json Datei anzeigen

@@ -1,6 +1,6 @@
1 1
 {
2 2
   "name": "react-native-agora",
3
-  "version": "1.0.3",
3
+  "version": "1.0.4",
4 4
   "description": "声网Agora",
5 5
   "main": "index.js",
6 6
   "scripts": {