Preserve original expiry when refreshing token (#4580)

To avoid shortening the token expiration time during
refreshing cause client reconnect failed after network
down for a long time (>5min).
This commit is contained in:
cnderrauber
2026-06-10 14:51:10 +08:00
committed by GitHub
parent 8d2b827f44
commit 7dc6877738
10 changed files with 125 additions and 9 deletions
+11 -1
View File
@@ -489,6 +489,7 @@ func (r *RoomManager) StartSession(
PublishEnabledCodecs: enabledCodecs,
SubscribeEnabledCodecs: enabledCodecs,
Grants: pi.Grants,
TokenExpiresAt: pi.TokenExpiresAt,
Reconnect: pi.Reconnect,
Logger: pLogger,
Reporter: roomobs.NewNoopParticipantSessionReporter(),
@@ -1124,11 +1125,20 @@ func (r *RoomManager) refreshToken(participant types.LocalParticipant) error {
}
grants := participant.ClaimGrants()
// Preserve the original token's expiry
validFor := tokenDefaultTTL
if expiresAt := participant.TokenExpiresAt(); !expiresAt.IsZero() {
if remaining := time.Until(expiresAt); remaining > validFor {
validFor = remaining
}
}
token := auth.NewAccessToken(key, secret)
token.SetName(grants.Name).
SetIdentity(string(participant.Identity())).
SetKind(grants.GetParticipantKind()).
SetValidFor(tokenDefaultTTL).
SetValidFor(validFor).
SetMetadata(grants.Metadata).
SetAttributes(grants.Attributes).
SetVideoGrant(grants.Video).