2025-03-06 12:58:57 -05:00
|
|
|
diff --git a/lib/WebSocketClient.js b/lib/WebSocketClient.js
|
|
|
|
index fb7572b382de289f7fa3ff35a9647f118f3bd4eb..0000a94607520b4b7ac71f5eee4ed297df8d1bf7 100644
|
|
|
|
--- a/lib/WebSocketClient.js
|
|
|
|
+++ b/lib/WebSocketClient.js
|
|
|
|
@@ -258,6 +258,7 @@ WebSocketClient.prototype.connect = function(requestUrl, protocols, origin, head
|
|
|
|
self.socket = socket;
|
|
|
|
self.response = response;
|
|
|
|
self.firstDataChunk = head;
|
|
|
|
+ self.emit('upgradeResponse', response);
|
|
|
|
self.validateHandshake();
|
|
|
|
});
|
|
|
|
req.on('error', handleRequestError);
|
2025-02-19 10:16:41 -08:00
|
|
|
diff --git a/lib/WebSocketConnection.js b/lib/WebSocketConnection.js
|
2025-03-06 12:58:57 -05:00
|
|
|
index 219de631dabe578e64574732fc95353a1c1047fa..93d380004b5bc58ba9895fb5a760709389641071 100644
|
2025-02-19 10:16:41 -08:00
|
|
|
--- a/lib/WebSocketConnection.js
|
|
|
|
+++ b/lib/WebSocketConnection.js
|
2022-08-10 16:21:30 -07:00
|
|
|
@@ -271,7 +271,7 @@ WebSocketConnection.prototype.handleSocketData = function(data) {
|
|
|
|
this.processReceivedData();
|
|
|
|
};
|
|
|
|
|
|
|
|
-WebSocketConnection.prototype.processReceivedData = function() {
|
|
|
|
+WebSocketConnection.prototype.processReceivedData = function(isSync = false) {
|
|
|
|
this._debug('processReceivedData');
|
|
|
|
// If we're not connected, we should ignore any data remaining on the buffer.
|
|
|
|
if (!this.connected) { return; }
|
|
|
|
@@ -320,7 +320,11 @@ WebSocketConnection.prototype.processReceivedData = function() {
|
|
|
|
process.nextTick(function() { self.emit('frame', frame); });
|
|
|
|
}
|
|
|
|
|
|
|
|
- process.nextTick(function() { self.processFrame(frame); });
|
|
|
|
+ if (isSync) {
|
|
|
|
+ self.processFrame(frame);
|
|
|
|
+ } else {
|
|
|
|
+ process.nextTick(function() { self.processFrame(frame); });
|
|
|
|
+ }
|
|
|
|
|
|
|
|
this.currentFrame = new WebSocketFrame(this.maskBytes, this.frameHeader, this.config);
|
|
|
|
|
|
|
|
@@ -329,7 +333,11 @@ WebSocketConnection.prototype.processReceivedData = function() {
|
|
|
|
// processed. We use setImmediate here instead of process.nextTick to
|
|
|
|
// explicitly indicate that we wish for other I/O to be handled first.
|
|
|
|
if (this.bufferList.length > 0) {
|
|
|
|
- setImmediateImpl(this.receivedDataHandler);
|
|
|
|
+ if (isSync) {
|
|
|
|
+ this.receivedDataHandler();
|
|
|
|
+ } else {
|
|
|
|
+ setImmediateImpl(this.receivedDataHandler);
|
|
|
|
+ }
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
@@ -353,6 +361,11 @@ WebSocketConnection.prototype.handleSocketError = function(error) {
|
|
|
|
};
|
|
|
|
|
|
|
|
WebSocketConnection.prototype.handleSocketEnd = function() {
|
|
|
|
+ // We might have socket data scheduled for a next tick, process it now.
|
|
|
|
+ if (this.bufferList.length > 0) {
|
|
|
|
+ this.receivedDataHandler(true);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
this._debug('handleSocketEnd: received socket end. state = %s', this.state);
|
|
|
|
this.receivedEnd = true;
|
|
|
|
if (this.state === STATE_CLOSED) {
|