Re-issue tokens when clients initially connect. (#569)
This ensures if they are disconnected before token is refreshed, they could reconnect back with a valid token.
This commit is contained in:
@@ -99,7 +99,7 @@ func (r *RedisRouter) SetNodeForRoom(_ context.Context, roomName livekit.RoomNam
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (r *RedisRouter) ClearRoomState(_ context.Context, roomName livekit.RoomName) error {
|
func (r *RedisRouter) ClearRoomState(_ context.Context, roomName livekit.RoomName) error {
|
||||||
if err := r.rc.HDel(r.ctx, NodeRoomKey, string(roomName)).Err(); err != nil {
|
if err := r.rc.HDel(context.Background(), NodeRoomKey, string(roomName)).Err(); err != nil {
|
||||||
return errors.Wrap(err, "could not clear room state")
|
return errors.Wrap(err, "could not clear room state")
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
+11
-10
@@ -394,22 +394,23 @@ func (r *RoomManager) rtcSessionWorker(room *rtc.Room, participant types.LocalPa
|
|||||||
participant.Identity(), participant.ID(),
|
participant.Identity(), participant.ID(),
|
||||||
)
|
)
|
||||||
|
|
||||||
lastTokenUpdate := time.Now()
|
// send first refresh for cases when client token is close to expiring
|
||||||
|
_ = r.refreshToken(participant)
|
||||||
|
tokenTicker := time.NewTicker(tokenRefreshInterval)
|
||||||
|
defer tokenTicker.Stop()
|
||||||
|
stateCheckTicker := time.NewTicker(time.Millisecond * 50)
|
||||||
|
defer stateCheckTicker.Stop()
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-time.After(time.Millisecond * 50):
|
case <-stateCheckTicker.C:
|
||||||
// periodic check to ensure participant didn't become disconnected
|
// periodic check to ensure participant didn't become disconnected
|
||||||
if participant.State() == livekit.ParticipantInfo_DISCONNECTED {
|
if participant.State() == livekit.ParticipantInfo_DISCONNECTED {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
case <-tokenTicker.C:
|
||||||
if time.Since(lastTokenUpdate) > tokenRefreshInterval {
|
// refresh token with the first API Key/secret pair
|
||||||
pLogger.Debugw("refreshing client token after interval")
|
if err := r.refreshToken(participant); err != nil {
|
||||||
// refresh token with the first API Key/secret pair
|
pLogger.Errorw("could not refresh token", err)
|
||||||
if err := r.refreshToken(participant); err != nil {
|
|
||||||
pLogger.Errorw("could not refresh token", err)
|
|
||||||
}
|
|
||||||
lastTokenUpdate = time.Now()
|
|
||||||
}
|
}
|
||||||
case obj := <-requestSource.ReadChan():
|
case obj := <-requestSource.ReadChan():
|
||||||
// In single node mode, the request source is directly tied to the signal message channel
|
// In single node mode, the request source is directly tied to the signal message channel
|
||||||
|
|||||||
Reference in New Issue
Block a user