Issue updated tokens to clients. (#365)

This ensures client reconnect attempts would be successful for long running rooms. It also fixes inaccurate permissions that were set incorrectly when full reconnections take place.
This commit is contained in:
David Zhao authored and GitHub committed 2022-01-23 23:15:49 -08:00
1 parent 6a46958870
commit 52fc53d325
13 files changed
+356 -15

No files matched your search

+2
View File
@@ -4,6 +4,7 @@ import (
"context"
"github.com/go-redis/redis/v8"
"github.com/livekit/protocol/auth"
"github.com/livekit/protocol/livekit"
"github.com/livekit/protocol/logger"
"google.golang.org/protobuf/proto"
@@ -36,6 +37,7 @@ type ParticipantInit struct {
Hidden bool
Recorder bool
Client *livekit.ClientInfo
Grants *auth.ClaimGrants
}
type NewParticipantCallback func(ctx context.Context, roomName livekit.RoomName, pi ParticipantInit, requestSource MessageSource, responseSink MessageSink)
+15
View File
@@ -2,9 +2,11 @@ package routing
import (
"context"
"encoding/json"
"time"
"github.com/go-redis/redis/v8"
"github.com/livekit/protocol/auth"
"github.com/livekit/protocol/livekit"
"github.com/livekit/protocol/logger"
"github.com/livekit/protocol/utils"
@@ -146,6 +148,12 @@ func (r *RedisRouter) StartParticipantSignal(ctx context.Context, roomName livek
sink := NewRTCNodeSink(r.rc, rtcNode.Id, pKey)
// serialize claims
claims, err := json.Marshal(pi.Grants)
if err != nil {
return
}
// sends a message to start session
err = sink.WriteMessage(&livekit.StartSession{
RoomName: string(roomName),
@@ -160,6 +168,7 @@ func (r *RedisRouter) StartParticipantSignal(ctx context.Context, roomName livek
Hidden: pi.Hidden,
Recorder: pi.Recorder,
Client: pi.Client,
GrantsJson: string(claims),
})
if err != nil {
return
@@ -238,6 +247,11 @@ func (r *RedisRouter) startParticipantRTC(ss *livekit.StartSession, participantK
}
}
claims := &auth.ClaimGrants{}
if err := json.Unmarshal([]byte(ss.GrantsJson), claims); err != nil {
return err
}
pi := ParticipantInit{
Identity: livekit.ParticipantIdentity(ss.Identity),
Metadata: ss.Metadata,
@@ -248,6 +262,7 @@ func (r *RedisRouter) startParticipantRTC(ss *livekit.StartSession, participantK
AutoSubscribe: ss.AutoSubscribe,
Hidden: ss.Hidden,
Recorder: ss.Recorder,
Grants: claims,
}
reqChan := r.getOrCreateMessageChannel(r.requestChannels, participantKey)