@dainprotocol/tunnel 1.1.13 → 1.1.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client/index.js +5 -0
- package/dist/server/index.js +16 -9
- package/package.json +1 -1
package/dist/client/index.js
CHANGED
|
@@ -274,6 +274,11 @@ class DainTunnel extends events_1.EventEmitter {
|
|
|
274
274
|
}
|
|
275
275
|
return;
|
|
276
276
|
}
|
|
277
|
+
// Optimize socket for low-latency streaming
|
|
278
|
+
const socket = res.socket || res.connection;
|
|
279
|
+
if (socket && socket.setNoDelay) {
|
|
280
|
+
socket.setNoDelay(true); // Disable Nagle's algorithm
|
|
281
|
+
}
|
|
277
282
|
console.log(`[SSE E2E] Client: Service accepted SSE connection ${message.id}, streaming started`);
|
|
278
283
|
// Process SSE stream
|
|
279
284
|
let buffer = '';
|
package/dist/server/index.js
CHANGED
|
@@ -20,16 +20,18 @@ const url_1 = require("url");
|
|
|
20
20
|
*/
|
|
21
21
|
function flushSSE(res) {
|
|
22
22
|
try {
|
|
23
|
-
//
|
|
24
|
-
//
|
|
23
|
+
// Node.js TCP sockets use cork/uncork for buffering control
|
|
24
|
+
// We uncork to force immediate transmission of buffered data
|
|
25
25
|
const socket = res.socket;
|
|
26
|
-
if (socket
|
|
27
|
-
socket
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
26
|
+
if (socket) {
|
|
27
|
+
// If socket is corked, uncork it to flush immediately
|
|
28
|
+
if (socket.uncork) {
|
|
29
|
+
socket.uncork();
|
|
30
|
+
}
|
|
31
|
+
// Disable Nagle's algorithm for low-latency streaming
|
|
32
|
+
if (socket.setNoDelay && !socket._noDelay) {
|
|
33
|
+
socket.setNoDelay(true);
|
|
34
|
+
}
|
|
33
35
|
}
|
|
34
36
|
}
|
|
35
37
|
catch (error) {
|
|
@@ -480,6 +482,11 @@ class DainTunnelServer {
|
|
|
480
482
|
// Setup SSE connection
|
|
481
483
|
const sseId = (0, uuid_1.v4)();
|
|
482
484
|
console.log(`[SSE E2E] Server: Establishing SSE connection ${sseId} from browser to ${req.url}`);
|
|
485
|
+
// Optimize TCP socket for low-latency streaming
|
|
486
|
+
const socket = req.socket || req.connection;
|
|
487
|
+
if (socket && socket.setNoDelay) {
|
|
488
|
+
socket.setNoDelay(true); // Disable Nagle's algorithm for immediate transmission
|
|
489
|
+
}
|
|
483
490
|
// Set SSE headers with anti-buffering directives
|
|
484
491
|
// Note: Do NOT set 'Connection: keep-alive' - it's forbidden in HTTP/2 and will cause immediate disconnect
|
|
485
492
|
res.writeHead(200, {
|