switched to Twirp for RPC, server skaffold
This commit is contained in:
@@ -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