WebSockets: allow the caller to choose when to start connecting.

This allows the caller to fully set up event handlers etc. before the
first 'connecting' message is fired.
This commit is contained in:
Neil Williams
2014-02-27 11:18:34 -08:00
parent 0de32efc29
commit b6323fa314

View File

@@ -1,17 +1,19 @@
r.WebSocket = function (url) {
this._url = url
this._connectionAttempts = 0
var websocketsAvailable = 'WebSocket' in window
if (websocketsAvailable) {
this._connect()
}
}
_.extend(r.WebSocket.prototype, Backbone.Events, {
_backoffTime: 2000,
_maximumRetries: 9,
_retryJitterAmount: 3000,
start: function () {
var websocketsAvailable = 'WebSocket' in window
if (websocketsAvailable) {
this._connect()
}
},
_connect: function () {
r.debug('websocket: connecting')
this.trigger('connecting')