-
Notifications
You must be signed in to change notification settings - Fork 126
Expand file tree
/
Copy pathsip_service.py
More file actions
871 lines (755 loc) · 26.7 KB
/
Copy pathsip_service.py
File metadata and controls
871 lines (755 loc) · 26.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
from __future__ import annotations
import aiohttp
import warnings
from typing import Optional
from livekit.protocol.models import ListUpdate
from livekit.protocol.sip import (
SIPOutboundConfig,
SIPTrunkInfo,
CreateSIPInboundTrunkRequest,
UpdateSIPInboundTrunkRequest,
SIPInboundTrunkInfo,
SIPInboundTrunkUpdate,
CreateSIPOutboundTrunkRequest,
UpdateSIPOutboundTrunkRequest,
SIPOutboundTrunkInfo,
SIPOutboundTrunkUpdate,
ListSIPInboundTrunkRequest,
ListSIPInboundTrunkResponse,
ListSIPOutboundTrunkRequest,
ListSIPOutboundTrunkResponse,
DeleteSIPTrunkRequest,
SIPDispatchRule,
SIPDispatchRuleInfo,
SIPDispatchRuleUpdate,
CreateSIPDispatchRuleRequest,
UpdateSIPDispatchRuleRequest,
ListSIPDispatchRuleRequest,
ListSIPDispatchRuleResponse,
DeleteSIPDispatchRuleRequest,
CreateSIPParticipantRequest,
TransferSIPParticipantRequest,
SIPParticipantInfo,
SIPTransport,
SIPMediaConfig,
)
from ._service import Service
from .twirp_client import SipCallError, ServerError
from ._dial_timeout import (
dial_timeout as _dial_timeout,
pin_ringing_timeout as _pin_ringing_timeout,
)
from .access_token import VideoGrants, SIPGrants
SVC = "SIP"
"""@private"""
def _as_sip_error(err: ServerError) -> ServerError:
"""Surface a SIP dialing failure as a SipCallError so callers can branch on
the SIP status; other failures (auth, validation) are returned unchanged."""
if "sip_status_code" in err.metadata:
return SipCallError.from_server_error(err)
return err
class SipService(Service):
"""Client for LiveKit SIP Service API
Recommended way to use this service is via `livekit.api.LiveKitAPI`:
```python
from livekit import api
lkapi = api.LiveKitAPI()
sip_service = lkapi.sip
```
"""
def __init__(
self,
session: aiohttp.ClientSession,
url: str,
api_key: str,
api_secret: str,
failover: bool = True,
):
super().__init__(session, url, api_key, api_secret, failover=failover)
async def create_inbound_trunk(
self, create: CreateSIPInboundTrunkRequest
) -> SIPInboundTrunkInfo:
"""Create a new SIP inbound trunk.
Args:
create: Request containing trunk details
Returns:
Created SIP inbound trunk
"""
return await self._client.request(
SVC,
"CreateSIPInboundTrunk",
create,
self._admin_headers(),
SIPInboundTrunkInfo,
)
async def create_sip_inbound_trunk(
self, create: CreateSIPInboundTrunkRequest
) -> SIPInboundTrunkInfo:
"""Create a new SIP inbound trunk.
.. deprecated::
Use :meth:`create_inbound_trunk` instead.
Args:
create: Request containing trunk details
Returns:
Created SIP inbound trunk
"""
warnings.warn(
"create_sip_inbound_trunk is deprecated, use create_inbound_trunk instead",
DeprecationWarning,
stacklevel=2,
)
return await self.create_inbound_trunk(create)
async def update_inbound_trunk(
self,
trunk_id: str,
trunk: SIPInboundTrunkInfo,
) -> SIPInboundTrunkInfo:
"""Updates an existing SIP inbound trunk by replacing it entirely.
Args:
trunk_id: ID of the SIP inbound trunk to update
trunk: SIP inbound trunk to update with
Returns:
Updated SIP inbound trunk
"""
return await self._client.request(
SVC,
"UpdateSIPInboundTrunk",
UpdateSIPInboundTrunkRequest(
sip_trunk_id=trunk_id,
replace=trunk,
),
self._admin_headers(),
SIPInboundTrunkInfo,
)
async def update_sip_inbound_trunk(
self,
trunk_id: str,
trunk: SIPInboundTrunkInfo,
) -> SIPInboundTrunkInfo:
"""Updates an existing SIP inbound trunk by replacing it entirely.
.. deprecated::
Use :meth:`update_inbound_trunk` instead.
Args:
trunk_id: ID of the SIP inbound trunk to update
trunk: SIP inbound trunk to update with
Returns:
Updated SIP inbound trunk
"""
warnings.warn(
"update_sip_inbound_trunk is deprecated, use update_inbound_trunk instead",
DeprecationWarning,
stacklevel=2,
)
return await self.update_inbound_trunk(trunk_id, trunk)
async def update_inbound_trunk_fields(
self,
trunk_id: str,
*,
numbers: Optional[ListUpdate | list[str]] = None,
allowed_addresses: Optional[ListUpdate | list[str]] = None,
allowed_numbers: Optional[ListUpdate | list[str]] = None,
auth_username: Optional[str] = None,
auth_password: Optional[str] = None,
name: Optional[str] = None,
metadata: Optional[str] = None,
media: Optional[SIPMediaConfig] = None,
) -> SIPInboundTrunkInfo:
"""Updates specific fields of an existing SIP inbound trunk.
Only provided fields will be updated.
"""
update = SIPInboundTrunkUpdate(
auth_username=auth_username,
auth_password=auth_password,
name=name,
metadata=metadata,
media=media,
)
if numbers is not None:
if isinstance(numbers, ListUpdate):
update.numbers.set.extend(numbers.set)
update.numbers.add.extend(numbers.add)
update.numbers.remove.extend(numbers.remove)
else:
update.numbers.set.extend(numbers)
if allowed_addresses is not None:
if isinstance(allowed_addresses, ListUpdate):
update.allowed_addresses.set.extend(allowed_addresses.set)
update.allowed_addresses.add.extend(allowed_addresses.add)
update.allowed_addresses.remove.extend(allowed_addresses.remove)
else:
update.allowed_addresses.set.extend(allowed_addresses)
if allowed_numbers is not None:
if isinstance(allowed_numbers, ListUpdate):
update.allowed_numbers.set.extend(allowed_numbers.set)
update.allowed_numbers.add.extend(allowed_numbers.add)
update.allowed_numbers.remove.extend(allowed_numbers.remove)
else:
update.allowed_numbers.set.extend(allowed_numbers)
return await self._client.request(
SVC,
"UpdateSIPInboundTrunk",
UpdateSIPInboundTrunkRequest(
sip_trunk_id=trunk_id,
update=update,
),
self._admin_headers(),
SIPInboundTrunkInfo,
)
async def update_sip_inbound_trunk_fields(
self,
trunk_id: str,
*,
numbers: Optional[list[str]] = None,
allowed_addresses: Optional[list[str]] = None,
allowed_numbers: Optional[list[str]] = None,
auth_username: Optional[str] = None,
auth_password: Optional[str] = None,
name: Optional[str] = None,
metadata: Optional[str] = None,
) -> SIPInboundTrunkInfo:
"""Updates specific fields of an existing SIP inbound trunk.
.. deprecated::
Use :meth:`update_inbound_trunk_fields` instead.
Only provided fields will be updated.
"""
warnings.warn(
"update_sip_inbound_trunk_fields is deprecated, use update_inbound_trunk_fields instead",
DeprecationWarning,
stacklevel=2,
)
return await self.update_inbound_trunk_fields(
trunk_id,
numbers=numbers,
allowed_addresses=allowed_addresses,
allowed_numbers=allowed_numbers,
auth_username=auth_username,
auth_password=auth_password,
name=name,
metadata=metadata,
)
async def create_outbound_trunk(
self, create: CreateSIPOutboundTrunkRequest
) -> SIPOutboundTrunkInfo:
"""Create a new SIP outbound trunk.
Args:
create: Request containing trunk details
Returns:
Created SIP outbound trunk
"""
return await self._client.request(
SVC,
"CreateSIPOutboundTrunk",
create,
self._admin_headers(),
SIPOutboundTrunkInfo,
)
async def create_sip_outbound_trunk(
self, create: CreateSIPOutboundTrunkRequest
) -> SIPOutboundTrunkInfo:
"""Create a new SIP outbound trunk.
.. deprecated::
Use :meth:`create_outbound_trunk` instead.
Args:
create: Request containing trunk details
Returns:
Created SIP outbound trunk
"""
warnings.warn(
"create_sip_outbound_trunk is deprecated, use create_outbound_trunk instead",
DeprecationWarning,
stacklevel=2,
)
return await self.create_outbound_trunk(create)
async def update_outbound_trunk(
self,
trunk_id: str,
trunk: SIPOutboundTrunkInfo,
) -> SIPOutboundTrunkInfo:
"""Updates an existing SIP outbound trunk by replacing it entirely.
Args:
trunk_id: ID of the SIP outbound trunk to update
trunk: SIP outbound trunk to update with
Returns:
Updated SIP outbound trunk
"""
return await self._client.request(
SVC,
"UpdateSIPOutboundTrunk",
UpdateSIPOutboundTrunkRequest(
sip_trunk_id=trunk_id,
replace=trunk,
),
self._admin_headers(),
SIPOutboundTrunkInfo,
)
async def update_sip_outbound_trunk(
self,
trunk_id: str,
trunk: SIPOutboundTrunkInfo,
) -> SIPOutboundTrunkInfo:
"""Updates an existing SIP outbound trunk by replacing it entirely.
.. deprecated::
Use :meth:`update_outbound_trunk` instead.
Args:
trunk_id: ID of the SIP outbound trunk to update
trunk: SIP outbound trunk to update with
Returns:
Updated SIP outbound trunk
"""
warnings.warn(
"update_sip_outbound_trunk is deprecated, use update_outbound_trunk instead",
DeprecationWarning,
stacklevel=2,
)
return await self.update_outbound_trunk(trunk_id, trunk)
async def update_outbound_trunk_fields(
self,
trunk_id: str,
*,
address: str | None = None,
transport: SIPTransport | None = None,
numbers: Optional[ListUpdate | list[str]] = None,
auth_username: str | None = None,
auth_password: str | None = None,
name: str | None = None,
metadata: str | None = None,
media: Optional[SIPMediaConfig] = None,
) -> SIPOutboundTrunkInfo:
"""Updates specific fields of an existing SIP outbound trunk.
Only provided fields will be updated.
"""
update = SIPOutboundTrunkUpdate(
address=address,
transport=transport,
auth_username=auth_username,
auth_password=auth_password,
name=name,
metadata=metadata,
media=media,
)
if numbers is not None:
if isinstance(numbers, ListUpdate):
update.numbers.set.extend(numbers.set)
update.numbers.add.extend(numbers.add)
update.numbers.remove.extend(numbers.remove)
else:
update.numbers.set.extend(numbers)
return await self._client.request(
SVC,
"UpdateSIPOutboundTrunk",
UpdateSIPOutboundTrunkRequest(
sip_trunk_id=trunk_id,
update=update,
),
self._admin_headers(),
SIPOutboundTrunkInfo,
)
async def update_sip_outbound_trunk_fields(
self,
trunk_id: str,
*,
address: str | None = None,
transport: SIPTransport | None = None,
numbers: list[str] | None = None,
auth_username: str | None = None,
auth_password: str | None = None,
name: str | None = None,
metadata: str | None = None,
) -> SIPOutboundTrunkInfo:
"""Updates specific fields of an existing SIP outbound trunk.
.. deprecated::
Use :meth:`update_outbound_trunk_fields` instead.
Only provided fields will be updated.
"""
warnings.warn(
"update_sip_outbound_trunk_fields is deprecated, use update_outbound_trunk_fields instead",
DeprecationWarning,
stacklevel=2,
)
return await self.update_outbound_trunk_fields(
trunk_id,
address=address,
transport=transport,
numbers=numbers,
auth_username=auth_username,
auth_password=auth_password,
name=name,
metadata=metadata,
)
async def list_inbound_trunk(
self, list: ListSIPInboundTrunkRequest
) -> ListSIPInboundTrunkResponse:
"""List SIP inbound trunks with optional filtering.
Args:
list: Request with optional filtering parameters
Returns:
Response containing list of SIP inbound trunks
"""
return await self._client.request(
SVC,
"ListSIPInboundTrunk",
list,
self._admin_headers(),
ListSIPInboundTrunkResponse,
)
async def list_sip_inbound_trunk(
self, list: ListSIPInboundTrunkRequest
) -> ListSIPInboundTrunkResponse:
"""List SIP inbound trunks with optional filtering.
.. deprecated::
Use :meth:`list_inbound_trunk` instead.
Args:
list: Request with optional filtering parameters
Returns:
Response containing list of SIP inbound trunks
"""
warnings.warn(
"list_sip_inbound_trunk is deprecated, use list_inbound_trunk instead",
DeprecationWarning,
stacklevel=2,
)
return await self.list_inbound_trunk(list)
async def list_outbound_trunk(
self, list: ListSIPOutboundTrunkRequest
) -> ListSIPOutboundTrunkResponse:
"""List SIP outbound trunks with optional filtering.
Args:
list: Request with optional filtering parameters
Returns:
Response containing list of SIP outbound trunks
"""
return await self._client.request(
SVC,
"ListSIPOutboundTrunk",
list,
self._admin_headers(),
ListSIPOutboundTrunkResponse,
)
async def list_sip_outbound_trunk(
self, list: ListSIPOutboundTrunkRequest
) -> ListSIPOutboundTrunkResponse:
"""List SIP outbound trunks with optional filtering.
.. deprecated::
Use :meth:`list_outbound_trunk` instead.
Args:
list: Request with optional filtering parameters
Returns:
Response containing list of SIP outbound trunks
"""
warnings.warn(
"list_sip_outbound_trunk is deprecated, use list_outbound_trunk instead",
DeprecationWarning,
stacklevel=2,
)
return await self.list_outbound_trunk(list)
async def delete_trunk(self, delete: DeleteSIPTrunkRequest) -> SIPTrunkInfo:
"""Delete a SIP trunk.
Args:
delete: Request containing trunk ID to delete
Returns:
Deleted trunk information
"""
return await self._client.request(
SVC,
"DeleteSIPTrunk",
delete,
self._admin_headers(),
SIPTrunkInfo,
)
async def delete_sip_trunk(self, delete: DeleteSIPTrunkRequest) -> SIPTrunkInfo:
"""Delete a SIP trunk.
.. deprecated::
Use :meth:`delete_trunk` instead.
Args:
delete: Request containing trunk ID to delete
Returns:
Deleted trunk information
"""
warnings.warn(
"delete_sip_trunk is deprecated, use delete_trunk instead",
DeprecationWarning,
stacklevel=2,
)
return await self.delete_trunk(delete)
async def create_dispatch_rule(
self, create: CreateSIPDispatchRuleRequest
) -> SIPDispatchRuleInfo:
"""Create a new SIP dispatch rule.
Args:
create: Request containing rule details
Returns:
Created SIP dispatch rule
"""
return await self._client.request(
SVC,
"CreateSIPDispatchRule",
create,
self._admin_headers(),
SIPDispatchRuleInfo,
)
async def create_sip_dispatch_rule(
self, create: CreateSIPDispatchRuleRequest
) -> SIPDispatchRuleInfo:
"""Create a new SIP dispatch rule.
.. deprecated::
Use :meth:`create_dispatch_rule` instead.
Args:
create: Request containing rule details
Returns:
Created SIP dispatch rule
"""
warnings.warn(
"create_sip_dispatch_rule is deprecated, use create_dispatch_rule instead",
DeprecationWarning,
stacklevel=2,
)
return await self.create_dispatch_rule(create)
async def update_dispatch_rule(
self,
rule_id: str,
rule: SIPDispatchRuleInfo,
) -> SIPDispatchRuleInfo:
"""Updates an existing SIP dispatch rule by replacing it entirely.
Args:
rule_id: ID of the SIP dispatch rule to update
rule: SIP dispatch rule to update with
Returns:
Updated SIP dispatch rule
"""
return await self._client.request(
SVC,
"UpdateSIPDispatchRule",
UpdateSIPDispatchRuleRequest(sip_dispatch_rule_id=rule_id, replace=rule),
self._admin_headers(),
SIPDispatchRuleInfo,
)
async def update_sip_dispatch_rule(
self,
rule_id: str,
rule: SIPDispatchRuleInfo,
) -> SIPDispatchRuleInfo:
"""Updates an existing SIP dispatch rule by replacing it entirely.
.. deprecated::
Use :meth:`update_dispatch_rule` instead.
Args:
rule_id: ID of the SIP dispatch rule to update
rule: SIP dispatch rule to update with
Returns:
Updated SIP dispatch rule
"""
warnings.warn(
"update_sip_dispatch_rule is deprecated, use update_dispatch_rule instead",
DeprecationWarning,
stacklevel=2,
)
return await self.update_dispatch_rule(rule_id, rule)
async def update_dispatch_rule_fields(
self,
rule_id: str,
*,
trunk_ids: Optional[ListUpdate | list[str]] = None,
rule: Optional[SIPDispatchRule] = None,
name: Optional[str] = None,
metadata: Optional[str] = None,
attributes: Optional[dict[str, str]] = None,
) -> SIPDispatchRuleInfo:
"""Updates specific fields of an existing SIP dispatch rule.
Only provided fields will be updated.
"""
update = SIPDispatchRuleUpdate(
name=name,
metadata=metadata,
rule=rule,
attributes=attributes,
)
if trunk_ids is not None:
if isinstance(trunk_ids, ListUpdate):
update.trunk_ids.set.extend(trunk_ids.set)
update.trunk_ids.add.extend(trunk_ids.add)
update.trunk_ids.remove.extend(trunk_ids.remove)
else:
update.trunk_ids.set.extend(trunk_ids)
return await self._client.request(
SVC,
"UpdateSIPDispatchRule",
UpdateSIPDispatchRuleRequest(sip_dispatch_rule_id=rule_id, update=update),
self._admin_headers(),
SIPDispatchRuleInfo,
)
async def update_sip_dispatch_rule_fields(
self,
rule_id: str,
*,
trunk_ids: Optional[list[str]] = None,
rule: Optional[SIPDispatchRule] = None,
name: Optional[str] = None,
metadata: Optional[str] = None,
attributes: Optional[dict[str, str]] = None,
) -> SIPDispatchRuleInfo:
"""Updates specific fields of an existing SIP dispatch rule.
.. deprecated::
Use :meth:`update_dispatch_rule_fields` instead.
Only provided fields will be updated.
"""
warnings.warn(
"update_sip_dispatch_rule_fields is deprecated, use update_dispatch_rule_fields instead",
DeprecationWarning,
stacklevel=2,
)
return await self.update_dispatch_rule_fields(
rule_id,
trunk_ids=trunk_ids,
rule=rule,
name=name,
metadata=metadata,
attributes=attributes,
)
async def list_dispatch_rule(
self, list: ListSIPDispatchRuleRequest
) -> ListSIPDispatchRuleResponse:
"""List SIP dispatch rules with optional filtering.
Args:
list: Request with optional filtering parameters
Returns:
Response containing list of SIP dispatch rules
"""
return await self._client.request(
SVC,
"ListSIPDispatchRule",
list,
self._admin_headers(),
ListSIPDispatchRuleResponse,
)
async def list_sip_dispatch_rule(
self, list: ListSIPDispatchRuleRequest
) -> ListSIPDispatchRuleResponse:
"""List SIP dispatch rules with optional filtering.
.. deprecated::
Use :meth:`list_dispatch_rule` instead.
Args:
list: Request with optional filtering parameters
Returns:
Response containing list of SIP dispatch rules
"""
warnings.warn(
"list_sip_dispatch_rule is deprecated, use list_dispatch_rule instead",
DeprecationWarning,
stacklevel=2,
)
return await self.list_dispatch_rule(list)
async def delete_dispatch_rule(
self, delete: DeleteSIPDispatchRuleRequest
) -> SIPDispatchRuleInfo:
"""Delete a SIP dispatch rule.
Args:
delete: Request containing rule ID to delete
Returns:
Deleted rule information
"""
return await self._client.request(
SVC,
"DeleteSIPDispatchRule",
delete,
self._admin_headers(),
SIPDispatchRuleInfo,
)
async def delete_sip_dispatch_rule(
self, delete: DeleteSIPDispatchRuleRequest
) -> SIPDispatchRuleInfo:
"""Delete a SIP dispatch rule.
.. deprecated::
Use :meth:`delete_dispatch_rule` instead.
Args:
delete: Request containing rule ID to delete
Returns:
Deleted rule information
"""
warnings.warn(
"delete_sip_dispatch_rule is deprecated, use delete_dispatch_rule instead",
DeprecationWarning,
stacklevel=2,
)
return await self.delete_dispatch_rule(delete)
async def create_sip_participant(
self,
create: CreateSIPParticipantRequest,
*,
timeout: Optional[float] = None,
trunk_id: Optional[str] = None,
outbound_trunk_config: Optional[SIPOutboundConfig] = None,
) -> SIPParticipantInfo:
"""Create a new SIP participant.
Args:
create: Request containing participant details
timeout: Optional request timeout in seconds
trunk_id: Optional SIP trunk ID to use for the participant
outbound_trunk_config: Optional outbound trunk configuration for the participant
Returns:
Created SIP participant
Raises:
SIPError: If the SIP operation fails
"""
client_timeout: Optional[aiohttp.ClientTimeout] = None
if create.wait_until_answered:
# Dialing a phone and waiting for an answer takes longer than a
# normal call, and the request must outlast ringing. Pin the ring
# window so the timeout doesn't depend on the server's default.
_pin_ringing_timeout(create)
client_timeout = aiohttp.ClientTimeout(total=_dial_timeout(timeout, create))
elif timeout:
# obey user specified timeout
client_timeout = aiohttp.ClientTimeout(total=timeout)
if trunk_id:
create.sip_trunk_id = trunk_id
if outbound_trunk_config:
create.trunk = outbound_trunk_config
try:
return await self._client.request(
SVC,
"CreateSIPParticipant",
create,
self._auth_header(VideoGrants(), sip=SIPGrants(call=True)),
SIPParticipantInfo,
timeout=client_timeout,
)
except ServerError as e:
raise _as_sip_error(e) from None
async def transfer_sip_participant(
self,
transfer: TransferSIPParticipantRequest,
*,
timeout: Optional[float] = None,
) -> SIPParticipantInfo:
"""Transfer a SIP participant to a different room.
Args:
transfer: Request containing transfer details
timeout: Optional request timeout in seconds. Transferring dials a
phone, which takes longer than normal, so it defaults to a
longer timeout when unset.
Returns:
Updated SIP participant information
"""
# Transferring a call dials a phone, which takes longer than a normal
# call, so keep the request alive past ringing. Pin the ring window so the
# timeout doesn't depend on the server's default.
_pin_ringing_timeout(transfer)
client_timeout = aiohttp.ClientTimeout(total=_dial_timeout(timeout, transfer))
try:
return await self._client.request(
SVC,
"TransferSIPParticipant",
transfer,
self._auth_header(
VideoGrants(
room_admin=True,
room=transfer.room_name,
),
sip=SIPGrants(call=True),
),
SIPParticipantInfo,
timeout=client_timeout,
)
except ServerError as e:
raise _as_sip_error(e) from None
def _admin_headers(self) -> dict[str, str]:
return self._auth_header(VideoGrants(), sip=SIPGrants(admin=True))