Set readyState to OPEN as soon as possible.

This commit is contained in:
James Coglan
2012-02-11 13:36:12 +00:00
parent fe4314e62b
commit a9659df7d8
+6 -4
View File
@@ -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;