|
1 | 1 | import aiohttp |
2 | | -import re |
3 | 2 | from typing import Optional |
4 | 3 |
|
5 | 4 | from livekit.protocol.models import ListUpdate |
|
32 | 31 | SIPTransport, |
33 | 32 | ) |
34 | 33 | from ._service import Service |
35 | | -from .twirp_client import TwirpError |
36 | 34 | from .access_token import VideoGrants, SIPGrants |
37 | 35 |
|
38 | 36 | SVC = "SIP" |
39 | 37 | """@private""" |
40 | 38 |
|
41 | | -_sip_status_pattern = re.compile(r"sip status: (\d+) \((.*?)\)") |
42 | | - |
43 | | - |
44 | | -class SIPError(TwirpError): |
45 | | - """Error raised by SIP service operations. |
46 | | -
|
47 | | - Contains SIP specific status and message information when available. |
48 | | - """ |
49 | | - |
50 | | - def __init__(self, code: str, msg: str, status: Optional[int] = None): |
51 | | - super().__init__(code, msg, status=status) |
52 | | - self._sip_status: Optional[int] = None |
53 | | - self._sip_message: Optional[str] = None |
54 | | - |
55 | | - @classmethod |
56 | | - def from_twirp_error(cls, e: TwirpError) -> "SIPError": |
57 | | - err = cls(e.code, e.message, status=e.status) |
58 | | - # Parse SIP status and message from error message |
59 | | - sip_status_match = _sip_status_pattern.search(e.message) |
60 | | - if sip_status_match: |
61 | | - err._sip_status = int(sip_status_match.group(1)) |
62 | | - err._sip_message = sip_status_match.group(2) |
63 | | - # maintain traceback from the original error |
64 | | - err.__traceback__ = e.__traceback__ |
65 | | - return err |
66 | | - |
67 | | - @property |
68 | | - def sip_status(self) -> Optional[int]: |
69 | | - return self._sip_status |
70 | | - |
71 | | - @property |
72 | | - def sip_message(self) -> Optional[str]: |
73 | | - return self._sip_message |
74 | | - |
75 | 39 |
|
76 | 40 | class SipService(Service): |
77 | 41 | """Client for LiveKit SIP Service API |
@@ -445,17 +409,14 @@ async def create_sip_participant( |
445 | 409 | ): |
446 | 410 | client_timeout = aiohttp.ClientTimeout(total=20) |
447 | 411 |
|
448 | | - try: |
449 | | - return await self._client.request( |
450 | | - SVC, |
451 | | - "CreateSIPParticipant", |
452 | | - create, |
453 | | - self._admin_headers(), |
454 | | - SIPParticipantInfo, |
455 | | - timeout=client_timeout, |
456 | | - ) |
457 | | - except TwirpError as e: |
458 | | - raise SIPError.from_twirp_error(e) from None |
| 412 | + return await self._client.request( |
| 413 | + SVC, |
| 414 | + "CreateSIPParticipant", |
| 415 | + create, |
| 416 | + self._auth_header(VideoGrants(), sip=SIPGrants(call=True)), |
| 417 | + SIPParticipantInfo, |
| 418 | + timeout=client_timeout, |
| 419 | + ) |
459 | 420 |
|
460 | 421 | async def transfer_sip_participant( |
461 | 422 | self, transfer: TransferSIPParticipantRequest |
|
0 commit comments