allow user to mute before track is fully published (#82)

fixes https://github.com/livekit/client-sdk-js/issues/28
This commit is contained in:
David Zhao
2021-08-10 21:09:23 -07:00
committed by GitHub
parent 896b28d45d
commit 5713731363
5 changed files with 44 additions and 6 deletions
+15
View File
@@ -303,6 +303,7 @@ func (p *ParticipantImpl) AddTrack(req *livekit.AddTrackRequest) {
Sid: utils.NewGuid(utils.TrackPrefix),
Width: req.Width,
Height: req.Height,
Muted: req.Muted,
}
p.pendingTracks[req.Cid] = ti
@@ -536,9 +537,21 @@ func (p *ParticipantImpl) SendDataPacket(dp *livekit.DataPacket) error {
}
func (p *ParticipantImpl) SetTrackMuted(trackId string, muted bool) {
isPending := false
p.lock.RLock()
for _, ti := range p.pendingTracks {
if ti.Sid == trackId {
ti.Muted = muted
isPending = true
}
}
track := p.publishedTracks[trackId]
p.lock.RUnlock()
// already handled
if isPending {
return
}
if track == nil {
logger.Warnw("could not locate track", nil, "track", trackId)
return
@@ -719,6 +732,7 @@ func (p *ParticipantImpl) onMediaTrack(track *webrtc.TrackRemote, rtpReceiver *w
}
// delete pending track if it's not simulcasting
// TODO: we should delete it after adding three tracks
ti := p.getPendingTrack(track.ID(), ToProtoTrackKind(track.Kind()), track.RID() == "")
if ti == nil {
return
@@ -745,6 +759,7 @@ func (p *ParticipantImpl) onMediaTrack(track *webrtc.TrackRemote, rtpReceiver *w
Height: ti.Height,
})
mt.name = ti.Name
mt.SetMuted(ti.Muted)
newTrack = true
}