Videos: reject a source that does not load, and stop stranding the viewer

Michael Camire reported the video tab locking up after the fifth watch each
day. Three separate faults behind it.

A campaign could go live with a video address that resolves nowhere, because
the form only checked the shape of the URL. One has been sitting there since
11 September pointing at the example host, serving every Tier 1 member a black
player it could never finish. The create route now fetches the address and
refuses a host that does not answer, a 404, or a page that is not a video.

The Watch tab holds the landscape videos and Shorts holds the upright ones,
but they share one daily count. A member who cleared the tab was told to come
back tomorrow while clips were still waiting one tap away. When the other
surface still has something, the done screen now says so and links to it.

When a browser refused to autoplay, the button offered "Tap to play" but was
wired to fetch a different video, so the loaded one was thrown away and the
next also would not start. On a phone the clip could never be played at all.
The button now starts what is already loaded.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
martbost
2026-09-22 16:54:31 -05:00
parent 68a92c39ff
commit ce9f3e6904
3 changed files with 56 additions and 9 deletions
+27 -7
View File
@@ -1262,7 +1262,7 @@
const p = $('vidPlayer'); if (!p) return;
const was = !!vidState.token && !vidState.done;
try { p.pause(); p.ontimeupdate = null; p.onseeking = null; p.removeAttribute('src'); p.load(); } catch (e) {}
vidState.token = null; vidState.done = false; vidState.credited = false; vidState.maxSeen = 0;
vidState.token = null; vidState.done = false; vidState.credited = false; vidState.maxSeen = 0; vidState.needsTap = false;
if ($('vidWrap')) $('vidWrap').hidden = true;
if ($('vidBox')) { $('vidBox').hidden = false; if (was) $('vidBox').innerHTML = '<span class="muted small">Video stopped when you left the tab. Tap Load a video to start a fresh one.</span>'; }
if ($('vidStartBtn')) { $('vidStartBtn').disabled = false; $('vidStartBtn').textContent = 'Load a video'; }
@@ -1274,10 +1274,17 @@
if (!r || !r.ad) {
// same done screen as Watch ads when the day's videos are finished (Marty, 2026-09-13)
const capHit = !!(r && r.status && r.status.left <= 0), allWatched = !!(r && r.allWatched);
$('vidBox').innerHTML = (capHit || allWatched)
? '<div class="done-big"><span class="tick">&#10003;</span><b>Videos done for today</b><span class="muted small">' + (capHit ? 'That is today&rsquo;s video set (' + r.status.count + ' watched). Fresh videos tomorrow.' : 'You have watched every live video for today; each one pays once a day. New ones appear as members launch video campaigns.') + '</span></div>'
: '<span class="muted small">No member videos are live right now. Check back when a campaign is running.</span>';
if ($('vidStartBtn')) $('vidStartBtn').hidden = capHit || allWatched;
// the tab can run dry while Shorts still has clips, and both count toward the same
// daily total, so say so instead of sending them away (Marty, 2026-09-22)
const toShorts = !capHit && r && r.otherFormat === 'shorts';
$('vidBox').innerHTML = toShorts
? '<div class="done-big"><span class="tick">&#10003;</span><b>That is every video on this tab</b>'
+ '<span class="muted small">You have watched all ' + r.status.count + ' of today&rsquo;s landscape videos. The rest are upright clips that play in Shorts, and they count toward the same daily ' + r.status.cap + '. You have <b>' + r.status.left + '</b> left.</span>'
+ '<a class="btn" href="/shorts" style="margin-top:12px">Open Shorts</a></div>'
: (capHit || allWatched)
? '<div class="done-big"><span class="tick">&#10003;</span><b>Videos done for today</b><span class="muted small">' + (capHit ? 'That is today&rsquo;s video set (' + r.status.count + ' watched). Fresh videos tomorrow.' : 'You have watched every live video for today; each one pays once a day. New ones appear as members launch video campaigns.') + '</span></div>'
: '<span class="muted small">No member videos are live right now. Check back when a campaign is running.</span>';
if ($('vidStartBtn')) $('vidStartBtn').hidden = capHit || allWatched || toShorts;
$('vidBox').hidden = false;
$('vidWrap').hidden = true;
return;
@@ -1301,7 +1308,11 @@
};
$('vidStartBtn').textContent = 'Playing…';
$('vidStartBtn').disabled = true;
try { await p.play(); } catch (e) { $('vidStartBtn').disabled = false; $('vidStartBtn').textContent = 'Tap to play'; }
vidState.needsTap = false;
// a browser that refuses to autoplay leaves the clip loaded and paused; the button then has to
// START it. Wired to loadVideoAd it threw the clip away and fetched another, so on a phone the
// video could never be played at all (Marty, 2026-09-22)
try { await p.play(); } catch (e) { vidState.needsTap = true; $('vidStartBtn').disabled = false; $('vidStartBtn').textContent = 'Tap to play'; }
$('vidCta').href = ad.ctaUrl;
$('vidCta').textContent = ad.ctaLabel || 'Learn more';
$('vidCta').hidden = false;
@@ -1320,7 +1331,16 @@
$('vidStartBtn').disabled = false;
$('vidStartBtn').textContent = 'Next video';
}
$('vidStartBtn').addEventListener('click', () => loadVideoAd());
$('vidStartBtn').addEventListener('click', () => {
const p = $('vidPlayer');
if (vidState.needsTap && p && p.src && !vidState.done) { // a clip is loaded and waiting on a tap: start it, never replace it
vidState.needsTap = false;
$('vidStartBtn').textContent = 'Playing…'; $('vidStartBtn').disabled = true;
p.play().catch(() => { vidState.needsTap = true; $('vidStartBtn').disabled = false; $('vidStartBtn').textContent = 'Tap to play'; });
return;
}
loadVideoAd();
});
// presence enforcement: pause the watch-to-earn video when the tab/window loses focus,
// resume when it comes back — the viewer must stay on the page for the watch to complete
document.addEventListener('visibilitychange', () => {