diff --git a/Source/ARTRealtimeChannel.m b/Source/ARTRealtimeChannel.m index c2f4a51c5..6c09bbfb0 100644 --- a/Source/ARTRealtimeChannel.m +++ b/Source/ARTRealtimeChannel.m @@ -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) { @@ -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 { @@ -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; } @@ -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]; } } diff --git a/Source/ARTTypes.h b/Source/ARTTypes.h index 915e6cc6c..32660bb32 100644 --- a/Source/ARTTypes.h +++ b/Source/ARTTypes.h @@ -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; diff --git a/Source/ARTTypes.m b/Source/ARTTypes.m index 9c5c56851..b116f4b63 100644 --- a/Source/ARTTypes.m +++ b/Source/ARTTypes.m @@ -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; } diff --git a/Spec/RealtimeClientChannel.swift b/Spec/RealtimeClientChannel.swift index aa8ec6734..e3a0e2e89 100644 --- a/Spec/RealtimeClientChannel.swift +++ b/Spec/RealtimeClientChannel.swift @@ -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 } @@ -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() @@ -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() } @@ -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() @@ -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()