Skip to content

Add maxDuration prop to <LiveKitRoom /> to automatically disconnect users after a fixed time #274

@emma-smashvision

Description

@emma-smashvision

Is your feature request related to a problem? Please describe.

I'm building a livestreaming feature using the LiveKitRoom React component. For sessions like sports matches, we want to enforce a maximum stream duration (e.g. 4 hours).

Right now, there's no built-in way to enforce a max session length from the frontend. Now I have to rely on manually setting setTimeout and handling disconnections outside of the LiveKit lifecycle, which feels fragile and easy to bypass or forget.

Describe the solution you'd like

I'd love to see support for a new maxDuration prop in , which would automatically disconnect the participant after a given time (in milliseconds), starting from when the room is connected.

For example:

<LiveKitRoom
  token={livekitToken}
  serverUrl={LIVEKIT_SERVER_URL}
  connect={true}
  maxDuration={4 * 60 * 60 * 1000} // 4 hours
/>

It would be helpful if this also triggered an optional callback, e.g. onMaxDurationReached.

Describe alternatives you've considered

We’ve implemented this manually using a setTimeout in a useEffect, like this:

useEffect(() => {
  const timeout = setTimeout(() => {
    room.disconnect();
    alert('Stream ended after 4 hours');
  }, 4 * 60 * 60 * 1000);
  return () => clearTimeout(timeout);
}, []);

But this is disconnected from the LiveKitRoom lifecycle, requires manual cleanup, and can't be enforced reliably if multiple rooms are used or context is lost.

Another backend-side workaround we’ve explored is to track the stream start time and call the LiveKit REST API’s DELETE /rooms/{room} endpoint after 4 hours. This does successfully disconnect all participants, but it requires additional infrastructure and doesn’t integrate directly with frontend session logic.

We also use .with_ttl() on token generation to limit reconnection after expiry — but this doesn't affect already connected users.

Additional context

This would be useful in any scenario where streams or calls have a contractual or time-based limit — livestreams, therapy sessions, teaching, or time-boxed meetings.

Love the work you’re doing — and thanks in advance for considering this!

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions