Catching a few more files with types (#299)
* Use types in mediatrack.go * A bunch more files get types * One more file
This commit is contained in:
@@ -8,7 +8,7 @@ import (
|
|||||||
"github.com/livekit/livekit-server/pkg/rtc/types/typesfakes"
|
"github.com/livekit/livekit-server/pkg/rtc/types/typesfakes"
|
||||||
)
|
)
|
||||||
|
|
||||||
func newMockParticipant(identity string, protocol types.ProtocolVersion, hidden bool) *typesfakes.FakeParticipant {
|
func newMockParticipant(identity livekit.ParticipantIdentity, protocol types.ProtocolVersion, hidden bool) *typesfakes.FakeParticipant {
|
||||||
p := &typesfakes.FakeParticipant{}
|
p := &typesfakes.FakeParticipant{}
|
||||||
p.IDReturns(utils.NewGuid(utils.ParticipantPrefix))
|
p.IDReturns(utils.NewGuid(utils.ParticipantPrefix))
|
||||||
p.IdentityReturns(identity)
|
p.IdentityReturns(identity)
|
||||||
@@ -38,7 +38,7 @@ func newMockParticipant(identity string, protocol types.ProtocolVersion, hidden
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
p.SetTrackMutedStub = func(sid string, muted bool, fromServer bool) {
|
p.SetTrackMutedStub = func(sid livekit.TrackID, muted bool, fromServer bool) {
|
||||||
updateTrack()
|
updateTrack()
|
||||||
}
|
}
|
||||||
p.AddTrackStub = func(req *livekit.AddTrackRequest) {
|
p.AddTrackStub = func(req *livekit.AddTrackRequest) {
|
||||||
|
|||||||
+18
-19
@@ -52,7 +52,7 @@ type MediaTrack struct {
|
|||||||
|
|
||||||
lock sync.RWMutex
|
lock sync.RWMutex
|
||||||
|
|
||||||
// map of target participantId -> types.SubscribedTrack
|
// map of target participantID -> types.SubscribedTrack
|
||||||
subscribedTracks sync.Map // participantSid => types.SubscribedTrack
|
subscribedTracks sync.Map // participantSid => types.SubscribedTrack
|
||||||
twcc *twcc.Responder
|
twcc *twcc.Responder
|
||||||
audioLevel *AudioLevel
|
audioLevel *AudioLevel
|
||||||
@@ -73,10 +73,10 @@ type MediaTrack struct {
|
|||||||
|
|
||||||
// quality level enable/disable
|
// quality level enable/disable
|
||||||
maxQualityLock sync.Mutex
|
maxQualityLock sync.Mutex
|
||||||
maxSubscriberQuality map[string]livekit.VideoQuality
|
maxSubscriberQuality map[livekit.ParticipantID]livekit.VideoQuality
|
||||||
maxSubscribedQuality livekit.VideoQuality
|
maxSubscribedQuality livekit.VideoQuality
|
||||||
allSubscribersMuted bool
|
allSubscribersMuted bool
|
||||||
onSubscribedMaxQualityChange func(trackSid string, subscribedQualities []*livekit.SubscribedQuality) error
|
onSubscribedMaxQualityChange func(trackID livekit.TrackID, subscribedQualities []*livekit.SubscribedQuality) error
|
||||||
|
|
||||||
onClose []func()
|
onClose []func()
|
||||||
}
|
}
|
||||||
@@ -85,8 +85,8 @@ type MediaTrackParams struct {
|
|||||||
TrackInfo *livekit.TrackInfo
|
TrackInfo *livekit.TrackInfo
|
||||||
SignalCid string
|
SignalCid string
|
||||||
SdpCid string
|
SdpCid string
|
||||||
ParticipantID string
|
ParticipantID livekit.ParticipantID
|
||||||
ParticipantIdentity string
|
ParticipantIdentity livekit.ParticipantIdentity
|
||||||
// channel to send RTCP packets to the source
|
// channel to send RTCP packets to the source
|
||||||
RTCPChan chan []rtcp.Packet
|
RTCPChan chan []rtcp.Packet
|
||||||
BufferFactory *buffer.Factory
|
BufferFactory *buffer.Factory
|
||||||
@@ -104,7 +104,7 @@ func NewMediaTrack(track *webrtc.TrackRemote, params MediaTrackParams) *MediaTra
|
|||||||
codec: track.Codec(),
|
codec: track.Codec(),
|
||||||
connectionStats: connectionquality.NewConnectionStats(),
|
connectionStats: connectionquality.NewConnectionStats(),
|
||||||
done: make(chan struct{}),
|
done: make(chan struct{}),
|
||||||
maxSubscriberQuality: make(map[string]livekit.VideoQuality),
|
maxSubscriberQuality: make(map[livekit.ParticipantID]livekit.VideoQuality),
|
||||||
}
|
}
|
||||||
|
|
||||||
if params.TrackInfo.Muted {
|
if params.TrackInfo.Muted {
|
||||||
@@ -122,7 +122,7 @@ func NewMediaTrack(track *webrtc.TrackRemote, params MediaTrackParams) *MediaTra
|
|||||||
return t
|
return t
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *MediaTrack) ID() string {
|
func (t *MediaTrack) ID() livekit.TrackID {
|
||||||
return t.params.TrackInfo.Sid
|
return t.params.TrackInfo.Sid
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -184,8 +184,8 @@ func (t *MediaTrack) AddOnClose(f func()) {
|
|||||||
t.onClose = append(t.onClose, f)
|
t.onClose = append(t.onClose, f)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *MediaTrack) IsSubscriber(subId string) bool {
|
func (t *MediaTrack) IsSubscriber(subID livekit.ParticipantID) bool {
|
||||||
_, ok := t.subscribedTracks.Load(subId)
|
_, ok := t.subscribedTracks.Load(subID)
|
||||||
return ok
|
return ok
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -453,8 +453,8 @@ func (t *MediaTrack) AddReceiver(receiver *webrtc.RTPReceiver, track *webrtc.Tra
|
|||||||
|
|
||||||
// RemoveSubscriber removes participant from subscription
|
// RemoveSubscriber removes participant from subscription
|
||||||
// stop all forwarders to the client
|
// stop all forwarders to the client
|
||||||
func (t *MediaTrack) RemoveSubscriber(participantId string) {
|
func (t *MediaTrack) RemoveSubscriber(participantID livekit.ParticipantID) {
|
||||||
subTrack := t.getSubscribedTrack(participantId)
|
subTrack := t.getSubscribedTrack(participantID)
|
||||||
if subTrack != nil {
|
if subTrack != nil {
|
||||||
go subTrack.DownTrack().Close()
|
go subTrack.DownTrack().Close()
|
||||||
}
|
}
|
||||||
@@ -473,11 +473,11 @@ func (t *MediaTrack) RemoveAllSubscribers() {
|
|||||||
t.subscribedTracks = sync.Map{}
|
t.subscribedTracks = sync.Map{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *MediaTrack) RevokeDisallowedSubscribers(allowedSubscriberIDs []string) []string {
|
func (t *MediaTrack) RevokeDisallowedSubscribers(allowedSubscriberIDs []livekit.ParticipantID) []livekit.ParticipantID {
|
||||||
t.lock.Lock()
|
t.lock.Lock()
|
||||||
defer t.lock.Unlock()
|
defer t.lock.Unlock()
|
||||||
|
|
||||||
var revokedSubscriberIDs []string
|
var revokedSubscriberIDs []livekit.ParticipantID
|
||||||
// LK-TODO: large number of subscribers needs to be solved for this loop
|
// LK-TODO: large number of subscribers needs to be solved for this loop
|
||||||
t.subscribedTracks.Range(func(key interface{}, val interface{}) bool {
|
t.subscribedTracks.Range(func(key interface{}, val interface{}) bool {
|
||||||
if subID, ok := key.(string); ok {
|
if subID, ok := key.(string); ok {
|
||||||
@@ -576,7 +576,7 @@ func (t *MediaTrack) GetQualityForDimension(width, height uint32) livekit.VideoQ
|
|||||||
return quality
|
return quality
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *MediaTrack) getSubscribedTrack(subscriberID string) types.SubscribedTrack {
|
func (t *MediaTrack) getSubscribedTrack(subscriberID livekit.ParticipantID) types.SubscribedTrack {
|
||||||
if val, ok := t.subscribedTracks.Load(subscriberID); ok {
|
if val, ok := t.subscribedTracks.Load(subscriberID); ok {
|
||||||
if st, ok := val.(types.SubscribedTrack); ok {
|
if st, ok := val.(types.SubscribedTrack); ok {
|
||||||
return st
|
return st
|
||||||
@@ -690,8 +690,7 @@ func (t *MediaTrack) handlePublisherFeedback(packets []rtcp.Packet) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// handles max loss for audio packets
|
// handles max loss for audio packets
|
||||||
func (t *MediaTrack) handleMaxLossFeedback(_ *sfu.DownTrack,
|
func (t *MediaTrack) handleMaxLossFeedback(_ *sfu.DownTrack, report *rtcp.ReceiverReport) {
|
||||||
report *rtcp.ReceiverReport) {
|
|
||||||
var (
|
var (
|
||||||
shouldUpdate bool
|
shouldUpdate bool
|
||||||
maxLost uint8
|
maxLost uint8
|
||||||
@@ -788,11 +787,11 @@ func (t *MediaTrack) calculateVideoScore() {
|
|||||||
t.connectionStats.Score = connectionquality.Loss2Score(t.PublishLossPercentage(), reducedQuality)
|
t.connectionStats.Score = connectionquality.Loss2Score(t.PublishLossPercentage(), reducedQuality)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *MediaTrack) OnSubscribedMaxQualityChange(f func(trackSid string, subscribedQualities []*livekit.SubscribedQuality) error) {
|
func (t *MediaTrack) OnSubscribedMaxQualityChange(f func(trackID livekit.TrackID, subscribedQualities []*livekit.SubscribedQuality) error) {
|
||||||
t.onSubscribedMaxQualityChange = f
|
t.onSubscribedMaxQualityChange = f
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *MediaTrack) NotifySubscriberMute(subscriberID string) {
|
func (t *MediaTrack) NotifySubscriberMute(subscriberID livekit.ParticipantID) {
|
||||||
if !t.IsSimulcast() {
|
if !t.IsSimulcast() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -810,7 +809,7 @@ func (t *MediaTrack) NotifySubscriberMute(subscriberID string) {
|
|||||||
t.updateQualityChange()
|
t.updateQualityChange()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *MediaTrack) NotifySubscriberMaxQuality(subscriberID string, quality livekit.VideoQuality) {
|
func (t *MediaTrack) NotifySubscriberMaxQuality(subscriberID livekit.ParticipantID, quality livekit.VideoQuality) {
|
||||||
if !t.IsSimulcast() {
|
if !t.IsSimulcast() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
+12
-12
@@ -129,10 +129,10 @@ func TestSubscribedMaxQuality(t *testing.T) {
|
|||||||
|
|
||||||
mt.NotifySubscriberMaxQuality("s1", livekit.VideoQuality_HIGH)
|
mt.NotifySubscriberMaxQuality("s1", livekit.VideoQuality_HIGH)
|
||||||
|
|
||||||
actualTrackSid := ""
|
actualTrackID := ""
|
||||||
actualSubscribedQualities := []*livekit.SubscribedQuality{}
|
actualSubscribedQualities := []*livekit.SubscribedQuality{}
|
||||||
mt.OnSubscribedMaxQualityChange(func(trackSid string, subscribedQualities []*livekit.SubscribedQuality) error {
|
mt.OnSubscribedMaxQualityChange(func(trackID livekit.TrackID, subscribedQualities []*livekit.SubscribedQuality) error {
|
||||||
actualTrackSid = trackSid
|
actualTrackID = trackID
|
||||||
actualSubscribedQualities = subscribedQualities
|
actualSubscribedQualities = subscribedQualities
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
@@ -145,7 +145,7 @@ func TestSubscribedMaxQuality(t *testing.T) {
|
|||||||
&livekit.SubscribedQuality{Quality: livekit.VideoQuality_MEDIUM, Enabled: false},
|
&livekit.SubscribedQuality{Quality: livekit.VideoQuality_MEDIUM, Enabled: false},
|
||||||
&livekit.SubscribedQuality{Quality: livekit.VideoQuality_HIGH, Enabled: false},
|
&livekit.SubscribedQuality{Quality: livekit.VideoQuality_HIGH, Enabled: false},
|
||||||
}
|
}
|
||||||
require.Equal(t, "v1", actualTrackSid)
|
require.Equal(t, "v1", actualTrackID)
|
||||||
require.EqualValues(t, expectedSubscribedQualities, actualSubscribedQualities)
|
require.EqualValues(t, expectedSubscribedQualities, actualSubscribedQualities)
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -175,10 +175,10 @@ func TestSubscribedMaxQuality(t *testing.T) {
|
|||||||
}})
|
}})
|
||||||
mt.simulcasted.TrySet(true)
|
mt.simulcasted.TrySet(true)
|
||||||
|
|
||||||
actualTrackSid := ""
|
actualTrackID := ""
|
||||||
actualSubscribedQualities := []*livekit.SubscribedQuality{}
|
actualSubscribedQualities := []*livekit.SubscribedQuality{}
|
||||||
mt.OnSubscribedMaxQualityChange(func(trackSid string, subscribedQualities []*livekit.SubscribedQuality) error {
|
mt.OnSubscribedMaxQualityChange(func(trackID livekit.TrackID, subscribedQualities []*livekit.SubscribedQuality) error {
|
||||||
actualTrackSid = trackSid
|
actualTrackID = trackID
|
||||||
actualSubscribedQualities = subscribedQualities
|
actualSubscribedQualities = subscribedQualities
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
@@ -191,7 +191,7 @@ func TestSubscribedMaxQuality(t *testing.T) {
|
|||||||
&livekit.SubscribedQuality{Quality: livekit.VideoQuality_MEDIUM, Enabled: true},
|
&livekit.SubscribedQuality{Quality: livekit.VideoQuality_MEDIUM, Enabled: true},
|
||||||
&livekit.SubscribedQuality{Quality: livekit.VideoQuality_HIGH, Enabled: true},
|
&livekit.SubscribedQuality{Quality: livekit.VideoQuality_HIGH, Enabled: true},
|
||||||
}
|
}
|
||||||
require.Equal(t, "v1", actualTrackSid)
|
require.Equal(t, "v1", actualTrackID)
|
||||||
require.EqualValues(t, expectedSubscribedQualities, actualSubscribedQualities)
|
require.EqualValues(t, expectedSubscribedQualities, actualSubscribedQualities)
|
||||||
|
|
||||||
// "s1" dropping to MEDIUM should disable HIGH layer
|
// "s1" dropping to MEDIUM should disable HIGH layer
|
||||||
@@ -202,7 +202,7 @@ func TestSubscribedMaxQuality(t *testing.T) {
|
|||||||
&livekit.SubscribedQuality{Quality: livekit.VideoQuality_MEDIUM, Enabled: true},
|
&livekit.SubscribedQuality{Quality: livekit.VideoQuality_MEDIUM, Enabled: true},
|
||||||
&livekit.SubscribedQuality{Quality: livekit.VideoQuality_HIGH, Enabled: false},
|
&livekit.SubscribedQuality{Quality: livekit.VideoQuality_HIGH, Enabled: false},
|
||||||
}
|
}
|
||||||
require.Equal(t, "v1", actualTrackSid)
|
require.Equal(t, "v1", actualTrackID)
|
||||||
require.EqualValues(t, expectedSubscribedQualities, actualSubscribedQualities)
|
require.EqualValues(t, expectedSubscribedQualities, actualSubscribedQualities)
|
||||||
|
|
||||||
// "s1" and "s1" dropping to LOW should disable HIGH & MEDIUM
|
// "s1" and "s1" dropping to LOW should disable HIGH & MEDIUM
|
||||||
@@ -214,7 +214,7 @@ func TestSubscribedMaxQuality(t *testing.T) {
|
|||||||
&livekit.SubscribedQuality{Quality: livekit.VideoQuality_MEDIUM, Enabled: false},
|
&livekit.SubscribedQuality{Quality: livekit.VideoQuality_MEDIUM, Enabled: false},
|
||||||
&livekit.SubscribedQuality{Quality: livekit.VideoQuality_HIGH, Enabled: false},
|
&livekit.SubscribedQuality{Quality: livekit.VideoQuality_HIGH, Enabled: false},
|
||||||
}
|
}
|
||||||
require.Equal(t, "v1", actualTrackSid)
|
require.Equal(t, "v1", actualTrackID)
|
||||||
require.EqualValues(t, expectedSubscribedQualities, actualSubscribedQualities)
|
require.EqualValues(t, expectedSubscribedQualities, actualSubscribedQualities)
|
||||||
|
|
||||||
// muting one should still produce LOW
|
// muting one should still produce LOW
|
||||||
@@ -225,7 +225,7 @@ func TestSubscribedMaxQuality(t *testing.T) {
|
|||||||
&livekit.SubscribedQuality{Quality: livekit.VideoQuality_MEDIUM, Enabled: false},
|
&livekit.SubscribedQuality{Quality: livekit.VideoQuality_MEDIUM, Enabled: false},
|
||||||
&livekit.SubscribedQuality{Quality: livekit.VideoQuality_HIGH, Enabled: false},
|
&livekit.SubscribedQuality{Quality: livekit.VideoQuality_HIGH, Enabled: false},
|
||||||
}
|
}
|
||||||
require.Equal(t, "v1", actualTrackSid)
|
require.Equal(t, "v1", actualTrackID)
|
||||||
require.EqualValues(t, expectedSubscribedQualities, actualSubscribedQualities)
|
require.EqualValues(t, expectedSubscribedQualities, actualSubscribedQualities)
|
||||||
|
|
||||||
// muting "s2" should disable all qualities
|
// muting "s2" should disable all qualities
|
||||||
@@ -236,7 +236,7 @@ func TestSubscribedMaxQuality(t *testing.T) {
|
|||||||
&livekit.SubscribedQuality{Quality: livekit.VideoQuality_MEDIUM, Enabled: false},
|
&livekit.SubscribedQuality{Quality: livekit.VideoQuality_MEDIUM, Enabled: false},
|
||||||
&livekit.SubscribedQuality{Quality: livekit.VideoQuality_HIGH, Enabled: false},
|
&livekit.SubscribedQuality{Quality: livekit.VideoQuality_HIGH, Enabled: false},
|
||||||
}
|
}
|
||||||
require.Equal(t, "v1", actualTrackSid)
|
require.Equal(t, "v1", actualTrackID)
|
||||||
require.EqualValues(t, expectedSubscribedQualities, actualSubscribedQualities)
|
require.EqualValues(t, expectedSubscribedQualities, actualSubscribedQualities)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
+37
-37
@@ -36,9 +36,9 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type ParticipantParams struct {
|
type ParticipantParams struct {
|
||||||
Identity string
|
Identity livekit.ParticipantIdentity
|
||||||
Name string
|
Name livekit.ParticipantName
|
||||||
SID string
|
SID livekit.ParticipantID
|
||||||
Config *WebRTCConfig
|
Config *WebRTCConfig
|
||||||
Sink routing.MessageSink
|
Sink routing.MessageSink
|
||||||
AudioConfig config.AudioConfig
|
AudioConfig config.AudioConfig
|
||||||
@@ -78,11 +78,11 @@ type ParticipantImpl struct {
|
|||||||
uptrackManager *UptrackManager
|
uptrackManager *UptrackManager
|
||||||
|
|
||||||
// tracks the current participant is subscribed to, map of sid => DownTrack
|
// tracks the current participant is subscribed to, map of sid => DownTrack
|
||||||
subscribedTracks map[string]types.SubscribedTrack
|
subscribedTracks map[livekit.TrackID]types.SubscribedTrack
|
||||||
// keeps track of disallowed tracks
|
// keeps track of disallowed tracks
|
||||||
disallowedSubscriptions map[string]string // trackSid -> publisherSid
|
disallowedSubscriptions map[livekit.TrackID]livekit.ParticipantID // trackID -> publisherID
|
||||||
// keep track of other publishers identities that we are subscribed to
|
// keep track of other publishers identities that we are subscribed to
|
||||||
subscribedTo sync.Map // string => struct{}
|
subscribedTo sync.Map // livekit.ParticipantID => struct{}
|
||||||
|
|
||||||
lock sync.RWMutex
|
lock sync.RWMutex
|
||||||
once sync.Once
|
once sync.Once
|
||||||
@@ -94,7 +94,7 @@ type ParticipantImpl struct {
|
|||||||
onStateChange func(p types.Participant, oldState livekit.ParticipantInfo_State)
|
onStateChange func(p types.Participant, oldState livekit.ParticipantInfo_State)
|
||||||
onMetadataUpdate func(types.Participant)
|
onMetadataUpdate func(types.Participant)
|
||||||
onDataPacket func(types.Participant, *livekit.DataPacket)
|
onDataPacket func(types.Participant, *livekit.DataPacket)
|
||||||
onClose func(types.Participant, map[string]string)
|
onClose func(types.Participant, map[livekit.TrackID]livekit.ParticipantID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewParticipant(params ParticipantParams) (*ParticipantImpl, error) {
|
func NewParticipant(params ParticipantParams) (*ParticipantImpl, error) {
|
||||||
@@ -102,8 +102,8 @@ func NewParticipant(params ParticipantParams) (*ParticipantImpl, error) {
|
|||||||
|
|
||||||
p := &ParticipantImpl{
|
p := &ParticipantImpl{
|
||||||
params: params,
|
params: params,
|
||||||
subscribedTracks: make(map[string]types.SubscribedTrack),
|
subscribedTracks: make(map[livekit.TrackID]types.SubscribedTrack),
|
||||||
disallowedSubscriptions: make(map[string]string),
|
disallowedSubscriptions: make(map[livekit.TrackID]livekit.ParticipantID),
|
||||||
connectedAt: time.Now(),
|
connectedAt: time.Now(),
|
||||||
}
|
}
|
||||||
p.state.Store(livekit.ParticipantInfo_JOINING)
|
p.state.Store(livekit.ParticipantInfo_JOINING)
|
||||||
@@ -185,11 +185,11 @@ func NewParticipant(params ParticipantParams) (*ParticipantImpl, error) {
|
|||||||
return p, nil
|
return p, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *ParticipantImpl) ID() string {
|
func (p *ParticipantImpl) ID() livekit.ParticipantID {
|
||||||
return p.params.SID
|
return p.params.SID
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *ParticipantImpl) Identity() string {
|
func (p *ParticipantImpl) Identity() livekit.ParticipantIdentity {
|
||||||
return p.params.Identity
|
return p.params.Identity
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -273,7 +273,7 @@ func (p *ParticipantImpl) OnDataPacket(callback func(types.Participant, *livekit
|
|||||||
p.onDataPacket = callback
|
p.onDataPacket = callback
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *ParticipantImpl) OnClose(callback func(types.Participant, map[string]string)) {
|
func (p *ParticipantImpl) OnClose(callback func(types.Participant, map[livekit.TrackID]livekit.ParticipantID)) {
|
||||||
p.onClose = callback
|
p.onClose = callback
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -399,9 +399,9 @@ func (p *ParticipantImpl) Close() error {
|
|||||||
p.uptrackManager.Close()
|
p.uptrackManager.Close()
|
||||||
|
|
||||||
p.lock.Lock()
|
p.lock.Lock()
|
||||||
disallowedSubscriptions := make(map[string]string)
|
disallowedSubscriptions := make(map[livekit.TrackID]livekit.ParticipantID)
|
||||||
for trackSid, publisherSid := range p.disallowedSubscriptions {
|
for trackID, publisherID := range p.disallowedSubscriptions {
|
||||||
disallowedSubscriptions[trackSid] = publisherSid
|
disallowedSubscriptions[trackID] = publisherID
|
||||||
}
|
}
|
||||||
|
|
||||||
// remove all downtracks
|
// remove all downtracks
|
||||||
@@ -450,8 +450,8 @@ func (p *ParticipantImpl) AddSubscriber(op types.Participant, params types.AddSu
|
|||||||
return p.uptrackManager.AddSubscriber(op, params)
|
return p.uptrackManager.AddSubscriber(op, params)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *ParticipantImpl) RemoveSubscriber(op types.Participant, trackSid string) {
|
func (p *ParticipantImpl) RemoveSubscriber(op types.Participant, trackID livekit.TrackID) {
|
||||||
p.uptrackManager.RemoveSubscriber(op, trackSid)
|
p.uptrackManager.RemoveSubscriber(op, trackID)
|
||||||
}
|
}
|
||||||
|
|
||||||
// signal connection methods
|
// signal connection methods
|
||||||
@@ -577,20 +577,20 @@ func (p *ParticipantImpl) SendConnectionQualityUpdate(update *livekit.Connection
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *ParticipantImpl) SetTrackMuted(trackSid string, muted bool, fromAdmin bool) {
|
func (p *ParticipantImpl) SetTrackMuted(trackID livekit.TrackID, muted bool, fromAdmin bool) {
|
||||||
// when request is coming from admin, send message to current participant
|
// when request is coming from admin, send message to current participant
|
||||||
if fromAdmin {
|
if fromAdmin {
|
||||||
_ = p.writeMessage(&livekit.SignalResponse{
|
_ = p.writeMessage(&livekit.SignalResponse{
|
||||||
Message: &livekit.SignalResponse_Mute{
|
Message: &livekit.SignalResponse_Mute{
|
||||||
Mute: &livekit.MuteTrackRequest{
|
Mute: &livekit.MuteTrackRequest{
|
||||||
Sid: trackSid,
|
Sid: trackID,
|
||||||
Muted: muted,
|
Muted: muted,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
p.uptrackManager.SetTrackMuted(trackSid, muted)
|
p.uptrackManager.SetTrackMuted(trackID, muted)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *ParticipantImpl) GetAudioLevel() (level uint8, active bool) {
|
func (p *ParticipantImpl) GetAudioLevel() (level uint8, active bool) {
|
||||||
@@ -625,20 +625,20 @@ func (p *ParticipantImpl) GetConnectionQuality() *livekit.ConnectionQualityInfo
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *ParticipantImpl) IsSubscribedTo(participantSid string) bool {
|
func (p *ParticipantImpl) IsSubscribedTo(participantID livekit.ParticipantID) bool {
|
||||||
_, ok := p.subscribedTo.Load(participantSid)
|
_, ok := p.subscribedTo.Load(participantID)
|
||||||
return ok
|
return ok
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *ParticipantImpl) GetSubscribedParticipants() []string {
|
func (p *ParticipantImpl) GetSubscribedParticipants() []livekit.ParticipantID {
|
||||||
var participantSids []string
|
var participantIDs []livekit.ParticipantID
|
||||||
p.subscribedTo.Range(func(key, _ interface{}) bool {
|
p.subscribedTo.Range(func(key, _ interface{}) bool {
|
||||||
if participantSid, ok := key.(string); ok {
|
if participantID, ok := key.(livekit.ParticipantID); ok {
|
||||||
participantSids = append(participantSids, participantSid)
|
participantIDs = append(participantIDs, participantID)
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
})
|
})
|
||||||
return participantSids
|
return participantIDs
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *ParticipantImpl) CanPublish() bool {
|
func (p *ParticipantImpl) CanPublish() bool {
|
||||||
@@ -669,7 +669,7 @@ func (p *ParticipantImpl) SubscriberPC() *webrtc.PeerConnection {
|
|||||||
return p.subscriber.pc
|
return p.subscriber.pc
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *ParticipantImpl) GetPublishedTrack(sid string) types.PublishedTrack {
|
func (p *ParticipantImpl) GetPublishedTrack(sid livekit.TrackID) types.PublishedTrack {
|
||||||
return p.uptrackManager.GetPublishedTrack(sid)
|
return p.uptrackManager.GetPublishedTrack(sid)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -677,7 +677,7 @@ func (p *ParticipantImpl) GetPublishedTracks() []types.PublishedTrack {
|
|||||||
return p.uptrackManager.GetPublishedTracks()
|
return p.uptrackManager.GetPublishedTracks()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *ParticipantImpl) GetSubscribedTrack(sid string) types.SubscribedTrack {
|
func (p *ParticipantImpl) GetSubscribedTrack(sid livekit.TrackID) types.SubscribedTrack {
|
||||||
p.lock.RLock()
|
p.lock.RLock()
|
||||||
defer p.lock.RUnlock()
|
defer p.lock.RUnlock()
|
||||||
return p.subscribedTracks[sid]
|
return p.subscribedTracks[sid]
|
||||||
@@ -735,25 +735,25 @@ func (p *ParticipantImpl) RemoveSubscribedTrack(subTrack types.SubscribedTrack)
|
|||||||
|
|
||||||
func (p *ParticipantImpl) UpdateSubscriptionPermissions(
|
func (p *ParticipantImpl) UpdateSubscriptionPermissions(
|
||||||
permissions *livekit.UpdateSubscriptionPermissions,
|
permissions *livekit.UpdateSubscriptionPermissions,
|
||||||
resolver func(participantSid string) types.Participant,
|
resolver func(participantID livekit.ParticipantID) types.Participant,
|
||||||
) error {
|
) error {
|
||||||
return p.uptrackManager.UpdateSubscriptionPermissions(permissions, resolver)
|
return p.uptrackManager.UpdateSubscriptionPermissions(permissions, resolver)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *ParticipantImpl) SubscriptionPermissionUpdate(publisherSid string, trackSid string, allowed bool) {
|
func (p *ParticipantImpl) SubscriptionPermissionUpdate(publisherID livekit.ParticipantID, trackID livekit.TrackID, allowed bool) {
|
||||||
p.lock.Lock()
|
p.lock.Lock()
|
||||||
if allowed {
|
if allowed {
|
||||||
delete(p.disallowedSubscriptions, trackSid)
|
delete(p.disallowedSubscriptions, trackID)
|
||||||
} else {
|
} else {
|
||||||
p.disallowedSubscriptions[trackSid] = publisherSid
|
p.disallowedSubscriptions[trackID] = publisherID
|
||||||
}
|
}
|
||||||
p.lock.Unlock()
|
p.lock.Unlock()
|
||||||
|
|
||||||
err := p.writeMessage(&livekit.SignalResponse{
|
err := p.writeMessage(&livekit.SignalResponse{
|
||||||
Message: &livekit.SignalResponse_SubscriptionPermissionUpdate{
|
Message: &livekit.SignalResponse_SubscriptionPermissionUpdate{
|
||||||
SubscriptionPermissionUpdate: &livekit.SubscriptionPermissionUpdate{
|
SubscriptionPermissionUpdate: &livekit.SubscriptionPermissionUpdate{
|
||||||
ParticipantSid: publisherSid,
|
ParticipantSid: publisherID,
|
||||||
TrackSid: trackSid,
|
TrackSid: trackID,
|
||||||
Allowed: allowed,
|
Allowed: allowed,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -1118,13 +1118,13 @@ func (p *ParticipantImpl) onStreamStateChange(update *sfu.StreamStateUpdate) err
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *ParticipantImpl) onSubscribedMaxQualityChange(trackSid string, subscribedQualities []*livekit.SubscribedQuality) error {
|
func (p *ParticipantImpl) onSubscribedMaxQualityChange(trackID livekit.TrackID, subscribedQualities []*livekit.SubscribedQuality) error {
|
||||||
if len(subscribedQualities) == 0 {
|
if len(subscribedQualities) == 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
subscribedQualityUpdate := &livekit.SubscribedQualityUpdate{
|
subscribedQualityUpdate := &livekit.SubscribedQualityUpdate{
|
||||||
TrackSid: trackSid,
|
TrackSid: trackID,
|
||||||
SubscribedQualities: subscribedQualities,
|
SubscribedQualities: subscribedQualities,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ func TestICEStateChange(t *testing.T) {
|
|||||||
t.Run("onClose gets called when ICE disconnected", func(t *testing.T) {
|
t.Run("onClose gets called when ICE disconnected", func(t *testing.T) {
|
||||||
p := newParticipantForTest("test")
|
p := newParticipantForTest("test")
|
||||||
closeChan := make(chan struct{})
|
closeChan := make(chan struct{})
|
||||||
p.onClose = func(participant types.Participant, disallowedSubscriptions map[string]string) {
|
p.onClose = func(participant types.Participant, disallowedSubscriptions map[livekit.TrackID]livekit.ParticipantID) {
|
||||||
close(closeChan)
|
close(closeChan)
|
||||||
}
|
}
|
||||||
p.handlePrimaryICEStateChange(webrtc.ICEConnectionStateFailed)
|
p.handlePrimaryICEStateChange(webrtc.ICEConnectionStateFailed)
|
||||||
@@ -341,7 +341,7 @@ func TestSubscriberAsPrimary(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func newParticipantForTest(identity string) *ParticipantImpl {
|
func newParticipantForTest(identity livekit.ParticipantIdentity) *ParticipantImpl {
|
||||||
conf, _ := config.NewConfig("", nil)
|
conf, _ := config.NewConfig("", nil)
|
||||||
// disable mux, it doesn't play too well with unit test
|
// disable mux, it doesn't play too well with unit test
|
||||||
conf.RTC.UDPPort = 0
|
conf.RTC.UDPPort = 0
|
||||||
|
|||||||
+36
-36
@@ -37,8 +37,8 @@ type Room struct {
|
|||||||
telemetry telemetry.TelemetryService
|
telemetry telemetry.TelemetryService
|
||||||
|
|
||||||
// map of identity -> Participant
|
// map of identity -> Participant
|
||||||
participants map[string]types.Participant
|
participants map[livekit.ParticipantIdentity]types.Participant
|
||||||
participantOpts map[string]*ParticipantOptions
|
participantOpts map[livekit.ParticipantIdentity]*ParticipantOptions
|
||||||
bufferFactory *buffer.Factory
|
bufferFactory *buffer.Factory
|
||||||
|
|
||||||
// time the first participant joined the room
|
// time the first participant joined the room
|
||||||
@@ -64,8 +64,8 @@ func NewRoom(room *livekit.Room, config WebRTCConfig, audioConfig *config.AudioC
|
|||||||
config: config,
|
config: config,
|
||||||
audioConfig: audioConfig,
|
audioConfig: audioConfig,
|
||||||
telemetry: telemetry,
|
telemetry: telemetry,
|
||||||
participants: make(map[string]types.Participant),
|
participants: make(map[livekit.ParticipantIdentity]types.Participant),
|
||||||
participantOpts: make(map[string]*ParticipantOptions),
|
participantOpts: make(map[livekit.ParticipantIdentity]*ParticipantOptions),
|
||||||
bufferFactory: buffer.NewBufferFactory(config.Receiver.PacketBufferSize, logr.Logger{}),
|
bufferFactory: buffer.NewBufferFactory(config.Receiver.PacketBufferSize, logr.Logger{}),
|
||||||
closed: make(chan struct{}),
|
closed: make(chan struct{}),
|
||||||
}
|
}
|
||||||
@@ -82,17 +82,17 @@ func NewRoom(room *livekit.Room, config WebRTCConfig, audioConfig *config.AudioC
|
|||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Room) Name() string {
|
func (r *Room) Name() livekit.RoomName {
|
||||||
return r.Room.Name
|
return r.Room.Name
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Room) GetParticipant(identity string) types.Participant {
|
func (r *Room) GetParticipant(identity livekit.ParticipantIdentity) types.Participant {
|
||||||
r.lock.RLock()
|
r.lock.RLock()
|
||||||
defer r.lock.RUnlock()
|
defer r.lock.RUnlock()
|
||||||
return r.participants[identity]
|
return r.participants[identity]
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Room) GetParticipantBySid(participantID string) types.Participant {
|
func (r *Room) GetParticipantBySid(participantID livekit.ParticipantID) types.Participant {
|
||||||
r.lock.RLock()
|
r.lock.RLock()
|
||||||
defer r.lock.RUnlock()
|
defer r.lock.RUnlock()
|
||||||
|
|
||||||
@@ -278,7 +278,7 @@ func (r *Room) ResumeParticipant(p types.Participant, responseSink routing.Messa
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Room) RemoveParticipant(identity string) {
|
func (r *Room) RemoveParticipant(identity livekit.ParticipantIdentity) {
|
||||||
r.lock.Lock()
|
r.lock.Lock()
|
||||||
p, ok := r.participants[identity]
|
p, ok := r.participants[identity]
|
||||||
if ok {
|
if ok {
|
||||||
@@ -337,18 +337,18 @@ func (r *Room) RemoveParticipant(identity string) {
|
|||||||
|
|
||||||
func (r *Room) UpdateSubscriptions(
|
func (r *Room) UpdateSubscriptions(
|
||||||
participant types.Participant,
|
participant types.Participant,
|
||||||
trackIds []string,
|
trackIDs []livekit.TrackID,
|
||||||
participantTracks []*livekit.ParticipantTracks,
|
participantTracks []*livekit.ParticipantTracks,
|
||||||
subscribe bool,
|
subscribe bool,
|
||||||
) error {
|
) error {
|
||||||
// find all matching tracks
|
// find all matching tracks
|
||||||
trackPublishers := make(map[string]types.Participant)
|
trackPublishers := make(map[livekit.TrackID]types.Participant)
|
||||||
participants := r.GetParticipants()
|
participants := r.GetParticipants()
|
||||||
for _, trackSid := range trackIds {
|
for _, trackID := range trackIDs {
|
||||||
for _, p := range participants {
|
for _, p := range participants {
|
||||||
track := p.GetPublishedTrack(trackSid)
|
track := p.GetPublishedTrack(trackID)
|
||||||
if track != nil {
|
if track != nil {
|
||||||
trackPublishers[trackSid] = p
|
trackPublishers[trackID] = p
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -359,19 +359,19 @@ func (r *Room) UpdateSubscriptions(
|
|||||||
if p == nil {
|
if p == nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
for _, trackSid := range pt.TrackSids {
|
for _, trackID := range pt.TrackSids {
|
||||||
trackPublishers[trackSid] = p
|
trackPublishers[trackID] = p
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// handle subscription changes
|
// handle subscription changes
|
||||||
for trackSid, publisher := range trackPublishers {
|
for trackID, publisher := range trackPublishers {
|
||||||
if subscribe {
|
if subscribe {
|
||||||
if _, err := publisher.AddSubscriber(participant, types.AddSubscriberParams{TrackSids: []string{trackSid}}); err != nil {
|
if _, err := publisher.AddSubscriber(participant, types.AddSubscriberParams{TrackIDs: []livekit.TrackID{trackID}}); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
publisher.RemoveSubscriber(participant, trackSid)
|
publisher.RemoveSubscriber(participant, trackID)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
@@ -381,14 +381,14 @@ func (r *Room) UpdateSubscriptionPermissions(participant types.Participant, perm
|
|||||||
return participant.UpdateSubscriptionPermissions(permissions, r.GetParticipantBySid)
|
return participant.UpdateSubscriptionPermissions(permissions, r.GetParticipantBySid)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Room) RemoveDisallowedSubscriptions(sub types.Participant, disallowedSubscriptions map[string]string) {
|
func (r *Room) RemoveDisallowedSubscriptions(sub types.Participant, disallowedSubscriptions map[livekit.TrackID]livekit.ParticipantID) {
|
||||||
for trackSid, publisherSid := range disallowedSubscriptions {
|
for trackID, publisherID := range disallowedSubscriptions {
|
||||||
pub := r.GetParticipantBySid(publisherSid)
|
pub := r.GetParticipantBySid(publisherID)
|
||||||
if pub == nil {
|
if pub == nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
pub.RemoveSubscriber(sub, trackSid)
|
pub.RemoveSubscriber(sub, trackID)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -532,13 +532,13 @@ func (r *Room) onTrackPublished(participant types.Participant, track types.Publi
|
|||||||
}
|
}
|
||||||
|
|
||||||
r.Logger.Debugw("subscribing to new track",
|
r.Logger.Debugw("subscribing to new track",
|
||||||
"participants", []string{participant.Identity(), existingParticipant.Identity()},
|
"participants", []livekit.ParticipantIdentity{participant.Identity(), existingParticipant.Identity()},
|
||||||
"pIDs", []string{participant.ID(), existingParticipant.ID()},
|
"pIDs", []livekit.ParticipantID{participant.ID(), existingParticipant.ID()},
|
||||||
"track", track.ID())
|
"track", track.ID())
|
||||||
if _, err := participant.AddSubscriber(existingParticipant, types.AddSubscriberParams{TrackSids: []string{track.ID()}}); err != nil {
|
if _, err := participant.AddSubscriber(existingParticipant, types.AddSubscriberParams{TrackIDs: []livekit.TrackID{track.ID()}}); err != nil {
|
||||||
r.Logger.Errorw("could not subscribe to remoteTrack", err,
|
r.Logger.Errorw("could not subscribe to remoteTrack", err,
|
||||||
"participants", []string{participant.Identity(), existingParticipant.Identity()},
|
"participants", []livekit.ParticipantIdentity{participant.Identity(), existingParticipant.Identity()},
|
||||||
"pIDs", []string{participant.ID(), existingParticipant.ID()},
|
"pIDs", []livekit.ParticipantID{participant.ID(), existingParticipant.ID()},
|
||||||
"track", track.ID())
|
"track", track.ID())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -579,8 +579,8 @@ func (r *Room) onDataPacket(source types.Participant, dp *livekit.DataPacket) {
|
|||||||
}
|
}
|
||||||
if len(dest) > 0 {
|
if len(dest) > 0 {
|
||||||
found := false
|
found := false
|
||||||
for _, dSid := range dest {
|
for _, dID := range dest {
|
||||||
if op.ID() == dSid {
|
if op.ID() == dID {
|
||||||
found = true
|
found = true
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@@ -610,8 +610,8 @@ func (r *Room) subscribeToExistingTracks(p types.Participant) {
|
|||||||
if n, err := op.AddSubscriber(p, types.AddSubscriberParams{AllTracks: true}); err != nil {
|
if n, err := op.AddSubscriber(p, types.AddSubscriberParams{AllTracks: true}); err != nil {
|
||||||
// TODO: log error? or disconnect?
|
// TODO: log error? or disconnect?
|
||||||
r.Logger.Errorw("could not subscribe to participant", err,
|
r.Logger.Errorw("could not subscribe to participant", err,
|
||||||
"participants", []string{op.Identity(), p.Identity()},
|
"participants", []livekit.ParticipantIdentity{op.Identity(), p.Identity()},
|
||||||
"pIDs", []string{op.ID(), p.ID()})
|
"pIDs", []livekit.ParticipantID{op.ID(), p.ID()})
|
||||||
} else {
|
} else {
|
||||||
tracksAdded += n
|
tracksAdded += n
|
||||||
}
|
}
|
||||||
@@ -682,17 +682,17 @@ func (r *Room) sendSpeakerChanges(speakers []*livekit.SpeakerInfo) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (r *Room) audioUpdateWorker() {
|
func (r *Room) audioUpdateWorker() {
|
||||||
var smoothValues map[string]float32
|
var smoothValues map[livekit.ParticipantID]float32
|
||||||
var smoothFactor float32
|
var smoothFactor float32
|
||||||
var activeThreshold float32
|
var activeThreshold float32
|
||||||
if ss := r.audioConfig.SmoothIntervals; ss > 1 {
|
if ss := r.audioConfig.SmoothIntervals; ss > 1 {
|
||||||
smoothValues = make(map[string]float32)
|
smoothValues = make(map[livekit.ParticipantID]float32)
|
||||||
// exponential moving average (EMA), same center of mass with simple moving average (SMA)
|
// exponential moving average (EMA), same center of mass with simple moving average (SMA)
|
||||||
smoothFactor = 2 / float32(ss+1)
|
smoothFactor = 2 / float32(ss+1)
|
||||||
activeThreshold = ConvertAudioLevel(r.audioConfig.ActiveLevel)
|
activeThreshold = ConvertAudioLevel(r.audioConfig.ActiveLevel)
|
||||||
}
|
}
|
||||||
|
|
||||||
lastActiveMap := make(map[string]*livekit.SpeakerInfo)
|
lastActiveMap := make(map[livekit.ParticipantID]*livekit.SpeakerInfo)
|
||||||
for {
|
for {
|
||||||
if r.IsClosed() {
|
if r.IsClosed() {
|
||||||
return
|
return
|
||||||
@@ -738,7 +738,7 @@ func (r *Room) audioUpdateWorker() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
changedSpeakers := make([]*livekit.SpeakerInfo, 0, len(activeSpeakers))
|
changedSpeakers := make([]*livekit.SpeakerInfo, 0, len(activeSpeakers))
|
||||||
nextActiveMap := make(map[string]*livekit.SpeakerInfo, len(activeSpeakers))
|
nextActiveMap := make(map[livekit.ParticipantID]*livekit.SpeakerInfo, len(activeSpeakers))
|
||||||
for _, speaker := range activeSpeakers {
|
for _, speaker := range activeSpeakers {
|
||||||
prev := lastActiveMap[speaker.Sid]
|
prev := lastActiveMap[speaker.Sid]
|
||||||
if prev == nil || prev.Level != speaker.Level {
|
if prev == nil || prev.Level != speaker.Level {
|
||||||
@@ -775,7 +775,7 @@ func (r *Room) connectionQualityWorker() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
participants := r.GetParticipants()
|
participants := r.GetParticipants()
|
||||||
connectionInfos := make(map[string]*livekit.ConnectionQualityInfo, len(participants))
|
connectionInfos := make(map[livekit.ParticipantID]*livekit.ConnectionQualityInfo, len(participants))
|
||||||
|
|
||||||
for _, p := range participants {
|
for _, p := range participants {
|
||||||
connectionInfos[p.ID()] = p.GetConnectionQuality()
|
connectionInfos[p.ID()] = p.GetConnectionQuality()
|
||||||
|
|||||||
@@ -176,7 +176,7 @@ func TestParticipantUpdate(t *testing.T) {
|
|||||||
t.Run(test.name, func(t *testing.T) {
|
t.Run(test.name, func(t *testing.T) {
|
||||||
rm := newRoomWithParticipants(t, testRoomOpts{num: 3})
|
rm := newRoomWithParticipants(t, testRoomOpts{num: 3})
|
||||||
// remember how many times send has been called for each
|
// remember how many times send has been called for each
|
||||||
callCounts := make(map[string]int)
|
callCounts := make(map[livekit.ParticipantID]int)
|
||||||
for _, p := range rm.GetParticipants() {
|
for _, p := range rm.GetParticipants() {
|
||||||
fp := p.(*typesfakes.FakeParticipant)
|
fp := p.(*typesfakes.FakeParticipant)
|
||||||
callCounts[p.ID()] = fp.SendParticipantUpdateCallCount()
|
callCounts[p.ID()] = fp.SendParticipantUpdateCallCount()
|
||||||
@@ -264,7 +264,7 @@ func TestNewTrack(t *testing.T) {
|
|||||||
require.Equal(t, 1, pub.AddSubscriberCallCount())
|
require.Equal(t, 1, pub.AddSubscriberCallCount())
|
||||||
sub, params := pub.AddSubscriberArgsForCall(pub.AddSubscriberCallCount() - 1)
|
sub, params := pub.AddSubscriberArgsForCall(pub.AddSubscriberCallCount() - 1)
|
||||||
require.Equal(t, p1, sub)
|
require.Equal(t, p1, sub)
|
||||||
require.Equal(t, types.AddSubscriberParams{TrackSids: []string{track.ID()}}, params)
|
require.Equal(t, types.AddSubscriberParams{TrackIDs: []livekit.TrackID{track.ID()}}, params)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,9 +18,9 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type SubscribedTrackParams struct {
|
type SubscribedTrackParams struct {
|
||||||
PublisherID string
|
PublisherID livekit.ParticipantID
|
||||||
PublisherIdentity string
|
PublisherIdentity livekit.ParticipantIdentity
|
||||||
SubscriberID string
|
SubscriberID livekit.ParticipantID
|
||||||
MediaTrack types.MediaTrack
|
MediaTrack types.MediaTrack
|
||||||
DownTrack *sfu.DownTrack
|
DownTrack *sfu.DownTrack
|
||||||
}
|
}
|
||||||
@@ -56,11 +56,11 @@ func (t *SubscribedTrack) ID() string {
|
|||||||
return t.params.DownTrack.ID()
|
return t.params.DownTrack.ID()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *SubscribedTrack) PublisherID() string {
|
func (t *SubscribedTrack) PublisherID() livekit.ParticipantID {
|
||||||
return t.params.PublisherID
|
return t.params.PublisherID
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *SubscribedTrack) PublisherIdentity() string {
|
func (t *SubscribedTrack) PublisherIdentity() livekit.ParticipantIdentity {
|
||||||
return t.params.PublisherIdentity
|
return t.params.PublisherIdentity
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -47,8 +47,8 @@ type PCTransport struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type TransportParams struct {
|
type TransportParams struct {
|
||||||
ParticipantID string
|
ParticipantID livekit.ParticipantID
|
||||||
ParticipantIdentity string
|
ParticipantIdentity livekit.ParticipantIdentity
|
||||||
Target livekit.SignalTarget
|
Target livekit.SignalTarget
|
||||||
Config *WebRTCConfig
|
Config *WebRTCConfig
|
||||||
Telemetry telemetry.TelemetryService
|
Telemetry telemetry.TelemetryService
|
||||||
|
|||||||
+23
-23
@@ -21,13 +21,13 @@ type WebsocketClient interface {
|
|||||||
|
|
||||||
type AddSubscriberParams struct {
|
type AddSubscriberParams struct {
|
||||||
AllTracks bool
|
AllTracks bool
|
||||||
TrackSids []string
|
TrackIDs []livekit.TrackID
|
||||||
}
|
}
|
||||||
|
|
||||||
//counterfeiter:generate . Participant
|
//counterfeiter:generate . Participant
|
||||||
type Participant interface {
|
type Participant interface {
|
||||||
ID() string
|
ID() livekit.ParticipantID
|
||||||
Identity() string
|
Identity() livekit.ParticipantIdentity
|
||||||
State() livekit.ParticipantInfo_State
|
State() livekit.ParticipantInfo_State
|
||||||
ProtocolVersion() ProtocolVersion
|
ProtocolVersion() ProtocolVersion
|
||||||
IsReady() bool
|
IsReady() bool
|
||||||
@@ -42,27 +42,27 @@ type Participant interface {
|
|||||||
ICERestart() error
|
ICERestart() error
|
||||||
|
|
||||||
AddTrack(req *livekit.AddTrackRequest)
|
AddTrack(req *livekit.AddTrackRequest)
|
||||||
GetPublishedTrack(sid string) PublishedTrack
|
GetPublishedTrack(sid livekit.TrackID) PublishedTrack
|
||||||
GetPublishedTracks() []PublishedTrack
|
GetPublishedTracks() []PublishedTrack
|
||||||
GetSubscribedTrack(sid string) SubscribedTrack
|
GetSubscribedTrack(sid livekit.TrackID) SubscribedTrack
|
||||||
GetSubscribedTracks() []SubscribedTrack
|
GetSubscribedTracks() []SubscribedTrack
|
||||||
HandleOffer(sdp webrtc.SessionDescription) (answer webrtc.SessionDescription, err error)
|
HandleOffer(sdp webrtc.SessionDescription) (answer webrtc.SessionDescription, err error)
|
||||||
HandleAnswer(sdp webrtc.SessionDescription) error
|
HandleAnswer(sdp webrtc.SessionDescription) error
|
||||||
AddICECandidate(candidate webrtc.ICECandidateInit, target livekit.SignalTarget) error
|
AddICECandidate(candidate webrtc.ICECandidateInit, target livekit.SignalTarget) error
|
||||||
AddSubscriber(op Participant, params AddSubscriberParams) (int, error)
|
AddSubscriber(op Participant, params AddSubscriberParams) (int, error)
|
||||||
RemoveSubscriber(op Participant, trackSid string)
|
RemoveSubscriber(op Participant, trackID livekit.TrackID)
|
||||||
SendJoinResponse(info *livekit.Room, otherParticipants []*livekit.ParticipantInfo, iceServers []*livekit.ICEServer) error
|
SendJoinResponse(info *livekit.Room, otherParticipants []*livekit.ParticipantInfo, iceServers []*livekit.ICEServer) error
|
||||||
SendParticipantUpdate(participants []*livekit.ParticipantInfo, updatedAt time.Time) error
|
SendParticipantUpdate(participants []*livekit.ParticipantInfo, updatedAt time.Time) error
|
||||||
SendSpeakerUpdate(speakers []*livekit.SpeakerInfo) error
|
SendSpeakerUpdate(speakers []*livekit.SpeakerInfo) error
|
||||||
SendDataPacket(packet *livekit.DataPacket) error
|
SendDataPacket(packet *livekit.DataPacket) error
|
||||||
SendRoomUpdate(room *livekit.Room) error
|
SendRoomUpdate(room *livekit.Room) error
|
||||||
SendConnectionQualityUpdate(update *livekit.ConnectionQualityUpdate) error
|
SendConnectionQualityUpdate(update *livekit.ConnectionQualityUpdate) error
|
||||||
SetTrackMuted(trackId string, muted bool, fromAdmin bool)
|
SetTrackMuted(trackID livekit.TrackID, muted bool, fromAdmin bool)
|
||||||
GetAudioLevel() (level uint8, active bool)
|
GetAudioLevel() (level uint8, active bool)
|
||||||
GetConnectionQuality() *livekit.ConnectionQualityInfo
|
GetConnectionQuality() *livekit.ConnectionQualityInfo
|
||||||
IsSubscribedTo(participantSid string) bool
|
IsSubscribedTo(participantID livekit.ParticipantID) bool
|
||||||
// returns list of participant identities that the current participant is subscribed to
|
// returns list of participant identities that the current participant is subscribed to
|
||||||
GetSubscribedParticipants() []string
|
GetSubscribedParticipants() []livekit.ParticipantID
|
||||||
|
|
||||||
// permissions
|
// permissions
|
||||||
CanPublish() bool
|
CanPublish() bool
|
||||||
@@ -83,15 +83,15 @@ type Participant interface {
|
|||||||
OnTrackUpdated(callback func(Participant, PublishedTrack))
|
OnTrackUpdated(callback func(Participant, PublishedTrack))
|
||||||
OnMetadataUpdate(callback func(Participant))
|
OnMetadataUpdate(callback func(Participant))
|
||||||
OnDataPacket(callback func(Participant, *livekit.DataPacket))
|
OnDataPacket(callback func(Participant, *livekit.DataPacket))
|
||||||
OnClose(func(Participant, map[string]string))
|
OnClose(func(Participant, map[livekit.TrackID]livekit.ParticipantID))
|
||||||
|
|
||||||
// package methods
|
// package methods
|
||||||
AddSubscribedTrack(st SubscribedTrack)
|
AddSubscribedTrack(st SubscribedTrack)
|
||||||
RemoveSubscribedTrack(st SubscribedTrack)
|
RemoveSubscribedTrack(st SubscribedTrack)
|
||||||
SubscriberPC() *webrtc.PeerConnection
|
SubscriberPC() *webrtc.PeerConnection
|
||||||
|
|
||||||
UpdateSubscriptionPermissions(permissions *livekit.UpdateSubscriptionPermissions, resolver func(participantSid string) Participant) error
|
UpdateSubscriptionPermissions(permissions *livekit.UpdateSubscriptionPermissions, resolver func(participantID livekit.ParticipantID) Participant) error
|
||||||
SubscriptionPermissionUpdate(publisherSid string, trackSid string, allowed bool)
|
SubscriptionPermissionUpdate(publisherID livekit.ParticipantID, trackID livekit.TrackID, allowed bool)
|
||||||
|
|
||||||
DebugInfo() map[string]interface{}
|
DebugInfo() map[string]interface{}
|
||||||
}
|
}
|
||||||
@@ -99,15 +99,15 @@ type Participant interface {
|
|||||||
// Room is a container of participants, and can provide room level actions
|
// Room is a container of participants, and can provide room level actions
|
||||||
//counterfeiter:generate . Room
|
//counterfeiter:generate . Room
|
||||||
type Room interface {
|
type Room interface {
|
||||||
Name() string
|
Name() livekit.RoomName
|
||||||
UpdateSubscriptions(participant Participant, trackIDs []string, participantTracks []*livekit.ParticipantTracks, subscribe bool) error
|
UpdateSubscriptions(participant Participant, trackIDs []livekit.TrackID, participantTracks []*livekit.ParticipantTracks, subscribe bool) error
|
||||||
UpdateSubscriptionPermissions(participant Participant, permissions *livekit.UpdateSubscriptionPermissions) error
|
UpdateSubscriptionPermissions(participant Participant, permissions *livekit.UpdateSubscriptionPermissions) error
|
||||||
}
|
}
|
||||||
|
|
||||||
// MediaTrack represents a media track
|
// MediaTrack represents a media track
|
||||||
//counterfeiter:generate . MediaTrack
|
//counterfeiter:generate . MediaTrack
|
||||||
type MediaTrack interface {
|
type MediaTrack interface {
|
||||||
ID() string
|
ID() livekit.TrackID
|
||||||
Kind() livekit.TrackType
|
Kind() livekit.TrackType
|
||||||
Name() string
|
Name() string
|
||||||
IsMuted() bool
|
IsMuted() bool
|
||||||
@@ -118,16 +118,16 @@ type MediaTrack interface {
|
|||||||
|
|
||||||
// subscribers
|
// subscribers
|
||||||
AddSubscriber(participant Participant) error
|
AddSubscriber(participant Participant) error
|
||||||
RemoveSubscriber(participantId string)
|
RemoveSubscriber(participantID livekit.ParticipantID)
|
||||||
IsSubscriber(subId string) bool
|
IsSubscriber(subID livekit.ParticipantID) bool
|
||||||
RemoveAllSubscribers()
|
RemoveAllSubscribers()
|
||||||
RevokeDisallowedSubscribers(allowedSubscriberIDs []string) []string
|
RevokeDisallowedSubscribers(allowedSubscriberIDs []livekit.ParticipantID) []livekit.ParticipantID
|
||||||
|
|
||||||
// returns quality information that's appropriate for width & height
|
// returns quality information that's appropriate for width & height
|
||||||
GetQualityForDimension(width, height uint32) livekit.VideoQuality
|
GetQualityForDimension(width, height uint32) livekit.VideoQuality
|
||||||
|
|
||||||
NotifySubscriberMute(subscriberID string)
|
NotifySubscriberMute(subscriberID livekit.ParticipantID)
|
||||||
NotifySubscriberMaxQuality(subscriberID string, quality livekit.VideoQuality)
|
NotifySubscriberMaxQuality(subscriberID livekit.ParticipantID, quality livekit.VideoQuality)
|
||||||
}
|
}
|
||||||
|
|
||||||
// PublishedTrack is the main interface representing a track published to the room
|
// PublishedTrack is the main interface representing a track published to the room
|
||||||
@@ -153,9 +153,9 @@ type PublishedTrack interface {
|
|||||||
//counterfeiter:generate . SubscribedTrack
|
//counterfeiter:generate . SubscribedTrack
|
||||||
type SubscribedTrack interface {
|
type SubscribedTrack interface {
|
||||||
OnBind(f func())
|
OnBind(f func())
|
||||||
ID() string
|
ID() livekit.TrackID
|
||||||
PublisherID() string
|
PublisherID() livekit.ParticipantID
|
||||||
PublisherIdentity() string
|
PublisherIdentity() livekit.ParticipantIdentity
|
||||||
DownTrack() *sfu.DownTrack
|
DownTrack() *sfu.DownTrack
|
||||||
MediaTrack() MediaTrack
|
MediaTrack() MediaTrack
|
||||||
IsMuted() bool
|
IsMuted() bool
|
||||||
|
|||||||
@@ -149,7 +149,7 @@ func (u *UptrackManager) AddSubscriber(sub types.Participant, params types.AddSu
|
|||||||
if params.AllTracks {
|
if params.AllTracks {
|
||||||
tracks = u.GetPublishedTracks()
|
tracks = u.GetPublishedTracks()
|
||||||
} else {
|
} else {
|
||||||
for _, trackID := range params.TrackSids {
|
for _, trackID := range params.TrackIDs {
|
||||||
track := u.getPublishedTrack(trackID)
|
track := u.getPublishedTrack(trackID)
|
||||||
if track == nil {
|
if track == nil {
|
||||||
continue
|
continue
|
||||||
|
|||||||
+10
-10
@@ -18,7 +18,7 @@ const (
|
|||||||
trackIdSeparator = "|"
|
trackIdSeparator = "|"
|
||||||
)
|
)
|
||||||
|
|
||||||
func UnpackStreamID(packed string) (participantId string, trackId string) {
|
func UnpackStreamID(packed string) (participantID livekit.ParticipantID, trackID livekit.TrackID) {
|
||||||
parts := strings.Split(packed, trackIdSeparator)
|
parts := strings.Split(packed, trackIdSeparator)
|
||||||
if len(parts) > 1 {
|
if len(parts) > 1 {
|
||||||
return parts[0], packed[len(parts[0])+1:]
|
return parts[0], packed[len(parts[0])+1:]
|
||||||
@@ -26,21 +26,21 @@ func UnpackStreamID(packed string) (participantId string, trackId string) {
|
|||||||
return packed, ""
|
return packed, ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func PackStreamID(participantId, trackId string) string {
|
func PackStreamID(participantID livekit.ParticipantID, trackID livekit.TrackID) string {
|
||||||
return participantId + trackIdSeparator + trackId
|
return participantID + trackIdSeparator + trackID
|
||||||
}
|
}
|
||||||
|
|
||||||
func PackDataTrackLabel(participantId, trackId string, label string) string {
|
func PackDataTrackLabel(participantID livekit.ParticipantID, trackID livekit.TrackID, label string) string {
|
||||||
return participantId + trackIdSeparator + trackId + trackIdSeparator + label
|
return participantID + trackIdSeparator + trackID + trackIdSeparator + label
|
||||||
}
|
}
|
||||||
|
|
||||||
func UnpackDataTrackLabel(packed string) (peerId string, trackId string, label string) {
|
func UnpackDataTrackLabel(packed string) (peerID livekit.ParticipantID, trackID livekit.TrackID, label string) {
|
||||||
parts := strings.Split(packed, trackIdSeparator)
|
parts := strings.Split(packed, trackIdSeparator)
|
||||||
if len(parts) != 3 {
|
if len(parts) != 3 {
|
||||||
return "", packed, ""
|
return "", packed, ""
|
||||||
}
|
}
|
||||||
peerId = parts[0]
|
peerID = parts[0]
|
||||||
trackId = parts[1]
|
trackID = parts[1]
|
||||||
label = parts[2]
|
label = parts[2]
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -133,7 +133,7 @@ func Recover() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// logger helpers
|
// logger helpers
|
||||||
func LoggerWithParticipant(l logger.Logger, identity, sid string) logger.Logger {
|
func LoggerWithParticipant(l logger.Logger, identity livekit.ParticipantIdentity, sid livekit.ParticipantID) logger.Logger {
|
||||||
lr := logr.Logger(l)
|
lr := logr.Logger(l)
|
||||||
if identity != "" {
|
if identity != "" {
|
||||||
lr = lr.WithValues("participant", identity)
|
lr = lr.WithValues("participant", identity)
|
||||||
@@ -144,7 +144,7 @@ func LoggerWithParticipant(l logger.Logger, identity, sid string) logger.Logger
|
|||||||
return logger.Logger(lr)
|
return logger.Logger(lr)
|
||||||
}
|
}
|
||||||
|
|
||||||
func LoggerWithRoom(l logger.Logger, name string) logger.Logger {
|
func LoggerWithRoom(l logger.Logger, name livekit.RoomName) logger.Logger {
|
||||||
lr := logr.Logger(l)
|
lr := logr.Logger(l)
|
||||||
return logger.Logger(
|
return logger.Logger(
|
||||||
lr.WithValues(
|
lr.WithValues(
|
||||||
|
|||||||
@@ -8,22 +8,22 @@ import (
|
|||||||
|
|
||||||
func TestPackStreamId(t *testing.T) {
|
func TestPackStreamId(t *testing.T) {
|
||||||
packed := "PA_123abc|uuid-id"
|
packed := "PA_123abc|uuid-id"
|
||||||
pId, trackId := UnpackStreamID(packed)
|
pID, trackID := UnpackStreamID(packed)
|
||||||
require.Equal(t, "PA_123abc", pId)
|
require.Equal(t, "PA_123abc", pID)
|
||||||
require.Equal(t, "uuid-id", trackId)
|
require.Equal(t, "uuid-id", trackID)
|
||||||
|
|
||||||
require.Equal(t, packed, PackStreamID(pId, trackId))
|
require.Equal(t, packed, PackStreamID(pID, trackID))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPackDataTrackLabel(t *testing.T) {
|
func TestPackDataTrackLabel(t *testing.T) {
|
||||||
pId := "PA_123abc"
|
pID := "PA_123abc"
|
||||||
trackId := "TR_b3da25"
|
trackID := "TR_b3da25"
|
||||||
label := "trackLabel"
|
label := "trackLabel"
|
||||||
packed := "PA_123abc|TR_b3da25|trackLabel"
|
packed := "PA_123abc|TR_b3da25|trackLabel"
|
||||||
require.Equal(t, packed, PackDataTrackLabel(pId, trackId, label))
|
require.Equal(t, packed, PackDataTrackLabel(pID, trackID, label))
|
||||||
|
|
||||||
p, tr, l := UnpackDataTrackLabel(packed)
|
p, tr, l := UnpackDataTrackLabel(packed)
|
||||||
require.Equal(t, pId, p)
|
require.Equal(t, pID, p)
|
||||||
require.Equal(t, trackId, tr)
|
require.Equal(t, trackID, tr)
|
||||||
require.Equal(t, label, l)
|
require.Equal(t, label, l)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,26 +2,27 @@ package rtc
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/livekit/livekit-server/pkg/sfu"
|
"github.com/livekit/livekit-server/pkg/sfu"
|
||||||
|
"github.com/livekit/protocol/livekit"
|
||||||
)
|
)
|
||||||
|
|
||||||
// wrapper around WebRTC receiver, overriding its ID
|
// wrapper around WebRTC receiver, overriding its ID
|
||||||
|
|
||||||
type WrappedReceiver struct {
|
type WrappedReceiver struct {
|
||||||
sfu.TrackReceiver
|
sfu.TrackReceiver
|
||||||
trackId string
|
trackID livekit.TrackID
|
||||||
streamId string
|
streamId string
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewWrappedReceiver(receiver sfu.TrackReceiver, trackId string, streamId string) WrappedReceiver {
|
func NewWrappedReceiver(receiver sfu.TrackReceiver, trackID livekit.TrackID, streamId string) WrappedReceiver {
|
||||||
return WrappedReceiver{
|
return WrappedReceiver{
|
||||||
TrackReceiver: receiver,
|
TrackReceiver: receiver,
|
||||||
trackId: trackId,
|
trackID: trackID,
|
||||||
streamId: streamId,
|
streamId: streamId,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r WrappedReceiver) TrackID() string {
|
func (r WrappedReceiver) TrackID() livekit.TrackID {
|
||||||
return r.trackId
|
return r.trackID
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r WrappedReceiver) StreamID() string {
|
func (r WrappedReceiver) StreamID() string {
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ type RoomManager struct {
|
|||||||
roomStore RoomStore
|
roomStore RoomStore
|
||||||
telemetry telemetry.TelemetryService
|
telemetry telemetry.TelemetryService
|
||||||
|
|
||||||
rooms map[string]*rtc.Room
|
rooms map[livekit.RoomName]*rtc.Room
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewLocalRoomManager(
|
func NewLocalRoomManager(
|
||||||
@@ -57,7 +57,7 @@ func NewLocalRoomManager(
|
|||||||
roomStore: roomStore,
|
roomStore: roomStore,
|
||||||
telemetry: telemetry,
|
telemetry: telemetry,
|
||||||
|
|
||||||
rooms: make(map[string]*rtc.Room),
|
rooms: make(map[livekit.RoomName]*rtc.Room),
|
||||||
}
|
}
|
||||||
|
|
||||||
// hook up to router
|
// hook up to router
|
||||||
@@ -66,14 +66,14 @@ func NewLocalRoomManager(
|
|||||||
return r, nil
|
return r, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *RoomManager) GetRoom(_ context.Context, roomName string) *rtc.Room {
|
func (r *RoomManager) GetRoom(_ context.Context, roomName livekit.RoomName) *rtc.Room {
|
||||||
r.lock.RLock()
|
r.lock.RLock()
|
||||||
defer r.lock.RUnlock()
|
defer r.lock.RUnlock()
|
||||||
return r.rooms[roomName]
|
return r.rooms[roomName]
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeleteRoom completely deletes all room information, including active sessions, room store, and routing info
|
// DeleteRoom completely deletes all room information, including active sessions, room store, and routing info
|
||||||
func (r *RoomManager) DeleteRoom(ctx context.Context, roomName string) error {
|
func (r *RoomManager) DeleteRoom(ctx context.Context, roomName livekit.RoomName) error {
|
||||||
logger.Infow("deleting room state", "room", roomName)
|
logger.Infow("deleting room state", "room", roomName)
|
||||||
r.lock.Lock()
|
r.lock.Lock()
|
||||||
delete(r.rooms, roomName)
|
delete(r.rooms, roomName)
|
||||||
@@ -173,7 +173,7 @@ func (r *RoomManager) Stop() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// StartSession starts WebRTC session when a new participant is connected, takes place on RTC node
|
// StartSession starts WebRTC session when a new participant is connected, takes place on RTC node
|
||||||
func (r *RoomManager) StartSession(ctx context.Context, roomName string, pi routing.ParticipantInit, requestSource routing.MessageSource, responseSink routing.MessageSink) {
|
func (r *RoomManager) StartSession(ctx context.Context, roomName livekit.RoomName, pi routing.ParticipantInit, requestSource routing.MessageSource, responseSink routing.MessageSink) {
|
||||||
room, err := r.getOrCreateRoom(ctx, roomName)
|
room, err := r.getOrCreateRoom(ctx, roomName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Errorw("could not create room", err, "room", roomName)
|
logger.Errorw("could not create room", err, "room", roomName)
|
||||||
@@ -275,7 +275,7 @@ func (r *RoomManager) StartSession(ctx context.Context, roomName string, pi rout
|
|||||||
}
|
}
|
||||||
|
|
||||||
r.telemetry.ParticipantJoined(ctx, room.Room, participant.ToProto(), pi.Client)
|
r.telemetry.ParticipantJoined(ctx, room.Room, participant.ToProto(), pi.Client)
|
||||||
participant.OnClose(func(p types.Participant, disallowedSubscriptions map[string]string) {
|
participant.OnClose(func(p types.Participant, disallowedSubscriptions map[livekit.TrackID]livekit.ParticipantID) {
|
||||||
if err := r.roomStore.DeleteParticipant(ctx, roomName, p.Identity()); err != nil {
|
if err := r.roomStore.DeleteParticipant(ctx, roomName, p.Identity()); err != nil {
|
||||||
pLogger.Errorw("could not delete participant", err)
|
pLogger.Errorw("could not delete participant", err)
|
||||||
}
|
}
|
||||||
@@ -295,7 +295,7 @@ func (r *RoomManager) StartSession(ctx context.Context, roomName string, pi rout
|
|||||||
}
|
}
|
||||||
|
|
||||||
// create the actual room object, to be used on RTC node
|
// create the actual room object, to be used on RTC node
|
||||||
func (r *RoomManager) getOrCreateRoom(ctx context.Context, roomName string) (*rtc.Room, error) {
|
func (r *RoomManager) getOrCreateRoom(ctx context.Context, roomName livekit.RoomName) (*rtc.Room, error) {
|
||||||
r.lock.RLock()
|
r.lock.RLock()
|
||||||
room := r.rooms[roomName]
|
room := r.rooms[roomName]
|
||||||
r.lock.RUnlock()
|
r.lock.RUnlock()
|
||||||
@@ -384,7 +384,7 @@ func (r *RoomManager) rtcSessionWorker(room *rtc.Room, participant types.Partici
|
|||||||
}
|
}
|
||||||
|
|
||||||
// handles RTC messages resulted from Room API calls
|
// handles RTC messages resulted from Room API calls
|
||||||
func (r *RoomManager) handleRTCMessage(_ context.Context, roomName, identity string, msg *livekit.RTCNodeMessage) {
|
func (r *RoomManager) handleRTCMessage(_ context.Context, roomName, identity livekit.ParticipantIdentity, msg *livekit.RTCNodeMessage) {
|
||||||
r.lock.RLock()
|
r.lock.RLock()
|
||||||
room := r.rooms[roomName]
|
room := r.rooms[roomName]
|
||||||
r.lock.RUnlock()
|
r.lock.RUnlock()
|
||||||
@@ -418,7 +418,7 @@ func (r *RoomManager) handleRTCMessage(_ context.Context, roomName, identity str
|
|||||||
pLogger.Errorw("cannot unmute track, remote unmute is disabled", nil)
|
pLogger.Errorw("cannot unmute track, remote unmute is disabled", nil)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
participant.SetTrackMuted(rm.MuteTrack.TrackSid, rm.MuteTrack.Muted, true)
|
participant.SetTrackMuted(livekit.TrackID(rm.MuteTrack.TrackSid), rm.MuteTrack.Muted, true)
|
||||||
case *livekit.RTCNodeMessage_UpdateParticipant:
|
case *livekit.RTCNodeMessage_UpdateParticipant:
|
||||||
if participant == nil {
|
if participant == nil {
|
||||||
return
|
return
|
||||||
|
|||||||
Reference in New Issue
Block a user