Skip to content

feat(room): emit RoomEvent.TokenRefreshed when the server issues a new token - #2200

Open
ninglinLiu wants to merge 2 commits into
livekit:mainfrom
ninglinLiu:feat/room-token-refreshed-event
Open

ninglinLiu wants to merge 2 commits into
livekit:mainfrom
ninglinLiu:feat/room-token-refreshed-event

Conversation

@ninglinLiu

Copy link
Copy Markdown
Contributor

Closes #2199

Problem

The server refreshes the local participant's access token periodically and after attribute or permission changes (and sends a new one on room moves). The SDK stores it in RTCEngine and uses it for resumes and full reconnects, but applications can only observe it through room.engine.on(EngineEvent.TokenRefreshed, …), and Room.engine is @internal and EngineEvent is not exported. The engine event is also re-emitted with the token it already holds before every reconnect attempt, so a listener has to deduplicate.

Change

  • New public RoomEvent.TokenRefreshed (tokenRefreshed: (token: string) => void in RoomEventCallbacks).
  • CoreRoom keeps the latest token for the local participant (set from the token passed to connect(), updated on every new server-issued token) and forwards EngineEvent.TokenRefreshed only when the token differs, so the reconnect re-emits do not surface as refreshes.
  • The existing regionUrlProvider.updateToken call is unchanged.

Tests

Room.test.ts: re-emitting the join token or the same refreshed token does not fire the event; each new token fires it once. vitest run src/room/Room.test.ts (23 passed), tsc --noEmit, eslint and prettier pass. Includes a minor changeset (new public API).

This PR was prepared with AI assistance and reviewed/tested by the author.

@changeset-bot

changeset-bot Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: fbd0706

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
livekit-client Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔍 Devin Review: 1 flag

Not posted on this PR by your GitHub settings — view it in Devin Review. (Configure)

Devin Review

@1egoman

1egoman commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

@lukasIO I would be curious your take on this. As part of the FrameProcessor work in python/node we had an opportunity to expose refresh tokens from Room and I remember you were against it there, but I don't remember the exact context, so we opted to reach into a room private api to get the token.

This seems like a similar type of change only applied to the web sdk. Can you go into those concerns again here? As is this looks good to me assuming the premise of exposing an updated token via a public api interface is ok.

@lukasIO

lukasIO commented Oct 28, 2026

Copy link
Copy Markdown
Contributor

@1egoman let's keep the discussion in the related issue

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Expose the server-refreshed token as a public RoomEvent

3 participants