diff --git a/voip_utils/call_phone.py b/voip_utils/call_phone.py index 68b48e4..59f84b3 100644 --- a/voip_utils/call_phone.py +++ b/voip_utils/call_phone.py @@ -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") @@ -34,7 +34,7 @@ "sleep_ratio": 0.99, } -CallProtocolFactory = Callable[[CallInfo, RtcpState], asyncio.Protocol] +CallProtocolFactory = Callable[[CallInfo, RtcpState], asyncio.DatagramProtocol] class VoipCallDatagramProtocol(CallPhoneDatagramProtocol): @@ -42,7 +42,7 @@ class VoipCallDatagramProtocol(CallPhoneDatagramProtocol): def __init__( self, - sdp_info: SdpInfo, + sdp_info: SdpInfo | None, source_endpoint: SipEndpoint, dest_endpoint: SipEndpoint, rtp_port: int, @@ -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: @@ -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(), diff --git a/voip_utils/sip.py b/voip_utils/sip.py index 7ff7290..a64c41e 100644 --- a/voip_utils/sip.py +++ b/voip_utils/sip.py @@ -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: @@ -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,