Added track success & muted events (#1308)
Related to livekit/protocol#273 This PR adds: - ParticipantResumed - for when ICE restart or migration had occurred - TrackPublishRequested - when we initiate a publication - TrackSubscribeRequested - when we initiate a subscription - TrackMuted - publisher muted track - TrackUnmuted - publisher unmuted track - TrackPublish/TrackSubcribe events will indicate when those actions have been successful, to differentiate.
This commit is contained in:
@@ -12,7 +12,7 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
monitorInterval = 3 * time.Second
|
||||
monitorInterval = 1 * time.Second
|
||||
)
|
||||
|
||||
type ParticipantSupervisorParams struct {
|
||||
@@ -92,7 +92,7 @@ func (p *ParticipantSupervisor) SetPublisherPeerConnectionConnected(isConnected
|
||||
p.lock.Unlock()
|
||||
}
|
||||
|
||||
func (p *ParticipantSupervisor) AddPublication(trackID livekit.TrackID, trackType livekit.TrackType) {
|
||||
func (p *ParticipantSupervisor) AddPublication(trackID livekit.TrackID, onSuccess func(track types.LocalMediaTrack)) {
|
||||
p.lock.Lock()
|
||||
pm, ok := p.publications[trackID]
|
||||
if !ok {
|
||||
@@ -102,12 +102,13 @@ func (p *ParticipantSupervisor) AddPublication(trackID livekit.TrackID, trackTyp
|
||||
TrackID: trackID,
|
||||
IsPeerConnectionConnected: p.isPublisherConnected,
|
||||
Logger: p.params.Logger,
|
||||
OnSuccess: onSuccess,
|
||||
},
|
||||
),
|
||||
}
|
||||
p.publications[trackID] = pm
|
||||
}
|
||||
pm.opMon.PostEvent(types.OperationMonitorEventAddPendingPublication, trackType.String())
|
||||
pm.opMon.PostEvent(types.OperationMonitorEventAddPendingPublication, nil)
|
||||
p.lock.Unlock()
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,6 @@ import (
|
||||
"github.com/gammazero/deque"
|
||||
|
||||
"github.com/livekit/livekit-server/pkg/rtc/types"
|
||||
"github.com/livekit/livekit-server/pkg/telemetry/prometheus"
|
||||
"github.com/livekit/protocol/livekit"
|
||||
"github.com/livekit/protocol/logger"
|
||||
)
|
||||
@@ -29,6 +28,7 @@ type PublicationMonitorParams struct {
|
||||
TrackID livekit.TrackID
|
||||
IsPeerConnectionConnected bool
|
||||
Logger logger.Logger
|
||||
OnSuccess func(t types.LocalMediaTrack)
|
||||
}
|
||||
|
||||
type PublicationMonitor struct {
|
||||
@@ -58,7 +58,7 @@ func (p *PublicationMonitor) PostEvent(ome types.OperationMonitorEvent, omd type
|
||||
case types.OperationMonitorEventPublisherPeerConnectionConnected:
|
||||
p.setConnected(omd.(bool))
|
||||
case types.OperationMonitorEventAddPendingPublication:
|
||||
p.addPending(omd.(string))
|
||||
p.addPending()
|
||||
case types.OperationMonitorEventSetPublicationMute:
|
||||
p.setMute(omd.(bool))
|
||||
case types.OperationMonitorEventSetPublishedTrack:
|
||||
@@ -68,9 +68,7 @@ func (p *PublicationMonitor) PostEvent(ome types.OperationMonitorEvent, omd type
|
||||
}
|
||||
}
|
||||
|
||||
func (p *PublicationMonitor) addPending(trackType string) {
|
||||
prometheus.AddPublishAttempt(trackType)
|
||||
|
||||
func (p *PublicationMonitor) addPending() {
|
||||
p.lock.Lock()
|
||||
p.desiredPublishes.PushBack(
|
||||
&publish{
|
||||
@@ -171,7 +169,9 @@ func (p *PublicationMonitor) update() {
|
||||
}
|
||||
|
||||
if pub.isStart && p.publishedTrack != nil {
|
||||
prometheus.AddPublishSuccess(p.publishedTrack.Kind().String())
|
||||
if p.params.OnSuccess != nil {
|
||||
p.params.OnSuccess(p.publishedTrack)
|
||||
}
|
||||
}
|
||||
|
||||
if (pub.isStart && p.publishedTrack == nil) || (!pub.isStart && p.publishedTrack != nil) {
|
||||
|
||||
Reference in New Issue
Block a user