Send explicit message to clients for mute/unmute. (#107)
* Send explicit message to clients for mute/unmute. * documentation in config
This commit is contained in:
@@ -74,6 +74,9 @@ keys:
|
||||
# enabled_codecs:
|
||||
# - mime: audio/opus
|
||||
# - mime: video/vp8
|
||||
# # allow tracks to be unmuted remotely, defaults to false
|
||||
# # tracks can always be muted from the Room Service APIs
|
||||
# enable_remote_unmute: true
|
||||
|
||||
# Webhooks
|
||||
# when configured, LiveKit notifies your URL handler with room events
|
||||
|
||||
@@ -14,7 +14,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.8.1
|
||||
github.com/livekit/protocol v0.8.2
|
||||
github.com/magefile/mage v1.11.0
|
||||
github.com/maxbrunsfeld/counterfeiter/v6 v6.3.0
|
||||
github.com/mitchellh/go-homedir v1.1.0
|
||||
|
||||
@@ -241,8 +241,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.9 h1:Ih+tE5CXqdL1o6iXfZn+uBoddBXWceaOKVIun6aVuZM=
|
||||
github.com/livekit/ion-sfu v1.20.9/go.mod h1:g8hwobZI5fvX1RXvayf4ZXkgP7spV5YGE4yTSsumpB4=
|
||||
github.com/livekit/protocol v0.8.1 h1:J4mz1C2rUM6696xc1UQJ+qpi7DJXLWl9oTR68xYTGX8=
|
||||
github.com/livekit/protocol v0.8.1/go.mod h1:YKcyBbqH0WmNL35i7c5jxr1L2Az13oT10oGNDOijI20=
|
||||
github.com/livekit/protocol v0.8.2 h1:GvB4fDaIOkDUtYe+G/AMm7mPE19U4zv/55XL7LrrqpY=
|
||||
github.com/livekit/protocol v0.8.2/go.mod h1:YKcyBbqH0WmNL35i7c5jxr1L2Az13oT10oGNDOijI20=
|
||||
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=
|
||||
|
||||
@@ -82,9 +82,10 @@ type RedisConfig struct {
|
||||
}
|
||||
|
||||
type RoomConfig struct {
|
||||
EnabledCodecs []CodecSpec `yaml:"enabled_codecs"`
|
||||
MaxParticipants uint32 `yaml:"max_participants"`
|
||||
EmptyTimeout uint32 `yaml:"empty_timeout"`
|
||||
EnabledCodecs []CodecSpec `yaml:"enabled_codecs"`
|
||||
MaxParticipants uint32 `yaml:"max_participants"`
|
||||
EmptyTimeout uint32 `yaml:"empty_timeout"`
|
||||
EnableRemoteUnmute bool `yaml:"enable_remote_unmute"`
|
||||
}
|
||||
|
||||
type CodecSpec struct {
|
||||
|
||||
@@ -30,7 +30,6 @@ type ParticipantInit struct {
|
||||
Reconnect bool
|
||||
Permission *livekit.ParticipantPermission
|
||||
ProtocolVersion int32
|
||||
UsePlanB bool
|
||||
AutoSubscribe bool
|
||||
Hidden bool
|
||||
}
|
||||
|
||||
@@ -154,7 +154,6 @@ func (r *RedisRouter) StartParticipantSignal(ctx context.Context, roomName strin
|
||||
Reconnect: pi.Reconnect,
|
||||
Permission: pi.Permission,
|
||||
ProtocolVersion: pi.ProtocolVersion,
|
||||
UsePlanB: pi.UsePlanB,
|
||||
AutoSubscribe: pi.AutoSubscribe,
|
||||
Hidden: pi.Hidden,
|
||||
})
|
||||
@@ -225,7 +224,6 @@ func (r *RedisRouter) startParticipantRTC(ss *livekit.StartSession, participantK
|
||||
Reconnect: ss.Reconnect,
|
||||
Permission: ss.Permission,
|
||||
ProtocolVersion: ss.ProtocolVersion,
|
||||
UsePlanB: ss.UsePlanB,
|
||||
AutoSubscribe: ss.AutoSubscribe,
|
||||
Hidden: ss.Hidden,
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ func newMockParticipant(identity string, protocol types.ProtocolVersion, hidden
|
||||
}
|
||||
}
|
||||
|
||||
p.SetTrackMutedStub = func(sid string, muted bool) {
|
||||
p.SetTrackMutedStub = func(sid string, muted bool, fromServer bool) {
|
||||
updateTrack()
|
||||
}
|
||||
p.AddTrackStub = func(req *livekit.AddTrackRequest) {
|
||||
|
||||
+13
-1
@@ -536,7 +536,7 @@ func (p *ParticipantImpl) SendDataPacket(dp *livekit.DataPacket) error {
|
||||
}
|
||||
}
|
||||
|
||||
func (p *ParticipantImpl) SetTrackMuted(trackId string, muted bool) {
|
||||
func (p *ParticipantImpl) SetTrackMuted(trackId string, muted bool, fromAdmin bool) {
|
||||
isPending := false
|
||||
p.lock.RLock()
|
||||
for _, ti := range p.pendingTracks {
|
||||
@@ -559,6 +559,18 @@ func (p *ParticipantImpl) SetTrackMuted(trackId string, muted bool) {
|
||||
currentMuted := track.IsMuted()
|
||||
track.SetMuted(muted)
|
||||
|
||||
// when request is coming from admin, send message to current participant
|
||||
if fromAdmin {
|
||||
_ = p.writeMessage(&livekit.SignalResponse{
|
||||
Message: &livekit.SignalResponse_Mute{
|
||||
Mute: &livekit.MuteTrackRequest{
|
||||
Sid: trackId,
|
||||
Muted: muted,
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
if currentMuted != track.IsMuted() && p.onTrackUpdated != nil {
|
||||
logger.Debugw("mute status changed",
|
||||
"participant", p.Identity(),
|
||||
|
||||
@@ -165,7 +165,7 @@ func TestMuteSetting(t *testing.T) {
|
||||
ti := &livekit.TrackInfo{Sid: "testTrack"}
|
||||
p.pendingTracks["cid"] = ti
|
||||
|
||||
p.SetTrackMuted(ti.Sid, true)
|
||||
p.SetTrackMuted(ti.Sid, true, false)
|
||||
require.True(t, ti.Muted)
|
||||
|
||||
})
|
||||
|
||||
@@ -146,7 +146,7 @@ func TestParticipantUpdate(t *testing.T) {
|
||||
"track mutes are sent to everyone",
|
||||
true,
|
||||
func(p types.Participant) {
|
||||
p.SetTrackMuted("", true)
|
||||
p.SetTrackMuted("", true, false)
|
||||
},
|
||||
},
|
||||
{
|
||||
|
||||
@@ -50,7 +50,7 @@ type Participant interface {
|
||||
SendParticipantUpdate(participants []*livekit.ParticipantInfo) error
|
||||
SendActiveSpeakers(speakers []*livekit.SpeakerInfo) error
|
||||
SendDataPacket(packet *livekit.DataPacket) error
|
||||
SetTrackMuted(trackId string, muted bool)
|
||||
SetTrackMuted(trackId string, muted bool, fromAdmin bool)
|
||||
GetAudioLevel() (level uint8, active bool)
|
||||
|
||||
// permissions
|
||||
|
||||
@@ -351,11 +351,12 @@ type FakeParticipant struct {
|
||||
setResponseSinkArgsForCall []struct {
|
||||
arg1 routing.MessageSink
|
||||
}
|
||||
SetTrackMutedStub func(string, bool)
|
||||
SetTrackMutedStub func(string, bool, bool)
|
||||
setTrackMutedMutex sync.RWMutex
|
||||
setTrackMutedArgsForCall []struct {
|
||||
arg1 string
|
||||
arg2 bool
|
||||
arg3 bool
|
||||
}
|
||||
StartStub func()
|
||||
startMutex sync.RWMutex
|
||||
@@ -2278,17 +2279,18 @@ func (fake *FakeParticipant) SetResponseSinkArgsForCall(i int) routing.MessageSi
|
||||
return argsForCall.arg1
|
||||
}
|
||||
|
||||
func (fake *FakeParticipant) SetTrackMuted(arg1 string, arg2 bool) {
|
||||
func (fake *FakeParticipant) SetTrackMuted(arg1 string, arg2 bool, arg3 bool) {
|
||||
fake.setTrackMutedMutex.Lock()
|
||||
fake.setTrackMutedArgsForCall = append(fake.setTrackMutedArgsForCall, struct {
|
||||
arg1 string
|
||||
arg2 bool
|
||||
}{arg1, arg2})
|
||||
arg3 bool
|
||||
}{arg1, arg2, arg3})
|
||||
stub := fake.SetTrackMutedStub
|
||||
fake.recordInvocation("SetTrackMuted", []interface{}{arg1, arg2})
|
||||
fake.recordInvocation("SetTrackMuted", []interface{}{arg1, arg2, arg3})
|
||||
fake.setTrackMutedMutex.Unlock()
|
||||
if stub != nil {
|
||||
fake.SetTrackMutedStub(arg1, arg2)
|
||||
fake.SetTrackMutedStub(arg1, arg2, arg3)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2298,17 +2300,17 @@ func (fake *FakeParticipant) SetTrackMutedCallCount() int {
|
||||
return len(fake.setTrackMutedArgsForCall)
|
||||
}
|
||||
|
||||
func (fake *FakeParticipant) SetTrackMutedCalls(stub func(string, bool)) {
|
||||
func (fake *FakeParticipant) SetTrackMutedCalls(stub func(string, bool, bool)) {
|
||||
fake.setTrackMutedMutex.Lock()
|
||||
defer fake.setTrackMutedMutex.Unlock()
|
||||
fake.SetTrackMutedStub = stub
|
||||
}
|
||||
|
||||
func (fake *FakeParticipant) SetTrackMutedArgsForCall(i int) (string, bool) {
|
||||
func (fake *FakeParticipant) SetTrackMutedArgsForCall(i int) (string, bool, bool) {
|
||||
fake.setTrackMutedMutex.RLock()
|
||||
defer fake.setTrackMutedMutex.RUnlock()
|
||||
argsForCall := fake.setTrackMutedArgsForCall[i]
|
||||
return argsForCall.arg1, argsForCall.arg2
|
||||
return argsForCall.arg1, argsForCall.arg2, argsForCall.arg3
|
||||
}
|
||||
|
||||
func (fake *FakeParticipant) Start() {
|
||||
|
||||
@@ -10,7 +10,6 @@ import (
|
||||
livekit "github.com/livekit/protocol/proto"
|
||||
"github.com/livekit/protocol/utils"
|
||||
"github.com/livekit/protocol/webhook"
|
||||
"github.com/pion/webrtc/v3"
|
||||
|
||||
"github.com/livekit/livekit-server/pkg/config"
|
||||
"github.com/livekit/livekit-server/pkg/logger"
|
||||
@@ -287,16 +286,12 @@ func (r *LocalRoomManager) StartSession(ctx context.Context, roomName string, pi
|
||||
"room", roomName,
|
||||
"nodeID", r.currentNode.Id,
|
||||
"participant", pi.Identity,
|
||||
"planB", pi.UsePlanB,
|
||||
"protocol", pi.ProtocolVersion,
|
||||
)
|
||||
|
||||
pv := types.ProtocolVersion(pi.ProtocolVersion)
|
||||
rtcConf := *r.rtcConfig
|
||||
rtcConf.SetBufferFactory(room.GetBufferFactor())
|
||||
if pi.UsePlanB {
|
||||
rtcConf.Configuration.SDPSemantics = webrtc.SDPSemanticsPlanB
|
||||
}
|
||||
participant, err = rtc.NewParticipant(rtc.ParticipantParams{
|
||||
Identity: pi.Identity,
|
||||
Config: &rtcConf,
|
||||
@@ -459,7 +454,7 @@ func (r *LocalRoomManager) rtcSessionWorker(room *rtc.Room, participant types.Pa
|
||||
logger.Errorw("could not handle trickle", err, "participant", participant.Identity(), "pID", participant.ID())
|
||||
}
|
||||
case *livekit.SignalRequest_Mute:
|
||||
participant.SetTrackMuted(msg.Mute.Sid, msg.Mute.Muted)
|
||||
participant.SetTrackMuted(msg.Mute.Sid, msg.Mute.Muted, false)
|
||||
case *livekit.SignalRequest_Subscription:
|
||||
if err := room.UpdateSubscriptions(participant, msg.Subscription.TrackSids, msg.Subscription.Subscribe); err != nil {
|
||||
logger.Warnw("could not update subscription", err,
|
||||
@@ -490,6 +485,7 @@ func (r *LocalRoomManager) rtcSessionWorker(room *rtc.Room, participant types.Pa
|
||||
}
|
||||
}
|
||||
|
||||
// handles RTC messages resulted from Room API calls
|
||||
func (r *LocalRoomManager) handleRTCMessage(ctx context.Context, roomName, identity string, msg *livekit.RTCNodeMessage) {
|
||||
r.lock.RLock()
|
||||
room := r.rooms[roomName]
|
||||
@@ -512,7 +508,11 @@ func (r *LocalRoomManager) handleRTCMessage(ctx context.Context, roomName, ident
|
||||
case *livekit.RTCNodeMessage_MuteTrack:
|
||||
logger.Debugw("setting track muted", "room", roomName, "participant", identity,
|
||||
"track", rm.MuteTrack.TrackSid, "muted", rm.MuteTrack.Muted)
|
||||
participant.SetTrackMuted(rm.MuteTrack.TrackSid, rm.MuteTrack.Muted)
|
||||
if !rm.MuteTrack.Muted && !r.config.Room.EnableRemoteUnmute {
|
||||
logger.Errorw("cannot unmute track, remote unmute is disabled", nil)
|
||||
return
|
||||
}
|
||||
participant.SetTrackMuted(rm.MuteTrack.TrackSid, rm.MuteTrack.Muted, true)
|
||||
case *livekit.RTCNodeMessage_UpdateParticipant:
|
||||
logger.Debugw("updating participant", "room", roomName, "participant", identity)
|
||||
if rm.UpdateParticipant.Metadata != "" {
|
||||
|
||||
@@ -68,8 +68,6 @@ func (s *RTCService) validate(r *http.Request) (string, routing.ParticipantInit,
|
||||
reconnectParam := r.FormValue("reconnect")
|
||||
protocolParam := r.FormValue("protocol")
|
||||
autoSubParam := r.FormValue("auto_subscribe")
|
||||
// plan b does not work fully at the moment.
|
||||
planBParam := r.FormValue("planb")
|
||||
|
||||
if onlyName != "" {
|
||||
roomName = onlyName
|
||||
@@ -78,7 +76,6 @@ func (s *RTCService) validate(r *http.Request) (string, routing.ParticipantInit,
|
||||
pi := routing.ParticipantInit{
|
||||
Reconnect: boolValue(reconnectParam),
|
||||
Identity: claims.Identity,
|
||||
UsePlanB: boolValue(planBParam),
|
||||
AutoSubscribe: true,
|
||||
Metadata: claims.Metadata,
|
||||
Hidden: claims.Video.Hidden,
|
||||
|
||||
Reference in New Issue
Block a user