Skip to content

Commit

Permalink
added support for handling clients that do not support trickle ice
Browse files Browse the repository at this point in the history
  • Loading branch information
trshafer committed Apr 2, 2015
1 parent 8358320 commit 142db75
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 31 deletions.
3 changes: 1 addition & 2 deletions cineio-peer-ios/cineio-peer-ios/CineLocalAnswerSDPObserver.m
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ - (void) peerConnection:(RTCPeerConnection *)peerConnection
- (void) sendLocalDescription
{
NSLog(@"sendLocalDescription");

[[self.cinePeerClient getSignalingConnection] sendLocalDescription:[self.rtcMember getSparkId] description:self.localSdp];
[self.rtcMember localDescriptionReady];
}

// Called when setting a local or remote description.
Expand Down
7 changes: 3 additions & 4 deletions cineio-peer-ios/cineio-peer-ios/CineLocalOfferSDPObserver.m
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,11 @@ - (void) sendLocalDescription
{
NSLog(@"sendLocalDescription");

[[self.cinePeerClient getSignalingConnection] sendLocalDescription:[self.rtcMember getSparkId] description:self.localSdp];
[self.rtcMember localDescriptionReady];

}

// Called when setting a local or remote description.
// Called when setting a local description.
- (void) peerConnection:(RTCPeerConnection *)peerConnection
didSetSessionDescriptionWithError:(NSError *)error
{
Expand All @@ -75,10 +76,8 @@ - (void) peerConnection:(RTCPeerConnection *)peerConnection
NSAssert(NO, error.description);
return;
}
dispatch_async(dispatch_get_main_queue(), ^{
NSLog(@"didSetSessionDescriptionWithError no error");
[self sendLocalDescription];
});
}

@end
10 changes: 5 additions & 5 deletions cineio-peer-ios/cineio-peer-ios/CinePeerConnectionManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@

- (void)configureICEServers:(NSArray *)configDicts;

- (void)ensurePeerConnection:(NSString *)otherClientSparkUUID otherClientSparkId:(NSString *)otherClientSparkId offer:(BOOL)offer;
- (void)ensurePeerConnection:(NSString *)otherClientSparkUUID otherClientSparkId:(NSString *)otherClientSparkId offer:(BOOL)offer support:(NSDictionary *)support;

- (CineRTCMember*)getPeerConnection:(NSString *)otherClientSparkUUID otherClientSparkId:(NSString *)otherClientSparkId offer:(BOOL)offer;
- (CineRTCMember*)getPeerConnection:(NSString *)otherClientSparkUUID otherClientSparkId:(NSString *)otherClientSparkId offer:(BOOL)offer support:(NSDictionary *)support;

- (void)closePeerConnection:(NSString *)otherClientSparkUUID;

- (void)handleOffer:(NSString *)otherClientSparkUUID otherClientSparkId:(NSString *)otherClientSparkId offer:(NSDictionary *)offer;
- (void)handleAnswer:(NSString *)otherClientSparkUUID otherClientSparkId:(NSString *)otherClientSparkId answer:(NSDictionary *)answer;
- (void)handleIce:(NSString *)otherClientSparkUUID otherClientSparkId:(NSString *)otherClientSparkId iceCandidate:(NSDictionary *)iceCandidate;
- (void)handleIce:(NSString *)otherClientSparkUUID otherClientSparkId:(NSString *)otherClientSparkId iceCandidate:(NSDictionary *)iceCandidate support:(NSDictionary *)support;
- (void)handleOffer:(NSString *)otherClientSparkUUID otherClientSparkId:(NSString *)otherClientSparkId offer:(NSDictionary *)offer support:(NSDictionary *)support;
- (void)handleAnswer:(NSString *)otherClientSparkUUID otherClientSparkId:(NSString *)otherClientSparkId answer:(NSDictionary *)answer support:(NSDictionary *)support;

@end

Expand Down
28 changes: 16 additions & 12 deletions cineio-peer-ios/cineio-peer-ios/CinePeerConnectionManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ - (void)configureICEServers:(NSArray *)configDicts
}
}

