3636 SIPMediaConfig ,
3737)
3838from ._service import Service
39+ from ._dial_timeout import (
40+ dial_timeout as _dial_timeout ,
41+ pin_ringing_timeout as _pin_ringing_timeout ,
42+ )
3943from .access_token import VideoGrants , SIPGrants
4044
4145SVC = "SIP"
@@ -786,17 +790,15 @@ async def create_sip_participant(
786790 SIPError: If the SIP operation fails
787791 """
788792 client_timeout : Optional [aiohttp .ClientTimeout ] = None
789- if timeout :
790- # obay user specified timeout
793+ if create .wait_until_answered :
794+ # Dialing a phone and waiting for an answer takes longer than a
795+ # normal call, and the request must outlast ringing. Pin the ring
796+ # window so the timeout doesn't depend on the server's default.
797+ _pin_ringing_timeout (create )
798+ client_timeout = aiohttp .ClientTimeout (total = _dial_timeout (timeout , create ))
799+ elif timeout :
800+ # obey user specified timeout
791801 client_timeout = aiohttp .ClientTimeout (total = timeout )
792- elif create .wait_until_answered :
793- # ensure default timeout isn't too short when using sync mode
794- if (
795- self ._client ._session .timeout
796- and self ._client ._session .timeout .total
797- and self ._client ._session .timeout .total < 20
798- ):
799- client_timeout = aiohttp .ClientTimeout (total = 20 )
800802
801803 if trunk_id :
802804 create .sip_trunk_id = trunk_id
@@ -814,16 +816,27 @@ async def create_sip_participant(
814816 )
815817
816818 async def transfer_sip_participant (
817- self , transfer : TransferSIPParticipantRequest
819+ self ,
820+ transfer : TransferSIPParticipantRequest ,
821+ * ,
822+ timeout : Optional [float ] = None ,
818823 ) -> SIPParticipantInfo :
819824 """Transfer a SIP participant to a different room.
820825
821826 Args:
822827 transfer: Request containing transfer details
828+ timeout: Optional request timeout in seconds. Transferring dials a
829+ phone, which takes longer than normal, so it defaults to a
830+ longer timeout when unset.
823831
824832 Returns:
825833 Updated SIP participant information
826834 """
835+ # Transferring a call dials a phone, which takes longer than a normal
836+ # call, so keep the request alive past ringing. Pin the ring window so the
837+ # timeout doesn't depend on the server's default.
838+ _pin_ringing_timeout (transfer )
839+ client_timeout = aiohttp .ClientTimeout (total = _dial_timeout (timeout , transfer ))
827840 return await self ._client .request (
828841 SVC ,
829842 "TransferSIPParticipant" ,
@@ -836,6 +849,7 @@ async def transfer_sip_participant(
836849 sip = SIPGrants (call = True ),
837850 ),
838851 SIPParticipantInfo ,
852+ timeout = client_timeout ,
839853 )
840854
841855 def _admin_headers (self ) -> dict [str , str ]:
0 commit comments