Merge pull request #2 from TheNeikos/claude/fix-screenshare-stream-43ABB
Fix WebRTC stream handling and improve screen share delivery
This commit is contained in:
commit
8cc9ab0d46
1 changed files with 20 additions and 4 deletions
|
|
@ -714,7 +714,15 @@
|
|||
console.log(`[${peerId.slice(0,8)}] Received track:`, event.track.kind);
|
||||
const peer = state.peers.get(peerId);
|
||||
if (peer) {
|
||||
// Use the associated stream, or build one from the track
|
||||
// (event.streams can be empty in some WebRTC edge cases)
|
||||
if (event.streams[0]) {
|
||||
peer.stream = event.streams[0];
|
||||
} else if (!peer.stream) {
|
||||
peer.stream = new MediaStream([event.track]);
|
||||
} else {
|
||||
peer.stream.addTrack(event.track);
|
||||
}
|
||||
updateUI();
|
||||
|
||||
// Auto-select if this is the first/only stream
|
||||
|
|
@ -913,13 +921,21 @@
|
|||
stopSharing();
|
||||
};
|
||||
|
||||
// Notify server - other peers will send request_stream in response
|
||||
// Notify server
|
||||
send({
|
||||
type: 'started_sharing',
|
||||
peer_id: state.peerId,
|
||||
has_audio: stream.getAudioTracks().length > 0,
|
||||
});
|
||||
|
||||
// Proactively send offers to all connected peers so they
|
||||
// receive the stream immediately. Without this, we rely on
|
||||
// a request_stream round-trip that can silently fail because
|
||||
// handleSignal is async but never awaited by ws.onmessage.
|
||||
for (const [peerId] of state.peers) {
|
||||
sendOfferTo(peerId);
|
||||
}
|
||||
|
||||
updateUI();
|
||||
} catch (err) {
|
||||
console.error('Error starting screen share:', err);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue