|
2 | 2 | #import "RNStringeeCall.h" |
3 | 3 | #import "RNStringeeInstanceManager.h" |
4 | 4 | #import <React/RCTLog.h> |
| 5 | +#import <objc/runtime.h> |
5 | 6 |
|
6 | 7 | static NSString *didChangeSignalingState = @"didChangeSignalingState"; |
7 | 8 | static NSString *didChangeMediaState = @"didChangeMediaState"; |
|
12 | 13 | static NSString *didReceiveCallInfo = @"didReceiveCallInfo"; |
13 | 14 | static NSString *didHandleOnAnotherDevice = @"didHandleOnAnotherDevice"; |
14 | 15 |
|
| 16 | +@implementation NSString (Helpers) |
| 17 | + |
| 18 | ++(BOOL)stringIsNilOrEmpty:(NSString*)aString { |
| 19 | + return !aString || ![aString length] || [aString length] == 0; |
| 20 | +} |
| 21 | +@end |
15 | 22 |
|
16 | 23 | @implementation RNStringeeCall { |
17 | 24 | NSMutableArray<NSString *> *jsEvents; |
@@ -45,6 +52,49 @@ + (BOOL)requiresMainQueueSetup { |
45 | 52 | return YES; |
46 | 53 | } |
47 | 54 |
|
| 55 | +void updateStringeeClzz() { |
| 56 | + SEL selectorOrigin = NSSelectorFromString(@"originalAddAllCandidate:"); |
| 57 | + if (![StringeeCall respondsToSelector: selectorOrigin]) { |
| 58 | + SEL selector = @selector(addAllCandidate:); |
| 59 | + Class clzStringeeCall = [StringeeCall class]; |
| 60 | + Class clzSelf = [RNStringeeCall class]; |
| 61 | + |
| 62 | + Method overrideAddAllCandidate = class_getInstanceMethod(clzSelf, selector); |
| 63 | + Method originalAddAllCandidate = class_getInstanceMethod(clzStringeeCall, selector); |
| 64 | + |
| 65 | + BOOL success = class_addMethod(clzStringeeCall, selectorOrigin, method_getImplementation(originalAddAllCandidate), method_getTypeEncoding(originalAddAllCandidate)); |
| 66 | + |
| 67 | + if (success) { |
| 68 | + class_replaceMethod(clzStringeeCall, @selector(addAllCandidate:), method_getImplementation(overrideAddAllCandidate), method_getTypeEncoding(overrideAddAllCandidate)); |
| 69 | + } |
| 70 | + } |
| 71 | +} |
| 72 | + |
| 73 | +- (void)addAllCandidate: (NSMutableArray*) candidates { |
| 74 | + BOOL isNullorEmpty = candidates == nil || [candidates count] == 0; |
| 75 | + if (!isNullorEmpty) { |
| 76 | + NSUInteger total = [candidates count] - 1; |
| 77 | + for (NSUInteger i = total; i > NSIntegerMax; i--) { |
| 78 | + NSString* sdp = (NSString*) [[candidates objectAtIndex: i] valueForKey:@"_sdp"]; |
| 79 | + NSLog(@"count i %tu sdp: %@", i, sdp); |
| 80 | + if ([NSString stringIsNilOrEmpty: sdp]) { |
| 81 | + [candidates removeObjectAtIndex: i]; |
| 82 | + } |
| 83 | + } |
| 84 | + } |
| 85 | + SEL originalAddAllCandidate = NSSelectorFromString(@"originalAddAllCandidate:"); |
| 86 | + StringeeCall* call = _stringeeCall; |
| 87 | + if (call != nil && [call respondsToSelector: originalAddAllCandidate]) |
| 88 | + { |
| 89 | + NSMethodSignature * methodSignature = [[call class] instanceMethodSignatureForSelector: originalAddAllCandidate]; |
| 90 | + NSInvocation * delegateInvocation = [NSInvocation invocationWithMethodSignature:methodSignature]; |
| 91 | + [delegateInvocation setSelector: originalAddAllCandidate]; |
| 92 | + [delegateInvocation setTarget:call]; |
| 93 | + [delegateInvocation setArgument:&candidates atIndex:2]; |
| 94 | + [delegateInvocation invoke]; |
| 95 | + } |
| 96 | +} |
| 97 | + |
48 | 98 | // TODO: - Publish Functions |
49 | 99 |
|
50 | 100 | RCT_EXPORT_METHOD(setNativeEvent:(NSString *)event) { |
@@ -127,6 +177,8 @@ + (BOOL)requiresMainQueueSetup { |
127 | 177 | RCT_EXPORT_METHOD(answer:(NSString *)callId callback:(RCTResponseSenderBlock)callback) { |
128 | 178 | if (callId.length) { |
129 | 179 | StringeeCall *call = [[RNStringeeInstanceManager instance].calls objectForKey:callId]; |
| 180 | + _stringeeCall = call; |
| 181 | + updateStringeeClzz(); |
130 | 182 | if (call) { |
131 | 183 | [call answerCallWithCompletionHandler:^(BOOL status, int code, NSString *message) { |
132 | 184 | callback(@[@(status), @(code), message]); |
@@ -308,7 +360,7 @@ + (BOOL)requiresMainQueueSetup { |
308 | 360 |
|
309 | 361 | [call mute:mute]; |
310 | 362 | callback(@[@(YES), @(0), @"Success"]); |
311 | | - |
| 363 | + |
312 | 364 | } |
313 | 365 |
|
314 | 366 | RCT_EXPORT_METHOD(setSpeakerphoneOn:(NSString *)callId speaker:(BOOL)speaker callback:(RCTResponseSenderBlock)callback) { |
|
0 commit comments