Skip to content

Commit

Permalink
switchProtocols without upgradeHead.
Browse files Browse the repository at this point in the history
  • Loading branch information
stephank committed Apr 4, 2012
1 parent 54630ee commit 0ca0d20
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions lib/faye/websocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,27 +52,23 @@ var WebSocket = function(request, response, supportedProtos, options) {
this.protocol = self._parser.protocol || '';
this.version = self._parser.getVersion();

response.switchProtocols(function(socket, head) {
response.switchProtocols(function(socket) {
self._stream = socket;
self._stream.setTimeout(0);
self._stream.setNoDelay(true);

var dataListener = function(data) {
self._stream.addListener('data', function(data) {
var reply = self._parser.parse(data);
if (!reply) return;
try { self._stream.write(reply, 'binary') } catch (e) {}
self._open();
};
self._stream.addListener('data', dataListener);

var closeListener = function() {
self.close(1006, '', false);
};
});
['close', 'end', 'error'].forEach(function(event) {
self._stream.addListener(event, closeListener);
self._stream.addListener(event, function() {
self.close(1006, '', false);
});
});

if (head.length !== 0) dataListener(head);
if (self._parser.isOpen()) self.readyState = API.OPEN;
process.nextTick(function() { self._open() });

Expand Down

0 comments on commit 0ca0d20

Please sign in to comment.