Merge pull request #2040 from PR0M3TH3AN/ai/fix-webseed-health-and-bootstrap-1140772652148172709

Fix WebTorrent webseed health check and bootstrap behavior
This commit is contained in:
thePR0M3TH3AN authored and GitHub committed 2026-02-01 10:52:02 -05:00
commit f66e98f969
2 files changed
+26 -9

No files matched your search

+2 -2
View File
@@ -135,9 +135,9 @@ function normalizeResult(result) {
const peers = Number.isFinite(result.peers)
? Math.max(0, Number(result.peers))
: 0;
const healthy = Boolean(result.healthy) && peers > 0;
const reason = typeof result.reason === "string" ? result.reason : "error";
const webseedOnly = Boolean(result.webseedOnly) && peers === 0;
const healthy = (Boolean(result.healthy) && peers > 0) || webseedOnly;
const reason = typeof result.reason === "string" ? result.reason : "error";
return {
healthy,
peers: healthy ? Math.max(1, peers) : peers,
+24 -7
View File
@@ -222,11 +222,19 @@ export class TorrentClient {
}
const trackers = normalizeTrackerList(TorrentClient.PROBE_TRACKERS);
const { magnet: augmentedMagnet, appended, hasProbeTrackers } =
let { magnet: augmentedMagnet, appended, hasProbeTrackers } =
appendProbeTrackers(magnet, trackers);
const hasMagnetWebSeed = magnet.includes("ws=") || magnet.includes("webSeed=");
const hasExplicitWebSeed = Array.isArray(urlList) && urlList.length > 0;
if (hasExplicitWebSeed) {
const wsParams = urlList
.map((url) => `ws=${encodeURIComponent(url)}`)
.join("&");
const separator = augmentedMagnet.includes("?") ? "&" : "?";
augmentedMagnet = `${augmentedMagnet}${separator}${wsParams}`;
}
const hasWebSeed = hasMagnetWebSeed || hasExplicitWebSeed;
if (!hasProbeTrackers && !hasWebSeed) {
@@ -929,7 +937,21 @@ export class TorrentClient {
*/
async streamVideo(magnetURI, videoElement, opts = {}) {
try {
const effectiveMagnetURI = stripXsParameter(magnetURI);
let effectiveMagnetURI = stripXsParameter(magnetURI);
const candidateUrls = Array.isArray(opts?.urlList)
? opts.urlList
.map((entry) => (typeof entry === "string" ? entry.trim() : ""))
.filter((entry) => /^https?:\/\//i.test(entry))
: [];
if (candidateUrls.length > 0) {
const wsParams = candidateUrls
.map((url) => `ws=${encodeURIComponent(url)}`)
.join("&");
const separator = effectiveMagnetURI.includes("?") ? "&" : "?";
effectiveMagnetURI = `${effectiveMagnetURI}${separator}${wsParams}`;
}
if (
effectiveMagnetURI !==
(typeof magnetURI === "string" ? magnetURI.trim() : "")
@@ -962,11 +984,6 @@ export class TorrentClient {
}
const isFirefoxBrowser = this.isFirefox();
const candidateUrls = Array.isArray(opts?.urlList)
? opts.urlList
.map((entry) => (typeof entry === "string" ? entry.trim() : ""))
.filter((entry) => /^https?:\/\//i.test(entry))
: [];
const chromeOptions = { strategy: "sequential" };
if (candidateUrls.length) {