Skip to content

Commit

Permalink
fix: add option to reconnect if connack has an error code
Browse files Browse the repository at this point in the history
fixes #1947
  • Loading branch information
mgabeler-lee-6rs committed Oct 16, 2024
1 parent abf0de4 commit abc335f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/lib/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,12 @@ export interface IClientOptions extends ISecureClientOptions {
* 1000 milliseconds, interval between two reconnections
*/
reconnectPeriod?: number
/**
* Set to true to enable the reconnect period to apply if the initial
* connection is denied with an error in the CONNACK packet, such as with an
* authentication error.
*/
reconnectOnConnackError?: boolean
/**
* 30 * 1000 milliseconds, time to wait before a CONNACK is received
*/
Expand Down
3 changes: 3 additions & 0 deletions src/lib/handlers/connack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ const handleConnack: PacketHandler = (client, packet: IConnackPacket) => {
rc,
)
client.emit('error', err)
if (client.options.reconnectOnConnackError) {
client['_cleanUp'](true)
}
}
}

Expand Down

0 comments on commit abc335f

Please sign in to comment.