Skip to content

Commit

Permalink
[FIX] Fixed broken references to phone.rtp_port_high and low in VoIPCall
Browse files Browse the repository at this point in the history
  • Loading branch information
tayler6000 committed Jan 3, 2024
1 parent 200ac5c commit eac3e50
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 19 deletions.
4 changes: 2 additions & 2 deletions pyVoIP/VoIP/call.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ def __init__(
self.session_id = str(session_id)
self.bind_ip = bind_ip
self.conn = conn
self.rtp_port_high = self.phone.rtp_port_high
self.rtp_port_low = self.phone.rtp_port_low
self.rtp_port_high = self.phone.voip_phone_parameter.rtp_port_high
self.rtp_port_low = self.phone.voip_phone_parameter.rtp_port_low
self.sendmode = sendmode

self.dtmfLock = Lock()
Expand Down
46 changes: 29 additions & 17 deletions pyVoIP/VoIP/phone.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,7 @@
import time


__all__ = [
"PhoneStatus",
"VoIPPhone",
"VoIPPhoneParameter"
]
__all__ = ["PhoneStatus", "VoIPPhone", "VoIPPhoneParameter"]

debug = pyVoIP.debug

Expand Down Expand Up @@ -58,18 +54,25 @@ class VoIPPhoneParameter:


class VoIPPhone:
def __init__(
self,
voip_phone_parameter: VoIPPhoneParameter
):
# data may transferred in voi
def __init__(self, voip_phone_parameter: VoIPPhoneParameter):
self.voip_phone_parameter = voip_phone_parameter
if self.voip_phone_parameter.rtp_port_low > self.voip_phone_parameter.rtp_port_high:
if (
self.voip_phone_parameter.rtp_port_low
> self.voip_phone_parameter.rtp_port_high
):
raise InvalidRangeError(
"'rtp_port_high' must be >= 'rtp_port_low'"
"`rtp_port_high` must be >= `rtp_port_low`"
)
self.callClass = self.voip_phone_parameter.callClass is not None and self.voip_phone_parameter.callClass or VoIPCall
self.sipClass = self.voip_phone_parameter.sipClass is not None and self.voip_phone_parameter.sipClass or SIP.SIPClient
self.callClass = (
self.voip_phone_parameter.callClass is not None
and self.voip_phone_parameter.callClass
or VoIPCall
)
self.sipClass = (
self.voip_phone_parameter.sipClass is not None
and self.voip_phone_parameter.sipClass
or SIP.SIPClient
)
# data defined in class
self._status = PhoneStatus.INACTIVE
self.NSD = False
Expand Down Expand Up @@ -357,22 +360,31 @@ def message(
def request_port(self, blocking=True) -> int:
ports_available = [
port
for port in range(self.voip_phone_parameter.rtp_port_low, self.voip_phone_parameter.rtp_port_high + 1)
for port in range(
self.voip_phone_parameter.rtp_port_low,
self.voip_phone_parameter.rtp_port_high + 1,
)
if port not in self.assignedPorts
]
if len(ports_available) == 0:
# If no ports are available attempt to cleanup any missed calls.
self.release_ports()
ports_available = [
port
for port in range(self.voip_phone_parameter.rtp_port_low, self.voip_phone_parameter.rtp_port_high + 1)
for port in range(
self.voip_phone_parameter.rtp_port_low,
self.voip_phone_parameter.rtp_port_high + 1,
)
if (port not in self.assignedPorts)
]

while self.NSD and blocking and len(ports_available) == 0:
ports_available = [
port
for port in range(self.voip_phone_parameter.rtp_port_low, self.voip_phone_parameter.rtp_port_high + 1)
for port in range(
self.voip_phone_parameter.rtp_port_low,
self.voip_phone_parameter.rtp_port_high + 1,
)
if (port not in self.assignedPorts)
]
time.sleep(0.5)
Expand Down

0 comments on commit eac3e50

Please sign in to comment.