Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .zuul.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ browsers:
- name: safari
version: latest
- name: ie
version: 6..latest
version: 10
platform: Windows 2012
- name: ie
version: [6..9, latest]
- name: iphone
version: oldest..latest
34 changes: 32 additions & 2 deletions lib/manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ function Manager(socket, opts){
this.engine = socket;
this.connected = 0;
this.attempts = 0;
this.encoding = false;
this.packetBuffer = [];
this.open();
}

Expand Down Expand Up @@ -266,18 +268,46 @@ Manager.prototype.destroy = function(socket){

Manager.prototype.packet = function(packet){
debug('writing packet %j', packet);
this.engine.write(parser.encode(packet));
var self = this;

if (!self.encoding) { // encode, then write to engine with result
self.encoding = true;
parser.encode(packet, function(encodedPacket) {
self.engine.write(encodedPacket);
self.encoding = false;
self.processPacketQueue();
});
} else { // add packet to the queue
self.packetBuffer.push(packet);
}
};

/**
* Clean up transport subscriptions.
* If packet buffer is non-empty, begins encoding the
* next packet in line.
*
* @api private
*/

Manager.prototype.processPacketQueue = function() {
if (this.packetBuffer.length > 0 && !this.encoding) {
var pack = this.packetBuffer.shift();
this.packet(pack);
}
}

/**
* Clean up transport subscriptions and packet buffer.
*
* @api private
*/

Manager.prototype.cleanup = function(){
var sub;
while (sub = this.subs.shift()) sub.destroy();

this.packetBuffer = [];
this.encoding = false;
};

/**
Expand Down
10 changes: 9 additions & 1 deletion lib/socket.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ var toArray = require('to-array');
var on = require('./on');
var bind = require('bind');
var debug = require('debug')('socket.io-client:socket');
var hasBin = require('has-binarydata');
var indexOf = require('indexof');

/**
* Module exports.
Expand Down Expand Up @@ -106,7 +108,9 @@ Socket.prototype.emit = function(ev){
}

var args = toArray(arguments);
var packet = { type: parser.EVENT, data: args };
var parserType = parser.EVENT; // default
if (hasBin(args)) { parserType = parser.BINARY_EVENT; } // binary
var packet = { type: parserType, data: args };

// event ack callback
if ('function' == typeof args[args.length - 1]) {
Expand Down Expand Up @@ -198,6 +202,10 @@ Socket.prototype.onpacket = function(packet){
this.onevent(packet);
break;

case parser.BINARY_EVENT:
this.onevent(packet);
break;

case parser.ACK:
this.onack(packet);
break;
Expand Down
15 changes: 10 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,28 @@
"client"
],
"dependencies": {
"engine.io-client": "0.9.0",
"engine.io-client": "LearnBoost/engine.io-client#b434277",
"emitter": "http://github.com/component/emitter/archive/1.0.1.tar.gz",
"bind": "http://github.com/component/bind/archive/0.0.1.tar.gz",
"object-component": "0.0.3",
"socket.io-parser": "1.1.2",
"socket.io-parser": "2.0.0",
"parseuri": "0.0.2",
"to-array": "0.1.3",
"debug": "0.7.4"
"debug": "0.7.4",
"has-binarydata": "0.0.31",
"indexof": "0.0.1"
},
"devDependencies": {
"socket.io": "https://github.com/LearnBoost/socket.io/archive/980b6a7c40ff4d32bd3377cc1f16009f3bf189c9.tar.gz",
"mocha": "1.16.2",
"zuul": "1.5.2",
"zuul": "1.5.4",
"istanbul": "0.2.1",
"expect.js": "0.2.0",
"uglify-js": "2.4.8",
"browserify": "2.35.1"
"browserify": "2.35.1",
"base64-js": "0.0.6",
"text-blob-builder": "0.0.1",
"has-cors": "1.0.3"
},
"scripts": {
"test": "make test"
Expand Down
Loading