Skip to content

Commit

Permalink
Removed libjingle_peerconnection pod; added WebRTC library; added Dat…
Browse files Browse the repository at this point in the history
…aChannel support (currently not working)
  • Loading branch information
Massimo Milazzo authored and Massimo Milazzo committed Jul 29, 2016
1 parent d0ea957 commit 4da72cf
Show file tree
Hide file tree
Showing 69 changed files with 2,179 additions and 394 deletions.
3 changes: 2 additions & 1 deletion Classes/Room/NBMRoom.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,12 @@ typedef NS_ENUM(NSInteger, NBMRoomErrorCode) {

@interface NBMRoom : NSObject

- (instancetype)initWithUsername:(NSString *)username roomName:(NSString *)name roomURL:(NSURL *)url;
- (instancetype)initWithUsername:(NSString *)username roomName:(NSString *)name roomURL:(NSURL *)url dataChannels:(BOOL)dataChannels;

@property (nonatomic, copy, readonly) NSString *name;
@property (nonatomic, strong, readonly) NSURL *url;
@property (nonatomic, copy, readonly) NBMPeer *localPeer;
@property (nonatomic, strong, readonly) NSSet *peers;
@property (nonatomic, assign, readonly) BOOL dataChannels;

@end
3 changes: 2 additions & 1 deletion Classes/Room/NBMRoom.m
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ @interface NBMRoom ()

@implementation NBMRoom

- (instancetype)initWithUsername:(NSString *)username roomName:(NSString *)name roomURL:(NSURL *)url {
- (instancetype)initWithUsername:(NSString *)username roomName:(NSString *)name roomURL:(NSURL *)url dataChannels:(BOOL)dataChannels {
NSParameterAssert(username);
NSParameterAssert(name);
NSParameterAssert(url);
Expand All @@ -42,6 +42,7 @@ - (instancetype)initWithUsername:(NSString *)username roomName:(NSString *)name
_localPeer = [[NBMPeer alloc] initWithId:username];
_name = name;
_url = url;
_dataChannels = dataChannels;
}
return self;
}
Expand Down
10 changes: 7 additions & 3 deletions Classes/Room/NBMRoomClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

@class NBMRoom;
@class NBMPeer;
@class RTCICECandidate;
@class RTCIceCandidate;
@protocol NBMRoomClientDelegate;

/**
Expand Down Expand Up @@ -127,6 +127,8 @@ typedef NS_ENUM(NSInteger, NBMRoomClientConnectionState) {
*/
- (void)joinRoom;

- (void)joinRoomWithDataChannels:(BOOL)dataChannels;

/**
* Represents a client's request to join a room. If the room does not exists, it is created.
* @note No message is sent to client's delegate.
Expand All @@ -135,6 +137,8 @@ typedef NS_ENUM(NSInteger, NBMRoomClientConnectionState) {
*/
- (void)joinRoom:(void (^)(NSSet *peers, NSError *error))block;

- (void)joinRoom:(void (^)(NSSet *peers, NSError *error))completionBlock dataChannels:(BOOL)dataChannels;

/**
* Represent a client's notification that it's leaving the room.
* When the request is processed, the [NBMRoomClientDelegate client:didLeaveRoom:] message is sent to the client's delegate.
Expand Down Expand Up @@ -226,7 +230,7 @@ typedef NS_ENUM(NSInteger, NBMRoomClientConnectionState) {
* @param candidate The RTCICECandidate object to send.
* @param peer The NBMPeer whose ICE candidate was found.
*/
- (void)sendICECandidate:(RTCICECandidate *)candidate forPeer:(NBMPeer *)peer;
- (void)sendICECandidate:(RTCIceCandidate *)candidate forPeer:(NBMPeer *)peer;

/**
* Request that carries info about an ICE candidate gathered on the client side. This information is required to implement the trickle ICE mechanism.
Expand All @@ -236,7 +240,7 @@ typedef NS_ENUM(NSInteger, NBMRoomClientConnectionState) {
* @param peer The NBMPeer whose ICE candidate was found.
* @param block A block object to be executed when the request is processed. This block has no return value and takes an error if the request failed.
*/
- (void)sendICECandidate:(RTCICECandidate *)candidate forPeer:(NBMPeer *)peer completion:(void (^)(NSError *error))block;
- (void)sendICECandidate:(RTCIceCandidate *)candidate forPeer:(NBMPeer *)peer completion:(void (^)(NSError *error))block;

/**
* Represents a client's request to send written message to all other participants in the room.
Expand Down
35 changes: 23 additions & 12 deletions Classes/Room/NBMRoomClient.m
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

#import "NBMLog.h"

#import <libjingle_peerconnection/RTCICECandidate.h>
#import <WebRTC/RTCIceCandidate.h>

//CLIENT REQUESTS

Expand All @@ -53,6 +53,7 @@
static NSString* const kJoinRoomMethod = @"joinRoom";
static NSString* const kJoinRoomUserParam = @"user";
static NSString* const kJoinRoomParam = @"room";
static NSString* const kJoinDataChannelsParam = @"dataChannels";
static NSString* const kJoinRoomPeerIdParam = @"id";
static NSString* const kJoinRoomPeerStreamsParam = @"streams";
static NSString* const kJoinRoomPeerStramIdParam = @"id";
Expand Down Expand Up @@ -204,16 +205,24 @@ - (NBMRoomClientConnectionState)connectionState {

#pragma mark Join room

- (void)joinRoom:(JoinRoomBlock)completionBlock dataChannels:(BOOL)dataChannels {
return [self nbm_joinRoom:self.room.name username:self.room.localPeer.identifier dataChannels:dataChannels completion:completionBlock];
}

- (void)joinRoom:(JoinRoomBlock)completionBlock {
return [self nbm_joinRoom:self.room.name username:self.room.localPeer.identifier completion:completionBlock];
[self joinRoom:completionBlock dataChannels:NO];
}

- (void)joinRoom {
- (void)joinRoomWithDataChannels:(BOOL)dataChannels {
return [self joinRoom:^(NSSet *peers, NSError *error) {
if ([self.delegate respondsToSelector:@selector(client:didJoinRoom:)]) {
[self.delegate client:self didJoinRoom:error];
}
}];
} dataChannels:dataChannels];
}

- (void)joinRoom {
[self joinRoomWithDataChannels:NO];
}

#pragma mark Leave room
Expand Down Expand Up @@ -290,15 +299,15 @@ - (void)unsubscribeVideoFromPeer:(NBMPeer *)peer completion:(void (^)(NSString *

#pragma mark Send ICE candidate

- (void)sendICECandidate:(RTCICECandidate *)candidate forPeer:(NBMPeer *)peer {
- (void)sendICECandidate:(RTCIceCandidate *)candidate forPeer:(NBMPeer *)peer {
return [self sendICECandidate:candidate forPeer:peer completion:^(NSError *error) {
if ([self.delegate respondsToSelector:@selector(client:didSentICECandidate:forPeer:)]) {
[self.delegate client:self didSentICECandidate:error forPeer:peer];
}
}];
}

- (void)sendICECandidate:(RTCICECandidate *)candidate forPeer:(NBMPeer *)peer completion:(void (^)(NSError *))block {
- (void)sendICECandidate:(RTCIceCandidate *)candidate forPeer:(NBMPeer *)peer completion:(void (^)(NSError *))block {
[self nbm_sendICECandidate:candidate forPeer:peer completion:block];
}

Expand Down Expand Up @@ -342,10 +351,11 @@ - (void)setupRpcClient:(NSTimeInterval)timeout {

#pragma mark Join room

- (void)nbm_joinRoom:(NSString *)roomName username:(NSString *)username completion:(JoinRoomBlock)block {
- (void)nbm_joinRoom:(NSString *)roomName username:(NSString *)username dataChannels:(BOOL)dataChannels completion:(JoinRoomBlock)block {
[self.jsonRpcClient sendRequestWithMethod:kJoinRoomMethod
parameters:@{kJoinRoomParam: roomName ?: @"",
kJoinRoomUserParam: username ?: @""}
kJoinRoomUserParam: username ?: @"",
kJoinDataChannelsParam: dataChannels ? @YES : @NO}
completion:^(NBMResponse *response) {
NSError *error;
NSSet *peers = [self peersFromResponse:response error:&error];
Expand All @@ -357,9 +367,10 @@ - (void)nbm_joinRoom:(NSString *)roomName username:(NSString *)username completi
if (block) {
block (peers, error);
}
}];
}];
}


- (NSSet *)peersFromResponse:(NBMResponse *)response error:(NSError **)error {
NSMutableDictionary *peers;
id result = response.result;
Expand Down Expand Up @@ -521,7 +532,7 @@ - (void)nbm_unsubscribeVideoFormPeer:(NBMPeer *)peer completion:(void (^)(NSStri

#pragma mark Send ICE candidate

- (void)nbm_sendICECandidate:(RTCICECandidate *)candidate forPeer:(NBMPeer *)peer completion:(void (^)(NSError *error))block {
- (void)nbm_sendICECandidate:(RTCIceCandidate *)candidate forPeer:(NBMPeer *)peer completion:(void (^)(NSError *error))block {
NSDictionary *params = @{kOnIceCandidateEpnameParam: peer.identifier,
kOnIceCandidateCandidateParam: candidate.sdp ?: @"",
kOnIceCandidateSdpMidParam: candidate.sdpMid ?: @"",
Expand Down Expand Up @@ -680,9 +691,9 @@ - (void)iceCandidateReceived:(id)params {
NSString *sdpMid = [NBMRoomClient element:params getStringPropertyWithName:kIceCandidateSdpMidParam error:&error];
NSString *sdp = [NBMRoomClient element:params getStringPropertyWithName:kIceCandidateCandidateParam error:&error];
NSNumber *sdpMLineIndexNumber = [NBMRoomClient element:params getPropertyWithName:kIceCandidateSdpMLineIndex ofClass:[NSNumber class] error:&error];
RTCICECandidate *candidate;
RTCIceCandidate *candidate;
if (sdpMid && sdp && sdpMLineIndexNumber) {
candidate = [[RTCICECandidate alloc] initWithMid:sdpMid index:sdpMLineIndexNumber.integerValue sdp:sdp];
candidate = [[RTCIceCandidate alloc] initWithSdp:sdp sdpMLineIndex:[sdpMLineIndexNumber intValue] sdpMid:sdpMid];
}
if ([self.delegate respondsToSelector:@selector(client:didReceiveICECandidate:fromParticipant:)]) {
[self.delegate client:self didReceiveICECandidate:candidate fromParticipant:peer];
Expand Down
2 changes: 1 addition & 1 deletion Classes/Room/NBMRoomClientDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
- (void)client:(NBMRoomClient *)client participantPublished:(NBMPeer *)peer;
- (void)client:(NBMRoomClient *)client participantUnpublished:(NBMPeer *)peer;

- (void)client:(NBMRoomClient *)client didReceiveICECandidate:(RTCICECandidate *)candidate fromParticipant:(NBMPeer *)peer;
- (void)client:(NBMRoomClient *)client didReceiveICECandidate:(RTCIceCandidate *)candidate fromParticipant:(NBMPeer *)peer;

- (void)client:(NBMRoomClient *)client didReceiveMessage:(NSString *)message fromParticipant:(NBMPeer *)peer;
- (void)client:(NBMRoomClient *)client mediaErrorOccurred:(NSError *)error;
Expand Down
4 changes: 2 additions & 2 deletions Classes/Tree/NBMTreeClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#import <Foundation/Foundation.h>

@class NBMJSONRPCClient;
@class RTCICECandidate;
@class RTCIceCandidate;
@class NBMTreeEndpoint;
@protocol NBMTreeClientDelegate;

Expand Down Expand Up @@ -184,6 +184,6 @@ typedef NS_ENUM(NSInteger, NBMTreeMode) {
* @param treeId Tree id to which belongs this candidate.
* @param block A block object to be executed when the request is processed. This block has no return value and takes an error if the request failed.
*/
- (void)sendICECandidate:(RTCICECandidate *)candidate forSink:(NSString *)sinkId tree:(NSString *)treeId completion:(void(^)(NSError *error))block;
- (void)sendICECandidate:(RTCIceCandidate *)candidate forSink:(NSString *)sinkId tree:(NSString *)treeId completion:(void(^)(NSError *error))block;

@end
10 changes: 5 additions & 5 deletions Classes/Tree/NBMTreeClient.m
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
#import "NBMRequest.h"
#import "NBMResponse.h"

#import <libjingle_peerconnection/RTCICECandidate.h>
#import <WebRTC/RTCIceCandidate.h>

static NSString* const kAddICECandidateMethod = @"addIceCandidate";
static NSString* const kICECandidateEvent = @"iceCandidate";
Expand Down Expand Up @@ -180,7 +180,7 @@ - (void)removeSink:(NSString *)sinkId tree:(NSString *)treeId completion:(void (
}];
}

