zebra-report: hoist musicMode + device prefs to fix TDZ blocking init — mirror

This commit is contained in:
russell@unturf.com 2026-06-01 21:59:56 -04:00
parent 8f2c6ea275
commit 53b29a97e8
No known key found for this signature in database

View file

@ -683,9 +683,10 @@ await loadOrCreateIdentity();
myHandle = localStorage.getItem(HANDLE_KEY) || '';
$('handle').value = myHandle;
/* preferences that should outlive a reload — music-mode toggle and the
* last-picked mic + camera deviceIds. They're applied here before any
* device enumeration / mic acquisition so the very first getUserMedia
* call uses the right device + constraints. */
* last-picked mic + camera deviceIds. Declared up here so the restore
* runs before their downstream `let` would put them in the temporal
* dead zone; downstream code now reads from these existing bindings. */
let musicMode = false, micDeviceId = '', cameraDeviceId = '';
try { musicMode = localStorage.getItem(MUSIC_MODE_KEY) === '1'; } catch(_){}
try { micDeviceId = localStorage.getItem(MIC_DEV_KEY) || ''; } catch(_){}
try { cameraDeviceId = localStorage.getItem(CAM_DEV_KEY) || ''; } catch(_){}
@ -730,7 +731,9 @@ const SFU_BASE = (new URLSearchParams(location.search).get('sfu')
let sfuPubPC = null, sfuPubPeerID = null;
let sfuSubPC = null, sfuSubPeerID = null, sfuSubEvents = null;
let sfuScreenPC = null, sfuScreenPeerID = null, sfuScreenStream = null;
let sfuCameraPC = null, sfuCameraPeerID = null, sfuCameraStream = null, cameraDeviceId = '';
let sfuCameraPC = null, sfuCameraPeerID = null, sfuCameraStream = null;
/* cameraDeviceId is declared earlier so localStorage restore can write to it
* before the device-list refresh runs */
/* incoming screen/camera streams keyed by publisher pubkey hex (== streamID).
* Cleared when the corresponding publisher leaves (peer-left or boot). */
const screenStreams = new Map(); // pubHex -> MediaStream
@ -1171,7 +1174,9 @@ async function refreshTurnCred(){
* zebra-audio carries over directly: re-acquire + replaceTrack on every
* live sender (now multiple senders, one per peer).
* ================================================================== */
let micStream = null, audioCtx = null, musicMode = false, micDeviceId = '';
let micStream = null, audioCtx = null;
/* musicMode + micDeviceId declared earlier so localStorage restore can
* populate them before getMic() reads micConstraints() */
function micConstraints(){
/* music mode = high-fidelity broadcast: stereo, raw, 48kHz so we can
* push 256kbps Opus and let Opus's stereo modes carry music properly.
@ -2174,8 +2179,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-02</span><br>
md5 <span class="stamp-md5">4eb2aa5b98de772e0982dce36a4e84a1</span><br>
sha256 <span class="stamp-sha">149cc312ddf22b2cc2963de39bbfd3e6413e42073b31acd759b73dddd19451dc</span><br>
md5 <span class="stamp-md5">0e924d8e993d1b869f7554421455636e</span><br>
sha256 <span class="stamp-sha">8677be259cd940bf3d290598171533e47b6ec04a85a855e18670ecd8aff12945</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>