mirror of
https://github.com/reddit-archive/reddit.git
synced 2026-04-27 03:00:12 -04:00
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:
@@ -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')
|
||||
|
||||
Reference in New Issue
Block a user