Update GAE API paths for join/leave.

BUG=4221
R=jiayl@webrtc.org

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

Cr-Commit-Position: refs/heads/master@{#8174}
git-svn-id: http://webrtc.googlecode.com/svn/trunk@8174 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
tkchin@webrtc.org 2015-01-27 21:34:39 +00:00
parent 8bb32d600b
commit 36401aba62
9 changed files with 99 additions and 98 deletions

View File

@ -48,7 +48,7 @@
@property(nonatomic, assign) BOOL isTurnComplete;
@property(nonatomic, assign) BOOL hasReceivedSdp;
@property(nonatomic, readonly) BOOL isRegisteredWithRoomServer;
@property(nonatomic, readonly) BOOL hasJoinedRoomServerRoom;
@property(nonatomic, strong) NSString *roomId;
@property(nonatomic, strong) NSString *clientId;

View File

@ -31,8 +31,8 @@
#import "ARDAppEngineClient.h"
#import "ARDCEODTURNClient.h"
#import "ARDJoinResponse.h"
#import "ARDMessageResponse.h"
#import "ARDRegisterResponse.h"
#import "ARDSignalingMessage.h"
#import "ARDUtilities.h"
#import "ARDWebSocketChannel.h"
@ -149,23 +149,23 @@ static NSInteger kARDAppClientErrorInvalidRoom = -6;
[strongSelf startSignalingIfReady];
}];
// Register with room server.
[_roomServerClient registerForRoomId:roomId
completionHandler:^(ARDRegisterResponse *response, NSError *error) {
// Join room on room server.
[_roomServerClient joinRoomWithRoomId:roomId
completionHandler:^(ARDJoinResponse *response, NSError *error) {
ARDAppClient *strongSelf = weakSelf;
if (error) {
[strongSelf.delegate appClient:strongSelf didError:error];
return;
}
NSError *registerError =
[[strongSelf class] errorForRegisterResultType:response.result];
if (registerError) {
NSLog(@"Failed to register with room server.");
NSError *joinError =
[[strongSelf class] errorForJoinResultType:response.result];
if (joinError) {
NSLog(@"Failed to join room:%@ on room server.", roomId);
[strongSelf disconnect];
[strongSelf.delegate appClient:strongSelf didError:registerError];
[strongSelf.delegate appClient:strongSelf didError:joinError];
return;
}
NSLog(@"Registered with room server.");
NSLog(@"Joined room:%@ on room server.", roomId);
strongSelf.roomId = response.roomId;
strongSelf.clientId = response.clientId;
strongSelf.isInitiator = response.isInitiator;
@ -189,8 +189,8 @@ static NSInteger kARDAppClientErrorInvalidRoom = -6;
if (_state == kARDAppClientStateDisconnected) {
return;
}
if (self.isRegisteredWithRoomServer) {
[_roomServerClient deregisterForRoomId:_roomId
if (self.hasJoinedRoomServerRoom) {
[_roomServerClient leaveRoomWithRoomId:_roomId
clientId:_clientId
completionHandler:nil];
}
@ -360,12 +360,12 @@ static NSInteger kARDAppClientErrorInvalidRoom = -6;
#pragma mark - Private
- (BOOL)isRegisteredWithRoomServer {
- (BOOL)hasJoinedRoomServerRoom {
return _clientId.length;
}
- (void)startSignalingIfReady {
if (!_isTurnComplete || !self.isRegisteredWithRoomServer) {
if (!_isTurnComplete || !self.hasJoinedRoomServerRoom) {
return;
}
self.state = kARDAppClientStateConnected;
@ -496,7 +496,7 @@ static NSInteger kARDAppClientErrorInvalidRoom = -6;
#pragma mark - Collider methods
- (void)registerWithColliderIfReady {
if (!self.isRegisteredWithRoomServer) {
if (!self.hasJoinedRoomServerRoom) {
return;
}
// Open WebSocket connection.
@ -558,12 +558,12 @@ static NSInteger kARDAppClientErrorInvalidRoom = -6;
#pragma mark - Errors
+ (NSError *)errorForRegisterResultType:(ARDRegisterResultType)resultType {
+ (NSError *)errorForJoinResultType:(ARDJoinResultType)resultType {
NSError *error = nil;
switch (resultType) {
case kARDRegisterResultTypeSuccess:
case kARDJoinResultTypeSuccess:
break;
case kARDRegisterResultTypeUnknown: {
case kARDJoinResultTypeUnknown: {
error = [[NSError alloc] initWithDomain:kARDAppClientErrorDomain
code:kARDAppClientErrorUnknown
userInfo:@{
@ -571,7 +571,7 @@ static NSInteger kARDAppClientErrorInvalidRoom = -6;
}];
break;
}
case kARDRegisterResultTypeFull: {
case kARDJoinResultTypeFull: {
error = [[NSError alloc] initWithDomain:kARDAppClientErrorDomain
code:kARDAppClientErrorRoomFull
userInfo:@{

View File

@ -27,20 +27,20 @@
#import "ARDAppEngineClient.h"
#import "ARDJoinResponse.h"
#import "ARDMessageResponse.h"
#import "ARDRegisterResponse.h"
#import "ARDSignalingMessage.h"
#import "ARDUtilities.h"
// TODO(tkchin): move these to a configuration object.
static NSString *kARDRoomServerHostUrl =
@"https://apprtc.appspot.com";
static NSString *kARDRoomServerRegisterFormat =
@"https://apprtc.appspot.com/register/%@";
static NSString *kARDRoomServerJoinFormat =
@"https://apprtc.appspot.com/join/%@";
static NSString *kARDRoomServerMessageFormat =
@"https://apprtc.appspot.com/message/%@/%@";
static NSString *kARDRoomServerByeFormat =
@"https://apprtc.appspot.com/bye/%@/%@";
static NSString *kARDRoomServerLeaveFormat =
@"https://apprtc.appspot.com/leave/%@/%@";
static NSString *kARDAppEngineClientErrorDomain = @"ARDAppEngineClient";
static NSInteger kARDAppEngineClientErrorBadResponse = -1;
@ -49,15 +49,15 @@ static NSInteger kARDAppEngineClientErrorBadResponse = -1;
#pragma mark - ARDRoomServerClient
- (void)registerForRoomId:(NSString *)roomId
completionHandler:(void (^)(ARDRegisterResponse *response,
NSError *error))completionHandler {
- (void)joinRoomWithRoomId:(NSString *)roomId
completionHandler:(void (^)(ARDJoinResponse *response,
NSError *error))completionHandler {
NSParameterAssert(roomId.length);
NSString *urlString =
[NSString stringWithFormat:kARDRoomServerRegisterFormat, roomId];
[NSString stringWithFormat:kARDRoomServerJoinFormat, roomId];
NSURL *roomURL = [NSURL URLWithString:urlString];
NSLog(@"Registering with room server.");
NSLog(@"Joining room:%@ on room server.", roomId);
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:roomURL];
request.HTTPMethod = @"POST";
__weak ARDAppEngineClient *weakSelf = self;
@ -72,9 +72,9 @@ static NSInteger kARDAppEngineClientErrorBadResponse = -1;
}
return;
}
ARDRegisterResponse *registerResponse =
[ARDRegisterResponse responseFromJSONData:data];
if (!registerResponse) {
ARDJoinResponse *joinResponse =
[ARDJoinResponse responseFromJSONData:data];
if (!joinResponse) {
if (completionHandler) {
NSError *error = [[self class] badResponseError];
completionHandler(nil, error);
@ -82,7 +82,7 @@ static NSInteger kARDAppEngineClientErrorBadResponse = -1;
return;
}
if (completionHandler) {
completionHandler(registerResponse, nil);
completionHandler(joinResponse, nil);
}
}];
}
@ -132,32 +132,33 @@ static NSInteger kARDAppEngineClientErrorBadResponse = -1;
}];
}
- (void)deregisterForRoomId:(NSString *)roomId
- (void)leaveRoomWithRoomId:(NSString *)roomId
clientId:(NSString *)clientId
completionHandler:(void (^)(NSError *error))completionHandler {
NSParameterAssert(roomId.length);
NSParameterAssert(clientId.length);
NSString *urlString =
[NSString stringWithFormat:kARDRoomServerByeFormat, roomId, clientId];
[NSString stringWithFormat:kARDRoomServerLeaveFormat, roomId, clientId];
NSURL *url = [NSURL URLWithString:urlString];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
NSURLResponse *response = nil;
NSError *error = nil;
// We want a synchronous request so that we know that we're unregistered from
// room server before we do any further unregistration.
// We want a synchronous request so that we know that we've left the room on
// room server before we do any further work.
NSLog(@"C->RS: BYE");
[NSURLConnection sendSynchronousRequest:request
returningResponse:&response
error:&error];
if (error) {
NSLog(@"Error unregistering from room server: %@", error);
NSLog(@"Error leaving room %@ on room server: %@",
roomId, error.localizedDescription);
if (completionHandler) {
completionHandler(error);
}
return;
}
NSLog(@"Unregistered from room server.");
NSLog(@"Left room:%@ on room server.", roomId);
if (completionHandler) {
completionHandler(nil);
}

View File

@ -25,11 +25,11 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#import "ARDRegisterResponse.h"
#import "ARDJoinResponse.h"
@interface ARDRegisterResponse ()
@interface ARDJoinResponse ()
@property(nonatomic, assign) ARDRegisterResultType result;
@property(nonatomic, assign) ARDJoinResultType result;
@property(nonatomic, assign) BOOL isInitiator;
@property(nonatomic, strong) NSString *roomId;
@property(nonatomic, strong) NSString *clientId;

View File

@ -27,16 +27,16 @@
#import <Foundation/Foundation.h>
typedef NS_ENUM(NSInteger, ARDRegisterResultType) {
kARDRegisterResultTypeUnknown,
kARDRegisterResultTypeSuccess,
kARDRegisterResultTypeFull
typedef NS_ENUM(NSInteger, ARDJoinResultType) {
kARDJoinResultTypeUnknown,
kARDJoinResultTypeSuccess,
kARDJoinResultTypeFull
};
// Result of registering with the GAE server.
@interface ARDRegisterResponse : NSObject
// Result of joining a room on the room server.
@interface ARDJoinResponse : NSObject
@property(nonatomic, readonly) ARDRegisterResultType result;
@property(nonatomic, readonly) ARDJoinResultType result;
@property(nonatomic, readonly) BOOL isInitiator;
@property(nonatomic, readonly) NSString *roomId;
@property(nonatomic, readonly) NSString *clientId;
@ -44,6 +44,6 @@ typedef NS_ENUM(NSInteger, ARDRegisterResultType) {
@property(nonatomic, readonly) NSURL *webSocketURL;
@property(nonatomic, readonly) NSURL *webSocketRestURL;
+ (ARDRegisterResponse *)responseFromJSONData:(NSData *)data;
+ (ARDJoinResponse *)responseFromJSONData:(NSData *)data;
@end

View File

@ -25,22 +25,22 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#import "ARDRegisterResponse+Internal.h"
#import "ARDJoinResponse+Internal.h"
#import "ARDSignalingMessage.h"
#import "ARDUtilities.h"
#import "RTCICEServer+JSON.h"
static NSString const *kARDRegisterResultKey = @"result";
static NSString const *kARDRegisterResultParamsKey = @"params";
static NSString const *kARDRegisterInitiatorKey = @"is_initiator";
static NSString const *kARDRegisterRoomIdKey = @"room_id";
static NSString const *kARDRegisterClientIdKey = @"client_id";
static NSString const *kARDRegisterMessagesKey = @"messages";
static NSString const *kARDRegisterWebSocketURLKey = @"wss_url";
static NSString const *kARDRegisterWebSocketRestURLKey = @"wss_post_url";
static NSString const *kARDJoinResultKey = @"result";
static NSString const *kARDJoinResultParamsKey = @"params";
static NSString const *kARDJoinInitiatorKey = @"is_initiator";
static NSString const *kARDJoinRoomIdKey = @"room_id";
static NSString const *kARDJoinClientIdKey = @"client_id";
static NSString const *kARDJoinMessagesKey = @"messages";
static NSString const *kARDJoinWebSocketURLKey = @"wss_url";
static NSString const *kARDJoinWebSocketRestURLKey = @"wss_post_url";
@implementation ARDRegisterResponse
@implementation ARDJoinResponse
@synthesize result = _result;
@synthesize isInitiator = _isInitiator;
@ -50,22 +50,22 @@ static NSString const *kARDRegisterWebSocketRestURLKey = @"wss_post_url";
@synthesize webSocketURL = _webSocketURL;
@synthesize webSocketRestURL = _webSocketRestURL;
+ (ARDRegisterResponse *)responseFromJSONData:(NSData *)data {
+ (ARDJoinResponse *)responseFromJSONData:(NSData *)data {
NSDictionary *responseJSON = [NSDictionary dictionaryWithJSONData:data];
if (!responseJSON) {
return nil;
}
ARDRegisterResponse *response = [[ARDRegisterResponse alloc] init];
NSString *resultString = responseJSON[kARDRegisterResultKey];
ARDJoinResponse *response = [[ARDJoinResponse alloc] init];
NSString *resultString = responseJSON[kARDJoinResultKey];
response.result = [[self class] resultTypeFromString:resultString];
NSDictionary *params = responseJSON[kARDRegisterResultParamsKey];
NSDictionary *params = responseJSON[kARDJoinResultParamsKey];
response.isInitiator = [params[kARDRegisterInitiatorKey] boolValue];
response.roomId = params[kARDRegisterRoomIdKey];
response.clientId = params[kARDRegisterClientIdKey];
response.isInitiator = [params[kARDJoinInitiatorKey] boolValue];
response.roomId = params[kARDJoinRoomIdKey];
response.clientId = params[kARDJoinClientIdKey];
// Parse messages.
NSArray *messages = params[kARDRegisterMessagesKey];
NSArray *messages = params[kARDJoinMessagesKey];
NSMutableArray *signalingMessages =
[NSMutableArray arrayWithCapacity:messages.count];
for (NSString *message in messages) {
@ -76,9 +76,9 @@ static NSString const *kARDRegisterWebSocketRestURLKey = @"wss_post_url";
response.messages = signalingMessages;
// Parse websocket urls.
NSString *webSocketURLString = params[kARDRegisterWebSocketURLKey];
NSString *webSocketURLString = params[kARDJoinWebSocketURLKey];
response.webSocketURL = [NSURL URLWithString:webSocketURLString];
NSString *webSocketRestURLString = params[kARDRegisterWebSocketRestURLKey];
NSString *webSocketRestURLString = params[kARDJoinWebSocketRestURLKey];
response.webSocketRestURL = [NSURL URLWithString:webSocketRestURLString];
return response;
@ -86,12 +86,12 @@ static NSString const *kARDRegisterWebSocketRestURLKey = @"wss_post_url";
#pragma mark - Private
+ (ARDRegisterResultType)resultTypeFromString:(NSString *)resultString {
ARDRegisterResultType result = kARDRegisterResultTypeUnknown;
+ (ARDJoinResultType)resultTypeFromString:(NSString *)resultString {
ARDJoinResultType result = kARDJoinResultTypeUnknown;
if ([resultString isEqualToString:@"SUCCESS"]) {
result = kARDRegisterResultTypeSuccess;
result = kARDJoinResultTypeSuccess;
} else if ([resultString isEqualToString:@"FULL"]) {
result = kARDRegisterResultTypeFull;
result = kARDJoinResultTypeFull;
}
return result;
}

View File

@ -27,15 +27,15 @@
#import <Foundation/Foundation.h>
@class ARDJoinResponse;
@class ARDMessageResponse;
@class ARDRegisterResponse;
@class ARDSignalingMessage;
@protocol ARDRoomServerClient <NSObject>
- (void)registerForRoomId:(NSString *)roomId
completionHandler:(void (^)(ARDRegisterResponse *response,
NSError *error))completionHandler;
- (void)joinRoomWithRoomId:(NSString *)roomId
completionHandler:(void (^)(ARDJoinResponse *response,
NSError *error))completionHandler;
- (void)sendMessage:(ARDSignalingMessage *)message
forRoomId:(NSString *)roomId
@ -43,7 +43,7 @@
completionHandler:(void (^)(ARDMessageResponse *response,
NSError *error))completionHandler;
- (void)deregisterForRoomId:(NSString *)roomId
- (void)leaveRoomWithRoomId:(NSString *)roomId
clientId:(NSString *)clientId
completionHandler:(void (^)(NSError *error))completionHandler;

View File

@ -30,7 +30,7 @@
#import <OCMock/OCMock.h>
#import "ARDAppClient+Internal.h"
#import "ARDRegisterResponse+Internal.h"
#import "ARDJoinResponse+Internal.h"
#import "ARDMessageResponse+Internal.h"
#import "RTCMediaConstraints.h"
#import "RTCPeerConnectionFactory.h"
@ -136,27 +136,27 @@
id mockRoomServerClient =
[OCMockObject mockForProtocol:@protocol(ARDRoomServerClient)];
// Successful register response.
ARDRegisterResponse *registerResponse = [[ARDRegisterResponse alloc] init];
registerResponse.result = kARDRegisterResultTypeSuccess;
registerResponse.roomId = roomId;
registerResponse.clientId = clientId;
registerResponse.isInitiator = isInitiator;
registerResponse.messages = messages;
// Successful join response.
ARDJoinResponse *joinResponse = [[ARDJoinResponse alloc] init];
joinResponse.result = kARDJoinResultTypeSuccess;
joinResponse.roomId = roomId;
joinResponse.clientId = clientId;
joinResponse.isInitiator = isInitiator;
joinResponse.messages = messages;
// Successful message response.
ARDMessageResponse *messageResponse = [[ARDMessageResponse alloc] init];
messageResponse.result = kARDMessageResultTypeSuccess;
// Return register response from above on register.
// Return join response from above on join.
[[[mockRoomServerClient stub] andDo:^(NSInvocation *invocation) {
__unsafe_unretained void (^completionHandler)(ARDRegisterResponse *response,
__unsafe_unretained void (^completionHandler)(ARDJoinResponse *response,
NSError *error);
[invocation getArgument:&completionHandler atIndex:3];
completionHandler(registerResponse, nil);
}] registerForRoomId:roomId completionHandler:[OCMArg any]];
completionHandler(joinResponse, nil);
}] joinRoomWithRoomId:roomId completionHandler:[OCMArg any]];
// Return message response from above on register.
// Return message response from above on join.
[[[mockRoomServerClient stub] andDo:^(NSInvocation *invocation) {
__unsafe_unretained ARDSignalingMessage *message;
__unsafe_unretained void (^completionHandler)(ARDMessageResponse *response,
@ -170,14 +170,14 @@
clientId:clientId
completionHandler:[OCMArg any]];
// Do nothing on deregister.
// Do nothing on leave.
[[[mockRoomServerClient stub] andDo:^(NSInvocation *invocation) {
__unsafe_unretained void (^completionHandler)(NSError *error);
[invocation getArgument:&completionHandler atIndex:4];
if (completionHandler) {
completionHandler(nil);
}
}] deregisterForRoomId:roomId
}] leaveRoomWithRoomId:roomId
clientId:clientId
completionHandler:[OCMArg any]];

View File

@ -161,12 +161,12 @@
'examples/objc/AppRTCDemo/ARDAppEngineClient.m',
'examples/objc/AppRTCDemo/ARDCEODTURNClient.h',
'examples/objc/AppRTCDemo/ARDCEODTURNClient.m',
'examples/objc/AppRTCDemo/ARDJoinResponse.h',
'examples/objc/AppRTCDemo/ARDJoinResponse.m',
'examples/objc/AppRTCDemo/ARDJoinResponse+Internal.h',
'examples/objc/AppRTCDemo/ARDMessageResponse.h',
'examples/objc/AppRTCDemo/ARDMessageResponse.m',
'examples/objc/AppRTCDemo/ARDMessageResponse+Internal.h',
'examples/objc/AppRTCDemo/ARDRegisterResponse.h',
'examples/objc/AppRTCDemo/ARDRegisterResponse.m',
'examples/objc/AppRTCDemo/ARDRegisterResponse+Internal.h',
'examples/objc/AppRTCDemo/ARDRoomServerClient.h',
'examples/objc/AppRTCDemo/ARDSignalingChannel.h',
'examples/objc/AppRTCDemo/ARDSignalingMessage.h',