mild refactor again, add dtmf handler (rudimentary)

This commit is contained in:
Matthew Connelly 2019-05-06 13:22:03 +01:00
parent 0e4bc692ab
commit eecf8ed026
1 changed files with 14 additions and 5 deletions

View File

@ -25,13 +25,18 @@ from random import shuffle
## Please also be aware that, by default, playlist length is limited to 64 items. I can find no reason ## Please also be aware that, by default, playlist length is limited to 64 items. I can find no reason
## for this limitation, and it is specific to the python bindings for the PJSUA library. ## for this limitation, and it is specific to the python bindings for the PJSUA library.
## If you'd like to have a playlist longer than 64 items, you will need to recompile python-pjsua ## If you'd like to have a playlist longer than 64 items, you will need to recompile python-pjsua
## with the appropriate adjustment to _pjsua.c line 2515 ## with the appropriate adjustment to pjsip-apps/src/python/_pjsua.c line 2515, in the definition for
## PyObject py_pjsua_playlist_create(self, args): pj_str_t files[64];
## A possible idea would be to make this configurable.
## ##
## If you can get this working using PJSUA2, a pull request would be greatly appreciated. ## If you can get this working using PJSUA2, a pull request would be greatly appreciated.
# Utility classes, used basically as enums or generics # Utility classes, used basically as enums or generics
class State(object): class State:
lib=None
running=False running=False
def stop(self):
self.running=False
class PJStates: class PJStates:
init=0 init=0
deinit=1 deinit=1
@ -64,7 +69,7 @@ def sighandle(_signo, _stack_frame):
elif _signo == 15: elif _signo == 15:
#SIGTERM #SIGTERM
Log(1, "sighandler", "SIGTERM invoked app shutdown") Log(1, "sighandler", "SIGTERM invoked app shutdown")
state.running=False state.stop()
pass pass
# Classes # Classes
@ -112,6 +117,10 @@ class CallCb(pj.CallCallback):
state.lib.playlist_destroy(self.instmedia) state.lib.playlist_destroy(self.instmedia)
Log(3, "event-call-conf-left", "removed trashtalk instance from call and destroyed it") Log(3, "event-call-conf-left", "removed trashtalk instance from call and destroyed it")
def on_dtmf_digit(self, digit):
global state
Log(2, "dtmf-digit", "received DTMF digit(s) %s" % digit)
#I'm not sure what this is for, as all media handling is actually done within the SIP events above #I'm not sure what this is for, as all media handling is actually done within the SIP events above
def on_media_state(self): def on_media_state(self):
if self.call.info().media_state == pj.MediaState.ACTIVE: if self.call.info().media_state == pj.MediaState.ACTIVE:
@ -206,10 +215,10 @@ def main():
WaitLoop() WaitLoop()
except pj.Error as e: except pj.Error as e:
Log(2, "pjsip-error", "trashtalker encountered pjsip exception %s" % str(e), error=True) Log(2, "pjsip-error", "trashtalker encountered pjsip exception %s" % str(e), error=True)
state.running=False state.stop()
pass pass
except KeyboardInterrupt: except KeyboardInterrupt:
state.running=False state.stop()
pass pass
Log(1, "deinit", "main loop exited, shutting down") Log(1, "deinit", "main loop exited, shutting down")
PJControl(PJStates.deinit) PJControl(PJStates.deinit)