From 45d2a4911f82346675eec9499750234bbfbfce56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mats=20T=C3=B6rnberg?= Date: Tue, 22 Sep 2026 10:46:28 +0200 Subject: [PATCH] Attach active screen share to new peers and prompt mic on join gesture --- public/app.js | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/public/app.js b/public/app.js index 7c7b010..b8533ac 100644 --- a/public/app.js +++ b/public/app.js @@ -80,13 +80,12 @@ async function joinVoice(room) { S.connecting = true; setStatus(`connecting to ${room}…`, 'connecting'); - try { - S.iceServers = await fetchIce(); - } catch { - toast('Could not load ICE config from server — using fallback STUN', 'warn'); - } + // Mic permission & AudioContext: request immediately on the user-click gesture + // so browsers don't block the microphone permission prompt or audio autoplay policy. + if (!S.audioCtx) S.audioCtx = new AudioContext(); + await S.audioCtx.resume().catch(() => {}); + orientListener(); - // mic (join anyway without one — listen-only) try { S.micStream = await navigator.mediaDevices.getUserMedia({ audio: { echoCancellation: true, noiseSuppression: true, autoGainControl: true }, @@ -99,10 +98,11 @@ async function joinVoice(room) { S.muted = false; $('#btn-share').disabled = false; - // audio context must exist after a user gesture — the channel click is one - if (!S.audioCtx) S.audioCtx = new AudioContext(); - await S.audioCtx.resume().catch(() => {}); - orientListener(); + try { + S.iceServers = await fetchIce(); + } catch { + toast('Could not load ICE config from server — using fallback STUN', 'warn'); + } await openSignaling(room); S.room = room; @@ -398,6 +398,15 @@ function ensurePC(peer, initiator) { pc.addTransceiver('audio', { direction: 'recvonly' }); } + // send my screen share if I am currently sharing when this peer connects + if (S.sharing && S.screenStream) { + const senders = []; + for (const track of S.screenStream.getTracks()) { + senders.push(pc.addTrack(track, S.screenStream)); + } + S.screenSenders.set(peer.id, senders); + } + if (initiator) pc.onnegotiationneeded(); return peer; }