@@ -521,7 +521,7 @@ module.exports = _dereq_('./socket');
521521 */
522522module . exports . parser = _dereq_ ( 'engine.io-parser' ) ;
523523
524- } , { "./socket" :7 , "engine.io-parser" :18 } ] , 7 :[ function ( _dereq_ , module , exports ) {
524+ } , { "./socket" :7 , "engine.io-parser" :19 } ] , 7 :[ function ( _dereq_ , module , exports ) {
525525( function ( global ) {
526526/**
527527 * Module dependencies.
@@ -782,7 +782,6 @@ Socket.prototype.probe = function (name) {
782782 self . setTransport ( transport ) ;
783783 transport . send ( [ { type : 'upgrade' } ] ) ;
784784 self . emit ( 'upgrade' , transport ) ;
785- transport = null ;
786785 self . upgrading = false ;
787786 self . flush ( ) ;
788787 } ) ;
@@ -800,17 +799,14 @@ Socket.prototype.probe = function (name) {
800799
801800 // Any callback called by transport should be ignored since now
802801 failed = true ;
803-
804802 cleanup ( ) ;
805-
806803 transport . close ( ) ;
807- transport = null ;
808804 }
809805
810806 //Handle any error that happens while probing
811807 function onerror ( err ) {
812808 var error = new Error ( 'probe error: ' + err ) ;
813- error . transport = transport . name ;
809+ error . transport = name ;
814810
815811 freezeTransport ( ) ;
816812
@@ -1152,7 +1148,7 @@ Socket.prototype.filterUpgrades = function (upgrades) {
11521148} ;
11531149
11541150} ) . call ( this , typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : { } )
1155- } , { "./transport" :8 , "./transports" :9 , "component-emitter" :15 , "debug" :17 , "engine.io-parser" :18 , "indexof" :27 , "parsejson" :28 , "parseqs" :29 , "parseuri" :30 } ] , 8 :[ function ( _dereq_ , module , exports ) {
1151+ } , { "./transport" :8 , "./transports" :9 , "component-emitter" :16 , "debug" :18 , "engine.io-parser" :19 , "indexof" :27 , "parsejson" :28 , "parseqs" :29 , "parseuri" :30 } ] , 8 :[ function ( _dereq_ , module , exports ) {
11561152/**
11571153 * Module dependencies.
11581154 */
@@ -1308,7 +1304,7 @@ Transport.prototype.onClose = function () {
13081304 this . emit ( 'close' ) ;
13091305} ;
13101306
1311- } , { "component-emitter" :15 , "engine.io-parser" :18 } ] , 9 :[ function ( _dereq_ , module , exports ) {
1307+ } , { "component-emitter" :16 , "engine.io-parser" :19 } ] , 9 :[ function ( _dereq_ , module , exports ) {
13121308( function ( global ) {
13131309/**
13141310 * Module dependencies
@@ -1596,7 +1592,7 @@ JSONPPolling.prototype.doWrite = function (data, fn) {
15961592} ;
15971593
15981594} ) . call ( this , typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : { } )
1599- } , { "./polling" :12 , "component-inherit" :16 } ] , 11 :[ function ( _dereq_ , module , exports ) {
1595+ } , { "./polling" :12 , "component-inherit" :17 } ] , 11 :[ function ( _dereq_ , module , exports ) {
16001596( function ( global ) {
16011597/**
16021598 * Module requirements.
@@ -1910,7 +1906,7 @@ function unloadHandler() {
19101906}
19111907
19121908} ) . call ( this , typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : { } )
1913- } , { "./polling" :12 , "component-emitter" :15 , "component-inherit" :16 , "debug" :17 , "xmlhttprequest" :14 } ] , 12 :[ function ( _dereq_ , module , exports ) {
1909+ } , { "./polling" :12 , "component-emitter" :16 , "component-inherit" :17 , "debug" :18 , "xmlhttprequest" :14 } ] , 12 :[ function ( _dereq_ , module , exports ) {
19141910/**
19151911 * Module dependencies.
19161912 */
@@ -2157,7 +2153,7 @@ Polling.prototype.uri = function(){
21572153 return schema + '://' + this . hostname + port + this . path + query ;
21582154} ;
21592155
2160- } , { "../transport" :8 , "component-inherit" :16 , "debug" :17 , "engine.io-parser" :18 , "parseqs" :29 , "xmlhttprequest" :14 } ] , 13 :[ function ( _dereq_ , module , exports ) {
2156+ } , { "../transport" :8 , "component-inherit" :17 , "debug" :18 , "engine.io-parser" :19 , "parseqs" :29 , "xmlhttprequest" :14 } ] , 13 :[ function ( _dereq_ , module , exports ) {
21612157/**
21622158 * Module dependencies.
21632159 */
@@ -2388,7 +2384,7 @@ WS.prototype.check = function(){
23882384 return ! ! WebSocket && ! ( '__initialize' in WebSocket && this . name === WS . prototype . name ) ;
23892385} ;
23902386
2391- } , { "../transport" :8 , "component-inherit" :16 , "debug" :17 , "engine.io-parser" :18 , "parseqs" :29 , "ws" :31 } ] , 14 :[ function ( _dereq_ , module , exports ) {
2387+ } , { "../transport" :8 , "component-inherit" :17 , "debug" :18 , "engine.io-parser" :19 , "parseqs" :29 , "ws" :31 } ] , 14 :[ function ( _dereq_ , module , exports ) {
23922388// browser shim for xmlhttprequest module
23932389var hasCORS = _dereq_ ( 'has-cors' ) ;
23942390
@@ -2410,6 +2406,59 @@ module.exports = function(opts) {
24102406}
24112407
24122408} , { "has-cors" :25 } ] , 15 :[ function ( _dereq_ , module , exports ) {
2409+ ( function ( global ) {
2410+ /**
2411+ * Create a blob builder even when vendor prefixes exist
2412+ */
2413+
2414+ var BlobBuilder = global . BlobBuilder
2415+ || global . WebKitBlobBuilder
2416+ || global . MSBlobBuilder
2417+ || global . MozBlobBuilder ;
2418+
2419+ /**
2420+ * Check if Blob constructor is supported
2421+ */
2422+
2423+ var blobSupported = ( function ( ) {
2424+ try {
2425+ var b = new Blob ( [ 'hi' ] ) ;
2426+ return b . size == 2 ;
2427+ } catch ( e ) {
2428+ return false ;
2429+ }
2430+ } ) ( ) ;
2431+
2432+ /**
2433+ * Check if BlobBuilder is supported
2434+ */
2435+
2436+ var blobBuilderSupported = BlobBuilder
2437+ && BlobBuilder . prototype . append
2438+ && BlobBuilder . prototype . getBlob ;
2439+
2440+ function BlobBuilderConstructor ( ary , options ) {
2441+ options = options || { } ;
2442+
2443+ var bb = new BlobBuilder ( ) ;
2444+ for ( var i = 0 ; i < ary . length ; i ++ ) {
2445+ bb . append ( ary [ i ] ) ;
2446+ }
2447+ return ( options . type ) ? bb . getBlob ( options . type ) : bb . getBlob ( ) ;
2448+ } ;
2449+
2450+ module . exports = ( function ( ) {
2451+ if ( blobSupported ) {
2452+ return global . Blob ;
2453+ } else if ( blobBuilderSupported ) {
2454+ return BlobBuilderConstructor ;
2455+ } else {
2456+ return undefined ;
2457+ }
2458+ } ) ( ) ;
2459+
2460+ } ) . call ( this , typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : { } )
2461+ } , { } ] , 16 :[ function ( _dereq_ , module , exports ) {
24132462
24142463/**
24152464 * Expose `Emitter`.
@@ -2575,15 +2624,15 @@ Emitter.prototype.hasListeners = function(event){
25752624 return ! ! this . listeners ( event ) . length ;
25762625} ;
25772626
2578- } , { } ] , 16 :[ function ( _dereq_ , module , exports ) {
2627+ } , { } ] , 17 :[ function ( _dereq_ , module , exports ) {
25792628
25802629module . exports = function ( a , b ) {
25812630 var fn = function ( ) { } ;
25822631 fn . prototype = b . prototype ;
25832632 a . prototype = new fn ;
25842633 a . prototype . constructor = a ;
25852634} ;
2586- } , { } ] , 17 :[ function ( _dereq_ , module , exports ) {
2635+ } , { } ] , 18 :[ function ( _dereq_ , module , exports ) {
25872636
25882637/**
25892638 * Expose `debug()` as the module.
@@ -2722,7 +2771,7 @@ try {
27222771 if ( window . localStorage ) debug . enable ( localStorage . debug ) ;
27232772} catch ( e ) { }
27242773
2725- } , { } ] , 18 :[ function ( _dereq_ , module , exports ) {
2774+ } , { } ] , 19 :[ function ( _dereq_ , module , exports ) {
27262775( function ( global ) {
27272776/**
27282777 * Module dependencies.
@@ -3269,7 +3318,7 @@ exports.decodePayloadAsBinary = function (data, binaryType, callback) {
32693318} ;
32703319
32713320} ) . call ( this , typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : { } )
3272- } , { "./keys" :19 , "after" :20 , "arraybuffer.slice" :21 , "base64-arraybuffer" :22 , "blob" :23 , "utf8" :24 } ] , 19 :[ function ( _dereq_ , module , exports ) {
3321+ } , { "./keys" :20 , "after" :21 , "arraybuffer.slice" :22 , "base64-arraybuffer" :23 , "blob" :15 , "utf8" :24 } ] , 20 :[ function ( _dereq_ , module , exports ) {
32733322
32743323/**
32753324 * Gets the keys for an object.
@@ -3290,7 +3339,7 @@ module.exports = Object.keys || function keys (obj){
32903339 return arr ;
32913340} ;
32923341
3293- } , { } ] , 20 :[ function ( _dereq_ , module , exports ) {
3342+ } , { } ] , 21 :[ function ( _dereq_ , module , exports ) {
32943343module . exports = after
32953344
32963345function after ( count , callback , err_cb ) {
@@ -3320,7 +3369,7 @@ function after(count, callback, err_cb) {
33203369
33213370function noop ( ) { }
33223371
3323- } , { } ] , 21 :[ function ( _dereq_ , module , exports ) {
3372+ } , { } ] , 22 :[ function ( _dereq_ , module , exports ) {
33243373/**
33253374 * An abstraction for slicing an arraybuffer even when
33263375 * ArrayBuffer.prototype.slice is not supported
@@ -3351,7 +3400,7 @@ module.exports = function(arraybuffer, start, end) {
33513400 return result . buffer ;
33523401} ;
33533402
3354- } , { } ] , 22 :[ function ( _dereq_ , module , exports ) {
3403+ } , { } ] , 23 :[ function ( _dereq_ , module , exports ) {
33553404/*
33563405 * base64-arraybuffer
33573406 * https://github.com/niklasvh/base64-arraybuffer
@@ -3412,59 +3461,6 @@ module.exports = function(arraybuffer, start, end) {
34123461 } ;
34133462} ) ( "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/" ) ;
34143463
3415- } , { } ] , 23 :[ function ( _dereq_ , module , exports ) {
3416- ( function ( global ) {
3417- /**
3418- * Create a blob builder even when vendor prefixes exist
3419- */
3420-
3421- var BlobBuilder = global . BlobBuilder
3422- || global . WebKitBlobBuilder
3423- || global . MSBlobBuilder
3424- || global . MozBlobBuilder ;
3425-
3426- /**
3427- * Check if Blob constructor is supported
3428- */
3429-
3430- var blobSupported = ( function ( ) {
3431- try {
3432- var b = new Blob ( [ 'hi' ] ) ;
3433- return b . size == 2 ;
3434- } catch ( e ) {
3435- return false ;
3436- }
3437- } ) ( ) ;
3438-
3439- /**
3440- * Check if BlobBuilder is supported
3441- */
3442-
3443- var blobBuilderSupported = BlobBuilder
3444- && BlobBuilder . prototype . append
3445- && BlobBuilder . prototype . getBlob ;
3446-
3447- function BlobBuilderConstructor ( ary , options ) {
3448- options = options || { } ;
3449-
3450- var bb = new BlobBuilder ( ) ;
3451- for ( var i = 0 ; i < ary . length ; i ++ ) {
3452- bb . append ( ary [ i ] ) ;
3453- }
3454- return ( options . type ) ? bb . getBlob ( options . type ) : bb . getBlob ( ) ;
3455- } ;
3456-
3457- module . exports = ( function ( ) {
3458- if ( blobSupported ) {
3459- return global . Blob ;
3460- } else if ( blobBuilderSupported ) {
3461- return BlobBuilderConstructor ;
3462- } else {
3463- return undefined ;
3464- }
3465- } ) ( ) ;
3466-
3467- } ) . call ( this , typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : { } )
34683464} , { } ] , 24 :[ function ( _dereq_ , module , exports ) {
34693465( function ( global ) {
34703466/*! http://mths.be/utf8js v2.0.0 by @mathias */
@@ -4046,6 +4042,8 @@ var SCSocket = function (options) {
40464042 'fail' : 1
40474043 } ;
40484044
4045+ this . _connectAttempts = 0 ;
4046+
40494047 this . _cid = 1 ;
40504048 this . _callbackMap = { } ;
40514049 this . _destId = null ;
@@ -4069,17 +4067,32 @@ var SCSocket = function (options) {
40694067 Socket . call ( this , this . options . url , this . options ) ;
40704068 }
40714069
4072- this . _sortWeights = {
4073- subscribe : - 2 ,
4074- start : - 1
4075- } ;
4076-
40774070 this . connected = false ;
40784071 this . connecting = true ;
40794072
4073+ Socket . prototype . on . call ( this , 'open' , function ( ) {
4074+ self . _connectAttempts = 0 ;
4075+ } ) ;
4076+
40804077 Socket . prototype . on . call ( this , 'error' , function ( err ) {
40814078 self . connecting = false ;
40824079 self . _emitBuffer = [ ] ;
4080+
4081+ // Exponential backoff reconnect
4082+ if ( ! self . connected ) {
4083+ var exponent = ++ self . _connectAttempts ;
4084+ if ( exponent > 5 ) {
4085+ exponent = 5 ;
4086+ }
4087+ var reconnectOptions = self . options . autoReconnectOptions ;
4088+ var initialTimeout = Math . round ( ( reconnectOptions . delay + ( reconnectOptions . randomness || 0 ) * Math . random ( ) ) * 1000 ) ;
4089+ var backoutTimeout = Math . round ( initialTimeout * Math . pow ( 1.5 , exponent ) ) ;
4090+ setTimeout ( function ( ) {
4091+ if ( ! self . connected && ! self . connecting ) {
4092+ self . connect ( ) ;
4093+ }
4094+ } , backoutTimeout ) ;
4095+ }
40834096 } ) ;
40844097
40854098 Socket . prototype . on . call ( this , 'close' , function ( ) {
@@ -4241,17 +4254,46 @@ SCSocket.prototype._emit = function (event, data, callback) {
42414254SCSocket . prototype . _flushEmitBuffer = function ( ) {
42424255 var self = this ;
42434256
4244- // 'subscribe' and 'ready' events have priority over user events.
4245- this . _emitBuffer . sort ( function ( a , b ) {
4246- return ( self . _sortWeights [ a . event ] || 0 ) - ( self . _sortWeights [ b . event ] || 0 ) ;
4247- } ) ;
4257+ /*
4258+ 'subscribe' and 'ready' events have priority over other events
4259+ so they get emitted first.
4260+ */
4261+
4262+ var subscribeEvents = [ ] ;
4263+ var readyEvents = [ ] ;
4264+ var otherEvents = [ ] ;
42484265
4249- var len = this . _emitBuffer . length ;
42504266 var ev ;
4267+ var len = this . _emitBuffer . length ;
42514268 for ( var i = 0 ; i < len ; i ++ ) {
42524269 ev = this . _emitBuffer [ i ] ;
4270+ if ( ev . event == 'subscribe' ) {
4271+ subscribeEvents . push ( ev ) ;
4272+ } else if ( ev . event == 'ready' ) {
4273+ readyEvents . push ( ev ) ;
4274+ } else {
4275+ otherEvents . push ( ev ) ;
4276+ }
4277+ }
4278+
4279+ len = subscribeEvents . length ;
4280+ for ( var j = 0 ; j < len ; j ++ ) {
4281+ ev = subscribeEvents [ j ] ;
4282+ this . _emit ( ev . event , ev . data , ev . callback ) ;
4283+ }
4284+
4285+ len = readyEvents . length ;
4286+ for ( var k = 0 ; k < len ; k ++ ) {
4287+ ev = readyEvents [ k ] ;
42534288 this . _emit ( ev . event , ev . data , ev . callback ) ;
42544289 }
4290+
4291+ len = otherEvents . length ;
4292+ for ( var m = 0 ; m < len ; m ++ ) {
4293+ ev = otherEvents [ m ] ;
4294+ this . _emit ( ev . event , ev . data , ev . callback ) ;
4295+ }
4296+
42554297 this . _emitBuffer = [ ] ;
42564298} ;
42574299
0 commit comments