mirror of
https://github.com/socketio/socket.io.git
synced 2026-04-30 03:00:39 -04:00
client now ignores unsupported upgrades
This commit is contained in:
@@ -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
11
test/socket.js
Normal 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']);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
Reference in New Issue
Block a user