mirror of
https://github.com/livekit/livekit.git
synced 2026-05-14 22:45:20 +00:00
Make sure client get participant info before track fired (#1147)
This commit is contained in:
@@ -212,6 +212,7 @@ func (t *MediaTrackSubscriptions) AddSubscriber(sub types.LocalParticipant, wr *
|
||||
addTrackParams := types.AddTrackParams{
|
||||
Stereo: info.Stereo,
|
||||
}
|
||||
sub.VerifySubscribeParticipantInfo(subTrack.PublisherID(), subTrack.PublisherVersion())
|
||||
if sub.ProtocolVersion().SupportsTransceiverReuse() {
|
||||
//
|
||||
// AddTrack will create a new transceiver or re-use an unused one
|
||||
|
||||
+14
-1
@@ -86,6 +86,7 @@ type ParticipantParams struct {
|
||||
AdaptiveStream bool
|
||||
AllowTCPFallback bool
|
||||
TURNSEnabled bool
|
||||
GetParticipantInfo func(pID livekit.ParticipantID) *livekit.ParticipantInfo
|
||||
}
|
||||
|
||||
type ParticipantImpl struct {
|
||||
@@ -192,7 +193,7 @@ func NewParticipant(params ParticipantParams) (*ParticipantImpl, error) {
|
||||
|
||||
var err error
|
||||
// keep last participants and when updates were sent
|
||||
if p.updateCache, err = lru.New(32); err != nil {
|
||||
if p.updateCache, err = lru.New(128); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -858,6 +859,18 @@ func (p *ParticipantImpl) UpdateSubscribedTrackSettings(trackID livekit.TrackID,
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *ParticipantImpl) VerifySubscribeParticipantInfo(pID livekit.ParticipantID, version uint32) {
|
||||
if v, ok := p.updateCache.Get(pID); ok && v.(uint32) >= version {
|
||||
return
|
||||
}
|
||||
|
||||
if f := p.params.GetParticipantInfo; f != nil {
|
||||
if info := f(pID); info != nil {
|
||||
p.SendParticipantUpdate([]*livekit.ParticipantInfo{info})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// AddSubscribedTrack adds a track to the participant's subscribed list
|
||||
func (p *ParticipantImpl) AddSubscribedTrack(subTrack types.SubscribedTrack) {
|
||||
p.lock.Lock()
|
||||
|
||||
@@ -273,6 +273,7 @@ type LocalParticipant interface {
|
||||
RemoveSubscribedTrack(st SubscribedTrack)
|
||||
UpdateSubscribedTrackSettings(trackID livekit.TrackID, settings *livekit.UpdateTrackSettings) error
|
||||
GetSubscribedTracks() []SubscribedTrack
|
||||
VerifySubscribeParticipantInfo(pID livekit.ParticipantID, version uint32)
|
||||
|
||||
// returns list of participant identities that the current participant is subscribed to
|
||||
GetSubscribedParticipants() []livekit.ParticipantID
|
||||
|
||||
@@ -755,6 +755,12 @@ type FakeLocalParticipant struct {
|
||||
updateVideoLayersReturnsOnCall map[int]struct {
|
||||
result1 error
|
||||
}
|
||||
VerifySubscribeParticipantInfoStub func(livekit.ParticipantID, uint32)
|
||||
verifySubscribeParticipantInfoMutex sync.RWMutex
|
||||
verifySubscribeParticipantInfoArgsForCall []struct {
|
||||
arg1 livekit.ParticipantID
|
||||
arg2 uint32
|
||||
}
|
||||
invocations map[string][][]interface{}
|
||||
invocationsMutex sync.RWMutex
|
||||
}
|
||||
@@ -4750,6 +4756,39 @@ func (fake *FakeLocalParticipant) UpdateVideoLayersReturnsOnCall(i int, result1
|
||||
}{result1}
|
||||
}
|
||||
|
||||
func (fake *FakeLocalParticipant) VerifySubscribeParticipantInfo(arg1 livekit.ParticipantID, arg2 uint32) {
|
||||
fake.verifySubscribeParticipantInfoMutex.Lock()
|
||||
fake.verifySubscribeParticipantInfoArgsForCall = append(fake.verifySubscribeParticipantInfoArgsForCall, struct {
|
||||
arg1 livekit.ParticipantID
|
||||
arg2 uint32
|
||||
}{arg1, arg2})
|
||||
stub := fake.VerifySubscribeParticipantInfoStub
|
||||
fake.recordInvocation("VerifySubscribeParticipantInfo", []interface{}{arg1, arg2})
|
||||
fake.verifySubscribeParticipantInfoMutex.Unlock()
|
||||
if stub != nil {
|
||||
fake.VerifySubscribeParticipantInfoStub(arg1, arg2)
|
||||
}
|
||||
}
|
||||
|
||||
func (fake *FakeLocalParticipant) VerifySubscribeParticipantInfoCallCount() int {
|
||||
fake.verifySubscribeParticipantInfoMutex.RLock()
|
||||
defer fake.verifySubscribeParticipantInfoMutex.RUnlock()
|
||||
return len(fake.verifySubscribeParticipantInfoArgsForCall)
|
||||
}
|
||||
|
||||
func (fake *FakeLocalParticipant) VerifySubscribeParticipantInfoCalls(stub func(livekit.ParticipantID, uint32)) {
|
||||
fake.verifySubscribeParticipantInfoMutex.Lock()
|
||||
defer fake.verifySubscribeParticipantInfoMutex.Unlock()
|
||||
fake.VerifySubscribeParticipantInfoStub = stub
|
||||
}
|
||||
|
||||
func (fake *FakeLocalParticipant) VerifySubscribeParticipantInfoArgsForCall(i int) (livekit.ParticipantID, uint32) {
|
||||
fake.verifySubscribeParticipantInfoMutex.RLock()
|
||||
defer fake.verifySubscribeParticipantInfoMutex.RUnlock()
|
||||
argsForCall := fake.verifySubscribeParticipantInfoArgsForCall[i]
|
||||
return argsForCall.arg1, argsForCall.arg2
|
||||
}
|
||||
|
||||
func (fake *FakeLocalParticipant) Invocations() map[string][][]interface{} {
|
||||
fake.invocationsMutex.RLock()
|
||||
defer fake.invocationsMutex.RUnlock()
|
||||
@@ -4923,6 +4962,8 @@ func (fake *FakeLocalParticipant) Invocations() map[string][][]interface{} {
|
||||
defer fake.updateSubscriptionPermissionMutex.RUnlock()
|
||||
fake.updateVideoLayersMutex.RLock()
|
||||
defer fake.updateVideoLayersMutex.RUnlock()
|
||||
fake.verifySubscribeParticipantInfoMutex.RLock()
|
||||
defer fake.verifySubscribeParticipantInfoMutex.RUnlock()
|
||||
copiedInvocations := map[string][][]interface{}{}
|
||||
for key, value := range fake.invocations {
|
||||
copiedInvocations[key] = value
|
||||
|
||||
@@ -297,6 +297,12 @@ func (r *RoomManager) StartSession(
|
||||
AdaptiveStream: pi.AdaptiveStream,
|
||||
AllowTCPFallback: allowFallback,
|
||||
TURNSEnabled: r.config.IsTURNSEnabled(),
|
||||
GetParticipantInfo: func(pID livekit.ParticipantID) *livekit.ParticipantInfo {
|
||||
if p := room.GetParticipantBySid(pID); p != nil {
|
||||
return p.ToProto()
|
||||
}
|
||||
return nil
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
Reference in New Issue
Block a user