diff --git a/lib/faye/websocket.js b/lib/faye/websocket.js index 699cc39..232b2c2 100644 --- a/lib/faye/websocket.js +++ b/lib/faye/websocket.js @@ -46,9 +46,15 @@ var WebSocket = function(request, socket, head, supportedProtos, options) { var Parser = getParser(request); this._parser = new Parser(this, {protocols: supportedProtos}); + var self = this; + this._sendBuffer = []; + process.nextTick(function() { self._open() }); + var handshake = this._parser.handshakeResponse(head); try { this._stream.write(handshake, 'binary') } catch (e) {} + if (this._parser.isOpen()) this.readyState = API.OPEN; + this.protocol = this._parser.protocol || ''; this.version = this._parser.getVersion(); @@ -62,10 +68,6 @@ var WebSocket = function(request, socket, head, supportedProtos, options) { self.ping(id); }, this._ping * 1000); - var self = this; - this._sendBuffer = []; - process.nextTick(function() { self._open() }); - this._stream.addListener('data', function(data) { var response = self._parser.parse(data); if (!response) return;