Streams: long-press menu on touch screens, show connecting and failure over the picture

A stream counted as live as soon as its track was announced, before any route
existed, so a viewer whose connection never came up saw a black picture.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-01 22:52:16 +02:00
co-authored by Claude Opus 5.5
parent 950a1afad7
commit 9832ba2749
3 changed files with 50 additions and 9 deletions
+8 -2
View File
@@ -230,9 +230,15 @@ class ScreenShare {
this.watchPc?.close();
const pc = new RTCPeerConnection({ iceServers: this.iceServers() });
this.watchPc = pc;
pc.addEventListener('track', e => { if (this.watchPc === pc) this.setWatchState('live', e.streams[0]); });
// The track is announced with the description, before any route exists: the stream only
// counts as live once the connection is up, otherwise the viewer stares at a black picture
pc.addEventListener('track', e => {
if (this.watchPc === pc) this.setWatchState(pc.connectionState === 'connected' ? 'live' : 'connecting', e.streams[0]);
});
pc.addEventListener('connectionstatechange', () => {
if (pc.connectionState === 'failed' && this.watchPc === pc) this.setWatchState('failed');
if (this.watchPc !== pc) return;
if (pc.connectionState === 'connected') this.setWatchState('live');
else if (pc.connectionState === 'failed') this.setWatchState('failed');
});
try {
await pc.setRemoteDescription({ type: 'offer', sdp });