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

TH5 #561

Merged
merged 1 commit into from
Jan 2, 2017
Merged

TH5 #561

Show file tree
Hide file tree
Changes from all commits
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
10 changes: 6 additions & 4 deletions Source/ARTRealtimeChannel.m
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ - (ARTEventListener *)timed:(ARTEventListener *)listener deadline:(NSTimeInterva
}

- (void)transition:(ARTRealtimeChannelState)state status:(ARTStatus *)status {
ARTChannelStateChange *stateChange = [[ARTChannelStateChange alloc] initWithCurrent:state previous:self.state reason:status.errorInfo];
ARTChannelStateChange *stateChange = [[ARTChannelStateChange alloc] initWithCurrent:state previous:self.state event:(ARTChannelEvent)state reason:status.errorInfo];
self.state = state;

if (status.storeErrorInfo) {
Expand All @@ -327,7 +327,7 @@ - (void)transition:(ARTRealtimeChannelState)state status:(ARTStatus *)status {
[_attachedEventEmitter emit:[NSNull null] with:[ARTErrorInfo createWithCode:90000 message:msg]];
}

[self emit:(ARTChannelEvent)stateChange.current with:stateChange];
[self emit:stateChange.event with:stateChange];
}

- (void)dealloc {
Expand Down Expand Up @@ -405,7 +405,8 @@ - (void)setAttached:(ARTProtocolMessage *)message {
if (message.error != nil) {
_errorReason = message.error;
}
[self emit:ARTChannelEventUpdate with:[[ARTChannelStateChange alloc] initWithCurrent:self.state previous:self.state reason:message.error]];
ARTChannelStateChange *stateChange = [[ARTChannelStateChange alloc] initWithCurrent:self.state previous:self.state event:ARTChannelEventUpdate reason:message.error];
[self emit:stateChange.event with:stateChange];
return;
}

Expand Down Expand Up @@ -486,7 +487,8 @@ - (void)onMessage:(ARTProtocolMessage *)message {
ARTErrorInfo *errorInfo = [ARTErrorInfo wrap:(ARTErrorInfo *)error.userInfo[NSLocalizedFailureReasonErrorKey] prepend:@"Failed to decode data: "];
[self.logger error:@"R:%p C:%p %@", _realtime, self, errorInfo.message];
_errorReason = errorInfo;
[self emit:ARTChannelEventUpdate with:[[ARTChannelStateChange alloc] initWithCurrent:self.state previous:self.state reason:errorInfo]];
ARTChannelStateChange *stateChange = [[ARTChannelStateChange alloc] initWithCurrent:self.state previous:self.state event:ARTChannelEventUpdate reason:errorInfo];
[self emit:stateChange.event with:stateChange];
}
}

Expand Down
3 changes: 3 additions & 0 deletions Source/ARTTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,15 +153,18 @@ NSString *generateNonce();

- (instancetype)initWithCurrent:(ARTRealtimeChannelState)current
previous:(ARTRealtimeChannelState)previous
event:(ARTChannelEvent)event
reason:(ARTErrorInfo *__art_nullable)reason;

- (instancetype)initWithCurrent:(ARTRealtimeChannelState)current
previous:(ARTRealtimeChannelState)previous
event:(ARTChannelEvent)event
reason:(ARTErrorInfo *__art_nullable)reason
resumed:(BOOL)resumed;

@property (readonly, nonatomic) ARTRealtimeChannelState current;
@property (readonly, nonatomic) ARTRealtimeChannelState previous;
@property (readonly, nonatomic) ARTChannelEvent event;
@property (readonly, nonatomic, art_nullable) ARTErrorInfo *reason;
@property (readonly, nonatomic) BOOL resumed;

Expand Down
7 changes: 4 additions & 3 deletions Source/ARTTypes.m
Original file line number Diff line number Diff line change
Expand Up @@ -119,15 +119,16 @@ - (void)setRetryIn:(NSTimeInterval)retryIn {

@implementation ARTChannelStateChange

- (instancetype)initWithCurrent:(ARTRealtimeChannelState)current previous:(ARTRealtimeChannelState)previous reason:(ARTErrorInfo *)reason {
return [self initWithCurrent:current previous:previous reason:reason resumed:NO];
- (instancetype)initWithCurrent:(ARTRealtimeChannelState)current previous:(ARTRealtimeChannelState)previous event:(ARTChannelEvent)event reason:(ARTErrorInfo *)reason {
return [self initWithCurrent:current previous:previous event:event reason:reason resumed:NO];
}

- (instancetype)initWithCurrent:(ARTRealtimeChannelState)current previous:(ARTRealtimeChannelState)previous reason:(ARTErrorInfo *)reason resumed:(BOOL)resumed {
- (instancetype)initWithCurrent:(ARTRealtimeChannelState)current previous:(ARTRealtimeChannelState)previous event:(ARTChannelEvent)event reason:(ARTErrorInfo *)reason resumed:(BOOL)resumed {
self = [self init];
if (self) {
_current = current;
_previous = previous;
_event = event;
_reason = reason;
_resumed = resumed;
}
Expand Down
7 changes: 7 additions & 0 deletions Spec/RealtimeClientChannel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,11 @@ class RealtimeClientChannel: QuickSpec {

switch stateChange.current {
case .Attached:
expect(stateChange.event).to(equal(ARTChannelEvent.Attached))
expect(stateChange.reason).to(beNil())
channel.detach()
case .Detached:
expect(stateChange.event).to(equal(ARTChannelEvent.Detached))
guard let error = stateChange.reason else {
fail("Detach state change reason is nil"); done(); return
}
Expand Down Expand Up @@ -162,12 +164,14 @@ class RealtimeClientChannel: QuickSpec {
expect(channel.state).to(equal(stateChange.current))
switch stateChange.current {
case .Attaching:
expect(stateChange.event).to(equal(ARTChannelEvent.Attaching))
expect(stateChange.reason).to(beNil())
expect(stateChange.previous).to(equal(ARTRealtimeChannelState.Initialized))
case .Failed:
guard let reason = stateChange.reason else {
fail("Reason is nil"); done(); return
}
expect(stateChange.event).to(equal(ARTChannelEvent.Failed))
expect(reason.code) == 40160
expect(stateChange.previous).to(equal(ARTRealtimeChannelState.Attaching))
done()
Expand Down Expand Up @@ -199,6 +203,7 @@ class RealtimeClientChannel: QuickSpec {
}
expect(stateChange.reason).to(beNil())
expect(stateChange.previous).to(equal(ARTRealtimeChannelState.Attached))
expect(stateChange.event).to(equal(ARTChannelEvent.Suspended))
expect(channel.state).to(equal(stateChange.current))
done()
}
Expand Down Expand Up @@ -232,6 +237,7 @@ class RealtimeClientChannel: QuickSpec {
expect(channel.state).to(equal(ARTRealtimeChannelState.Attached))
expect(stateChange.previous).to(equal(channel.state))
expect(stateChange.current).to(equal(channel.state))
expect(stateChange.event).to(equal(ARTChannelEvent.Update))
expect(stateChange.resumed).to(beFalse())
expect(stateChange.reason).to(beNil())
done()
Expand Down Expand Up @@ -2835,6 +2841,7 @@ class RealtimeClientChannel: QuickSpec {
guard let stateChange = stateChange else {
fail("ChannelStateChange is nil"); done(); return
}
expect(stateChange.event).to(equal(ARTChannelEvent.Update))
expect(stateChange.reason).to(beIdenticalTo(attachedMessageWithError.error))
expect(channel.errorReason).to(beIdenticalTo(stateChange.reason))
done()
Expand Down