switched to Twirp for RPC, server skaffold
This commit is contained in:
+33
-1
@@ -1,5 +1,37 @@
|
||||
package config
|
||||
|
||||
type Config struct {
|
||||
import (
|
||||
"github.com/urfave/cli/v2"
|
||||
"gopkg.in/yaml.v2"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
APIPort uint32 `yaml:"api_port"`
|
||||
RTCPort uint32 `yaml:"rtc_port"`
|
||||
UDPRangeStart uint32 `yaml:"udp_range_start"`
|
||||
UDPRangeEnd uint32 `yaml:"udp_range_end"`
|
||||
|
||||
// multi-node configuration,
|
||||
MultiNode bool `yaml:"multi_node"`
|
||||
Development bool `yaml:"development"`
|
||||
}
|
||||
|
||||
func NewConfig(confString string) (*Config, error) {
|
||||
// start with defaults
|
||||
conf := &Config{
|
||||
APIPort: 7880,
|
||||
RTCPort: 7881,
|
||||
UDPRangeStart: 10000,
|
||||
UDPRangeEnd: 11000,
|
||||
}
|
||||
if confString != "" {
|
||||
yaml.Unmarshal([]byte(confString), conf)
|
||||
}
|
||||
return conf, nil
|
||||
}
|
||||
|
||||
func (conf *Config) UpdateFromCLI(c *cli.Context) {
|
||||
if c.IsSet("dev") {
|
||||
conf.Development = c.Bool("dev")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
package logger
|
||||
|
||||
import (
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
var logger *zap.SugaredLogger
|
||||
|
||||
func GetLogger() *zap.SugaredLogger {
|
||||
if logger == nil {
|
||||
InitDevelopment()
|
||||
}
|
||||
return logger
|
||||
}
|
||||
|
||||
func InitProduction() {
|
||||
l, _ := zap.NewProduction()
|
||||
logger = l.Sugar()
|
||||
}
|
||||
|
||||
func InitDevelopment() {
|
||||
l, _ := zap.NewDevelopment()
|
||||
logger = l.Sugar()
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
|
||||
"github.com/livekit/livekit-server/proto"
|
||||
)
|
||||
|
||||
type RTCService struct {
|
||||
}
|
||||
|
||||
func (s *RTCService) Offer(ctx context.Context, offer *proto.SessionDescription) (answer *proto.SessionDescription, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func (s *RTCService) Trickle(ctx context.Context, req *proto.TrickleRequest) (res *proto.TrickleResponse, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func (s *RTCService) Signal(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
}
|
||||
|
||||
func NewRTCService() *RTCService {
|
||||
return &RTCService{}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/google/wire"
|
||||
|
||||
"github.com/livekit/livekit-server/pkg/config"
|
||||
"github.com/livekit/livekit-server/pkg/node"
|
||||
"github.com/livekit/livekit-server/proto"
|
||||
)
|
||||
|
||||
var ServiceSet = wire.NewSet(
|
||||
NewRoomService,
|
||||
NewRTCService,
|
||||
)
|
||||
|
||||
func NewRoomService(conf *config.Config, localNode *node.Node) (proto.RoomService, error) {
|
||||
if conf.MultiNode {
|
||||
return nil, fmt.Errorf("multinode is not supported")
|
||||
} else {
|
||||
return NewSimpleRoomService(localNode)
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,10 @@ package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
"sync"
|
||||
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
|
||||
"github.com/livekit/livekit-server/pkg/node"
|
||||
"github.com/livekit/livekit-server/proto"
|
||||
@@ -11,26 +15,53 @@ import (
|
||||
type SimpleRoomService struct {
|
||||
localNode *node.Node
|
||||
rooms map[string]bool
|
||||
roomLock sync.Mutex
|
||||
}
|
||||
|
||||
func NewRoomService(localNode *node.Node) (svc *SimpleRoomService, err error) {
|
||||
func NewSimpleRoomService(localNode *node.Node) (svc *SimpleRoomService, err error) {
|
||||
svc = &SimpleRoomService{
|
||||
localNode: localNode,
|
||||
rooms: make(map[string]bool),
|
||||
roomLock: sync.Mutex{},
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (s *SimpleRoomService) CreateRoom(ctx context.Context, req *proto.CreateRoomRequest) (res *proto.CreateRoomResponse, err error) {
|
||||
s.roomLock.Lock()
|
||||
defer s.roomLock.Unlock()
|
||||
|
||||
if s.rooms[req.Room] {
|
||||
err = status.Errorf(codes.AlreadyExists, "room %s already exists", req.Room)
|
||||
return
|
||||
}
|
||||
|
||||
s.rooms[req.Room] = true
|
||||
|
||||
res = &proto.CreateRoomResponse{
|
||||
Room: req.Room,
|
||||
NodeIp: s.localNode.Ip,
|
||||
NodeRtcPort: s.localNode.RtcPort,
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (s *SimpleRoomService) JoinRoom(ctx context.Context, req *proto.JoinRoomRequest) (res *proto.JoinRoomResponse, err error) {
|
||||
if !s.rooms[req.Room] {
|
||||
err = status.Errorf(codes.NotFound, "room %s does not exist", req.Room)
|
||||
return
|
||||
}
|
||||
|
||||
res = &proto.JoinRoomResponse{
|
||||
NodeIp: s.localNode.Ip,
|
||||
NodeRtcPort: s.localNode.RtcPort,
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (s *SimpleRoomService) DeleteRoom(ctx context.Context, req *proto.DeleteRoomRequest) (res *proto.DeleteRoomResponse, err error) {
|
||||
delete(s.rooms, req.Room)
|
||||
res = &proto.DeleteRoomResponse{}
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user