@torrent-tv/proxy 2.9.107 → 2.9.109
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/CHANGELOG.md +8 -0
- package/bin/cli.js +4 -1
- package/package.json +2 -3
- package/services/data-channel-handler.js +638 -542
- package/services/hls-session-manager.js +11 -1
- package/services/webrtc-manager.js +46 -1
|
@@ -137,7 +137,17 @@ const MAX_SEEK_FAILURES = 3;
|
|
|
137
137
|
// look-ahead cap when idle, so a lingering session costs retained segments on
|
|
138
138
|
// disk, not sustained CPU. Active playback refreshes the timer on every segment
|
|
139
139
|
// fetch, so it never expires mid-watch.
|
|
140
|
-
|
|
140
|
+
// How long a session outlives the BROWSER, not the viewing. Since server
|
|
141
|
+
// 0.8.103 a browser that holds a session re-asserts it every 30 s, so an open
|
|
142
|
+
// tab never consumes this at all — not while paused, not across a three-hour
|
|
143
|
+
// film. What is left is the case where the browser has genuinely gone: the tab
|
|
144
|
+
// was killed without releasing, the phone slept, the network dropped. Keeping
|
|
145
|
+
// the session means such a viewer comes back to a warm encoder instead of
|
|
146
|
+
// waiting out a cold start; the cost while nobody is there is disk for the
|
|
147
|
+
// produced segments, since the encoder is suspended and burns no CPU, and that
|
|
148
|
+
// disk is already bounded by the pool's 10 GB cap with eviction. Thirty minutes
|
|
149
|
+
// covers a meal, a phone call or a lift ride.
|
|
150
|
+
const DEFAULT_SESSION_TTL_MS = 30 * 60 * 1000;
|
|
141
151
|
const DEFAULT_STARTUP_WAIT_MS = 5_000;
|
|
142
152
|
// Realtime budget — runtime downswitch (software encoder only). Periodically
|
|
143
153
|
// check each active software-transcode session's ffmpeg `speed`; when it stays
|
|
@@ -429,5 +429,50 @@ export function createWebRtcManager({ sendSignal, onDataChannel, onLog, udpPort,
|
|
|
429
429
|
}
|
|
430
430
|
}
|
|
431
431
|
|
|
432
|
-
|
|
432
|
+
/**
|
|
433
|
+
* What the transport itself is doing for one session.
|
|
434
|
+
*
|
|
435
|
+
* The discriminator for a send queue that stops draining. `bufferedAmount`
|
|
436
|
+
* alone says only that bytes are stuck in OUR queue; these say whether they
|
|
437
|
+
* are leaving the machine:
|
|
438
|
+
*
|
|
439
|
+
* - `bytesSent` climbing while the queue climbs → packets ARE going out and
|
|
440
|
+
* nothing is acknowledging them: the path back is broken.
|
|
441
|
+
* - `bytesSent` flat while the queue climbs → SCTP is not transmitting at
|
|
442
|
+
* all: the peer's receive window is closed, or congestion control has
|
|
443
|
+
* collapsed. `bytesReceived` still climbing at the same time proves the
|
|
444
|
+
* peer is alive and its packets still reach us, i.e. the failure is
|
|
445
|
+
* one-directional.
|
|
446
|
+
* - both flat → nothing crosses in either direction.
|
|
447
|
+
*
|
|
448
|
+
* @param {string} sessionId
|
|
449
|
+
* @returns {{ bytesSent: number, bytesReceived: number, rtt: number, pair: string, state: string, iceState: string } | null}
|
|
450
|
+
*/
|
|
451
|
+
function getTransportSnapshot(sessionId) {
|
|
452
|
+
const pc = peers.get(sessionId);
|
|
453
|
+
if (!pc) {
|
|
454
|
+
return null;
|
|
455
|
+
}
|
|
456
|
+
const read = (fn, fallback) => {
|
|
457
|
+
try {
|
|
458
|
+
return fn();
|
|
459
|
+
} catch {
|
|
460
|
+
return fallback;
|
|
461
|
+
}
|
|
462
|
+
};
|
|
463
|
+
const pair = read(() => pc.getSelectedCandidatePair(), null);
|
|
464
|
+
return {
|
|
465
|
+
bytesSent: read(() => pc.bytesSent(), -1),
|
|
466
|
+
bytesReceived: read(() => pc.bytesReceived(), -1),
|
|
467
|
+
rtt: read(() => pc.rtt(), -1),
|
|
468
|
+
pair: pair
|
|
469
|
+
? `${pair.local?.address}:${pair.local?.port}->${pair.remote?.address}:${pair.remote?.port}` +
|
|
470
|
+
` (${pair.local?.type}/${pair.remote?.type})`
|
|
471
|
+
: "none",
|
|
472
|
+
state: read(() => pc.state(), "?"),
|
|
473
|
+
iceState: read(() => pc.iceState(), "?")
|
|
474
|
+
};
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
return { handleSignal, closeSession, dispose, getTransportSnapshot };
|
|
433
478
|
}
|