Changeset View
Changeset View
Standalone View
Standalone View
webroot/rsrc/externals/javelin/lib/WebSocket.js
| Show First 20 Lines • Show All 124 Lines • ▼ Show 20 Lines | members: { | ||||
| /** | /** | ||||
| * Callback for connection open. | * Callback for connection open. | ||||
| */ | */ | ||||
| _onopen: function() { | _onopen: function() { | ||||
| this._isOpen = true; | this._isOpen = true; | ||||
| // Reset the reconnect delay, since we connected successfully. | // Since we connected successfully, reset the reconnect delay to 0. | ||||
| this._resetDelay(); | |||||
| // This will make us try the first reconnect immediately after a | |||||
| // connection failure. This limits downtime in cases like a service | |||||
| // restart or a load balancer connection timeout. | |||||
| // We only do an immediate retry after a successful connection. | |||||
| this._delayUntilReconnect = 0; | |||||
| var handler = this.getOpenHandler(); | var handler = this.getOpenHandler(); | ||||
| if (handler) { | if (handler) { | ||||
| handler(); | handler(); | ||||
| } | } | ||||
| }, | }, | ||||
| ▲ Show 20 Lines • Show All 42 Lines • ▼ Show 20 Lines | members: { | ||||
| /** | /** | ||||
| * Reconnect an interrupted socket. | * Reconnect an interrupted socket. | ||||
| */ | */ | ||||
| _reconnect: function() { | _reconnect: function() { | ||||
| // Increase the reconnect delay by a factor of 2. If we fail to open the | // Increase the reconnect delay by a factor of 2. If we fail to open the | ||||
| // connection, the close handler will send us back here. We'll reconnect | // connection, the close handler will send us back here. We'll reconnect | ||||
| // more and more slowly until we eventually get a valid connection. | // more and more slowly until we eventually get a valid connection. | ||||
| if (!this._delayUntilReconnect) { | |||||
| this._resetDelay(); | |||||
| } else { | |||||
| this._delayUntilReconnect = this._delayUntilReconnect * 2; | this._delayUntilReconnect = this._delayUntilReconnect * 2; | ||||
| } | |||||
| // Max out at 5 minutes between attempts. | // Max out at 5 minutes between attempts. | ||||
| this._delayUntilReconnect = Math.min(this._delayUntilReconnect, 300000); | this._delayUntilReconnect = Math.min(this._delayUntilReconnect, 300000); | ||||
| this.open(); | this.open(); | ||||
| } | } | ||||
| } | } | ||||
| }); | }); | ||||