Update 'trashtalker.py'
This commit is contained in:
parent
c60d5872d0
commit
b128aa14fd
|
@ -37,8 +37,8 @@ def elog(sev, source, line):
|
||||||
def olog(sev, source, line):
|
def olog(sev, source, line):
|
||||||
print("%s %s: %s" % ("*"*sev, source, line))
|
print("%s %s: %s" % ("*"*sev, source, line))
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
|
#SIGTERM handler; could be expanded to handle SIGKILL, SIGHUP, SIGUSR1, etc.
|
||||||
|
#Handling of SIGHUP or SIGUSR1 could be useful for "live" relaoding of playlist
|
||||||
def sighandle(_signo, _stack_frame):
|
def sighandle(_signo, _stack_frame):
|
||||||
global mainloop
|
global mainloop
|
||||||
mainloop=False
|
mainloop=False
|
||||||
|
@ -48,18 +48,18 @@ def sighandle(_signo, _stack_frame):
|
||||||
class SIPStates:
|
class SIPStates:
|
||||||
ringing=180
|
ringing=180
|
||||||
answer=200
|
answer=200
|
||||||
|
# Account Callback class
|
||||||
class AccountCb(pj.AccountCallback):
|
class AccountCb(pj.AccountCallback):
|
||||||
def __init__(self, account=None):
|
def __init__(self, account=None):
|
||||||
pj.AccountCallback.__init__(self, account)
|
pj.AccountCallback.__init__(self, account)
|
||||||
|
|
||||||
def on_incoming_call(self, call):
|
def on_incoming_call(self, call):
|
||||||
olog(2, "event-call-in", "caller %s dialled in" % call.info().remote_uri)
|
olog(2, "event-call-in", "caller %s dialled in" % call.info().remote_uri)
|
||||||
call.set_callback(CallCb(call))
|
call.set_callback(CallCb(call))
|
||||||
call.answer(SIPStates.ringing)
|
call.answer(SIPStates.ringing)
|
||||||
sleep(0.3)
|
sleep(0.3)
|
||||||
call.answer(SIPStates.answer)
|
call.answer(SIPStates.answer)
|
||||||
|
# Call Callback class
|
||||||
class CallCb(pj.CallCallback):
|
class CallCb(pj.CallCallback):
|
||||||
def __init__(self, call=None):
|
def __init__(self, call=None):
|
||||||
pj.CallCallback.__init__(self, call)
|
pj.CallCallback.__init__(self, call)
|
||||||
|
@ -131,17 +131,20 @@ def PjDeinit():
|
||||||
global sipport
|
global sipport
|
||||||
global lib
|
global lib
|
||||||
lib.hangup_all()
|
lib.hangup_all()
|
||||||
|
# allow time for cleanup before destroying objects
|
||||||
|
lib.handle_events(timeout=250)
|
||||||
try:
|
try:
|
||||||
lib.destroy()
|
|
||||||
acct.delete()
|
acct.delete()
|
||||||
|
lib.destroy()
|
||||||
lib=None
|
lib=None
|
||||||
transport=None
|
|
||||||
acct=None
|
acct=None
|
||||||
|
transport=None
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
elog(1, "deinit", "AttributeError when clearing down pjsip, this is likely fine")
|
elog(1, "deinit", "AttributeError when clearing down pjsip, this is likely fine")
|
||||||
pass
|
pass
|
||||||
|
except pj.Error as e:
|
||||||
|
elog(1, "deinit", "pjsip error when clearing down: %s" % str(e))
|
||||||
|
pass
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
olog(1, "init", "initialising trashtalker")
|
olog(1, "init", "initialising trashtalker")
|
||||||
|
|
Loading…
Reference in New Issue