Skip to content

Commit 15b9224

Browse files
committed
Fix reconnecting if a list of hosts|uris was given. At the seconds+ failover
1 parent a1d0c16 commit 15b9224

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/paho-mqtt.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -1055,6 +1055,7 @@ function onMessageArrived(message) {
10551055
this.connected = false;
10561056

10571057

1058+
this._trace("_doConnect ", wsurl);
10581059

10591060
if (this.connectOptions.mqttVersion < 4) {
10601061
this.socket = new global.WebSocket(wsurl, ["mqttv3.1"]);
@@ -1542,8 +1543,12 @@ function onMessageArrived(message) {
15421543
if (this._reconnectInterval < 128)
15431544
this._reconnectInterval = this._reconnectInterval * 2;
15441545
if (this.connectOptions.uris) {
1545-
this.hostIndex = 0;
1546-
this._doConnect(this.connectOptions.uris[0]);
1546+
// Loop through all host until we find an working one.
1547+
this.hostIndex++;
1548+
if (this.hostIndex >= this.connectOptions.uris.length) {
1549+
this.hostIndex = 0;
1550+
}
1551+
this._doConnect(this.connectOptions.uris[this.hostIndex]);
15471552
} else {
15481553
this._doConnect(this.uri);
15491554
}

0 commit comments

Comments
 (0)