fix deadlocks in track subscription
This commit is contained in:
+5
-4
@@ -318,14 +318,12 @@ func (r *Room) OnParticipantChanged(f func(participant types.Participant)) {
|
||||
r.onParticipantChanged = f
|
||||
}
|
||||
|
||||
// checks if participant should be autosubscribed to new tracks, assumes lock is already acquired
|
||||
func (r *Room) autoSubscribe(participant types.Participant) bool {
|
||||
if !participant.CanSubscribe() {
|
||||
return false
|
||||
}
|
||||
|
||||
r.lock.RLock()
|
||||
defer r.lock.RUnlock()
|
||||
|
||||
opts := r.participantOpts[participant.Identity()]
|
||||
// default to true if no options are set
|
||||
if opts != nil && !opts.AutoSubscribe {
|
||||
@@ -402,7 +400,10 @@ func (r *Room) onDataPacket(source types.Participant, dp *livekit.DataPacket) {
|
||||
}
|
||||
|
||||
func (r *Room) subscribeToExistingTracks(p types.Participant) {
|
||||
if !r.autoSubscribe(p) {
|
||||
r.lock.RLock()
|
||||
shouldSubscribe := r.autoSubscribe(p)
|
||||
r.lock.RUnlock()
|
||||
if !shouldSubscribe {
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user