mirror of
https://github.com/livekit/livekit.git
synced 2026-04-01 02:15:39 +00:00
* small refactor * extra line * fix room allocator test * selector fakes not used * keep decisions out of router * put nodeId logic back * fix room allocator test
23 lines
570 B
Go
23 lines
570 B
Go
package selector
|
|
|
|
import (
|
|
"time"
|
|
|
|
livekit "github.com/livekit/protocol/proto"
|
|
"github.com/thoas/go-funk"
|
|
)
|
|
|
|
const AvailableSeconds = 5
|
|
|
|
// checks if a node has been updated recently to be considered for selection
|
|
func IsAvailable(node *livekit.Node) bool {
|
|
delta := time.Now().Unix() - node.Stats.UpdatedAt
|
|
return int(delta) < AvailableSeconds
|
|
}
|
|
|
|
func GetAvailableNodes(nodes []*livekit.Node) []*livekit.Node {
|
|
return funk.Filter(nodes, func(node *livekit.Node) bool {
|
|
return IsAvailable(node) && node.State == livekit.NodeState_SERVING
|
|
}).([]*livekit.Node)
|
|
}
|