@torrent-tv/proxy 2.5.1 → 2.5.5
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/package.json +2 -2
- package/services/tunnel-client.js +20 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@torrent-tv/proxy",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.5",
|
|
4
4
|
"description": "Torrent proxy client that exposes webseed-like HTTP stream endpoint.",
|
|
5
5
|
"license": "GPL-3.0-or-later",
|
|
6
6
|
"publishConfig": {
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"fastify": "^5.8.5",
|
|
27
27
|
"ffmpeg-static": "^5.3.0",
|
|
28
28
|
"get-port": "^7.1.0",
|
|
29
|
-
"node-datachannel": "^0.
|
|
29
|
+
"node-datachannel": "^0.32.0",
|
|
30
30
|
"webtorrent": "^2.8.4",
|
|
31
31
|
"ws": "^8.18.2"
|
|
32
32
|
}
|
|
@@ -75,6 +75,8 @@ import { WebSocket } from "ws";
|
|
|
75
75
|
*/
|
|
76
76
|
|
|
77
77
|
const RECONNECT_DELAY_MS = 5_000;
|
|
78
|
+
/** Send a keepalive ping every 30 s to prevent Cloudflare's idle WebSocket timeout (~100 s). */
|
|
79
|
+
const KEEPALIVE_INTERVAL_MS = 30_000;
|
|
78
80
|
|
|
79
81
|
/**
|
|
80
82
|
* Create and manage the outbound WebSocket tunnel to the registry server.
|
|
@@ -89,6 +91,8 @@ export function createTunnelClient({ serverUrl, proxyId, token, proxyPort, onSig
|
|
|
89
91
|
let socket = null;
|
|
90
92
|
/** @type {ReturnType<typeof setTimeout> | null} */
|
|
91
93
|
let reconnectTimer = null;
|
|
94
|
+
/** @type {ReturnType<typeof setInterval> | null} */
|
|
95
|
+
let keepaliveTimer = null;
|
|
92
96
|
let stopped = false;
|
|
93
97
|
|
|
94
98
|
/**
|
|
@@ -118,12 +122,19 @@ export function createTunnelClient({ serverUrl, proxyId, token, proxyPort, onSig
|
|
|
118
122
|
socket = new WebSocket(wsUrl, {
|
|
119
123
|
headers: {
|
|
120
124
|
"x-proxy-id": proxyId,
|
|
121
|
-
"x-proxy-token": token
|
|
125
|
+
"x-proxy-token": token,
|
|
126
|
+
"user-agent": "torrent-tv-proxy/1.0"
|
|
122
127
|
}
|
|
123
128
|
});
|
|
124
129
|
|
|
125
130
|
socket.addEventListener("open", () => {
|
|
126
131
|
log("Tunnel connected.");
|
|
132
|
+
// Start keepalive pings to prevent Cloudflare's idle WebSocket timeout.
|
|
133
|
+
keepaliveTimer = setInterval(() => {
|
|
134
|
+
if (socket && socket.readyState === WebSocket.OPEN) {
|
|
135
|
+
send({ type: "ping" });
|
|
136
|
+
}
|
|
137
|
+
}, KEEPALIVE_INTERVAL_MS);
|
|
127
138
|
if (typeof onConnect === "function") {
|
|
128
139
|
onConnect();
|
|
129
140
|
}
|
|
@@ -163,6 +174,10 @@ export function createTunnelClient({ serverUrl, proxyId, token, proxyPort, onSig
|
|
|
163
174
|
socket.addEventListener("close", (event) => {
|
|
164
175
|
log(`Tunnel disconnected (code=${event.code}). Reconnecting in ${RECONNECT_DELAY_MS}ms...`);
|
|
165
176
|
socket = null;
|
|
177
|
+
if (keepaliveTimer !== null) {
|
|
178
|
+
clearInterval(keepaliveTimer);
|
|
179
|
+
keepaliveTimer = null;
|
|
180
|
+
}
|
|
166
181
|
if (!stopped) {
|
|
167
182
|
reconnectTimer = setTimeout(connect, RECONNECT_DELAY_MS);
|
|
168
183
|
}
|
|
@@ -273,6 +288,10 @@ export function createTunnelClient({ serverUrl, proxyId, token, proxyPort, onSig
|
|
|
273
288
|
*/
|
|
274
289
|
disconnect() {
|
|
275
290
|
stopped = true;
|
|
291
|
+
if (keepaliveTimer !== null) {
|
|
292
|
+
clearInterval(keepaliveTimer);
|
|
293
|
+
keepaliveTimer = null;
|
|
294
|
+
}
|
|
276
295
|
if (reconnectTimer != null) {
|
|
277
296
|
clearTimeout(reconnectTimer);
|
|
278
297
|
reconnectTimer = null;
|