mirror of
https://github.com/livekit/livekit.git
synced 2026-08-03 08:59:29 +00:00
switched to Twirp for RPC, server skaffold
This commit is contained in:
@@ -1,43 +0,0 @@
|
||||
package node
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/livekit/livekit-server/proto"
|
||||
)
|
||||
|
||||
// Router selects the best node for room interactions
|
||||
type Chooser interface {
|
||||
ChooseNodeForRoom(roomId string) (*proto.Node, error)
|
||||
GetNodeForRoom(roomId string) (*proto.Node, error)
|
||||
ClearRoom(roomId string) error
|
||||
}
|
||||
|
||||
func NewSingleNodeChooser(n *Node) *SingleNodeChooser {
|
||||
return &SingleNodeChooser{
|
||||
localNode: n,
|
||||
rooms: make(map[string]bool),
|
||||
}
|
||||
}
|
||||
|
||||
type SingleNodeChooser struct {
|
||||
localNode *Node
|
||||
rooms map[string]bool
|
||||
}
|
||||
|
||||
func (c *SingleNodeChooser) ChooseNodeForRoom(roomId string) (n *proto.Node, err error) {
|
||||
if c.rooms[roomId] {
|
||||
err = fmt.Errorf("Room already exists")
|
||||
return
|
||||
}
|
||||
c.rooms[roomId] = true
|
||||
n = &c.localNode.Node
|
||||
return
|
||||
}
|
||||
|
||||
func (c *SingleNodeChooser) GetNodeForRoom(roomId string) (*proto.Node, error) {
|
||||
if !c.rooms[roomId] {
|
||||
return nil, fmt.Errorf("room %d had not been created", roomId)
|
||||
}
|
||||
return &c.localNode.Node, nil
|
||||
}
|
||||
+13
-6
@@ -2,6 +2,7 @@ package node
|
||||
|
||||
import (
|
||||
"github.com/google/uuid"
|
||||
"github.com/google/wire"
|
||||
"github.com/pion/stun"
|
||||
|
||||
"github.com/livekit/livekit-server/proto"
|
||||
@@ -11,16 +12,18 @@ const (
|
||||
googleStunServer = "stun.l.google.com:19302"
|
||||
)
|
||||
|
||||
var NodeSet = wire.NewSet(NewLocalNode)
|
||||
|
||||
type Node struct {
|
||||
proto.Node
|
||||
}
|
||||
|
||||
type NodeStats struct {
|
||||
NumRooms int32
|
||||
NumClients int32
|
||||
NumRooms int32
|
||||
NumClients int32
|
||||
NumVideoChannels int32
|
||||
NumAudioChannels int32
|
||||
BytesPerMin int64
|
||||
BytesPerMin int64
|
||||
}
|
||||
|
||||
func NewLocalNode() (*Node, error) {
|
||||
@@ -28,11 +31,15 @@ func NewLocalNode() (*Node, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &Node{
|
||||
n := &Node{
|
||||
proto.Node{
|
||||
Id: id.String(),
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
if err = n.DiscoverNetworkInfo(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return n, nil
|
||||
}
|
||||
|
||||
func (n *Node) DiscoverNetworkInfo() error {
|
||||
@@ -65,4 +72,4 @@ func (n *Node) DiscoverNetworkInfo() error {
|
||||
err = stunErr
|
||||
}
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user