@@ -5,7 +5,15 @@ import type { JsonValue } from '@bufbuild/protobuf';
55
66// twirp RPC adapter for client implementation
77
8+ type Options = {
9+ /** Prefix for the RPC requests */
10+ prefix ?: string ;
11+ /** Timeout for fetch requests, in seconds. Must be within the valid range for abort signal timeouts. */
12+ requestTimeout ?: number ;
13+ } ;
14+
815const defaultPrefix = '/twirp' ;
16+ const defaultTimeoutSeconds = 60 ;
917
1018export const livekitPackage = 'livekit' ;
1119export interface Rpc {
@@ -48,21 +56,24 @@ export class TwirpRpc {
4856
4957 prefix : string ;
5058
51- constructor ( host : string , pkg : string , prefix ?: string ) {
59+ requestTimeout : number ;
60+
61+ constructor ( host : string , pkg : string , options ?: Options ) {
5262 if ( host . startsWith ( 'ws' ) ) {
5363 host = host . replace ( 'ws' , 'http' ) ;
5464 }
5565 this . host = host ;
5666 this . pkg = pkg ;
57- this . prefix = prefix || defaultPrefix ;
67+ this . requestTimeout = options ?. requestTimeout ?? defaultTimeoutSeconds ;
68+ this . prefix = options ?. prefix || defaultPrefix ;
5869 }
5970
6071 async request (
6172 service : string ,
6273 method : string ,
6374 data : any , // eslint-disable-line @typescript-eslint/no-explicit-any
6475 headers : any , // eslint-disable-line @typescript-eslint/no-explicit-any
65- timeout = 60 ,
76+ timeout = this . requestTimeout ,
6677 // eslint-disable-next-line @typescript-eslint/no-explicit-any
6778 ) : Promise < any > {
6879 const path = `${ this . prefix } /${ this . pkg } .${ service } /${ method } ` ;
0 commit comments