Changeset View
Changeset View
Standalone View
Standalone View
webroot/rsrc/externals/javelin/lib/WebSocket.js
| /** | /** | ||||
| * @requires javelin-install | * @requires javelin-install | ||||
| * @provides javelin-websocket | * @provides javelin-websocket | ||||
| * @javelin | * @javelin | ||||
| */ | */ | ||||
| /** | /** | ||||
| * Wraps a WebSocket. | * Wraps a WebSocket. | ||||
| */ | */ | ||||
| JX.install('WebSocket', { | JX.install('WebSocket', { | ||||
| construct: function(uri) { | construct: function(uri) { | ||||
| this.setURI(uri); | this.setURI(uri); | ||||
| this._resetDelay(); | |||||
| }, | }, | ||||
| properties: { | properties: { | ||||
| URI: null, | URI: null, | ||||
| /** | /** | ||||
| * Called when a connection is established or re-established after an | * Called when a connection is established or re-established after an | ||||
| * interruption. | * interruption. | ||||
| ▲ Show 20 Lines • Show All 43 Lines • ▼ Show 20 Lines | members: { | ||||
| * Open the connection. | * Open the connection. | ||||
| */ | */ | ||||
| open: function() { | open: function() { | ||||
| if (!window.WebSocket) { | if (!window.WebSocket) { | ||||
| return; | return; | ||||
| } | } | ||||
| this._shouldClose = false; | this._shouldClose = false; | ||||
| this._resetDelay(); | |||||
epriestley: This is the timeout fix. | |||||
| this._socket = new WebSocket(this.getURI()); | this._socket = new WebSocket(this.getURI()); | ||||
| this._socket.onopen = JX.bind(this, this._onopen); | this._socket.onopen = JX.bind(this, this._onopen); | ||||
| this._socket.onmessage = JX.bind(this, this._onmessage); | this._socket.onmessage = JX.bind(this, this._onmessage); | ||||
| this._socket.onclose = JX.bind(this, this._onclose); | this._socket.onclose = JX.bind(this, this._onclose); | ||||
| }, | }, | ||||
| ▲ Show 20 Lines • Show All 84 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. | ||||
| this._delayUntilReconnect = this._delayUntilReconnect * 2; | this._delayUntilReconnect = this._delayUntilReconnect * 2; | ||||
| // Max out at 5 minutes between attempts. | |||||
| this._delayUntilReconnect = Math.min(this._delayUntilReconnect, 300000); | |||||
| this.open(); | this.open(); | ||||
| } | } | ||||
| } | } | ||||
| }); | }); | ||||
This is the timeout fix.