client now ignores unsupported upgrades

This commit is contained in:
Andor Goetzendorff
2013-01-17 17:34:25 +01:00
parent d2196bfbc8
commit 05c4bf02fe
2 changed files with 28 additions and 1 deletions

View File

@@ -364,7 +364,7 @@ Socket.prototype.onHandshake = function (data) {
this.emit('handshake', data);
this.id = data.sid;
this.transport.query.sid = data.sid;
this.upgrades = data.upgrades;
this.upgrades = this.filterUpgrades(data.upgrades);
this.pingInterval = data.pingInterval;
this.pingTimeout = data.pingTimeout;
this.onOpen();
@@ -498,6 +498,22 @@ Socket.prototype.onClose = function (reason, desc) {
}
};
/**
* Filters upgrades, returning only those matching client transports.
*
* @param {Array} server upgrades
* @api private
*
*/
Socket.prototype.filterUpgrades = function (upgrades) {
var filteredUpgrades = [];
for (var i = 0, j = upgrades.length; i<j; i++) {
if (~this.transports.indexOf(upgrades[i])) filteredUpgrades.push(upgrades[i]);
}
return filteredUpgrades;
};
/**
* Generates a random uid.
*

11
test/socket.js Normal file
View File

@@ -0,0 +1,11 @@
describe('Socket', function () {
describe('filterUpgrades', function () {
it('should return only available transports', function () {
var socket = new eio.Socket({'transports': ['polling']});
expect(socket.filterUpgrades(['polling','websocket'])).to.eql(['polling']);
});
});
});