fixed multi-node so signal node can start sessions
This commit is contained in:
@@ -54,7 +54,8 @@ func (r *RoomManager) CreateRoom(req *livekit.CreateRoomRequest) (*livekit.Room,
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if req.NodeId == "" {
|
||||
nodeId := req.NodeId
|
||||
if nodeId == "" {
|
||||
// select a node for room
|
||||
nodes, err := r.router.ListNodes()
|
||||
if err != nil {
|
||||
@@ -65,10 +66,11 @@ func (r *RoomManager) CreateRoom(req *livekit.CreateRoomRequest) (*livekit.Room,
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
req.NodeId = node.Id
|
||||
nodeId = node.Id
|
||||
}
|
||||
|
||||
if err := r.router.SetNodeForRoom(req.Name, req.NodeId); err != nil {
|
||||
logger.Debugw("selected node for room", "room", rm.Name, "node", nodeId)
|
||||
if err := r.router.SetNodeForRoom(req.Name, nodeId); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -131,6 +133,7 @@ func (r *RoomManager) StartSession(roomName, participantId, participantName stri
|
||||
|
||||
logger.Debugw("starting RTC session",
|
||||
"room", roomName,
|
||||
"node", r.currentNode.Id,
|
||||
"participant", participantName,
|
||||
"num_participants", len(room.GetParticipants()),
|
||||
)
|
||||
@@ -201,7 +204,6 @@ func (r *RoomManager) rtcSessionWorker(room *rtc.Room, participant types.Partici
|
||||
}()
|
||||
defer rtc.Recover()
|
||||
|
||||
logger.Debugw("starting RTC session", "node", r.currentNode.Id)
|
||||
for {
|
||||
select {
|
||||
case <-time.After(time.Millisecond * 100):
|
||||
|
||||
+24
-25
@@ -70,6 +70,30 @@ func (s *RTCService) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
participantId := utils.NewGuid(utils.ParticipantPrefix)
|
||||
err = s.router.StartParticipant(roomName, participantId, pName)
|
||||
if err != nil {
|
||||
handleError(w, http.StatusInternalServerError, "could not start session: "+err.Error())
|
||||
return
|
||||
}
|
||||
reqSink, err := s.router.GetRequestSink(participantId)
|
||||
if err != nil {
|
||||
handleError(w, http.StatusInternalServerError, "could not get request sink"+err.Error())
|
||||
return
|
||||
}
|
||||
done := make(chan bool, 1)
|
||||
defer func() {
|
||||
logger.Infow("WS connection closed", "participant", pName)
|
||||
reqSink.Close()
|
||||
close(done)
|
||||
}()
|
||||
|
||||
resSource, err := s.router.GetResponseSource(participantId)
|
||||
if err != nil {
|
||||
handleError(w, http.StatusInternalServerError, "could not get response source"+err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
// upgrade only once the basics are good to go
|
||||
conn, err := s.upgrader.Upgrade(w, r, nil)
|
||||
if err != nil {
|
||||
@@ -79,39 +103,14 @@ func (s *RTCService) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
handleError(w, http.StatusInternalServerError, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
sigConn := NewWSSignalConnection(conn)
|
||||
|
||||
participantId := utils.NewGuid(utils.ParticipantPrefix)
|
||||
err = s.router.StartParticipant(roomName, participantId, pName)
|
||||
if err != nil {
|
||||
handleError(w, http.StatusInternalServerError, "could not start session: "+err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
logger.Infow("new client connected",
|
||||
"room", rm.Sid,
|
||||
"roomName", rm.Name,
|
||||
"name", pName,
|
||||
)
|
||||
|
||||
reqSink, err := s.router.GetRequestSink(participantId)
|
||||
if err != nil {
|
||||
handleError(w, http.StatusInternalServerError, "could not get request sink"+err.Error())
|
||||
return
|
||||
}
|
||||
resSource, err := s.router.GetResponseSource(participantId)
|
||||
if err != nil {
|
||||
handleError(w, http.StatusInternalServerError, "could not get response source"+err.Error())
|
||||
return
|
||||
}
|
||||
done := make(chan bool, 1)
|
||||
defer func() {
|
||||
logger.Infow("WS connection closed", "participant", pName)
|
||||
reqSink.Close()
|
||||
close(done)
|
||||
}()
|
||||
|
||||
// handle responses
|
||||
go func() {
|
||||
for {
|
||||
|
||||
Reference in New Issue
Block a user