Skip to content

Commit

Permalink
Fix reconnecting if a list of hosts|uris was given. At the seconds+ f…
Browse files Browse the repository at this point in the history
…ailover

Signed-off-by: Heiko Henning UE85540 <[email protected]>
  • Loading branch information
GreenRover committed Sep 9, 2019
1 parent a1d0c16 commit 48da7c6
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/paho-mqtt.js
Original file line number Diff line number Diff line change
Expand Up @@ -1055,6 +1055,7 @@ function onMessageArrived(message) {
this.connected = false;


this._trace("_doConnect ", wsurl);

if (this.connectOptions.mqttVersion < 4) {
this.socket = new global.WebSocket(wsurl, ["mqttv3.1"]);
Expand Down Expand Up @@ -1542,8 +1543,12 @@ function onMessageArrived(message) {
if (this._reconnectInterval < 128)
this._reconnectInterval = this._reconnectInterval * 2;
if (this.connectOptions.uris) {
this.hostIndex = 0;
this._doConnect(this.connectOptions.uris[0]);
// Loop through all host until we find an working one.
this.hostIndex++;
if (this.hostIndex >= this.connectOptions.uris.length) {
this.hostIndex = 0;
}
this._doConnect(this.connectOptions.uris[this.hostIndex]);
} else {
this._doConnect(this.uri);
}
Expand Down

0 comments on commit 48da7c6

Please sign in to comment.