Browse Source

Merge pull request #71 from syanbo/fix/migrate-to-mainthread

fix iOS receiveStreamMessage is null and invoke enableVideo in main thread.
matrixbirds 5 years ago
parent
commit
cad48a408d
No account linked to committer's email address
1 changed files with 22 additions and 16 deletions
  1. 22
    16
      ios/RCTAgora/RCTAgora.m

+ 22
- 16
ios/RCTAgora/RCTAgora.m View File

158
   //enable dual stream
158
   //enable dual stream
159
   if ([options objectForKey:@"dualStream"]) {
159
   if ([options objectForKey:@"dualStream"]) {
160
     [self.rtcEngine enableDualStreamMode:[options[@"dualStream"] boolValue]];
160
     [self.rtcEngine enableDualStreamMode:[options[@"dualStream"] boolValue]];
161
-     }
161
+  }
162
+  dispatch_sync(dispatch_get_main_queue(), ^{
163
+    [self.rtcEngine enableVideo];
164
+    [self.rtcEngine enableAudio];
165
+  });
162
   if ([options objectForKey:@"mode"]) {
166
   if ([options objectForKey:@"mode"]) {
163
     switch([options[@"mode"] integerValue]) {
167
     switch([options[@"mode"] integerValue]) {
164
        case AgoraAudioMode: {
168
        case AgoraAudioMode: {
165
-         [self.rtcEngine enableAudio];
166
-         [self.rtcEngine disableVideo];
169
+         [self.rtcEngine enableLocalAudio:true];
170
+         [self.rtcEngine enableLocalVideo:false];
167
          break;
171
          break;
168
        }
172
        }
169
        case AgoraVideoMode: {
173
        case AgoraVideoMode: {
170
-         [self.rtcEngine enableVideo];
171
-         [self.rtcEngine disableAudio];
174
+         [self.rtcEngine enableLocalVideo:true];
175
+         [self.rtcEngine enableLocalAudio:false];
172
          break;
176
          break;
173
        }
177
        }
174
     }
178
     }
175
    } else {
179
    } else {
176
-     [self.rtcEngine enableVideo];
177
-     [self.rtcEngine enableAudio];
180
+     [self.rtcEngine enableLocalVideo:true];
181
+     [self.rtcEngine enableLocalAudio:true];
178
    }
182
    }
179
   
183
   
180
   if ([options objectForKey:@"beauty"]) {
184
   if ([options objectForKey:@"beauty"]) {
1520
                   :(NSDictionary *)options
1524
                   :(NSDictionary *)options
1521
                   resolve:(RCTPromiseResolveBlock)resolve
1525
                   resolve:(RCTPromiseResolveBlock)resolve
1522
                   reject:(RCTPromiseRejectBlock)reject) {
1526
                   reject:(RCTPromiseRejectBlock)reject) {
1523
-  BOOL res = [self.rtcEngine setCameraFocusPositionInPreview:CGPointMake((CGFloat)[options[@"x"] floatValue], (CGFloat)[options[@"y"] floatValue])];
1524
-  resolve(@{
1525
-            @"success": @(YES),
1526
-            @"value": @(res)
1527
-            });
1527
+  dispatch_sync(dispatch_get_main_queue(), ^{
1528
+    BOOL res = [self.rtcEngine setCameraFocusPositionInPreview:CGPointMake((CGFloat)[options[@"x"] floatValue], (CGFloat)[options[@"y"] floatValue])];
1529
+    resolve(@{
1530
+              @"success": @(YES),
1531
+              @"value": @(res)
1532
+              });
1533
+  });
1528
 }
1534
 }
1529
 
1535
 
1530
 // setCameraExposurePosition
1536
 // setCameraExposurePosition
2395
 }
2401
 }
2396
 
2402
 
2397
 - (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine receiveStreamMessageFromUid:(NSUInteger)uid streamId:(NSInteger)streamId data:(NSData *_Nonnull)data {
2403
 - (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine receiveStreamMessageFromUid:(NSUInteger)uid streamId:(NSInteger)streamId data:(NSData *_Nonnull)data {
2404
+  NSString *_data = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
2398
   [self sendEvent:AGReceiveStreamMessage params:@{
2405
   [self sendEvent:AGReceiveStreamMessage params:@{
2399
-                                                @"uid": @(uid),
2400
-                                                @"streamId": @(streamId),
2401
-                                                @"data": data
2402
-                                                }];
2406
+                                                  @"uid": @(uid),
2407
+                                                  @"streamId": @(streamId),
2408
+                                                  @"data": _data}];
2403
 }
2409
 }
2404
 
2410
 
2405
 - (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine didOccurStreamMessageErrorFromUid:(NSUInteger)uid streamId:(NSInteger)streamId error:(NSInteger)error missed:(NSInteger)missed cached:(NSInteger)cached {
2411
 - (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine didOccurStreamMessageErrorFromUid:(NSUInteger)uid streamId:(NSInteger)streamId error:(NSInteger)error missed:(NSInteger)missed cached:(NSInteger)cached {