agents icon indicating copy to clipboard operation
agents copied to clipboard

Auto Egress not working for agent track

Open willsmanley opened this issue 1 year ago • 8 comments

I am creating a room with autoegress for both the room composite and individual tracks.

My goal is to store 3 recordings: 1) user track, 2) agent track, 3) composite track

1 and 3 are working great, but the agent track is not being egressed properly.

I can see that the agent identity is randomized like "agent-AJ_5quWN4B3jyEh"

Here is the code I am using to create the egress requests from the room:

import "jsr:@supabase/functions-js/edge-runtime.d.ts";
import { AccessToken, RoomServiceClient, S3Upload } from 'npm:livekit-server-sdk';
import { ulid } from 'npm:ulid';

const LIVEKIT_URL = 'asdf';
const LIVEKIT_API_URL = 'asdf';
const LIVEKIT_API_KEY = 'asdf';
const LIVEKIT_API_SECRET = 'asdf';

async function generateToken(): Promise<{ accessToken: string, url: string }> {
  const roomName = ulid();

  const accessToken = new AccessToken(LIVEKIT_API_KEY, LIVEKIT_API_SECRET, {
    identity: "human_user",
  });

  accessToken.addGrant({
    roomJoin: true,
    roomCreate: true,
    roomRecord: true,
    room: roomName,
    canPublish: true,
    canSubscribe: true,
    canPublishData: true,
  });

  const token = await accessToken.toJwt();

  await createRoomWithEgress(roomName, token);

  return {
    accessToken: token,
    url: LIVEKIT_URL,
  };
}

async function createRoomWithEgress(roomName: string, token: string) {
  const output = {
    case: 's3',
    value: new S3Upload({
      secret: "asdf", 
      bucket: "asdf",
      endpoint: 'asdf',
      accessKey: "asdf",
    }),
  };
  const roomClient = new RoomServiceClient(LIVEKIT_API_URL, LIVEKIT_API_KEY, LIVEKIT_API_SECRET);
  await roomClient.createRoom({
    name: roomName,
    egress: {
      room: {
        roomName: roomName,
        audioOnly: true,
        fileOutputs: [
          {
            filepath: `${roomName}/room-{time}.ogg`,
            output,
          }
        ]
      },
      tracks: {
        filepath: `${roomName}/{publisher_identity}-{time}.ogg`,
        output,
      },
    }
  });

  console.log('Room created successfully:', roomName);
}

Deno.serve(async (req) => {
  return new Response(
    JSON.stringify(await generateToken()),
    { headers: { "Content-Type": "application/json" } },
  );
});

You don't have to run it from deno, it works the same in node or vanilla twirp.

This successfully records the human_user track, but not the agent track. Maybe there is something I am doing wrong, but my understanding is that this should automatically save any participant tracks that join the room.

There is no problem with the request being received properly. If you send a poorly structured request it will reject it with 400 Bad Request. If you send a poorly structured S3 object it will fail. I have confirmed neither of these are applicable as it is storing the other recordings via S3 successfully.

willsmanley avatar Aug 22 '24 16:08 willsmanley