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:
@@ -14,7 +14,6 @@ var (
|
|||||||
ErrMissingGrants = errors.New("VideoGrant is missing")
|
ErrMissingGrants = errors.New("VideoGrant is missing")
|
||||||
|
|
||||||
// Track subscription related
|
// Track subscription related
|
||||||
ErrPublisherNotConnected = errors.New("publisher is not connected")
|
|
||||||
ErrNoTrackPermission = errors.New("participant is not allowed to subscribe to this track")
|
ErrNoTrackPermission = errors.New("participant is not allowed to subscribe to this track")
|
||||||
ErrNoSubscribePermission = errors.New("participant is not given permission to subscribe to tracks")
|
ErrNoSubscribePermission = errors.New("participant is not given permission to subscribe to tracks")
|
||||||
ErrTrackNotFound = errors.New("track cannot be found")
|
ErrTrackNotFound = errors.New("track cannot be found")
|
||||||
|
|||||||
+23
-7
@@ -138,6 +138,7 @@ type ParticipantImpl struct {
|
|||||||
// callbacks & handlers
|
// callbacks & handlers
|
||||||
onTrackPublished func(types.LocalParticipant, types.MediaTrack)
|
onTrackPublished func(types.LocalParticipant, types.MediaTrack)
|
||||||
onTrackUpdated 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)
|
onStateChange func(p types.LocalParticipant, oldState livekit.ParticipantInfo_State)
|
||||||
onParticipantUpdate func(types.LocalParticipant)
|
onParticipantUpdate func(types.LocalParticipant)
|
||||||
onDataPacket func(types.LocalParticipant, *livekit.DataPacket)
|
onDataPacket func(types.LocalParticipant, *livekit.DataPacket)
|
||||||
@@ -412,6 +413,12 @@ func (p *ParticipantImpl) OnTrackPublished(callback func(types.LocalParticipant,
|
|||||||
p.lock.Unlock()
|
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)) {
|
func (p *ParticipantImpl) OnStateChange(callback func(p types.LocalParticipant, oldState livekit.ParticipantInfo_State)) {
|
||||||
p.lock.Lock()
|
p.lock.Lock()
|
||||||
p.onStateChange = callback
|
p.onStateChange = callback
|
||||||
@@ -1011,11 +1018,7 @@ func (p *ParticipantImpl) setupUpTrackManager() {
|
|||||||
VersionGenerator: p.params.VersionGenerator,
|
VersionGenerator: p.params.VersionGenerator,
|
||||||
})
|
})
|
||||||
|
|
||||||
p.UpTrackManager.OnPublishedTrackUpdated(func(track types.MediaTrack, onlyIfReady bool) {
|
p.UpTrackManager.OnPublishedTrackUpdated(func(track types.MediaTrack) {
|
||||||
if onlyIfReady && !p.IsReady() {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
p.lock.RLock()
|
p.lock.RLock()
|
||||||
onTrackUpdated := p.onTrackUpdated
|
onTrackUpdated := p.onTrackUpdated
|
||||||
p.lock.RUnlock()
|
p.lock.RUnlock()
|
||||||
@@ -1613,8 +1616,9 @@ func (p *ParticipantImpl) addMediaTrack(signalCid string, sdpCid string, ti *liv
|
|||||||
delete(p.pendingTracks, signalCid)
|
delete(p.pendingTracks, signalCid)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
trackID := livekit.TrackID(ti.Sid)
|
||||||
mt.AddOnClose(func() {
|
mt.AddOnClose(func() {
|
||||||
p.supervisor.ClearPublishedTrack(livekit.TrackID(ti.Sid), mt)
|
p.supervisor.ClearPublishedTrack(trackID, mt)
|
||||||
|
|
||||||
// not logged when closing
|
// not logged when closing
|
||||||
p.params.Telemetry.TrackUnpublished(
|
p.params.Telemetry.TrackUnpublished(
|
||||||
@@ -1625,14 +1629,26 @@ func (p *ParticipantImpl) addMediaTrack(signalCid string, sdpCid string, ti *liv
|
|||||||
!p.IsClosed(),
|
!p.IsClosed(),
|
||||||
)
|
)
|
||||||
|
|
||||||
// re-use track sid
|
isUnpublished := false
|
||||||
|
// re-use Track sid
|
||||||
p.pendingTracksLock.Lock()
|
p.pendingTracksLock.Lock()
|
||||||
if pti := p.pendingTracks[signalCid]; pti != nil {
|
if pti := p.pendingTracks[signalCid]; pti != nil {
|
||||||
p.sendTrackPublished(signalCid, pti.trackInfos[0])
|
p.sendTrackPublished(signalCid, pti.trackInfos[0])
|
||||||
} else {
|
} else {
|
||||||
p.unpublishedTracks = append(p.unpublishedTracks, ti)
|
p.unpublishedTracks = append(p.unpublishedTracks, ti)
|
||||||
|
isUnpublished = true
|
||||||
}
|
}
|
||||||
p.pendingTracksLock.Unlock()
|
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
|
return mt
|
||||||
|
|||||||
@@ -71,14 +71,9 @@ func TestTrackPublishing(t *testing.T) {
|
|||||||
})
|
})
|
||||||
p.UpTrackManager.AddPublishedTrack(track)
|
p.UpTrackManager.AddPublishedTrack(track)
|
||||||
p.handleTrackPublished(track)
|
p.handleTrackPublished(track)
|
||||||
|
|
||||||
require.True(t, published)
|
require.True(t, published)
|
||||||
require.False(t, updated)
|
require.False(t, updated)
|
||||||
require.Len(t, p.UpTrackManager.publishedTracks, 1)
|
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) {
|
t.Run("sends back trackPublished event", func(t *testing.T) {
|
||||||
|
|||||||
+45
-50
@@ -13,7 +13,6 @@ import (
|
|||||||
"google.golang.org/protobuf/proto"
|
"google.golang.org/protobuf/proto"
|
||||||
|
|
||||||
"github.com/livekit/livekit-server/pkg/sfu/connectionquality"
|
"github.com/livekit/livekit-server/pkg/sfu/connectionquality"
|
||||||
"github.com/livekit/livekit-server/pkg/utils"
|
|
||||||
"github.com/livekit/protocol/livekit"
|
"github.com/livekit/protocol/livekit"
|
||||||
"github.com/livekit/protocol/logger"
|
"github.com/livekit/protocol/logger"
|
||||||
|
|
||||||
@@ -50,7 +49,7 @@ type Room struct {
|
|||||||
serverInfo *livekit.ServerInfo
|
serverInfo *livekit.ServerInfo
|
||||||
telemetry telemetry.TelemetryService
|
telemetry telemetry.TelemetryService
|
||||||
egressLauncher EgressLauncher
|
egressLauncher EgressLauncher
|
||||||
changeNotifier *utils.ChangeNotifierManager
|
trackManager *RoomTrackManager
|
||||||
|
|
||||||
// map of identity -> Participant
|
// map of identity -> Participant
|
||||||
participants map[livekit.ParticipantIdentity]types.LocalParticipant
|
participants map[livekit.ParticipantIdentity]types.LocalParticipant
|
||||||
@@ -94,7 +93,7 @@ func NewRoom(
|
|||||||
audioConfig: audioConfig,
|
audioConfig: audioConfig,
|
||||||
telemetry: telemetry,
|
telemetry: telemetry,
|
||||||
egressLauncher: egressLauncher,
|
egressLauncher: egressLauncher,
|
||||||
changeNotifier: utils.NewChangeNotifierManager(),
|
trackManager: NewRoomTrackManager(),
|
||||||
serverInfo: serverInfo,
|
serverInfo: serverInfo,
|
||||||
participants: make(map[livekit.ParticipantIdentity]types.LocalParticipant),
|
participants: make(map[livekit.ParticipantIdentity]types.LocalParticipant),
|
||||||
participantOpts: make(map[livekit.ParticipantIdentity]*ParticipantOptions),
|
participantOpts: make(map[livekit.ParticipantIdentity]*ParticipantOptions),
|
||||||
@@ -251,7 +250,7 @@ func (r *Room) Join(participant types.LocalParticipant, opts *ParticipantOptions
|
|||||||
r.protoRoom.NumParticipants++
|
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.OnTrackPublished(r.onTrackPublished)
|
||||||
participant.OnStateChange(func(p types.LocalParticipant, oldState livekit.ParticipantInfo_State) {
|
participant.OnStateChange(func(p types.LocalParticipant, oldState livekit.ParticipantInfo_State) {
|
||||||
r.Logger.Infow("participant state changed",
|
r.Logger.Infow("participant state changed",
|
||||||
@@ -266,7 +265,7 @@ func (r *Room) Join(participant types.LocalParticipant, opts *ParticipantOptions
|
|||||||
|
|
||||||
state := p.State()
|
state := p.State()
|
||||||
if state == livekit.ParticipantInfo_ACTIVE {
|
if state == livekit.ParticipantInfo_ACTIVE {
|
||||||
// subscribe participant to existing publishedTracks
|
// subscribe participant to existing published tracks
|
||||||
r.subscribeToExistingTracks(p)
|
r.subscribeToExistingTracks(p)
|
||||||
|
|
||||||
// start the workers once connectivity is established
|
// 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.OnTrackUpdated(r.onTrackUpdated)
|
||||||
|
participant.OnTrackUnpublished(r.onTrackUnpublished)
|
||||||
participant.OnParticipantUpdate(r.onParticipantUpdate)
|
participant.OnParticipantUpdate(r.onParticipantUpdate)
|
||||||
participant.OnDataPacket(r.onDataPacket)
|
participant.OnDataPacket(r.onDataPacket)
|
||||||
participant.OnSubscribeStatusChanged(func(publisherID livekit.ParticipantID, subscribed bool) {
|
participant.OnSubscribeStatusChanged(func(publisherID livekit.ParticipantID, subscribed bool) {
|
||||||
@@ -425,16 +425,12 @@ func (r *Room) RemoveParticipant(identity livekit.ParticipantIdentity, pID livek
|
|||||||
return
|
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
|
// send broadcast only if it's not already closed
|
||||||
sendUpdates := !p.IsDisconnected()
|
sendUpdates := !p.IsDisconnected()
|
||||||
|
|
||||||
p.OnTrackUpdated(nil)
|
p.OnTrackUpdated(nil)
|
||||||
p.OnTrackPublished(nil)
|
p.OnTrackPublished(nil)
|
||||||
|
p.OnTrackUnpublished(nil)
|
||||||
p.OnStateChange(nil)
|
p.OnStateChange(nil)
|
||||||
p.OnParticipantUpdate(nil)
|
p.OnParticipantUpdate(nil)
|
||||||
p.OnDataPacket(nil)
|
p.OnDataPacket(nil)
|
||||||
@@ -464,40 +460,25 @@ func (r *Room) UpdateSubscriptions(
|
|||||||
participantTracks []*livekit.ParticipantTracks,
|
participantTracks []*livekit.ParticipantTracks,
|
||||||
subscribe bool,
|
subscribe bool,
|
||||||
) {
|
) {
|
||||||
// find all matching tracks
|
// handle subscription changes
|
||||||
publisherIDs := make(map[livekit.TrackID]livekit.ParticipantID)
|
|
||||||
publisherIdentities := make(map[livekit.TrackID]livekit.ParticipantIdentity)
|
|
||||||
participants := r.GetParticipants()
|
|
||||||
for _, trackID := range trackIDs {
|
for _, trackID := range trackIDs {
|
||||||
for _, p := range participants {
|
if subscribe {
|
||||||
track := p.GetPublishedTrack(trackID)
|
participant.SubscribeToTrack(trackID)
|
||||||
if track != nil {
|
} else {
|
||||||
publisherIDs[trackID] = p.ID()
|
participant.UnsubscribeFromTrack(trackID)
|
||||||
publisherIdentities[trackID] = p.Identity()
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, pt := range participantTracks {
|
for _, pt := range participantTracks {
|
||||||
pub := r.GetParticipantByID(livekit.ParticipantID(pt.ParticipantSid))
|
|
||||||
for _, trackID := range livekit.StringsAsTrackIDs(pt.TrackSids) {
|
for _, trackID := range livekit.StringsAsTrackIDs(pt.TrackSids) {
|
||||||
publisherIDs[trackID] = livekit.ParticipantID(pt.ParticipantSid)
|
|
||||||
if pub != nil {
|
|
||||||
publisherIdentities[trackID] = pub.Identity()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// handle subscription changes
|
|
||||||
for trackID, publisherID := range publisherIDs {
|
|
||||||
if subscribe {
|
if subscribe {
|
||||||
participant.SubscribeToTrack(trackID, publisherIdentities[trackID], publisherID)
|
participant.SubscribeToTrack(trackID)
|
||||||
} else {
|
} else {
|
||||||
participant.UnsubscribeFromTrack(trackID)
|
participant.UnsubscribeFromTrack(trackID)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (r *Room) SyncState(participant types.LocalParticipant, state *livekit.SyncState) error {
|
func (r *Room) SyncState(participant types.LocalParticipant, state *livekit.SyncState) error {
|
||||||
return nil
|
return nil
|
||||||
@@ -508,10 +489,7 @@ func (r *Room) UpdateSubscriptionPermission(participant types.LocalParticipant,
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
for _, track := range participant.GetPublishedTracks() {
|
for _, track := range participant.GetPublishedTracks() {
|
||||||
notifier := r.changeNotifier.GetNotifier(string(track.ID()))
|
r.trackManager.NotifyTrackChanged(track.ID())
|
||||||
if notifier != nil {
|
|
||||||
notifier.NotifyChanged()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -534,18 +512,28 @@ func (r *Room) UpdateVideoLayers(participant types.Participant, updateVideoLayer
|
|||||||
return participant.UpdateVideoLayers(updateVideoLayers)
|
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{}
|
res := types.MediaResolverResult{}
|
||||||
pub := r.GetParticipantByID(publisherID)
|
|
||||||
if pub == nil {
|
info := r.trackManager.GetTrackInfo(trackID)
|
||||||
return res, ErrPublisherNotConnected
|
res.TrackChangedNotifier = r.trackManager.GetOrCreateTrackChangeNotifier(trackID)
|
||||||
|
|
||||||
|
if info == nil {
|
||||||
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
res.Track = pub.GetPublishedTrack(trackID)
|
res.Track = info.Track
|
||||||
res.TrackChangeNotifier = r.changeNotifier.GetOrCreateNotifier(string(trackID))
|
res.TrackRemovedNotifier = r.trackManager.GetOrCreateTrackRemoveNotifier(trackID)
|
||||||
res.HasPermission = pub.HasPermission(trackID, subIdentity)
|
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 {
|
func (r *Room) IsClosed() bool {
|
||||||
@@ -768,7 +756,7 @@ func (r *Room) onTrackPublished(participant types.LocalParticipant, track types.
|
|||||||
"publisher", participant.Identity(),
|
"publisher", participant.Identity(),
|
||||||
"publisherID", participant.ID(),
|
"publisherID", participant.ID(),
|
||||||
"trackID", track.ID())
|
"trackID", track.ID())
|
||||||
existingParticipant.SubscribeToTrack(track.ID(), participant.Identity(), participant.ID())
|
existingParticipant.SubscribeToTrack(track.ID())
|
||||||
}
|
}
|
||||||
onParticipantChanged := r.onParticipantChanged
|
onParticipantChanged := r.onParticipantChanged
|
||||||
r.lock.RUnlock()
|
r.lock.RUnlock()
|
||||||
@@ -777,10 +765,7 @@ func (r *Room) onTrackPublished(participant types.LocalParticipant, track types.
|
|||||||
onParticipantChanged(participant)
|
onParticipantChanged(participant)
|
||||||
}
|
}
|
||||||
|
|
||||||
notifier := r.changeNotifier.GetNotifier(string(track.ID()))
|
r.trackManager.AddTrack(track, participant.Identity(), participant.ID())
|
||||||
if notifier != nil {
|
|
||||||
notifier.NotifyChanged()
|
|
||||||
}
|
|
||||||
|
|
||||||
// auto track egress
|
// auto track egress
|
||||||
if r.internal != nil && r.internal.TrackEgress != nil {
|
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) {
|
func (r *Room) onParticipantUpdate(p types.LocalParticipant) {
|
||||||
// immediately notify when permissions or metadata changed
|
// immediately notify when permissions or metadata changed
|
||||||
r.broadcastParticipantState(p, broadcastOptions{immediate: true})
|
r.broadcastParticipantState(p, broadcastOptions{immediate: true})
|
||||||
@@ -871,7 +866,7 @@ func (r *Room) subscribeToExistingTracks(p types.LocalParticipant) {
|
|||||||
// subscribe to all
|
// subscribe to all
|
||||||
for _, track := range op.GetPublishedTracks() {
|
for _, track := range op.GetPublishedTracks() {
|
||||||
trackIDs = append(trackIDs, track.ID())
|
trackIDs = append(trackIDs, track.ID())
|
||||||
p.SubscribeToTrack(track.ID(), op.Identity(), op.ID())
|
p.SubscribeToTrack(track.ID())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if len(trackIDs) > 0 {
|
if len(trackIDs) > 0 {
|
||||||
|
|||||||
@@ -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))
|
||||||
|
}
|
||||||
@@ -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()
|
m.lock.Lock()
|
||||||
sub, ok := m.subscriptions[trackID]
|
sub, ok := m.subscriptions[trackID]
|
||||||
if !ok {
|
if !ok {
|
||||||
sLogger := m.params.Logger.WithValues(
|
sLogger := m.params.Logger.WithValues(
|
||||||
"trackID", trackID,
|
"trackID", trackID,
|
||||||
"publisherID", publisherID,
|
|
||||||
"publisherIdentity", publisherIdentity,
|
|
||||||
)
|
)
|
||||||
sub = newTrackSubscription(m.params.Participant.ID(), trackID, sLogger)
|
sub = newTrackSubscription(m.params.Participant.ID(), trackID, sLogger)
|
||||||
m.subscriptions[trackID] = sub
|
m.subscriptions[trackID] = sub
|
||||||
}
|
}
|
||||||
desireChanged := sub.setDesired(true)
|
desireChanged := sub.setDesired(true)
|
||||||
m.lock.Unlock()
|
m.lock.Unlock()
|
||||||
sub.setPublisher(publisherIdentity, publisherID)
|
|
||||||
if desireChanged {
|
if desireChanged {
|
||||||
sub.logger.Infow("subscribing to track")
|
sub.logger.Infow("subscribing to track")
|
||||||
}
|
}
|
||||||
@@ -274,10 +271,6 @@ func (m *SubscriptionManager) reconcileSubscription(s *trackSubscription) {
|
|||||||
&livekit.TrackInfo{
|
&livekit.TrackInfo{
|
||||||
Sid: string(s.trackID),
|
Sid: string(s.trackID),
|
||||||
},
|
},
|
||||||
&livekit.ParticipantInfo{
|
|
||||||
Sid: string(s.getPublisherID()),
|
|
||||||
Identity: string(s.getPublisherIdentity()),
|
|
||||||
},
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
if err := m.subscribe(s); err != nil {
|
if err := m.subscribe(s); err != nil {
|
||||||
@@ -295,8 +288,8 @@ func (m *SubscriptionManager) reconcileSubscription(s *trackSubscription) {
|
|||||||
if s.durationSinceStart() > subscriptionTimeout {
|
if s.durationSinceStart() > subscriptionTimeout {
|
||||||
s.maybeRecordError(m.params.Telemetry, m.params.Participant.ID(), err, true)
|
s.maybeRecordError(m.params.Telemetry, m.params.Participant.ID(), err, true)
|
||||||
}
|
}
|
||||||
case ErrPublisherNotConnected, ErrTrackNotFound:
|
case ErrTrackNotFound:
|
||||||
// publisher left or source track was never published or closed
|
// source track was never published or closed
|
||||||
// if after timeout, we'd unsubscribe from it.
|
// if after timeout, we'd unsubscribe from it.
|
||||||
// this is the *only* case we'd change desired state
|
// this is the *only* case we'd change desired state
|
||||||
if s.durationSinceStart() > notFoundTimeout {
|
if s.durationSinceStart() > notFoundTimeout {
|
||||||
@@ -393,21 +386,24 @@ func (m *SubscriptionManager) subscribe(s *trackSubscription) error {
|
|||||||
return ErrNoSubscribePermission
|
return ErrNoSubscribePermission
|
||||||
}
|
}
|
||||||
|
|
||||||
res, err := m.params.TrackResolver(m.params.Participant.Identity(), s.publisherID, s.trackID)
|
res := m.params.TrackResolver(m.params.Participant.Identity(), s.trackID)
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
s.logger.Debugw("resolved track", "result", res)
|
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
|
// 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
|
// we set the observer before checking for existence of track, so that we may get notified
|
||||||
// available
|
// when the track becomes available
|
||||||
res.TrackChangeNotifier.AddObserver(string(m.params.Participant.ID()), func() {
|
res.TrackChangedNotifier.AddObserver(string(m.params.Participant.ID()), func() {
|
||||||
m.queueReconcile(s.trackID)
|
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
|
track := res.Track
|
||||||
if track == nil {
|
if track == nil {
|
||||||
@@ -424,6 +420,7 @@ func (m *SubscriptionManager) subscribe(s *trackSubscription) error {
|
|||||||
return ErrNoTrackPermission
|
return ErrNoTrackPermission
|
||||||
}
|
}
|
||||||
|
|
||||||
|
s.setPublisher(res.PublisherIdentity, res.PublisherID)
|
||||||
subTrack, err := track.AddSubscriber(m.params.Participant)
|
subTrack, err := track.AddSubscriber(m.params.Participant)
|
||||||
if err != nil && err != errAlreadySubscribed {
|
if err != nil && err != errAlreadySubscribed {
|
||||||
// ignore already subscribed error
|
// ignore already subscribed error
|
||||||
@@ -568,7 +565,8 @@ type trackSubscription struct {
|
|||||||
publisherID livekit.ParticipantID
|
publisherID livekit.ParticipantID
|
||||||
publisherIdentity livekit.ParticipantIdentity
|
publisherIdentity livekit.ParticipantIdentity
|
||||||
settings *livekit.UpdateTrackSettings
|
settings *livekit.UpdateTrackSettings
|
||||||
changeNotifier types.ChangeNotifier
|
changedNotifier types.ChangeNotifier
|
||||||
|
removedNotifier types.ChangeNotifier
|
||||||
hasPermission bool
|
hasPermission bool
|
||||||
subscribedTrack types.SubscribedTrack
|
subscribedTrack types.SubscribedTrack
|
||||||
eventSent atomic.Bool
|
eventSent atomic.Bool
|
||||||
@@ -604,16 +602,8 @@ func (s *trackSubscription) getPublisherID() livekit.ParticipantID {
|
|||||||
return s.publisherID
|
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 {
|
func (s *trackSubscription) setDesired(desired bool) bool {
|
||||||
s.lock.Lock()
|
s.lock.Lock()
|
||||||
defer s.lock.Unlock()
|
|
||||||
|
|
||||||
if desired {
|
if desired {
|
||||||
// as long as user explicitly set it to desired
|
// as long as user explicitly set it to desired
|
||||||
// we'll reset the timer so it has sufficient time to reconcile
|
// 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 {
|
if s.desired == desired {
|
||||||
|
s.lock.Unlock()
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
s.desired = desired
|
s.desired = desired
|
||||||
// when no longer desired, we no longer care about change notifications
|
s.lock.Unlock()
|
||||||
if !desired && s.changeNotifier != nil {
|
|
||||||
s.changeNotifier.RemoveObserver(string(s.subscriberID))
|
|
||||||
s.changeNotifier = nil
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// when no longer desired, we no longer care about change notifications
|
||||||
if desired {
|
if desired {
|
||||||
// reset attempts
|
// reset attempts
|
||||||
s.numAttempts.Store(0)
|
s.numAttempts.Store(0)
|
||||||
|
} else {
|
||||||
|
s.setChangedNotifier(nil)
|
||||||
|
s.setRemovedNotifier(nil)
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
@@ -684,15 +675,32 @@ func (s *trackSubscription) getSubscribedTrack() types.SubscribedTrack {
|
|||||||
return s.subscribedTrack
|
return s.subscribedTrack
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *trackSubscription) setChangeNotifier(notifier types.ChangeNotifier) bool {
|
func (s *trackSubscription) setChangedNotifier(notifier types.ChangeNotifier) bool {
|
||||||
s.lock.Lock()
|
s.lock.Lock()
|
||||||
if s.changeNotifier == notifier {
|
if s.changedNotifier == notifier {
|
||||||
s.lock.Unlock()
|
s.lock.Unlock()
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
existing := s.changeNotifier
|
existing := s.changedNotifier
|
||||||
s.changeNotifier = notifier
|
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()
|
s.lock.Unlock()
|
||||||
|
|
||||||
if existing != nil {
|
if existing != nil {
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ func TestSubscribe(t *testing.T) {
|
|||||||
t.Run("happy path subscribe", func(t *testing.T) {
|
t.Run("happy path subscribe", func(t *testing.T) {
|
||||||
sm := newTestSubscriptionManager(t)
|
sm := newTestSubscriptionManager(t)
|
||||||
defer sm.Close(false)
|
defer sm.Close(false)
|
||||||
resolver := newTestResolver(true, nil)
|
resolver := newTestResolver(true, true, "pub", "pubID")
|
||||||
sm.params.TrackResolver = resolver.Resolve
|
sm.params.TrackResolver = resolver.Resolve
|
||||||
subCount := atomic.Int32{}
|
subCount := atomic.Int32{}
|
||||||
failed := atomic.Bool{}
|
failed := atomic.Bool{}
|
||||||
@@ -67,7 +67,7 @@ func TestSubscribe(t *testing.T) {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
sm.SubscribeToTrack("track", "pub", "pubID")
|
sm.SubscribeToTrack("track")
|
||||||
s := sm.subscriptions["track"]
|
s := sm.subscriptions["track"]
|
||||||
require.True(t, s.isDesired())
|
require.True(t, s.isDesired())
|
||||||
require.Eventually(t, func() bool {
|
require.Eventually(t, func() bool {
|
||||||
@@ -112,14 +112,14 @@ func TestSubscribe(t *testing.T) {
|
|||||||
t.Run("no track permission", func(t *testing.T) {
|
t.Run("no track permission", func(t *testing.T) {
|
||||||
sm := newTestSubscriptionManager(t)
|
sm := newTestSubscriptionManager(t)
|
||||||
defer sm.Close(false)
|
defer sm.Close(false)
|
||||||
resolver := newTestResolver(false, nil)
|
resolver := newTestResolver(false, true, "pub", "pubID")
|
||||||
sm.params.TrackResolver = resolver.Resolve
|
sm.params.TrackResolver = resolver.Resolve
|
||||||
failed := atomic.Bool{}
|
failed := atomic.Bool{}
|
||||||
sm.params.OnSubcriptionError = func(trackID livekit.TrackID) {
|
sm.params.OnSubcriptionError = func(trackID livekit.TrackID) {
|
||||||
failed.Store(true)
|
failed.Store(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
sm.SubscribeToTrack("track", "pub", "pubID")
|
sm.SubscribeToTrack("track")
|
||||||
s := sm.subscriptions["track"]
|
s := sm.subscriptions["track"]
|
||||||
require.Eventually(t, func() bool {
|
require.Eventually(t, func() bool {
|
||||||
return !s.getHasPermission()
|
return !s.getHasPermission()
|
||||||
@@ -153,21 +153,21 @@ func TestSubscribe(t *testing.T) {
|
|||||||
t.Run("publisher left", func(t *testing.T) {
|
t.Run("publisher left", func(t *testing.T) {
|
||||||
sm := newTestSubscriptionManager(t)
|
sm := newTestSubscriptionManager(t)
|
||||||
defer sm.Close(false)
|
defer sm.Close(false)
|
||||||
resolver := newTestResolver(true, nil)
|
resolver := newTestResolver(true, true, "pub", "pubID")
|
||||||
sm.params.TrackResolver = resolver.Resolve
|
sm.params.TrackResolver = resolver.Resolve
|
||||||
failed := atomic.Bool{}
|
failed := atomic.Bool{}
|
||||||
sm.params.OnSubcriptionError = func(trackID livekit.TrackID) {
|
sm.params.OnSubcriptionError = func(trackID livekit.TrackID) {
|
||||||
failed.Store(true)
|
failed.Store(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
sm.SubscribeToTrack("track", "pub", "pubID")
|
sm.SubscribeToTrack("track")
|
||||||
s := sm.subscriptions["track"]
|
s := sm.subscriptions["track"]
|
||||||
require.Eventually(t, func() bool {
|
require.Eventually(t, func() bool {
|
||||||
return !s.needsSubscribe()
|
return !s.needsSubscribe()
|
||||||
}, subSettleTimeout, subCheckInterval, "should be subscribed")
|
}, subSettleTimeout, subCheckInterval, "should be subscribed")
|
||||||
|
|
||||||
resolver.lock.Lock()
|
resolver.lock.Lock()
|
||||||
resolver.err = ErrTrackNotFound
|
resolver.hasTrack = false
|
||||||
resolver.lock.Unlock()
|
resolver.lock.Unlock()
|
||||||
|
|
||||||
// publisher triggers close
|
// publisher triggers close
|
||||||
@@ -187,7 +187,7 @@ func TestUnsubscribe(t *testing.T) {
|
|||||||
unsubCount.Add(1)
|
unsubCount.Add(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
resolver := newTestResolver(true, nil)
|
resolver := newTestResolver(true, true, "pub", "pubID")
|
||||||
|
|
||||||
s := &trackSubscription{
|
s := &trackSubscription{
|
||||||
trackID: "track",
|
trackID: "track",
|
||||||
@@ -200,10 +200,9 @@ func TestUnsubscribe(t *testing.T) {
|
|||||||
logger: logger.GetLogger(),
|
logger: logger.GetLogger(),
|
||||||
}
|
}
|
||||||
// a bunch of unfortunate manual wiring
|
// a bunch of unfortunate manual wiring
|
||||||
res, err := resolver.Resolve("sub", s.publisherID, s.trackID)
|
res := resolver.Resolve("sub", s.trackID)
|
||||||
require.NoError(t, err)
|
res.TrackChangedNotifier.AddObserver(string(sm.params.Participant.ID()), func() {})
|
||||||
res.TrackChangeNotifier.AddObserver(string(sm.params.Participant.ID()), func() {})
|
s.changedNotifier = res.TrackChangedNotifier
|
||||||
s.changeNotifier = res.TrackChangeNotifier
|
|
||||||
st, err := res.Track.AddSubscriber(sm.params.Participant)
|
st, err := res.Track.AddSubscriber(sm.params.Participant)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
s.subscribedTrack = st
|
s.subscribedTrack = st
|
||||||
@@ -227,14 +226,14 @@ func TestUnsubscribe(t *testing.T) {
|
|||||||
|
|
||||||
require.Eventually(t, func() bool {
|
require.Eventually(t, func() bool {
|
||||||
return !s.needsUnsubscribe()
|
return !s.needsUnsubscribe()
|
||||||
}, subSettleTimeout, subCheckInterval, "track was not unsubscribed")
|
}, subSettleTimeout, subCheckInterval, "Track was not unsubscribed")
|
||||||
|
|
||||||
// no traces should be left
|
// no traces should be left
|
||||||
require.Len(t, sm.GetSubscribedTracks(), 0)
|
require.Len(t, sm.GetSubscribedTracks(), 0)
|
||||||
sm.lock.RLock()
|
sm.lock.RLock()
|
||||||
require.Len(t, sm.subscriptions, 0)
|
require.Len(t, sm.subscriptions, 0)
|
||||||
sm.lock.RUnlock()
|
sm.lock.RUnlock()
|
||||||
require.False(t, res.TrackChangeNotifier.HasObservers())
|
require.False(t, res.TrackChangedNotifier.HasObservers())
|
||||||
|
|
||||||
tm := sm.params.Telemetry.(*telemetryfakes.FakeTelemetryService)
|
tm := sm.params.Telemetry.(*telemetryfakes.FakeTelemetryService)
|
||||||
require.Equal(t, 1, tm.TrackUnsubscribedCallCount())
|
require.Equal(t, 1, tm.TrackUnsubscribedCallCount())
|
||||||
@@ -243,7 +242,7 @@ func TestUnsubscribe(t *testing.T) {
|
|||||||
func TestSubscribeStatusChanged(t *testing.T) {
|
func TestSubscribeStatusChanged(t *testing.T) {
|
||||||
sm := newTestSubscriptionManager(t)
|
sm := newTestSubscriptionManager(t)
|
||||||
defer sm.Close(false)
|
defer sm.Close(false)
|
||||||
resolver := newTestResolver(true, nil)
|
resolver := newTestResolver(true, true, "pub", "pubID")
|
||||||
sm.params.TrackResolver = resolver.Resolve
|
sm.params.TrackResolver = resolver.Resolve
|
||||||
numParticipantSubscribed := atomic.Int32{}
|
numParticipantSubscribed := atomic.Int32{}
|
||||||
numParticipantUnsubscribed := atomic.Int32{}
|
numParticipantUnsubscribed := atomic.Int32{}
|
||||||
@@ -255,8 +254,8 @@ func TestSubscribeStatusChanged(t *testing.T) {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
sm.SubscribeToTrack("track1", "pub", "pubID")
|
sm.SubscribeToTrack("track1")
|
||||||
sm.SubscribeToTrack("track2", "pub", "pubID")
|
sm.SubscribeToTrack("track2")
|
||||||
s1 := sm.subscriptions["track1"]
|
s1 := sm.subscriptions["track1"]
|
||||||
s2 := sm.subscriptions["track2"]
|
s2 := sm.subscriptions["track2"]
|
||||||
require.Eventually(t, func() bool {
|
require.Eventually(t, func() bool {
|
||||||
@@ -300,7 +299,7 @@ func TestSubscribeStatusChanged(t *testing.T) {
|
|||||||
func TestUpdateSettingsBeforeSubscription(t *testing.T) {
|
func TestUpdateSettingsBeforeSubscription(t *testing.T) {
|
||||||
sm := newTestSubscriptionManager(t)
|
sm := newTestSubscriptionManager(t)
|
||||||
defer sm.Close(false)
|
defer sm.Close(false)
|
||||||
resolver := newTestResolver(true, nil)
|
resolver := newTestResolver(true, true, "pub", "pubID")
|
||||||
sm.params.TrackResolver = resolver.Resolve
|
sm.params.TrackResolver = resolver.Resolve
|
||||||
|
|
||||||
settings := &livekit.UpdateTrackSettings{
|
settings := &livekit.UpdateTrackSettings{
|
||||||
@@ -310,12 +309,12 @@ func TestUpdateSettingsBeforeSubscription(t *testing.T) {
|
|||||||
}
|
}
|
||||||
sm.UpdateSubscribedTrackSettings("track", settings)
|
sm.UpdateSubscribedTrackSettings("track", settings)
|
||||||
|
|
||||||
sm.SubscribeToTrack("track", "pub", "pubID")
|
sm.SubscribeToTrack("track")
|
||||||
|
|
||||||
s := sm.subscriptions["track"]
|
s := sm.subscriptions["track"]
|
||||||
require.Eventually(t, func() bool {
|
require.Eventually(t, func() bool {
|
||||||
return !s.needsSubscribe()
|
return !s.needsSubscribe()
|
||||||
}, subSettleTimeout, subCheckInterval, "track should be subscribed")
|
}, subSettleTimeout, subCheckInterval, "Track should be subscribed")
|
||||||
|
|
||||||
st := s.getSubscribedTrack().(*typesfakes.FakeSubscribedTrack)
|
st := s.getSubscribedTrack().(*typesfakes.FakeSubscribedTrack)
|
||||||
require.Equal(t, 1, st.UpdateSubscriberSettingsCallCount())
|
require.Equal(t, 1, st.UpdateSubscriberSettingsCallCount())
|
||||||
@@ -336,8 +335,8 @@ func newTestSubscriptionManager(t *testing.T) *SubscriptionManager {
|
|||||||
OnTrackSubscribed: func(subTrack types.SubscribedTrack) {},
|
OnTrackSubscribed: func(subTrack types.SubscribedTrack) {},
|
||||||
OnTrackUnsubscribed: func(subTrack types.SubscribedTrack) {},
|
OnTrackUnsubscribed: func(subTrack types.SubscribedTrack) {},
|
||||||
OnSubcriptionError: func(trackID livekit.TrackID) {},
|
OnSubcriptionError: func(trackID livekit.TrackID) {},
|
||||||
TrackResolver: func(identity livekit.ParticipantIdentity, pID livekit.ParticipantID, trackID livekit.TrackID) (types.MediaResolverResult, error) {
|
TrackResolver: func(identity livekit.ParticipantIdentity, trackID livekit.TrackID) types.MediaResolverResult {
|
||||||
return types.MediaResolverResult{}, ErrTrackNotFound
|
return types.MediaResolverResult{}
|
||||||
},
|
},
|
||||||
Telemetry: &telemetryfakes.FakeTelemetryService{},
|
Telemetry: &telemetryfakes.FakeTelemetryService{},
|
||||||
})
|
})
|
||||||
@@ -346,34 +345,41 @@ func newTestSubscriptionManager(t *testing.T) *SubscriptionManager {
|
|||||||
type testResolver struct {
|
type testResolver struct {
|
||||||
lock sync.Mutex
|
lock sync.Mutex
|
||||||
hasPermission bool
|
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{
|
return &testResolver{
|
||||||
hasPermission: hasPermission,
|
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()
|
t.lock.Lock()
|
||||||
defer t.lock.Unlock()
|
defer t.lock.Unlock()
|
||||||
if t.err != nil {
|
res := types.MediaResolverResult{
|
||||||
return types.MediaResolverResult{}, t.err
|
TrackChangedNotifier: utils.NewChangeNotifier(),
|
||||||
|
TrackRemovedNotifier: utils.NewChangeNotifier(),
|
||||||
|
HasPermission: t.hasPermission,
|
||||||
|
PublisherID: t.pubID,
|
||||||
|
PublisherIdentity: t.pubIdentity,
|
||||||
}
|
}
|
||||||
|
if t.hasTrack {
|
||||||
mt := &typesfakes.FakeMediaTrack{}
|
mt := &typesfakes.FakeMediaTrack{}
|
||||||
st := &typesfakes.FakeSubscribedTrack{}
|
st := &typesfakes.FakeSubscribedTrack{}
|
||||||
st.IDReturns(trackID)
|
st.IDReturns(trackID)
|
||||||
st.PublisherIDReturns(pID)
|
st.PublisherIDReturns(t.pubID)
|
||||||
st.PublisherIdentityReturns(identity)
|
st.PublisherIdentityReturns(t.pubIdentity)
|
||||||
mt.AddSubscriberReturns(st, nil)
|
mt.AddSubscriberReturns(st, nil)
|
||||||
st.MediaTrackReturns(mt)
|
st.MediaTrackReturns(mt)
|
||||||
return types.MediaResolverResult{
|
res.Track = mt
|
||||||
Track: mt,
|
}
|
||||||
TrackChangeNotifier: utils.NewChangeNotifier(),
|
return res
|
||||||
HasPermission: t.hasPermission,
|
|
||||||
}, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func setTestSubscribedTrackBound(t *testing.T, st types.SubscribedTrack) {
|
func setTestSubscribedTrackBound(t *testing.T, st types.SubscribedTrack) {
|
||||||
|
|||||||
@@ -268,7 +268,7 @@ type LocalParticipant interface {
|
|||||||
RemoveTrackFromSubscriber(sender *webrtc.RTPSender) error
|
RemoveTrackFromSubscriber(sender *webrtc.RTPSender) error
|
||||||
|
|
||||||
// subscriptions
|
// subscriptions
|
||||||
SubscribeToTrack(trackID livekit.TrackID, publisherIdentity livekit.ParticipantIdentity, publisherID livekit.ParticipantID)
|
SubscribeToTrack(trackID livekit.TrackID)
|
||||||
UnsubscribeFromTrack(trackID livekit.TrackID)
|
UnsubscribeFromTrack(trackID livekit.TrackID)
|
||||||
UpdateSubscribedTrackSettings(trackID livekit.TrackID, settings *livekit.UpdateTrackSettings)
|
UpdateSubscribedTrackSettings(trackID livekit.TrackID, settings *livekit.UpdateTrackSettings)
|
||||||
GetSubscribedTracks() []SubscribedTrack
|
GetSubscribedTracks() []SubscribedTrack
|
||||||
@@ -303,6 +303,8 @@ type LocalParticipant interface {
|
|||||||
OnTrackPublished(func(LocalParticipant, MediaTrack))
|
OnTrackPublished(func(LocalParticipant, MediaTrack))
|
||||||
// OnTrackUpdated - one of its publishedTracks changed in status
|
// OnTrackUpdated - one of its publishedTracks changed in status
|
||||||
OnTrackUpdated(callback func(LocalParticipant, MediaTrack))
|
OnTrackUpdated(callback func(LocalParticipant, MediaTrack))
|
||||||
|
// OnTrackUnpublished - a track was unpublished
|
||||||
|
OnTrackUnpublished(callback func(LocalParticipant, MediaTrack))
|
||||||
// OnParticipantUpdate - metadata or permission is updated
|
// OnParticipantUpdate - metadata or permission is updated
|
||||||
OnParticipantUpdate(callback func(LocalParticipant))
|
OnParticipantUpdate(callback func(LocalParticipant))
|
||||||
OnDataPacket(callback func(LocalParticipant, *livekit.DataPacket))
|
OnDataPacket(callback func(LocalParticipant, *livekit.DataPacket))
|
||||||
@@ -343,7 +345,7 @@ type Room interface {
|
|||||||
SyncState(participant LocalParticipant, state *livekit.SyncState) error
|
SyncState(participant LocalParticipant, state *livekit.SyncState) error
|
||||||
SimulateScenario(participant LocalParticipant, scenario *livekit.SimulateScenario) error
|
SimulateScenario(participant LocalParticipant, scenario *livekit.SimulateScenario) error
|
||||||
UpdateVideoLayers(participant Participant, updateVideoLayers *livekit.UpdateVideoLayers) 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
|
// MediaTrack represents a media track
|
||||||
@@ -440,14 +442,17 @@ type ChangeNotifier interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type MediaResolverResult struct {
|
type MediaResolverResult struct {
|
||||||
TrackChangeNotifier ChangeNotifier
|
TrackChangedNotifier ChangeNotifier
|
||||||
|
TrackRemovedNotifier ChangeNotifier
|
||||||
Track MediaTrack
|
Track MediaTrack
|
||||||
// is permission given to the requesting participant
|
// 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
|
// 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
|
// Supervisor/operation monitor related definitions
|
||||||
type OperationMonitorEvent int
|
type OperationMonitorEvent int
|
||||||
|
|||||||
@@ -476,6 +476,11 @@ type FakeLocalParticipant struct {
|
|||||||
onTrackPublishedArgsForCall []struct {
|
onTrackPublishedArgsForCall []struct {
|
||||||
arg1 func(types.LocalParticipant, types.MediaTrack)
|
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))
|
OnTrackUpdatedStub func(func(types.LocalParticipant, types.MediaTrack))
|
||||||
onTrackUpdatedMutex sync.RWMutex
|
onTrackUpdatedMutex sync.RWMutex
|
||||||
onTrackUpdatedArgsForCall []struct {
|
onTrackUpdatedArgsForCall []struct {
|
||||||
@@ -663,12 +668,10 @@ type FakeLocalParticipant struct {
|
|||||||
stateReturnsOnCall map[int]struct {
|
stateReturnsOnCall map[int]struct {
|
||||||
result1 livekit.ParticipantInfo_State
|
result1 livekit.ParticipantInfo_State
|
||||||
}
|
}
|
||||||
SubscribeToTrackStub func(livekit.TrackID, livekit.ParticipantIdentity, livekit.ParticipantID)
|
SubscribeToTrackStub func(livekit.TrackID)
|
||||||
subscribeToTrackMutex sync.RWMutex
|
subscribeToTrackMutex sync.RWMutex
|
||||||
subscribeToTrackArgsForCall []struct {
|
subscribeToTrackArgsForCall []struct {
|
||||||
arg1 livekit.TrackID
|
arg1 livekit.TrackID
|
||||||
arg2 livekit.ParticipantIdentity
|
|
||||||
arg3 livekit.ParticipantID
|
|
||||||
}
|
}
|
||||||
SubscriberAsPrimaryStub func() bool
|
SubscriberAsPrimaryStub func() bool
|
||||||
subscriberAsPrimaryMutex sync.RWMutex
|
subscriberAsPrimaryMutex sync.RWMutex
|
||||||
@@ -3273,6 +3276,38 @@ func (fake *FakeLocalParticipant) OnTrackPublishedArgsForCall(i int) func(types.
|
|||||||
return argsForCall.arg1
|
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)) {
|
func (fake *FakeLocalParticipant) OnTrackUpdated(arg1 func(types.LocalParticipant, types.MediaTrack)) {
|
||||||
fake.onTrackUpdatedMutex.Lock()
|
fake.onTrackUpdatedMutex.Lock()
|
||||||
fake.onTrackUpdatedArgsForCall = append(fake.onTrackUpdatedArgsForCall, struct {
|
fake.onTrackUpdatedArgsForCall = append(fake.onTrackUpdatedArgsForCall, struct {
|
||||||
@@ -4334,18 +4369,16 @@ func (fake *FakeLocalParticipant) StateReturnsOnCall(i int, result1 livekit.Part
|
|||||||
}{result1}
|
}{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.subscribeToTrackMutex.Lock()
|
||||||
fake.subscribeToTrackArgsForCall = append(fake.subscribeToTrackArgsForCall, struct {
|
fake.subscribeToTrackArgsForCall = append(fake.subscribeToTrackArgsForCall, struct {
|
||||||
arg1 livekit.TrackID
|
arg1 livekit.TrackID
|
||||||
arg2 livekit.ParticipantIdentity
|
}{arg1})
|
||||||
arg3 livekit.ParticipantID
|
|
||||||
}{arg1, arg2, arg3})
|
|
||||||
stub := fake.SubscribeToTrackStub
|
stub := fake.SubscribeToTrackStub
|
||||||
fake.recordInvocation("SubscribeToTrack", []interface{}{arg1, arg2, arg3})
|
fake.recordInvocation("SubscribeToTrack", []interface{}{arg1})
|
||||||
fake.subscribeToTrackMutex.Unlock()
|
fake.subscribeToTrackMutex.Unlock()
|
||||||
if stub != nil {
|
if stub != nil {
|
||||||
fake.SubscribeToTrackStub(arg1, arg2, arg3)
|
fake.SubscribeToTrackStub(arg1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -4355,17 +4388,17 @@ func (fake *FakeLocalParticipant) SubscribeToTrackCallCount() int {
|
|||||||
return len(fake.subscribeToTrackArgsForCall)
|
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()
|
fake.subscribeToTrackMutex.Lock()
|
||||||
defer fake.subscribeToTrackMutex.Unlock()
|
defer fake.subscribeToTrackMutex.Unlock()
|
||||||
fake.SubscribeToTrackStub = stub
|
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()
|
fake.subscribeToTrackMutex.RLock()
|
||||||
defer fake.subscribeToTrackMutex.RUnlock()
|
defer fake.subscribeToTrackMutex.RUnlock()
|
||||||
argsForCall := fake.subscribeToTrackArgsForCall[i]
|
argsForCall := fake.subscribeToTrackArgsForCall[i]
|
||||||
return argsForCall.arg1, argsForCall.arg2, argsForCall.arg3
|
return argsForCall.arg1
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fake *FakeLocalParticipant) SubscriberAsPrimary() bool {
|
func (fake *FakeLocalParticipant) SubscriberAsPrimary() bool {
|
||||||
@@ -5206,6 +5239,8 @@ func (fake *FakeLocalParticipant) Invocations() map[string][][]interface{} {
|
|||||||
defer fake.onSubscribeStatusChangedMutex.RUnlock()
|
defer fake.onSubscribeStatusChangedMutex.RUnlock()
|
||||||
fake.onTrackPublishedMutex.RLock()
|
fake.onTrackPublishedMutex.RLock()
|
||||||
defer fake.onTrackPublishedMutex.RUnlock()
|
defer fake.onTrackPublishedMutex.RUnlock()
|
||||||
|
fake.onTrackUnpublishedMutex.RLock()
|
||||||
|
defer fake.onTrackUnpublishedMutex.RUnlock()
|
||||||
fake.onTrackUpdatedMutex.RLock()
|
fake.onTrackUpdatedMutex.RLock()
|
||||||
defer fake.onTrackUpdatedMutex.RUnlock()
|
defer fake.onTrackUpdatedMutex.RUnlock()
|
||||||
fake.protocolVersionMutex.RLock()
|
fake.protocolVersionMutex.RLock()
|
||||||
|
|||||||
@@ -36,20 +36,17 @@ type FakeRoom struct {
|
|||||||
arg2 livekit.ParticipantID
|
arg2 livekit.ParticipantID
|
||||||
arg3 types.ParticipantCloseReason
|
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
|
resolveMediaTrackForSubscriberMutex sync.RWMutex
|
||||||
resolveMediaTrackForSubscriberArgsForCall []struct {
|
resolveMediaTrackForSubscriberArgsForCall []struct {
|
||||||
arg1 livekit.ParticipantIdentity
|
arg1 livekit.ParticipantIdentity
|
||||||
arg2 livekit.ParticipantID
|
arg2 livekit.TrackID
|
||||||
arg3 livekit.TrackID
|
|
||||||
}
|
}
|
||||||
resolveMediaTrackForSubscriberReturns struct {
|
resolveMediaTrackForSubscriberReturns struct {
|
||||||
result1 types.MediaResolverResult
|
result1 types.MediaResolverResult
|
||||||
result2 error
|
|
||||||
}
|
}
|
||||||
resolveMediaTrackForSubscriberReturnsOnCall map[int]struct {
|
resolveMediaTrackForSubscriberReturnsOnCall map[int]struct {
|
||||||
result1 types.MediaResolverResult
|
result1 types.MediaResolverResult
|
||||||
result2 error
|
|
||||||
}
|
}
|
||||||
SimulateScenarioStub func(types.LocalParticipant, *livekit.SimulateScenario) error
|
SimulateScenarioStub func(types.LocalParticipant, *livekit.SimulateScenario) error
|
||||||
simulateScenarioMutex sync.RWMutex
|
simulateScenarioMutex sync.RWMutex
|
||||||
@@ -251,25 +248,24 @@ func (fake *FakeRoom) RemoveParticipantArgsForCall(i int) (livekit.ParticipantId
|
|||||||
return argsForCall.arg1, argsForCall.arg2, argsForCall.arg3
|
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()
|
fake.resolveMediaTrackForSubscriberMutex.Lock()
|
||||||
ret, specificReturn := fake.resolveMediaTrackForSubscriberReturnsOnCall[len(fake.resolveMediaTrackForSubscriberArgsForCall)]
|
ret, specificReturn := fake.resolveMediaTrackForSubscriberReturnsOnCall[len(fake.resolveMediaTrackForSubscriberArgsForCall)]
|
||||||
fake.resolveMediaTrackForSubscriberArgsForCall = append(fake.resolveMediaTrackForSubscriberArgsForCall, struct {
|
fake.resolveMediaTrackForSubscriberArgsForCall = append(fake.resolveMediaTrackForSubscriberArgsForCall, struct {
|
||||||
arg1 livekit.ParticipantIdentity
|
arg1 livekit.ParticipantIdentity
|
||||||
arg2 livekit.ParticipantID
|
arg2 livekit.TrackID
|
||||||
arg3 livekit.TrackID
|
}{arg1, arg2})
|
||||||
}{arg1, arg2, arg3})
|
|
||||||
stub := fake.ResolveMediaTrackForSubscriberStub
|
stub := fake.ResolveMediaTrackForSubscriberStub
|
||||||
fakeReturns := fake.resolveMediaTrackForSubscriberReturns
|
fakeReturns := fake.resolveMediaTrackForSubscriberReturns
|
||||||
fake.recordInvocation("ResolveMediaTrackForSubscriber", []interface{}{arg1, arg2, arg3})
|
fake.recordInvocation("ResolveMediaTrackForSubscriber", []interface{}{arg1, arg2})
|
||||||
fake.resolveMediaTrackForSubscriberMutex.Unlock()
|
fake.resolveMediaTrackForSubscriberMutex.Unlock()
|
||||||
if stub != nil {
|
if stub != nil {
|
||||||
return stub(arg1, arg2, arg3)
|
return stub(arg1, arg2)
|
||||||
}
|
}
|
||||||
if specificReturn {
|
if specificReturn {
|
||||||
return ret.result1, ret.result2
|
return ret.result1
|
||||||
}
|
}
|
||||||
return fakeReturns.result1, fakeReturns.result2
|
return fakeReturns.result1
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fake *FakeRoom) ResolveMediaTrackForSubscriberCallCount() int {
|
func (fake *FakeRoom) ResolveMediaTrackForSubscriberCallCount() int {
|
||||||
@@ -278,43 +274,40 @@ func (fake *FakeRoom) ResolveMediaTrackForSubscriberCallCount() int {
|
|||||||
return len(fake.resolveMediaTrackForSubscriberArgsForCall)
|
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()
|
fake.resolveMediaTrackForSubscriberMutex.Lock()
|
||||||
defer fake.resolveMediaTrackForSubscriberMutex.Unlock()
|
defer fake.resolveMediaTrackForSubscriberMutex.Unlock()
|
||||||
fake.ResolveMediaTrackForSubscriberStub = stub
|
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()
|
fake.resolveMediaTrackForSubscriberMutex.RLock()
|
||||||
defer fake.resolveMediaTrackForSubscriberMutex.RUnlock()
|
defer fake.resolveMediaTrackForSubscriberMutex.RUnlock()
|
||||||
argsForCall := fake.resolveMediaTrackForSubscriberArgsForCall[i]
|
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()
|
fake.resolveMediaTrackForSubscriberMutex.Lock()
|
||||||
defer fake.resolveMediaTrackForSubscriberMutex.Unlock()
|
defer fake.resolveMediaTrackForSubscriberMutex.Unlock()
|
||||||
fake.ResolveMediaTrackForSubscriberStub = nil
|
fake.ResolveMediaTrackForSubscriberStub = nil
|
||||||
fake.resolveMediaTrackForSubscriberReturns = struct {
|
fake.resolveMediaTrackForSubscriberReturns = struct {
|
||||||
result1 types.MediaResolverResult
|
result1 types.MediaResolverResult
|
||||||
result2 error
|
}{result1}
|
||||||
}{result1, result2}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fake *FakeRoom) ResolveMediaTrackForSubscriberReturnsOnCall(i int, result1 types.MediaResolverResult, result2 error) {
|
func (fake *FakeRoom) ResolveMediaTrackForSubscriberReturnsOnCall(i int, result1 types.MediaResolverResult) {
|
||||||
fake.resolveMediaTrackForSubscriberMutex.Lock()
|
fake.resolveMediaTrackForSubscriberMutex.Lock()
|
||||||
defer fake.resolveMediaTrackForSubscriberMutex.Unlock()
|
defer fake.resolveMediaTrackForSubscriberMutex.Unlock()
|
||||||
fake.ResolveMediaTrackForSubscriberStub = nil
|
fake.ResolveMediaTrackForSubscriberStub = nil
|
||||||
if fake.resolveMediaTrackForSubscriberReturnsOnCall == nil {
|
if fake.resolveMediaTrackForSubscriberReturnsOnCall == nil {
|
||||||
fake.resolveMediaTrackForSubscriberReturnsOnCall = make(map[int]struct {
|
fake.resolveMediaTrackForSubscriberReturnsOnCall = make(map[int]struct {
|
||||||
result1 types.MediaResolverResult
|
result1 types.MediaResolverResult
|
||||||
result2 error
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
fake.resolveMediaTrackForSubscriberReturnsOnCall[i] = struct {
|
fake.resolveMediaTrackForSubscriberReturnsOnCall[i] = struct {
|
||||||
result1 types.MediaResolverResult
|
result1 types.MediaResolverResult
|
||||||
result2 error
|
}{result1}
|
||||||
}{result1, result2}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fake *FakeRoom) SimulateScenario(arg1 types.LocalParticipant, arg2 *livekit.SimulateScenario) error {
|
func (fake *FakeRoom) SimulateScenario(arg1 types.LocalParticipant, arg2 *livekit.SimulateScenario) error {
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ type UpTrackManager struct {
|
|||||||
|
|
||||||
// callbacks & handlers
|
// callbacks & handlers
|
||||||
onClose func()
|
onClose func()
|
||||||
onTrackUpdated func(track types.MediaTrack, onlyIfReady bool)
|
onTrackUpdated func(track types.MediaTrack)
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewUpTrackManager(params UpTrackManagerParams) *UpTrackManager {
|
func NewUpTrackManager(params UpTrackManagerParams) *UpTrackManager {
|
||||||
@@ -83,7 +83,7 @@ func (u *UpTrackManager) ToProto() []*livekit.TrackInfo {
|
|||||||
return trackInfos
|
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
|
u.onTrackUpdated = f
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -99,7 +99,7 @@ func (u *UpTrackManager) SetPublishedTrackMuted(trackID livekit.TrackID, muted b
|
|||||||
if currentMuted != track.IsMuted() {
|
if currentMuted != track.IsMuted() {
|
||||||
u.params.Logger.Infow("publisher mute status changed", "trackID", trackID, "muted", track.IsMuted())
|
u.params.Logger.Infow("publisher mute status changed", "trackID", trackID, "muted", track.IsMuted())
|
||||||
if u.onTrackUpdated != nil {
|
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)
|
track.UpdateVideoLayers(updateVideoLayers.Layers)
|
||||||
if u.onTrackUpdated != nil {
|
if u.onTrackUpdated != nil {
|
||||||
u.onTrackUpdated(track, false)
|
u.onTrackUpdated(track)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
@@ -260,11 +260,6 @@ func (u *UpTrackManager) AddPublishedTrack(track types.MediaTrack) {
|
|||||||
}
|
}
|
||||||
u.lock.Unlock()
|
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 {
|
if notifyClose && u.onClose != nil {
|
||||||
u.onClose()
|
u.onClose()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -245,14 +245,12 @@ func (t *telemetryService) TrackSubscribeRequested(
|
|||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
participantID livekit.ParticipantID,
|
participantID livekit.ParticipantID,
|
||||||
track *livekit.TrackInfo,
|
track *livekit.TrackInfo,
|
||||||
publisher *livekit.ParticipantInfo,
|
|
||||||
) {
|
) {
|
||||||
t.enqueue(func() {
|
t.enqueue(func() {
|
||||||
prometheus.RecordTrackSubscribeAttempt()
|
prometheus.RecordTrackSubscribeAttempt()
|
||||||
|
|
||||||
room := t.getRoomDetails(participantID)
|
room := t.getRoomDetails(participantID)
|
||||||
ev := newTrackEvent(livekit.AnalyticsEventType_TRACK_SUBSCRIBE_REQUESTED, room, participantID, track)
|
ev := newTrackEvent(livekit.AnalyticsEventType_TRACK_SUBSCRIBE_REQUESTED, room, participantID, track)
|
||||||
ev.Publisher = publisher
|
|
||||||
t.SendEvent(ctx, ev)
|
t.SendEvent(ctx, ev)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -145,13 +145,12 @@ type FakeTelemetryService struct {
|
|||||||
arg4 error
|
arg4 error
|
||||||
arg5 bool
|
arg5 bool
|
||||||
}
|
}
|
||||||
TrackSubscribeRequestedStub func(context.Context, livekit.ParticipantID, *livekit.TrackInfo, *livekit.ParticipantInfo)
|
TrackSubscribeRequestedStub func(context.Context, livekit.ParticipantID, *livekit.TrackInfo)
|
||||||
trackSubscribeRequestedMutex sync.RWMutex
|
trackSubscribeRequestedMutex sync.RWMutex
|
||||||
trackSubscribeRequestedArgsForCall []struct {
|
trackSubscribeRequestedArgsForCall []struct {
|
||||||
arg1 context.Context
|
arg1 context.Context
|
||||||
arg2 livekit.ParticipantID
|
arg2 livekit.ParticipantID
|
||||||
arg3 *livekit.TrackInfo
|
arg3 *livekit.TrackInfo
|
||||||
arg4 *livekit.ParticipantInfo
|
|
||||||
}
|
}
|
||||||
TrackSubscribedStub func(context.Context, livekit.ParticipantID, *livekit.TrackInfo, *livekit.ParticipantInfo, bool)
|
TrackSubscribedStub func(context.Context, livekit.ParticipantID, *livekit.TrackInfo, *livekit.ParticipantInfo, bool)
|
||||||
trackSubscribedMutex sync.RWMutex
|
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
|
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.trackSubscribeRequestedMutex.Lock()
|
||||||
fake.trackSubscribeRequestedArgsForCall = append(fake.trackSubscribeRequestedArgsForCall, struct {
|
fake.trackSubscribeRequestedArgsForCall = append(fake.trackSubscribeRequestedArgsForCall, struct {
|
||||||
arg1 context.Context
|
arg1 context.Context
|
||||||
arg2 livekit.ParticipantID
|
arg2 livekit.ParticipantID
|
||||||
arg3 *livekit.TrackInfo
|
arg3 *livekit.TrackInfo
|
||||||
arg4 *livekit.ParticipantInfo
|
}{arg1, arg2, arg3})
|
||||||
}{arg1, arg2, arg3, arg4})
|
|
||||||
stub := fake.TrackSubscribeRequestedStub
|
stub := fake.TrackSubscribeRequestedStub
|
||||||
fake.recordInvocation("TrackSubscribeRequested", []interface{}{arg1, arg2, arg3, arg4})
|
fake.recordInvocation("TrackSubscribeRequested", []interface{}{arg1, arg2, arg3})
|
||||||
fake.trackSubscribeRequestedMutex.Unlock()
|
fake.trackSubscribeRequestedMutex.Unlock()
|
||||||
if stub != nil {
|
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)
|
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()
|
fake.trackSubscribeRequestedMutex.Lock()
|
||||||
defer fake.trackSubscribeRequestedMutex.Unlock()
|
defer fake.trackSubscribeRequestedMutex.Unlock()
|
||||||
fake.TrackSubscribeRequestedStub = stub
|
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()
|
fake.trackSubscribeRequestedMutex.RLock()
|
||||||
defer fake.trackSubscribeRequestedMutex.RUnlock()
|
defer fake.trackSubscribeRequestedMutex.RUnlock()
|
||||||
argsForCall := fake.trackSubscribeRequestedArgsForCall[i]
|
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) {
|
func (fake *FakeTelemetryService) TrackSubscribed(arg1 context.Context, arg2 livekit.ParticipantID, arg3 *livekit.TrackInfo, arg4 *livekit.ParticipantInfo, arg5 bool) {
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ type TelemetryService interface {
|
|||||||
// TrackUnpublished - a participant unpublished a track
|
// TrackUnpublished - a participant unpublished a track
|
||||||
TrackUnpublished(ctx context.Context, participantID livekit.ParticipantID, identity livekit.ParticipantIdentity, track *livekit.TrackInfo, shouldSendEvent bool)
|
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 - 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 - a participant subscribed to a track successfully
|
||||||
TrackSubscribed(ctx context.Context, participantID livekit.ParticipantID, track *livekit.TrackInfo, publisher *livekit.ParticipantInfo, shouldSendEvent bool)
|
TrackSubscribed(ctx context.Context, participantID livekit.ParticipantID, track *livekit.TrackInfo, publisher *livekit.ParticipantInfo, shouldSendEvent bool)
|
||||||
// TrackUnsubscribed - a participant unsubscribed from a track successfully
|
// TrackUnsubscribed - a participant unsubscribed from a track successfully
|
||||||
|
|||||||
Reference in New Issue
Block a user