Skip to content

Commit 8a683bb

Browse files
committed
Add SIP services. Support SIP DTMF in RTC.
1 parent d59860e commit 8a683bb

24 files changed

+1090
-660
lines changed
+90
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
import aiohttp
2+
from livekit.protocol import sip as proto_sip
3+
from ._service import Service
4+
from .access_token import VideoGrants
5+
6+
SVC = "SIP"
7+
8+
9+
class SipService(Service):
10+
def __init__(
11+
self, session: aiohttp.ClientSession, url: str, api_key: str, api_secret: str
12+
):
13+
super().__init__(session, url, api_key, api_secret)
14+
15+
async def create_sip_trunk(
16+
self, create: proto_sip.CreateSIPTrunkRequest
17+
) -> proto_sip.SIPTrunkInfo:
18+
return await self._client.request(
19+
SVC,
20+
"CreateSIPTrunk",
21+
create,
22+
self._auth_header(VideoGrants()),
23+
proto_sip.SIPTrunkInfo,
24+
)
25+
26+
async def list_sip_trunk(
27+
self, list: proto_sip.ListSIPTrunkRequest
28+
) -> proto_sip.ListSIPTrunkResponse:
29+
return await self._client.request(
30+
SVC,
31+
"ListSIPTrunk",
32+
list,
33+
self._auth_header(VideoGrants()),
34+
proto_sip.ListSIPTrunkResponse,
35+
)
36+
37+
async def delete_sip_trunk(
38+
self, delete: proto_sip.DeleteSIPTrunkRequest
39+
) -> proto_sip.SIPTrunkInfo:
40+
return await self._client.request(
41+
SVC,
42+
"DeleteSIPTrunk",
43+
delete,
44+
self._auth_header(VideoGrants()),
45+
proto_sip.SIPTrunkInfo,
46+
)
47+
48+
async def create_sip_dispatch_rule(
49+
self, create: proto_sip.CreateSIPDispatchRuleRequest
50+
) -> proto_sip.SIPDispatchRuleInfo:
51+
return await self._client.request(
52+
SVC,
53+
"CreateSIPDispatchRule",
54+
create,
55+
self._auth_header(VideoGrants()),
56+
proto_sip.SIPDispatchRuleInfo,
57+
)
58+
59+
async def list_sip_dispatch_rule(
60+
self, list: proto_sip.ListSIPDispatchRuleRequest
61+
) -> proto_sip.ListSIPDispatchRuleResponse:
62+
return await self._client.request(
63+
SVC,
64+
"ListSIPDispatchRule",
65+
list,
66+
self._auth_header(VideoGrants()),
67+
proto_sip.ListSIPDispatchRuleResponse,
68+
)
69+
70+
async def delete_sip_dispatch_rule(
71+
self, delete: proto_sip.DeleteSIPDispatchRuleRequest
72+
) -> proto_sip.SIPDispatchRuleInfo:
73+
return await self._client.request(
74+
SVC,
75+
"DeleteSIPDispatchRule",
76+
delete,
77+
self._auth_header(VideoGrants()),
78+
proto_sip.SIPDispatchRuleInfo,
79+
)
80+
81+
async def create_sip_participant(
82+
self, create: proto_sip.CreateSIPParticipantRequest
83+
) -> proto_sip.SIPParticipantInfo:
84+
return await self._client.request(
85+
SVC,
86+
"CreateSIPParticipant",
87+
create,
88+
self._auth_header(VideoGrants()),
89+
proto_sip.SIPParticipantInfo,
90+
)

livekit-protocol/generate_proto.sh

+4-1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ protoc \
3131
$API_PROTOCOL/livekit_ingress.proto \
3232
$API_PROTOCOL/livekit_models.proto \
3333
$API_PROTOCOL/livekit_agent.proto \
34+
$API_PROTOCOL/livekit_sip.proto \
3435
$API_PROTOCOL/livekit_analytics.proto
3536

3637

@@ -59,7 +60,9 @@ mv "$API_OUT_PYTHON/livekit_agent_pb2.py" "$API_OUT_PYTHON/agent.py"
5960
mv "$API_OUT_PYTHON/livekit_agent_pb2.pyi" "$API_OUT_PYTHON/agent.pyi"
6061
mv "$API_OUT_PYTHON/livekit_analytics_pb2.py" "$API_OUT_PYTHON/analytics.py"
6162
mv "$API_OUT_PYTHON/livekit_analytics_pb2.pyi" "$API_OUT_PYTHON/analytics.pyi"
63+
mv "$API_OUT_PYTHON/livekit_sip_pb2.py" "$API_OUT_PYTHON/sip.py"
64+
mv "$API_OUT_PYTHON/livekit_sip_pb2.pyi" "$API_OUT_PYTHON/sip.pyi"
6265

63-
perl -i -pe 's|^(import (livekit_egress_pb2\|livekit_room_pb2\|livekit_webhook_pb2\|livekit_ingress_pb2\|livekit_models_pb2\|livekit_agent_pb2\|livekit_analytics_pb2))|from . $1|g' "$API_OUT_PYTHON"/*.py "$API_OUT_PYTHON"/*.pyi
66+
perl -i -pe 's|^(import (livekit_egress_pb2\|livekit_room_pb2\|livekit_webhook_pb2\|livekit_ingress_pb2\|livekit_models_pb2\|livekit_agent_pb2\|livekit_analytics_pb2\|livekit_sip_pb2))|from . $1|g' "$API_OUT_PYTHON"/*.py "$API_OUT_PYTHON"/*.pyi
6467

6568
perl -i -pe 's|livekit_(\w+)_pb2|${1}|g' "$API_OUT_PYTHON"/*.py "$API_OUT_PYTHON"/*.pyi

livekit-protocol/livekit/protocol/sip.py

+61
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

livekit-protocol/livekit/protocol/sip.pyi

+156
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)