fixed localrouter timeout, updated VideoGrant fields

This commit is contained in:
David Zhao
2021-01-24 12:52:40 -08:00
parent 18264e7a8b
commit c4fb1b3808
5 changed files with 22 additions and 5 deletions
+13 -1
View File
@@ -2,11 +2,12 @@ package routing
import (
"sync"
"time"
"github.com/livekit/livekit-server/proto/livekit"
)
// a router of messages
// a router of messages on the same node, basic implementation for local testing
type LocalRouter struct {
currentNode LocalNode
lock sync.RWMutex
@@ -68,7 +69,9 @@ func (r *LocalRouter) StartParticipant(roomName, participantId, participantName
roomName,
participantId,
participantName,
// request source
r.getOrCreateMessageChannel(r.requestChannels, participantId),
// response sink
r.getOrCreateMessageChannel(r.responseChannels, participantId),
)
return nil
@@ -93,6 +96,7 @@ func (r *LocalRouter) OnNewParticipant(callback ParticipantCallback) {
}
func (r *LocalRouter) Start() error {
go r.statsWorker()
// on local routers, Start doesn't do anything, websocket connections initiate the connections
return nil
}
@@ -100,6 +104,14 @@ func (r *LocalRouter) Start() error {
func (r *LocalRouter) Stop() {
}
func (r *LocalRouter) statsWorker() {
for {
// update every 10 seconds
<-time.After(statsUpdateInterval)
r.currentNode.Stats.UpdatedAt = time.Now().Unix()
}
}
func (r *LocalRouter) getOrCreateMessageChannel(target map[string]*MessageChannel, participantId string) *MessageChannel {
r.lock.RLock()
mc := target[participantId]