Browse Source

refactor. init# support audio / video only mode and dualStream switch

matrixbirds 5 years ago
parent
commit
7dad98346e

+ 48
- 18
android/src/main/java/com/syan/agora/AgoraManager.java View File

@@ -88,35 +88,65 @@ public class AgoraManager {
88 88
      * initialize rtc engine
89 89
      */
90 90
     public int init(Context context, IRtcEngineEventHandler mRtcEventHandler, ReadableMap options) {
91
-        this.context = context;
92
-
93 91
         //create rtcEngine instance and setup rtcEngine eventHandler
94 92
         try {
95
-            mRtcEngine = RtcEngine.create(context, options.getString("appid"), mRtcEventHandler);
93
+            this.context = context;
94
+            this.mRtcEngine = RtcEngine.create(context, options.getString("appid"), mRtcEventHandler);
96 95
             if (options.hasKey("secret") && null != options.getString("secret")) {
97 96
                 mRtcEngine.setEncryptionSecret(options.getString("secret"));
98 97
                 if (options.hasKey("secretMode") && null != options.getString("secretMode")) {
99 98
                     mRtcEngine.setEncryptionMode(options.getString("secretMode"));
100 99
                 }
101 100
             }
101
+            if (options.hasKey("channelProfile")) {
102
+                mRtcEngine.setChannelProfile(options.getInt("channelProfile"));
103
+            }
104
+            if (options.hasKey("dualStream")) {
105
+                mRtcEngine.enableDualStreamMode(options.getBoolean("dualStream"));
106
+            }
107
+            if (options.hasKey("mode")) {
108
+                Integer mode = options.getInt("mode");
109
+                switch (mode) {
110
+                    case 0: {
111
+                        mRtcEngine.enableAudio();
112
+                        mRtcEngine.disableVideo();
113
+                        break;
114
+                    }
115
+                    case 1: {
116
+                        mRtcEngine.enableVideo();
117
+                        mRtcEngine.disableAudio();
118
+                        break;
119
+                    }
120
+                }
121
+            } else {
122
+                mRtcEngine.enableVideo();
123
+                mRtcEngine.enableAudio();
124
+            }
125
+
126
+            if (options.hasKey("videoEncoderConfig") && null != options.getMap("videoEncoderConfig")) {
127
+                ReadableMap config = options.getMap("videoEncoderConfig");
128
+                VideoEncoderConfiguration encoderConfig = new VideoEncoderConfiguration(
129
+                        config.getInt("width"),
130
+                        config.getInt("height"),
131
+                        getVideoEncoderEnum(config.getInt("frameRate")),
132
+                        config.getInt("bitrate"),
133
+                        getOrientationModeEnum(config.getInt("orientationMode"))
134
+                );
135
+                mRtcEngine.setVideoEncoderConfiguration(encoderConfig);
136
+            }
137
+
138
+            if (options.hasKey("audioProfile") &&
139
+                options.hasKey("audioScenario")) {
140
+                mRtcEngine.setAudioProfile(options.getInt("audioProfile"), options.getInt("audioScenario"));
141
+            }
142
+
143
+            if (options.hasKey("clientRole")) {
144
+                mRtcEngine.setClientRole(options.getInt("clientRole"));
145
+            }
146
+            return mRtcEngine.enableWebSdkInteroperability(true);
102 147
         } catch (Exception e) {
103 148
             throw new RuntimeException("create rtc engine failed\n" + Log.getStackTraceString(e));
104 149
         }
105
-        mRtcEngine.enableDualStreamMode(true);
106
-        mRtcEngine.setChannelProfile(options.getInt("channelProfile"));
107
-        mRtcEngine.enableVideo();
108
-        ReadableMap config = options.getMap("videoEncoderConfig");
109
-        VideoEncoderConfiguration encoderConfig = new VideoEncoderConfiguration(
110
-            config.getInt("width"),
111
-            config.getInt("height"),
112
-            getVideoEncoderEnum(config.getInt("frameRate")),
113
-            config.getInt("bitrate"),
114
-            getOrientationModeEnum(config.getInt("orientationMode"))
115
-        );
116
-        mRtcEngine.setVideoEncoderConfiguration(encoderConfig);
117
-        mRtcEngine.setAudioProfile(options.getInt("audioProfile"), options.getInt("audioScenario"));
118
-        mRtcEngine.setClientRole(options.getInt("clientRole"));
119
-        return mRtcEngine.enableWebSdkInteroperability(true);
120 150
     }
121 151
 
122 152
     /**

+ 105
- 108
android/src/main/java/com/syan/agora/AgoraModule.java View File

@@ -1,12 +1,7 @@
1 1
 package com.syan.agora;
2 2
 
3 3
 import android.graphics.Rect;
4
-import android.media.MediaRecorder;
5
-import android.net.wifi.p2p.nsd.WifiP2pServiceRequest;
6 4
 import android.support.annotation.Nullable;
7
-import android.support.v7.widget.LinearLayoutCompat;
8
-import android.telecom.Call;
9
-import android.util.Log;
10 5
 
11 6
 import com.facebook.react.bridge.Arguments;
12 7
 import com.facebook.react.bridge.Callback;
@@ -36,112 +31,112 @@ import io.agora.rtc.video.AgoraImage;
36 31
 import io.agora.rtc.video.VideoEncoderConfiguration;
37 32
 
38 33
 import static com.facebook.react.bridge.UiThreadUtil.runOnUiThread;
39
-import static io.agora.rtc.Constants.AudioScenario;
40
-import static io.agora.rtc.Constants.AudioProfile;
41 34
 
42 35
 public class AgoraModule extends ReactContextBaseJavaModule {
43 36
 
44
-    private static String FPS1 = "FPS1";
45
-    private static String FPS7 = "FPS7";
46
-    private static String FPS10 = "FPS10";
47
-    private static String FPS15 = "FPS15";
48
-    private static String FPS24 = "FPS24";
49
-    private static String FPS30 = "FPS30";
50
-    private static String FPS60 = "FPS60";
51
-    private static String Adaptative = "Adaptative";
52
-    private static String FixedLandscape = "FixedLandscape";
53
-    private static String FixedPortrait = "FixedPortrait";
54
-    private static String Host = "Host";
55
-    private static String Audience = "Audience";
56
-    private static String UserOfflineReasonQuit = "UserOfflineReasonQuit";
57
-    private static String UserOfflineReasonDropped = "UserOfflineReasonDropped";
58
-    private static String UserOfflineReasonBecomeAudience = "UserOfflineReasonBecomeAudience";
59
-    private static String AudioSampleRateType32000 = "AudioSampleRateType32000";
60
-    private static String AudioSampleRateType44100 = "AudioSampleRateType44100";
61
-    private static String AudioSampleRateType48000 = "AudioSampleRateType48000";
62
-    private static String CodecTypeBaseLine = "CodecTypeBaseLine";
63
-    private static String CodecTypeMain = "CodecTypeMain";
64
-    private static String CodecTypeHigh = "CodecTypeHigh";
65
-    private static String QualityLow = "QualityLow";
66
-    private static String QualityMedium = "QualityMedium";
67
-    private static String QualityHigh = "QualityHigh";
68
-    private static String Disconnected = "Disconnected";
69
-    private static String Connecting = "Connecting";
70
-    private static String Connected = "Connected";
71
-    private static String Reconnecting = "Reconnecting";
72
-    private static String ConnectionFailed = "ConnectionFailed";
73
-    private static String ConnectionChangedConnecting = "ConnectionChangedConnecting";
74
-    private static String ConnectionChangedJoinSuccess =  "ConnectionChangedJoinSuccess";
75
-    private static String ConnectionChangedInterrupted = "ConnectionChangedInterrupted";
76
-    private static String ConnectionChangedBannedByServer = "ConnectionChangedBannedByServer";
77
-    private static String ConnectionChangedJoinFailed = "ConnectionChangedJoinFailed";
78
-    private static String ConnectionChangedLeaveChannel = "ConnectionChangedLeaveChannel";
79
-    private static String AudioOutputRoutingDefault = "AudioOutputRoutingDefault";
80
-    private static String AudioOutputRoutingHeadset = "AudioOutputRoutingHeadset";
81
-    private static String AudioOutputRoutingEarpiece = "AudioOutputRoutingEarpiece";
82
-    private static String AudioOutputRoutingHeadsetNoMic = "AudioOutputRoutingHeadsetNoMic";
83
-    private static String AudioOutputRoutingSpeakerphone = "AudioOutputRoutingSpeakerphone";
84
-    private static String AudioOutputRoutingLoudspeaker = "AudioOutputRoutingLoudspeaker";
85
-    private static String AudioOutputRoutingHeadsetBluetooth = "AudioOutputRoutingHeadsetBluetooth";
86
-    private static String NetworkQualityUnknown = "NetworkQualityUnknown";
87
-    private static String NetworkQualityExcellent = "NetworkQualityExcellent";
88
-    private static String NetworkQualityGood = "NetworkQualityGood";
89
-    private static String NetworkQualityPoor = "NetworkQualityPoor";
90
-    private static String NetworkQualityBad = "NetworkQualityBad";
91
-    private static String NetworkQualityVBad = "NetworkQualityVBad";
92
-    private static String NetworkQualityDown = "NetworkQualityDown";
93
-    private static String AudioProfileDefault = "AudioProfileDefault";
94
-    private static String AudioProfileSpeechStandard = "AudioProfileSpeechStandard";
95
-    private static String AudioProfileMusicStandard = "AudioProfileMusicStandard";
96
-    private static String AgoraAudioProfileMusicStandardStereo = "AudioProfileMusicStandardStereo";
97
-    private static String AudioProfileMusicHighQuality = "AudioProfileMusicHighQuality";
98
-    private static String AudioProfileMusicHighQualityStereo = "AudioProfileMusicHighQualityStereo";
99
-    private static String AudioScenarioDefault = "AudioScenarioDefault";
100
-    private static String AudioScenarioChatRoomEntertainment = "AudioScenarioChatRoomEntertainment";
101
-    private static String AudioScenarioEducation = "AudioScenarioEducation";
102
-    private static String AudioScenarioGameStreaming = "AudioScenarioGameStreaming";
103
-    private static String AudioScenarioShowRoom = "AudioScenarioShowRoom";
104
-    private static String AudioScenarioChatRoomGaming = "AudioScenarioChatRoomGaming";
105
-    private static String AudioEqualizationBand31 = "AudioEqualizationBand31";
106
-    private static String AudioEqualizationBand62 = "AudioEqualizationBand62";
107
-    private static String AudioEqualizationBand125 = "AudioEqualizationBand125";
108
-    private static String AudioEqualizationBand250 = "AudioEqualizationBand250";
109
-    private static String AudioEqualizationBand500 = "AudioEqualizationBand500";
110
-    private static String AudioEqualizationBand1K = "AudioEqualizationBand1K";
111
-    private static String AudioEqualizationBand2K = "AudioEqualizationBand2K";
112
-    private static String AudioEqualizationBand4K = "AudioEqualizationBand4K";
113
-    private static String AudioEqualizationBand8K = "AudioEqualizationBand8K";
114
-    private static String AudioEqualizationBand16K = "AudioEqualizationBand16K";
115
-    private static String AudioRawFrameOperationModeReadOnly = "AudioRawFrameOperationModeReadOnly";
116
-    private static String AudioRawFrameOperationModeWriteOnly = "AudioRawFrameOperationModeWriteOnly";
117
-    private static String AudioRawFrameOperationModeReadWrite = "AudioRawFrameOperationModeReadWrite";
118
-    private static String VideoStreamTypeHigh = "VideoStreamTypeHigh";
119
-    private static String VideoStreamTypeLow = "VideoStreamTypeLow";
120
-    private static String VideoMirrorModeAuto = "VideoMirrorModeAuto";
121
-    private static String VideoMirrorModeEnabled = "VideoMirrorModeEnabled";
122
-    private static String VideoMirrorModeDisabled = "VideoMirrorModeDisabled";
123
-    private static String ChannelProfileCommunication = "ChannelProfileCommunication";
124
-    private static String ChannelProfileLiveBroadcasting = "ChannelProfileLiveBroadcasting";
125
-    private static String ChannelProfileGame = "ChannelProfileGame";
126
-    private static String ErrorCodeNoError = "ErrorCodeNoError";
127
-    private static String ErrorCodeFailed = "ErrorCodeFailed";
128
-    private static String ErrorCodeInvalidArgument = "ErrorCodeInvalidArgument";
129
-    private static String ErrorCodeTimedOut = "ErrorCodeTimedOut";
130
-    private static String ErrorCodeAlreadyInUse = "ErrorCodeAlreadyInUse";
37
+    private static final String FPS1 = "FPS1";
38
+    private static final String FPS7 = "FPS7";
39
+    private static final String FPS10 = "FPS10";
40
+    private static final String FPS15 = "FPS15";
41
+    private static final String FPS24 = "FPS24";
42
+    private static final String FPS30 = "FPS30";
43
+    private static final String FPS60 = "FPS60";
44
+    private static final String Adaptative = "Adaptative";
45
+    private static final String FixedLandscape = "FixedLandscape";
46
+    private static final String FixedPortrait = "FixedPortrait";
47
+    private static final String Host = "Host";
48
+    private static final String Audience = "Audience";
49
+    private static final String UserOfflineReasonQuit = "UserOfflineReasonQuit";
50
+    private static final String UserOfflineReasonDropped = "UserOfflineReasonDropped";
51
+    private static final String UserOfflineReasonBecomeAudience = "UserOfflineReasonBecomeAudience";
52
+    private static final String AudioSampleRateType32000 = "AudioSampleRateType32000";
53
+    private static final String AudioSampleRateType44100 = "AudioSampleRateType44100";
54
+    private static final String AudioSampleRateType48000 = "AudioSampleRateType48000";
55
+    private static final String CodecTypeBaseLine = "CodecTypeBaseLine";
56
+    private static final String CodecTypeMain = "CodecTypeMain";
57
+    private static final String CodecTypeHigh = "CodecTypeHigh";
58
+    private static final String QualityLow = "QualityLow";
59
+    private static final String QualityMedium = "QualityMedium";
60
+    private static final String QualityHigh = "QualityHigh";
61
+    private static final String Disconnected = "Disconnected";
62
+    private static final String Connecting = "Connecting";
63
+    private static final String Connected = "Connected";
64
+    private static final String Reconnecting = "Reconnecting";
65
+    private static final String ConnectionFailed = "ConnectionFailed";
66
+    private static final String ConnectionChangedConnecting = "ConnectionChangedConnecting";
67
+    private static final String ConnectionChangedJoinSuccess =  "ConnectionChangedJoinSuccess";
68
+    private static final String ConnectionChangedInterrupted = "ConnectionChangedInterrupted";
69
+    private static final String ConnectionChangedBannedByServer = "ConnectionChangedBannedByServer";
70
+    private static final String ConnectionChangedJoinFailed = "ConnectionChangedJoinFailed";
71
+    private static final String ConnectionChangedLeaveChannel = "ConnectionChangedLeaveChannel";
72
+    private static final String AudioOutputRoutingDefault = "AudioOutputRoutingDefault";
73
+    private static final String AudioOutputRoutingHeadset = "AudioOutputRoutingHeadset";
74
+    private static final String AudioOutputRoutingEarpiece = "AudioOutputRoutingEarpiece";
75
+    private static final String AudioOutputRoutingHeadsetNoMic = "AudioOutputRoutingHeadsetNoMic";
76
+    private static final String AudioOutputRoutingSpeakerphone = "AudioOutputRoutingSpeakerphone";
77
+    private static final String AudioOutputRoutingLoudspeaker = "AudioOutputRoutingLoudspeaker";
78
+    private static final String AudioOutputRoutingHeadsetBluetooth = "AudioOutputRoutingHeadsetBluetooth";
79
+    private static final String NetworkQualityUnknown = "NetworkQualityUnknown";
80
+    private static final String NetworkQualityExcellent = "NetworkQualityExcellent";
81
+    private static final String NetworkQualityGood = "NetworkQualityGood";
82
+    private static final String NetworkQualityPoor = "NetworkQualityPoor";
83
+    private static final String NetworkQualityBad = "NetworkQualityBad";
84
+    private static final String NetworkQualityVBad = "NetworkQualityVBad";
85
+    private static final String NetworkQualityDown = "NetworkQualityDown";
86
+    private static final String AudioProfileDefault = "AudioProfileDefault";
87
+    private static final String AudioProfileSpeechStandard = "AudioProfileSpeechStandard";
88
+    private static final String AudioProfileMusicStandard = "AudioProfileMusicStandard";
89
+    private static final String AgoraAudioProfileMusicStandardStereo = "AudioProfileMusicStandardStereo";
90
+    private static final String AudioProfileMusicHighQuality = "AudioProfileMusicHighQuality";
91
+    private static final String AudioProfileMusicHighQualityStereo = "AudioProfileMusicHighQualityStereo";
92
+    private static final String AudioScenarioDefault = "AudioScenarioDefault";
93
+    private static final String AudioScenarioChatRoomEntertainment = "AudioScenarioChatRoomEntertainment";
94
+    private static final String AudioScenarioEducation = "AudioScenarioEducation";
95
+    private static final String AudioScenarioGameStreaming = "AudioScenarioGameStreaming";
96
+    private static final String AudioScenarioShowRoom = "AudioScenarioShowRoom";
97
+    private static final String AudioScenarioChatRoomGaming = "AudioScenarioChatRoomGaming";
98
+    private static final String AudioEqualizationBand31 = "AudioEqualizationBand31";
99
+    private static final String AudioEqualizationBand62 = "AudioEqualizationBand62";
100
+    private static final String AudioEqualizationBand125 = "AudioEqualizationBand125";
101
+    private static final String AudioEqualizationBand250 = "AudioEqualizationBand250";
102
+    private static final String AudioEqualizationBand500 = "AudioEqualizationBand500";
103
+    private static final String AudioEqualizationBand1K = "AudioEqualizationBand1K";
104
+    private static final String AudioEqualizationBand2K = "AudioEqualizationBand2K";
105
+    private static final String AudioEqualizationBand4K = "AudioEqualizationBand4K";
106
+    private static final String AudioEqualizationBand8K = "AudioEqualizationBand8K";
107
+    private static final String AudioEqualizationBand16K = "AudioEqualizationBand16K";
108
+    private static final String AudioRawFrameOperationModeReadOnly = "AudioRawFrameOperationModeReadOnly";
109
+    private static final String AudioRawFrameOperationModeWriteOnly = "AudioRawFrameOperationModeWriteOnly";
110
+    private static final String AudioRawFrameOperationModeReadWrite = "AudioRawFrameOperationModeReadWrite";
111
+    private static final String VideoStreamTypeHigh = "VideoStreamTypeHigh";
112
+    private static final String VideoStreamTypeLow = "VideoStreamTypeLow";
113
+    private static final String VideoMirrorModeAuto = "VideoMirrorModeAuto";
114
+    private static final String VideoMirrorModeEnabled = "VideoMirrorModeEnabled";
115
+    private static final String VideoMirrorModeDisabled = "VideoMirrorModeDisabled";
116
+    private static final String ChannelProfileCommunication = "ChannelProfileCommunication";
117
+    private static final String ChannelProfileLiveBroadcasting = "ChannelProfileLiveBroadcasting";
118
+    private static final String ChannelProfileGame = "ChannelProfileGame";
119
+    private static final String ErrorCodeNoError = "ErrorCodeNoError";
120
+    private static final String ErrorCodeFailed = "ErrorCodeFailed";
121
+    private static final String ErrorCodeInvalidArgument = "ErrorCodeInvalidArgument";
122
+    private static final String ErrorCodeTimedOut = "ErrorCodeTimedOut";
123
+    private static final String ErrorCodeAlreadyInUse = "ErrorCodeAlreadyInUse";
131 124
 //    private static String ErrorCodeAbort = "ErrorCodeAbort";
132
-    private static String ErrorCodeEncryptedStreamNotAllowedPublished = "ErrorCodeEncryptedStreamNotAllowedPublished";
125
+    private static final String ErrorCodeEncryptedStreamNotAllowedPublished = "ErrorCodeEncryptedStreamNotAllowedPublished";
133 126
 //    private static String ErrorCodeResourceLimited = "ErrorCodeResourceLimited";
134
-    private static String InjectStreamStatusStartSuccess = "InjectStreamStatusStartSuccess";
135
-    private static String InjectStreamStatusStartAlreadyExist = "InjectStreamStatusStartAlreadyExist";
136
-    private static String InjectStreamStatusStartUnauthorized = "InjectStreamStatusStartUnauthorized";
137
-    private static String InjectStreamStatusStartTimeout = "InjectStreamStatusStartTimeout";
138
-    private static String InjectStreamStatusStartFailed = "InjectStreamStatusStartFailed";
139
-    private static String InjectStreamStatusStopSuccess = "InjectStreamStatusStopSuccess";
140
-    private static String InjectStreamStatusStopNotFound = "InjectStreamStatusStopNotFound";
141
-    private static String InjectStreamStatusStopUnauthorized = "InjectStreamStatusStopUnauthorized";
142
-    private static String InjectStreamStatusStopTimeout = "InjectStreamStatusStopTimeout";
143
-    private static String InjectStreamStatusStopFailed = "InjectStreamStatusStopFailed";
144
-    private static String InjectStreamStatusBroken = "InjectStreamStatusBroken";
127
+    private static final String InjectStreamStatusStartSuccess = "InjectStreamStatusStartSuccess";
128
+    private static final String InjectStreamStatusStartAlreadyExist = "InjectStreamStatusStartAlreadyExist";
129
+    private static final String InjectStreamStatusStartUnauthorized = "InjectStreamStatusStartUnauthorized";
130
+    private static final String InjectStreamStatusStartTimeout = "InjectStreamStatusStartTimeout";
131
+    private static final String InjectStreamStatusStartFailed = "InjectStreamStatusStartFailed";
132
+    private static final String InjectStreamStatusStopSuccess = "InjectStreamStatusStopSuccess";
133
+    private static final String InjectStreamStatusStopNotFound = "InjectStreamStatusStopNotFound";
134
+    private static final String InjectStreamStatusStopUnauthorized = "InjectStreamStatusStopUnauthorized";
135
+    private static final String InjectStreamStatusStopTimeout = "InjectStreamStatusStopTimeout";
136
+    private static final String InjectStreamStatusStopFailed = "InjectStreamStatusStopFailed";
137
+    private static final String InjectStreamStatusBroken = "InjectStreamStatusBroken";
138
+    private static final String AgoraAudioMode = "AgoraAudioMode";
139
+    private static final String AgoraVideoMode = "AgoraVideoMode";
145 140
 
146 141
     public AgoraModule(ReactApplicationContext context) {
147 142
         super(context);
@@ -254,6 +249,8 @@ public class AgoraModule extends ReactContextBaseJavaModule {
254 249
         constants.put(QualityLow, Constants.AUDIO_RECORDING_QUALITY_LOW);
255 250
         constants.put(QualityMedium, Constants.AUDIO_RECORDING_QUALITY_MEDIUM);
256 251
         constants.put(QualityHigh, Constants.AUDIO_RECORDING_QUALITY_HIGH);
252
+        constants.put(AgoraAudioMode, 0);
253
+        constants.put(AgoraVideoMode, 1);
257 254
         return constants;
258 255
     }
259 256
 
@@ -2169,8 +2166,8 @@ public class AgoraModule extends ReactContextBaseJavaModule {
2169 2166
     public void setLiveTranscoding(ReadableMap options) {
2170 2167
         try {
2171 2168
             LiveTranscoding transcoding = new LiveTranscoding();
2172
-            ReadableMap size = options.getMap("size");
2173
-            if (size != null) {
2169
+            if (options.hasKey("size") && null != options.getMap("size")) {
2170
+                ReadableMap size = options.getMap("size");
2174 2171
                 transcoding.width = size.getInt("width");
2175 2172
                 transcoding.height = size.getInt("height");
2176 2173
             }

+ 0
- 1
android/src/main/java/com/syan/agora/AgoraViewManage.java View File

@@ -2,7 +2,6 @@ package com.syan.agora;
2 2
 
3 3
 import android.view.SurfaceView;
4 4
 
5
-import com.facebook.react.bridge.ReadableMap;
6 5
 import com.facebook.react.uimanager.SimpleViewManager;
7 6
 import com.facebook.react.uimanager.ThemedReactContext;
8 7
 import com.facebook.react.uimanager.annotations.ReactProp;

+ 0
- 3
android/src/main/java/com/syan/agora/ReactNativeAgoraException.java View File

@@ -1,8 +1,5 @@
1 1
 package com.syan.agora;
2 2
 
3
-
4
-import com.facebook.react.bridge.WritableMap;
5
-
6 3
 public class ReactNativeAgoraException extends Exception {
7 4
 
8 5
     private int code;

+ 5
- 0
ios/RCTAgora/AgoraConst.h View File

@@ -73,6 +73,11 @@ static NSString *AGOccurStreamMessageError = @"occurStreamMessageError";
73 73
 static NSString *AGMediaEngineLoaded = @"mediaEngineLoaded";
74 74
 static NSString *AGMediaEngineStartCall = @"mediaEngineStartCall";
75 75
 
76
+typedef NS_ENUM(NSInteger, AgoraModeType) {
77
+  AgoraAudioMode,
78
+  AgoraVideoMode
79
+};
80
+
76 81
 @interface AgoraConst : NSObject
77 82
 
78 83
 @property (nonatomic, copy) NSString *appid;

+ 38
- 18
ios/RCTAgora/RCTAgora.m View File

@@ -137,7 +137,9 @@ RCT_EXPORT_MODULE();
137 137
            @"AgoraVideoMirrorModeDisabled": @(AgoraVideoMirrorModeDisabled),
138 138
            @"AgoraChannelProfileCommunication": @(AgoraChannelProfileCommunication),
139 139
            @"AgoraChannelProfileLiveBroadcasting": @(AgoraChannelProfileLiveBroadcasting),
140
-           @"AgoraChannelProfileGame": @(AgoraChannelProfileGame)
140
+           @"AgoraChannelProfileGame": @(AgoraChannelProfileGame),
141
+           @"AgoraAudioMode": @(AgoraAudioMode),
142
+           @"AgoraVideoMode": @(AgoraVideoMode),
141 143
          };
142 144
 }
143 145
 
@@ -154,25 +156,43 @@ RCT_EXPORT_METHOD(init:(NSDictionary *)options) {
154 156
   //channel mode
155 157
   [self.rtcEngine setChannelProfile:[options[@"channelProfile"] integerValue]];
156 158
   //enable dual stream
157
-  [self.rtcEngine enableDualStreamMode:YES];
158
-  [self.rtcEngine enableVideo];
159
-  
160
-  if (options[@"secret"] != nil) {
161
-    [self.rtcEngine setEncryptionSecret:[options[@"secret"] stringValue]];
162
-    if (options[@"secretMode"] != nil) {
163
-      [self.rtcEngine setEncryptionMode:[options[@"secretMode"] stringValue]];
159
+  if ([options objectForKey:@"dualStream"]) {
160
+    [self.rtcEngine enableDualStreamMode:[options[@"dualStream"] boolValue]];
161
+     }
162
+  if ([options objectForKey:@"mode"]) {
163
+    switch([options[@"mode"] integerValue]) {
164
+       case AgoraAudioMode: {
165
+         [self.rtcEngine enableAudio];
166
+         [self.rtcEngine disableVideo];
167
+         break;
168
+       }
169
+       case AgoraVideoMode: {
170
+         [self.rtcEngine enableVideo];
171
+         [self.rtcEngine disableAudio];
172
+         break;
173
+       }
164 174
     }
165
-  }
175
+   } else {
176
+     [self.rtcEngine enableVideo];
177
+     [self.rtcEngine enableAudio];
178
+   }
166 179
   
167
-  AgoraVideoEncoderConfiguration *video_encoder_config = [[AgoraVideoEncoderConfiguration new] initWithWidth:[options[@"videoEncoderConfig"][@"width"] integerValue] height:[options[@"videoEncoderConfig"][@"height"] integerValue] frameRate:(AgoraVideoFrameRate)[options[@"videoEncoderConfig"][@"frameRate"] integerValue] bitrate:[options[@"videoEncoderConfig"][@"bitrate"] integerValue] orientationMode: (AgoraVideoOutputOrientationMode)[options[@"videoEncoderConfig"][@"orientationMode"] integerValue]];
168
-  [self.rtcEngine setVideoEncoderConfiguration:video_encoder_config];
169
-  [self.rtcEngine setClientRole:(AgoraClientRole)[options[@"clientRole"] integerValue]];
170
-  [self.rtcEngine setAudioProfile:(AgoraAudioProfile)[options[@"audioProfile"] integerValue]
171
-                         scenario:(AgoraAudioScenario)[options[@"audioScenario"] integerValue]];
172
-  
173
-  //Enable Agora Native SDK be Interoperable with Agora Web SDK
174
-  [self.rtcEngine enableWebSdkInteroperability:YES];
175
-}
180
+   if (options[@"secret"] != nil) {
181
+     [self.rtcEngine setEncryptionSecret:[options[@"secret"] stringValue]];
182
+     if (options[@"secretMode"] != nil) {
183
+       [self.rtcEngine setEncryptionMode:[options[@"secretMode"] stringValue]];
184
+     }
185
+   }
186
+     
187
+   AgoraVideoEncoderConfiguration *video_encoder_config = [[AgoraVideoEncoderConfiguration new] initWithWidth:[options[@"videoEncoderConfig"][@"width"] integerValue] height:[options[@"videoEncoderConfig"][@"height"] integerValue] frameRate:(AgoraVideoFrameRate)[options[@"videoEncoderConfig"][@"frameRate"] integerValue] bitrate:[options[@"videoEncoderConfig"][@"bitrate"] integerValue] orientationMode: (AgoraVideoOutputOrientationMode)[options[@"videoEncoderConfig"][@"orientationMode"] integerValue]];
188
+   [self.rtcEngine setVideoEncoderConfiguration:video_encoder_config];
189
+   [self.rtcEngine setClientRole:(AgoraClientRole)[options[@"clientRole"] integerValue]];
190
+   [self.rtcEngine setAudioProfile:(AgoraAudioProfile)[options[@"audioProfile"] integerValue]
191
+                          scenario:(AgoraAudioScenario)[options[@"audioScenario"] integerValue]];
192
+     
193
+     //Enable Agora Native SDK be Interoperable with Agora Web SDK
194
+   [self.rtcEngine enableWebSdkInteroperability:YES];
195
+ }
176 196
 
177 197
 // renew token
178 198
 RCT_EXPORT_METHOD(renewToken

+ 2
- 0
src/types.d.ts View File

@@ -15,6 +15,8 @@ export interface Option {
15 15
   videoProfile: number
16 16
   channelProfile: number,
17 17
   videoEncoderConfig: VideoEncoderConfig,
18
+  dualStream: boolean,
19
+  mode: number,
18 20
   clientRole: number,
19 21
   audioProfile: number,
20 22
   audioScenario: number