Objective-C readability review.

BUG=
R=rsesek@chromium.org

Review URL: https://webrtc-codereview.appspot.com/34679004

Cr-Commit-Position: refs/heads/master@{#8784}
git-svn-id: http://webrtc.googlecode.com/svn/trunk@8784 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
tkchin@webrtc.org
2015-03-18 23:38:04 +00:00
parent 2a8a46dacb
commit 8cc47e926c
5 changed files with 59 additions and 28 deletions

View File

@ -38,6 +38,7 @@
@interface ARDAppClient () <ARDSignalingChannelDelegate, @interface ARDAppClient () <ARDSignalingChannelDelegate,
RTCPeerConnectionDelegate, RTCSessionDescriptionDelegate> RTCPeerConnectionDelegate, RTCSessionDescriptionDelegate>
// All properties should only be mutated from the main queue.
@property(nonatomic, strong) id<ARDRoomServerClient> roomServerClient; @property(nonatomic, strong) id<ARDRoomServerClient> roomServerClient;
@property(nonatomic, strong) id<ARDSignalingChannel> channel; @property(nonatomic, strong) id<ARDSignalingChannel> channel;
@property(nonatomic, strong) id<ARDTURNClient> turnClient; @property(nonatomic, strong) id<ARDTURNClient> turnClient;

View File

@ -39,6 +39,8 @@ typedef NS_ENUM(NSInteger, ARDAppClientState) {
}; };
@class ARDAppClient; @class ARDAppClient;
// The delegate is informed of pertinent events and will be called on the
// main queue.
@protocol ARDAppClientDelegate <NSObject> @protocol ARDAppClientDelegate <NSObject>
- (void)appClient:(ARDAppClient *)client - (void)appClient:(ARDAppClient *)client
@ -58,12 +60,15 @@ typedef NS_ENUM(NSInteger, ARDAppClientState) {
@end @end
// Handles connections to the AppRTC server for a given room. // Handles connections to the AppRTC server for a given room. Methods on this
// class should only be called from the main queue.
@interface ARDAppClient : NSObject @interface ARDAppClient : NSObject
@property(nonatomic, readonly) ARDAppClientState state; @property(nonatomic, readonly) ARDAppClientState state;
@property(nonatomic, weak) id<ARDAppClientDelegate> delegate; @property(nonatomic, weak) id<ARDAppClientDelegate> delegate;
// Convenience constructor since all expected use cases will need a delegate
// in order to receive remote tracks.
- (instancetype)initWithDelegate:(id<ARDAppClientDelegate>)delegate; - (instancetype)initWithDelegate:(id<ARDAppClientDelegate>)delegate;
// Establishes a connection with the AppRTC servers for the given room id. // Establishes a connection with the AppRTC servers for the given room id.

View File

@ -45,20 +45,20 @@
#import "RTCVideoCapturer.h" #import "RTCVideoCapturer.h"
#import "RTCVideoTrack.h" #import "RTCVideoTrack.h"
static NSString *kARDDefaultSTUNServerUrl = static NSString * const kARDDefaultSTUNServerUrl =
@"stun:stun.l.google.com:19302"; @"stun:stun.l.google.com:19302";
// TODO(tkchin): figure out a better username for CEOD statistics. // TODO(tkchin): figure out a better username for CEOD statistics.
static NSString *kARDTurnRequestUrl = static NSString * const kARDTurnRequestUrl =
@"https://computeengineondemand.appspot.com" @"https://computeengineondemand.appspot.com"
@"/turn?username=iapprtc&key=4080218913"; @"/turn?username=iapprtc&key=4080218913";
static NSString *kARDAppClientErrorDomain = @"ARDAppClient"; static NSString * const kARDAppClientErrorDomain = @"ARDAppClient";
static NSInteger kARDAppClientErrorUnknown = -1; static NSInteger const kARDAppClientErrorUnknown = -1;
static NSInteger kARDAppClientErrorRoomFull = -2; static NSInteger const kARDAppClientErrorRoomFull = -2;
static NSInteger kARDAppClientErrorCreateSDP = -3; static NSInteger const kARDAppClientErrorCreateSDP = -3;
static NSInteger kARDAppClientErrorSetSDP = -4; static NSInteger const kARDAppClientErrorSetSDP = -4;
static NSInteger kARDAppClientErrorInvalidClient = -5; static NSInteger const kARDAppClientErrorInvalidClient = -5;
static NSInteger kARDAppClientErrorInvalidRoom = -6; static NSInteger const kARDAppClientErrorInvalidRoom = -6;
@implementation ARDAppClient @implementation ARDAppClient
@ -81,6 +81,16 @@ static NSInteger kARDAppClientErrorInvalidRoom = -6;
@synthesize defaultPeerConnectionConstraints = @synthesize defaultPeerConnectionConstraints =
_defaultPeerConnectionConstraints; _defaultPeerConnectionConstraints;
- (instancetype)init {
if (self = [super init]) {
_roomServerClient = [[ARDAppEngineClient alloc] init];
NSURL *turnRequestURL = [NSURL URLWithString:kARDTurnRequestUrl];
_turnClient = [[ARDCEODTURNClient alloc] initWithURL:turnRequestURL];
[self configure];
}
return self;
}
- (instancetype)initWithDelegate:(id<ARDAppClientDelegate>)delegate { - (instancetype)initWithDelegate:(id<ARDAppClientDelegate>)delegate {
if (self = [super init]) { if (self = [super init]) {
_roomServerClient = [[ARDAppEngineClient alloc] init]; _roomServerClient = [[ARDAppEngineClient alloc] init];
@ -219,6 +229,8 @@ static NSInteger kARDAppClientErrorInvalidRoom = -6;
switch (message.type) { switch (message.type) {
case kARDSignalingMessageTypeOffer: case kARDSignalingMessageTypeOffer:
case kARDSignalingMessageTypeAnswer: case kARDSignalingMessageTypeAnswer:
// Offers and answers must be processed before any other message, so we
// place them at the front of the queue.
_hasReceivedSdp = YES; _hasReceivedSdp = YES;
[_messageQueue insertObject:message atIndex:0]; [_messageQueue insertObject:message atIndex:0];
break; break;
@ -226,6 +238,7 @@ static NSInteger kARDAppClientErrorInvalidRoom = -6;
[_messageQueue addObject:message]; [_messageQueue addObject:message];
break; break;
case kARDSignalingMessageTypeBye: case kARDSignalingMessageTypeBye:
// Disconnects can be processed immediately.
[self processSignalingMessage:message]; [self processSignalingMessage:message];
return; return;
} }
@ -249,6 +262,8 @@ static NSInteger kARDAppClientErrorInvalidRoom = -6;
} }
#pragma mark - RTCPeerConnectionDelegate #pragma mark - RTCPeerConnectionDelegate
// Callbacks for this delegate occur on non-main thread and need to be
// dispatched back to main queue as needed.
- (void)peerConnection:(RTCPeerConnection *)peerConnection - (void)peerConnection:(RTCPeerConnection *)peerConnection
signalingStateChanged:(RTCSignalingState)stateChanged { signalingStateChanged:(RTCSignalingState)stateChanged {
@ -305,6 +320,8 @@ static NSInteger kARDAppClientErrorInvalidRoom = -6;
} }
#pragma mark - RTCSessionDescriptionDelegate #pragma mark - RTCSessionDescriptionDelegate
// Callbacks for this delegate occur on non-main thread and need to be
// dispatched back to main queue as needed.
- (void)peerConnection:(RTCPeerConnection *)peerConnection - (void)peerConnection:(RTCPeerConnection *)peerConnection
didCreateSessionDescription:(RTCSessionDescription *)sdp didCreateSessionDescription:(RTCSessionDescription *)sdp
@ -364,6 +381,11 @@ static NSInteger kARDAppClientErrorInvalidRoom = -6;
return _clientId.length; return _clientId.length;
} }
// Begins the peer connection connection process if we have both joined a room
// on the room server and tried to obtain a TURN server. Otherwise does nothing.
// A peer connection object will be created with a stream that contains local
// audio and video capture. If this client is the caller, an offer is created as
// well, otherwise the client will wait for an offer to arrive.
- (void)startSignalingIfReady { - (void)startSignalingIfReady {
if (!_isTurnComplete || !self.hasJoinedRoomServerRoom) { if (!_isTurnComplete || !self.hasJoinedRoomServerRoom) {
return; return;
@ -375,24 +397,24 @@ static NSInteger kARDAppClientErrorInvalidRoom = -6;
_peerConnection = [_factory peerConnectionWithICEServers:_iceServers _peerConnection = [_factory peerConnectionWithICEServers:_iceServers
constraints:constraints constraints:constraints
delegate:self]; delegate:self];
// Create AV media stream and add it to the peer connection.
RTCMediaStream *localStream = [self createLocalMediaStream]; RTCMediaStream *localStream = [self createLocalMediaStream];
[_peerConnection addStream:localStream]; [_peerConnection addStream:localStream];
if (_isInitiator) { if (_isInitiator) {
[self sendOffer]; // Send offer.
} else {
[self waitForAnswer];
}
}
- (void)sendOffer {
[_peerConnection createOfferWithDelegate:self [_peerConnection createOfferWithDelegate:self
constraints:[self defaultOfferConstraints]]; constraints:[self defaultOfferConstraints]];
} } else {
// Check if we've received an offer.
- (void)waitForAnswer {
[self drainMessageQueueIfReady]; [self drainMessageQueueIfReady];
} }
}
// Processes the messages that we've received from the room server and the
// signaling channel. The offer or answer message must be processed before other
// signaling messages, however they can arrive out of order. Hence, this method
// only processes pending messages if there is a peer connection object and
// if we have received either an offer or answer.
- (void)drainMessageQueueIfReady { - (void)drainMessageQueueIfReady {
if (!_peerConnection || !_hasReceivedSdp) { if (!_peerConnection || !_hasReceivedSdp) {
return; return;
@ -403,6 +425,7 @@ static NSInteger kARDAppClientErrorInvalidRoom = -6;
[_messageQueue removeAllObjects]; [_messageQueue removeAllObjects];
} }
// Processes the given signaling message based on its type.
- (void)processSignalingMessage:(ARDSignalingMessage *)message { - (void)processSignalingMessage:(ARDSignalingMessage *)message {
NSParameterAssert(_peerConnection || NSParameterAssert(_peerConnection ||
message.type == kARDSignalingMessageTypeBye); message.type == kARDSignalingMessageTypeBye);
@ -431,6 +454,9 @@ static NSInteger kARDAppClientErrorInvalidRoom = -6;
} }
} }
// Sends a signaling message to the other client. The caller will send messages
// through the room server, whereas the callee will send messages over the
// signaling channel.
- (void)sendSignalingMessage:(ARDSignalingMessage *)message { - (void)sendSignalingMessage:(ARDSignalingMessage *)message {
if (_isInitiator) { if (_isInitiator) {
__weak ARDAppClient *weakSelf = self; __weak ARDAppClient *weakSelf = self;

View File

@ -33,17 +33,17 @@
#import "ARDUtilities.h" #import "ARDUtilities.h"
// TODO(tkchin): move these to a configuration object. // TODO(tkchin): move these to a configuration object.
static NSString *kARDRoomServerHostUrl = static NSString * const kARDRoomServerHostUrl =
@"https://apprtc.appspot.com"; @"https://apprtc.appspot.com";
static NSString *kARDRoomServerJoinFormat = static NSString * const kARDRoomServerJoinFormat =
@"https://apprtc.appspot.com/join/%@"; @"https://apprtc.appspot.com/join/%@";
static NSString *kARDRoomServerMessageFormat = static NSString * const kARDRoomServerMessageFormat =
@"https://apprtc.appspot.com/message/%@/%@"; @"https://apprtc.appspot.com/message/%@/%@";
static NSString *kARDRoomServerLeaveFormat = static NSString * const kARDRoomServerLeaveFormat =
@"https://apprtc.appspot.com/leave/%@/%@"; @"https://apprtc.appspot.com/leave/%@/%@";
static NSString *kARDAppEngineClientErrorDomain = @"ARDAppEngineClient"; static NSString * const kARDAppEngineClientErrorDomain = @"ARDAppEngineClient";
static NSInteger kARDAppEngineClientErrorBadResponse = -1; static NSInteger const kARDAppEngineClientErrorBadResponse = -1;
@implementation ARDAppEngineClient @implementation ARDAppEngineClient

View File

@ -25,7 +25,6 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
#import <OCMock/OCMock.h> #import <OCMock/OCMock.h>