separated join from creation, room options & token

This commit is contained in:
David Zhao
2020-10-07 23:54:44 -07:00
parent 37984bd167
commit 6752c4a91d
13 changed files with 1127 additions and 757 deletions
+3 -3
View File
@@ -6,7 +6,7 @@ import (
"github.com/pion/stun"
"github.com/livekit/livekit-server/pkg/config"
"github.com/livekit/livekit-server/proto"
"github.com/livekit/livekit-server/proto/livekit"
)
const (
@@ -16,7 +16,7 @@ const (
var NodeSet = wire.NewSet(NewLocalNode)
type Node struct {
proto.Node
livekit.Node
}
type NodeStats struct {
@@ -33,7 +33,7 @@ func NewLocalNode(conf *config.Config) (*Node, error) {
return nil, err
}
n := &Node{
Node: proto.Node{
Node: livekit.Node{
Id: id.String(),
RtcPort: conf.RTCPort,
},
+33
View File
@@ -0,0 +1,33 @@
package rooms
import (
"time"
"github.com/google/uuid"
"github.com/livekit/livekit-server/proto/livekit"
)
func NewRoomForRequest(req *livekit.CreateRoomRequest) (*livekit.Room, error) {
id, err := uuid.NewRandom()
if err != nil {
return nil, err
}
return &livekit.Room{
RoomId: req.RoomId,
EmptyTimeout: req.EmptyTimeout,
MaxParticipants: req.MaxParticipants,
CreationTime: time.Now().Unix(),
Token: id.String(),
}, nil
}
func ToRoomInfo(node *livekit.Node, room *livekit.Room) *livekit.RoomInfo {
return &livekit.RoomInfo{
RoomId: room.RoomId,
NodeIp: node.Ip,
NodeRtcPort: node.RtcPort,
CreationTime: room.CreationTime,
Token: room.Token,
}
}
+7 -3
View File
@@ -4,17 +4,21 @@ import (
"context"
"net/http"
"github.com/livekit/livekit-server/proto"
"github.com/livekit/livekit-server/proto/livekit"
)
type RTCService struct {
}
func (s *RTCService) Offer(ctx context.Context, offer *proto.SessionDescription) (answer *proto.SessionDescription, err error) {
func (s *RTCService) Join(ctx context.Context, req *livekit.JoinRequest) (res *livekit.JoinResponse, err error) {
return
}
func (s *RTCService) Trickle(ctx context.Context, req *proto.TrickleRequest) (res *proto.TrickleResponse, err error) {
func (s *RTCService) Offer(ctx context.Context, offer *livekit.SessionDescription) (answer *livekit.SessionDescription, err error) {
return
}
func (s *RTCService) Trickle(ctx context.Context, req *livekit.TrickleRequest) (res *livekit.TrickleResponse, err error) {
return
}
+2 -2
View File
@@ -7,7 +7,7 @@ import (
"github.com/livekit/livekit-server/pkg/config"
"github.com/livekit/livekit-server/pkg/node"
"github.com/livekit/livekit-server/proto"
"github.com/livekit/livekit-server/proto/livekit"
)
var ServiceSet = wire.NewSet(
@@ -15,7 +15,7 @@ var ServiceSet = wire.NewSet(
NewRTCService,
)
func NewRoomService(conf *config.Config, localNode *node.Node) (proto.RoomService, error) {
func NewRoomService(conf *config.Config, localNode *node.Node) (livekit.RoomService, error) {
if conf.MultiNode {
return nil, fmt.Errorf("multinode is not supported")
} else {
+22 -23
View File
@@ -7,60 +7,59 @@ import (
"github.com/twitchtv/twirp"
"github.com/livekit/livekit-server/pkg/node"
"github.com/livekit/livekit-server/proto"
"github.com/livekit/livekit-server/pkg/rooms"
"github.com/livekit/livekit-server/proto/livekit"
)
// A room service that supports a single node
// A rooms service that supports a single node
type SimpleRoomService struct {
localNode *node.Node
rooms map[string]bool
rooms map[string]*livekit.Room
roomLock sync.Mutex
}
func NewSimpleRoomService(localNode *node.Node) (svc *SimpleRoomService, err error) {
svc = &SimpleRoomService{
localNode: localNode,
rooms: make(map[string]bool),
rooms: make(map[string]*livekit.Room),
roomLock: sync.Mutex{},
}
return
}
func (s *SimpleRoomService) CreateRoom(ctx context.Context, req *proto.CreateRoomRequest) (res *proto.CreateRoomResponse, err error) {
func (s *SimpleRoomService) CreateRoom(ctx context.Context, req *livekit.CreateRoomRequest) (res *livekit.RoomInfo, err error) {
s.roomLock.Lock()
defer s.roomLock.Unlock()
if s.rooms[req.Room] {
err = twirp.NewError(twirp.AlreadyExists, "room already exists")
if s.rooms[req.RoomId] != nil {
err = twirp.NewError(twirp.AlreadyExists, "rooms already exists")
return
}
s.rooms[req.Room] = true
res = &proto.CreateRoomResponse{
Room: req.Room,
NodeIp: s.localNode.Ip,
NodeRtcPort: s.localNode.RtcPort,
room, err := rooms.NewRoomForRequest(req)
if err != nil {
return
}
s.rooms[req.RoomId] = room
res = rooms.ToRoomInfo(&s.localNode.Node, room)
return
}
func (s *SimpleRoomService) JoinRoom(ctx context.Context, req *proto.JoinRoomRequest) (res *proto.JoinRoomResponse, err error) {
if !s.rooms[req.Room] {
err = twirp.NewError(twirp.AlreadyExists, "the room does not exist")
func (s *SimpleRoomService) GetRoom(ctx context.Context, req *livekit.GetRoomRequest) (res *livekit.RoomInfo, err error) {
room := s.rooms[req.RoomId]
if room == nil {
err = twirp.NewError(twirp.NotFound, "the rooms does not exist")
return
}
res = &proto.JoinRoomResponse{
NodeIp: s.localNode.Ip,
NodeRtcPort: s.localNode.RtcPort,
}
res = rooms.ToRoomInfo(&s.localNode.Node, room)
return
}
func (s *SimpleRoomService) DeleteRoom(ctx context.Context, req *proto.DeleteRoomRequest) (res *proto.DeleteRoomResponse, err error) {
delete(s.rooms, req.Room)
res = &proto.DeleteRoomResponse{}
func (s *SimpleRoomService) DeleteRoom(ctx context.Context, req *livekit.DeleteRoomRequest) (res *livekit.DeleteRoomResponse, err error) {
delete(s.rooms, req.RoomId)
res = &livekit.DeleteRoomResponse{}
return
}