Skip to main content

Py Session SetHangupHook

About

Slightly different than the JS counterpart in that it calls back with a uuid rather than a session instance.

Example 1

def hangup_hook(uuid):
console_log("INFO","\n\nhangup hook, uuid: %s!!\n\n" % uuid)
return "Result"

def handler(uuid):
session = PySession(uuid)
session.setHangupHook(hangup_hook)
session.hangup("1")

Example 2

Use a nested method in order to have the PySession object in scope.

class TestSuite1:

def __init__(self, session):
self.session = session
self.session.answer()
def hangup_hook(uuid):
console_log("INFO","\n\nhangup hook, session: %s!!\n\n" % self.session)
return "Result"
self.session.setHangupHook(hangup_hook)

def handler(uuid):
session = PySession(uuid)
testsuite1 = TestSuite1(session)
testsuite1.run_test()

Hanging call problem

In the FreeSWITCH-1.4.7~64bit, some call case(python script) makes hanging call. But, it's not the matter of call scenario. Some call cases are fired wrong python exception handler. It might be fixed in the newest version of FreeSWITCH, but, it would be helpful for older version users.

In the freeswitch python script, we can set the hangup hook function. But after sets the hook, return or finish the script without destroy() function call, it makes hanging call.

Problem case :
Just finished the script without calling the destroy() function.

    ...
session.setHangupHook(hangup_handler)
return

Fixed case :
Finished the script with calling the destroy() function.

    ...
session.setHangupHook(hangup_handler)
session.destroy()
return