Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 24 additions & 4 deletions packages/livekit-server-sdk/src/EgressClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import type {
ImageOutput,
SegmentedFileOutput,
StreamOutput,
WebhookConfig,
} from '@livekit/protocol';
import {
AudioMixing,
Expand All @@ -30,7 +31,14 @@ import { TwirpRpc, livekitPackage } from './TwirpRPC.js';

const svc = 'Egress';

export interface RoomCompositeOptions {
export interface BaseOptions {
/**
* webhooks to call for this request, optional.
*/
webhooks?: WebhookConfig[];
}

export interface RoomCompositeOptions extends BaseOptions {
/**
* egress layout. optional
*/
Expand All @@ -57,7 +65,7 @@ export interface RoomCompositeOptions {
audioMixing?: AudioMixing;
}

export interface WebOptions {
export interface WebOptions extends BaseOptions {
/**
* encoding options or preset. optional
*/
Expand All @@ -76,7 +84,7 @@ export interface WebOptions {
awaitStartSignal?: boolean;
}

export interface ParticipantEgressOptions {
export interface ParticipantEgressOptions extends BaseOptions {
/**
* true to capture source screenshare and screenshare_audio
* false to capture camera and microphone
Expand All @@ -88,7 +96,7 @@ export interface ParticipantEgressOptions {
encodingOptions?: EncodingOptionsPreset | EncodingOptions;
}

export interface TrackCompositeOptions {
export interface TrackCompositeOptions extends BaseOptions {
/**
* audio track ID
*/
Expand Down Expand Up @@ -169,6 +177,7 @@ export class EgressClient extends ServiceBase {
audioMixing?: AudioMixing,
): Promise<EgressInfo> {
let layout: string | undefined;
let webhooks: WebhookConfig[] | undefined;
if (optsOrLayout !== undefined) {
if (typeof optsOrLayout === 'string') {
layout = optsOrLayout;
Expand All @@ -180,6 +189,7 @@ export class EgressClient extends ServiceBase {
videoOnly = opts.videoOnly;
customBaseUrl = opts.customBaseUrl;
audioMixing = opts.audioMixing;
webhooks = opts.webhooks;
}
}

Expand Down Expand Up @@ -211,6 +221,7 @@ export class EgressClient extends ServiceBase {
streamOutputs,
segmentOutputs,
imageOutputs,
webhooks,
}).toJson();

const data = await this.rpc.request(
Expand All @@ -235,6 +246,7 @@ export class EgressClient extends ServiceBase {
const audioOnly = opts?.audioOnly || false;
const videoOnly = opts?.videoOnly || false;
const awaitStartSignal = opts?.awaitStartSignal || false;
const webhooks = opts?.webhooks || [];
const {
output: legacyOutput,
options,
Expand All @@ -255,6 +267,7 @@ export class EgressClient extends ServiceBase {
streamOutputs,
segmentOutputs,
imageOutputs,
webhooks,
}).toJson();

const data = await this.rpc.request(
Expand All @@ -279,6 +292,7 @@ export class EgressClient extends ServiceBase {
output: EncodedOutputs,
opts?: ParticipantEgressOptions,
): Promise<EgressInfo> {
const webhooks = opts?.webhooks || [];
const { options, fileOutputs, streamOutputs, segmentOutputs, imageOutputs } =
this.getOutputParams(output, opts?.encodingOptions);
const req = new ParticipantEgressRequest({
Expand All @@ -290,6 +304,7 @@ export class EgressClient extends ServiceBase {
streamOutputs,
segmentOutputs,
imageOutputs,
webhooks,
}).toJson();

const data = await this.rpc.request(
Expand Down Expand Up @@ -329,6 +344,7 @@ export class EgressClient extends ServiceBase {
options?: EncodingOptionsPreset | EncodingOptions,
): Promise<EgressInfo> {
let audioTrackId: string | undefined;
let webhooks: WebhookConfig[] | undefined;
if (optsOrAudioTrackId !== undefined) {
if (typeof optsOrAudioTrackId === 'string') {
audioTrackId = optsOrAudioTrackId;
Expand All @@ -337,6 +353,7 @@ export class EgressClient extends ServiceBase {
audioTrackId = opts.audioTrackId;
videoTrackId = opts.videoTrackId;
options = opts.encodingOptions;
webhooks = opts.webhooks;
}
}

Expand All @@ -361,6 +378,7 @@ export class EgressClient extends ServiceBase {
streamOutputs,
segmentOutputs,
imageOutputs,
webhooks,
}).toJson();

const data = await this.rpc.request(
Expand Down Expand Up @@ -516,6 +534,7 @@ export class EgressClient extends ServiceBase {
roomName: string,
output: DirectFileOutput | string,
trackId: string,
webhooks?: WebhookConfig[],
): Promise<EgressInfo> {
let legacyOutput:
| {
Expand Down Expand Up @@ -544,6 +563,7 @@ export class EgressClient extends ServiceBase {
roomName,
trackId,
output: legacyOutput,
webhooks,
}).toJson();

const data = await this.rpc.request(
Expand Down
1 change: 1 addition & 0 deletions packages/livekit-server-sdk/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export {
TrackType,
WebEgressRequest,
VideoCodec,
WebhookConfig,
} from '@livekit/protocol';
export * from './AccessToken.js';
export * from './AgentDispatchClient.js';
Expand Down