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
+1 -1
View File
@@ -12,7 +12,7 @@ require (
github.com/google/wire v0.5.0
github.com/gorilla/websocket v1.4.2
github.com/jxskiss/base62 v0.0.0-20191017122030-4f11678b909b
github.com/livekit/protocol v0.7.1
github.com/livekit/protocol v0.7.2
github.com/magefile/mage v1.11.0
github.com/maxbrunsfeld/counterfeiter/v6 v6.3.0
github.com/mitchellh/go-homedir v1.1.0
+2 -4
View File
@@ -237,10 +237,8 @@ github.com/lithammer/shortuuid/v3 v3.0.6 h1:pr15YQyvhiSX/qPxncFtqk+v4xLEpOZObbsY
github.com/lithammer/shortuuid/v3 v3.0.6/go.mod h1:vMk8ke37EmiewwolSO1NLW8vP4ZaKlRuDIi8tWWmAts=
github.com/livekit/ion-sfu v1.20.6 h1:vA98RfuW3sSidV1rfK+/szGWgHFgki4Q4pomxsJS0i0=
github.com/livekit/ion-sfu v1.20.6/go.mod h1:dEdOG4KSqIftr5HxxqciNKBIdu0v3OD0ZYL7A3J09KA=
github.com/livekit/protocol v0.7.0 h1:p1HjTwlFdWalJAHs0zDFXy3Nyou0z+WqD9bernAoGT0=
github.com/livekit/protocol v0.7.0/go.mod h1:Vk04t1uIJa+U2L5SeANEmDl6ebjc9tKVi4kk3CpqW74=
github.com/livekit/protocol v0.7.1 h1:KO6n7SYrwJfnHekX0GrFY1BfC+fCXYHa5yIQ099rgsU=
github.com/livekit/protocol v0.7.1/go.mod h1:Vk04t1uIJa+U2L5SeANEmDl6ebjc9tKVi4kk3CpqW74=
github.com/livekit/protocol v0.7.2 h1:4qwCkIFKhDYeyzp79lwb09/nwkjyjql3/o/Viifnyig=
github.com/livekit/protocol v0.7.2/go.mod h1:Vk04t1uIJa+U2L5SeANEmDl6ebjc9tKVi4kk3CpqW74=
github.com/lucsky/cuid v1.0.2 h1:z4XlExeoderxoPj2/dxKOyPxe9RCOu7yNq9/XWxIUMQ=
github.com/lucsky/cuid v1.0.2/go.mod h1:QaaJqckboimOmhRSJXSx/+IT+VTfxfPGSo/6mfgUfmE=
github.com/lyft/protoc-gen-validate v0.0.13/go.mod h1:XbGvPuh87YZc5TdIa2/I4pLk0QoUACkjt2znoq26NVQ=
+1 -1
View File
@@ -182,7 +182,6 @@ func (t *MediaTrack) AddSubscriber(sub types.Participant) error {
downTrack.SetTransceiver(transceiver)
// when outtrack is bound, start loop to send reports
downTrack.OnBind(func() {
subTrack.SetPublisherMuted(t.IsMuted())
go t.sendDownTrackBindingReports(sub)
})
@@ -227,6 +226,7 @@ func (t *MediaTrack) AddSubscriber(sub types.Participant) error {
})
t.subscribedTracks[sub.ID()] = subTrack
subTrack.SetPublisherMuted(t.IsMuted())
t.receiver.AddDownTrack(downTrack, t.shouldStartWithBestQuality())
// since sub will lock, run it in a goroutine to avoid deadlocks
+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
}
+25
View File
@@ -159,6 +159,31 @@ func TestCorrectJoinedAt(t *testing.T) {
require.True(t, time.Now().Unix()-info.JoinedAt <= 1)
}
func TestMuteSetting(t *testing.T) {
t.Run("can set mute when track is pending", func(t *testing.T) {
p := newParticipantForTest("test")
ti := &livekit.TrackInfo{Sid: "testTrack"}
p.pendingTracks["cid"] = ti
p.SetTrackMuted(ti.Sid, true)
require.True(t, ti.Muted)
})
t.Run("can publish a muted track", func(t *testing.T) {
p := newParticipantForTest("test")
p.AddTrack(&livekit.AddTrackRequest{
Cid: "cid",
Type: livekit.TrackType_AUDIO,
Muted: true,
})
ti := p.getPendingTrack("cid", livekit.TrackType_AUDIO, false)
require.NotNil(t, ti)
require.True(t, ti.Muted)
})
}
func newParticipantForTest(identity string) *ParticipantImpl {
conf, _ := config.NewConfig("", nil)
// disable mux, it doesn't play too well with unit test