|
|
|
@ -47,17 +47,16 @@ class PhoneEvent(object):
@@ -47,17 +47,16 @@ class PhoneEvent(object):
|
|
|
|
|
|
|
|
|
|
class PhoneInterface(object): |
|
|
|
|
def __init__(self, config): |
|
|
|
|
cbs = { |
|
|
|
|
'global_state_changed': self.__global_state_changed, |
|
|
|
|
'registration_state_changed': self.__registration_state_changed, |
|
|
|
|
'call_state_changed': self.__call_state_changed |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
self.__event_cbs = [] |
|
|
|
|
|
|
|
|
|
self.__config = config |
|
|
|
|
self.__core = LinphoneCommunicationSocket("/var/tmp/debian-sid/tmp/linphone") |
|
|
|
|
|
|
|
|
|
self.__core.onLinphoneCallIncomingReceived = self.on_LinphoneCallIncomingReceived |
|
|
|
|
self.__core.onLinphoneCallOutgoingRinging = self.on_LinphoneCallOutgoingRinging |
|
|
|
|
self.__core.onLinphoneCallConnected = self.on_LinphoneCallConnected |
|
|
|
|
self.__core.onLinphoneCallEnd = self.on_LinphoneCallEnd |
|
|
|
|
|
|
|
|
|
# Create and add all proxy configs |
|
|
|
|
for p in config.proxies: |
|
|
|
|
aid = self.__core.register(p.identity, p.proxy, p.password, p.username) # sip:XXXX@hg.eventphone.de, hg.eventphone.de, MySecretPassword, XXXX |
|
|
|
@ -82,52 +81,23 @@ class PhoneInterface(object):
@@ -82,52 +81,23 @@ class PhoneInterface(object):
|
|
|
|
|
#self.__core.video_capture_enabled = False |
|
|
|
|
#self.__core.video_display_enabled = False |
|
|
|
|
|
|
|
|
|
def __global_state_changed(self, core, state, msg): |
|
|
|
|
print('Global state changed:', state, msg) |
|
|
|
|
# TODO: Do we need events emitted here? |
|
|
|
|
pass |
|
|
|
|
|
|
|
|
|
def __registration_state_changed(self, core, proxyconf, state, msg): |
|
|
|
|
print('Registration state changed:', proxyconf, state, msg) |
|
|
|
|
evt = None |
|
|
|
|
if state == linphone.RegistrationState.Progress: |
|
|
|
|
evt = PhoneEvent.RegInProgress |
|
|
|
|
elif state == linphone.RegistrationState.Ok: |
|
|
|
|
evt = PhoneEvent.RegSuccessfull |
|
|
|
|
elif state == linphone.RegistrationState.None: |
|
|
|
|
evt = PhoneEvent.RegLost |
|
|
|
|
|
|
|
|
|
if evt is not None: |
|
|
|
|
for cb in self.__event_cbs: |
|
|
|
|
cb(evt) |
|
|
|
|
else: |
|
|
|
|
print('Unhandled registration state:', linphone.RegistrationState.string(state)) |
|
|
|
|
|
|
|
|
|
def __call_state_changed(self, core, call, state, msg): |
|
|
|
|
print('Call state changed:', call, state, msg) |
|
|
|
|
evt = None |
|
|
|
|
if state == linphone.CallState.IncomingReceived: |
|
|
|
|
evt = PhoneEvent.CallIncoming |
|
|
|
|
elif state == linphone.CallState.OutgoingRinging: |
|
|
|
|
evt = PhoneEvent.CallRinging |
|
|
|
|
elif state == linphone.CallState.Connected: |
|
|
|
|
evt = PhoneEvent.CallAccepted |
|
|
|
|
elif state == linphone.CallState.End: |
|
|
|
|
evt = PhoneEvent.CallEnded |
|
|
|
|
elif state == linphone.CallState.Error: |
|
|
|
|
error = call.error_info.reason |
|
|
|
|
if error == linphone.Reason.Busy: |
|
|
|
|
evt = PhoneEvent.CallBusy |
|
|
|
|
elif error == linphone.Reason.NotFound: |
|
|
|
|
evt = PhoneEvent.CallInvalidNumber |
|
|
|
|
else: |
|
|
|
|
evt = PhoneEvent.CallEnded |
|
|
|
|
|
|
|
|
|
if evt is not None: |
|
|
|
|
for cb in self.__event_cbs: |
|
|
|
|
cb(evt) |
|
|
|
|
else: |
|
|
|
|
print('Unhandled call state:', linphone.CallState.string(state)) |
|
|
|
|
|
|
|
|
|
def run_callbacks(self, evt): |
|
|
|
|
print(PhoneEvent.string(evt)) |
|
|
|
|
for cb in self.__event_cbs: |
|
|
|
|
cb(evt) |
|
|
|
|
|
|
|
|
|
def on_LinphoneCallIncomingReceived(self, event): |
|
|
|
|
self.run_callbacks(PhoneEvent.CallIncoming) |
|
|
|
|
|
|
|
|
|
def on_LinphoneCallOutgoingRinging(self, event): |
|
|
|
|
self.run_callbacks(PhoneEvent.CallRinging) |
|
|
|
|
|
|
|
|
|
def on_LinphoneCallConnected(self, event): |
|
|
|
|
self.run_callbacks(PhoneEvent.CallAccepted) |
|
|
|
|
|
|
|
|
|
def on_LinphoneCallEnd(self, event): |
|
|
|
|
self.run_callbacks(PhoneEvent.CallEnded) |
|
|
|
|
|
|
|
|
|
def __pollthread(self): |
|
|
|
|
while self.__running: |
|
|
|
|