From ddc8133c5b923c8caac327f2e68cfeb2bd087cc6 Mon Sep 17 00:00:00 2001 From: WebStreamr <210764791+webstreamr@users.noreply.github.com> Date: Wed, 24 Sep 2025 18:29:27 +0000 Subject: [PATCH] fix: always move errors up and external urls down --- src/utils/StreamResolver.ts | 12 ++- .../__snapshots__/StreamResolver.test.ts.snap | 94 +++++++++---------- 2 files changed, 55 insertions(+), 51 deletions(-) diff --git a/src/utils/StreamResolver.ts b/src/utils/StreamResolver.ts index 5b78976..78cdb56 100644 --- a/src/utils/StreamResolver.ts +++ b/src/utils/StreamResolver.ts @@ -69,6 +69,14 @@ export class StreamResolver { await Promise.all(sourcePromises); urlResults.sort((a, b) => { + if (a.error || b.error) { + return a.isExternal ? -1 : 1; + } + + if (a.isExternal || b.isExternal) { + return a.isExternal ? 1 : -1; + } + const heightComparison = (b.meta?.height ?? 0) - (a.meta?.height ?? 0); if (heightComparison !== 0) { return heightComparison; @@ -79,10 +87,6 @@ export class StreamResolver { return bytesComparison; } - if (a.isExternal || b.isExternal) { - return a.isExternal ? 1 : -1; - } - return a.label.localeCompare(b.label); }); diff --git a/src/utils/__snapshots__/StreamResolver.test.ts.snap b/src/utils/__snapshots__/StreamResolver.test.ts.snap index c097f06..0d8d429 100644 --- a/src/utils/__snapshots__/StreamResolver.test.ts.snap +++ b/src/utils/__snapshots__/StreamResolver.test.ts.snap @@ -30,21 +30,48 @@ exports[`resolve adds error info 2`] = ` "streams": [ { "behaviorHints": { - "bingeGroup": "webstreamr-hostercom", "notWebReady": true, }, + "externalUrl": "https://example5.com/", "name": "WebStreamr 🇩🇪", - "title": "🔗 working1", - "url": "https://working2.com/", + "title": "🔗 hoster.com +❌ Request failed with status 418 (I'm a tea pot). Request-id: test.", }, { "behaviorHints": { - "bingeGroup": "webstreamr-hostercom", "notWebReady": true, }, + "externalUrl": "https://example4.com/", "name": "WebStreamr 🇩🇪", - "title": "🔗 working2", - "url": "https://working1.com/", + "title": "🔗 hoster.com +❌ Remote server has issues. We can't fix this, please try later again.", + }, + { + "behaviorHints": { + "notWebReady": true, + }, + "externalUrl": "https://example3.com/", + "name": "WebStreamr 🇩🇪", + "title": "🔗 hoster.com +⏳ Request queue is full. Please try again later or consider self-hosting.", + }, + { + "behaviorHints": { + "notWebReady": true, + }, + "externalUrl": "https://example2.com/", + "name": "WebStreamr 🇩🇪", + "title": "🔗 hoster.com +🐢 Request timed out.", + }, + { + "behaviorHints": { + "notWebReady": true, + }, + "externalUrl": "https://example2.com/", + "name": "WebStreamr 🇩🇪", + "title": "🔗 hoster.com +❌ Request failed. Request-id: test.", }, { "behaviorHints": { @@ -53,34 +80,7 @@ exports[`resolve adds error info 2`] = ` "externalUrl": "https://example.com/", "name": "WebStreamr 🇩🇪", "title": "🔗 hoster.com -⚠️ Request was blocked. Reason: cloudflare_challenge", - }, - { - "behaviorHints": { - "notWebReady": true, - }, - "externalUrl": "https://example.com/", - "name": "WebStreamr 🇩🇪", - "title": "🔗 hoster.com -⚠️ Request was blocked. Reason: cloudflare_censor", - }, - { - "behaviorHints": { - "notWebReady": true, - }, - "externalUrl": "https://example.com/", - "name": "WebStreamr 🇩🇪", - "title": "🔗 hoster.com -⚠️ MediaFlow Proxy authentication failed. Please set the correct password.", - }, - { - "behaviorHints": { - "notWebReady": true, - }, - "externalUrl": "https://example.com/", - "name": "WebStreamr 🇩🇪", - "title": "🔗 hoster.com -⚠️ Request was blocked. Reason: unknown", +🚦 Too many recent timeouts. Please try again later.", }, { "behaviorHints": { @@ -98,52 +98,52 @@ exports[`resolve adds error info 2`] = ` "externalUrl": "https://example.com/", "name": "WebStreamr 🇩🇪", "title": "🔗 hoster.com -🚦 Too many recent timeouts. Please try again later.", +⚠️ Request was blocked. Reason: unknown", }, { "behaviorHints": { "notWebReady": true, }, - "externalUrl": "https://example2.com/", + "externalUrl": "https://example.com/", "name": "WebStreamr 🇩🇪", "title": "🔗 hoster.com -❌ Request failed. Request-id: test.", +⚠️ MediaFlow Proxy authentication failed. Please set the correct password.", }, { "behaviorHints": { "notWebReady": true, }, - "externalUrl": "https://example2.com/", + "externalUrl": "https://example.com/", "name": "WebStreamr 🇩🇪", "title": "🔗 hoster.com -🐢 Request timed out.", +⚠️ Request was blocked. Reason: cloudflare_censor", }, { "behaviorHints": { "notWebReady": true, }, - "externalUrl": "https://example3.com/", + "externalUrl": "https://example.com/", "name": "WebStreamr 🇩🇪", "title": "🔗 hoster.com -⏳ Request queue is full. Please try again later or consider self-hosting.", +⚠️ Request was blocked. Reason: cloudflare_challenge", }, { "behaviorHints": { + "bingeGroup": "webstreamr-hostercom", "notWebReady": true, }, - "externalUrl": "https://example4.com/", "name": "WebStreamr 🇩🇪", - "title": "🔗 hoster.com -❌ Remote server has issues. We can't fix this, please try later again.", + "title": "🔗 working1", + "url": "https://working2.com/", }, { "behaviorHints": { + "bingeGroup": "webstreamr-hostercom", "notWebReady": true, }, - "externalUrl": "https://example5.com/", "name": "WebStreamr 🇩🇪", - "title": "🔗 hoster.com -❌ Request failed with status 418 (I'm a tea pot). Request-id: test.", + "title": "🔗 working2", + "url": "https://working1.com/", }, ], }