My custom recording template got EGRESS_ABORTED st...
# ask-ai
r
My custom recording template got EGRESS_ABORTED status and the reason says "End reason: StopEgress API Start signal not received" no error when i access manually the custom template html in the browser. The START_RECORDING was also log in console.
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.
I'm sorry to hear you're encountering the
EGRESS_ABORTED
status with the reason "StopEgress API Start signal not received." This usually means the egress process was stopped because the start signal from the recording source didn’t arrive within the expected time. Let’s work through some steps together to help resolve this: • Verify Start Signal Emission: Please double-check that your custom template includes the necessary JavaScript to send the start signal. It might help to look at the browser console logs for any JavaScript errors that could be preventing the signal from being sent. • Check Template Functionality: Make sure your custom template properly connects to the LiveKit room and fully loads before trying to emit signals. Also, it’s good to confirm there are no CORS or security policies blocking the JavaScript from running. • Review Timing: Take a look at when the
StopEgress
API is being called—sometimes it might be triggered too early. Ensuring there’s enough time for the start signal to be sent after egress starts can make a big difference. • Enable Debug Logging: Keep an eye on the egress logs for messages like "waiting for start signal." This can give clues about where the process might be getting stuck. • Session Limit Configuration: It’s also helpful to check your egress setup’s timeout settings to make sure the session isn’t ending before the start signal arrives. If you’re still having trouble after trying these steps, please feel free to share more details about your egress setup—like how the
await_start_signal
parameter is configured and any relevant logs. We’re here to help you get this sorted out! Sources: livekit/livekit_egress.twirp.go | pkg/pipeline/controller.go | lib/livekit/egress_service_client.rb
r
When shoud i trigger the START_RECORDING signal can you give me a code sample?
t
I'm happy to guide you through triggering the
START_RECORDING
signal in your custom recording template using the
startRecording()
method from the
EgressHelper
SDK. Here's a helpful code sample to get you started:
Copy code
import EgressHelper from '@livekit/egress-sdk';

// Make sure the room is set in the EgressHelper
EgressHelper.setRoom(room); // `room` represents your connected LiveKit Room object

// When you're ready to start recording
EgressHelper.startRecording(); // This will trigger the START_RECORDING signal
Typically, recording begins after confirming that media tracks are ready. Here's an example to illustrate this approach:
Copy code
useEffect(() => {
  const startTime = Date.now();
  const interval = setInterval(async () => {
    let shouldStartRecording = false;
    let hasVideoTracks = false;
    let hasSubscribedTracks = false;
    let hasDecodedFrames = false;

    for (const p of Array.from(room.remoteParticipants.values())) {
      for (const pub of Array.from(p.trackPublications.values())) {
        if (pub.isSubscribed) {
          hasSubscribedTracks = true;
        }
        if (pub.kind === Track.Kind.Video) {
          hasVideoTracks = true;
          if (pub.videoTrack) {
            const stats = await pub.videoTrack.getRTCStatsReport();
            if (stats) {
              hasDecodedFrames = Array.from(stats).some(
                (item) => item[1].type === 'inbound-rtp' && item[1].framesDecoded > 0
              );
            }
          }
        }
      }
    }

    const timeDelta = Date.now() - startTime;
    if (hasDecodedFrames) {
      shouldStartRecording = true;
    } else if (!hasVideoTracks && hasSubscribedTracks && timeDelta > 500) {
      shouldStartRecording = true;
    } else if (timeDelta > FRAME_DECODE_TIMEOUT && hasSubscribedTracks) {
      shouldStartRecording = true;
    }

    if (shouldStartRecording) {
      EgressHelper.startRecording(); // This triggers START_RECORDING
      clearInterval(interval);
    }
  }, 100);
}, []);
This way, the recording starts only once the media tracks are ready, ensuring a smooth experience. If you have any questions or need more help, please don’t hesitate to reach out—I’m here for you! Sources: Custom recording templates | LiveKit docs | template-sdk/README.md
r
Can you convert this using javascript sdk EgressHelper.startRecording();
t
The
EgressHelper.startRecording()
function is a special feature of the
@livekit/egress-sdk
, designed to be used within custom recording templates to let the LiveKit Egress service know when to start recording. It’s important to note that this function doesn’t directly translate to the standard LiveKit JavaScript SDK (
livekit-client
) because they have different roles. Here’s a friendly example of how you might use
EgressHelper.startRecording()
inside a custom recording template:
Copy code
import EgressHelper from '@livekit/egress-sdk';
import { Room } from 'livekit-client';

async function setupRecording() {
  const url = EgressHelper.getLiveKitURL();
  const token = EgressHelper.getAccessToken();

  const room = await Room.connect(url, token);
  EgressHelper.setRoom(room);

  // Decide when to start recording
  setTimeout(() => {
    EgressHelper.startRecording(); // Signals egress to start
  }, 2000);
}
This snippet runs inside the custom recording template that the Egress service loads. When
startRecording()
is called, it logs
START_RECORDING
to the console, which the Egress service listens for to begin recording. If you’re aiming to start recording programmatically, the best approach is to use a backend SDK like Node.js to initiate egress. For example:
Copy code
import { EgressClient } from 'livekit-server-sdk';

const egressClient = new EgressClient('<LIVEKIT_SERVER_URL>', '<API_KEY>', '<API_SECRET>');

await egressClient.startWebEgress('<TEMPLATE_URL>', output, {
  awaitStartSignal: true, // Waits for console.log("START_RECORDING")
});
Please feel free to reach out if you’d like me to walk you through setting up your custom recording template or backend integration. I’m here to help! Sources: Custom recording templates | LiveKit docs | packages/livekit-server-sdk/src/EgressClient.ts | Egress examples | LiveKit docs | template-default/src/App.tsx