Skip to main content

Recording

Create join tokens and start and stop LiveKit recordings according to consent.

Part of the API reference for the Consent Ledger LiveKit reference integration.

Functions exported from consent-ledger-livekit/livekit. They create join tokens and start and stop recordings according to consent.


Functions

Function

Returns

Use it to

createRoomToken(config, identity, options?)

Promise<string>

Give an authenticated participant a join token

createRecordingController(options)

RecordingController

Start and stop recordings according to consent

recordingFile(job)

string | undefined

Get the bucket key of a finished recording

createMemoryRecordingJobStore()

RecordingJobStore

Keep recording jobs in memory (tests and trials only)


createRoomToken(config, identity, options?)

const token = await createRoomToken(
  { apiKey, apiSecret, room },  // room = the consent sessionId
  participantId,                // identity = the consent participantId
  { name: 'Zoë Ng' },           // optional display name, up to 100 characters
);

The token lasts 5 minutes, joins only that room, and may publish only microphone and camera. It grants no data messages, room admin, or recording rights. Authenticate the person and check they belong in the room before you call it.


createRecordingController(options)

Option

Required

Meaning

consent

Yes

The ConsentClient from createConsentClient

egress

Yes

LiveKit's EgressClient (or anything with startParticipantEgress, stopEgress, listEgress)

purposeId

Yes

The consent purpose this controller records for. Use one purpose per room.

output

Yes

({ room, participantId, recordingId }) => EncodedOutputs: where LiveKit uploads each file. Name files from recordingId.

jobs

Production

A RecordingJobStore, such as the PostgreSQL one. Without it, recording state is lost on restart.

decisions

Production

A CurrentDecisionSource, such as the PostgreSQL consent store, so reconcile() can find every current decision.

onSync

No

Called with the result of each sync a consent change starts, for logging or metrics

startOnConsent

No

false turns off automatic starts, for host-approved recording. Stops still happen.

egressOptions

No

Passed to LiveKit's startParticipantEgress

startGraceMs

No

How long an uncertain start may take to show up in LiveKit (default 120,000 ms). Shorten only in tests.

The controller it returns:

Method

Returns

What it does

syncParticipant({ room, participantId }, { start? })

Promise<RecordingSyncResult>

Checks one participant: stops their recording if not permitted, starts one if permitted and nothing records them. { start: false } only checks and stops.

handleWebhookEvent(event)

Promise<RecordingSyncResult | undefined>

Handles a LiveKit webhook whose signature WebhookReceiver has checked: participant_joined syncs the participant, egress_* updates and checks jobs, room_finished ends the session.

reconcile()

Promise<RecordingReconcileReport>

Finishes work a restart or missed event left behind. Run at startup and every minute. Returns results and unresolved receipts for an operator.

close()

void

Stops listening to consent changes. Call on shutdown.


Recording results

A RecordingSyncResult has room, participantId, permitted, and an action:

action

Meaning

started

LiveKit accepted the start and reports a starting or active recording (egressId). It does not guarantee media is already flowing.

start-unknown

LiveKit's answer was lost; it may be recording (recordingId). reconcile() resolves it.

stopping

LiveKit accepted the stop and is still finishing the file (egressIds).

stopped

Every affected recording has finished (egressIds).

unchanged

Nothing to do (egressIds of any existing recordings).

failed

Could not start or stop (reason). Recording may still be active.


recordingFile(job)

Returns the bucket key of a complete recording (the file LiveKit reported, else the requested path), or undefined for one that did not finish. It does not check who may see the file.

Did this answer your question?