many-forest-60185
12/27/2025, 6:48 AMtall-airline-16756
12/27/2025, 6:48 AMtall-airline-16756
12/27/2025, 6:49 AMmany-forest-60185
12/27/2025, 6:49 AMtall-airline-16756
12/27/2025, 6:50 AMLIVEKIT_URL, API_KEY, API_SECRET, your-gcs-bucket) with your values and provide GCP credentials via credentials_json or GOOGLE_APPLICATION_CREDENTIALS.
// npm install livekit-server-sdk
const {
EgressClient,
RoomCompositeEgressRequest,
GCPUpload,
RoomCompositeEgressRequest_Output,
RoomCompositeEgressRequest_File
} = require('livekit-server-sdk');
const LIVEKIT_URL = '<wss://LIVEKIT_URL>';
const API_KEY = 'API_KEY';
const API_SECRET = 'API_SECRET';
const egressClient = new EgressClient(LIVEKIT_URL, API_KEY, API_SECRET);
async function startRoomCompositeToGCS() {
const request = new RoomCompositeEgressRequest({
room_name: 'my-room',
layout: 'speaker-dark',
audio_only: false,
video_only: false,
file: new RoomCompositeEgressRequest_File({
filename: 'recordings/my-room-${timestamp}.mp4',
output: new RoomCompositeEgressRequest_Output({
$case: 'gcp',
gcp: new GCPUpload({
bucket: 'your-gcs-bucket',
// Optional: provide service account JSON string if not using env var
// credentials_json: JSON.stringify(require('./gcp-service-account.json')),
}),
}),
}),
});
try {
const info = await egressClient.startRoomCompositeEgress(request);
console.log('Egress started, egress_id:', info.egress_id);
return info.egress_id;
} catch (err) {
console.error('Failed to start egress:', err);
throw err;
}
}
// Example: call and optionally stop after some time
(async () => {
const egressId = await startRoomCompositeToGCS();
// To stop later:
// await egressClient.stopEgress(egressId);
})();
If you want an example for Track egress or Track Composite egress instead, or need the exact shape for providing inline credentials_json, tell me which one and I’ll provide it.
Sources: server-sdk-js | livekit/livekit_composite | DeepWiki | Python SDKs | livekit/livekit_composite | DeepWiki