Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ public void init() {
mClient = mStringeeManager.getClient();
if (mClient == null) {
mClient = new StringeeClient(getReactApplicationContext());
mClient.setConnectionListener(this);
}

mClient.setConnectionListener(this);
mStringeeManager.setClient(mClient);
}

Expand Down
2 changes: 2 additions & 0 deletions ios/RNStringeeCall.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

@interface RNStringeeCall : RCTEventEmitter <RCTBridgeModule, StringeeCallDelegate>

@property(strong, nonatomic) StringeeCall *stringeeCall;

- (void)addRenderToView:(UIView *)view callId:(NSString *)callId isLocal:(BOOL)isLocal;

@end
51 changes: 51 additions & 0 deletions ios/RNStringeeCall.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#import "RNStringeeCall.h"
#import "RNStringeeInstanceManager.h"
#import <React/RCTLog.h>
#import <objc/runtime.h>

static NSString *didChangeSignalingState = @"didChangeSignalingState";
static NSString *didChangeMediaState = @"didChangeMediaState";
Expand All @@ -12,6 +13,12 @@
static NSString *didReceiveCallInfo = @"didReceiveCallInfo";
static NSString *didHandleOnAnotherDevice = @"didHandleOnAnotherDevice";

@implementation NSString (Helpers)

+(BOOL)stringIsNilOrEmpty:(NSString*)aString {
return !aString || ![aString length] || [aString length] == 0;
}
@end

@implementation RNStringeeCall {
NSMutableArray<NSString *> *jsEvents;
Expand Down Expand Up @@ -45,6 +52,48 @@ + (BOOL)requiresMainQueueSetup {
return YES;
}

void updateStringeeClzz() {
SEL selectorOrigin = NSSelectorFromString(@"originalAddAllCandidate:");
if (![StringeeCall respondsToSelector: selectorOrigin]) {
SEL selector = @selector(addAllCandidate:);
Class clzStringeeCall = [StringeeCall class];
Class clzSelf = [RNStringeeCall class];

Method overrideAddAllCandidate = class_getInstanceMethod(clzSelf, selector);
Method originalAddAllCandidate = class_getInstanceMethod(clzStringeeCall, selector);

BOOL success = class_addMethod(clzStringeeCall, selectorOrigin, method_getImplementation(originalAddAllCandidate), method_getTypeEncoding(originalAddAllCandidate));

if (success) {
class_replaceMethod(clzStringeeCall, @selector(addAllCandidate:), method_getImplementation(overrideAddAllCandidate), method_getTypeEncoding(overrideAddAllCandidate));
}
}
}

- (void)addAllCandidate: (NSMutableArray*) candidates {
BOOL isNullorEmpty = candidates == nil || [candidates count] == 0;
if (!isNullorEmpty) {
NSUInteger total = [candidates count] - 1;
for (NSUInteger i = total; i > NSIntegerMax; i--) {
NSString* sdp = (NSString*) [[candidates objectAtIndex: i] valueForKey:@"_sdp"];
if ([NSString stringIsNilOrEmpty: sdp]) {
[candidates removeObjectAtIndex: i];
}
}
}
SEL originalAddAllCandidate = NSSelectorFromString(@"originalAddAllCandidate:");
StringeeCall* call = _stringeeCall;
if (call != nil && [call respondsToSelector: originalAddAllCandidate])
{
NSMethodSignature * methodSignature = [[call class] instanceMethodSignatureForSelector: originalAddAllCandidate];
NSInvocation * delegateInvocation = [NSInvocation invocationWithMethodSignature:methodSignature];
[delegateInvocation setSelector: originalAddAllCandidate];
[delegateInvocation setTarget:call];
[delegateInvocation setArgument:&candidates atIndex:2];
[delegateInvocation invoke];
}
}

// TODO: - Publish Functions

RCT_EXPORT_METHOD(setNativeEvent:(NSString *)event) {
Expand Down Expand Up @@ -127,6 +176,8 @@ + (BOOL)requiresMainQueueSetup {
RCT_EXPORT_METHOD(answer:(NSString *)callId callback:(RCTResponseSenderBlock)callback) {
if (callId.length) {
StringeeCall *call = [[RNStringeeInstanceManager instance].calls objectForKey:callId];
_stringeeCall = call;
updateStringeeClzz();
if (call) {
[call answerCallWithCompletionHandler:^(BOOL status, int code, NSString *message) {
callback(@[@(status), @(code), message]);
Expand Down