Skip to content

Commit

Permalink
Fix some type checking issues
Browse files Browse the repository at this point in the history
  • Loading branch information
jaminh committed Jul 17, 2024
1 parent 5079d20 commit 37a2e73
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 15 deletions.
20 changes: 8 additions & 12 deletions voip_utils/call_phone.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
load_dotenv()

CALL_SRC_USER = os.getenv("CALL_SRC_USER")
CALL_SRC_IP = os.getenv("CALL_SRC_IP")
CALL_SRC_PORT = int(os.getenv("CALL_SRC_PORT"))
CALL_SRC_IP = os.getenv("CALL_SRC_IP", "127.0.0.1")
CALL_SRC_PORT = int(os.getenv("CALL_SRC_PORT", 5060))
CALL_VIA_IP = os.getenv("CALL_VIA_IP")
CALL_DEST_IP = os.getenv("CALL_DEST_IP")
CALL_DEST_PORT = int(os.getenv("CALL_DEST_PORT"))
CALL_DEST_IP = os.getenv("CALL_DEST_IP", "127.0.0.1")
CALL_DEST_PORT = int(os.getenv("CALL_DEST_PORT", 5060))
CALL_DEST_USER = os.getenv("CALL_DEST_USER")


Expand All @@ -34,15 +34,15 @@
"sleep_ratio": 0.99,
}

CallProtocolFactory = Callable[[CallInfo, RtcpState], asyncio.Protocol]
CallProtocolFactory = Callable[[CallInfo, RtcpState], asyncio.DatagramProtocol]


class VoipCallDatagramProtocol(CallPhoneDatagramProtocol):
"""UDP server for Voice over IP (VoIP)."""

def __init__(
self,
sdp_info: SdpInfo,
sdp_info: SdpInfo | None,
source_endpoint: SipEndpoint,
dest_endpoint: SipEndpoint,
rtp_port: int,
Expand Down Expand Up @@ -130,7 +130,8 @@ def __init__(
self.message_delay = message_delay
self.loop_delay = loop_delay
self._audio_task: asyncio.Task | None = None
self._audio_bytes: bytes | None = None
file_path = Path(__file__).parent / self.file_name
self._audio_bytes: bytes = file_path.read_bytes()
_LOGGER.debug("Created PreRecordMessageProtocol")

def on_chunk(self, audio_bytes: bytes) -> None:
Expand All @@ -139,11 +140,6 @@ def on_chunk(self, audio_bytes: bytes) -> None:
if self.transport is None:
return

if self._audio_bytes is None:
# 16Khz, 16-bit mono audio message
file_path = Path(__file__).parent / self.file_name
self._audio_bytes = file_path.read_bytes()

if self._audio_task is None:
self._audio_task = self.loop.create_task(
self._play_message(),
Expand Down
6 changes: 3 additions & 3 deletions voip_utils/sip.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ class SipEndpoint:

host: str
port: int
username: str
description: str
username: str | None
description: str | None

@property
def sip_uri(self) -> str:
Expand Down Expand Up @@ -346,7 +346,7 @@ def _parse_sip(
class CallPhoneDatagramProtocol(asyncio.DatagramProtocol, ABC):
def __init__(
self,
sdp_info: SdpInfo,
sdp_info: SdpInfo | None,
source: SipEndpoint,
dest: SipEndpoint,
rtp_port: int,
Expand Down

0 comments on commit 37a2e73

Please sign in to comment.