Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
13 changes: 11 additions & 2 deletions packages/livekit-server-sdk/src/AgentDispatchClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
metadata?: string;
}

type ClientOptions = {
requestTimeout?: number;
};

const svc = 'AgentDispatchService';

/**
Expand All @@ -29,10 +33,15 @@
* @param host - hostname including protocol. i.e. 'https://<project>.livekit.cloud'
* @param apiKey - API Key, can be set in env var LIVEKIT_API_KEY
* @param secret - API Secret, can be set in env var LIVEKIT_API_SECRET
* @param options - client options
* @param options.requestTimeout - optional timeout, in seconds, for all server requests

Check warning on line 37 in packages/livekit-server-sdk/src/AgentDispatchClient.ts

View workflow job for this annotation

GitHub Actions / Formatting

tsdoc-param-tag-with-invalid-name: The @param block should be followed by a valid parameter name: The identifier cannot non-word characters
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of describing the usage here, could you do it just above the field definition in the ClientOptions type?

Would also be nice if we could share the ClientOptions type across different implementations instead of redefining it in each client module.

*/
constructor(host: string, apiKey?: string, secret?: string) {
constructor(host: string, apiKey?: string, secret?: string, options?: ClientOptions) {
super(apiKey, secret);
this.rpc = new TwirpRpc(host, livekitPackage);
const rpcOptions = options?.requestTimeout
? { requestTimeout: options.requestTimeout }
: undefined;
this.rpc = new TwirpRpc(host, livekitPackage, rpcOptions);
}

/**
Expand Down
13 changes: 11 additions & 2 deletions packages/livekit-server-sdk/src/EgressClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@
active?: boolean;
}

type ClientOptions = {
requestTimeout?: number;
};

/**
* Client to access Egress APIs
*/
Expand All @@ -137,10 +141,15 @@
* @param host - hostname including protocol. i.e. 'https://<project>.livekit.cloud'
* @param apiKey - API Key, can be set in env var LIVEKIT_API_KEY
* @param secret - API Secret, can be set in env var LIVEKIT_API_SECRET
* @param options - client options
* @param options.requestTimeout - optional timeout, in seconds, for all server requests

Check warning on line 145 in packages/livekit-server-sdk/src/EgressClient.ts

View workflow job for this annotation

GitHub Actions / Formatting

tsdoc-param-tag-with-invalid-name: The @param block should be followed by a valid parameter name: The identifier cannot non-word characters
*/
constructor(host: string, apiKey?: string, secret?: string) {
constructor(host: string, apiKey?: string, secret?: string, options?: ClientOptions) {
super(apiKey, secret);
this.rpc = new TwirpRpc(host, livekitPackage);
const rpcOptions = options?.requestTimeout
? { requestTimeout: options.requestTimeout }
: undefined;
this.rpc = new TwirpRpc(host, livekitPackage, rpcOptions);
}

/**
Expand Down
13 changes: 11 additions & 2 deletions packages/livekit-server-sdk/src/IngressClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@
ingressId?: string;
}

type ClientOptions = {
requestTimeout?: number;
};

/**
* Client to access Ingress APIs
*/
Expand All @@ -124,10 +128,15 @@
* @param host - hostname including protocol. i.e. 'https://<project>.livekit.cloud'
* @param apiKey - API Key, can be set in env var LIVEKIT_API_KEY
* @param secret - API Secret, can be set in env var LIVEKIT_API_SECRET
* @param options - client options
* @param options.requestTimeout - optional timeout, in seconds, for all server requests

Check warning on line 132 in packages/livekit-server-sdk/src/IngressClient.ts

View workflow job for this annotation

GitHub Actions / Formatting

tsdoc-param-tag-with-invalid-name: The @param block should be followed by a valid parameter name: The identifier cannot non-word characters
*/
constructor(host: string, apiKey?: string, secret?: string) {
constructor(host: string, apiKey?: string, secret?: string, options?: ClientOptions) {
super(apiKey, secret);
this.rpc = new TwirpRpc(host, livekitPackage);
const rpcOptions = options?.requestTimeout
? { requestTimeout: options.requestTimeout }
: undefined;
this.rpc = new TwirpRpc(host, livekitPackage, rpcOptions);
}

/**
Expand Down
13 changes: 11 additions & 2 deletions packages/livekit-server-sdk/src/RoomServiceClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@
name?: string;
};

type ClientOptions = {
requestTimeout?: number;
};

const svc = 'RoomService';

/**
Expand All @@ -120,10 +124,15 @@
* @param host - hostname including protocol. i.e. 'https://<project>.livekit.cloud'
* @param apiKey - API Key, can be set in env var LIVEKIT_API_KEY
* @param secret - API Secret, can be set in env var LIVEKIT_API_SECRET
* @param options - client options
* @param options.requestTimeout - optional timeout, in seconds, for all server requests

Check warning on line 128 in packages/livekit-server-sdk/src/RoomServiceClient.ts

View workflow job for this annotation

GitHub Actions / Formatting

tsdoc-param-tag-with-invalid-name: The @param block should be followed by a valid parameter name: The identifier cannot non-word characters
*/
constructor(host: string, apiKey?: string, secret?: string) {
constructor(host: string, apiKey?: string, secret?: string, options?: ClientOptions) {
super(apiKey, secret);
this.rpc = new TwirpRpc(host, livekitPackage);
const rpcOptions = options?.requestTimeout
? { requestTimeout: options.requestTimeout }
: undefined;
this.rpc = new TwirpRpc(host, livekitPackage, rpcOptions);
}

/**
Expand Down
13 changes: 11 additions & 2 deletions packages/livekit-server-sdk/src/SipClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,10 @@
headers?: { [key: string]: string };
}

type ClientOptions = {
requestTimeout?: number;
};

/**
* Client to access Egress APIs
*/
Expand All @@ -215,10 +219,15 @@
* @param host - hostname including protocol. i.e. 'https://<project>.livekit.cloud'
* @param apiKey - API Key, can be set in env var LIVEKIT_API_KEY
* @param secret - API Secret, can be set in env var LIVEKIT_API_SECRET
* @param options - client options
* @param options.requestTimeout - optional timeout, in seconds, for all server requests

Check warning on line 223 in packages/livekit-server-sdk/src/SipClient.ts

View workflow job for this annotation

GitHub Actions / Formatting

tsdoc-param-tag-with-invalid-name: The @param block should be followed by a valid parameter name: The identifier cannot non-word characters
*/
constructor(host: string, apiKey?: string, secret?: string) {
constructor(host: string, apiKey?: string, secret?: string, options?: ClientOptions) {
super(apiKey, secret);
this.rpc = new TwirpRpc(host, livekitPackage);
const rpcOptions = options?.requestTimeout
? { requestTimeout: options.requestTimeout }
: undefined;
this.rpc = new TwirpRpc(host, livekitPackage, rpcOptions);
}

/**
Expand Down
17 changes: 14 additions & 3 deletions packages/livekit-server-sdk/src/TwirpRPC.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,15 @@ import type { JsonValue } from '@bufbuild/protobuf';

// twirp RPC adapter for client implementation

type Options = {
/** Prefix for the RPC requests */
prefix?: string;
/** Timeout for fetch requests, in seconds. Must resolve to a positive integer millisecond value. */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The "must resolve to a positive integer millisecond value" part feels slightly confusing to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I re-worded this to be less specific and hopefully less confusing.

requestTimeout?: number;
};

const defaultPrefix = '/twirp';
const defaultTimeoutSeconds = 60;

export const livekitPackage = 'livekit';
export interface Rpc {
Expand Down Expand Up @@ -48,21 +56,24 @@ export class TwirpRpc {

prefix: string;

constructor(host: string, pkg: string, prefix?: string) {
requestTimeout: number;

constructor(host: string, pkg: string, options?: Options) {
if (host.startsWith('ws')) {
host = host.replace('ws', 'http');
}
this.host = host;
this.pkg = pkg;
this.prefix = prefix || defaultPrefix;
this.requestTimeout = options?.requestTimeout ?? defaultTimeoutSeconds;
this.prefix = options?.prefix || defaultPrefix;
}

async request(
service: string,
method: string,
data: any, // eslint-disable-line @typescript-eslint/no-explicit-any
headers: any, // eslint-disable-line @typescript-eslint/no-explicit-any
timeout = 60,
timeout = this.requestTimeout,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
): Promise<any> {
const path = `${this.prefix}/${this.pkg}.${service}/${method}`;
Expand Down