Skip to content

Commit

Permalink
v5.2.0 - Clone data by default so that we get consistent behaviour be…
Browse files Browse the repository at this point in the history
…tween connected and disconnected sockets
  • Loading branch information
jondubois committed Jan 2, 2017
1 parent b177f6a commit a18effe
Show file tree
Hide file tree
Showing 8 changed files with 1,917 additions and 135 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "socketcluster-client",
"main": "socketcluster.js",
"version": "5.1.1",
"version": "5.2.0",
"homepage": "https://github.com/SocketCluster/socketcluster-client",
"description": "SocketCluster JavaScript client",
"authors": [
Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ module.exports.destroy = function (options) {
return SCSocketCreator.destroy(options);
};

module.exports.version = '5.1.1';
module.exports.version = '5.2.0';
10 changes: 8 additions & 2 deletions lib/scsocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ var SCTransport = require('./sctransport').SCTransport;
var querystring = require('querystring');
var LinkedList = require('linked-list');
var base64 = require('base-64');
var cloneDeep = require('lodash.clonedeep');

var scErrors = require('sc-errors');
var InvalidArgumentsError = scErrors.InvalidArgumentsError;
Expand Down Expand Up @@ -625,7 +626,7 @@ SCSocket.prototype._flushEmitBuffer = function () {
nextNode = currentNode.next;
var eventObject = currentNode.data;
currentNode.detach();
this.transport.emitRaw(eventObject);
this.transport.emitObject(eventObject);
currentNode = nextNode;
}
};
Expand Down Expand Up @@ -655,7 +656,12 @@ SCSocket.prototype._emit = function (event, data, callback) {
};

var eventNode = new LinkedList.Item();
eventNode.data = eventObject;

if (this.options.cloneData) {
eventNode.data = cloneDeep(eventObject);
} else {
eventNode.data = eventObject;
}

eventObject.timeout = setTimeout(function () {
self._handleEventAckTimeout(eventObject, eventNode);
Expand Down
3 changes: 2 additions & 1 deletion lib/scsocketcreator.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ function connect(options) {
authEngine: null,
authTokenName: 'socketCluster.authToken',
binaryType: 'arraybuffer',
multiplex: true
multiplex: true,
cloneData: true
};
for (var i in options) {
if (options.hasOwnProperty(i)) {
Expand Down
15 changes: 11 additions & 4 deletions lib/sctransport.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ SCTransport.prototype.close = function (code, data) {
}
};

SCTransport.prototype.emitRaw = function (eventObject) {
SCTransport.prototype.emitObject = function (eventObject) {
var simpleEventObject = {
event: eventObject.event,
data: eventObject.data
Expand All @@ -265,7 +265,6 @@ SCTransport.prototype.emitRaw = function (eventObject) {
return eventObject.cid || null;
};


SCTransport.prototype._handleEventAckTimeout = function (eventObject) {
var errorMessage = "Event response for '" + eventObject.event + "' timed out";
var error = new TimeoutError(errorMessage);
Expand Down Expand Up @@ -310,7 +309,7 @@ SCTransport.prototype.emit = function (event, data, a, b) {

var cid = null;
if (this.state == this.OPEN || options.force) {
cid = this.emitRaw(eventObject);
cid = this.emitObject(eventObject);
}
return cid;
};
Expand All @@ -335,7 +334,7 @@ SCTransport.prototype.send = function (data) {
}
};

SCTransport.prototype.sendObject = function (object) {
SCTransport.prototype.serializeObject = function (object) {
var str, formatError;
try {
str = this.encode(object);
Expand All @@ -344,6 +343,14 @@ SCTransport.prototype.sendObject = function (object) {
this._onError(formatError);
}
if (!formatError) {
return str;
}
return null;
};

SCTransport.prototype.sendObject = function (object) {
var str = this.serializeObject(object);
if (str != null) {
this.send(str);
}
};
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "socketcluster-client",
"description": "SocketCluster JavaScript client",
"version": "5.1.1",
"version": "5.2.0",
"homepage": "http://socketcluster.io",
"contributors": [
{
Expand All @@ -16,6 +16,7 @@
"dependencies": {
"base-64": "0.1.0",
"linked-list": "0.1.0",
"lodash.clonedeep": "4.5.0",
"querystring": "0.2.0",
"sc-channel": "1.0.x",
"sc-emitter": "1.0.x",
Expand Down
Loading

0 comments on commit a18effe

Please sign in to comment.