@@ -46,6 +46,7 @@ import type { ClientOptions } from './ClientOptions.js';
4646import { ServiceBase } from './ServiceBase.js' ;
4747import type { Rpc } from './TwirpRPC.js' ;
4848import { TwirpRpc , livekitPackage } from './TwirpRPC.js' ;
49+ import { DEFAULT_RINGING_TIMEOUT_SECONDS , dialRequestTimeout } from './dialTimeout.js' ;
4950
5051const svc = 'SIP' ;
5152
@@ -170,7 +171,7 @@ export interface CreateSipParticipantOptions {
170171 krispEnabled ?: boolean ;
171172 /** If `true`, this will wait until the call is answered before returning. */
172173 waitUntilAnswered ?: boolean ;
173- /** Optional request timeout in seconds. default 60 seconds if waitUntilAnswered is true, otherwise 10 seconds */
174+ /** Optional request timeout in seconds. Defaults to 30s when waitUntilAnswered is true (dialing takes time) , otherwise the client default. */
174175 timeout ?: number ;
175176 media ?: SIPMediaConfig ;
176177}
@@ -233,6 +234,8 @@ export interface TransferSipParticipantOptions {
233234 headers ?: { [ key : string ] : string } ;
234235 /** Maximum time for the transfer destination to answer the call, in seconds. */
235236 ringingTimeout ?: number ;
237+ /** Optional request timeout in seconds. Defaults to 30s (dialing takes time). */
238+ timeout ?: number ;
236239}
237240
238241/**
@@ -249,10 +252,10 @@ export class SipClient extends ServiceBase {
249252 */
250253 constructor ( host : string , apiKey ?: string , secret ?: string , options ?: ClientOptions ) {
251254 super ( apiKey , secret ) ;
252- const rpcOptions = options ?. requestTimeout
253- ? { requestTimeout : options . requestTimeout }
254- : undefined ;
255- this . rpc = new TwirpRpc ( host , livekitPackage , rpcOptions ) ;
255+ this . rpc = new TwirpRpc ( host , livekitPackage , {
256+ requestTimeout : options ? .requestTimeout ,
257+ failover : options ?. failover ,
258+ } ) ;
256259 }
257260
258261 /**
@@ -764,8 +767,13 @@ export class SipClient extends ServiceBase {
764767 opts = { } ;
765768 }
766769
767- if ( opts . timeout === undefined ) {
768- opts . timeout = opts . waitUntilAnswered ? 60 : 10 ;
770+ // Dialing a phone and waiting for an answer takes longer than a normal call,
771+ // and the request must outlast ringing so the call can be answered. Pin the
772+ // ring window explicitly so our request timeout doesn't depend on the server's
773+ // default (which could change out from under us).
774+ if ( opts . waitUntilAnswered ) {
775+ opts . ringingTimeout ??= DEFAULT_RINGING_TIMEOUT_SECONDS ;
776+ opts . timeout = dialRequestTimeout ( opts . timeout , opts . ringingTimeout ) ;
769777 }
770778
771779 const req = new CreateSIPParticipantRequest ( {
@@ -823,6 +831,12 @@ export class SipClient extends ServiceBase {
823831 opts = { } ;
824832 }
825833
834+ // Transferring a call dials a phone, which takes longer than a normal call,
835+ // so keep the request alive past ringing. Pin the ring window explicitly so
836+ // our request timeout doesn't depend on the server's default.
837+ opts . ringingTimeout ??= DEFAULT_RINGING_TIMEOUT_SECONDS ;
838+ opts . timeout = dialRequestTimeout ( opts . timeout , opts . ringingTimeout ) ;
839+
826840 const req = new TransferSIPParticipantRequest ( {
827841 participantIdentity : participantIdentity ,
828842 roomName : roomName ,
@@ -839,6 +853,7 @@ export class SipClient extends ServiceBase {
839853 'TransferSIPParticipant' ,
840854 req ,
841855 await this . authHeader ( { roomAdmin : true , room : roomName } , { call : true } ) ,
856+ opts . timeout ,
842857 ) ;
843858 }
844859}
0 commit comments