- (void)sendICECandidate:(RTCICECandidate *)candidate forSink:(NSString *)sinkId tree:(NSString *)treeId completion:(void (^)(NSError *))block {
- (void)sendICECandidate:(RTCIceCandidate *)candidate forSink:(NSString *)sinkId tree:(NSString *)treeId completion:(void (^)(NSError *))block {
NSParameterAssert(candidate);
NSParameterAssert(treeId);
return [self nbm_sendICECandidate:candidate forSink:sinkId tree:treeId completion:block];
Expand Down Expand Up @@ -310,7 +310,7 @@ - (void)nbm_removeSink:(NSString *)sinkId tree:(NSString *)treeId completion:(vo
}];
}

- (void)nbm_sendICECandidate:(RTCICECandidate *)candidate forSink:(NSString *)sinkId tree:(NSString *)treeId completion:(void(^)(NSError *error))block {
- (void)nbm_sendICECandidate:(RTCIceCandidate *)candidate forSink:(NSString *)sinkId tree:(NSString *)treeId completion:(void(^)(NSError *error))block {
NSMutableDictionary *params = [NSMutableDictionary dictionary];
[params setObject:treeId forKey:kTreeId];
if (sinkId.length > 0) {
Expand Down Expand Up @@ -430,9 +430,9 @@ - (void)iceCandidateReceived:(id)params {
NSString *sdp = [NBMTreeClient element:params getStringPropertyWithName:kICECandidate error:&error];
NSString *sdpMid = [NBMTreeClient element:params getStringPropertyWithName:kICESdpMid error:&error];
NSNumber *index = [NBMTreeClient element:params getPropertyWithName:kICESdpMLineIndex ofClass:[NSNumber class] error:&error];
RTCICECandidate *candidate;
RTCIceCandidate *candidate;
if (!error) {
candidate = [[RTCICECandidate alloc] initWithMid:sdpMid index:index.integerValue sdp:sdp];
candidate = [[RTCIceCandidate alloc] initWithSdp:sdp sdpMLineIndex:index.integerValue sdpMid:sdpMid];
}

NSString *treeId = [NBMTreeClient element:params getStringPropertyWithName:kTreeId error:&error];
Expand Down
4 changes: 2 additions & 2 deletions Classes/Tree/NBMTreeClientDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#import <Foundation/Foundation.h>

@class NBMTreeClient;
@class RTCICECandidate;
@class RTCIceCandidate;

@protocol NBMTreeClientDelegate <NSObject>

Expand All @@ -42,6 +42,6 @@
* @param sinkId Sink id to which belongs the candidate, 'nil' when the candidate is referred to the tree source.
* @param treeId Tree id to which belongs this candidate.
*/
- (void)client:(NBMTreeClient *)client iceCandidateReceived:(RTCICECandidate *)candidate ofSink:(NSString *)sinkId tree:(NSString *)treeId;
- (void)client:(NBMTreeClient *)client iceCandidateReceived:(RTCIceCandidate *)candidate ofSink:(NSString *)sinkId tree:(NSString *)treeId;

@end
47 changes: 23 additions & 24 deletions Classes/WebRTC/Internals/NBMSessionDescriptionFactory.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@

#import "NBMSessionDescriptionFactory.h"

#import "RTCMediaConstraints.h"
#import "RTCPair.h"
#import "RTCSessionDescription.h"
#import <WebRTC/RTCMediaConstraints.h>
#import <WebRTC/RTCSessionDescription.h>

@implementation NBMSessionDescriptionFactory

Expand All @@ -21,11 +20,10 @@ + (RTCMediaConstraints *)offerConstraints {
+ (RTCMediaConstraints *)offerConstraintsRestartIce:(BOOL)restartICE;
{
// In the AppRTC example optional offer contraints are nil
NSArray *optional = nil;
NSMutableDictionary *optional = [NSMutableDictionary dictionaryWithDictionary:[self optionalConstraints]];

if (restartICE) {
RTCPair *icePair = [[RTCPair alloc] initWithKey:@"IceRestart" value:@"true"];
optional = @[icePair];
[optional setObject:@"true" forKey:@"IceRestart"];
}

RTCMediaConstraints *constraints = [[RTCMediaConstraints alloc] initWithMandatoryConstraints:[self mandatoryConstraints]
Expand Down Expand Up @@ -59,10 +57,10 @@ + (RTCSessionDescription *)conditionedSessionDescription:(RTCSessionDescription
// Audio

if (audioCodec == NBMAudioCodecOpus) {
sdpString = sessionDescription.description;
sdpString = sessionDescription.sdp;
}
else {
sdpString = [self preferISACSimple:sessionDescription.description];
sdpString = [self preferISACSimple:sessionDescription.sdp];
}

// Video
Expand All @@ -83,29 +81,30 @@ + (RTCSessionDescription *)conditionedSessionDescription:(RTCSessionDescription

#pragma mark - Private

+ (NSArray *)constraintsForVideoFormat:(NBMVideoFormat)format
+ (NSDictionary *)constraintsForVideoFormat:(NBMVideoFormat)format
{
RTCPair *maxWidth = [[RTCPair alloc] initWithKey:@"maxWidth" value:[NSString stringWithFormat:@"%d", format.dimensions.width]];
RTCPair *maxHeight = [[RTCPair alloc] initWithKey:@"maxHeight" value:[NSString stringWithFormat:@"%d", format.dimensions.height]];
RTCPair *minWidth = [[RTCPair alloc] initWithKey:@"minWidth" value:@"240"];
RTCPair *minHeight = [[RTCPair alloc] initWithKey:@"minHeight" value:@"160"];

return @[maxWidth, maxHeight, minWidth, minHeight];
return @{
@"maxWidth": [NSString stringWithFormat:@"%d", format.dimensions.width],
@"maxHeight": [NSString stringWithFormat:@"%d", format.dimensions.height],
@"minWidth": @"240",
@"minHeight": @"160"
};
}

+ (NSArray *)mandatoryConstraints
+ (NSDictionary *)mandatoryConstraints
{
RTCPair *audioPair = [[RTCPair alloc] initWithKey:@"OfferToReceiveAudio" value:@"true"];
RTCPair *videoPair = [[RTCPair alloc] initWithKey:@"OfferToReceiveVideo" value:@"true"];

return @[ audioPair, videoPair ];
return @{
@"OfferToReceiveAudio": @"true",
@"OfferToReceiveVideo": @"true"
};
}

+ (NSArray *)optionalConstraints
+ (NSDictionary *)optionalConstraints
{
//[[RTCPair alloc] initWithKey:@"internalSctpDataChannels" value:@"true"] ??
NSArray *optionalConstraints = @[[[RTCPair alloc] initWithKey:@"DtlsSrtpKeyAgreement" value:@"true"]];
return optionalConstraints;
return @{
@"internalSctpDataChannels": @"true",
@"DtlsSrtpKeyAgreement": @"true"
};
}

+ (NSString *)preferISACSimple:(NSString *)sdp
Expand Down
2 changes: 1 addition & 1 deletion Classes/WebRTC/Internals/RTCMediaStream+Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

#import "RTCMediaStream.h"
#import <WebRTC/RTCMediaStream.h>

@interface RTCMediaStream (Configuration)

Expand Down
8 changes: 4 additions & 4 deletions Classes/WebRTC/Internals/RTCMediaStream+Configuration.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
// THE SOFTWARE.

#import "RTCMediaStream+Configuration.h"
#import "RTCAudioTrack.h"
#import "RTCVideoTrack.h"
#import <WebRTC/RTCAudioTrack.h>
#import <WebRTC/RTCVideoTrack.h>

@implementation RTCMediaStream (Configuration)

Expand All @@ -35,7 +35,7 @@ - (BOOL)isAudioEnabled
- (void)setAudioEnabled:(BOOL)audioEnabled
{
RTCAudioTrack *audioTrack = [self.audioTracks firstObject];
[audioTrack setEnabled:audioEnabled];
[audioTrack setIsEnabled:audioEnabled];
}

- (BOOL)isVideoEnabled
Expand All @@ -47,7 +47,7 @@ - (BOOL)isVideoEnabled
- (void)setVideoEnabled:(BOOL)videoEnabled
{
RTCVideoTrack *videoTrack = [self.videoTracks firstObject];
[videoTrack setEnabled:videoEnabled];
[videoTrack setIsEnabled:videoEnabled];
}


Expand Down
Loading

0 comments on commit 4da72cf

Please sign in to comment.