add session & metrics to webrtc peer.

This commit is contained in:
Miroslav Šedivý 2023-04-10 21:37:39 +02:00
parent 9928feefef
commit ec8560b290
3 changed files with 8 additions and 4 deletions

View File

@ -452,6 +452,8 @@ func (manager *WebRTCManagerCtx) CreatePeer(session types.Session, bitrate int,
peer := &WebRTCPeerCtx{ peer := &WebRTCPeerCtx{
logger: logger, logger: logger,
session: session,
metrics: metrics,
connection: connection, connection: connection,
// tracks & channels // tracks & channels
audioTrack: audioTrack, audioTrack: audioTrack,

View File

@ -13,16 +13,16 @@ import (
type metricsManager struct { type metricsManager struct {
mu sync.Mutex mu sync.Mutex
sessions map[string]metrics sessions map[string]*metrics
} }
func newMetricsManager() *metricsManager { func newMetricsManager() *metricsManager {
return &metricsManager{ return &metricsManager{
sessions: map[string]metrics{}, sessions: map[string]*metrics{},
} }
} }
func (m *metricsManager) getBySession(session types.Session) metrics { func (m *metricsManager) getBySession(session types.Session) *metrics {
m.mu.Lock() m.mu.Lock()
defer m.mu.Unlock() defer m.mu.Unlock()
@ -33,7 +33,7 @@ func (m *metricsManager) getBySession(session types.Session) metrics {
return met return met
} }
met = metrics{ met = &metrics{
sessionId: sessionId, sessionId: sessionId,
connectionState: promauto.NewGauge(prometheus.GaugeOpts{ connectionState: promauto.NewGauge(prometheus.GaugeOpts{

View File

@ -16,6 +16,8 @@ import (
type WebRTCPeerCtx struct { type WebRTCPeerCtx struct {
mu sync.Mutex mu sync.Mutex
logger zerolog.Logger logger zerolog.Logger
session types.Session
metrics *metrics
connection *webrtc.PeerConnection connection *webrtc.PeerConnection
// tracks & channels // tracks & channels
audioTrack *Track audioTrack *Track