Skip to main content

Consultations by booking

Markdown

A video visit with a doctor, a lawyer, a tutor or a coach: two people meet at a booked time from a link on the page of the appointment. It opens only to those two, only from shortly before its time until its end, and its media is encrypted end to end, so the media servers forward what they cannot read. Whoever comes first waits in it for the other, and nothing rings.

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

Your route​

A group call for each booking, named after it: visit:81. The doctor and the patient join it from the page of the appointment.

Your app decides who may join, and when, in a route of its own. The page asks it for a token as the person joins, and your route makes your own check, then answers a token for that visit, or 403. This route says yes when:

  1. The person is the doctor or the patient of the booking.
  2. It is time: from ten minutes before the start until the end.

And every token for the visit encrypts it end to end. findBooking() is yours:

// Your route, GET /api/visit-token?id=81. Express here, the same in any framework.
app.get( '/api/visit-token', async ( req, res ) => {
const me = userOf( req );
const booking = await findBooking( req.query.id );

// 1. The doctor or the patient of the booking.
if ( ! me || ! booking || ! [ booking.doctorId, booking.patientId ].includes( me ) ) return res.sendStatus( 403 );

// 2. From ten minutes before it starts until it ends.
if ( Date.now() < booking.start - 10 * 60 * 1000 || Date.now() > booking.end ) return res.sendStatus( 403 );

// Encrypted end to end: the same in every token for the visit.
res.json( { token: await realtime.groupCallToken( me, 'visit:' + booking.id, { encrypt: true } ) } );
} );
  • Only its two people, and only in its time: anyone else, or the patient a day early, is refused, and the page hears forbidden.
  • encrypt: true encrypts every frame in the browser with a key your server makes, which only those your route gave a token get.
  • Your route runs when someone joins. Those in the call stay until they leave or your server ends it.
  • On WordPress, its package decides who joins by a rule of its own (WordPress group calls).

The page of the appointment​

Ready-made, with the call screen of Better Messages once on the page (rt.callScreen(), or <CallScreen /> in React):

<group-call-button call="visit:81" token-url="/api/visit-token?id=81" type="video" title="Your appointment with Dr. Lee">Join the visit</group-call-button>

A press asks your route with ?id=81&call=visit:81&type=video. Or your own:

// Asks your route for a token: GET /api/visit-token, as above.
async function visitToken( id ) {
const answer = await fetch( '/api/visit-token?id=' + id );
if ( ! answer.ok ) throw new Error( 'forbidden' ); // outside its time, or not theirs

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

const visit = await rt.joinGroupCall( await visitToken( 81 ) );
await visit.setCamera( true );
await visit.setMicrophone( true );

visit.on( 'person', ( person ) => { // the other one arrived, or what they send changed
person.camera?.attach( theirVideo );
person.microphone?.attach( theirAudio );
} );
visit.on( 'person_left', () => showWaiting() );
leaveButton.onclick = () => visit.leave();

visit.encrypted is true, which the page may show with a lock.

Ending it on time​

At the end of the booking, a job of your server ends the visit for both, and refuses the tokens they had:

await realtime.call( 'visit:81' ).end();

realtime.call( 'visit:81' ).get() says who is in it and since when, for the record of the visit.

Variations​

  • A patient without an account: the link in the booking email signs its holder in for that visit alone, as a user your server names, such as guest:81, and your route takes that id as the patient. Calls take any id of up to 64 characters with no space (calls).
  • The doctor lets the patient in when ready, from a waiting room (waiting rooms).
  • Notes and files during the visit: a room of the same name with emit: [ 'message' ], kept by your server from the webhook (chat).
  • A call that rings, for an appointment by phone: a call between the two at the time, its token from a route with the same check (calls from a button).
  • On phones: the iOS and Android SDKs join the same group call, for a visit from the app of the patient (iOS, Android), and a Capacitor app joins it as a browser does (mobile apps).
  • A whole site, in Next.js: times booked with experts, a waiting room, and a visit encrypted end to end with its messages and files beside it (consultations site).