- (void)handleOffer:(NSString *)otherClientSparkUUID otherClientSparkId:(NSString *)otherClientSparkId offer:(NSDictionary *)offer
- (void)handleOffer:(NSString *)otherClientSparkUUID otherClientSparkId:(NSString *)otherClientSparkId offer:(NSDictionary *)offer support:(NSDictionary *)support
{
NSLog(@"HANDLE OFFER");

Expand All @@ -82,7 +82,7 @@ - (void)handleOffer:(NSString *)otherClientSparkUUID otherClientSparkId:(NSStrin
[[RTCSessionDescription alloc] initWithType:offer[@"type"]
sdp:[CineRTCHelper preferISAC:sdpString]];

CineRTCMember *rtcMember = [self getPeerConnection:otherClientSparkUUID otherClientSparkId:otherClientSparkId offer:false];
CineRTCMember *rtcMember = [self getPeerConnection:otherClientSparkUUID otherClientSparkId:otherClientSparkId offer:false support:support];
NSLog(@"GOT member");

RTCPeerConnection* conn = [rtcMember getPeerConnection];
Expand All @@ -94,20 +94,18 @@ - (void)handleOffer:(NSString *)otherClientSparkUUID otherClientSparkId:(NSStrin

}

- (void)handleAnswer:(NSString *)otherClientSparkUUID otherClientSparkId:(NSString *)otherClientSparkId answer:(NSDictionary *)answer
- (void)handleAnswer:(NSString *)otherClientSparkUUID otherClientSparkId:(NSString *)otherClientSparkId answer:(NSDictionary *)answer support:(NSDictionary *)support
{
NSLog(@"HANDLE ANSWER");

CineRTCMember *rtcMember = [self getPeerConnection:otherClientSparkUUID otherClientSparkId:otherClientSparkId offer:false];
CineRTCMember *rtcMember = [self getPeerConnection:otherClientSparkUUID otherClientSparkId:otherClientSparkId offer:false support:support];
NSLog(@"GOT member");

NSString* sdpString = answer[@"sdp"];
[rtcMember setRemoteAnswerAndSetIfIceIsComplete:sdpString];


}

- (void)handleIce:(NSString *)otherClientSparkUUID otherClientSparkId:(NSString *)otherClientSparkId iceCandidate:(NSDictionary *)iceCandidate
- (void)handleIce:(NSString *)otherClientSparkUUID otherClientSparkId:(NSString *)otherClientSparkId iceCandidate:(NSDictionary *)iceCandidate support:(NSDictionary *)support
{
NSLog(@"disregarding ice candidates, I do not support trickle ice");

Expand All @@ -132,22 +130,22 @@ - (void)handleIce:(NSString *)otherClientSparkUUID otherClientSparkId:(NSString



- (void)ensurePeerConnection:(NSString *)otherClientSparkUUID otherClientSparkId:(NSString *)otherClientSparkId offer:(BOOL)offer
- (void)ensurePeerConnection:(NSString *)otherClientSparkUUID otherClientSparkId:(NSString *)otherClientSparkId offer:(BOOL)offer support:(NSDictionary *)support
{
[self getPeerConnection:otherClientSparkUUID otherClientSparkId:otherClientSparkId offer:offer];
[self getPeerConnection:otherClientSparkUUID otherClientSparkId:otherClientSparkId offer:offer support:support];
}

- (CineRTCMember*)getPeerConnection:(NSString *)otherClientSparkUUID otherClientSparkId:(NSString *)otherClientSparkId offer:(BOOL)offer
- (CineRTCMember*)getPeerConnection:(NSString *)otherClientSparkUUID otherClientSparkId:(NSString *)otherClientSparkId offer:(BOOL)offer support:(NSDictionary *)support
{
CineRTCMember *member = [self.rtcMembers objectForKey:otherClientSparkUUID];
if (member != nil) {
[member setSparkId:otherClientSparkId];
return member;
}
return [self createPeerConnection:otherClientSparkUUID otherClientSparkId:otherClientSparkId offer:offer];
return [self createPeerConnection:otherClientSparkUUID otherClientSparkId:otherClientSparkId offer:offer support:support];
}

- (CineRTCMember*)createPeerConnection:(NSString *)otherClientSparkUUID otherClientSparkId:(NSString *)otherClientSparkId offer:(BOOL)offer
- (CineRTCMember*)createPeerConnection:(NSString *)otherClientSparkUUID otherClientSparkId:(NSString *)otherClientSparkId offer:(BOOL)offer support:(NSDictionary *)support
{
NSLog(@"creating new peer connection: %@", otherClientSparkUUID);
CineRTCMember *member = [[CineRTCMember alloc] init];
Expand All @@ -157,6 +155,12 @@ - (CineRTCMember*)createPeerConnection:(NSString *)otherClientSparkUUID otherCli
[member setSparkUUID:otherClientSparkUUID];
NSLog(@"set spark uuid");

[member setSupport:support];
NSLog(@"created set support");

[member setSignalingConnection:[self.cinePeerClient getSignalingConnection]];
NSLog(@"set signaling connection");


CinePeerObserver *observer = [[CinePeerObserver alloc] init];
NSLog(@"created observer");
Expand Down
12 changes: 10 additions & 2 deletions cineio-peer-ios/cineio-peer-ios/CinePeerObserver.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#import "CineSignalingConnection.h"
#import "RTCMediaStream.h"
#import "RTCPeerConnectionDelegate.h"
#import "RTCPeerConnection.h"

@interface CinePeerObserver () <RTCPeerConnectionDelegate>
@property (nonatomic, weak) CineRTCMember* rtcMember;
Expand Down Expand Up @@ -132,6 +133,7 @@ - (void)peerConnection:(RTCPeerConnection *)peerConnection
{
NSLog(@"iceGatheringChanged");
if (newState == RTCICEGatheringComplete) {
// peerConnection.localDescription
NSLog(@"iceGatheringChanged complete");
[self.rtcMember markIceComplete];
}
Expand All @@ -140,8 +142,14 @@ - (void)peerConnection:(RTCPeerConnection *)peerConnection
- (void)peerConnection:(RTCPeerConnection *)peerConnection
gotICECandidate:(RTCICECandidate *)candidate
{
NSString* sparkId = [self.rtcMember getSparkId];
[[self.cinePeerClient getSignalingConnection] sendIceCandidate:sparkId candidate:candidate];
if ([self.rtcMember supportsTrickleIce]) {
NSLog(@"gotICECandidate and sending: %@", candidate);

NSString* sparkId = [self.rtcMember getSparkId];
[[self.cinePeerClient getSignalingConnection] sendIceCandidate:sparkId candidate:candidate];
}else {
NSLog(@"gotICECandidate but not sending: %@", candidate);
}

// //NSLog(@"gotICECandidate: %@", candidate);
// dispatch_async(dispatch_get_main_queue(), ^{
Expand Down
7 changes: 6 additions & 1 deletion cineio-peer-ios/cineio-peer-ios/CineRTCMember.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,19 @@

//Cine Peer SDK
@class CinePeerObserver;
@class CineSignalingConnection;

@interface CineRTCMember : NSObject

- (void)setSupport:(NSDictionary *)support;
- (void)setSparkId:(NSString *)sparkId;
- (void)setSignalingConnection:(CineSignalingConnection *)signalingConnection;

- (BOOL)supportsTrickleIce;

- (void) markIceComplete;
- (void)setRemoteAnswerAndSetIfIceIsComplete:(NSString *)remoteAnswer;

- (void)localDescriptionReady;
- (NSString *)getSparkId;

- (void)setSparkUUID:(NSString *)sparkUUID;
Expand Down
37 changes: 37 additions & 0 deletions cineio-peer-ios/cineio-peer-ios/CineRTCMember.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#import "CineRemoteAnswerSDPObserver.h"
#import "CineRTCHelper.h"
#import "RTCSessionDescription.h"
#import "CineSignalingConnection.h"

// WebRTC includes
#import "RTCPeerConnection.h"
Expand All @@ -25,8 +26,11 @@ @interface CineRTCMember ()
@property (nonatomic, strong) RTCPeerConnection* peerConnection;
@property (nonatomic, strong) CinePeerObserver* peerObserver;
@property (nonatomic, strong) NSString* remoteAnswer;
@property (nonatomic, strong) NSDictionary* support;
@property (nonatomic, strong) CineSignalingConnection* signalingConnection;

@property BOOL iceGatheringComplete;
@property BOOL waitingToSendLocalDescription;

@end

Expand All @@ -37,13 +41,41 @@ @implementation CineRTCMember
@synthesize sparkUUID;
@synthesize peerConnection;
@synthesize peerObserver;
@synthesize support;
@synthesize signalingConnection;

- (void)markIceComplete
{
self.iceGatheringComplete = true;
if (self.remoteAnswer){
NSLog(@"markIceComplete remoteAnswer");
[self setAnswerOnPeerConnection];
}
if (self.waitingToSendLocalDescription) {
NSLog(@"markIceComplete waitingToSendLocalDescription");
[self sendLocalDescription];
}
}

- (void)localDescriptionReady
{
if ([self supportsTrickleIce]) {
NSLog(@"localDescriptionReady supports trickleIce");
[self sendLocalDescription];
} else if (self.iceGatheringComplete) {
NSLog(@"localDescriptionReady sending because iceGatheringComplete");
[self sendLocalDescription];
} else {
self.waitingToSendLocalDescription = true;
NSLog(@"localDescriptionReady waiting for iceGatheringComplete");
}

}

- (void)sendLocalDescription
{
RTCSessionDescription* localDescription = [self.peerConnection localDescription];
[self.signalingConnection sendLocalDescription:self.sparkId description:localDescription];
}

- (void)setRemoteAnswerAndSetIfIceIsComplete:(NSString *)remoteAnswer
Expand Down Expand Up @@ -81,6 +113,11 @@ - (void)setAnswerOnPeerConnection

}

- (BOOL)supportsTrickleIce
{
return self.support[@"trickleIce"] != NO;
}

- (NSString *)getSparkId
{
return self.sparkId;
Expand Down
10 changes: 5 additions & 5 deletions cineio-peer-ios/cineio-peer-ios/CineSignalingConnection.m
Original file line number Diff line number Diff line change
Expand Up @@ -229,17 +229,17 @@ - (void)rejectCall:(NSString *)roomName
// Signaling callbacks
- (void)handleIce:(NSDictionary *)message
{
[self.peerConnectionManager handleIce:message[@"sparkUUID"] otherClientSparkId:message[@"sparkId"] iceCandidate:message[@"offer"]];
[self.peerConnectionManager handleIce:message[@"sparkUUID"] otherClientSparkId:message[@"sparkId"] iceCandidate:message[@"offer"] support:message[@"support"]];
}

- (void)handleOffer:(NSDictionary *)message
{
[self.peerConnectionManager handleOffer:message[@"sparkUUID"] otherClientSparkId:message[@"sparkId"] offer:message[@"offer"]];
[self.peerConnectionManager handleOffer:message[@"sparkUUID"] otherClientSparkId:message[@"sparkId"] offer:message[@"offer"] support:message[@"support"]];
}

- (void)handleAnswer:(NSDictionary *)message
{
[self.peerConnectionManager handleAnswer:message[@"sparkUUID"] otherClientSparkId:message[@"sparkId"] answer:message[@"answer"]];
[self.peerConnectionManager handleAnswer:message[@"sparkUUID"] otherClientSparkId:message[@"sparkId"] answer:message[@"answer"] support:message[@"support"]];
}

- (void)handleError:(NSDictionary *)message
Expand All @@ -253,7 +253,7 @@ - (void)roomJoin:(NSDictionary *)message
{
NSString* otherClientSparkId = message[@"sparkId"];
NSString* otherClientSparkUUID = message[@"sparkUUID"];
[self.peerConnectionManager ensurePeerConnection:otherClientSparkUUID otherClientSparkId:otherClientSparkId offer:true];
[self.peerConnectionManager ensurePeerConnection:otherClientSparkUUID otherClientSparkId:otherClientSparkId offer:true support:message[@"support"]];
[self sendToOtherSpark:otherClientSparkId data:@{@"action": @"room-announce", @"room": message[@"room"]}];

}
Expand All @@ -271,7 +271,7 @@ - (void)roomAnnounce:(NSDictionary *)message
{
NSString* otherClientSparkId = message[@"sparkId"];
NSString* otherClientSparkUUID = message[@"sparkUUID"];
[self.peerConnectionManager ensurePeerConnection:otherClientSparkUUID otherClientSparkId:otherClientSparkId offer:false];
[self.peerConnectionManager ensurePeerConnection:otherClientSparkUUID otherClientSparkId:otherClientSparkId offer:false support:message[@"support"]];
}

- (void)roomGoodbye:(NSDictionary *)message
Expand Down

0 comments on commit 142db75

Please sign in to comment.