Improved robustness of subscription stack (#1382)

UpdateSubscription had a shortcoming where when it couldn't find the
participant, it ignored the request.

This PR further removes the reliance of current publisher state from
subscribers.
- SubscribeToTrack only takes in a trackID
- Introduced RoomTrackManager to maintain all published tracks to a room
- Added TrackUnpublished event to clearly indicate when a track has been removed
- SubscribeRequested event no longer include information about the publisher
This commit is contained in:
David Zhao
2023-02-06 18:08:26 -08:00
committed by GitHub
parent aaba402ada
commit 2851a8ac98
14 changed files with 365 additions and 205 deletions
-1
View File
@@ -14,7 +14,6 @@ var (
ErrMissingGrants = errors.New("VideoGrant is missing")
// Track subscription related
ErrPublisherNotConnected = errors.New("publisher is not connected")
ErrNoTrackPermission = errors.New("participant is not allowed to subscribe to this track")
ErrNoSubscribePermission = errors.New("participant is not given permission to subscribe to tracks")
ErrTrackNotFound = errors.New("track cannot be found")
+23 -7
View File
@@ -138,6 +138,7 @@ type ParticipantImpl struct {
// callbacks & handlers
onTrackPublished func(types.LocalParticipant, types.MediaTrack)
onTrackUpdated func(types.LocalParticipant, types.MediaTrack)
onTrackUnpublished func(types.LocalParticipant, types.MediaTrack)
onStateChange func(p types.LocalParticipant, oldState livekit.ParticipantInfo_State)
onParticipantUpdate func(types.LocalParticipant)
onDataPacket func(types.LocalParticipant, *livekit.DataPacket)
@@ -412,6 +413,12 @@ func (p *ParticipantImpl) OnTrackPublished(callback func(types.LocalParticipant,
p.lock.Unlock()
}
func (p *ParticipantImpl) OnTrackUnpublished(callback func(types.LocalParticipant, types.MediaTrack)) {
p.lock.Lock()
p.onTrackUnpublished = callback
p.lock.Unlock()
}
func (p *ParticipantImpl) OnStateChange(callback func(p types.LocalParticipant, oldState livekit.ParticipantInfo_State)) {
p.lock.Lock()
p.onStateChange = callback
@@ -1011,11 +1018,7 @@ func (p *ParticipantImpl) setupUpTrackManager() {
VersionGenerator: p.params.VersionGenerator,
})
p.UpTrackManager.OnPublishedTrackUpdated(func(track types.MediaTrack, onlyIfReady bool) {
if onlyIfReady && !p.IsReady() {
return
}
p.UpTrackManager.OnPublishedTrackUpdated(func(track types.MediaTrack) {
p.lock.RLock()
onTrackUpdated := p.onTrackUpdated
p.lock.RUnlock()
@@ -1613,8 +1616,9 @@ func (p *ParticipantImpl) addMediaTrack(signalCid string, sdpCid string, ti *liv
delete(p.pendingTracks, signalCid)
}
trackID := livekit.TrackID(ti.Sid)
mt.AddOnClose(func() {
p.supervisor.ClearPublishedTrack(livekit.TrackID(ti.Sid), mt)
p.supervisor.ClearPublishedTrack(trackID, mt)
// not logged when closing
p.params.Telemetry.TrackUnpublished(
@@ -1625,14 +1629,26 @@ func (p *ParticipantImpl) addMediaTrack(signalCid string, sdpCid string, ti *liv
!p.IsClosed(),
)
// re-use track sid
isUnpublished := false
// re-use Track sid
p.pendingTracksLock.Lock()
if pti := p.pendingTracks[signalCid]; pti != nil {
p.sendTrackPublished(signalCid, pti.trackInfos[0])
} else {
p.unpublishedTracks = append(p.unpublishedTracks, ti)
isUnpublished = true
}
p.pendingTracksLock.Unlock()
if isUnpublished && !p.IsClosed() {
// unpublished events aren't necessary when participant is closed
p.lock.RLock()
onTrackUnpublished := p.onTrackUnpublished
p.lock.RUnlock()
if onTrackUnpublished != nil {
onTrackUnpublished(p, mt)
}
}
})
return mt
-5
View File
@@ -71,14 +71,9 @@ func TestTrackPublishing(t *testing.T) {
})
p.UpTrackManager.AddPublishedTrack(track)
p.handleTrackPublished(track)
require.True(t, published)
require.False(t, updated)
require.Len(t, p.UpTrackManager.publishedTracks, 1)
track.AddOnCloseArgsForCall(0)()
require.Len(t, p.UpTrackManager.publishedTracks, 0)
require.True(t, updated)
})
t.Run("sends back trackPublished event", func(t *testing.T) {
+47 -52
View File
@@ -13,7 +13,6 @@ import (
"google.golang.org/protobuf/proto"
"github.com/livekit/livekit-server/pkg/sfu/connectionquality"
"github.com/livekit/livekit-server/pkg/utils"
"github.com/livekit/protocol/livekit"
"github.com/livekit/protocol/logger"
@@ -50,7 +49,7 @@ type Room struct {
serverInfo *livekit.ServerInfo
telemetry telemetry.TelemetryService
egressLauncher EgressLauncher
changeNotifier *utils.ChangeNotifierManager
trackManager *RoomTrackManager
// map of identity -> Participant
participants map[livekit.ParticipantIdentity]types.LocalParticipant
@@ -94,7 +93,7 @@ func NewRoom(
audioConfig: audioConfig,
telemetry: telemetry,
egressLauncher: egressLauncher,
changeNotifier: utils.NewChangeNotifierManager(),
trackManager: NewRoomTrackManager(),
serverInfo: serverInfo,
participants: make(map[livekit.ParticipantIdentity]types.LocalParticipant),
participantOpts: make(map[livekit.ParticipantIdentity]*ParticipantOptions),
@@ -251,7 +250,7 @@ func (r *Room) Join(participant types.LocalParticipant, opts *ParticipantOptions
r.protoRoom.NumParticipants++
}
// it's important to set this before connection, we don't want to miss out on any publishedTracks
// it's important to set this before connection, we don't want to miss out on any published tracks
participant.OnTrackPublished(r.onTrackPublished)
participant.OnStateChange(func(p types.LocalParticipant, oldState livekit.ParticipantInfo_State) {
r.Logger.Infow("participant state changed",
@@ -266,7 +265,7 @@ func (r *Room) Join(participant types.LocalParticipant, opts *ParticipantOptions
state := p.State()
if state == livekit.ParticipantInfo_ACTIVE {
// subscribe participant to existing publishedTracks
// subscribe participant to existing published tracks
r.subscribeToExistingTracks(p)
// start the workers once connectivity is established
@@ -282,6 +281,7 @@ func (r *Room) Join(participant types.LocalParticipant, opts *ParticipantOptions
}
})
participant.OnTrackUpdated(r.onTrackUpdated)
participant.OnTrackUnpublished(r.onTrackUnpublished)
participant.OnParticipantUpdate(r.onParticipantUpdate)
participant.OnDataPacket(r.onDataPacket)
participant.OnSubscribeStatusChanged(func(publisherID livekit.ParticipantID, subscribed bool) {
@@ -425,16 +425,12 @@ func (r *Room) RemoveParticipant(identity livekit.ParticipantIdentity, pID livek
return
}
// clean up notifiers, participant isn't coming back
for _, track := range p.GetPublishedTracks() {
r.changeNotifier.RemoveNotifier(string(track.ID()), true)
}
// send broadcast only if it's not already closed
sendUpdates := !p.IsDisconnected()
p.OnTrackUpdated(nil)
p.OnTrackPublished(nil)
p.OnTrackUnpublished(nil)
p.OnStateChange(nil)
p.OnParticipantUpdate(nil)
p.OnDataPacket(nil)
@@ -464,39 +460,24 @@ func (r *Room) UpdateSubscriptions(
participantTracks []*livekit.ParticipantTracks,
subscribe bool,
) {
// find all matching tracks
publisherIDs := make(map[livekit.TrackID]livekit.ParticipantID)
publisherIdentities := make(map[livekit.TrackID]livekit.ParticipantIdentity)
participants := r.GetParticipants()
// handle subscription changes
for _, trackID := range trackIDs {
for _, p := range participants {
track := p.GetPublishedTrack(trackID)
if track != nil {
publisherIDs[trackID] = p.ID()
publisherIdentities[trackID] = p.Identity()
break
}
if subscribe {
participant.SubscribeToTrack(trackID)
} else {
participant.UnsubscribeFromTrack(trackID)
}
}
for _, pt := range participantTracks {
pub := r.GetParticipantByID(livekit.ParticipantID(pt.ParticipantSid))
for _, trackID := range livekit.StringsAsTrackIDs(pt.TrackSids) {
publisherIDs[trackID] = livekit.ParticipantID(pt.ParticipantSid)
if pub != nil {
publisherIdentities[trackID] = pub.Identity()
if subscribe {
participant.SubscribeToTrack(trackID)
} else {
participant.UnsubscribeFromTrack(trackID)
}
}
}
// handle subscription changes
for trackID, publisherID := range publisherIDs {
if subscribe {
participant.SubscribeToTrack(trackID, publisherIdentities[trackID], publisherID)
} else {
participant.UnsubscribeFromTrack(trackID)
}
}
}
func (r *Room) SyncState(participant types.LocalParticipant, state *livekit.SyncState) error {
@@ -508,10 +489,7 @@ func (r *Room) UpdateSubscriptionPermission(participant types.LocalParticipant,
return err
}
for _, track := range participant.GetPublishedTracks() {
notifier := r.changeNotifier.GetNotifier(string(track.ID()))
if notifier != nil {
notifier.NotifyChanged()
}
r.trackManager.NotifyTrackChanged(track.ID())
}
return nil
}
@@ -534,18 +512,28 @@ func (r *Room) UpdateVideoLayers(participant types.Participant, updateVideoLayer
return participant.UpdateVideoLayers(updateVideoLayers)
}
func (r *Room) ResolveMediaTrackForSubscriber(subIdentity livekit.ParticipantIdentity, publisherID livekit.ParticipantID, trackID livekit.TrackID) (types.MediaResolverResult, error) {
func (r *Room) ResolveMediaTrackForSubscriber(subIdentity livekit.ParticipantIdentity, trackID livekit.TrackID) types.MediaResolverResult {
res := types.MediaResolverResult{}
pub := r.GetParticipantByID(publisherID)
if pub == nil {
return res, ErrPublisherNotConnected
info := r.trackManager.GetTrackInfo(trackID)
res.TrackChangedNotifier = r.trackManager.GetOrCreateTrackChangeNotifier(trackID)
if info == nil {
return res
}
res.Track = pub.GetPublishedTrack(trackID)
res.TrackChangeNotifier = r.changeNotifier.GetOrCreateNotifier(string(trackID))
res.HasPermission = pub.HasPermission(trackID, subIdentity)
res.Track = info.Track
res.TrackRemovedNotifier = r.trackManager.GetOrCreateTrackRemoveNotifier(trackID)
res.PublisherIdentity = info.PublisherIdentity
res.PublisherID = info.PublisherID
return res, nil
pub := r.GetParticipantByID(info.PublisherID)
// when publisher is not found, we will assume it doesn't have permission to access
if pub != nil {
res.HasPermission = pub.HasPermission(trackID, subIdentity)
}
return res
}
func (r *Room) IsClosed() bool {
@@ -768,7 +756,7 @@ func (r *Room) onTrackPublished(participant types.LocalParticipant, track types.
"publisher", participant.Identity(),
"publisherID", participant.ID(),
"trackID", track.ID())
existingParticipant.SubscribeToTrack(track.ID(), participant.Identity(), participant.ID())
existingParticipant.SubscribeToTrack(track.ID())
}
onParticipantChanged := r.onParticipantChanged
r.lock.RUnlock()
@@ -777,10 +765,7 @@ func (r *Room) onTrackPublished(participant types.LocalParticipant, track types.
onParticipantChanged(participant)
}
notifier := r.changeNotifier.GetNotifier(string(track.ID()))
if notifier != nil {
notifier.NotifyChanged()
}
r.trackManager.AddTrack(track, participant.Identity(), participant.ID())
// auto track egress
if r.internal != nil && r.internal.TrackEgress != nil {
@@ -806,6 +791,16 @@ func (r *Room) onTrackUpdated(p types.LocalParticipant, _ types.MediaTrack) {
}
}
func (r *Room) onTrackUnpublished(p types.LocalParticipant, track types.MediaTrack) {
r.trackManager.RemoveTrack(track)
if !p.IsClosed() {
r.broadcastParticipantState(p, broadcastOptions{skipSource: true})
}
if r.onParticipantChanged != nil {
r.onParticipantChanged(p)
}
}
func (r *Room) onParticipantUpdate(p types.LocalParticipant) {
// immediately notify when permissions or metadata changed
r.broadcastParticipantState(p, broadcastOptions{immediate: true})
@@ -871,7 +866,7 @@ func (r *Room) subscribeToExistingTracks(p types.LocalParticipant) {
// subscribe to all
for _, track := range op.GetPublishedTracks() {
trackIDs = append(trackIDs, track.ID())
p.SubscribeToTrack(track.ID(), op.Identity(), op.ID())
p.SubscribeToTrack(track.ID())
}
}
if len(trackIDs) > 0 {
+117
View File
@@ -0,0 +1,117 @@
/*
* Copyright 2023 LiveKit, Inc
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package rtc
import (
"sync"
"github.com/livekit/livekit-server/pkg/rtc/types"
"github.com/livekit/livekit-server/pkg/utils"
"github.com/livekit/protocol/livekit"
)
// RoomTrackManager holds tracks that are published to the room
type RoomTrackManager struct {
lock sync.RWMutex
changedNotifier *utils.ChangeNotifierManager
removedNotifier *utils.ChangeNotifierManager
tracks map[livekit.TrackID]*TrackInfo
}
type TrackInfo struct {
Track types.MediaTrack
PublisherIdentity livekit.ParticipantIdentity
PublisherID livekit.ParticipantID
}
func NewRoomTrackManager() *RoomTrackManager {
return &RoomTrackManager{
tracks: make(map[livekit.TrackID]*TrackInfo),
changedNotifier: utils.NewChangeNotifierManager(),
removedNotifier: utils.NewChangeNotifierManager(),
}
}
func (r *RoomTrackManager) AddTrack(track types.MediaTrack, publisherIdentity livekit.ParticipantIdentity, publisherID livekit.ParticipantID) {
r.lock.Lock()
r.tracks[track.ID()] = &TrackInfo{
Track: track,
PublisherIdentity: publisherIdentity,
PublisherID: publisherID,
}
r.lock.Unlock()
r.NotifyTrackChanged(track.ID())
}
func (r *RoomTrackManager) RemoveTrack(track types.MediaTrack) {
r.lock.Lock()
// ensure we are removing the same track as added
info, ok := r.tracks[track.ID()]
if !ok || info.Track != track {
r.lock.Unlock()
return
}
delete(r.tracks, track.ID())
r.lock.Unlock()
n := r.removedNotifier.GetNotifier(string(track.ID()))
if n != nil {
n.NotifyChanged()
}
r.changedNotifier.RemoveNotifier(string(track.ID()), true)
r.removedNotifier.RemoveNotifier(string(track.ID()), true)
}
func (r *RoomTrackManager) GetTrackInfo(trackID livekit.TrackID) *TrackInfo {
r.lock.RLock()
defer r.lock.RUnlock()
return r.tracks[trackID]
}
func (r *RoomTrackManager) NotifyTrackChanged(trackID livekit.TrackID) {
n := r.changedNotifier.GetNotifier(string(trackID))
if n != nil {
n.NotifyChanged()
}
}
// HasObservers lets caller know if the current media track has any observers
// this is used to signal interest in the track. when another MediaTrack with the same
// trackID is being used, track is not considered to be observed.
func (r *RoomTrackManager) HasObservers(track types.MediaTrack) bool {
n := r.changedNotifier.GetNotifier(string(track.ID()))
if n == nil || !n.HasObservers() {
return false
}
info := r.GetTrackInfo(track.ID())
if info == nil || info.Track != track {
return false
}
return true
}
func (r *RoomTrackManager) GetOrCreateTrackChangeNotifier(trackID livekit.TrackID) *utils.ChangeNotifier {
return r.changedNotifier.GetOrCreateNotifier(string(trackID))
}
func (r *RoomTrackManager) GetOrCreateTrackRemoveNotifier(trackID livekit.TrackID) *utils.ChangeNotifier {
return r.removedNotifier.GetOrCreateNotifier(string(trackID))
}
+45 -37
View File
@@ -113,21 +113,18 @@ func (m *SubscriptionManager) isClosed() bool {
}
}
func (m *SubscriptionManager) SubscribeToTrack(trackID livekit.TrackID, publisherIdentity livekit.ParticipantIdentity, publisherID livekit.ParticipantID) {
func (m *SubscriptionManager) SubscribeToTrack(trackID livekit.TrackID) {
m.lock.Lock()
sub, ok := m.subscriptions[trackID]
if !ok {
sLogger := m.params.Logger.WithValues(
"trackID", trackID,
"publisherID", publisherID,
"publisherIdentity", publisherIdentity,
)
sub = newTrackSubscription(m.params.Participant.ID(), trackID, sLogger)
m.subscriptions[trackID] = sub
}
desireChanged := sub.setDesired(true)
m.lock.Unlock()
sub.setPublisher(publisherIdentity, publisherID)
if desireChanged {
sub.logger.Infow("subscribing to track")
}
@@ -274,10 +271,6 @@ func (m *SubscriptionManager) reconcileSubscription(s *trackSubscription) {
&livekit.TrackInfo{
Sid: string(s.trackID),
},
&livekit.ParticipantInfo{
Sid: string(s.getPublisherID()),
Identity: string(s.getPublisherIdentity()),
},
)
}
if err := m.subscribe(s); err != nil {
@@ -295,8 +288,8 @@ func (m *SubscriptionManager) reconcileSubscription(s *trackSubscription) {
if s.durationSinceStart() > subscriptionTimeout {
s.maybeRecordError(m.params.Telemetry, m.params.Participant.ID(), err, true)
}
case ErrPublisherNotConnected, ErrTrackNotFound:
// publisher left or source track was never published or closed
case ErrTrackNotFound:
// source track was never published or closed
// if after timeout, we'd unsubscribe from it.
// this is the *only* case we'd change desired state
if s.durationSinceStart() > notFoundTimeout {
@@ -393,21 +386,24 @@ func (m *SubscriptionManager) subscribe(s *trackSubscription) error {
return ErrNoSubscribePermission
}
res, err := m.params.TrackResolver(m.params.Participant.Identity(), s.publisherID, s.trackID)
if err != nil {
return err
}
res := m.params.TrackResolver(m.params.Participant.Identity(), s.trackID)
s.logger.Debugw("resolved track", "result", res)
if res.TrackChangeNotifier != nil && s.setChangeNotifier(res.TrackChangeNotifier) {
if res.TrackChangedNotifier != nil && s.setChangedNotifier(res.TrackChangedNotifier) {
// set callback only when we haven't done it before
// we set the observer before checking for existence of track, so that we may get notified when track becomes
// available
res.TrackChangeNotifier.AddObserver(string(m.params.Participant.ID()), func() {
// we set the observer before checking for existence of track, so that we may get notified
// when the track becomes available
res.TrackChangedNotifier.AddObserver(string(m.params.Participant.ID()), func() {
m.queueReconcile(s.trackID)
})
}
if res.TrackRemovedNotifier != nil && s.setRemovedNotifier(res.TrackRemovedNotifier) {
res.TrackRemovedNotifier.AddObserver(string(m.params.Participant.ID()), func() {
// source track removed, we would unsubscribe
s.logger.Debugw("unsubscribing track since source track was removed")
s.setDesired(false)
})
}
track := res.Track
if track == nil {
@@ -424,6 +420,7 @@ func (m *SubscriptionManager) subscribe(s *trackSubscription) error {
return ErrNoTrackPermission
}
s.setPublisher(res.PublisherIdentity, res.PublisherID)
subTrack, err := track.AddSubscriber(m.params.Participant)
if err != nil && err != errAlreadySubscribed {
// ignore already subscribed error
@@ -568,7 +565,8 @@ type trackSubscription struct {
publisherID livekit.ParticipantID
publisherIdentity livekit.ParticipantIdentity
settings *livekit.UpdateTrackSettings
changeNotifier types.ChangeNotifier
changedNotifier types.ChangeNotifier
removedNotifier types.ChangeNotifier
hasPermission bool
subscribedTrack types.SubscribedTrack
eventSent atomic.Bool
@@ -604,16 +602,8 @@ func (s *trackSubscription) getPublisherID() livekit.ParticipantID {
return s.publisherID
}
func (s *trackSubscription) getPublisherIdentity() livekit.ParticipantIdentity {
s.lock.RLock()
defer s.lock.RUnlock()
return s.publisherIdentity
}
func (s *trackSubscription) setDesired(desired bool) bool {
s.lock.Lock()
defer s.lock.Unlock()
if desired {
// as long as user explicitly set it to desired
// we'll reset the timer so it has sufficient time to reconcile
@@ -622,18 +612,19 @@ func (s *trackSubscription) setDesired(desired bool) bool {
}
if s.desired == desired {
s.lock.Unlock()
return false
}
s.desired = desired
// when no longer desired, we no longer care about change notifications
if !desired && s.changeNotifier != nil {
s.changeNotifier.RemoveObserver(string(s.subscriberID))
s.changeNotifier = nil
}
s.lock.Unlock()
// when no longer desired, we no longer care about change notifications
if desired {
// reset attempts
s.numAttempts.Store(0)
} else {
s.setChangedNotifier(nil)
s.setRemovedNotifier(nil)
}
return true
}
@@ -684,15 +675,32 @@ func (s *trackSubscription) getSubscribedTrack() types.SubscribedTrack {
return s.subscribedTrack
}
func (s *trackSubscription) setChangeNotifier(notifier types.ChangeNotifier) bool {
func (s *trackSubscription) setChangedNotifier(notifier types.ChangeNotifier) bool {
s.lock.Lock()
if s.changeNotifier == notifier {
if s.changedNotifier == notifier {
s.lock.Unlock()
return false
}
existing := s.changeNotifier
s.changeNotifier = notifier
existing := s.changedNotifier
s.changedNotifier = notifier
s.lock.Unlock()
if existing != nil {
existing.RemoveObserver(string(s.subscriberID))
}
return true
}
func (s *trackSubscription) setRemovedNotifier(notifier types.ChangeNotifier) bool {
s.lock.Lock()
if s.removedNotifier == notifier {
s.lock.Unlock()
return false
}
existing := s.removedNotifier
s.removedNotifier = notifier
s.lock.Unlock()
if existing != nil {
+46 -40
View File
@@ -47,7 +47,7 @@ func TestSubscribe(t *testing.T) {
t.Run("happy path subscribe", func(t *testing.T) {
sm := newTestSubscriptionManager(t)
defer sm.Close(false)
resolver := newTestResolver(true, nil)
resolver := newTestResolver(true, true, "pub", "pubID")
sm.params.TrackResolver = resolver.Resolve
subCount := atomic.Int32{}
failed := atomic.Bool{}
@@ -67,7 +67,7 @@ func TestSubscribe(t *testing.T) {
}
})
sm.SubscribeToTrack("track", "pub", "pubID")
sm.SubscribeToTrack("track")
s := sm.subscriptions["track"]
require.True(t, s.isDesired())
require.Eventually(t, func() bool {
@@ -112,14 +112,14 @@ func TestSubscribe(t *testing.T) {
t.Run("no track permission", func(t *testing.T) {
sm := newTestSubscriptionManager(t)
defer sm.Close(false)
resolver := newTestResolver(false, nil)
resolver := newTestResolver(false, true, "pub", "pubID")
sm.params.TrackResolver = resolver.Resolve
failed := atomic.Bool{}
sm.params.OnSubcriptionError = func(trackID livekit.TrackID) {
failed.Store(true)
}
sm.SubscribeToTrack("track", "pub", "pubID")
sm.SubscribeToTrack("track")
s := sm.subscriptions["track"]
require.Eventually(t, func() bool {
return !s.getHasPermission()
@@ -153,21 +153,21 @@ func TestSubscribe(t *testing.T) {
t.Run("publisher left", func(t *testing.T) {
sm := newTestSubscriptionManager(t)
defer sm.Close(false)
resolver := newTestResolver(true, nil)
resolver := newTestResolver(true, true, "pub", "pubID")
sm.params.TrackResolver = resolver.Resolve
failed := atomic.Bool{}
sm.params.OnSubcriptionError = func(trackID livekit.TrackID) {
failed.Store(true)
}
sm.SubscribeToTrack("track", "pub", "pubID")
sm.SubscribeToTrack("track")
s := sm.subscriptions["track"]
require.Eventually(t, func() bool {
return !s.needsSubscribe()
}, subSettleTimeout, subCheckInterval, "should be subscribed")
resolver.lock.Lock()
resolver.err = ErrTrackNotFound
resolver.hasTrack = false
resolver.lock.Unlock()
// publisher triggers close
@@ -187,7 +187,7 @@ func TestUnsubscribe(t *testing.T) {
unsubCount.Add(1)
}
resolver := newTestResolver(true, nil)
resolver := newTestResolver(true, true, "pub", "pubID")
s := &trackSubscription{
trackID: "track",
@@ -200,10 +200,9 @@ func TestUnsubscribe(t *testing.T) {
logger: logger.GetLogger(),
}
// a bunch of unfortunate manual wiring
res, err := resolver.Resolve("sub", s.publisherID, s.trackID)
require.NoError(t, err)
res.TrackChangeNotifier.AddObserver(string(sm.params.Participant.ID()), func() {})
s.changeNotifier = res.TrackChangeNotifier
res := resolver.Resolve("sub", s.trackID)
res.TrackChangedNotifier.AddObserver(string(sm.params.Participant.ID()), func() {})
s.changedNotifier = res.TrackChangedNotifier
st, err := res.Track.AddSubscriber(sm.params.Participant)
require.NoError(t, err)
s.subscribedTrack = st
@@ -227,14 +226,14 @@ func TestUnsubscribe(t *testing.T) {
require.Eventually(t, func() bool {
return !s.needsUnsubscribe()
}, subSettleTimeout, subCheckInterval, "track was not unsubscribed")
}, subSettleTimeout, subCheckInterval, "Track was not unsubscribed")
// no traces should be left
require.Len(t, sm.GetSubscribedTracks(), 0)
sm.lock.RLock()
require.Len(t, sm.subscriptions, 0)
sm.lock.RUnlock()
require.False(t, res.TrackChangeNotifier.HasObservers())
require.False(t, res.TrackChangedNotifier.HasObservers())
tm := sm.params.Telemetry.(*telemetryfakes.FakeTelemetryService)
require.Equal(t, 1, tm.TrackUnsubscribedCallCount())
@@ -243,7 +242,7 @@ func TestUnsubscribe(t *testing.T) {
func TestSubscribeStatusChanged(t *testing.T) {
sm := newTestSubscriptionManager(t)
defer sm.Close(false)
resolver := newTestResolver(true, nil)
resolver := newTestResolver(true, true, "pub", "pubID")
sm.params.TrackResolver = resolver.Resolve
numParticipantSubscribed := atomic.Int32{}
numParticipantUnsubscribed := atomic.Int32{}
@@ -255,8 +254,8 @@ func TestSubscribeStatusChanged(t *testing.T) {
}
})
sm.SubscribeToTrack("track1", "pub", "pubID")
sm.SubscribeToTrack("track2", "pub", "pubID")
sm.SubscribeToTrack("track1")
sm.SubscribeToTrack("track2")
s1 := sm.subscriptions["track1"]
s2 := sm.subscriptions["track2"]
require.Eventually(t, func() bool {
@@ -300,7 +299,7 @@ func TestSubscribeStatusChanged(t *testing.T) {
func TestUpdateSettingsBeforeSubscription(t *testing.T) {
sm := newTestSubscriptionManager(t)
defer sm.Close(false)
resolver := newTestResolver(true, nil)
resolver := newTestResolver(true, true, "pub", "pubID")
sm.params.TrackResolver = resolver.Resolve
settings := &livekit.UpdateTrackSettings{
@@ -310,12 +309,12 @@ func TestUpdateSettingsBeforeSubscription(t *testing.T) {
}
sm.UpdateSubscribedTrackSettings("track", settings)
sm.SubscribeToTrack("track", "pub", "pubID")
sm.SubscribeToTrack("track")
s := sm.subscriptions["track"]
require.Eventually(t, func() bool {
return !s.needsSubscribe()
}, subSettleTimeout, subCheckInterval, "track should be subscribed")
}, subSettleTimeout, subCheckInterval, "Track should be subscribed")
st := s.getSubscribedTrack().(*typesfakes.FakeSubscribedTrack)
require.Equal(t, 1, st.UpdateSubscriberSettingsCallCount())
@@ -336,8 +335,8 @@ func newTestSubscriptionManager(t *testing.T) *SubscriptionManager {
OnTrackSubscribed: func(subTrack types.SubscribedTrack) {},
OnTrackUnsubscribed: func(subTrack types.SubscribedTrack) {},
OnSubcriptionError: func(trackID livekit.TrackID) {},
TrackResolver: func(identity livekit.ParticipantIdentity, pID livekit.ParticipantID, trackID livekit.TrackID) (types.MediaResolverResult, error) {
return types.MediaResolverResult{}, ErrTrackNotFound
TrackResolver: func(identity livekit.ParticipantIdentity, trackID livekit.TrackID) types.MediaResolverResult {
return types.MediaResolverResult{}
},
Telemetry: &telemetryfakes.FakeTelemetryService{},
})
@@ -346,34 +345,41 @@ func newTestSubscriptionManager(t *testing.T) *SubscriptionManager {
type testResolver struct {
lock sync.Mutex
hasPermission bool
err error
hasTrack bool
pubIdentity livekit.ParticipantIdentity
pubID livekit.ParticipantID
}
func newTestResolver(hasPermission bool, err error) *testResolver {
func newTestResolver(hasPermission bool, hasTrack bool, pubIdentity livekit.ParticipantIdentity, pubID livekit.ParticipantID) *testResolver {
return &testResolver{
hasPermission: hasPermission,
err: err,
hasTrack: hasTrack,
pubIdentity: pubIdentity,
pubID: pubID,
}
}
func (t *testResolver) Resolve(identity livekit.ParticipantIdentity, pID livekit.ParticipantID, trackID livekit.TrackID) (types.MediaResolverResult, error) {
func (t *testResolver) Resolve(identity livekit.ParticipantIdentity, trackID livekit.TrackID) types.MediaResolverResult {
t.lock.Lock()
defer t.lock.Unlock()
if t.err != nil {
return types.MediaResolverResult{}, t.err
res := types.MediaResolverResult{
TrackChangedNotifier: utils.NewChangeNotifier(),
TrackRemovedNotifier: utils.NewChangeNotifier(),
HasPermission: t.hasPermission,
PublisherID: t.pubID,
PublisherIdentity: t.pubIdentity,
}
mt := &typesfakes.FakeMediaTrack{}
st := &typesfakes.FakeSubscribedTrack{}
st.IDReturns(trackID)
st.PublisherIDReturns(pID)
st.PublisherIdentityReturns(identity)
mt.AddSubscriberReturns(st, nil)
st.MediaTrackReturns(mt)
return types.MediaResolverResult{
Track: mt,
TrackChangeNotifier: utils.NewChangeNotifier(),
HasPermission: t.hasPermission,
}, nil
if t.hasTrack {
mt := &typesfakes.FakeMediaTrack{}
st := &typesfakes.FakeSubscribedTrack{}
st.IDReturns(trackID)
st.PublisherIDReturns(t.pubID)
st.PublisherIdentityReturns(t.pubIdentity)
mt.AddSubscriberReturns(st, nil)
st.MediaTrackReturns(mt)
res.Track = mt
}
return res
}
func setTestSubscribedTrackBound(t *testing.T, st types.SubscribedTrack) {
+11 -6
View File
@@ -268,7 +268,7 @@ type LocalParticipant interface {
RemoveTrackFromSubscriber(sender *webrtc.RTPSender) error
// subscriptions
SubscribeToTrack(trackID livekit.TrackID, publisherIdentity livekit.ParticipantIdentity, publisherID livekit.ParticipantID)
SubscribeToTrack(trackID livekit.TrackID)
UnsubscribeFromTrack(trackID livekit.TrackID)
UpdateSubscribedTrackSettings(trackID livekit.TrackID, settings *livekit.UpdateTrackSettings)
GetSubscribedTracks() []SubscribedTrack
@@ -303,6 +303,8 @@ type LocalParticipant interface {
OnTrackPublished(func(LocalParticipant, MediaTrack))
// OnTrackUpdated - one of its publishedTracks changed in status
OnTrackUpdated(callback func(LocalParticipant, MediaTrack))
// OnTrackUnpublished - a track was unpublished
OnTrackUnpublished(callback func(LocalParticipant, MediaTrack))
// OnParticipantUpdate - metadata or permission is updated
OnParticipantUpdate(callback func(LocalParticipant))
OnDataPacket(callback func(LocalParticipant, *livekit.DataPacket))
@@ -343,7 +345,7 @@ type Room interface {
SyncState(participant LocalParticipant, state *livekit.SyncState) error
SimulateScenario(participant LocalParticipant, scenario *livekit.SimulateScenario) error
UpdateVideoLayers(participant Participant, updateVideoLayers *livekit.UpdateVideoLayers) error
ResolveMediaTrackForSubscriber(subIdentity livekit.ParticipantIdentity, publisherID livekit.ParticipantID, trackID livekit.TrackID) (MediaResolverResult, error)
ResolveMediaTrackForSubscriber(subIdentity livekit.ParticipantIdentity, trackID livekit.TrackID) MediaResolverResult
}
// MediaTrack represents a media track
@@ -440,14 +442,17 @@ type ChangeNotifier interface {
}
type MediaResolverResult struct {
TrackChangeNotifier ChangeNotifier
Track MediaTrack
TrackChangedNotifier ChangeNotifier
TrackRemovedNotifier ChangeNotifier
Track MediaTrack
// is permission given to the requesting participant
HasPermission bool
HasPermission bool
PublisherID livekit.ParticipantID
PublisherIdentity livekit.ParticipantIdentity
}
// MediaTrackResolver locates a specific media track for a subscriber
type MediaTrackResolver func(livekit.ParticipantIdentity, livekit.ParticipantID, livekit.TrackID) (MediaResolverResult, error)
type MediaTrackResolver func(livekit.ParticipantIdentity, livekit.TrackID) MediaResolverResult
// Supervisor/operation monitor related definitions
type OperationMonitorEvent int
@@ -476,6 +476,11 @@ type FakeLocalParticipant struct {
onTrackPublishedArgsForCall []struct {
arg1 func(types.LocalParticipant, types.MediaTrack)
}
OnTrackUnpublishedStub func(func(types.LocalParticipant, types.MediaTrack))
onTrackUnpublishedMutex sync.RWMutex
onTrackUnpublishedArgsForCall []struct {
arg1 func(types.LocalParticipant, types.MediaTrack)
}
OnTrackUpdatedStub func(func(types.LocalParticipant, types.MediaTrack))
onTrackUpdatedMutex sync.RWMutex
onTrackUpdatedArgsForCall []struct {
@@ -663,12 +668,10 @@ type FakeLocalParticipant struct {
stateReturnsOnCall map[int]struct {
result1 livekit.ParticipantInfo_State
}
SubscribeToTrackStub func(livekit.TrackID, livekit.ParticipantIdentity, livekit.ParticipantID)
SubscribeToTrackStub func(livekit.TrackID)
subscribeToTrackMutex sync.RWMutex
subscribeToTrackArgsForCall []struct {
arg1 livekit.TrackID
arg2 livekit.ParticipantIdentity
arg3 livekit.ParticipantID
}
SubscriberAsPrimaryStub func() bool
subscriberAsPrimaryMutex sync.RWMutex
@@ -3273,6 +3276,38 @@ func (fake *FakeLocalParticipant) OnTrackPublishedArgsForCall(i int) func(types.
return argsForCall.arg1
}
func (fake *FakeLocalParticipant) OnTrackUnpublished(arg1 func(types.LocalParticipant, types.MediaTrack)) {
fake.onTrackUnpublishedMutex.Lock()
fake.onTrackUnpublishedArgsForCall = append(fake.onTrackUnpublishedArgsForCall, struct {
arg1 func(types.LocalParticipant, types.MediaTrack)
}{arg1})
stub := fake.OnTrackUnpublishedStub
fake.recordInvocation("OnTrackUnpublished", []interface{}{arg1})
fake.onTrackUnpublishedMutex.Unlock()
if stub != nil {
fake.OnTrackUnpublishedStub(arg1)
}
}
func (fake *FakeLocalParticipant) OnTrackUnpublishedCallCount() int {
fake.onTrackUnpublishedMutex.RLock()
defer fake.onTrackUnpublishedMutex.RUnlock()
return len(fake.onTrackUnpublishedArgsForCall)
}
func (fake *FakeLocalParticipant) OnTrackUnpublishedCalls(stub func(func(types.LocalParticipant, types.MediaTrack))) {
fake.onTrackUnpublishedMutex.Lock()
defer fake.onTrackUnpublishedMutex.Unlock()
fake.OnTrackUnpublishedStub = stub
}
func (fake *FakeLocalParticipant) OnTrackUnpublishedArgsForCall(i int) func(types.LocalParticipant, types.MediaTrack) {
fake.onTrackUnpublishedMutex.RLock()
defer fake.onTrackUnpublishedMutex.RUnlock()
argsForCall := fake.onTrackUnpublishedArgsForCall[i]
return argsForCall.arg1
}
func (fake *FakeLocalParticipant) OnTrackUpdated(arg1 func(types.LocalParticipant, types.MediaTrack)) {
fake.onTrackUpdatedMutex.Lock()
fake.onTrackUpdatedArgsForCall = append(fake.onTrackUpdatedArgsForCall, struct {
@@ -4334,18 +4369,16 @@ func (fake *FakeLocalParticipant) StateReturnsOnCall(i int, result1 livekit.Part
}{result1}
}
func (fake *FakeLocalParticipant) SubscribeToTrack(arg1 livekit.TrackID, arg2 livekit.ParticipantIdentity, arg3 livekit.ParticipantID) {
func (fake *FakeLocalParticipant) SubscribeToTrack(arg1 livekit.TrackID) {
fake.subscribeToTrackMutex.Lock()
fake.subscribeToTrackArgsForCall = append(fake.subscribeToTrackArgsForCall, struct {
arg1 livekit.TrackID
arg2 livekit.ParticipantIdentity
arg3 livekit.ParticipantID
}{arg1, arg2, arg3})
}{arg1})
stub := fake.SubscribeToTrackStub
fake.recordInvocation("SubscribeToTrack", []interface{}{arg1, arg2, arg3})
fake.recordInvocation("SubscribeToTrack", []interface{}{arg1})
fake.subscribeToTrackMutex.Unlock()
if stub != nil {
fake.SubscribeToTrackStub(arg1, arg2, arg3)
fake.SubscribeToTrackStub(arg1)
}
}
@@ -4355,17 +4388,17 @@ func (fake *FakeLocalParticipant) SubscribeToTrackCallCount() int {
return len(fake.subscribeToTrackArgsForCall)
}
func (fake *FakeLocalParticipant) SubscribeToTrackCalls(stub func(livekit.TrackID, livekit.ParticipantIdentity, livekit.ParticipantID)) {
func (fake *FakeLocalParticipant) SubscribeToTrackCalls(stub func(livekit.TrackID)) {
fake.subscribeToTrackMutex.Lock()
defer fake.subscribeToTrackMutex.Unlock()
fake.SubscribeToTrackStub = stub
}
func (fake *FakeLocalParticipant) SubscribeToTrackArgsForCall(i int) (livekit.TrackID, livekit.ParticipantIdentity, livekit.ParticipantID) {
func (fake *FakeLocalParticipant) SubscribeToTrackArgsForCall(i int) livekit.TrackID {
fake.subscribeToTrackMutex.RLock()
defer fake.subscribeToTrackMutex.RUnlock()
argsForCall := fake.subscribeToTrackArgsForCall[i]
return argsForCall.arg1, argsForCall.arg2, argsForCall.arg3
return argsForCall.arg1
}
func (fake *FakeLocalParticipant) SubscriberAsPrimary() bool {
@@ -5206,6 +5239,8 @@ func (fake *FakeLocalParticipant) Invocations() map[string][][]interface{} {
defer fake.onSubscribeStatusChangedMutex.RUnlock()
fake.onTrackPublishedMutex.RLock()
defer fake.onTrackPublishedMutex.RUnlock()
fake.onTrackUnpublishedMutex.RLock()
defer fake.onTrackUnpublishedMutex.RUnlock()
fake.onTrackUpdatedMutex.RLock()
defer fake.onTrackUpdatedMutex.RUnlock()
fake.protocolVersionMutex.RLock()
+16 -23
View File
@@ -36,20 +36,17 @@ type FakeRoom struct {
arg2 livekit.ParticipantID
arg3 types.ParticipantCloseReason
}
ResolveMediaTrackForSubscriberStub func(livekit.ParticipantIdentity, livekit.ParticipantID, livekit.TrackID) (types.MediaResolverResult, error)
ResolveMediaTrackForSubscriberStub func(livekit.ParticipantIdentity, livekit.TrackID) types.MediaResolverResult
resolveMediaTrackForSubscriberMutex sync.RWMutex
resolveMediaTrackForSubscriberArgsForCall []struct {
arg1 livekit.ParticipantIdentity
arg2 livekit.ParticipantID
arg3 livekit.TrackID
arg2 livekit.TrackID
}
resolveMediaTrackForSubscriberReturns struct {
result1 types.MediaResolverResult
result2 error
}
resolveMediaTrackForSubscriberReturnsOnCall map[int]struct {
result1 types.MediaResolverResult
result2 error
}
SimulateScenarioStub func(types.LocalParticipant, *livekit.SimulateScenario) error
simulateScenarioMutex sync.RWMutex
@@ -251,25 +248,24 @@ func (fake *FakeRoom) RemoveParticipantArgsForCall(i int) (livekit.ParticipantId
return argsForCall.arg1, argsForCall.arg2, argsForCall.arg3
}
func (fake *FakeRoom) ResolveMediaTrackForSubscriber(arg1 livekit.ParticipantIdentity, arg2 livekit.ParticipantID, arg3 livekit.TrackID) (types.MediaResolverResult, error) {
func (fake *FakeRoom) ResolveMediaTrackForSubscriber(arg1 livekit.ParticipantIdentity, arg2 livekit.TrackID) types.MediaResolverResult {
fake.resolveMediaTrackForSubscriberMutex.Lock()
ret, specificReturn := fake.resolveMediaTrackForSubscriberReturnsOnCall[len(fake.resolveMediaTrackForSubscriberArgsForCall)]
fake.resolveMediaTrackForSubscriberArgsForCall = append(fake.resolveMediaTrackForSubscriberArgsForCall, struct {
arg1 livekit.ParticipantIdentity
arg2 livekit.ParticipantID
arg3 livekit.TrackID
}{arg1, arg2, arg3})
arg2 livekit.TrackID
}{arg1, arg2})
stub := fake.ResolveMediaTrackForSubscriberStub
fakeReturns := fake.resolveMediaTrackForSubscriberReturns
fake.recordInvocation("ResolveMediaTrackForSubscriber", []interface{}{arg1, arg2, arg3})
fake.recordInvocation("ResolveMediaTrackForSubscriber", []interface{}{arg1, arg2})
fake.resolveMediaTrackForSubscriberMutex.Unlock()
if stub != nil {
return stub(arg1, arg2, arg3)
return stub(arg1, arg2)
}
if specificReturn {
return ret.result1, ret.result2
return ret.result1
}
return fakeReturns.result1, fakeReturns.result2
return fakeReturns.result1
}
func (fake *FakeRoom) ResolveMediaTrackForSubscriberCallCount() int {
@@ -278,43 +274,40 @@ func (fake *FakeRoom) ResolveMediaTrackForSubscriberCallCount() int {
return len(fake.resolveMediaTrackForSubscriberArgsForCall)
}
func (fake *FakeRoom) ResolveMediaTrackForSubscriberCalls(stub func(livekit.ParticipantIdentity, livekit.ParticipantID, livekit.TrackID) (types.MediaResolverResult, error)) {
func (fake *FakeRoom) ResolveMediaTrackForSubscriberCalls(stub func(livekit.ParticipantIdentity, livekit.TrackID) types.MediaResolverResult) {
fake.resolveMediaTrackForSubscriberMutex.Lock()
defer fake.resolveMediaTrackForSubscriberMutex.Unlock()
fake.ResolveMediaTrackForSubscriberStub = stub
}
func (fake *FakeRoom) ResolveMediaTrackForSubscriberArgsForCall(i int) (livekit.ParticipantIdentity, livekit.ParticipantID, livekit.TrackID) {
func (fake *FakeRoom) ResolveMediaTrackForSubscriberArgsForCall(i int) (livekit.ParticipantIdentity, livekit.TrackID) {
fake.resolveMediaTrackForSubscriberMutex.RLock()
defer fake.resolveMediaTrackForSubscriberMutex.RUnlock()
argsForCall := fake.resolveMediaTrackForSubscriberArgsForCall[i]
return argsForCall.arg1, argsForCall.arg2, argsForCall.arg3
return argsForCall.arg1, argsForCall.arg2
}
func (fake *FakeRoom) ResolveMediaTrackForSubscriberReturns(result1 types.MediaResolverResult, result2 error) {
func (fake *FakeRoom) ResolveMediaTrackForSubscriberReturns(result1 types.MediaResolverResult) {
fake.resolveMediaTrackForSubscriberMutex.Lock()
defer fake.resolveMediaTrackForSubscriberMutex.Unlock()
fake.ResolveMediaTrackForSubscriberStub = nil
fake.resolveMediaTrackForSubscriberReturns = struct {
result1 types.MediaResolverResult
result2 error
}{result1, result2}
}{result1}
}
func (fake *FakeRoom) ResolveMediaTrackForSubscriberReturnsOnCall(i int, result1 types.MediaResolverResult, result2 error) {
func (fake *FakeRoom) ResolveMediaTrackForSubscriberReturnsOnCall(i int, result1 types.MediaResolverResult) {
fake.resolveMediaTrackForSubscriberMutex.Lock()
defer fake.resolveMediaTrackForSubscriberMutex.Unlock()
fake.ResolveMediaTrackForSubscriberStub = nil
if fake.resolveMediaTrackForSubscriberReturnsOnCall == nil {
fake.resolveMediaTrackForSubscriberReturnsOnCall = make(map[int]struct {
result1 types.MediaResolverResult
result2 error
})
}
fake.resolveMediaTrackForSubscriberReturnsOnCall[i] = struct {
result1 types.MediaResolverResult
result2 error
}{result1, result2}
}{result1}
}
func (fake *FakeRoom) SimulateScenario(arg1 types.LocalParticipant, arg2 *livekit.SimulateScenario) error {
+4 -9
View File
@@ -38,7 +38,7 @@ type UpTrackManager struct {
// callbacks & handlers
onClose func()
onTrackUpdated func(track types.MediaTrack, onlyIfReady bool)
onTrackUpdated func(track types.MediaTrack)
}
func NewUpTrackManager(params UpTrackManagerParams) *UpTrackManager {
@@ -83,7 +83,7 @@ func (u *UpTrackManager) ToProto() []*livekit.TrackInfo {
return trackInfos
}
func (u *UpTrackManager) OnPublishedTrackUpdated(f func(track types.MediaTrack, onlyIfReady bool)) {
func (u *UpTrackManager) OnPublishedTrackUpdated(f func(track types.MediaTrack)) {
u.onTrackUpdated = f
}
@@ -99,7 +99,7 @@ func (u *UpTrackManager) SetPublishedTrackMuted(trackID livekit.TrackID, muted b
if currentMuted != track.IsMuted() {
u.params.Logger.Infow("publisher mute status changed", "trackID", trackID, "muted", track.IsMuted())
if u.onTrackUpdated != nil {
u.onTrackUpdated(track, false)
u.onTrackUpdated(track)
}
}
}
@@ -232,7 +232,7 @@ func (u *UpTrackManager) UpdateVideoLayers(updateVideoLayers *livekit.UpdateVide
track.UpdateVideoLayers(updateVideoLayers.Layers)
if u.onTrackUpdated != nil {
u.onTrackUpdated(track, false)
u.onTrackUpdated(track)
}
return nil
@@ -260,11 +260,6 @@ func (u *UpTrackManager) AddPublishedTrack(track types.MediaTrack) {
}
u.lock.Unlock()
// only send this when client is in a ready state
if u.onTrackUpdated != nil {
u.onTrackUpdated(track, true)
}
if notifyClose && u.onClose != nil {
u.onClose()
}
-2
View File
@@ -245,14 +245,12 @@ func (t *telemetryService) TrackSubscribeRequested(
ctx context.Context,
participantID livekit.ParticipantID,
track *livekit.TrackInfo,
publisher *livekit.ParticipantInfo,
) {
t.enqueue(func() {
prometheus.RecordTrackSubscribeAttempt()
room := t.getRoomDetails(participantID)
ev := newTrackEvent(livekit.AnalyticsEventType_TRACK_SUBSCRIBE_REQUESTED, room, participantID, track)
ev.Publisher = publisher
t.SendEvent(ctx, ev)
})
}
@@ -145,13 +145,12 @@ type FakeTelemetryService struct {
arg4 error
arg5 bool
}
TrackSubscribeRequestedStub func(context.Context, livekit.ParticipantID, *livekit.TrackInfo, *livekit.ParticipantInfo)
TrackSubscribeRequestedStub func(context.Context, livekit.ParticipantID, *livekit.TrackInfo)
trackSubscribeRequestedMutex sync.RWMutex
trackSubscribeRequestedArgsForCall []struct {
arg1 context.Context
arg2 livekit.ParticipantID
arg3 *livekit.TrackInfo
arg4 *livekit.ParticipantInfo
}
TrackSubscribedStub func(context.Context, livekit.ParticipantID, *livekit.TrackInfo, *livekit.ParticipantInfo, bool)
trackSubscribedMutex sync.RWMutex
@@ -836,19 +835,18 @@ func (fake *FakeTelemetryService) TrackSubscribeFailedArgsForCall(i int) (contex
return argsForCall.arg1, argsForCall.arg2, argsForCall.arg3, argsForCall.arg4, argsForCall.arg5
}
func (fake *FakeTelemetryService) TrackSubscribeRequested(arg1 context.Context, arg2 livekit.ParticipantID, arg3 *livekit.TrackInfo, arg4 *livekit.ParticipantInfo) {
func (fake *FakeTelemetryService) TrackSubscribeRequested(arg1 context.Context, arg2 livekit.ParticipantID, arg3 *livekit.TrackInfo) {
fake.trackSubscribeRequestedMutex.Lock()
fake.trackSubscribeRequestedArgsForCall = append(fake.trackSubscribeRequestedArgsForCall, struct {
arg1 context.Context
arg2 livekit.ParticipantID
arg3 *livekit.TrackInfo
arg4 *livekit.ParticipantInfo
}{arg1, arg2, arg3, arg4})
}{arg1, arg2, arg3})
stub := fake.TrackSubscribeRequestedStub
fake.recordInvocation("TrackSubscribeRequested", []interface{}{arg1, arg2, arg3, arg4})
fake.recordInvocation("TrackSubscribeRequested", []interface{}{arg1, arg2, arg3})
fake.trackSubscribeRequestedMutex.Unlock()
if stub != nil {
fake.TrackSubscribeRequestedStub(arg1, arg2, arg3, arg4)
fake.TrackSubscribeRequestedStub(arg1, arg2, arg3)
}
}
@@ -858,17 +856,17 @@ func (fake *FakeTelemetryService) TrackSubscribeRequestedCallCount() int {
return len(fake.trackSubscribeRequestedArgsForCall)
}
func (fake *FakeTelemetryService) TrackSubscribeRequestedCalls(stub func(context.Context, livekit.ParticipantID, *livekit.TrackInfo, *livekit.ParticipantInfo)) {
func (fake *FakeTelemetryService) TrackSubscribeRequestedCalls(stub func(context.Context, livekit.ParticipantID, *livekit.TrackInfo)) {
fake.trackSubscribeRequestedMutex.Lock()
defer fake.trackSubscribeRequestedMutex.Unlock()
fake.TrackSubscribeRequestedStub = stub
}
func (fake *FakeTelemetryService) TrackSubscribeRequestedArgsForCall(i int) (context.Context, livekit.ParticipantID, *livekit.TrackInfo, *livekit.ParticipantInfo) {
func (fake *FakeTelemetryService) TrackSubscribeRequestedArgsForCall(i int) (context.Context, livekit.ParticipantID, *livekit.TrackInfo) {
fake.trackSubscribeRequestedMutex.RLock()
defer fake.trackSubscribeRequestedMutex.RUnlock()
argsForCall := fake.trackSubscribeRequestedArgsForCall[i]
return argsForCall.arg1, argsForCall.arg2, argsForCall.arg3, argsForCall.arg4
return argsForCall.arg1, argsForCall.arg2, argsForCall.arg3
}
func (fake *FakeTelemetryService) TrackSubscribed(arg1 context.Context, arg2 livekit.ParticipantID, arg3 *livekit.TrackInfo, arg4 *livekit.ParticipantInfo, arg5 bool) {
+1 -1
View File
@@ -36,7 +36,7 @@ type TelemetryService interface {
// TrackUnpublished - a participant unpublished a track
TrackUnpublished(ctx context.Context, participantID livekit.ParticipantID, identity livekit.ParticipantIdentity, track *livekit.TrackInfo, shouldSendEvent bool)
// TrackSubscribeRequested - a participant requested to subscribe to a track
TrackSubscribeRequested(ctx context.Context, participantID livekit.ParticipantID, track *livekit.TrackInfo, publisher *livekit.ParticipantInfo)
TrackSubscribeRequested(ctx context.Context, participantID livekit.ParticipantID, track *livekit.TrackInfo)
// TrackSubscribed - a participant subscribed to a track successfully
TrackSubscribed(ctx context.Context, participantID livekit.ParticipantID, track *livekit.TrackInfo, publisher *livekit.ParticipantInfo, shouldSendEvent bool)
// TrackUnsubscribed - a participant unsubscribed from a track successfully