mirror of
https://github.com/livekit/livekit.git
synced 2026-03-30 17:45:40 +00:00
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 {
|
||||
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 nil
|
||||
|
||||
@@ -394,22 +394,23 @@ func (r *RoomManager) rtcSessionWorker(room *rtc.Room, participant types.LocalPa
|
||||
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 {
|
||||
select {
|
||||
case <-time.After(time.Millisecond * 50):
|
||||
case <-stateCheckTicker.C:
|
||||
// periodic check to ensure participant didn't become disconnected
|
||||
if participant.State() == livekit.ParticipantInfo_DISCONNECTED {
|
||||
return
|
||||
}
|
||||
|
||||
if time.Since(lastTokenUpdate) > tokenRefreshInterval {
|
||||
pLogger.Debugw("refreshing client token after interval")
|
||||
// refresh token with the first API Key/secret pair
|
||||
if err := r.refreshToken(participant); err != nil {
|
||||
pLogger.Errorw("could not refresh token", err)
|
||||
}
|
||||
lastTokenUpdate = time.Now()
|
||||
case <-tokenTicker.C:
|
||||
// refresh token with the first API Key/secret pair
|
||||
if err := r.refreshToken(participant); err != nil {
|
||||
pLogger.Errorw("could not refresh token", err)
|
||||
}
|
||||
case obj := <-requestSource.ReadChan():
|
||||
// In single node mode, the request source is directly tied to the signal message channel
|
||||
|
||||
Reference in New Issue
Block a user