From 4f84c72c85ec5aab416add38429c9396a50da347 Mon Sep 17 00:00:00 2001 From: Zac Gaetano Date: Sun, 3 May 2026 11:23:55 +0000 Subject: [PATCH] feat(core/webrtc): expose Peer.Done() channel + AddICECandidate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Two small additions to support the M3 handler: - Peer.Done() — read-only view of the existing 'done' channel, closed on Close(). Lets external indexes (Handler, admin API) await peer teardown without polling. - Peer.AddICECandidate — passthrough so the WHEP PATCH handler can forward trickle-ICE candidates without reaching into the PeerConnection directly. Co-Authored-By: Claude Opus 4.7 --- core/webrtc/peer.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/core/webrtc/peer.go b/core/webrtc/peer.go index 64a1cc8..7782ed2 100644 --- a/core/webrtc/peer.go +++ b/core/webrtc/peer.go @@ -152,6 +152,12 @@ func (p *Peer) Answer() webrtc.SessionDescription { return p.answer } // ResourceID returns the stable resource id used in the WHEP Location header. func (p *Peer) ResourceID() string { return p.resourceID } +// Done returns a channel that is closed when the Peer has been torn down +// (either explicitly via Close, or because Pion observed an ICE +// failure / disconnection). Consumers can range over it to drive +// index cleanup without polling. +func (p *Peer) Done() <-chan struct{} { return p.done } + // Close tears down the peer connection and unsubscribes from each // source. Safe to call multiple times. func (p *Peer) Close() error { @@ -257,6 +263,14 @@ func (f *PeerFactory) CreatePeerFromSources(ctx context.Context, return p, nil } + +// AddICECandidate forwards a trickle-ICE candidate to the underlying +// PeerConnection. Returns the underlying error if the candidate is +// malformed or the connection has already been closed. +func (p *Peer) AddICECandidate(c webrtc.ICECandidateInit) error { + return p.pc.AddICECandidate(c) +} + func newResourceID() string { b := make([]byte, 8) _, _ = rand.Read(b)