Skip to content

Commit

Permalink
To avoid premature reconnect due to exeeded threshhold while CONNECTI…
Browse files Browse the repository at this point in the history
…NG, reachability now activated after token request is complited. During token request user will receive the request error in case of unreachable network.
  • Loading branch information
maratal committed Mar 1, 2024
1 parent 913659d commit 3eac846
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions Source/ARTRealtime.m
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ - (void)auth:(ARTAuthInternal *)auth didAuthorize:(ARTTokenDetails *)tokenDetail
ARTLogDebug(self.logger, @"RS:%p halt current connection and reconnect with %@", self.rest, tokenDetails);
[self abortAndReleaseTransport:[ARTStatus state:ARTStateOk]];
[self setTransportWithResumeKey:self->_transport.resumeKey];
[self->_transport connectWithToken:tokenDetails.token];
[self connectTransportWithToken:tokenDetails.token orKey:nil];
[self cancelAllPendingAuthorizations];
waitForResponse();
};
Expand Down Expand Up @@ -644,8 +644,6 @@ - (void)performTransitionToState:(ARTRealtimeConnectionState)state withParams:(A
[self createAndConnectTransportWithConnectionResume:resume];
}

[self setReachabilityActive:YES];

break;
}
case ARTRealtimeClosing: {
Expand Down Expand Up @@ -811,6 +809,16 @@ - (void)createAndConnectTransportWithConnectionResume:(BOOL)resume {
[self transportConnectForcingNewToken:_renewingToken newConnection:true];
}

- (void)connectTransportWithToken:(nullable NSString *)token orKey:(nullable NSString *)key {
if (token != nil) {
[self.transport connectWithToken:token];
}
else {
[self.transport connectWithKey:key];
}
[self setReachabilityActive:YES];
}

- (void)abortAndReleaseTransport:(ARTStatus *)status {
[_transport abort:status];
_transport = nil;
Expand Down Expand Up @@ -1077,7 +1085,7 @@ - (void)transportConnectForcingNewToken:(BOOL)forceNewToken newConnection:(BOOL)
ARTClientOptions *options = [self.options copy];
if ([options isBasicAuth]) {
// Basic
[self.transport connectWithKey:options.key];
[self connectTransportWithToken:nil orKey:options.key];
}
else {
// Token
Expand All @@ -1086,7 +1094,7 @@ - (void)transportConnectForcingNewToken:(BOOL)forceNewToken newConnection:(BOOL)
if (!forceNewToken && [self.auth tokenRemainsValid]) {
// Reuse token
ARTLogDebug(self.logger, @"R:%p reusing token for auth", self);
[self.transport connectWithToken:self.auth.tokenDetails.token];
[self connectTransportWithToken:self.auth.tokenDetails.token orKey:nil];
}
else {
// New Token
Expand Down Expand Up @@ -1128,7 +1136,7 @@ - (void)transportConnectForcingNewToken:(BOOL)forceNewToken newConnection:(BOOL)
[self resetTransportWithResumeKey:self->_transport.resumeKey];
}
if (newConnection) {
[self.transport connectWithToken:tokenDetails.token];
[self connectTransportWithToken:tokenDetails.token orKey:nil];
}
}];
}
Expand Down

0 comments on commit 3eac846

Please sign in to comment.