I'm trying to figure out why my custom recording t...
# ask-ai
r
I'm trying to figure out why my custom recording template didn't work. My goal is to create a picture in picture layout. My code works fine when I use the default layouts but didn't work when i tried my custom recording template. My setup is livekit room -> egress -> mux livestream. When i access the custom base url I was able to log the START_RECORDING, connect to the room and attach the track in the element. Below are my node js sample and pip.html sample code. Node JS - Composite Egress const date_now = Date.now(); const MUX_STREAM_OUTPUT = new StreamOutput({ protocol: StreamProtocol.RTMP, urls: [request.rtmp_url], }); const encoded_uri = encodeURIComponent(process.env.LIVEKIT_WS_URL); const egress = await EGRESS_CLIENT.startRoomCompositeEgress( request.room_name, { stream: MUX_STREAM_OUTPUT, }, { customBaseUrl:
https://my-public-domain/custom-template/pip.html?v=${date_now}&url=${encoded_uri}&token=${request.token}
, awaitStartSignal: true, }, ); pip.html <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>PiP Layout</title> <script src="https://cdn.jsdelivr.net/npm/livekit-client/dist/livekit-client.umd.min.js"></script> <style> html, body { margin: 0; padding: 0; background: black; width: 100%; height: 100%; overflow: hidden; } video { position: absolute; object-fit: cover; background: black; } #screen { top: 0; left: 0; width: 100vw; height: 100vh; z-index: 1; } #camera { width: 25vw; height: 14vw; bottom: 2%; right: 2%; border-radius: 16px; border: 2px solid white; box-shadow: 0 0 10px rgba(0,0,0,0.6); z-index: 2; } #debug { position: absolute; top: 10px; left: 10px; color: white; font-family: monospace; z-index: 9999; } </style> </head> <body> <video id="screen" autoplay playsinline muted></video> <video id="camera" autoplay playsinline muted></video> <div id="debug">Loading...</div> <script> (async () => { console.log('START_RECORDING'); const params = new URLSearchParams(location.search); const url = params.get("url"); const token = params.get("token"); const screenEl = document.getElementById("screen"); const cameraEl = document.getElementById("camera"); const debugEl = document.getElementById("debug"); if (!url || !token) { console.error("Missing ?url or ?token parameters"); debugEl.textContent = "❌ Missing URL or token"; return; } const { Room, RoomEvent, Track } = LivekitClient; const room = new Room({ adaptiveStream: false, dynacast: false }); function safePlay(el) { const playLoop = () => el.play(() => { console.log('START_RECORDING ...'); }).catch(() => { console.log('RETRYING_RECORDING...'); setTimeout(playLoop, 500); }); playLoop(); } room.on(RoomEvent.TrackSubscribed, (track, publication, participant) => { if (track.kind !== 'video') return; const el = (track.source === Track.Source.ScreenShare) ? screenEl : cameraEl; console.log("Attaching track", track.source, participant.identity); track.attach(el); el.muted = true; el.autoplay = true; el.playsInline = true; safePlay(el); }); room.on(RoomEvent.TrackUnsubscribed, (track) => { track.detach(); }); room.on(RoomEvent.Disconnected, () => { console.log('END_RECORDING'); debugEl.textContent = "Disconnected."; }); try { await room.connect(url, token); console.log("✅ Connected to room:", room.name); debugEl.textContent = `Connected: ${room.name}`; // Render heartbeat for compositor visibility setInterval(() => { debugEl.textContent = new Date().toISOString(); }, 1000); // Force paint loop to wake compositor const canvas = document.createElement("canvas"); const ctx = canvas.getContext("2d"); canvas.width = 640; canvas.height = 360; setInterval(() => { [screenEl, cameraEl].forEach(v => { if (v.readyState >= 2 && v.videoWidth > 0) { ctx.drawImage(v, 0, 0, 64, 64); } }); }, 1000); } catch (e) { console.error("Failed to connect:", e); debugEl.textContent = "❌ Connect failed"; } })(); </script> </body> </html>
t
Thanks for reaching out, Bil. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
It sounds like your custom recording template isn’t working as expected, and I’m here to help you figure it out! Here are a few common areas to check: • Template Accessibility: First, please make sure your custom template is properly deployed and that the URL you’ve set in
customBaseUrl
is accessible. If the URL can’t be reached or doesn’t display correctly in a browser, the template won’t load. • JavaScript Errors: Sometimes, JavaScript errors or missing dependencies in your template can cause issues. It’s a good idea to review your code to ensure everything loads smoothly within the headless Chrome instance that LiveKit uses. • Parameter Handling: Double-check that your template handles the query parameters like
url
and
token
properly. These are crucial for connecting to the room and starting the recording. • Testing: A really helpful step is to use the LiveKit CLI command
lk egress test-template
. This lets you simulate publishers and load your template in a browser with the right parameters, so you can spot any issues before going live. To move forward, I’d suggest confirming your template is deployed correctly, running the CLI test, and making sure all parameters are handled as needed. If you’d like, I’m here to walk you through any of these steps or answer any questions you have! Sources: Custom recording templates | LiveKit docs | packages/livekit-server-sdk/src/EgressClient.ts | README.md
r
The template is deployed correctly and when i access the custom base url I was able to see START_RECORDING log, connect to the room and attach the track in the element. The mux didn't received any recording.
t
It’s great to hear that your custom template is working well! Since Mux isn’t receiving the recording, let’s explore a few common reasons and some helpful troubleshooting steps together: • RTMP Configuration: Could you please double-check that the RTMP URL and stream key in your
StreamOutput
settings exactly match what Mux has provided? Sometimes a small typo or an unreachable URL can stop the data from being sent. • Network Connectivity: It’s important to make sure the LiveKit egress service can reach Mux’s RTMP endpoint. You might want to look into any firewall settings or network restrictions that could be blocking this connection. • Egress Logs: Using LiveKit APIs like
ListEgress
or
StopEgress
can be really insightful. They’ll show you the current status and any error messages for the egress job, which can help pinpoint why the recording isn’t making it to Mux. • Template Rendering: Even though your template seems to be working, it’s a good idea to confirm it renders properly in the headless Chromium instance LiveKit uses. You can run
lk egress test-template
in the CLI to simulate the recording environment and check the output. • Webhook Notifications: If you’ve set up webhooks, keep an eye on them for any egress status updates. This can give clues if the recording is created but not reaching Mux. If you’re using file-based output instead of RTMP, just make sure the recordings are uploaded somewhere Mux can access, like an S3 bucket. Please don’t hesitate to reach out if you’d like me to walk you through any of these steps—I’m here to help! Sources: livekit-api/livekit/api/egress_service.py | packages/livekit-server-sdk/src/EgressClient.ts | Composite and web recordings | LiveKit docs | README.md | Custom recording templates | LiveKit docs