Skip to content

Commit

Permalink
Merge pull request #25 from jaminh/voip-assist-sat-announce
Browse files Browse the repository at this point in the history
VOIP Assist Satellite Announce support
  • Loading branch information
synesthesiam authored Jan 27, 2025
2 parents 7801717 + 8c2429b commit 5fdfce6
Show file tree
Hide file tree
Showing 5 changed files with 450 additions and 529 deletions.
33 changes: 26 additions & 7 deletions call_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@

from dotenv import load_dotenv

from voip_utils.call_phone import VoipCallDatagramProtocol
from voip_utils.voip import VoipDatagramProtocol, CallProtocolFactory
from voip_utils.sip import (
CallInfo,
CallPhoneDatagramProtocol,
SdpInfo,
SipEndpoint,
get_sip_endpoint,
Expand Down Expand Up @@ -52,6 +51,22 @@ def get_env_int(env_var: str, default_val: int) -> int:
"sleep_ratio": 0.99,
}

class ExampleVoipDatagramProtocol(VoipDatagramProtocol):

def __init__(
self,
sdp_info: SdpInfo,
valid_protocol_factory: CallProtocolFactory,
invalid_protocol_factory: Optional[CallProtocolFactory] = None,
) -> None:
"""Set up VoIP call handler."""
super().__init__(sdp_info, valid_protocol_factory, invalid_protocol_factory)
self.call_end = asyncio.Event()


def on_hangup(self, call_info: CallInfo):
"""Example implementation of on hangup. """
self.call_end.set()

class PreRecordMessageProtocol(RtpDatagramProtocol):
"""Plays a pre-recorded message on a loop."""
Expand Down Expand Up @@ -153,11 +168,13 @@ async def main() -> None:
pass

_, protocol = await loop.create_datagram_endpoint(
lambda: VoipCallDatagramProtocol(
lambda: ExampleVoipDatagramProtocol(
None,
source,
destination,
rtp_port,
lambda call_info, rtcp_state: PreRecordMessageProtocol(
"problem.pcm",
call_info.opus_payload_type,
rtcp_state=rtcp_state,
),
lambda call_info, rtcp_state: PreRecordMessageProtocol(
"problem.pcm",
call_info.opus_payload_type,
Expand All @@ -167,7 +184,9 @@ async def main() -> None:
local_addr=(CALL_SRC_IP, CALL_SRC_PORT),
)

await protocol.wait_closed()
protocol.outgoing_call(source, destination, rtp_port)

await protocol.call_end.wait()


if __name__ == "__main__":
Expand Down
1 change: 1 addition & 0 deletions requirements_dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ black==23.3.0
flake8==7.1.0
isort==5.12.0
mypy==1.1.1
opuslib==3.0.1
pylint==3.2.5
pytest==7.2.2
python-dotenv==1.0.1
101 changes: 0 additions & 101 deletions voip_utils/call_phone.py

This file was deleted.

Loading

0 comments on commit 5fdfce6

Please sign in to comment.