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:
@@ -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