zebra-spaces: tap-resume reload + click event + log retry result

When stream autoplay was blocked and the listener tapped to resume,
the retry called a.play() on a <audio> that had already been left in
error state by the browser-aborted prior load. play() on a stuck
element silently no-ops — listener saw the 'tap anywhere' message but
got no audio and no feedback.

Three fixes:
  - call a.load() inside the gesture handler before a.play() to
    restart the fetch from a clean state
  - add 'click' to the listened events alongside pointerdown/
    touchstart — Firefox Android only grants gesture activation on
    click in some configurations
  - log retry result: 'stream resumed after tap' on success,
    'stream tap-retry failed: <msg>' on rejection, so we can see
    what's happening instead of silent failure

Tests green (83 fsm + 16 zebra-spaces).
This commit is contained in:
Russell Ballestrini 2026-06-03 20:18:53 -04:00
parent 6c9d1b8ecc
commit e1ba62e7ac
No known key found for this signature in database

View file

@ -4058,24 +4058,46 @@ function streamUrlFor(pubHex){
* once. Idempotent install. */
const pendingAutoplay = new Set();
let tapResumeInstalled = false;
let tapResumeRetry = null;
function uninstallTapResume(){
if (!tapResumeInstalled || !tapResumeRetry) return;
document.removeEventListener('pointerdown', tapResumeRetry);
document.removeEventListener('touchstart', tapResumeRetry);
document.removeEventListener('click', tapResumeRetry);
tapResumeInstalled = false; tapResumeRetry = null;
}
function installTapResume(){
if (tapResumeInstalled) return;
tapResumeInstalled = true;
const retry = () => {
if (!pendingAutoplay.size) return;
tapResumeRetry = () => {
if (!pendingAutoplay.size){ uninstallTapResume(); return; }
/* The prior load was aborted by the browser when it denied
* autoplay; the <audio> element is in error state. Re-load it
* inside the gesture handler so play() has a fresh request to
* attach to — bare a.play() on a stuck element silently no-ops. */
for (const a of [...pendingAutoplay]){
try { a.load(); } catch(_){}
const p = a.play();
if (p && p.then) p.then(() => pendingAutoplay.delete(a)).catch(()=>{});
else pendingAutoplay.delete(a);
}
if (!pendingAutoplay.size){
document.removeEventListener('pointerdown', retry);
document.removeEventListener('touchstart', retry);
tapResumeInstalled = false;
if (p && p.then){
p.then(() => {
pendingAutoplay.delete(a);
logLine('', 'stream resumed after tap');
if (!pendingAutoplay.size) uninstallTapResume();
}).catch(e => {
logLine('err', 'stream tap-retry failed: '+(e && e.message || e));
});
} else {
pendingAutoplay.delete(a);
if (!pendingAutoplay.size) uninstallTapResume();
}
}
};
document.addEventListener('pointerdown', retry, { passive: true });
document.addEventListener('touchstart', retry, { passive: true });
/* Listen on click in addition to pointer/touch — Firefox Android
* sometimes denies gesture-activation on pointerdown alone and
* only grants it on the click event after release. */
document.addEventListener('pointerdown', tapResumeRetry, { passive: true });
document.addEventListener('touchstart', tapResumeRetry, { passive: true });
document.addEventListener('click', tapResumeRetry, { passive: true });
}
async function startStream(uuid, pubHex){
/* DON'T mute the WebRTC audio yet — if the fresh <audio>'s autoplay
@ -4819,8 +4841,8 @@ logLine('', 'ready — pick a handle, type a rendezvous code, enter the space');
<footer style="margin:2.2rem auto 0;font-size:0.65rem;color:#999;line-height:1.7;word-break:break-all;font-family:monospace">
<span id="pi-seal" style="color:#777;cursor:default;user-select:none" title="">page integrity</span> &nbsp;·&nbsp; built <span class="stamp-date">2026-06-04</span><br>
md5 <span class="stamp-md5">988fb9812616b4cbd5c7f1073f3e4d01</span><br>
sha256 <span class="stamp-sha">7b9cc2c6cdab3bba55beb73b6afa413b784743b986294b3ad4e043f31c553e3f</span><br>
md5 <span class="stamp-md5">36ae23a6e8baa61fba8cf6fe48d1c45b</span><br>
sha256 <span class="stamp-sha">ef709e213eaad4024f34fc231c804780632207d5b9dd6d1a9a18c9e0eb4b053b</span><br>
<span style="color:#bbb">hashes are of this page with these two fields zeroed — to verify, blank them and re-hash</span><br>
<span style="color:#bbb">one self-contained file — <strong>save a copy</strong> and verify against these hashes; point at your own servers with ?signal= and ?turncred=, or <a href="host-your-own.html" style="color:#999">host your own community</a></span>
</footer>