reduce reliance of funk, fixed bug getting subscribed tracks
This commit is contained in:
+16
-4
@@ -11,7 +11,6 @@ import (
|
||||
"github.com/pion/rtcp"
|
||||
"github.com/pion/webrtc/v3"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/thoas/go-funk"
|
||||
|
||||
"github.com/livekit/livekit-server/pkg/config"
|
||||
"github.com/livekit/livekit-server/pkg/logger"
|
||||
@@ -271,7 +270,11 @@ func (p *ParticipantImpl) AddTrack(clientId, name string, trackType livekit.Trac
|
||||
func (p *ParticipantImpl) GetPublishedTracks() []types.PublishedTrack {
|
||||
p.lock.RUnlock()
|
||||
defer p.lock.RUnlock()
|
||||
return funk.Values(p.publishedTracks).([]types.PublishedTrack)
|
||||
tracks := make([]types.PublishedTrack, 0, len(p.publishedTracks))
|
||||
for _, t := range p.publishedTracks {
|
||||
tracks = append(tracks, t)
|
||||
}
|
||||
return tracks
|
||||
}
|
||||
|
||||
// handles a client answer response, with subscriber PC, server initiates the offer
|
||||
@@ -347,7 +350,10 @@ func (p *ParticipantImpl) Close() error {
|
||||
// Subscribes op to all publishedTracks
|
||||
func (p *ParticipantImpl) AddSubscriber(op types.Participant) error {
|
||||
p.lock.RLock()
|
||||
tracks := funk.Values(p.publishedTracks).([]types.PublishedTrack)
|
||||
tracks := make([]types.PublishedTrack, 0, len(p.publishedTracks))
|
||||
for _, t := range p.publishedTracks {
|
||||
tracks = append(tracks, t)
|
||||
}
|
||||
defer p.lock.RUnlock()
|
||||
|
||||
if len(tracks) == 0 {
|
||||
@@ -476,7 +482,13 @@ func (p *ParticipantImpl) SubscriberPC() *webrtc.PeerConnection {
|
||||
func (p *ParticipantImpl) GetSubscribedTracks() []types.SubscribedTrack {
|
||||
p.lock.RLock()
|
||||
defer p.lock.RUnlock()
|
||||
return funk.Values(p.subscribedTracks).([]types.SubscribedTrack)
|
||||
subscribed := make([]types.SubscribedTrack, 0, len(p.subscribedTracks))
|
||||
for _, pTracks := range p.subscribedTracks {
|
||||
for _, t := range pTracks {
|
||||
subscribed = append(subscribed, t)
|
||||
}
|
||||
}
|
||||
return subscribed
|
||||
}
|
||||
|
||||
// add a track to the participant's subscribed list
|
||||
|
||||
+1
-1
@@ -323,7 +323,7 @@ func (r *Room) onTrackAdded(participant types.Participant, track types.Published
|
||||
|
||||
func (r *Room) onTrackUpdated(p types.Participant, track types.PublishedTrack) {
|
||||
// send track updates to everyone, especially if track was updated by admin
|
||||
r.broadcastParticipantState(p, true)
|
||||
r.broadcastParticipantState(p, false)
|
||||
if r.onParticipantChanged != nil {
|
||||
r.onParticipantChanged(p)
|
||||
}
|
||||
|
||||
@@ -4,8 +4,6 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/thoas/go-funk"
|
||||
|
||||
livekit "github.com/livekit/livekit-server/proto"
|
||||
)
|
||||
|
||||
@@ -58,7 +56,11 @@ func (p *LocalRoomStore) GetRoom(idOrName string) (*livekit.Room, error) {
|
||||
func (p *LocalRoomStore) ListRooms() ([]*livekit.Room, error) {
|
||||
p.lock.RLock()
|
||||
defer p.lock.RUnlock()
|
||||
return funk.Values(p.rooms).([]*livekit.Room), nil
|
||||
rooms := make([]*livekit.Room, 0, len(p.rooms))
|
||||
for _, r := range p.rooms {
|
||||
rooms = append(rooms, r)
|
||||
}
|
||||
return rooms, nil
|
||||
}
|
||||
|
||||
func (p *LocalRoomStore) DeleteRoom(idOrName string) error {
|
||||
@@ -115,8 +117,10 @@ func (p *LocalRoomStore) ListParticipants(roomName string) ([]*livekit.Participa
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
items := funk.Values(roomParticipants).([]*livekit.ParticipantInfo)
|
||||
// TODO: should short this to something reasonable
|
||||
items := make([]*livekit.ParticipantInfo, 0, len(roomParticipants))
|
||||
for _, p := range roomParticipants {
|
||||
items = append(items, p)
|
||||
}
|
||||
|
||||
return items, nil
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/thoas/go-funk"
|
||||
"github.com/livekit/protocol/utils"
|
||||
|
||||
"github.com/livekit/livekit-server/pkg/config"
|
||||
"github.com/livekit/livekit-server/pkg/logger"
|
||||
@@ -13,7 +13,6 @@ import (
|
||||
"github.com/livekit/livekit-server/pkg/rtc"
|
||||
"github.com/livekit/livekit-server/pkg/rtc/types"
|
||||
livekit "github.com/livekit/livekit-server/proto"
|
||||
"github.com/livekit/protocol/utils"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -162,7 +161,10 @@ func (r *RoomManager) CleanupRooms() error {
|
||||
|
||||
func (r *RoomManager) CloseIdleRooms() {
|
||||
r.lock.RLock()
|
||||
rooms := funk.Values(r.rooms).([]*rtc.Room)
|
||||
rooms := make([]*rtc.Room, 0, len(r.rooms))
|
||||
for _, rm := range r.rooms {
|
||||
rooms = append(rooms, rm)
|
||||
}
|
||||
r.lock.RUnlock()
|
||||
|
||||
for _, room := range rooms {
|
||||
@@ -347,7 +349,7 @@ func (r *RoomManager) rtcSessionWorker(room *rtc.Room, participant types.Partici
|
||||
if subTrack.ID() != sid {
|
||||
continue
|
||||
}
|
||||
subTrack.SetMuted(msg.TrackSetting.Mute)
|
||||
subTrack.SetMuted(msg.TrackSetting.Disabled)
|
||||
subTrack.SetVideoQuality(msg.TrackSetting.Quality)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user