Attach active screen share to new peers and prompt mic on join gesture
This commit is contained in:
1 parent
dee8ef4f7c
commit
45d2a4911f
1 file changed
+19
-10
+19
-10
@@ -80,13 +80,12 @@ async function joinVoice(room) {
|
|||||||
S.connecting = true;
|
S.connecting = true;
|
||||||
setStatus(`connecting to ${room}…`, 'connecting');
|
setStatus(`connecting to ${room}…`, 'connecting');
|
||||||
|
|
||||||
try {
|
// Mic permission & AudioContext: request immediately on the user-click gesture
|
||||||
S.iceServers = await fetchIce();
|
// so browsers don't block the microphone permission prompt or audio autoplay policy.
|
||||||
} catch {
|
if (!S.audioCtx) S.audioCtx = new AudioContext();
|
||||||
toast('Could not load ICE config from server — using fallback STUN', 'warn');
|
await S.audioCtx.resume().catch(() => {});
|
||||||
}
|
orientListener();
|
||||||
|
|
||||||
// mic (join anyway without one — listen-only)
|
|
||||||
try {
|
try {
|
||||||
S.micStream = await navigator.mediaDevices.getUserMedia({
|
S.micStream = await navigator.mediaDevices.getUserMedia({
|
||||||
audio: { echoCancellation: true, noiseSuppression: true, autoGainControl: true },
|
audio: { echoCancellation: true, noiseSuppression: true, autoGainControl: true },
|
||||||
@@ -99,10 +98,11 @@ async function joinVoice(room) {
|
|||||||
S.muted = false;
|
S.muted = false;
|
||||||
$('#btn-share').disabled = false;
|
$('#btn-share').disabled = false;
|
||||||
|
|
||||||
// audio context must exist after a user gesture — the channel click is one
|
try {
|
||||||
if (!S.audioCtx) S.audioCtx = new AudioContext();
|
S.iceServers = await fetchIce();
|
||||||
await S.audioCtx.resume().catch(() => {});
|
} catch {
|
||||||
orientListener();
|
toast('Could not load ICE config from server — using fallback STUN', 'warn');
|
||||||
|
}
|
||||||
|
|
||||||
await openSignaling(room);
|
await openSignaling(room);
|
||||||
S.room = room;
|
S.room = room;
|
||||||
@@ -398,6 +398,15 @@ function ensurePC(peer, initiator) {
|
|||||||
pc.addTransceiver('audio', { direction: 'recvonly' });
|
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();
|
if (initiator) pc.onnegotiationneeded();
|
||||||
return peer;
|
return peer;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user