|
|
@ -1,8 +1,7 @@ |
|
|
|
import linphone |
|
|
|
|
|
|
|
import time |
|
|
|
import time |
|
|
|
import threading |
|
|
|
import threading |
|
|
|
import subprocess |
|
|
|
import subprocess |
|
|
|
from pylinphone import LinphoneCommunicationSocket |
|
|
|
from pylinphone.pylinphone import LinphoneCommunicationSocket |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class PhoneProxyConfiguration(object): |
|
|
|
class PhoneProxyConfiguration(object): |
|
|
@ -48,23 +47,19 @@ class PhoneEvent(object): |
|
|
|
|
|
|
|
|
|
|
|
class PhoneInterface(object): |
|
|
|
class PhoneInterface(object): |
|
|
|
def __init__(self, config): |
|
|
|
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.__event_cbs = [] |
|
|
|
|
|
|
|
|
|
|
|
self.__config = config |
|
|
|
self.__config = config |
|
|
|
self.__core = LinphoneCommunicationSocket("/tmp/lpdaemon") |
|
|
|
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 |
|
|
|
# Create and add all proxy configs |
|
|
|
for p in config.proxies: |
|
|
|
for p in config.proxies: |
|
|
|
ainfo = self.__core.create_auth_info(p.username, p.username, |
|
|
|
aid = self.__core.register(p.identity, p.proxy, p.password, p.username) # sip:XXXX@hg.eventphone.de, hg.eventphone.de, MySecretPassword, XXXX |
|
|
|
p.password, None, p.realm, |
|
|
|
|
|
|
|
None) |
|
|
|
|
|
|
|
aid = self.__core.register(p.username, p.proxy_address, p.password, p.username) # sip:XXXX@hg.eventphone.de, hg.eventphone.de, MySecretPassword, XXXX |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.__audioproc = None |
|
|
|
self.__audioproc = None |
|
|
|
aplay = subprocess.Popen(['aplay', '-qD%s' % config.sound_device], |
|
|
|
aplay = subprocess.Popen(['aplay', '-qD%s' % config.sound_device], |
|
|
@ -86,52 +81,23 @@ class PhoneInterface(object): |
|
|
|
#self.__core.video_capture_enabled = False |
|
|
|
#self.__core.video_capture_enabled = False |
|
|
|
#self.__core.video_display_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): |
|
|
|
def run_callbacks(self, evt): |
|
|
|
print('Registration state changed:', proxyconf, state, msg) |
|
|
|
print(PhoneEvent.string(evt)) |
|
|
|
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: |
|
|
|
for cb in self.__event_cbs: |
|
|
|
cb(evt) |
|
|
|
cb(evt) |
|
|
|
else: |
|
|
|
|
|
|
|
print('Unhandled registration state:', linphone.RegistrationState.string(state)) |
|
|
|
def on_LinphoneCallIncomingReceived(self, event): |
|
|
|
|
|
|
|
self.run_callbacks(PhoneEvent.CallIncoming) |
|
|
|
def __call_state_changed(self, core, call, state, msg): |
|
|
|
|
|
|
|
print('Call state changed:', call, state, msg) |
|
|
|
def on_LinphoneCallOutgoingRinging(self, event): |
|
|
|
evt = None |
|
|
|
self.run_callbacks(PhoneEvent.CallRinging) |
|
|
|
if state == linphone.CallState.IncomingReceived: |
|
|
|
|
|
|
|
evt = PhoneEvent.CallIncoming |
|
|
|
def on_LinphoneCallConnected(self, event): |
|
|
|
elif state == linphone.CallState.OutgoingRinging: |
|
|
|
self.run_callbacks(PhoneEvent.CallAccepted) |
|
|
|
evt = PhoneEvent.CallRinging |
|
|
|
|
|
|
|
elif state == linphone.CallState.Connected: |
|
|
|
def on_LinphoneCallEnd(self, event): |
|
|
|
evt = PhoneEvent.CallAccepted |
|
|
|
self.run_callbacks(PhoneEvent.CallEnded) |
|
|
|
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 __pollthread(self): |
|
|
|
def __pollthread(self): |
|
|
|
while self.__running: |
|
|
|
while self.__running: |
|
|
@ -153,23 +119,32 @@ class PhoneInterface(object): |
|
|
|
self.__event_cbs.append(cb) |
|
|
|
self.__event_cbs.append(cb) |
|
|
|
|
|
|
|
|
|
|
|
def call(self, number): |
|
|
|
def call(self, number): |
|
|
|
if '@' not in number and self.__core.default_proxy_config is None: |
|
|
|
if '@' not in number: |
|
|
|
|
|
|
|
proxy = None |
|
|
|
|
|
|
|
default_name = self.__config.default_proxy |
|
|
|
|
|
|
|
for p in self.__config.proxies: |
|
|
|
|
|
|
|
if p.name == default_name: |
|
|
|
|
|
|
|
proxy = p |
|
|
|
|
|
|
|
break |
|
|
|
|
|
|
|
if proxy is None: |
|
|
|
# Try to resolve prefix |
|
|
|
# Try to resolve prefix |
|
|
|
for p in self.__config.proxies: |
|
|
|
for p in self.__config.proxies: |
|
|
|
if number.startswith(p.prefix): |
|
|
|
if number.startswith(p.prefix): |
|
|
|
number = number[len(p.prefix):] |
|
|
|
number = number[len(p.prefix):] |
|
|
|
number += '@' + p.realm |
|
|
|
proxy = p |
|
|
|
break |
|
|
|
break |
|
|
|
self.__core.invite(number) |
|
|
|
if proxy is not None: |
|
|
|
|
|
|
|
number += '@' + proxy.realm |
|
|
|
|
|
|
|
self.__core.call(number) |
|
|
|
|
|
|
|
|
|
|
|
def accept_call(self): |
|
|
|
def accept_call(self): |
|
|
|
self.__core.accept_call(self.__core.current_call) |
|
|
|
self.__core.answer() |
|
|
|
|
|
|
|
|
|
|
|
def decline_call(self): |
|
|
|
def decline_call(self): |
|
|
|
self.__core.decline_call(self.__core.current_call, linphone.Reason.Busy) |
|
|
|
self.__core.decline_call(self.__core.current_call) |
|
|
|
|
|
|
|
|
|
|
|
def end_call(self): |
|
|
|
def end_call(self): |
|
|
|
self.__core.terminate_call(self.__core.current_call) |
|
|
|
self.__core.terminate() |
|
|
|
|
|
|
|
|
|
|
|
def play_dial_tone(self): |
|
|
|
def play_dial_tone(self): |
|
|
|
self.stop_playing() |
|
|
|
self.stop_playing() |
|
|
@ -203,7 +178,9 @@ class PhoneInterface(object): |
|
|
|
self.__ttsproc.stdin.flush() |
|
|
|
self.__ttsproc.stdin.flush() |
|
|
|
|
|
|
|
|
|
|
|
def get_remote_number(self): |
|
|
|
def get_remote_number(self): |
|
|
|
return self.__core.current_call_remote_address.username |
|
|
|
# FIXME |
|
|
|
|
|
|
|
#return self.__core.current_call_remote_address.username |
|
|
|
|
|
|
|
return '0000' |
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__': |
|
|
|
if __name__ == '__main__': |
|
|
|
def event_cb(evt): |
|
|
|
def event_cb(evt): |
|
|
|