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:
+25
-5
@@ -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)
|
||||
// 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">✓</span><b>That is every video on this tab</b>'
|
||||
+ '<span class="muted small">You have watched all ' + r.status.count + ' of today’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">✓</span><b>Videos done for today</b><span class="muted small">' + (capHit ? 'That is today’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;
|
||||
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', () => {
|
||||
|
||||
+1
-1
@@ -1070,7 +1070,7 @@
|
||||
<script src="/assets/common.js?v=20260916a"></script>
|
||||
<script src="/assets/wallet.js?v=20260911a"></script>
|
||||
<script src="/assets/promo.js?v=20260921d"></script>
|
||||
<script src="/assets/my.js?v=20260922x"></script>
|
||||
<script src="/assets/my.js?v=20260922v"></script>
|
||||
<script src="/assets/chat.js?v=20260907l"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -368,6 +368,24 @@ async function imageCheck(url) {
|
||||
return { ok: false, reason: 'That link is a web page, not an image. Paste the direct image link (it usually ends in .png or .jpg), or use Promo tools > Banners > Copy image URL.' };
|
||||
} catch (e) { return { ok: false, reason: 'Could not load that image link. Paste the direct image link (ends in .png or .jpg), or use Promo tools > Banners > Copy image URL.' }; }
|
||||
}
|
||||
// A video campaign's source has to actually exist. The create form only matched the URL
|
||||
// shape, so a placeholder (yourdomain.com/....mp4) went live on 2026-09-11 and sat there for
|
||||
// eleven days handing every Tier 1 viewer a black player they could never finish.
|
||||
async function videoCheck(url) {
|
||||
const u = String(url || '').trim();
|
||||
if (/^\/uploads\//.test(u)) return { ok: true }; // uploaded here, already on our disk
|
||||
let h;
|
||||
try { h = await headUrl(u); }
|
||||
catch (e) { // no DNS, refused, timed out
|
||||
return { ok: false, reason: 'We could not reach that video link, so members would just see a black player. Check the address, or upload the file here instead.' };
|
||||
}
|
||||
if (h && (h.status === 404 || h.status === 410))
|
||||
return { ok: false, reason: 'That video link answers with HTTP ' + h.status + ' — the file is not there. Point the campaign at a file that loads, or upload it here.' };
|
||||
const ct = String((h && h.contentType) || '').split(';')[0].trim().toLowerCase();
|
||||
if (ct && !/^video\//.test(ct) && ct !== 'application/octet-stream' && ct !== 'binary/octet-stream')
|
||||
return { ok: false, reason: 'That link returns ' + ct + ', not a video file. Paste the direct .mp4 or .webm link, or upload the file here.' };
|
||||
return { ok: true };
|
||||
}
|
||||
function headUrl(url) {
|
||||
return new Promise((resolve, reject) => {
|
||||
let u; try { u = new URL(url); } catch (e) { return reject(new Error('bad url')); }
|
||||
@@ -2637,7 +2655,15 @@ const server = http.createServer(async (req, res) => {
|
||||
const ad = await ads.serveVideo(Object.assign({ excludeEmail: s.email, orientation }, viewerGeo(req))); // never your own video
|
||||
if (!ad) { // distinguish "you have watched every live video today" from "nothing is live" (Marty, 2026-09-13)
|
||||
let allWatched = false; try { allWatched = !!(await ads.serveVideo(Object.assign({ excludeEmail: s.email, orientation, ignoreSeen: true }, viewerGeo(req)))); } catch (e) {}
|
||||
return json(res, 200, { ad: null, status, allWatched });
|
||||
// this surface is empty but the other one may not be: the Watch tab holds the landscape
|
||||
// videos and Shorts holds the portrait ones, and they share one daily cap, so a member
|
||||
// who runs the tab dry still has clips waiting (Marty, 2026-09-22)
|
||||
let otherFormat = null;
|
||||
if (status.left > 0 && (orientation === 'landscape' || orientation === 'portrait')) {
|
||||
const alt = orientation === 'landscape' ? 'portrait' : 'landscape';
|
||||
try { if (await ads.serveVideo(Object.assign({ excludeEmail: s.email, orientation: alt }, viewerGeo(req)))) otherFormat = alt === 'portrait' ? 'shorts' : 'watch'; } catch (e) {}
|
||||
}
|
||||
return json(res, 200, { ad: null, status, allWatched, otherFormat });
|
||||
}
|
||||
const token = crypto.randomBytes(16).toString('hex');
|
||||
videoTokens.set(s.email, { token, ts: Date.now(), id: ad.id, secs: ad.watchSecs });
|
||||
@@ -2827,6 +2853,7 @@ const server = http.createServer(async (req, res) => {
|
||||
const fc = await frameCheck(b.targetUrl);
|
||||
if (!fc.ok) return json(res, 400, { error: fc.reason });
|
||||
}
|
||||
if (String(b.type) === 'video') { const vc = await videoCheck(b.videoUrl); if (!vc.ok) return json(res, 400, { error: vc.reason }); }
|
||||
// charge the best-funded of the member's positions (main + Qualified Start
|
||||
// wallets). A campaign burns from one member id, so the budget must fit inside it.
|
||||
const ids = (await myMemberIds(s)).ids;
|
||||
|
||||
Reference in New Issue
Block a user