Skip to main content

Waiting rooms and breakout rooms

Markdown

Guests wait in a lobby until the host admits them, and during the meeting the host sends people to smaller rooms and brings them back. Both are a rule and a few routes of yours: the lobby is a presence room the host watches, each room is a group call your route gives a token for to whom you chose, and your server tells each page where to go.

In your stack: Next.js · Express · Laravel · PHP · Django · FastAPI · Flask · WordPress

Who may be where​

Three places, each named after the meeting: the lobby lobby:5, where guests wait, the meeting meeting:5, and its breakout rooms meeting:5:breakout:1, meeting:5:breakout:2 and so on.

The lobby is a room, so a rule of your server lets a page in: a function your server registers once for every room whose name fits lobby:{id}. The meeting and its breakout rooms are group calls, which start from a token: the page asks a route of yours for one as it joins, and your route makes your own check, then answers a token for that room, or 403. They say:

  1. The lobby lets in anyone signed in, and the host sees who waits.
  2. The meeting lets in its host and the guests the host admitted.
  3. A breakout room lets in the host, and those the host sent there.

The host hosts each of them, with the buttons to mute or take someone out. isHostOf(), isAdmitted() and breakoutOf() are yours:

// 1. The lobby, such as lobby:5: anyone signed in waits there, and the host sees who.
realtime.room( 'lobby:{id}', ( user ) => user !== null, { presence: true } );

// Your route, GET /api/meeting-token?id=5, or &room=1 for a breakout room. Express here, the same in any framework.
app.get( '/api/meeting-token', async ( req, res ) => {
const me = userOf( req );
const { id, room } = req.query;
if ( ! me ) return res.sendStatus( 401 );
const host = await isHostOf( id, me );

// 2. The meeting, such as meeting:5: its host, and those the host admitted.
if ( ! room ) {
if ( ! host && ! ( await isAdmitted( id, me ) ) ) return res.sendStatus( 403 );
return res.json( { token: await realtime.groupCallToken( me, 'meeting:' + id, { admin: host } ) } );
}

// 3. A breakout room, such as meeting:5:breakout:1: the host, and those sent there.
if ( ! host && String( await breakoutOf( id, me ) ) !== String( room ) ) return res.sendStatus( 403 );
res.json( { token: await realtime.groupCallToken( me, `meeting:${ id }:breakout:${ room }`, { admin: host } ) } );
} );
  • A token is for one room: the name your route builds from the id and the room. The token of the meeting lets nobody into a breakout room.
  • On WordPress, its package decides who joins each group call by a rule of its own (WordPress group calls).

Admitting a guest​

The Admit button of the host calls a route of yours, which checks that the host asks, then:

  1. Keeps the choice where your token route reads it.
  2. Tells the guest, on every page and app they have open.
app.post( '/meetings/:id/admit', async ( req, res ) => {
// Only the host of the meeting.
if ( !( await isHostOf( req.params.id, req.user.id ) ) ) return res.sendStatus( 403 );

// 1. Kept for whom the meeting lets in.
await admit( req.params.id, req.body.user );

// 2. The guest told.
await realtime.toUser( req.body.user ).emit( 'admitted', { meeting: req.params.id } );
res.sendStatus( 204 );
} );

The page of the guest waits in the lobby, and joins when admitted:

// Asks your route for a token: GET /api/meeting-token, as above. A room of null is the meeting itself.
async function meetingToken( meeting, room = null ) {
const answer = await fetch( `/api/meeting-token?id=${ meeting }` + ( room === null ? '' : `&room=${ room }` ) );
if ( ! answer.ok ) throw new Error( 'Your server said no' );

return ( await answer.json() ).token;
}

const lobby = rt.join( 'lobby:5' );

rt.on( 'admitted', async ( { meeting } ) => {
rt.leave( 'lobby:5' );
showMeeting( await rt.joinGroupCall( await meetingToken( meeting ) ) );
} );

The page of the host lists who waits, from the presence of the lobby:

const lobby = rt.join( 'lobby:5' );
lobby.on( 'joined', () => showWaiting( [ ...lobby.members ] ) );
lobby.on( 'join', ( { id, info } ) => addWaiting( id, info.name ) );
lobby.on( 'leave', ( { id } ) => removeWaiting( id ) );
  • Before being admitted, the guest is refused by the meeting with forbidden, whatever their page tries.
  • A guest who closes the page leaves the lobby, and the list of the host follows.

Breakout rooms​

The host sends people to a room, and later back, through a route of yours, which checks that the host asks, then:

  1. Keeps the room of the person where your token route reads it: 1, 2 and so on, or none for back.
  2. Tells the person, whose page moves.
app.post( '/meetings/:id/breakouts', async ( req, res ) => {
// Only the host of the meeting.
if ( !( await isHostOf( req.params.id, req.user.id ) ) ) return res.sendStatus( 403 );
const { user, room } = req.body; // room: 1, 2 … or null for back

// 1. Kept for whom the breakout rooms let in.
await setBreakout( req.params.id, user, room );

// 2. The person told.
await realtime.toUser( user ).emit( 'breakout', { meeting: req.params.id, room } );
res.sendStatus( 204 );
} );

The page moves its user:

// meetingToken(): your route, as above.
let current = await rt.joinGroupCall( await meetingToken( 5 ) );

rt.on( 'breakout', async ( { meeting, room } ) => {
current.leave();
current = await rt.joinGroupCall( await meetingToken( meeting, room ) );
showMeeting( current );
} );
  • A breakout room is a group call of its own: its people see and hear only each other.
  • Only those sent there get in. Once back, your route refuses them a token for the room, since it no longer names it for them.
  • Everyone back at once: your server clears the rooms and sends breakout with room: null to each, in one realtime.batch().
  • The host visits any room, since your route gives the host a token for each.

Variations​

  • A lobby for a consultation: the doctor admits the patient when ready (consultations).
  • On phones: admitted reaches the iOS and Android apps of the user too, with rt.on("admitted"), which then join the meeting (iOS, Android), and a Capacitor app runs the same page as here (mobile apps).
  • A lobby for a class: the teacher admits the late, then lets students speak (classes).
  • A whole site, in Next.js: a client waits for their visit, and the expert sees them waiting on any page and lets them in (consultations site).