diff --git a/app/webrtc/whip_handler.go b/app/webrtc/whip_handler.go index 1924371..fb3bfb4 100644 --- a/app/webrtc/whip_handler.go +++ b/app/webrtc/whip_handler.go @@ -36,6 +36,10 @@ type WHIPHandler struct { // NewWHIPHandler wraps the subsystem in an Echo-compatible WHIP handler. // maxPublishers caps concurrent ingest sessions across all streams; // pass 0 to default to 64. +// +// The constructor registers a teardown hook on the Subsystem so that +// when a process stops, any active WHIP publisher is closed automatically +// (mirroring the pattern used by the WHEP NewHandler). func NewWHIPHandler(s *Subsystem, maxPublishers int) *WHIPHandler { total := int64(maxPublishers) if total <= 0 { @@ -47,6 +51,12 @@ func NewWHIPHandler(s *Subsystem, maxPublishers int) *WHIPHandler { ingestStream: make(map[string]string), maxCapTotal: total, } + // Wire the WHIP teardown hook so onWHIPProcessStop notifies us + // before releasing the port allocation — same pattern as WHEP's + // NewHandler → s.SetTeardownHook(h.tearDownStreamPeers). + if s != nil { + s.SetWHIPTeardownHook(h.tearDownStreamIngests) + } return h } @@ -313,8 +323,9 @@ func (h *WHIPHandler) awaitIngestClose(resource string, peer *corewebrtc.IngestP } } -// tearDownStreamIngests is called by the Subsystem's onWHIPProcessStop -// hook to close any active publisher when the FFmpeg process stops. +// tearDownStreamIngests is called by the Subsystem's SetWHIPTeardownHook +// to close any active publisher when the FFmpeg process stops. +// Not exported — registered internally via NewWHIPHandler. func (h *WHIPHandler) tearDownStreamIngests(streamID string) { h.mu.Lock() bucket := h.ingestByStream[streamID]