-
Notifications
You must be signed in to change notification settings - Fork 99
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reconcile track mute state by client to avoid mute message loop #352
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,6 +58,7 @@ func (p *LocalParticipant) PublishTrack(track webrtc.TrackLocal, opts *TrackPubl | |
pub.OnRttUpdate(func(rtt uint32) { | ||
p.engine.setRTT(rtt) | ||
}) | ||
pub.onMuteChanged = p.onTrackMuted | ||
|
||
req := &livekit.AddTrackRequest{ | ||
Cid: track.ID(), | ||
|
@@ -149,6 +150,7 @@ func (p *LocalParticipant) PublishSimulcastTrack(tracks []*LocalSampleTrack, opt | |
mainTrack := tracks[len(tracks)-1] | ||
|
||
pub := NewLocalTrackPublication(KindFromRTPType(mainTrack.Kind()), nil, *opts, p.engine.client) | ||
pub.onMuteChanged = p.onTrackMuted | ||
|
||
var layers []*livekit.VideoLayer | ||
for _, st := range tracks { | ||
|
@@ -359,16 +361,7 @@ func (p *LocalParticipant) updateInfo(info *livekit.ParticipantInfo) { | |
continue | ||
} | ||
if pub.IsMuted() != ti.Muted { | ||
pub.SetMuted(ti.Muted) | ||
|
||
// trigger callback | ||
if ti.Muted { | ||
p.Callback.OnTrackMuted(pub, p) | ||
p.roomCallback.OnTrackMuted(pub, p) | ||
} else if !ti.Muted { | ||
p.Callback.OnTrackUnmuted(pub, p) | ||
p.roomCallback.OnTrackUnmuted(pub, p) | ||
} | ||
_ = p.engine.client.SendMuteTrack(pub.SID(), pub.IsMuted()) | ||
} | ||
} | ||
} | ||
|
@@ -379,3 +372,13 @@ func (p *LocalParticipant) getLocalPublication(sid string) *LocalTrackPublicatio | |
} | ||
return nil | ||
} | ||
|
||
func (p *LocalParticipant) onTrackMuted(pub *LocalTrackPublication, muted bool) { | ||
if muted { | ||
p.Callback.OnTrackMuted(pub, p) | ||
p.roomCallback.OnTrackMuted(pub, p) | ||
} else { | ||
p.Callback.OnTrackUnmuted(pub, p) | ||
p.roomCallback.OnTrackUnmuted(pub, p) | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a chance of this racing and setting wrong callbacks? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, the callback is set in the |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -242,6 +242,7 @@ type LocalTrackPublication struct { | |
simulcastTracks map[livekit.VideoQuality]*LocalSampleTrack | ||
onRttUpdate func(uint32) | ||
opts TrackPublicationOptions | ||
onMuteChanged func(*LocalTrackPublication, bool) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we make this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will cause the callback can be accessed by the user, so keep it lowercase to be access only by internal code |
||
} | ||
|
||
func NewLocalTrackPublication(kind TrackKind, track Track, opts TrackPublicationOptions, client *SignalClient) *LocalTrackPublication { | ||
|
@@ -280,17 +281,27 @@ func (p *LocalTrackPublication) GetSimulcastTrack(quality livekit.VideoQuality) | |
} | ||
|
||
func (p *LocalTrackPublication) SetMuted(muted bool) { | ||
p.setMuted(muted, false) | ||
} | ||
|
||
func (p *LocalTrackPublication) setMuted(muted bool, byRemote bool) { | ||
if p.isMuted.Swap(muted) == muted { | ||
return | ||
} | ||
|
||
_ = p.client.SendMuteTrack(p.sid.Load(), muted) | ||
if !byRemote { | ||
_ = p.client.SendMuteTrack(p.sid.Load(), muted) | ||
} | ||
if track := p.track; track != nil { | ||
switch t := track.(type) { | ||
case *LocalSampleTrack: | ||
t.setMuted(muted) | ||
} | ||
} | ||
|
||
if p.onMuteChanged != nil { | ||
p.onMuteChanged(p, muted) | ||
} | ||
} | ||
|
||
func (p *LocalTrackPublication) addSimulcastTrack(st *LocalSampleTrack) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be called directly? Feels like
pub.SetMuted
would be the right thing as it will do the right thing of sending message and issuing callback? Did you want to remove the callback when mute is managed through this path? Even then, callingSetMuted
and doing callback or not there might be better?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The pub.SetMuted will find the new state is the same as the current publication state and return directly, this pr keeps same behavior like js-client to send a mute message only when server-side info is inconsistent