11/**
2- * SocketCluster JavaScript client v11.0.2
2+ * SocketCluster JavaScript client v11.1.0
33 */
44( function ( f ) { if ( typeof exports === "object" && typeof module !== "undefined" ) { module . exports = f ( ) } else if ( typeof define === "function" && define . amd ) { define ( [ ] , f ) } else { var g ; if ( typeof window !== "undefined" ) { g = window } else if ( typeof global !== "undefined" ) { g = global } else if ( typeof self !== "undefined" ) { g = self } else { g = this } g . socketCluster = f ( ) } } ) ( function ( ) { var define , module , exports ; return ( function ( ) { function r ( e , n , t ) { function o ( i , f ) { if ( ! n [ i ] ) { if ( ! e [ i ] ) { var c = "function" == typeof require && require ; if ( ! f && c ) return c ( i , ! 0 ) ; if ( u ) return u ( i , ! 0 ) ; var a = new Error ( "Cannot find module '" + i + "'" ) ; throw a . code = "MODULE_NOT_FOUND" , a } var p = n [ i ] = { exports :{ } } ; e [ i ] [ 0 ] . call ( p . exports , function ( r ) { var n = e [ i ] [ 1 ] [ r ] ; return o ( n || r ) } , p , p . exports , r , e , n , t ) } return n [ i ] . exports } for ( var u = "function" == typeof require && require , i = 0 ; i < t . length ; i ++ ) o ( t [ i ] ) ; return o } return r } ) ( ) ( { 1 :[ function ( _dereq_ , module , exports ) {
55var SCSocket = _dereq_ ( './lib/scsocket' ) ;
@@ -22,7 +22,7 @@ module.exports.destroy = function (socket) {
2222
2323module . exports . clients = SCSocketCreator . clients ;
2424
25- module . exports . version = '11.0.2 ' ;
25+ module . exports . version = '11.1.0 ' ;
2626
2727} , { "./lib/scsocket" :4 , "./lib/scsocketcreator" :5 , "component-emitter" :12 } ] , 2 :[ function ( _dereq_ , module , exports ) {
2828( function ( global ) {
@@ -285,18 +285,16 @@ var SCSocket = function (opts) {
285285 this . options . query = querystring . parse ( this . options . query ) ;
286286 }
287287
288- if ( this . options . autoConnect ) {
289- this . connect ( ) ;
290- }
291-
292288 this . _channelEmitter = new Emitter ( ) ;
293289
294- if ( isBrowser && this . disconnectOnUnload && global . addEventListener ) {
295- this . _unloadHandler = function ( ) {
296- self . disconnect ( ) ;
297- } ;
290+ this . _unloadHandler = function ( ) {
291+ self . disconnect ( ) ;
292+ } ;
298293
299- global . addEventListener ( 'beforeunload' , this . _unloadHandler , false ) ;
294+ if ( this . options . autoConnect ) {
295+ this . connect ( ) ;
296+ } else {
297+ this . activate ( ) ;
300298 }
301299} ;
302300
@@ -403,6 +401,8 @@ SCSocket.prototype.deauthenticate = function (callback) {
403401SCSocket . prototype . connect = SCSocket . prototype . open = function ( ) {
404402 var self = this ;
405403
404+ this . activate ( ) ;
405+
406406 if ( this . state == this . CLOSED ) {
407407 this . pendingReconnect = false ;
408408 this . pendingReconnectTimeout = null ;
@@ -463,10 +463,19 @@ SCSocket.prototype.disconnect = function (code, data) {
463463 }
464464} ;
465465
466+ SCSocket . prototype . activate = function ( ) {
467+ if ( isBrowser && this . disconnectOnUnload && global . addEventListener && ! this . active ) {
468+ global . addEventListener ( 'beforeunload' , this . _unloadHandler , false ) ;
469+ }
470+ this . _clientMap [ this . clientId ] = this ;
471+ this . active = true ;
472+ } ;
473+
466474SCSocket . prototype . destroy = function ( code , data ) {
467- if ( this . _unloadHandler ) {
475+ if ( isBrowser && global . removeEventListener ) {
468476 global . removeEventListener ( 'beforeunload' , this . _unloadHandler , false ) ;
469477 }
478+ this . active = false ;
470479 this . disconnect ( code , data ) ;
471480 delete this . _clientMap [ this . clientId ] ;
472481} ;
@@ -671,7 +680,9 @@ SCSocket.prototype._onSCOpen = function (status) {
671680 self . processPendingSubscriptions ( ) ;
672681 } ) ;
673682
674- this . _flushEmitBuffer ( ) ;
683+ if ( this . state == this . OPEN ) {
684+ this . _flushEmitBuffer ( ) ;
685+ }
675686} ;
676687
677688SCSocket . prototype . _onSCError = function ( err ) {
@@ -864,7 +875,6 @@ SCSocket.prototype._emit = function (event, data, callback) {
864875 } , this . ackTimeout ) ;
865876
866877 this . _emitBuffer . append ( eventNode ) ;
867-
868878 if ( this . state == this . OPEN ) {
869879 this . _flushEmitBuffer ( ) ;
870880 }
@@ -1319,6 +1329,8 @@ var BadConnectionError = scErrors.BadConnectionError;
13191329
13201330
13211331var SCTransport = function ( authEngine , codecEngine , options ) {
1332+ var self = this ;
1333+
13221334 this . state = this . CLOSED ;
13231335 this . auth = authEngine ;
13241336 this . codec = codecEngine ;
@@ -1332,53 +1344,14 @@ var SCTransport = function (authEngine, codecEngine, options) {
13321344 this . _callbackMap = { } ;
13331345 this . _batchSendList = [ ] ;
13341346
1335- this . open ( ) ;
1336- } ;
1337-
1338- SCTransport . prototype = Object . create ( Emitter . prototype ) ;
1339-
1340- SCTransport . CONNECTING = SCTransport . prototype . CONNECTING = 'connecting' ;
1341- SCTransport . OPEN = SCTransport . prototype . OPEN = 'open' ;
1342- SCTransport . CLOSED = SCTransport . prototype . CLOSED = 'closed' ;
1343-
1344- SCTransport . prototype . uri = function ( ) {
1345- var query = this . options . query || { } ;
1346- var schema = this . options . secure ? 'wss' : 'ws' ;
1347-
1348- if ( this . options . timestampRequests ) {
1349- query [ this . options . timestampParam ] = ( new Date ( ) ) . getTime ( ) ;
1350- }
1351-
1352- query = querystring . encode ( query ) ;
1353-
1354- if ( query . length ) {
1355- query = '?' + query ;
1356- }
1357-
1358- var host ;
1359- if ( this . options . host ) {
1360- host = this . options . host ;
1361- } else {
1362- var port = '' ;
1363-
1364- if ( this . options . port && ( ( schema == 'wss' && this . options . port != 443 )
1365- || ( schema == 'ws' && this . options . port != 80 ) ) ) {
1366- port = ':' + this . options . port ;
1367- }
1368- host = this . options . hostname + port ;
1369- }
1370-
1371- return schema + '://' + host + this . options . path + query ;
1372- } ;
1373-
1374- SCTransport . prototype . open = function ( ) {
1375- var self = this ;
1347+ // Open the connection.
13761348
13771349 this . state = this . CONNECTING ;
13781350 var uri = this . uri ( ) ;
13791351
13801352 var wsSocket = createWebSocket ( uri , this . options ) ;
13811353 wsSocket . binaryType = this . options . binaryType ;
1354+
13821355 this . socket = wsSocket ;
13831356
13841357 wsSocket . onopen = function ( ) {
@@ -1421,6 +1394,42 @@ SCTransport.prototype.open = function () {
14211394 } , this . connectTimeout ) ;
14221395} ;
14231396
1397+ SCTransport . prototype = Object . create ( Emitter . prototype ) ;
1398+
1399+ SCTransport . CONNECTING = SCTransport . prototype . CONNECTING = 'connecting' ;
1400+ SCTransport . OPEN = SCTransport . prototype . OPEN = 'open' ;
1401+ SCTransport . CLOSED = SCTransport . prototype . CLOSED = 'closed' ;
1402+
1403+ SCTransport . prototype . uri = function ( ) {
1404+ var query = this . options . query || { } ;
1405+ var schema = this . options . secure ? 'wss' : 'ws' ;
1406+
1407+ if ( this . options . timestampRequests ) {
1408+ query [ this . options . timestampParam ] = ( new Date ( ) ) . getTime ( ) ;
1409+ }
1410+
1411+ query = querystring . encode ( query ) ;
1412+
1413+ if ( query . length ) {
1414+ query = '?' + query ;
1415+ }
1416+
1417+ var host ;
1418+ if ( this . options . host ) {
1419+ host = this . options . host ;
1420+ } else {
1421+ var port = '' ;
1422+
1423+ if ( this . options . port && ( ( schema == 'wss' && this . options . port != 443 )
1424+ || ( schema == 'ws' && this . options . port != 80 ) ) ) {
1425+ port = ':' + this . options . port ;
1426+ }
1427+ host = this . options . hostname + port ;
1428+ }
1429+
1430+ return schema + '://' + host + this . options . path + query ;
1431+ } ;
1432+
14241433SCTransport . prototype . _onOpen = function ( ) {
14251434 var self = this ;
14261435
0 commit comments