Skip to content
Merged
9 changes: 6 additions & 3 deletions lib/transports/websocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,12 @@ exports = module.exports = WebSocket;
*/

function WebSocket (mng, data, req) {
var version = req.headers['sec-websocket-version'];
var transport
, version = req.headers['sec-websocket-version'];
if (typeof version !== 'undefined' && typeof protocolVersions[version] !== 'undefined') {
return new protocolVersions[version](mng, data, req);
transport = new protocolVersions[version](mng, data, req);
}
return new protocolVersions['default'](mng, data, req);
else transport = new protocolVersions['default'](mng, data, req);
if (typeof this.name !== 'undefined') transport.name = this.name;
return transport;
};
14 changes: 14 additions & 0 deletions lib/transports/websocket/hybi-07-12.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,20 @@ WebSocket.prototype.write = function (data) {
}
};

/**
* Writes a payload.
*
* @api private
*/

WebSocket.prototype.payload = function (msgs) {
for (var i = 0, l = msgs.length; i < l; i++) {
this.write(msgs[i]);
}

return this;
};

/**
* Frame server-to-client output as a text packet.
*
Expand Down
10 changes: 5 additions & 5 deletions test/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,14 +191,14 @@ create = function (cl) {
* @api private
*/

function WSClient (port, sid) {
function WSClient (port, sid, transport) {
this.sid = sid;
this.port = port;

this.transportName = transport || 'websocket';
WebSocket.call(
this
, 'ws://localhost:' + port + '/socket.io/'
+ io.protocol + '/websocket/' + sid
+ io.protocol + '/' + this.transportName + '/' + sid
);
};

Expand Down Expand Up @@ -239,6 +239,6 @@ WSClient.prototype.packet = function (pack) {
* @api public
*/

websocket = function (cl, sid) {
return new WSClient(cl.port, sid);
websocket = function (cl, sid, transport) {
return new WSClient(cl.port, sid, transport);
};
16 changes: 15 additions & 1 deletion test/transports.flashsocket.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,20 @@ module.exports = {

io.flashPolicyServer.close();
done();
}
},

'flashsocket identifies as flashsocket': function (done) {
var cl = client(++ports)
, io = create(cl)
, messages = 0
, ws;
io.set('transports', ['flashsocket']);
io.sockets.on('connection', function (socket) {
socket.manager.transports[socket.id].name.should.equal('flashsocket');
done();
});
cl.handshake(function (sid) {
ws = websocket(cl, sid, 'flashsocket');
});
}
};
14 changes: 14 additions & 0 deletions test/transports.websocket.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,20 @@ var sio = require('socket.io')
*/

module.exports = {
'websocket identifies as websocket': function (done) {
var cl = client(++ports)
, io = create(cl)
, messages = 0
, ws;
io.set('transports', ['websocket']);
io.sockets.on('connection', function (socket) {
socket.manager.transports[socket.id].name.should.equal('websocket');
done();
});
cl.handshake(function (sid) {
ws = websocket(cl, sid);
});
},

'test that not responding to a heartbeat drops client': function (done) {
var cl = client(++ports)
Expand Down