Skip to content

Commit 7b49973

Browse files
committed
v11.1.0
1 parent c3ec820 commit 7b49973

File tree

6 files changed

+73
-64
lines changed

6 files changed

+73
-64
lines changed

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "socketcluster-client",
33
"main": "socketcluster.js",
4-
"version": "11.0.2",
4+
"version": "11.1.0",
55
"homepage": "https://github.com/SocketCluster/socketcluster-client",
66
"description": "SocketCluster JavaScript client",
77
"authors": [

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ module.exports.destroy = function (socket) {
1818

1919
module.exports.clients = SCSocketCreator.clients;
2020

21-
module.exports.version = '11.0.2';
21+
module.exports.version = '11.1.0';

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "socketcluster-client",
33
"description": "SocketCluster JavaScript client",
4-
"version": "11.0.2",
4+
"version": "11.1.0",
55
"homepage": "http://socketcluster.io",
66
"contributors": [
77
{
@@ -27,7 +27,7 @@
2727
"sc-errors": "^1.4.0",
2828
"sc-formatter": "^3.0.1",
2929
"uuid": "3.2.1",
30-
"ws": "^5.1.1"
30+
"ws": "5.1.1"
3131
},
3232
"browser": {
3333
"ws": "./lib/ws-browser.js"

socketcluster.js

Lines changed: 64 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
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){
55
var SCSocket = _dereq_('./lib/scsocket');
@@ -22,7 +22,7 @@ module.exports.destroy = function (socket) {
2222

2323
module.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) {
403401
SCSocket.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+
466474
SCSocket.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

677688
SCSocket.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

13211331
var 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+
14241433
SCTransport.prototype._onOpen = function () {
14251434
var self = this;
14261435

socketcluster.min.js

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)