From 1d7cd5b5205020133f89c9e154e294d114dbaba3 Mon Sep 17 00:00:00 2001 From: ZGaetano Date: Wed, 6 May 2026 15:57:13 -0400 Subject: [PATCH] feat(webrtc): add StreamCount() for metrics snapshot --- app/webrtc/subsystem.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/app/webrtc/subsystem.go b/app/webrtc/subsystem.go index a9257d4..c325b46 100644 --- a/app/webrtc/subsystem.go +++ b/app/webrtc/subsystem.go @@ -12,8 +12,7 @@ import ( // Subsystem is the app-level WebRTC egress manager. It sits alongside // api.API as a sibling — both consume the Restream service, both wire -// themselves into the Echo HTTP router. The subsystem is responsible -// for: +// themselves into the Echo HTTP router. The subsystem is responsible for: // // - Translating the global config.DataWebRTC into the core-level // corewebrtc.Config used by the PeerFactory. @@ -129,6 +128,14 @@ func (s *Subsystem) SetTeardownHook(fn func(streamID string)) { s.teardown = fn } +// StreamCount returns the number of processes currently registered with +// active WebRTC egress. Used by the Prometheus snapshot collector. +func (s *Subsystem) StreamCount() int { + s.mu.Lock() + defer s.mu.Unlock() + return len(s.streams) +} + // lookup returns the per-process stream pair for id, or nil, false. // Used by the WHEP handler. func (s *Subsystem) lookup(id string) (*processStream, bool) {