How can I implement a breakout room with livekit i...
# ask-ai
p
How can I implement a breakout room with livekit in nextjs ?
t
Thanks for reaching out, Yassine. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
You're asking how to implement breakout rooms with LiveKit in a Next.js app — below is a concise, practical approach you can follow. 1) Install SDKs • npm install livekit-server-sdk @livekit/components-react @livekit/components-styles 2) Env vars (in .env.local) • LIVEKIT_API_KEY, LIVEKIT_API_SECRET, LIVEKIT_URL, NEXT_PUBLIC_LIVEKIT_URL 3) Token endpoint (Next.js API route) • Create an API route that issues JWT access tokens scoped to a room and identity using
AccessToken
. Ensure the token grants
roomJoin
and the appropriate publish/subscribe permissions. 4) Create breakout rooms server-side • Use
RoomServiceClient
to create rooms programmatically: ◦ set
name
, optional
emptyTimeout
,
maxParticipants
as needed. 5) Move participants between rooms • Use the
MoveParticipant
API via
RoomServiceClient
to move an identity from the main room to a breakout room (and back when done). 6) Frontend (Next.js + React) • Fetch a token from your API for the target room, then connect with LiveKit React components (e.g.,
LiveKitRoom
/
VideoConference
) using
serverUrl
and the token. • Provide UI buttons to request backend actions for creating breakout rooms and moving participants. 7) Key considerations • Generate separate tokens scoped to each breakout room so permissions are enforced per room. • Add server authorization checks (who can create rooms or move participants). • Clean up empty breakout rooms (configure
emptyTimeout
or delete when done). If you’d like, I can: • Provide a ready-to-use code snippet for the Next.js API token route. • Show the exact
RoomServiceClient
calls for creating rooms and moving participants. • Suggest a minimal UI flow for admins to create/move/close breakout rooms. Which of those would you like next? Sources: Managing rooms | LiveKit docs | Managing participants | LiveKit docs | Authentication | LiveKit docs | Next.js quickstart | LiveKit docs
p
From the main room can i listen to the tracks of the sub room? I mean can I move the participants and return them from the main room?
t
Regarding your questions about main room vs. breakout (sub) rooms: • You cannot directly listen to media published inside one room from another room. Rooms are isolated; tracks are only available to participants in the room where they were published. • You can move participants between rooms using the
MoveParticipant
API — when moved, their tracks follow them and become available in the destination room. You can move them back the same way. • If you want to hear a participant in the main room without moving them, LiveKit Cloud supports a ForwardParticipant feature that forwards a participant’s tracks to another room (e.g., the main room) until forwarding is stopped. Which behavior do you want to implement: moving participants, forwarding tracks, or both? I can provide the exact server-side calls and a Next.js code example for the option you choose. Sources: Rooms, participants, and tracks | LiveKit docs | Managing participants | LiveKit docs | Agent-assisted warm transfer | LiveKit docs
p
What is the forwarded participants
t
A forwarded participant is a participant whose published media (audio/video) from one room is shared into another room without physically moving that participant. Forwarding lets you make someone’s tracks available in a different room while they remain connected to their original room. How it works • A server-side action enables forwarding for a given participant from a source room to a destination room. • The participant stays in the source room and continues publishing there. • The destination room receives the participant’s tracks as if that participant were present in that room. • Forwarding can be stopped to remove the forwarded tracks from the destination room. Common use cases • Moderators in a main room monitoring breakout room audio/video. • Broadcasting a presenter’s feed into multiple rooms without reconnecting them. • Recording or streaming a single participant into another room for a specific audience. Notes and limitations • Forwarded tracks are available only while forwarding is active; they aren’t a permanent copy. • Forwarding is a server-side feature (LiveKit Cloud / enabled deployments) and requires appropriate API calls/permissions. • If you prefer not to use forwarding, you can move participants between rooms with
MoveParticipant
so their tracks become available only in the room they join. Would you like the exact server API call and a Next.js code example to enable forwarding?