Skip to content

Commit

Permalink
Merge pull request #38 from ricardopereira/rtc4
Browse files Browse the repository at this point in the history
RTC4, RTC4a
  • Loading branch information
paddybyers committed Oct 29, 2015
2 parents 9681d48 + 717c15c commit b71d23a
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 14 deletions.
3 changes: 3 additions & 0 deletions ably-ios/ARTAuth+Private.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ ART_ASSUME_NONNULL_BEGIN
- (NSURL *)buildURL:(ARTAuthOptions *)options withParams:(ARTAuthTokenParams *)params;
- (NSMutableURLRequest *)buildRequest:(ARTAuthOptions *)options withParams:(ARTAuthTokenParams *)params;

// CONNECTED ProtocolMessage may contain a clientId
- (void)setProtocolClientId:(NSString *)clientId;

@end

ART_ASSUME_NONNULL_END
17 changes: 16 additions & 1 deletion ably-ios/ARTAuth.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

@implementation ARTAuth {
__weak ARTRest *_rest;
// Dedicated to Protocol Message
NSString *_protocolClientId;
}

- (instancetype)init:(ARTRest *)rest withOptions:(ARTClientOptions *)options {
Expand All @@ -28,6 +30,7 @@ - (instancetype)init:(ARTRest *)rest withOptions:(ARTClientOptions *)options {
_tokenDetails = options.tokenDetails;
_options = options;
_logger = rest.logger;
_protocolClientId = nil;

[self validate:options];
}
Expand Down Expand Up @@ -255,8 +258,20 @@ - (void)createTokenRequest:(ARTAuthTokenParams *)tokenParams options:(ARTAuthOpt
}
}

- (void)setProtocolClientId:(NSString *)clientId {
_protocolClientId = clientId;
}

- (NSString *)getClientId {
if (self.tokenDetails) {
if (_protocolClientId) {
// Check wildcard
if ([_protocolClientId isEqual:@"*"])
// Any client
return nil;
else
return _protocolClientId;
}
else if (self.tokenDetails) {
// Check wildcard
if ([self.tokenDetails.clientId isEqual:@"*"])
// Any client
Expand Down
13 changes: 10 additions & 3 deletions ably-ios/ARTJsonEncoder.m
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ - (ARTProtocolMessage *)protocolMessageFromDictionary:(NSDictionary *)input {
message.channelSerial = [input artString:@"channelSerial"];
message.connectionId = [input artString:@"connectionId"];
NSNumber * serial = [input artNumber:@"connectionSerial"];
if(serial) {
if (serial) {
message.connectionSerial = [serial longLongValue];
}
message.id = [input artString:@"id"];
Expand All @@ -422,11 +422,18 @@ - (ARTProtocolMessage *)protocolMessageFromDictionary:(NSDictionary *)input {
message.presence = [self presenceMessagesFromArray:[input objectForKey:@"presence"]];
message.connectionKey = [input artString:@"connectionKey"];
message.flags = [[input artNumber:@"flags"] longLongValue];
NSDictionary * error = [input valueForKey:@"error"];
if(error) {

NSDictionary *connectionDetails = [input valueForKey:@"connectionDetails"];
if (connectionDetails) {
message.clientId = [connectionDetails artString:@"clientId"];
}

NSDictionary *error = [input valueForKey:@"error"];
if (error) {
message.error = [[ARTErrorInfo alloc] init];
[message.error setCode:[[error artNumber:@"code"] intValue] status:[[error artNumber:@"statusCode"] intValue] message:[error artString:@"message"]];
}

return message;
}

Expand Down
17 changes: 9 additions & 8 deletions ably-ios/ARTProtocolMessage.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,18 @@ ART_ASSUME_NONNULL_BEGIN
@property (readwrite, assign, nonatomic) ARTProtocolMessageAction action;
@property (readwrite, assign, nonatomic) int count;
@property (art_nullable, readwrite, strong, nonatomic) ARTErrorInfo *error;
@property (readwrite, strong, nonatomic) NSString *id;
@property (readwrite, strong, nonatomic) NSString *channel;
@property (readwrite, strong, nonatomic) NSString *channelSerial;
@property (readwrite, strong, nonatomic) NSString *connectionId;
@property (readwrite, strong, nonatomic) NSString *connectionKey;
@property (art_nullable, readwrite, strong, nonatomic) NSString *id;
@property (art_nullable, readwrite, strong, nonatomic) NSString *channel;
@property (art_nullable, readwrite, strong, nonatomic) NSString *channelSerial;
@property (art_nullable, readwrite, strong, nonatomic) NSString *connectionId;
@property (art_nullable, readwrite, strong, nonatomic) NSString *connectionKey;
@property (art_nullable, readwrite, strong, nonatomic) NSString *clientId;
@property (readwrite, assign, nonatomic) int64_t connectionSerial;
@property (readwrite, assign, nonatomic) BOOL hasConnectionSerial;
@property (readwrite, assign, nonatomic) int64_t msgSerial;
@property (readwrite, strong, nonatomic) NSDate *timestamp;
@property (readwrite, strong, nonatomic) NSArray *messages;
@property (readwrite, strong, nonatomic) NSArray *presence;
@property (art_nullable, readwrite, strong, nonatomic) NSDate *timestamp;
@property (art_nullable, readwrite, strong, nonatomic) NSArray *messages;
@property (art_nullable, readwrite, strong, nonatomic) NSArray *presence;
@property (readonly, assign, nonatomic) BOOL ackRequired;
@property (readwrite, assign, nonatomic) int64_t flags;

Expand Down
1 change: 1 addition & 0 deletions ably-ios/ARTProtocolMessage.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ - (id)init {
if (self) {
_count = 0;
_id = nil;
_clientId = nil;
_channel = nil;
_channelSerial = nil;
_connectionId = nil;
Expand Down
8 changes: 6 additions & 2 deletions ably-ios/ARTRealtime.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#import "ARTStatus.h"
#import "ARTDefault.h"
#import "ARTRest.h"
#import "ARTAuth+Private.h"
#import "ARTMessage.h"
#import "ARTClientOptions.h"
#import "ARTChannelOptions.h"
Expand Down Expand Up @@ -272,8 +273,8 @@ - (void)transition:(ARTRealtimeConnectionState)state withErrorInfo:(ARTErrorInfo
[self startConnectTimer];

// Create transport and initiate connection
if(!self.transport) {
if(previousState == ARTRealtimeFailed || previousState == ARTRealtimeDisconnected) {
if (!self.transport) {
if (previousState == ARTRealtimeFailed || previousState == ARTRealtimeDisconnected) {
self.options.connectionSerial = self.connectionSerial;
self.options.resumeKey = self.connectionKey;
}
Expand Down Expand Up @@ -756,6 +757,9 @@ - (void)realtimeTransport:(id)transport didReceiveMessage:(ARTProtocolMessage *)
[self onError:message withErrorInfo:message.error];
break;
case ARTProtocolMessageConnected:
// Set Auth#clientId
[[self auth] setProtocolClientId:message.clientId];
// Event
[self onConnected:message withErrorInfo:message.error];
break;
case ARTProtocolMessageDisconnected:
Expand Down
34 changes: 34 additions & 0 deletions ablySpec/RealtimeClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,40 @@ class RealtimeClient: QuickSpec {

expect(client.channels()["test"]).toNot(beNil())
}

context("Auth object") {

// RTC4
it("should provide access to the Auth object") {
let options = AblyTests.commonAppSetup()
let client = ARTRealtime(options: options)

expect(client.auth().options.key).to(equal(options.key))
}

// RTC4a
it("clientId may be populated when the connection is established") {
let options = AblyTests.commonAppSetup()
options.clientId = "client_string"
let client = ARTRealtime(options: options)

waitUntil(timeout: 60) { done in
client.eventEmitter.on { state, errorInfo in
switch state {
case .Failed:
self.checkError(errorInfo, withAlternative: "Failed state")
done()
case .Connected:
self.checkError(errorInfo)
expect(client.auth().clientId).to(equal(options.clientId))
done()
default:
break
}
}
}
}
}
}
}
}

0 comments on commit b71d23a

Please sign in to comment.