rough-energy-64097
11/13/2025, 1:43 AMhttps://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>tall-airline-16756
11/13/2025, 1:43 AMtall-airline-16756
11/13/2025, 1:43 AMcustomBaseUrl 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.mdrough-energy-64097
11/13/2025, 12:42 PMtall-airline-16756
11/13/2025, 12:43 PMStreamOutput 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