bekriebel / fvtt-module-avclient-livekit

Other
23 stars 12 forks source link

Add auto egress #52

Open HandsomeStrife opened 1 year ago

HandsomeStrife commented 1 year ago

With the release of LiveKit Cloud, and their auto egress functionality, I wondered if we might be able to include a setting to automatically record the audio/video to any room joined? Based on https://docs.livekit.io/server/egress/autoegress/ there would need to be an enable option, along with settings for the s3 information (access key, secret key, bucket name and region).

I imagine that it would look something like (in LiveKitClient.ts):

async initializeRoom(): Promise<void> {
    // set the LiveKit publish defaults
    const liveKitPublishDefaults = this.trackPublishOptions;

    // If egress is enabled, add the extra settings
    let egressSettings = undefined;
    if (this.settings.egressEnabled) {
      egressSettings = {
        tracks: {
          filepath: this.settings.s3BucketPath + "/{room_name}-{publisher_identity}-{time}",
          s3 : {
            access_key: this.settings.s3AccessKey,
            secret: this.settings.s3Secret,
            bucket: this.settings.s3Bucket,
            region: this.settings.s3Region
          }
        }
      };
    } else {
      egressSettings = undefined;
    }

    // Set the livekit room options
    const liveKitRoomOptions: RoomOptions = {
      adaptiveStream: liveKitPublishDefaults.simulcast,
      dynacast: liveKitPublishDefaults.simulcast,
      publishDefaults: liveKitPublishDefaults,
      egress: egressSettings,
    };

    // Create and configure the room
    this.liveKitRoom = new Room(liveKitRoomOptions);

    // Set up room callbacks
    this.setRoomCallbacks();
  }

...on the assumption that the settings are registered accordingly. Unfortunately I'm not able to test locally as I'm using Forge to run my instance, and I'm also very unfamiliar with how Foundry modules work with initialising and saving settings. As well as this, I also don't know if it is LiveKitClient or livekit-web-client that need to be altered, or both.

I'd be happy to share some API keys/access privately to facilitate testing though.

bekriebel commented 1 year ago

Ohh, interesting. I didn't know that was something they implemented. I can try to take a look at this soon. I'll let you know if some keys are helpful.

HandsomeStrife commented 1 year ago

Amazing, thank you! Currently I have a python script that runs and detects everyone in any rooms and sends LiveKit API calls to record each stream, but that doesn't work with the breakout rooms as I'd have to run the script again to detect it.

Not that I imagine it would be an immediate problem for me, but a thought that had occurred :)

GamerSeth commented 1 month ago

I would love to see a client side option to set up egress. Our use case is to use the live http://livekit.io project as the signaling server and then have a configuration in the module to set up either do a room composite, track composite or track egress. https://github.com/livekit/egress

We would likely use track composite to record the audio/video or each player got a cloud storage location (S3 compatable)

A peak behind the screen is that we currently record the entire gaming session with OBS and browser capture with the imbedded A/V. But we would love to have individual tracks recorded so that we have the option to post process the sessions for a podcast format using a tool like DaVinci Resolve.