Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reattaching channels in compliance with RTN15c3 #1172

Merged
merged 4 commits into from
Aug 31, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Source/ARTRealtime.m
Original file line number Diff line number Diff line change
Expand Up @@ -779,7 +779,7 @@ - (void)onConnected:(ARTProtocolMessage *)message {

// Resuming
if (_resuming) {
if (![message.connectionId isEqualToString:self.connection.id_nosync]) {
if (![message.connectionId isEqualToString:self.connection.id_nosync]) { // RTN15c3
[self.logger warn:@"RT:%p connection \"%@\" has reconnected, but resume failed. Reattaching any attached channels", self, message.connectionId];
// Reattach all channels
for (ARTRealtimeChannelInternal *channel in self.channels.nosyncIterable) {
Expand Down
4 changes: 3 additions & 1 deletion Source/ARTRealtimeChannel+Private.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ NS_ASSUME_NONNULL_BEGIN

- (ARTRealtimeChannelState)state_nosync;
- (ARTErrorInfo *)errorReason_nosync;
- (NSString *_Nullable)clientId_nosync;
- (NSString * _Nullable)clientId_nosync;
- (NSString * _Nullable)stateString_nosync;
- (BOOL)canBeReattached;

@property (readonly, weak, nonatomic) ARTRealtimeInternal *realtime; // weak because realtime owns self
@property (readonly, strong, nonatomic) ARTRestChannelInternal *restChannel;
Expand Down
43 changes: 29 additions & 14 deletions Source/ARTRealtimeChannel.m
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,30 @@ - (ARTRealtimeChannelState)state_nosync {
return _state;
}

- (NSString *)stateString_nosync {
switch (self.state_nosync) {
case ARTRealtimeChannelInitialized: return @"initialized";
case ARTRealtimeChannelAttaching: return @"attaching";
case ARTRealtimeChannelAttached: return @"attached";
case ARTRealtimeChannelDetaching: return @"detaching";
case ARTRealtimeChannelDetached: return @"detached";
case ARTRealtimeChannelSuspended: return @"suspended";
case ARTRealtimeChannelFailed: return @"failed";
}
return nil;
}

- (BOOL)canBeReattached {
switch (self.state_nosync) {
case ARTRealtimeChannelAttaching:
case ARTRealtimeChannelAttached:
case ARTRealtimeChannelSuspended:
return YES;
default:
return NO;
}
}

- (ARTErrorInfo *)errorReason_nosync {
return _errorReason;
}
Expand Down Expand Up @@ -954,21 +978,12 @@ - (void)_attach:(void (^)(ARTErrorInfo *__art_nullable))callback {
}

- (void)reattachWithReason:(ARTErrorInfo *)reason callback:(void (^)(ARTErrorInfo *))callback {
switch (self.state_nosync) {
case ARTRealtimeChannelAttached:
[self.realtime.logger debug:__FILE__ line:__LINE__ message:@"RT:%p C:%p (%@) attached and will reattach", _realtime, self, self.name];
break;
case ARTRealtimeChannelSuspended:
[self.realtime.logger debug:__FILE__ line:__LINE__ message:@"RT:%p C:%p (%@) suspended and will reattach", _realtime, self, self.name];
break;
case ARTRealtimeChannelAttaching:
[self.realtime.logger debug:__FILE__ line:__LINE__ message:@"RT:%p C:%p (%@) already attaching", _realtime, self, self.name];
if (callback) [_attachedEventEmitter once:callback];
return;
default:
break;
if ([self canBeReattached]) {
[self.realtime.logger debug:__FILE__ line:__LINE__ message:@"RT:%p C:%p (%@) %@ and will reattach", _realtime, self, self.name, self.stateString_nosync];
[self internalAttach:callback withReason:reason];
} else {
[self.realtime.logger debug:__FILE__ line:__LINE__ message:@"RT:%p C:%p (%@) %@ should not reattach", _realtime, self, self.name, self.stateString_nosync];
}
[self internalAttach:callback withReason:reason];
}

- (void)internalAttach:(void (^)(ARTErrorInfo *))callback withReason:(ARTErrorInfo *)reason {
Expand Down