Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SIP services. Support SIP DTMF in RTC. #190

Merged
merged 1 commit into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
61 changes: 61 additions & 0 deletions livekit-protocol/livekit/protocol/sip.py

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

156 changes: 156 additions & 0 deletions livekit-protocol/livekit/protocol/sip.pyi

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

Loading
Loading