Skip to content

Commit

Permalink
Add SIP services. Support SIP DTMF in RTC.
Browse files Browse the repository at this point in the history
  • Loading branch information
dennwc committed Apr 9, 2024
1 parent d59860e commit 4eacb5d
Show file tree
Hide file tree
Showing 38 changed files with 1,293 additions and 860 deletions.
90 changes: 90 additions & 0 deletions livekit-api/livekit/api/sip_service.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import aiohttp
from livekit.protocol import sip as proto_sip
from ._service import Service
from .access_token import VideoGrants

SVC = "SIP"


class SipService(Service):
def __init__(
self, session: aiohttp.ClientSession, url: str, api_key: str, api_secret: str
):
super().__init__(session, url, api_key, api_secret)

async def create_sip_trunk(
self, create: proto_sip.CreateSipTrunkRequest
) -> proto_sip.SipTrunkInfo:
return await self._client.request(
SVC,
"CreateSIPTrunk",
create,
self._auth_header(VideoGrants()),
proto_sip.SipTrunkInfo,
)

async def list_sip_trunk(
self, list: proto_sip.ListSipTrunkRequest
) -> proto_sip.ListSipTrunkResponse:
return await self._client.request(
SVC,
"ListSIPTrunk",
list,
self._auth_header(VideoGrants()),
proto_sip.ListSipTrunkResponse,
)

async def delete_sip_trunk(
self, delete: proto_sip.DeleteSipTrunkRequest
) -> proto_sip.SipTrunkInfo:
return await self._client.request(
SVC,
"DeleteSIPTrunk",
delete,
self._auth_header(VideoGrants()),
proto_sip.SipTrunkInfo,
)

async def create_sip_dispatch_rule(
self, create: proto_sip.CreateSipDispatchRuleRequest
) -> proto_sip.SipDispatchRuleInfo:
return await self._client.request(
SVC,
"CreateSIPDispatchRule",
create,
self._auth_header(VideoGrants()),
proto_sip.SipDispatchRuleInfo,
)

async def list_sip_dispatch_rule(
self, list: proto_sip.ListSipDispatchRuleRequest
) -> proto_sip.ListSipDispatchRuleResponse:
return await self._client.request(
SVC,
"ListSIPDispatchRule",
list,
self._auth_header(VideoGrants()),
proto_sip.ListSipDispatchRuleResponse,
)

async def delete_sip_dispatch_rule(
self, delete: proto_sip.DeleteSipDispatchRuleRequest
) -> proto_sip.SipDispatchRuleInfo:
return await self._client.request(
SVC,
"DeleteSIPDispatchRule",
delete,
self._auth_header(VideoGrants()),
proto_sip.SipDispatchRuleInfo,
)

async def create_sip_participant(
self, create: proto_sip.CreateSipParticipantRequest
) -> proto_sip.SipParticipantInfo:
return await self._client.request(
SVC,
"CreateSIPParticipant",
create,
self._auth_header(VideoGrants()),
proto_sip.SipParticipantInfo,
)
5 changes: 4 additions & 1 deletion livekit-protocol/generate_proto.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ protoc \
$API_PROTOCOL/livekit_ingress.proto \
$API_PROTOCOL/livekit_models.proto \
$API_PROTOCOL/livekit_agent.proto \
$API_PROTOCOL/livekit_sip.proto \
$API_PROTOCOL/livekit_analytics.proto


Expand Down Expand Up @@ -59,7 +60,9 @@ mv "$API_OUT_PYTHON/livekit_agent_pb2.py" "$API_OUT_PYTHON/agent.py"
mv "$API_OUT_PYTHON/livekit_agent_pb2.pyi" "$API_OUT_PYTHON/agent.pyi"
mv "$API_OUT_PYTHON/livekit_analytics_pb2.py" "$API_OUT_PYTHON/analytics.py"
mv "$API_OUT_PYTHON/livekit_analytics_pb2.pyi" "$API_OUT_PYTHON/analytics.pyi"
mv "$API_OUT_PYTHON/livekit_sip_pb2.py" "$API_OUT_PYTHON/sip.py"
mv "$API_OUT_PYTHON/livekit_sip_pb2.pyi" "$API_OUT_PYTHON/sip.pyi"

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
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

perl -i -pe 's|livekit_(\w+)_pb2|${1}|g' "$API_OUT_PYTHON"/*.py "$API_OUT_PYTHON"/*.pyi
6 changes: 3 additions & 3 deletions livekit-protocol/livekit/protocol/agent.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 19 additions & 19 deletions livekit-protocol/livekit/protocol/agent.pyi

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions livekit-protocol/livekit/protocol/analytics.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 4eacb5d

Please sign in to comment.