diff --git a/cineio-peer-ios/cineio-peer-ios/CineLocalAnswerSDPObserver.m b/cineio-peer-ios/cineio-peer-ios/CineLocalAnswerSDPObserver.m index 182c21e..10023d4 100644 --- a/cineio-peer-ios/cineio-peer-ios/CineLocalAnswerSDPObserver.m +++ b/cineio-peer-ios/cineio-peer-ios/CineLocalAnswerSDPObserver.m @@ -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. diff --git a/cineio-peer-ios/cineio-peer-ios/CineLocalOfferSDPObserver.m b/cineio-peer-ios/cineio-peer-ios/CineLocalOfferSDPObserver.m index efc43b7..b4730c0 100644 --- a/cineio-peer-ios/cineio-peer-ios/CineLocalOfferSDPObserver.m +++ b/cineio-peer-ios/cineio-peer-ios/CineLocalOfferSDPObserver.m @@ -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 { @@ -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 diff --git a/cineio-peer-ios/cineio-peer-ios/CinePeerConnectionManager.h b/cineio-peer-ios/cineio-peer-ios/CinePeerConnectionManager.h index 3243bb1..9eb5f63 100644 --- a/cineio-peer-ios/cineio-peer-ios/CinePeerConnectionManager.h +++ b/cineio-peer-ios/cineio-peer-ios/CinePeerConnectionManager.h @@ -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 diff --git a/cineio-peer-ios/cineio-peer-ios/CinePeerConnectionManager.m b/cineio-peer-ios/cineio-peer-ios/CinePeerConnectionManager.m index de45604..5d916fd 100644 --- a/cineio-peer-ios/cineio-peer-ios/CinePeerConnectionManager.m +++ b/cineio-peer-ios/cineio-peer-ios/CinePeerConnectionManager.m @@ -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"); @@ -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]; @@ -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"); @@ -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]; @@ -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"); diff --git a/cineio-peer-ios/cineio-peer-ios/CinePeerObserver.m b/cineio-peer-ios/cineio-peer-ios/CinePeerObserver.m index 880b948..1d0cce3 100644 --- a/cineio-peer-ios/cineio-peer-ios/CinePeerObserver.m +++ b/cineio-peer-ios/cineio-peer-ios/CinePeerObserver.m @@ -13,6 +13,7 @@ #import "CineSignalingConnection.h" #import "RTCMediaStream.h" #import "RTCPeerConnectionDelegate.h" +#import "RTCPeerConnection.h" @interface CinePeerObserver () @property (nonatomic, weak) CineRTCMember* rtcMember; @@ -132,6 +133,7 @@ - (void)peerConnection:(RTCPeerConnection *)peerConnection { NSLog(@"iceGatheringChanged"); if (newState == RTCICEGatheringComplete) { +// peerConnection.localDescription NSLog(@"iceGatheringChanged complete"); [self.rtcMember markIceComplete]; } @@ -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(), ^{ diff --git a/cineio-peer-ios/cineio-peer-ios/CineRTCMember.h b/cineio-peer-ios/cineio-peer-ios/CineRTCMember.h index 0f31eca..0e853bd 100644 --- a/cineio-peer-ios/cineio-peer-ios/CineRTCMember.h +++ b/cineio-peer-ios/cineio-peer-ios/CineRTCMember.h @@ -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; diff --git a/cineio-peer-ios/cineio-peer-ios/CineRTCMember.m b/cineio-peer-ios/cineio-peer-ios/CineRTCMember.m index 82fd6ea..71c6451 100644 --- a/cineio-peer-ios/cineio-peer-ios/CineRTCMember.m +++ b/cineio-peer-ios/cineio-peer-ios/CineRTCMember.m @@ -13,6 +13,7 @@ #import "CineRemoteAnswerSDPObserver.h" #import "CineRTCHelper.h" #import "RTCSessionDescription.h" +#import "CineSignalingConnection.h" // WebRTC includes #import "RTCPeerConnection.h" @@ -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 @@ -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 @@ -81,6 +113,11 @@ - (void)setAnswerOnPeerConnection } +- (BOOL)supportsTrickleIce +{ + return self.support[@"trickleIce"] != NO; +} + - (NSString *)getSparkId { return self.sparkId; diff --git a/cineio-peer-ios/cineio-peer-ios/CineSignalingConnection.m b/cineio-peer-ios/cineio-peer-ios/CineSignalingConnection.m index c51a168..727206d 100644 --- a/cineio-peer-ios/cineio-peer-ios/CineSignalingConnection.m +++ b/cineio-peer-ios/cineio-peer-ios/CineSignalingConnection.m @@ -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 @@ -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"]}]; } @@ -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