tayler6000 / pyVoIP

Pure python VoIP/SIP/RTP library. Currently supports PCMA, PCMU, and telephone-event
https://pypi.org/project/pyVoIP/
GNU General Public License v3.0
235 stars 109 forks source link

Deny Not Working #243

Open TECH7Fox opened 9 months ago

TECH7Fox commented 9 months ago

When I call call.deny() I get this error: AttributeError: 'RTPClient' object has no attribute 'sin'

Traceback (most recent call last):
  File "/config/custom_components/sipclient/__init__.py", line 189, in deny_call
    call.deny()
  File "/usr/local/lib/python3.11/site-packages/pyVoIP/VoIP/VoIP.py", line 413, in deny
    x.stop()
  File "/usr/local/lib/python3.11/site-packages/pyVoIP/RTP.py", line 354, in stop
    self.sin.close()
    ^^^^^^^^
AttributeError: 'RTPClient' object has no attribute 'sin'

Seems like it tries to stop the RTPClient when it never started? For now I manually set the callstate to ENDED when it throws a error, which seems to work.

try:
    call.deny()
except:
    call.state = CallState.ENDED
mptsolutions commented 6 months ago

I solved this by commenting out line 413 and 414 of RTP.py. Since the RTP clients will only have a self.sin object if they were started, there is no need to stop them in the case of a call that has not yet been answered.

def deny(self) -> None:
    if self.state != CallState.RINGING:
        raise InvalidStateError("Call is not ringing")
    message = self.sip.gen_busy(self.request)
    self.sip.out.sendto(
        message.encode("utf8"), (self.phone.server, self.phone.port)
    )
    # for x in self.RTPClients:
    #     x.stop()
    self.state = CallState.ENDED
    del self.phone.calls[self.request.headers["Call-ID"]]