Skip to content

Extension for MQTTSessionManagerDelegate #401

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
9 changes: 9 additions & 0 deletions MQTTClient/MQTTClient/MQTTSessionManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,15 @@ typedef NS_ENUM(int, MQTTSessionManagerState) {
*/
- (void)sessionManager:(MQTTSessionManager *)sessionManager didChangeState:(MQTTSessionManagerState)newState;

- (void)sessionManager:(MQTTSessionManager *)sessionManager didReceiveErrorEvent:(MQTTSessionManagerState)newState;

/** let user to decide wheather trigger reconnect,sometime when `error.code` == MQTTSessionErrorConnackBadUsernameOrPassword | MQTTSessionErrorConnackNotAuthorized,reconnect is unnecessary.
@param sessionManager the instance of MQTTSessionManager whose state changed
@param error
*/
- (BOOL)sessionManager:(MQTTSessionManager *)sessionManager shouldTriggerDelayedReconnectForError:(NSError *)error;


@end

/** SessionManager handles the MQTT session for your application
Expand Down
10 changes: 9 additions & 1 deletion MQTTClient/MQTTClient/MQTTSessionManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -391,9 +391,17 @@ - (void)handleEvent:(MQTTSession *)session event:(MQTTSessionEvent)eventCode err
case MQTTSessionEventProtocolError:
case MQTTSessionEventConnectionRefused:
case MQTTSessionEventConnectionError:
[self triggerDelayedReconnect];

self.lastErrorCode = error;
[self updateState:MQTTSessionManagerStateError];

if([self.delegate respondsToSelector:@selector(sessionManager:shouldTriggerDelayedReconnectForError:)] && ![self.delegate sessionManager:self shouldTriggerDelayedReconnectForError:error]){
//do nothing
}else {
[self triggerDelayedReconnect];
}


break;

default:
Expand Down