fierce-television-48756
08/21/2025, 3:46 AMEgress started with ID: ${egressInfo.egressId});
} catch (error) {
console.error('Egress start failed:', error);
}
};
The Error I'm getting is:
ReferenceError: StreamOutput is not defined (and also StreamProtocol is not defined).
My Question:
What is the correct way to import StreamOutput and StreamProtocol? And what is the exact, correct structure for the startRoomCompositeEgress call for an audio-only RTMP stream?
Could you please provide the final, correct code snippet, including all necessary require statements from the livekit-server-sdk?tall-airline-16756
08/21/2025, 3:46 AMtall-airline-16756
08/21/2025, 3:47 AM// Import necessary modules
const { EgressClient, StreamOutput, StreamProtocol } = require('livekit-server-sdk');
const { v4: uuidv4 } = require('uuid');
// Create an instance of EgressClient
const egressClient = new EgressClient(
<LIVEKIT_SERVER_URL>, // Swap this out for your LiveKit server URL
<API_KEY>, // Your API key goes here
<API_SECRET> // And your API secret here
);
// Function to start the egress
exports.startCompositeEgress = async (roomName) => {
try {
const streamKey = uuidv4();
const rtmpUrl = `rtmp://127.0.0.1:1935/live/${streamKey}`;
// Define the RTMP output
const streamOutput = new StreamOutput({
protocol: StreamProtocol.RTMP,
urls: [rtmpUrl],
});
// Start the egress
const egressInfo = await egressClient.startRoomCompositeEgress(
roomName,
{ stream: streamOutput },
{ audioOnly: true }
);
console.log(`Egress started with ID: ${egressInfo.egressId}`);
} catch (error) {
console.error('Oops, starting the egress didn’t work:', error);
}
};
Just a heads-up: don’t forget to replace those placeholders like <LIVEKIT_SERVER_URL>, <API_KEY>, and <API_SECRET> with your real LiveKit server details. This setup ensures your RTMP stream is configured just right for audio-only streaming. If you hit any bumps, I’m here to help!
Sources: packages/livekit-server-sdk/src/EgressClient.ts | RoomComposite Egress | LiveKit Docs