RoomService.updateParticipantMetadata, participant permissions
This commit is contained in:
+41
-9
@@ -38,9 +38,10 @@ type ParticipantImpl struct {
|
||||
conf *WebRTCConfig
|
||||
identity string
|
||||
// JSON encoded metadata to pass to clients
|
||||
metadata string
|
||||
state atomic.Value // livekit.ParticipantInfo_State
|
||||
rtcpCh chan []rtcp.Packet
|
||||
metadata string
|
||||
permission *livekit.ParticipantPermission
|
||||
state atomic.Value // livekit.ParticipantInfo_State
|
||||
rtcpCh chan []rtcp.Packet
|
||||
|
||||
// hold reference for MediaTrack
|
||||
twcc *twcc.Responder
|
||||
@@ -59,6 +60,7 @@ type ParticipantImpl struct {
|
||||
onTrackPublished func(types.Participant, types.PublishedTrack)
|
||||
onTrackUpdated func(types.Participant, types.PublishedTrack)
|
||||
onStateChange func(p types.Participant, oldState livekit.ParticipantInfo_State)
|
||||
onMetadataUpdate func(types.Participant)
|
||||
onClose func(types.Participant)
|
||||
}
|
||||
|
||||
@@ -140,18 +142,24 @@ func (p *ParticipantImpl) IsReady() bool {
|
||||
func (p *ParticipantImpl) SetMetadata(metadata map[string]interface{}) error {
|
||||
if metadata == nil {
|
||||
p.metadata = ""
|
||||
return nil
|
||||
}
|
||||
|
||||
if data, err := json.Marshal(metadata); err != nil {
|
||||
return err
|
||||
} else {
|
||||
p.metadata = string(data)
|
||||
if data, err := json.Marshal(metadata); err != nil {
|
||||
return err
|
||||
} else {
|
||||
p.metadata = string(data)
|
||||
}
|
||||
}
|
||||
|
||||
if p.onMetadataUpdate != nil {
|
||||
p.onMetadataUpdate(p)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *ParticipantImpl) SetPermission(permission *livekit.ParticipantPermission) {
|
||||
p.permission = permission
|
||||
}
|
||||
|
||||
func (p *ParticipantImpl) RTCPChan() chan []rtcp.Packet {
|
||||
return p.rtcpCh
|
||||
}
|
||||
@@ -197,6 +205,10 @@ func (p *ParticipantImpl) OnTrackUpdated(callback func(types.Participant, types.
|
||||
p.onTrackUpdated = callback
|
||||
}
|
||||
|
||||
func (p *ParticipantImpl) OnMetadataUpdate(callback func(types.Participant)) {
|
||||
p.onMetadataUpdate = callback
|
||||
}
|
||||
|
||||
func (p *ParticipantImpl) OnClose(callback func(types.Participant)) {
|
||||
p.onClose = callback
|
||||
}
|
||||
@@ -459,6 +471,14 @@ func (p *ParticipantImpl) GetAudioLevel() (level uint8, noisy bool) {
|
||||
return
|
||||
}
|
||||
|
||||
func (p *ParticipantImpl) CanPublish() bool {
|
||||
return p.permission == nil || p.permission.CanPublish
|
||||
}
|
||||
|
||||
func (p *ParticipantImpl) CanSubscribe() bool {
|
||||
return p.permission == nil || p.permission.CanSubscribe
|
||||
}
|
||||
|
||||
func (p *ParticipantImpl) SubscriberPC() *webrtc.PeerConnection {
|
||||
return p.subscriber.pc
|
||||
}
|
||||
@@ -580,6 +600,12 @@ func (p *ParticipantImpl) onMediaTrack(track *webrtc.TrackRemote, rtpReceiver *w
|
||||
"remoteTrack", track.ID(),
|
||||
"rid", track.RID())
|
||||
|
||||
if !p.CanPublish() {
|
||||
logger.Warnw("no permission to publish mediaTrack",
|
||||
"participant", p.Identity())
|
||||
return
|
||||
}
|
||||
|
||||
// delete pending track if it's not simulcasting
|
||||
ti := p.getPendingTrack(track.ID(), ToProtoTrackKind(track.Kind()), track.RID() == "")
|
||||
if ti == nil {
|
||||
@@ -620,6 +646,12 @@ func (p *ParticipantImpl) onDataChannel(dc *webrtc.DataChannel) {
|
||||
}
|
||||
logger.Debugw("dataChannel added", "participant", p.Identity(), "label", dc.Label())
|
||||
|
||||
if !p.CanPublish() {
|
||||
logger.Warnw("no permission to publish dataTrack",
|
||||
"participant", p.Identity())
|
||||
return
|
||||
}
|
||||
|
||||
// data channels have numeric ids, so we use its label to identify
|
||||
ti := p.getPendingTrack(dc.Label(), livekit.TrackType_DATA, true)
|
||||
if ti == nil {
|
||||
|
||||
+15
-7
@@ -137,7 +137,7 @@ func (r *Room) Join(participant types.Participant) error {
|
||||
if r.onParticipantChanged != nil {
|
||||
r.onParticipantChanged(participant)
|
||||
}
|
||||
r.broadcastParticipantState(p)
|
||||
r.broadcastParticipantState(p, true)
|
||||
|
||||
if p.State() == livekit.ParticipantInfo_ACTIVE {
|
||||
// subscribe participant to existing publishedTracks
|
||||
@@ -161,7 +161,7 @@ func (r *Room) Join(participant types.Participant) error {
|
||||
}
|
||||
})
|
||||
participant.OnTrackUpdated(r.onTrackUpdated)
|
||||
|
||||
participant.OnMetadataUpdate(r.onParticipantMetadataUpdate)
|
||||
logger.Infow("new participant joined",
|
||||
"id", participant.ID(),
|
||||
"identity", participant.Identity(),
|
||||
@@ -213,7 +213,7 @@ func (r *Room) RemoveParticipant(identity string) {
|
||||
if r.onParticipantChanged != nil {
|
||||
r.onParticipantChanged(p)
|
||||
}
|
||||
r.broadcastParticipantState(p)
|
||||
r.broadcastParticipantState(p, true)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -288,7 +288,7 @@ func (r *Room) OnParticipantChanged(f func(participant types.Participant)) {
|
||||
// a ParticipantImpl in the room added a new remoteTrack, subscribe other participants to it
|
||||
func (r *Room) onTrackAdded(participant types.Participant, track types.PublishedTrack) {
|
||||
// publish participant update, since track state is changed
|
||||
r.broadcastParticipantState(participant)
|
||||
r.broadcastParticipantState(participant, true)
|
||||
|
||||
r.lock.RLock()
|
||||
defer r.lock.RUnlock()
|
||||
@@ -322,19 +322,27 @@ func (r *Room) onTrackAdded(participant types.Participant, track types.Published
|
||||
}
|
||||
|
||||
func (r *Room) onTrackUpdated(p types.Participant, track types.PublishedTrack) {
|
||||
r.broadcastParticipantState(p)
|
||||
// send track updates to everyone, especially if track was updated by admin
|
||||
r.broadcastParticipantState(p, false)
|
||||
if r.onParticipantChanged != nil {
|
||||
r.onParticipantChanged(p)
|
||||
}
|
||||
}
|
||||
|
||||
func (r *Room) onParticipantMetadataUpdate(p types.Participant) {
|
||||
r.broadcastParticipantState(p, false)
|
||||
if r.onParticipantChanged != nil {
|
||||
r.onParticipantChanged(p)
|
||||
}
|
||||
}
|
||||
|
||||
// broadcast an update about participant p
|
||||
func (r *Room) broadcastParticipantState(p types.Participant) {
|
||||
func (r *Room) broadcastParticipantState(p types.Participant, skipSource bool) {
|
||||
updates := ToProtoParticipants([]types.Participant{p})
|
||||
participants := r.GetParticipants()
|
||||
for _, op := range participants {
|
||||
// skip itself && closed participants
|
||||
if p.ID() == op.ID() || op.State() == livekit.ParticipantInfo_DISCONNECTED {
|
||||
if (skipSource && p.ID() == op.ID()) || op.State() == livekit.ParticipantInfo_DISCONNECTED {
|
||||
continue
|
||||
}
|
||||
|
||||
|
||||
@@ -29,6 +29,7 @@ type Participant interface {
|
||||
ToProto() *livekit.ParticipantInfo
|
||||
RTCPChan() chan []rtcp.Packet
|
||||
SetMetadata(metadata map[string]interface{}) error
|
||||
SetPermission(permission *livekit.ParticipantPermission)
|
||||
GetResponseSink() routing.MessageSink
|
||||
SetResponseSink(sink routing.MessageSink)
|
||||
SubscriberMediaEngine() *webrtc.MediaEngine
|
||||
@@ -47,6 +48,10 @@ type Participant interface {
|
||||
SetTrackMuted(trackId string, muted bool)
|
||||
GetAudioLevel() (level uint8, noisy bool)
|
||||
|
||||
// permissions
|
||||
CanPublish() bool
|
||||
CanSubscribe() bool
|
||||
|
||||
Start()
|
||||
Close() error
|
||||
|
||||
@@ -56,6 +61,7 @@ type Participant interface {
|
||||
OnTrackPublished(func(Participant, PublishedTrack))
|
||||
// OnTrackUpdated - one of its publishedTracks changed in status
|
||||
OnTrackUpdated(callback func(Participant, PublishedTrack))
|
||||
OnMetadataUpdate(callback func(Participant))
|
||||
OnClose(func(Participant))
|
||||
|
||||
// package methods
|
||||
|
||||
@@ -48,6 +48,26 @@ type FakeParticipant struct {
|
||||
arg2 string
|
||||
arg3 livekit.TrackType
|
||||
}
|
||||
CanPublishStub func() bool
|
||||
canPublishMutex sync.RWMutex
|
||||
canPublishArgsForCall []struct {
|
||||
}
|
||||
canPublishReturns struct {
|
||||
result1 bool
|
||||
}
|
||||
canPublishReturnsOnCall map[int]struct {
|
||||
result1 bool
|
||||
}
|
||||
CanSubscribeStub func() bool
|
||||
canSubscribeMutex sync.RWMutex
|
||||
canSubscribeArgsForCall []struct {
|
||||
}
|
||||
canSubscribeReturns struct {
|
||||
result1 bool
|
||||
}
|
||||
canSubscribeReturnsOnCall map[int]struct {
|
||||
result1 bool
|
||||
}
|
||||
CloseStub func() error
|
||||
closeMutex sync.RWMutex
|
||||
closeArgsForCall []struct {
|
||||
@@ -159,6 +179,11 @@ type FakeParticipant struct {
|
||||
onCloseArgsForCall []struct {
|
||||
arg1 func(types.Participant)
|
||||
}
|
||||
OnMetadataUpdateStub func(func(types.Participant))
|
||||
onMetadataUpdateMutex sync.RWMutex
|
||||
onMetadataUpdateArgsForCall []struct {
|
||||
arg1 func(types.Participant)
|
||||
}
|
||||
OnStateChangeStub func(func(p types.Participant, oldState livekit.ParticipantInfo_State))
|
||||
onStateChangeMutex sync.RWMutex
|
||||
onStateChangeArgsForCall []struct {
|
||||
@@ -241,6 +266,11 @@ type FakeParticipant struct {
|
||||
setMetadataReturnsOnCall map[int]struct {
|
||||
result1 error
|
||||
}
|
||||
SetPermissionStub func(*livekit.ParticipantPermission)
|
||||
setPermissionMutex sync.RWMutex
|
||||
setPermissionArgsForCall []struct {
|
||||
arg1 *livekit.ParticipantPermission
|
||||
}
|
||||
SetResponseSinkStub func(routing.MessageSink)
|
||||
setResponseSinkMutex sync.RWMutex
|
||||
setResponseSinkArgsForCall []struct {
|
||||
@@ -490,6 +520,112 @@ func (fake *FakeParticipant) AddTrackArgsForCall(i int) (string, string, livekit
|
||||
return argsForCall.arg1, argsForCall.arg2, argsForCall.arg3
|
||||
}
|
||||
|
||||
func (fake *FakeParticipant) CanPublish() bool {
|
||||
fake.canPublishMutex.Lock()
|
||||
ret, specificReturn := fake.canPublishReturnsOnCall[len(fake.canPublishArgsForCall)]
|
||||
fake.canPublishArgsForCall = append(fake.canPublishArgsForCall, struct {
|
||||
}{})
|
||||
stub := fake.CanPublishStub
|
||||
fakeReturns := fake.canPublishReturns
|
||||
fake.recordInvocation("CanPublish", []interface{}{})
|
||||
fake.canPublishMutex.Unlock()
|
||||
if stub != nil {
|
||||
return stub()
|
||||
}
|
||||
if specificReturn {
|
||||
return ret.result1
|
||||
}
|
||||
return fakeReturns.result1
|
||||
}
|
||||
|
||||
func (fake *FakeParticipant) CanPublishCallCount() int {
|
||||
fake.canPublishMutex.RLock()
|
||||
defer fake.canPublishMutex.RUnlock()
|
||||
return len(fake.canPublishArgsForCall)
|
||||
}
|
||||
|
||||
func (fake *FakeParticipant) CanPublishCalls(stub func() bool) {
|
||||
fake.canPublishMutex.Lock()
|
||||
defer fake.canPublishMutex.Unlock()
|
||||
fake.CanPublishStub = stub
|
||||
}
|
||||
|
||||
func (fake *FakeParticipant) CanPublishReturns(result1 bool) {
|
||||
fake.canPublishMutex.Lock()
|
||||
defer fake.canPublishMutex.Unlock()
|
||||
fake.CanPublishStub = nil
|
||||
fake.canPublishReturns = struct {
|
||||
result1 bool
|
||||
}{result1}
|
||||
}
|
||||
|
||||
func (fake *FakeParticipant) CanPublishReturnsOnCall(i int, result1 bool) {
|
||||
fake.canPublishMutex.Lock()
|
||||
defer fake.canPublishMutex.Unlock()
|
||||
fake.CanPublishStub = nil
|
||||
if fake.canPublishReturnsOnCall == nil {
|
||||
fake.canPublishReturnsOnCall = make(map[int]struct {
|
||||
result1 bool
|
||||
})
|
||||
}
|
||||
fake.canPublishReturnsOnCall[i] = struct {
|
||||
result1 bool
|
||||
}{result1}
|
||||
}
|
||||
|
||||
func (fake *FakeParticipant) CanSubscribe() bool {
|
||||
fake.canSubscribeMutex.Lock()
|
||||
ret, specificReturn := fake.canSubscribeReturnsOnCall[len(fake.canSubscribeArgsForCall)]
|
||||
fake.canSubscribeArgsForCall = append(fake.canSubscribeArgsForCall, struct {
|
||||
}{})
|
||||
stub := fake.CanSubscribeStub
|
||||
fakeReturns := fake.canSubscribeReturns
|
||||
fake.recordInvocation("CanSubscribe", []interface{}{})
|
||||
fake.canSubscribeMutex.Unlock()
|
||||
if stub != nil {
|
||||
return stub()
|
||||
}
|
||||
if specificReturn {
|
||||
return ret.result1
|
||||
}
|
||||
return fakeReturns.result1
|
||||
}
|
||||
|
||||
func (fake *FakeParticipant) CanSubscribeCallCount() int {
|
||||
fake.canSubscribeMutex.RLock()
|
||||
defer fake.canSubscribeMutex.RUnlock()
|
||||
return len(fake.canSubscribeArgsForCall)
|
||||
}
|
||||
|
||||
func (fake *FakeParticipant) CanSubscribeCalls(stub func() bool) {
|
||||
fake.canSubscribeMutex.Lock()
|
||||
defer fake.canSubscribeMutex.Unlock()
|
||||
fake.CanSubscribeStub = stub
|
||||
}
|
||||
|
||||
func (fake *FakeParticipant) CanSubscribeReturns(result1 bool) {
|
||||
fake.canSubscribeMutex.Lock()
|
||||
defer fake.canSubscribeMutex.Unlock()
|
||||
fake.CanSubscribeStub = nil
|
||||
fake.canSubscribeReturns = struct {
|
||||
result1 bool
|
||||
}{result1}
|
||||
}
|
||||
|
||||
func (fake *FakeParticipant) CanSubscribeReturnsOnCall(i int, result1 bool) {
|
||||
fake.canSubscribeMutex.Lock()
|
||||
defer fake.canSubscribeMutex.Unlock()
|
||||
fake.CanSubscribeStub = nil
|
||||
if fake.canSubscribeReturnsOnCall == nil {
|
||||
fake.canSubscribeReturnsOnCall = make(map[int]struct {
|
||||
result1 bool
|
||||
})
|
||||
}
|
||||
fake.canSubscribeReturnsOnCall[i] = struct {
|
||||
result1 bool
|
||||
}{result1}
|
||||
}
|
||||
|
||||
func (fake *FakeParticipant) Close() error {
|
||||
fake.closeMutex.Lock()
|
||||
ret, specificReturn := fake.closeReturnsOnCall[len(fake.closeArgsForCall)]
|
||||
@@ -1074,6 +1210,38 @@ func (fake *FakeParticipant) OnCloseArgsForCall(i int) func(types.Participant) {
|
||||
return argsForCall.arg1
|
||||
}
|
||||
|
||||
func (fake *FakeParticipant) OnMetadataUpdate(arg1 func(types.Participant)) {
|
||||
fake.onMetadataUpdateMutex.Lock()
|
||||
fake.onMetadataUpdateArgsForCall = append(fake.onMetadataUpdateArgsForCall, struct {
|
||||
arg1 func(types.Participant)
|
||||
}{arg1})
|
||||
stub := fake.OnMetadataUpdateStub
|
||||
fake.recordInvocation("OnMetadataUpdate", []interface{}{arg1})
|
||||
fake.onMetadataUpdateMutex.Unlock()
|
||||
if stub != nil {
|
||||
fake.OnMetadataUpdateStub(arg1)
|
||||
}
|
||||
}
|
||||
|
||||
func (fake *FakeParticipant) OnMetadataUpdateCallCount() int {
|
||||
fake.onMetadataUpdateMutex.RLock()
|
||||
defer fake.onMetadataUpdateMutex.RUnlock()
|
||||
return len(fake.onMetadataUpdateArgsForCall)
|
||||
}
|
||||
|
||||
func (fake *FakeParticipant) OnMetadataUpdateCalls(stub func(func(types.Participant))) {
|
||||
fake.onMetadataUpdateMutex.Lock()
|
||||
defer fake.onMetadataUpdateMutex.Unlock()
|
||||
fake.OnMetadataUpdateStub = stub
|
||||
}
|
||||
|
||||
func (fake *FakeParticipant) OnMetadataUpdateArgsForCall(i int) func(types.Participant) {
|
||||
fake.onMetadataUpdateMutex.RLock()
|
||||
defer fake.onMetadataUpdateMutex.RUnlock()
|
||||
argsForCall := fake.onMetadataUpdateArgsForCall[i]
|
||||
return argsForCall.arg1
|
||||
}
|
||||
|
||||
func (fake *FakeParticipant) OnStateChange(arg1 func(p types.Participant, oldState livekit.ParticipantInfo_State)) {
|
||||
fake.onStateChangeMutex.Lock()
|
||||
fake.onStateChangeArgsForCall = append(fake.onStateChangeArgsForCall, struct {
|
||||
@@ -1554,6 +1722,38 @@ func (fake *FakeParticipant) SetMetadataReturnsOnCall(i int, result1 error) {
|
||||
}{result1}
|
||||
}
|
||||
|
||||
func (fake *FakeParticipant) SetPermission(arg1 *livekit.ParticipantPermission) {
|
||||
fake.setPermissionMutex.Lock()
|
||||
fake.setPermissionArgsForCall = append(fake.setPermissionArgsForCall, struct {
|
||||
arg1 *livekit.ParticipantPermission
|
||||
}{arg1})
|
||||
stub := fake.SetPermissionStub
|
||||
fake.recordInvocation("SetPermission", []interface{}{arg1})
|
||||
fake.setPermissionMutex.Unlock()
|
||||
if stub != nil {
|
||||
fake.SetPermissionStub(arg1)
|
||||
}
|
||||
}
|
||||
|
||||
func (fake *FakeParticipant) SetPermissionCallCount() int {
|
||||
fake.setPermissionMutex.RLock()
|
||||
defer fake.setPermissionMutex.RUnlock()
|
||||
return len(fake.setPermissionArgsForCall)
|
||||
}
|
||||
|
||||
func (fake *FakeParticipant) SetPermissionCalls(stub func(*livekit.ParticipantPermission)) {
|
||||
fake.setPermissionMutex.Lock()
|
||||
defer fake.setPermissionMutex.Unlock()
|
||||
fake.SetPermissionStub = stub
|
||||
}
|
||||
|
||||
func (fake *FakeParticipant) SetPermissionArgsForCall(i int) *livekit.ParticipantPermission {
|
||||
fake.setPermissionMutex.RLock()
|
||||
defer fake.setPermissionMutex.RUnlock()
|
||||
argsForCall := fake.setPermissionArgsForCall[i]
|
||||
return argsForCall.arg1
|
||||
}
|
||||
|
||||
func (fake *FakeParticipant) SetResponseSink(arg1 routing.MessageSink) {
|
||||
fake.setResponseSinkMutex.Lock()
|
||||
fake.setResponseSinkArgsForCall = append(fake.setResponseSinkArgsForCall, struct {
|
||||
@@ -1866,6 +2066,10 @@ func (fake *FakeParticipant) Invocations() map[string][][]interface{} {
|
||||
defer fake.addSubscriberMutex.RUnlock()
|
||||
fake.addTrackMutex.RLock()
|
||||
defer fake.addTrackMutex.RUnlock()
|
||||
fake.canPublishMutex.RLock()
|
||||
defer fake.canPublishMutex.RUnlock()
|
||||
fake.canSubscribeMutex.RLock()
|
||||
defer fake.canSubscribeMutex.RUnlock()
|
||||
fake.closeMutex.RLock()
|
||||
defer fake.closeMutex.RUnlock()
|
||||
fake.getAudioLevelMutex.RLock()
|
||||
@@ -1888,6 +2092,8 @@ func (fake *FakeParticipant) Invocations() map[string][][]interface{} {
|
||||
defer fake.isReadyMutex.RUnlock()
|
||||
fake.onCloseMutex.RLock()
|
||||
defer fake.onCloseMutex.RUnlock()
|
||||
fake.onMetadataUpdateMutex.RLock()
|
||||
defer fake.onMetadataUpdateMutex.RUnlock()
|
||||
fake.onStateChangeMutex.RLock()
|
||||
defer fake.onStateChangeMutex.RUnlock()
|
||||
fake.onTrackPublishedMutex.RLock()
|
||||
@@ -1908,6 +2114,8 @@ func (fake *FakeParticipant) Invocations() map[string][][]interface{} {
|
||||
defer fake.sendParticipantUpdateMutex.RUnlock()
|
||||
fake.setMetadataMutex.RLock()
|
||||
defer fake.setMetadataMutex.RUnlock()
|
||||
fake.setPermissionMutex.RLock()
|
||||
defer fake.setPermissionMutex.RUnlock()
|
||||
fake.setResponseSinkMutex.RLock()
|
||||
defer fake.setResponseSinkMutex.RUnlock()
|
||||
fake.setTrackMutedMutex.RLock()
|
||||
|
||||
Reference in New Issue
Block a user