mirror of
https://github.com/PR0M3TH3AN/bitvid.git
synced 2026-11-11 23:32:31 +00:00
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:
2 files changed
+26
-9
No files matched your search
+2
-2
@@ -135,9 +135,9 @@ function normalizeResult(result) {
|
|||||||
const peers = Number.isFinite(result.peers)
|
const peers = Number.isFinite(result.peers)
|
||||||
? Math.max(0, Number(result.peers))
|
? Math.max(0, Number(result.peers))
|
||||||
: 0;
|
: 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 webseedOnly = Boolean(result.webseedOnly) && peers === 0;
|
||||||
|
const healthy = (Boolean(result.healthy) && peers > 0) || webseedOnly;
|
||||||
|
const reason = typeof result.reason === "string" ? result.reason : "error";
|
||||||
return {
|
return {
|
||||||
healthy,
|
healthy,
|
||||||
peers: healthy ? Math.max(1, peers) : peers,
|
peers: healthy ? Math.max(1, peers) : peers,
|
||||||
|
|||||||
+24
-7
@@ -222,11 +222,19 @@ export class TorrentClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const trackers = normalizeTrackerList(TorrentClient.PROBE_TRACKERS);
|
const trackers = normalizeTrackerList(TorrentClient.PROBE_TRACKERS);
|
||||||
const { magnet: augmentedMagnet, appended, hasProbeTrackers } =
|
let { magnet: augmentedMagnet, appended, hasProbeTrackers } =
|
||||||
appendProbeTrackers(magnet, trackers);
|
appendProbeTrackers(magnet, trackers);
|
||||||
|
|
||||||
const hasMagnetWebSeed = magnet.includes("ws=") || magnet.includes("webSeed=");
|
const hasMagnetWebSeed = magnet.includes("ws=") || magnet.includes("webSeed=");
|
||||||
const hasExplicitWebSeed = Array.isArray(urlList) && urlList.length > 0;
|
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;
|
const hasWebSeed = hasMagnetWebSeed || hasExplicitWebSeed;
|
||||||
|
|
||||||
if (!hasProbeTrackers && !hasWebSeed) {
|
if (!hasProbeTrackers && !hasWebSeed) {
|
||||||
@@ -929,7 +937,21 @@ export class TorrentClient {
|
|||||||
*/
|
*/
|
||||||
async streamVideo(magnetURI, videoElement, opts = {}) {
|
async streamVideo(magnetURI, videoElement, opts = {}) {
|
||||||
try {
|
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 (
|
if (
|
||||||
effectiveMagnetURI !==
|
effectiveMagnetURI !==
|
||||||
(typeof magnetURI === "string" ? magnetURI.trim() : "")
|
(typeof magnetURI === "string" ? magnetURI.trim() : "")
|
||||||
@@ -962,11 +984,6 @@ export class TorrentClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const isFirefoxBrowser = this.isFirefox();
|
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" };
|
const chromeOptions = { strategy: "sequential" };
|
||||||
if (candidateUrls.length) {
|
if (candidateUrls.length) {
|
||||||
|
|||||||
Reference in new issue
Block a user