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:
+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,
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user