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"
|
||||
)
|
||||
|
||||
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.IDReturns(utils.NewGuid(utils.ParticipantPrefix))
|
||||
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()
|
||||
}
|
||||
p.AddTrackStub = func(req *livekit.AddTrackRequest) {
|
||||
|
||||
+18
-19
@@ -52,7 +52,7 @@ type MediaTrack struct {
|
||||
|
||||
lock sync.RWMutex
|
||||
|
||||
// map of target participantId -> types.SubscribedTrack
|
||||
// map of target participantID -> types.SubscribedTrack
|
||||
subscribedTracks sync.Map // participantSid => types.SubscribedTrack
|
||||
twcc *twcc.Responder
|
||||
audioLevel *AudioLevel
|
||||
@@ -73,10 +73,10 @@ type MediaTrack struct {
|
||||
|
||||
// quality level enable/disable
|
||||
maxQualityLock sync.Mutex
|
||||
maxSubscriberQuality map[string]livekit.VideoQuality
|
||||
maxSubscriberQuality map[livekit.ParticipantID]livekit.VideoQuality
|
||||
maxSubscribedQuality livekit.VideoQuality
|
||||
allSubscribersMuted bool
|
||||
onSubscribedMaxQualityChange func(trackSid string, subscribedQualities []*livekit.SubscribedQuality) error
|
||||
onSubscribedMaxQualityChange func(trackID livekit.TrackID, subscribedQualities []*livekit.SubscribedQuality) error
|
||||
|
||||
onClose []func()
|
||||
}
|
||||
@@ -85,8 +85,8 @@ type MediaTrackParams struct {
|
||||
TrackInfo *livekit.TrackInfo
|
||||
SignalCid string
|
||||
SdpCid string
|
||||
ParticipantID string
|
||||
ParticipantIdentity string
|
||||
ParticipantID livekit.ParticipantID
|
||||
ParticipantIdentity livekit.ParticipantIdentity
|
||||
// channel to send RTCP packets to the source
|
||||
RTCPChan chan []rtcp.Packet
|
||||
BufferFactory *buffer.Factory
|
||||
@@ -104,7 +104,7 @@ func NewMediaTrack(track *webrtc.TrackRemote, params MediaTrackParams) *MediaTra
|
||||
codec: track.Codec(),
|
||||
connectionStats: connectionquality.NewConnectionStats(),
|
||||
done: make(chan struct{}),
|
||||
maxSubscriberQuality: make(map[string]livekit.VideoQuality),
|
||||
maxSubscriberQuality: make(map[livekit.ParticipantID]livekit.VideoQuality),
|
||||
}
|
||||
|
||||
if params.TrackInfo.Muted {
|
||||
@@ -122,7 +122,7 @@ func NewMediaTrack(track *webrtc.TrackRemote, params MediaTrackParams) *MediaTra
|
||||
return t
|
||||
}
|
||||
|
||||
func (t *MediaTrack) ID() string {
|
||||
func (t *MediaTrack) ID() livekit.TrackID {
|
||||
return t.params.TrackInfo.Sid
|
||||
}
|
||||
|
||||
@@ -184,8 +184,8 @@ func (t *MediaTrack) AddOnClose(f func()) {
|
||||
t.onClose = append(t.onClose, f)
|
||||
}
|
||||
|
||||
func (t *MediaTrack) IsSubscriber(subId string) bool {
|
||||
_, ok := t.subscribedTracks.Load(subId)
|
||||
func (t *MediaTrack) IsSubscriber(subID livekit.ParticipantID) bool {
|
||||
_, ok := t.subscribedTracks.Load(subID)
|
||||
return ok
|
||||
}
|
||||
|
||||
@@ -453,8 +453,8 @@ func (t *MediaTrack) AddReceiver(receiver *webrtc.RTPReceiver, track *webrtc.Tra
|
||||
|
||||
// RemoveSubscriber removes participant from subscription
|
||||
// stop all forwarders to the client
|
||||
func (t *MediaTrack) RemoveSubscriber(participantId string) {
|
||||
subTrack := t.getSubscribedTrack(participantId)
|
||||
func (t *MediaTrack) RemoveSubscriber(participantID livekit.ParticipantID) {
|
||||
subTrack := t.getSubscribedTrack(participantID)
|
||||
if subTrack != nil {
|
||||
go subTrack.DownTrack().Close()
|
||||
}
|
||||
@@ -473,11 +473,11 @@ func (t *MediaTrack) RemoveAllSubscribers() {
|
||||
t.subscribedTracks = sync.Map{}
|
||||
}
|
||||
|
||||
func (t *MediaTrack) RevokeDisallowedSubscribers(allowedSubscriberIDs []string) []string {
|
||||
func (t *MediaTrack) RevokeDisallowedSubscribers(allowedSubscriberIDs []livekit.ParticipantID) []livekit.ParticipantID {
|
||||
t.lock.Lock()
|
||||
defer t.lock.Unlock()
|
||||
|
||||
var revokedSubscriberIDs []string
|
||||
var revokedSubscriberIDs []livekit.ParticipantID
|
||||
// LK-TODO: large number of subscribers needs to be solved for this loop
|
||||
t.subscribedTracks.Range(func(key interface{}, val interface{}) bool {
|
||||
if subID, ok := key.(string); ok {
|
||||
@@ -576,7 +576,7 @@ func (t *MediaTrack) GetQualityForDimension(width, height uint32) livekit.VideoQ
|
||||
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 st, ok := val.(types.SubscribedTrack); ok {
|
||||
return st
|
||||
@@ -690,8 +690,7 @@ func (t *MediaTrack) handlePublisherFeedback(packets []rtcp.Packet) {
|
||||
}
|
||||
|
||||
// handles max loss for audio packets
|
||||
func (t *MediaTrack) handleMaxLossFeedback(_ *sfu.DownTrack,
|
||||
report *rtcp.ReceiverReport) {
|
||||
func (t *MediaTrack) handleMaxLossFeedback(_ *sfu.DownTrack, report *rtcp.ReceiverReport) {
|
||||
var (
|
||||
shouldUpdate bool
|
||||
maxLost uint8
|
||||
@@ -788,11 +787,11 @@ func (t *MediaTrack) calculateVideoScore() {
|
||||
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
|
||||
}
|
||||
|
||||
func (t *MediaTrack) NotifySubscriberMute(subscriberID string) {
|
||||
func (t *MediaTrack) NotifySubscriberMute(subscriberID livekit.ParticipantID) {
|
||||
if !t.IsSimulcast() {
|
||||
return
|
||||
}
|
||||
@@ -810,7 +809,7 @@ func (t *MediaTrack) NotifySubscriberMute(subscriberID string) {
|
||||
t.updateQualityChange()
|
||||
}
|
||||
|
||||
func (t *MediaTrack) NotifySubscriberMaxQuality(subscriberID string, quality livekit.VideoQuality) {
|
||||
func (t *MediaTrack) NotifySubscriberMaxQuality(subscriberID livekit.ParticipantID, quality livekit.VideoQuality) {
|
||||
if !t.IsSimulcast() {
|
||||
return
|
||||
}
|
||||
|
||||
+12
-12
@@ -129,10 +129,10 @@ func TestSubscribedMaxQuality(t *testing.T) {
|
||||
|
||||
mt.NotifySubscriberMaxQuality("s1", livekit.VideoQuality_HIGH)
|
||||
|
||||
actualTrackSid := ""
|
||||
actualTrackID := ""
|
||||
actualSubscribedQualities := []*livekit.SubscribedQuality{}
|
||||
mt.OnSubscribedMaxQualityChange(func(trackSid string, subscribedQualities []*livekit.SubscribedQuality) error {
|
||||
actualTrackSid = trackSid
|
||||
mt.OnSubscribedMaxQualityChange(func(trackID livekit.TrackID, subscribedQualities []*livekit.SubscribedQuality) error {
|
||||
actualTrackID = trackID
|
||||
actualSubscribedQualities = subscribedQualities
|
||||
return nil
|
||||
})
|
||||
@@ -145,7 +145,7 @@ func TestSubscribedMaxQuality(t *testing.T) {
|
||||
&livekit.SubscribedQuality{Quality: livekit.VideoQuality_MEDIUM, 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)
|
||||
})
|
||||
|
||||
@@ -175,10 +175,10 @@ func TestSubscribedMaxQuality(t *testing.T) {
|
||||
}})
|
||||
mt.simulcasted.TrySet(true)
|
||||
|
||||
actualTrackSid := ""
|
||||
actualTrackID := ""
|
||||
actualSubscribedQualities := []*livekit.SubscribedQuality{}
|
||||
mt.OnSubscribedMaxQualityChange(func(trackSid string, subscribedQualities []*livekit.SubscribedQuality) error {
|
||||
actualTrackSid = trackSid
|
||||
mt.OnSubscribedMaxQualityChange(func(trackID livekit.TrackID, subscribedQualities []*livekit.SubscribedQuality) error {
|
||||
actualTrackID = trackID
|
||||
actualSubscribedQualities = subscribedQualities
|
||||
return nil
|
||||
})
|
||||
@@ -191,7 +191,7 @@ func TestSubscribedMaxQuality(t *testing.T) {
|
||||
&livekit.SubscribedQuality{Quality: livekit.VideoQuality_MEDIUM, 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)
|
||||
|
||||
// "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_HIGH, Enabled: false},
|
||||
}
|
||||
require.Equal(t, "v1", actualTrackSid)
|
||||
require.Equal(t, "v1", actualTrackID)
|
||||
require.EqualValues(t, expectedSubscribedQualities, actualSubscribedQualities)
|
||||
|
||||
// "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_HIGH, Enabled: false},
|
||||
}
|
||||
require.Equal(t, "v1", actualTrackSid)
|
||||
require.Equal(t, "v1", actualTrackID)
|
||||
require.EqualValues(t, expectedSubscribedQualities, actualSubscribedQualities)
|
||||
|
||||
// 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_HIGH, Enabled: false},
|
||||
}
|
||||
require.Equal(t, "v1", actualTrackSid)
|
||||
require.Equal(t, "v1", actualTrackID)
|
||||
require.EqualValues(t, expectedSubscribedQualities, actualSubscribedQualities)
|
||||
|
||||
// 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_HIGH, Enabled: false},
|
||||
}
|
||||
require.Equal(t, "v1", actualTrackSid)
|
||||
require.Equal(t, "v1", actualTrackID)
|
||||
require.EqualValues(t, expectedSubscribedQualities, actualSubscribedQualities)
|
||||
})
|
||||
}
|
||||
|
||||
+37
-37
@@ -36,9 +36,9 @@ const (
|
||||
)
|
||||
|
||||
type ParticipantParams struct {
|
||||
Identity string
|
||||
Name string
|
||||
SID string
|
||||
Identity livekit.ParticipantIdentity
|
||||
Name livekit.ParticipantName
|
||||
SID livekit.ParticipantID
|
||||
Config *WebRTCConfig
|
||||
Sink routing.MessageSink
|
||||
AudioConfig config.AudioConfig
|
||||
@@ -78,11 +78,11 @@ type ParticipantImpl struct {
|
||||
uptrackManager *UptrackManager
|
||||
|
||||
// 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
|
||||
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
|
||||
subscribedTo sync.Map // string => struct{}
|
||||
subscribedTo sync.Map // livekit.ParticipantID => struct{}
|
||||
|
||||
lock sync.RWMutex
|
||||
once sync.Once
|
||||
@@ -94,7 +94,7 @@ type ParticipantImpl struct {
|
||||
onStateChange func(p types.Participant, oldState livekit.ParticipantInfo_State)
|
||||
onMetadataUpdate func(types.Participant)
|
||||
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) {
|
||||
@@ -102,8 +102,8 @@ func NewParticipant(params ParticipantParams) (*ParticipantImpl, error) {
|
||||
|
||||
p := &ParticipantImpl{
|
||||
params: params,
|
||||
subscribedTracks: make(map[string]types.SubscribedTrack),
|
||||
disallowedSubscriptions: make(map[string]string),
|
||||
subscribedTracks: make(map[livekit.TrackID]types.SubscribedTrack),
|
||||
disallowedSubscriptions: make(map[livekit.TrackID]livekit.ParticipantID),
|
||||
connectedAt: time.Now(),
|
||||
}
|
||||
p.state.Store(livekit.ParticipantInfo_JOINING)
|
||||
@@ -185,11 +185,11 @@ func NewParticipant(params ParticipantParams) (*ParticipantImpl, error) {
|
||||
return p, nil
|
||||
}
|
||||
|
||||
func (p *ParticipantImpl) ID() string {
|
||||
func (p *ParticipantImpl) ID() livekit.ParticipantID {
|
||||
return p.params.SID
|
||||
}
|
||||
|
||||
func (p *ParticipantImpl) Identity() string {
|
||||
func (p *ParticipantImpl) Identity() livekit.ParticipantIdentity {
|
||||
return p.params.Identity
|
||||
}
|
||||
|
||||
@@ -273,7 +273,7 @@ func (p *ParticipantImpl) OnDataPacket(callback func(types.Participant, *livekit
|
||||
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
|
||||
}
|
||||
|
||||
@@ -399,9 +399,9 @@ func (p *ParticipantImpl) Close() error {
|
||||
p.uptrackManager.Close()
|
||||
|
||||
p.lock.Lock()
|
||||
disallowedSubscriptions := make(map[string]string)
|
||||
for trackSid, publisherSid := range p.disallowedSubscriptions {
|
||||
disallowedSubscriptions[trackSid] = publisherSid
|
||||
disallowedSubscriptions := make(map[livekit.TrackID]livekit.ParticipantID)
|
||||
for trackID, publisherID := range p.disallowedSubscriptions {
|
||||
disallowedSubscriptions[trackID] = publisherID
|
||||
}
|
||||
|
||||
// remove all downtracks
|
||||
@@ -450,8 +450,8 @@ func (p *ParticipantImpl) AddSubscriber(op types.Participant, params types.AddSu
|
||||
return p.uptrackManager.AddSubscriber(op, params)
|
||||
}
|
||||
|
||||
func (p *ParticipantImpl) RemoveSubscriber(op types.Participant, trackSid string) {
|
||||
p.uptrackManager.RemoveSubscriber(op, trackSid)
|
||||
func (p *ParticipantImpl) RemoveSubscriber(op types.Participant, trackID livekit.TrackID) {
|
||||
p.uptrackManager.RemoveSubscriber(op, trackID)
|
||||
}
|
||||
|
||||
// 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
|
||||
if fromAdmin {
|
||||
_ = p.writeMessage(&livekit.SignalResponse{
|
||||
Message: &livekit.SignalResponse_Mute{
|
||||
Mute: &livekit.MuteTrackRequest{
|
||||
Sid: trackSid,
|
||||
Sid: trackID,
|
||||
Muted: muted,
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
p.uptrackManager.SetTrackMuted(trackSid, muted)
|
||||
p.uptrackManager.SetTrackMuted(trackID, muted)
|
||||
}
|
||||
|
||||
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 {
|
||||
_, ok := p.subscribedTo.Load(participantSid)
|
||||
func (p *ParticipantImpl) IsSubscribedTo(participantID livekit.ParticipantID) bool {
|
||||
_, ok := p.subscribedTo.Load(participantID)
|
||||
return ok
|
||||
}
|
||||
|
||||
func (p *ParticipantImpl) GetSubscribedParticipants() []string {
|
||||
var participantSids []string
|
||||
func (p *ParticipantImpl) GetSubscribedParticipants() []livekit.ParticipantID {
|
||||
var participantIDs []livekit.ParticipantID
|
||||
p.subscribedTo.Range(func(key, _ interface{}) bool {
|
||||
if participantSid, ok := key.(string); ok {
|
||||
participantSids = append(participantSids, participantSid)
|
||||
if participantID, ok := key.(livekit.ParticipantID); ok {
|
||||
participantIDs = append(participantIDs, participantID)
|
||||
}
|
||||
return true
|
||||
})
|
||||
return participantSids
|
||||
return participantIDs
|
||||
}
|
||||
|
||||
func (p *ParticipantImpl) CanPublish() bool {
|
||||
@@ -669,7 +669,7 @@ func (p *ParticipantImpl) SubscriberPC() *webrtc.PeerConnection {
|
||||
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)
|
||||
}
|
||||
|
||||
@@ -677,7 +677,7 @@ func (p *ParticipantImpl) GetPublishedTracks() []types.PublishedTrack {
|
||||
return p.uptrackManager.GetPublishedTracks()
|
||||
}
|
||||
|
||||
func (p *ParticipantImpl) GetSubscribedTrack(sid string) types.SubscribedTrack {
|
||||
func (p *ParticipantImpl) GetSubscribedTrack(sid livekit.TrackID) types.SubscribedTrack {
|
||||
p.lock.RLock()
|
||||
defer p.lock.RUnlock()
|
||||
return p.subscribedTracks[sid]
|
||||
@@ -735,25 +735,25 @@ func (p *ParticipantImpl) RemoveSubscribedTrack(subTrack types.SubscribedTrack)
|
||||
|
||||
func (p *ParticipantImpl) UpdateSubscriptionPermissions(
|
||||
permissions *livekit.UpdateSubscriptionPermissions,
|
||||
resolver func(participantSid string) types.Participant,
|
||||
resolver func(participantID livekit.ParticipantID) types.Participant,
|
||||
) error {
|
||||
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()
|
||||
if allowed {
|
||||
delete(p.disallowedSubscriptions, trackSid)
|
||||
delete(p.disallowedSubscriptions, trackID)
|
||||
} else {
|
||||
p.disallowedSubscriptions[trackSid] = publisherSid
|
||||
p.disallowedSubscriptions[trackID] = publisherID
|
||||
}
|
||||
p.lock.Unlock()
|
||||
|
||||
err := p.writeMessage(&livekit.SignalResponse{
|
||||
Message: &livekit.SignalResponse_SubscriptionPermissionUpdate{
|
||||
SubscriptionPermissionUpdate: &livekit.SubscriptionPermissionUpdate{
|
||||
ParticipantSid: publisherSid,
|
||||
TrackSid: trackSid,
|
||||
ParticipantSid: publisherID,
|
||||
TrackSid: trackID,
|
||||
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 {
|
||||
return nil
|
||||
}
|
||||
|
||||
subscribedQualityUpdate := &livekit.SubscribedQualityUpdate{
|
||||
TrackSid: trackSid,
|
||||
TrackSid: trackID,
|
||||
SubscribedQualities: subscribedQualities,
|
||||
}
|
||||
|
||||
|
||||
@@ -52,7 +52,7 @@ func TestICEStateChange(t *testing.T) {
|
||||
t.Run("onClose gets called when ICE disconnected", func(t *testing.T) {
|
||||
p := newParticipantForTest("test")
|
||||
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)
|
||||
}
|
||||
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)
|
||||
// disable mux, it doesn't play too well with unit test
|
||||
conf.RTC.UDPPort = 0
|
||||
|
||||
+36
-36
@@ -37,8 +37,8 @@ type Room struct {
|
||||
telemetry telemetry.TelemetryService
|
||||
|
||||
// map of identity -> Participant
|
||||
participants map[string]types.Participant
|
||||
participantOpts map[string]*ParticipantOptions
|
||||
participants map[livekit.ParticipantIdentity]types.Participant
|
||||
participantOpts map[livekit.ParticipantIdentity]*ParticipantOptions
|
||||
bufferFactory *buffer.Factory
|
||||
|
||||
// time the first participant joined the room
|
||||
@@ -64,8 +64,8 @@ func NewRoom(room *livekit.Room, config WebRTCConfig, audioConfig *config.AudioC
|
||||
config: config,
|
||||
audioConfig: audioConfig,
|
||||
telemetry: telemetry,
|
||||
participants: make(map[string]types.Participant),
|
||||
participantOpts: make(map[string]*ParticipantOptions),
|
||||
participants: make(map[livekit.ParticipantIdentity]types.Participant),
|
||||
participantOpts: make(map[livekit.ParticipantIdentity]*ParticipantOptions),
|
||||
bufferFactory: buffer.NewBufferFactory(config.Receiver.PacketBufferSize, logr.Logger{}),
|
||||
closed: make(chan struct{}),
|
||||
}
|
||||
@@ -82,17 +82,17 @@ func NewRoom(room *livekit.Room, config WebRTCConfig, audioConfig *config.AudioC
|
||||
return r
|
||||
}
|
||||
|
||||
func (r *Room) Name() string {
|
||||
func (r *Room) Name() livekit.RoomName {
|
||||
return r.Room.Name
|
||||
}
|
||||
|
||||
func (r *Room) GetParticipant(identity string) types.Participant {
|
||||
func (r *Room) GetParticipant(identity livekit.ParticipantIdentity) types.Participant {
|
||||
r.lock.RLock()
|
||||
defer r.lock.RUnlock()
|
||||
return r.participants[identity]
|
||||
}
|
||||
|
||||
func (r *Room) GetParticipantBySid(participantID string) types.Participant {
|
||||
func (r *Room) GetParticipantBySid(participantID livekit.ParticipantID) types.Participant {
|
||||
r.lock.RLock()
|
||||
defer r.lock.RUnlock()
|
||||
|
||||
@@ -278,7 +278,7 @@ func (r *Room) ResumeParticipant(p types.Participant, responseSink routing.Messa
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *Room) RemoveParticipant(identity string) {
|
||||
func (r *Room) RemoveParticipant(identity livekit.ParticipantIdentity) {
|
||||
r.lock.Lock()
|
||||
p, ok := r.participants[identity]
|
||||
if ok {
|
||||
@@ -337,18 +337,18 @@ func (r *Room) RemoveParticipant(identity string) {
|
||||
|
||||
func (r *Room) UpdateSubscriptions(
|
||||
participant types.Participant,
|
||||
trackIds []string,
|
||||
trackIDs []livekit.TrackID,
|
||||
participantTracks []*livekit.ParticipantTracks,
|
||||
subscribe bool,
|
||||
) error {
|
||||
// find all matching tracks
|
||||
trackPublishers := make(map[string]types.Participant)
|
||||
trackPublishers := make(map[livekit.TrackID]types.Participant)
|
||||
participants := r.GetParticipants()
|
||||
for _, trackSid := range trackIds {
|
||||
for _, trackID := range trackIDs {
|
||||
for _, p := range participants {
|
||||
track := p.GetPublishedTrack(trackSid)
|
||||
track := p.GetPublishedTrack(trackID)
|
||||
if track != nil {
|
||||
trackPublishers[trackSid] = p
|
||||
trackPublishers[trackID] = p
|
||||
break
|
||||
}
|
||||
}
|
||||
@@ -359,19 +359,19 @@ func (r *Room) UpdateSubscriptions(
|
||||
if p == nil {
|
||||
continue
|
||||
}
|
||||
for _, trackSid := range pt.TrackSids {
|
||||
trackPublishers[trackSid] = p
|
||||
for _, trackID := range pt.TrackSids {
|
||||
trackPublishers[trackID] = p
|
||||
}
|
||||
}
|
||||
|
||||
// handle subscription changes
|
||||
for trackSid, publisher := range trackPublishers {
|
||||
for trackID, publisher := range trackPublishers {
|
||||
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
|
||||
}
|
||||
} else {
|
||||
publisher.RemoveSubscriber(participant, trackSid)
|
||||
publisher.RemoveSubscriber(participant, trackID)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
@@ -381,14 +381,14 @@ func (r *Room) UpdateSubscriptionPermissions(participant types.Participant, perm
|
||||
return participant.UpdateSubscriptionPermissions(permissions, r.GetParticipantBySid)
|
||||
}
|
||||
|
||||
func (r *Room) RemoveDisallowedSubscriptions(sub types.Participant, disallowedSubscriptions map[string]string) {
|
||||
for trackSid, publisherSid := range disallowedSubscriptions {
|
||||
pub := r.GetParticipantBySid(publisherSid)
|
||||
func (r *Room) RemoveDisallowedSubscriptions(sub types.Participant, disallowedSubscriptions map[livekit.TrackID]livekit.ParticipantID) {
|
||||
for trackID, publisherID := range disallowedSubscriptions {
|
||||
pub := r.GetParticipantBySid(publisherID)
|
||||
if pub == nil {
|
||||
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",
|
||||
"participants", []string{participant.Identity(), existingParticipant.Identity()},
|
||||
"pIDs", []string{participant.ID(), existingParticipant.ID()},
|
||||
"participants", []livekit.ParticipantIdentity{participant.Identity(), existingParticipant.Identity()},
|
||||
"pIDs", []livekit.ParticipantID{participant.ID(), existingParticipant.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,
|
||||
"participants", []string{participant.Identity(), existingParticipant.Identity()},
|
||||
"pIDs", []string{participant.ID(), existingParticipant.ID()},
|
||||
"participants", []livekit.ParticipantIdentity{participant.Identity(), existingParticipant.Identity()},
|
||||
"pIDs", []livekit.ParticipantID{participant.ID(), existingParticipant.ID()},
|
||||
"track", track.ID())
|
||||
}
|
||||
}
|
||||
@@ -579,8 +579,8 @@ func (r *Room) onDataPacket(source types.Participant, dp *livekit.DataPacket) {
|
||||
}
|
||||
if len(dest) > 0 {
|
||||
found := false
|
||||
for _, dSid := range dest {
|
||||
if op.ID() == dSid {
|
||||
for _, dID := range dest {
|
||||
if op.ID() == dID {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
@@ -610,8 +610,8 @@ func (r *Room) subscribeToExistingTracks(p types.Participant) {
|
||||
if n, err := op.AddSubscriber(p, types.AddSubscriberParams{AllTracks: true}); err != nil {
|
||||
// TODO: log error? or disconnect?
|
||||
r.Logger.Errorw("could not subscribe to participant", err,
|
||||
"participants", []string{op.Identity(), p.Identity()},
|
||||
"pIDs", []string{op.ID(), p.ID()})
|
||||
"participants", []livekit.ParticipantIdentity{op.Identity(), p.Identity()},
|
||||
"pIDs", []livekit.ParticipantID{op.ID(), p.ID()})
|
||||
} else {
|
||||
tracksAdded += n
|
||||
}
|
||||
@@ -682,17 +682,17 @@ func (r *Room) sendSpeakerChanges(speakers []*livekit.SpeakerInfo) {
|
||||
}
|
||||
|
||||
func (r *Room) audioUpdateWorker() {
|
||||
var smoothValues map[string]float32
|
||||
var smoothValues map[livekit.ParticipantID]float32
|
||||
var smoothFactor float32
|
||||
var activeThreshold float32
|
||||
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)
|
||||
smoothFactor = 2 / float32(ss+1)
|
||||
activeThreshold = ConvertAudioLevel(r.audioConfig.ActiveLevel)
|
||||
}
|
||||
|
||||
lastActiveMap := make(map[string]*livekit.SpeakerInfo)
|
||||
lastActiveMap := make(map[livekit.ParticipantID]*livekit.SpeakerInfo)
|
||||
for {
|
||||
if r.IsClosed() {
|
||||
return
|
||||
@@ -738,7 +738,7 @@ func (r *Room) audioUpdateWorker() {
|
||||
}
|
||||
|
||||
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 {
|
||||
prev := lastActiveMap[speaker.Sid]
|
||||
if prev == nil || prev.Level != speaker.Level {
|
||||
@@ -775,7 +775,7 @@ func (r *Room) connectionQualityWorker() {
|
||||
}
|
||||
|
||||
participants := r.GetParticipants()
|
||||
connectionInfos := make(map[string]*livekit.ConnectionQualityInfo, len(participants))
|
||||
connectionInfos := make(map[livekit.ParticipantID]*livekit.ConnectionQualityInfo, len(participants))
|
||||
|
||||
for _, p := range participants {
|
||||
connectionInfos[p.ID()] = p.GetConnectionQuality()
|
||||
|
||||
@@ -176,7 +176,7 @@ func TestParticipantUpdate(t *testing.T) {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
rm := newRoomWithParticipants(t, testRoomOpts{num: 3})
|
||||
// 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() {
|
||||
fp := p.(*typesfakes.FakeParticipant)
|
||||
callCounts[p.ID()] = fp.SendParticipantUpdateCallCount()
|
||||
@@ -264,7 +264,7 @@ func TestNewTrack(t *testing.T) {
|
||||
require.Equal(t, 1, pub.AddSubscriberCallCount())
|
||||
sub, params := pub.AddSubscriberArgsForCall(pub.AddSubscriberCallCount() - 1)
|
||||
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 {
|
||||
PublisherID string
|
||||
PublisherIdentity string
|
||||
SubscriberID string
|
||||
PublisherID livekit.ParticipantID
|
||||
PublisherIdentity livekit.ParticipantIdentity
|
||||
SubscriberID livekit.ParticipantID
|
||||
MediaTrack types.MediaTrack
|
||||
DownTrack *sfu.DownTrack
|
||||
}
|
||||
@@ -56,11 +56,11 @@ func (t *SubscribedTrack) ID() string {
|
||||
return t.params.DownTrack.ID()
|
||||
}
|
||||
|
||||
func (t *SubscribedTrack) PublisherID() string {
|
||||
func (t *SubscribedTrack) PublisherID() livekit.ParticipantID {
|
||||
return t.params.PublisherID
|
||||
}
|
||||
|
||||
func (t *SubscribedTrack) PublisherIdentity() string {
|
||||
func (t *SubscribedTrack) PublisherIdentity() livekit.ParticipantIdentity {
|
||||
return t.params.PublisherIdentity
|
||||
}
|
||||
|
||||
|
||||
@@ -47,8 +47,8 @@ type PCTransport struct {
|
||||
}
|
||||
|
||||
type TransportParams struct {
|
||||
ParticipantID string
|
||||
ParticipantIdentity string
|
||||
ParticipantID livekit.ParticipantID
|
||||
ParticipantIdentity livekit.ParticipantIdentity
|
||||
Target livekit.SignalTarget
|
||||
Config *WebRTCConfig
|
||||
Telemetry telemetry.TelemetryService
|
||||
|
||||
+23
-23
@@ -21,13 +21,13 @@ type WebsocketClient interface {
|
||||
|
||||
type AddSubscriberParams struct {
|
||||
AllTracks bool
|
||||
TrackSids []string
|
||||
TrackIDs []livekit.TrackID
|
||||
}
|
||||
|
||||
//counterfeiter:generate . Participant
|
||||
type Participant interface {
|
||||
ID() string
|
||||
Identity() string
|
||||
ID() livekit.ParticipantID
|
||||
Identity() livekit.ParticipantIdentity
|
||||
State() livekit.ParticipantInfo_State
|
||||
ProtocolVersion() ProtocolVersion
|
||||
IsReady() bool
|
||||
@@ -42,27 +42,27 @@ type Participant interface {
|
||||
ICERestart() error
|
||||
|
||||
AddTrack(req *livekit.AddTrackRequest)
|
||||
GetPublishedTrack(sid string) PublishedTrack
|
||||
GetPublishedTrack(sid livekit.TrackID) PublishedTrack
|
||||
GetPublishedTracks() []PublishedTrack
|
||||
GetSubscribedTrack(sid string) SubscribedTrack
|
||||
GetSubscribedTrack(sid livekit.TrackID) SubscribedTrack
|
||||
GetSubscribedTracks() []SubscribedTrack
|
||||
HandleOffer(sdp webrtc.SessionDescription) (answer webrtc.SessionDescription, err error)
|
||||
HandleAnswer(sdp webrtc.SessionDescription) error
|
||||
AddICECandidate(candidate webrtc.ICECandidateInit, target livekit.SignalTarget) 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
|
||||
SendParticipantUpdate(participants []*livekit.ParticipantInfo, updatedAt time.Time) error
|
||||
SendSpeakerUpdate(speakers []*livekit.SpeakerInfo) error
|
||||
SendDataPacket(packet *livekit.DataPacket) error
|
||||
SendRoomUpdate(room *livekit.Room) 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)
|
||||
GetConnectionQuality() *livekit.ConnectionQualityInfo
|
||||
IsSubscribedTo(participantSid string) bool
|
||||
IsSubscribedTo(participantID livekit.ParticipantID) bool
|
||||
// returns list of participant identities that the current participant is subscribed to
|
||||
GetSubscribedParticipants() []string
|
||||
GetSubscribedParticipants() []livekit.ParticipantID
|
||||
|
||||
// permissions
|
||||
CanPublish() bool
|
||||
@@ -83,15 +83,15 @@ type Participant interface {
|
||||
OnTrackUpdated(callback func(Participant, PublishedTrack))
|
||||
OnMetadataUpdate(callback func(Participant))
|
||||
OnDataPacket(callback func(Participant, *livekit.DataPacket))
|
||||
OnClose(func(Participant, map[string]string))
|
||||
OnClose(func(Participant, map[livekit.TrackID]livekit.ParticipantID))
|
||||
|
||||
// package methods
|
||||
AddSubscribedTrack(st SubscribedTrack)
|
||||
RemoveSubscribedTrack(st SubscribedTrack)
|
||||
SubscriberPC() *webrtc.PeerConnection
|
||||
|
||||
UpdateSubscriptionPermissions(permissions *livekit.UpdateSubscriptionPermissions, resolver func(participantSid string) Participant) error
|
||||
SubscriptionPermissionUpdate(publisherSid string, trackSid string, allowed bool)
|
||||
UpdateSubscriptionPermissions(permissions *livekit.UpdateSubscriptionPermissions, resolver func(participantID livekit.ParticipantID) Participant) error
|
||||
SubscriptionPermissionUpdate(publisherID livekit.ParticipantID, trackID livekit.TrackID, allowed bool)
|
||||
|
||||
DebugInfo() map[string]interface{}
|
||||
}
|
||||
@@ -99,15 +99,15 @@ type Participant interface {
|
||||
// Room is a container of participants, and can provide room level actions
|
||||
//counterfeiter:generate . Room
|
||||
type Room interface {
|
||||
Name() string
|
||||
UpdateSubscriptions(participant Participant, trackIDs []string, participantTracks []*livekit.ParticipantTracks, subscribe bool) error
|
||||
Name() livekit.RoomName
|
||||
UpdateSubscriptions(participant Participant, trackIDs []livekit.TrackID, participantTracks []*livekit.ParticipantTracks, subscribe bool) error
|
||||
UpdateSubscriptionPermissions(participant Participant, permissions *livekit.UpdateSubscriptionPermissions) error
|
||||
}
|
||||
|
||||
// MediaTrack represents a media track
|
||||
//counterfeiter:generate . MediaTrack
|
||||
type MediaTrack interface {
|
||||
ID() string
|
||||
ID() livekit.TrackID
|
||||
Kind() livekit.TrackType
|
||||
Name() string
|
||||
IsMuted() bool
|
||||
@@ -118,16 +118,16 @@ type MediaTrack interface {
|
||||
|
||||
// subscribers
|
||||
AddSubscriber(participant Participant) error
|
||||
RemoveSubscriber(participantId string)
|
||||
IsSubscriber(subId string) bool
|
||||
RemoveSubscriber(participantID livekit.ParticipantID)
|
||||
IsSubscriber(subID livekit.ParticipantID) bool
|
||||
RemoveAllSubscribers()
|
||||
RevokeDisallowedSubscribers(allowedSubscriberIDs []string) []string
|
||||
RevokeDisallowedSubscribers(allowedSubscriberIDs []livekit.ParticipantID) []livekit.ParticipantID
|
||||
|
||||
// returns quality information that's appropriate for width & height
|
||||
GetQualityForDimension(width, height uint32) livekit.VideoQuality
|
||||
|
||||
NotifySubscriberMute(subscriberID string)
|
||||
NotifySubscriberMaxQuality(subscriberID string, quality livekit.VideoQuality)
|
||||
NotifySubscriberMute(subscriberID livekit.ParticipantID)
|
||||
NotifySubscriberMaxQuality(subscriberID livekit.ParticipantID, quality livekit.VideoQuality)
|
||||
}
|
||||
|
||||
// PublishedTrack is the main interface representing a track published to the room
|
||||
@@ -153,9 +153,9 @@ type PublishedTrack interface {
|
||||
//counterfeiter:generate . SubscribedTrack
|
||||
type SubscribedTrack interface {
|
||||
OnBind(f func())
|
||||
ID() string
|
||||
PublisherID() string
|
||||
PublisherIdentity() string
|
||||
ID() livekit.TrackID
|
||||
PublisherID() livekit.ParticipantID
|
||||
PublisherIdentity() livekit.ParticipantIdentity
|
||||
DownTrack() *sfu.DownTrack
|
||||
MediaTrack() MediaTrack
|
||||
IsMuted() bool
|
||||
|
||||
@@ -149,7 +149,7 @@ func (u *UptrackManager) AddSubscriber(sub types.Participant, params types.AddSu
|
||||
if params.AllTracks {
|
||||
tracks = u.GetPublishedTracks()
|
||||
} else {
|
||||
for _, trackID := range params.TrackSids {
|
||||
for _, trackID := range params.TrackIDs {
|
||||
track := u.getPublishedTrack(trackID)
|
||||
if track == nil {
|
||||
continue
|
||||
|
||||
+10
-10
@@ -18,7 +18,7 @@ const (
|
||||
trackIdSeparator = "|"
|
||||
)
|
||||
|
||||
func UnpackStreamID(packed string) (participantId string, trackId string) {
|
||||
func UnpackStreamID(packed string) (participantID livekit.ParticipantID, trackID livekit.TrackID) {
|
||||
parts := strings.Split(packed, trackIdSeparator)
|
||||
if len(parts) > 1 {
|
||||
return parts[0], packed[len(parts[0])+1:]
|
||||
@@ -26,21 +26,21 @@ func UnpackStreamID(packed string) (participantId string, trackId string) {
|
||||
return packed, ""
|
||||
}
|
||||
|
||||
func PackStreamID(participantId, trackId string) string {
|
||||
return participantId + trackIdSeparator + trackId
|
||||
func PackStreamID(participantID livekit.ParticipantID, trackID livekit.TrackID) string {
|
||||
return participantID + trackIdSeparator + trackID
|
||||
}
|
||||
|
||||
func PackDataTrackLabel(participantId, trackId string, label string) string {
|
||||
return participantId + trackIdSeparator + trackId + trackIdSeparator + label
|
||||
func PackDataTrackLabel(participantID livekit.ParticipantID, trackID livekit.TrackID, label string) string {
|
||||
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)
|
||||
if len(parts) != 3 {
|
||||
return "", packed, ""
|
||||
}
|
||||
peerId = parts[0]
|
||||
trackId = parts[1]
|
||||
peerID = parts[0]
|
||||
trackID = parts[1]
|
||||
label = parts[2]
|
||||
return
|
||||
}
|
||||
@@ -133,7 +133,7 @@ func Recover() {
|
||||
}
|
||||
|
||||
// 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)
|
||||
if identity != "" {
|
||||
lr = lr.WithValues("participant", identity)
|
||||
@@ -144,7 +144,7 @@ func LoggerWithParticipant(l logger.Logger, identity, sid string) logger.Logger
|
||||
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)
|
||||
return logger.Logger(
|
||||
lr.WithValues(
|
||||
|
||||
@@ -8,22 +8,22 @@ import (
|
||||
|
||||
func TestPackStreamId(t *testing.T) {
|
||||
packed := "PA_123abc|uuid-id"
|
||||
pId, trackId := UnpackStreamID(packed)
|
||||
require.Equal(t, "PA_123abc", pId)
|
||||
require.Equal(t, "uuid-id", trackId)
|
||||
pID, trackID := UnpackStreamID(packed)
|
||||
require.Equal(t, "PA_123abc", pID)
|
||||
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) {
|
||||
pId := "PA_123abc"
|
||||
trackId := "TR_b3da25"
|
||||
pID := "PA_123abc"
|
||||
trackID := "TR_b3da25"
|
||||
label := "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)
|
||||
require.Equal(t, pId, p)
|
||||
require.Equal(t, trackId, tr)
|
||||
require.Equal(t, pID, p)
|
||||
require.Equal(t, trackID, tr)
|
||||
require.Equal(t, label, l)
|
||||
}
|
||||
|
||||
@@ -2,26 +2,27 @@ package rtc
|
||||
|
||||
import (
|
||||
"github.com/livekit/livekit-server/pkg/sfu"
|
||||
"github.com/livekit/protocol/livekit"
|
||||
)
|
||||
|
||||
// wrapper around WebRTC receiver, overriding its ID
|
||||
|
||||
type WrappedReceiver struct {
|
||||
sfu.TrackReceiver
|
||||
trackId string
|
||||
trackID livekit.TrackID
|
||||
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{
|
||||
TrackReceiver: receiver,
|
||||
trackId: trackId,
|
||||
trackID: trackID,
|
||||
streamId: streamId,
|
||||
}
|
||||
}
|
||||
|
||||
func (r WrappedReceiver) TrackID() string {
|
||||
return r.trackId
|
||||
func (r WrappedReceiver) TrackID() livekit.TrackID {
|
||||
return r.trackID
|
||||
}
|
||||
|
||||
func (r WrappedReceiver) StreamID() string {
|
||||
|
||||
@@ -33,7 +33,7 @@ type RoomManager struct {
|
||||
roomStore RoomStore
|
||||
telemetry telemetry.TelemetryService
|
||||
|
||||
rooms map[string]*rtc.Room
|
||||
rooms map[livekit.RoomName]*rtc.Room
|
||||
}
|
||||
|
||||
func NewLocalRoomManager(
|
||||
@@ -57,7 +57,7 @@ func NewLocalRoomManager(
|
||||
roomStore: roomStore,
|
||||
telemetry: telemetry,
|
||||
|
||||
rooms: make(map[string]*rtc.Room),
|
||||
rooms: make(map[livekit.RoomName]*rtc.Room),
|
||||
}
|
||||
|
||||
// hook up to router
|
||||
@@ -66,14 +66,14 @@ func NewLocalRoomManager(
|
||||
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()
|
||||
defer r.lock.RUnlock()
|
||||
return r.rooms[roomName]
|
||||
}
|
||||
|
||||
// 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)
|
||||
r.lock.Lock()
|
||||
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
|
||||
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)
|
||||
if err != nil {
|
||||
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)
|
||||
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 {
|
||||
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
|
||||
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()
|
||||
room := r.rooms[roomName]
|
||||
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
|
||||
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()
|
||||
room := r.rooms[roomName]
|
||||
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)
|
||||
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:
|
||||
if participant == nil {
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user