Switch to stdlib maps, slices (#4445)
* Switch to stdlib maps, slices * slices
This commit is contained in:
@@ -4,14 +4,15 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"io"
|
"io"
|
||||||
|
"maps"
|
||||||
"math"
|
"math"
|
||||||
"math/rand/v2"
|
"math/rand/v2"
|
||||||
|
"slices"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/frostbyte73/core"
|
"github.com/frostbyte73/core"
|
||||||
"github.com/gammazero/deque"
|
"github.com/gammazero/deque"
|
||||||
"golang.org/x/exp/maps"
|
|
||||||
|
|
||||||
"github.com/livekit/livekit-server/pkg/agent"
|
"github.com/livekit/livekit-server/pkg/agent"
|
||||||
"github.com/livekit/livekit-server/pkg/config"
|
"github.com/livekit/livekit-server/pkg/config"
|
||||||
@@ -423,7 +424,7 @@ func (w *AgentWorker) SimulateRoomJob(roomName string) {
|
|||||||
func (w *AgentWorker) Jobs() []*AgentJob {
|
func (w *AgentWorker) Jobs() []*AgentJob {
|
||||||
w.mu.Lock()
|
w.mu.Lock()
|
||||||
defer w.mu.Unlock()
|
defer w.mu.Unlock()
|
||||||
return maps.Values(w.jobs)
|
return slices.Collect(maps.Values(w.jobs))
|
||||||
}
|
}
|
||||||
|
|
||||||
type stableJobLoad struct {
|
type stableJobLoad struct {
|
||||||
|
|||||||
@@ -15,10 +15,10 @@
|
|||||||
package dynacast
|
package dynacast
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"maps"
|
||||||
|
"slices"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"golang.org/x/exp/maps"
|
|
||||||
|
|
||||||
"github.com/livekit/protocol/codecs/mime"
|
"github.com/livekit/protocol/codecs/mime"
|
||||||
"github.com/livekit/protocol/logger"
|
"github.com/livekit/protocol/logger"
|
||||||
|
|
||||||
@@ -161,5 +161,5 @@ func (d *dynacastManagerBase) getOrCreateDynacastQuality(mimeType mime.MimeType)
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (d *dynacastManagerBase) getDynacastQualitiesLocked() []dynacastQuality {
|
func (d *dynacastManagerBase) getDynacastQualitiesLocked() []dynacastQuality {
|
||||||
return maps.Values(d.dynacastQuality)
|
return slices.Collect(maps.Values(d.dynacastQuality))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ package rtc
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"maps"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"os"
|
"os"
|
||||||
"slices"
|
"slices"
|
||||||
@@ -33,7 +34,6 @@ import (
|
|||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"go.uber.org/atomic"
|
"go.uber.org/atomic"
|
||||||
"go.uber.org/zap/zapcore"
|
"go.uber.org/zap/zapcore"
|
||||||
"golang.org/x/exp/maps"
|
|
||||||
"google.golang.org/protobuf/proto"
|
"google.golang.org/protobuf/proto"
|
||||||
|
|
||||||
"github.com/livekit/mediatransportutil/pkg/twcc"
|
"github.com/livekit/mediatransportutil/pkg/twcc"
|
||||||
@@ -1443,7 +1443,7 @@ func (p *ParticipantImpl) Close(sendLeave bool, reason types.ParticipantCloseRea
|
|||||||
// ensure this is synchronized
|
// ensure this is synchronized
|
||||||
p.CloseSignalConnection(types.SignallingCloseReasonParticipantClose)
|
p.CloseSignalConnection(types.SignallingCloseReasonParticipantClose)
|
||||||
p.lock.RLock()
|
p.lock.RLock()
|
||||||
onClose := maps.Values(p.onClose)
|
onClose := slices.Collect(maps.Values(p.onClose))
|
||||||
p.lock.RUnlock()
|
p.lock.RUnlock()
|
||||||
for _, cb := range onClose {
|
for _, cb := range onClose {
|
||||||
cb(p)
|
cb(p)
|
||||||
|
|||||||
+8
-8
@@ -17,6 +17,7 @@ package rtc
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"maps"
|
||||||
"math"
|
"math"
|
||||||
"slices"
|
"slices"
|
||||||
"sort"
|
"sort"
|
||||||
@@ -25,7 +26,6 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"go.uber.org/atomic"
|
"go.uber.org/atomic"
|
||||||
"golang.org/x/exp/maps"
|
|
||||||
"google.golang.org/protobuf/proto"
|
"google.golang.org/protobuf/proto"
|
||||||
|
|
||||||
"github.com/livekit/protocol/codecs/mime"
|
"github.com/livekit/protocol/codecs/mime"
|
||||||
@@ -196,7 +196,7 @@ func (ad *agentDispatch) jobsLaunching() (jobsLaunched func()) {
|
|||||||
|
|
||||||
func (ad *agentDispatch) waitForPendingJobs() {
|
func (ad *agentDispatch) waitForPendingJobs() {
|
||||||
ad.lock.Lock()
|
ad.lock.Lock()
|
||||||
cs := maps.Keys(ad.pending)
|
cs := slices.Collect(maps.Keys(ad.pending))
|
||||||
ad.lock.Unlock()
|
ad.lock.Unlock()
|
||||||
|
|
||||||
for _, c := range cs {
|
for _, c := range cs {
|
||||||
@@ -305,7 +305,7 @@ func NewRoom(
|
|||||||
|
|
||||||
r.createAgentDispatchesFromRoomAgent()
|
r.createAgentDispatchesFromRoomAgent()
|
||||||
|
|
||||||
r.launchRoomAgents(maps.Values(r.agentDispatches))
|
r.launchRoomAgents(slices.Collect(maps.Values(r.agentDispatches)))
|
||||||
|
|
||||||
go r.audioUpdateWorker()
|
go r.audioUpdateWorker()
|
||||||
go r.connectionQualityWorker()
|
go r.connectionQualityWorker()
|
||||||
@@ -364,7 +364,7 @@ func (r *Room) GetParticipants() []types.LocalParticipant {
|
|||||||
r.lock.RLock()
|
r.lock.RLock()
|
||||||
defer r.lock.RUnlock()
|
defer r.lock.RUnlock()
|
||||||
|
|
||||||
return maps.Values(r.participants)
|
return slices.Collect(maps.Values(r.participants))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Room) GetLocalParticipants() []types.LocalParticipant {
|
func (r *Room) GetLocalParticipants() []types.LocalParticipant {
|
||||||
@@ -469,7 +469,7 @@ func (r *Room) Join(
|
|||||||
r.joinedAt.Store(time.Now().Unix())
|
r.joinedAt.Store(time.Now().Unix())
|
||||||
}
|
}
|
||||||
|
|
||||||
r.launchTargetAgents(maps.Values(r.agentDispatches), participant, livekit.JobType_JT_PARTICIPANT)
|
r.launchTargetAgents(slices.Collect(maps.Values(r.agentDispatches)), participant, livekit.JobType_JT_PARTICIPANT)
|
||||||
|
|
||||||
r.logger.Debugw(
|
r.logger.Debugw(
|
||||||
"new participant joined",
|
"new participant joined",
|
||||||
@@ -1040,7 +1040,7 @@ func (r *Room) createJoinResponseLocked(
|
|||||||
OtherParticipants: GetOtherParticipantInfo(
|
OtherParticipants: GetOtherParticipantInfo(
|
||||||
participant,
|
participant,
|
||||||
false, // isMigratingIn
|
false, // isMigratingIn
|
||||||
toParticipants(maps.Values(r.participants)),
|
toParticipants(slices.Collect(maps.Values(r.participants))),
|
||||||
false, // skipSubscriberBroadcast
|
false, // skipSubscriberBroadcast
|
||||||
),
|
),
|
||||||
IceServers: iceServers,
|
IceServers: iceServers,
|
||||||
@@ -1104,7 +1104,7 @@ func (r *Room) onTrackPublished(participant types.Participant, track types.Media
|
|||||||
|
|
||||||
if !hasPublished {
|
if !hasPublished {
|
||||||
r.lock.RLock()
|
r.lock.RLock()
|
||||||
r.launchTargetAgents(maps.Values(r.agentDispatches), participant, livekit.JobType_JT_PUBLISHER)
|
r.launchTargetAgents(slices.Collect(maps.Values(r.agentDispatches)), participant, livekit.JobType_JT_PUBLISHER)
|
||||||
r.lock.RUnlock()
|
r.lock.RUnlock()
|
||||||
if r.internal != nil && r.internal.ParticipantEgress != nil {
|
if r.internal != nil && r.internal.ParticipantEgress != nil {
|
||||||
go func() {
|
go func() {
|
||||||
@@ -1601,7 +1601,7 @@ func (r *Room) changeUpdateWorker() {
|
|||||||
r.batchedUpdates = make(map[livekit.ParticipantIdentity]*ParticipantUpdate)
|
r.batchedUpdates = make(map[livekit.ParticipantIdentity]*ParticipantUpdate)
|
||||||
r.batchedUpdatesMu.Unlock()
|
r.batchedUpdatesMu.Unlock()
|
||||||
|
|
||||||
SendParticipantUpdates(maps.Values(updatesMap), r.GetParticipants(), r.roomConfig.UpdateBatchTargetSize)
|
SendParticipantUpdates(slices.Collect(maps.Values(updatesMap)), r.GetParticipants(), r.roomConfig.UpdateBatchTargetSize)
|
||||||
|
|
||||||
case <-cleanDataMessageTicker.C:
|
case <-cleanDataMessageTicker.C:
|
||||||
r.dataMessageCache.Prune()
|
r.dataMessageCache.Prune()
|
||||||
|
|||||||
@@ -18,12 +18,12 @@ package types
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"slices"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/pion/ice/v4"
|
"github.com/pion/ice/v4"
|
||||||
"github.com/pion/webrtc/v4"
|
"github.com/pion/webrtc/v4"
|
||||||
"golang.org/x/exp/slices"
|
|
||||||
|
|
||||||
"github.com/livekit/protocol/livekit"
|
"github.com/livekit/protocol/livekit"
|
||||||
"github.com/livekit/protocol/logger"
|
"github.com/livekit/protocol/logger"
|
||||||
|
|||||||
@@ -15,13 +15,14 @@
|
|||||||
package rtc
|
package rtc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"maps"
|
||||||
|
"slices"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/livekit/livekit-server/pkg/rtc/datatrack"
|
"github.com/livekit/livekit-server/pkg/rtc/datatrack"
|
||||||
"github.com/livekit/livekit-server/pkg/rtc/types"
|
"github.com/livekit/livekit-server/pkg/rtc/types"
|
||||||
"github.com/livekit/protocol/livekit"
|
"github.com/livekit/protocol/livekit"
|
||||||
"github.com/livekit/protocol/logger"
|
"github.com/livekit/protocol/logger"
|
||||||
"golang.org/x/exp/maps"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type UpDataTrackManagerParams struct {
|
type UpDataTrackManagerParams struct {
|
||||||
@@ -94,7 +95,7 @@ func (u *UpDataTrackManager) GetPublishedDataTracks() []types.DataTrack {
|
|||||||
u.lock.RLock()
|
u.lock.RLock()
|
||||||
defer u.lock.RUnlock()
|
defer u.lock.RUnlock()
|
||||||
|
|
||||||
return maps.Values(u.dataTracks)
|
return slices.Collect(maps.Values(u.dataTracks))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *UpDataTrackManager) GetPublishedDataTrack(handle uint16) types.DataTrack {
|
func (u *UpDataTrackManager) GetPublishedDataTrack(handle uint16) types.DataTrack {
|
||||||
|
|||||||
@@ -16,11 +16,12 @@ package rtc
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"maps"
|
||||||
|
"slices"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/livekit/protocol/livekit"
|
"github.com/livekit/protocol/livekit"
|
||||||
"github.com/livekit/protocol/logger"
|
"github.com/livekit/protocol/logger"
|
||||||
"golang.org/x/exp/maps"
|
|
||||||
|
|
||||||
"github.com/livekit/livekit-server/pkg/rtc/types"
|
"github.com/livekit/livekit-server/pkg/rtc/types"
|
||||||
"github.com/livekit/protocol/utils"
|
"github.com/livekit/protocol/utils"
|
||||||
@@ -146,7 +147,7 @@ func (u *UpTrackManager) GetPublishedTracks() []types.MediaTrack {
|
|||||||
u.lock.RLock()
|
u.lock.RLock()
|
||||||
defer u.lock.RUnlock()
|
defer u.lock.RUnlock()
|
||||||
|
|
||||||
return maps.Values(u.publishedTracks)
|
return slices.Collect(maps.Values(u.publishedTracks))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *UpTrackManager) UpdateSubscriptionPermission(
|
func (u *UpTrackManager) UpdateSubscriptionPermission(
|
||||||
|
|||||||
@@ -16,12 +16,12 @@ package rtc
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"maps"
|
||||||
|
"slices"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/pion/webrtc/v4"
|
"github.com/pion/webrtc/v4"
|
||||||
"go.uber.org/atomic"
|
"go.uber.org/atomic"
|
||||||
"golang.org/x/exp/maps"
|
|
||||||
"golang.org/x/exp/slices"
|
|
||||||
|
|
||||||
protoCodecs "github.com/livekit/protocol/codecs"
|
protoCodecs "github.com/livekit/protocol/codecs"
|
||||||
"github.com/livekit/protocol/codecs/mime"
|
"github.com/livekit/protocol/codecs/mime"
|
||||||
@@ -394,7 +394,7 @@ func (d *DummyReceiver) GetDownTracks() []sfu.TrackSender {
|
|||||||
if receiver := d.getReceiver(); receiver != nil {
|
if receiver := d.getReceiver(); receiver != nil {
|
||||||
return receiver.GetDownTracks()
|
return receiver.GetDownTracks()
|
||||||
}
|
}
|
||||||
return maps.Values(d.downTracks)
|
return slices.Collect(maps.Values(d.downTracks))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *DummyReceiver) DebugInfo() map[string]any {
|
func (d *DummyReceiver) DebugInfo() map[string]any {
|
||||||
@@ -567,7 +567,7 @@ func (d *DummyRedReceiver) GetDownTracks() []sfu.TrackSender {
|
|||||||
if r, ok := d.redReceiver.Load().(sfu.TrackReceiver); ok {
|
if r, ok := d.redReceiver.Load().(sfu.TrackReceiver); ok {
|
||||||
return r.GetDownTracks()
|
return r.GetDownTracks()
|
||||||
}
|
}
|
||||||
return maps.Values(d.downTracks)
|
return slices.Collect(maps.Values(d.downTracks))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *DummyRedReceiver) ReadRTP(buf []byte, layer uint8, esn uint64) (int, error) {
|
func (d *DummyRedReceiver) ReadRTP(buf []byte, layer uint8, esn uint64) (int, error) {
|
||||||
|
|||||||
@@ -20,12 +20,13 @@ import (
|
|||||||
"crypto/sha1"
|
"crypto/sha1"
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"maps"
|
||||||
"os"
|
"os"
|
||||||
|
"slices"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"golang.org/x/exp/maps"
|
|
||||||
|
|
||||||
"github.com/livekit/mediatransportutil/pkg/rtcconfig"
|
"github.com/livekit/mediatransportutil/pkg/rtcconfig"
|
||||||
"github.com/livekit/protocol/auth"
|
"github.com/livekit/protocol/auth"
|
||||||
@@ -214,7 +215,7 @@ func (r *RoomManager) deleteRoom(ctx context.Context, roomName livekit.RoomName)
|
|||||||
|
|
||||||
func (r *RoomManager) CloseIdleRooms() {
|
func (r *RoomManager) CloseIdleRooms() {
|
||||||
r.lock.RLock()
|
r.lock.RLock()
|
||||||
rooms := maps.Values(r.rooms)
|
rooms := slices.Collect(maps.Values(r.rooms))
|
||||||
r.lock.RUnlock()
|
r.lock.RUnlock()
|
||||||
|
|
||||||
for _, room := range rooms {
|
for _, room := range rooms {
|
||||||
@@ -237,7 +238,7 @@ func (r *RoomManager) HasParticipants() bool {
|
|||||||
func (r *RoomManager) Stop() {
|
func (r *RoomManager) Stop() {
|
||||||
// disconnect all clients
|
// disconnect all clients
|
||||||
r.lock.RLock()
|
r.lock.RLock()
|
||||||
rooms := maps.Values(r.rooms)
|
rooms := slices.Collect(maps.Values(r.rooms))
|
||||||
r.lock.RUnlock()
|
r.lock.RUnlock()
|
||||||
|
|
||||||
for _, room := range rooms {
|
for _, room := range rooms {
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"maps"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
@@ -32,7 +33,6 @@ import (
|
|||||||
|
|
||||||
"github.com/gorilla/websocket"
|
"github.com/gorilla/websocket"
|
||||||
"go.uber.org/atomic"
|
"go.uber.org/atomic"
|
||||||
"golang.org/x/exp/maps"
|
|
||||||
"google.golang.org/protobuf/proto"
|
"google.golang.org/protobuf/proto"
|
||||||
|
|
||||||
"github.com/livekit/protocol/livekit"
|
"github.com/livekit/protocol/livekit"
|
||||||
|
|||||||
@@ -16,8 +16,7 @@ package dependencydescriptor
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"slices"
|
||||||
"golang.org/x/exp/slices"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type TemplateMatch struct {
|
type TemplateMatch struct {
|
||||||
|
|||||||
Reference in New Issue
Block a user