fixed multi-node so signal node can start sessions
This commit is contained in:
+1
-1
@@ -157,7 +157,7 @@ func Test() error {
|
|||||||
// run all thests including integration
|
// run all thests including integration
|
||||||
func TestAll() error {
|
func TestAll() error {
|
||||||
mg.Deps(Proto)
|
mg.Deps(Proto)
|
||||||
cmd := exec.Command("go", "test", "./...", "-count=1")
|
cmd := exec.Command("go", "test", "./...", "-count=1", "-timeout=1m")
|
||||||
connectStd(cmd)
|
connectStd(cmd)
|
||||||
return cmd.Run()
|
return cmd.Run()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ var (
|
|||||||
ErrNotFound = errors.New("could not find object")
|
ErrNotFound = errors.New("could not find object")
|
||||||
ErrHandlerNotDefined = errors.New("handler not defined")
|
ErrHandlerNotDefined = errors.New("handler not defined")
|
||||||
ErrNoAvailableNodes = errors.New("could not find any available nodes")
|
ErrNoAvailableNodes = errors.New("could not find any available nodes")
|
||||||
ErrIncorrectNodeForRoom = errors.New("incorrect node for the current room")
|
|
||||||
errInvalidRouterMessage = errors.New("invalid router message")
|
errInvalidRouterMessage = errors.New("invalid router message")
|
||||||
ErrChannelClosed = errors.New("channel closed")
|
ErrChannelClosed = errors.New("channel closed")
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -161,12 +161,7 @@ func (r *RedisRouter) StartParticipant(roomName, participantId, participantName
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// StartParticipant should only be called on the current node
|
if r.useLocal && rtcNode == r.currentNode.Id {
|
||||||
if rtcNode != r.currentNode.Id {
|
|
||||||
return ErrIncorrectNodeForRoom
|
|
||||||
}
|
|
||||||
|
|
||||||
if r.useLocal {
|
|
||||||
return r.LocalRouter.StartParticipant(roomName, participantId, participantId)
|
return r.LocalRouter.StartParticipant(roomName, participantId, participantId)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -282,7 +277,6 @@ func (r *RedisRouter) subscribeWorker() {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.Debugw("received redis message", "message", msg, "node", r.currentNode.Id)
|
|
||||||
rm := livekit.RouterMessage{}
|
rm := livekit.RouterMessage{}
|
||||||
err = proto.Unmarshal([]byte(msg.Payload), &rm)
|
err = proto.Unmarshal([]byte(msg.Payload), &rm)
|
||||||
pId := rm.ParticipantId
|
pId := rm.ParticipantId
|
||||||
|
|||||||
@@ -109,7 +109,7 @@ func NewParticipant(participantId, name string, pc types.PeerConnection, rs rout
|
|||||||
ci := c.ToJSON()
|
ci := c.ToJSON()
|
||||||
|
|
||||||
// write candidate
|
// write candidate
|
||||||
logger.Debugw("sending ice candidates")
|
//logger.Debugw("sending ice candidates")
|
||||||
err := rs.WriteMessage(&livekit.SignalResponse{
|
err := rs.WriteMessage(&livekit.SignalResponse{
|
||||||
Message: &livekit.SignalResponse_Trickle{
|
Message: &livekit.SignalResponse_Trickle{
|
||||||
Trickle: ToProtoTrickle(ci),
|
Trickle: ToProtoTrickle(ci),
|
||||||
|
|||||||
@@ -54,7 +54,8 @@ func (r *RoomManager) CreateRoom(req *livekit.CreateRoomRequest) (*livekit.Room,
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if req.NodeId == "" {
|
nodeId := req.NodeId
|
||||||
|
if nodeId == "" {
|
||||||
// select a node for room
|
// select a node for room
|
||||||
nodes, err := r.router.ListNodes()
|
nodes, err := r.router.ListNodes()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -65,10 +66,11 @@ func (r *RoomManager) CreateRoom(req *livekit.CreateRoomRequest) (*livekit.Room,
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
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
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -131,6 +133,7 @@ func (r *RoomManager) StartSession(roomName, participantId, participantName stri
|
|||||||
|
|
||||||
logger.Debugw("starting RTC session",
|
logger.Debugw("starting RTC session",
|
||||||
"room", roomName,
|
"room", roomName,
|
||||||
|
"node", r.currentNode.Id,
|
||||||
"participant", participantName,
|
"participant", participantName,
|
||||||
"num_participants", len(room.GetParticipants()),
|
"num_participants", len(room.GetParticipants()),
|
||||||
)
|
)
|
||||||
@@ -201,7 +204,6 @@ func (r *RoomManager) rtcSessionWorker(room *rtc.Room, participant types.Partici
|
|||||||
}()
|
}()
|
||||||
defer rtc.Recover()
|
defer rtc.Recover()
|
||||||
|
|
||||||
logger.Debugw("starting RTC session", "node", r.currentNode.Id)
|
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-time.After(time.Millisecond * 100):
|
case <-time.After(time.Millisecond * 100):
|
||||||
|
|||||||
+24
-25
@@ -70,6 +70,30 @@ func (s *RTCService) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
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
|
// upgrade only once the basics are good to go
|
||||||
conn, err := s.upgrader.Upgrade(w, r, nil)
|
conn, err := s.upgrader.Upgrade(w, r, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -79,39 +103,14 @@ func (s *RTCService) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
handleError(w, http.StatusInternalServerError, err.Error())
|
handleError(w, http.StatusInternalServerError, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
sigConn := NewWSSignalConnection(conn)
|
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",
|
logger.Infow("new client connected",
|
||||||
"room", rm.Sid,
|
"room", rm.Sid,
|
||||||
"roomName", rm.Name,
|
"roomName", rm.Name,
|
||||||
"name", pName,
|
"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
|
// handle responses
|
||||||
go func() {
|
go func() {
|
||||||
for {
|
for {
|
||||||
|
|||||||
@@ -115,10 +115,10 @@ func waitUntilConnected(t *testing.T, clients ...*client.RTCClient) {
|
|||||||
c := clients[i]
|
c := clients[i]
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
go func() {
|
go func() {
|
||||||
|
defer wg.Done()
|
||||||
if !assert.NoError(t, c.WaitUntilConnected()) {
|
if !assert.NoError(t, c.WaitUntilConnected()) {
|
||||||
t.Fatal("one or more clients could not connect")
|
t.Fatal("one or more clients could not connect")
|
||||||
}
|
}
|
||||||
wg.Done()
|
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
|
|||||||
@@ -31,13 +31,15 @@ func TestMultiNodeRouting(t *testing.T) {
|
|||||||
|
|
||||||
// one node connecting to node 1, and another connecting to node 2
|
// one node connecting to node 1, and another connecting to node 2
|
||||||
c1 := createRTCClient("c1", defaultServerPort)
|
c1 := createRTCClient("c1", defaultServerPort)
|
||||||
c2 := createRTCClient("c2", defaultServerPort)
|
c2 := createRTCClient("c2", secondServerPort)
|
||||||
waitUntilConnected(t, c1, c2)
|
waitUntilConnected(t, c1, c2)
|
||||||
|
|
||||||
// c1 publishing, and c2 receiving
|
// c1 publishing, and c2 receiving
|
||||||
t1, err := c1.AddStaticTrack("audio/opus", "audio", "webcam")
|
t1, err := c1.AddStaticTrack("audio/opus", "audio", "webcam")
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
defer t1.Stop()
|
if t1 != nil {
|
||||||
|
defer t1.Stop()
|
||||||
|
}
|
||||||
|
|
||||||
withTimeout(t, "c2 should receive one track", func() bool {
|
withTimeout(t, "c2 should receive one track", func() bool {
|
||||||
if len(c2.SubscribedTracks()) == 0 {
|
if len(c2.SubscribedTracks()) == 0 {
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
package test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
// a scenario with lots of clients connecting, publishing, and leaving at random periods
|
||||||
|
func scenarioRandom(t *testing.T) {
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user