Added config classes for phone interface
This commit is contained in:
parent
7b15aa13c1
commit
d1d2976e6a
|
@ -3,6 +3,24 @@ import time
|
||||||
import threading
|
import threading
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
|
class PhoneProxyConfiguration(object):
|
||||||
|
def __init__(self):
|
||||||
|
self.name = 'eventphone'
|
||||||
|
self.proxy = 'sip:hg.eventphone.de'
|
||||||
|
self.identity = 'sip:0815@hg.eventphone.de'
|
||||||
|
self.username = '0815'
|
||||||
|
self.password = 'secret'
|
||||||
|
self.realm = 'hg.eventphone.de'
|
||||||
|
|
||||||
|
class PhoneConfiguration(object):
|
||||||
|
def __init__(self):
|
||||||
|
self.sound_device = 'default:CARD=Device'
|
||||||
|
self.incoming_timeout = 3*60
|
||||||
|
self.linphone_config = 'linphone.conf'
|
||||||
|
self.default_proxy = 'eventphone'
|
||||||
|
self.proxies = []
|
||||||
|
self.stun_server = 'sipgate.de'
|
||||||
|
|
||||||
class PhoneEvent(object):
|
class PhoneEvent(object):
|
||||||
RegInProgress,\
|
RegInProgress,\
|
||||||
RegSuccessfull,\
|
RegSuccessfull,\
|
||||||
|
@ -21,7 +39,7 @@ class PhoneEvent(object):
|
||||||
return k
|
return k
|
||||||
|
|
||||||
class PhoneInterface(object):
|
class PhoneInterface(object):
|
||||||
def __init__(self, config, roconfig):
|
def __init__(self, config):
|
||||||
cbs = {
|
cbs = {
|
||||||
'global_state_changed': self.__global_state_changed,
|
'global_state_changed': self.__global_state_changed,
|
||||||
'registration_state_changed': self.__registration_state_changed,
|
'registration_state_changed': self.__registration_state_changed,
|
||||||
|
@ -30,14 +48,38 @@ class PhoneInterface(object):
|
||||||
|
|
||||||
self.__event_cbs = []
|
self.__event_cbs = []
|
||||||
|
|
||||||
self.__core = linphone.Core.new(cbs, config, roconfig)
|
self.__config = config
|
||||||
|
self.__core = linphone.Core.new(cbs, None, config.linphone_config)
|
||||||
|
|
||||||
|
# Create and add all proxy configs
|
||||||
|
for p in config.proxies:
|
||||||
|
ainfo = self.__core.create_auth_info(p.username, p.username, p.password, None, p.realm, None)
|
||||||
|
self.__core.add_auth_info(ainfo)
|
||||||
|
|
||||||
|
pconf = self.__core.create_proxy_config()
|
||||||
|
pconf.edit()
|
||||||
|
pconf.identity = p.identity
|
||||||
|
pconf.publish_enabled = False
|
||||||
|
pconf.realm = p.realm
|
||||||
|
pconf.register_enabled = True
|
||||||
|
pconf.register_enabled = True
|
||||||
|
pconf.server_addr = p.proxy
|
||||||
|
self.__core.add_proxy_config(pconf)
|
||||||
|
pconf.done()
|
||||||
|
|
||||||
|
if p.name == config.default_proxy:
|
||||||
|
self.__core.default_proxy_config = pconf
|
||||||
|
|
||||||
self.__audioproc = None
|
self.__audioproc = None
|
||||||
|
aplay = subprocess.Popen(['aplay', '-qD%s' % config.sound_device], stdin=subprocess.PIPE)
|
||||||
|
self.__ttsproc = subprocess.Popen(['espeak', '-p10', '--stdout'], stdin=subprocess.PIPE, stdout=aplay.stdin)
|
||||||
|
|
||||||
# Set default parameters overriding the ones from the given config file
|
# Set default parameters overriding the ones from the given config file
|
||||||
self.__core.set_user_agent('FeTAp 615', '0.1')
|
self.__core.set_user_agent('FeTAp 615', '0.1')
|
||||||
|
self.__core.stun_server = config.stun_server
|
||||||
self.__core.ringback = ''
|
self.__core.ringback = ''
|
||||||
self.__core.max_calls = 1
|
self.__core.max_calls = 1
|
||||||
|
self.__core.inc_timeout = config.incoming_timeout
|
||||||
self.__core.set_call_error_tone(linphone.Reason.Busy, '')
|
self.__core.set_call_error_tone(linphone.Reason.Busy, '')
|
||||||
self.__core.disable_chat(linphone.Reason.None)
|
self.__core.disable_chat(linphone.Reason.None)
|
||||||
self.__core.echo_cancellation_enabled = False
|
self.__core.echo_cancellation_enabled = False
|
||||||
|
@ -90,7 +132,7 @@ class PhoneInterface(object):
|
||||||
cb(evt)
|
cb(evt)
|
||||||
else:
|
else:
|
||||||
print 'Unhandled call state:', linphone.CallState.string(state)
|
print 'Unhandled call state:', linphone.CallState.string(state)
|
||||||
|
|
||||||
def __pollthread(self):
|
def __pollthread(self):
|
||||||
while self.__running:
|
while self.__running:
|
||||||
self.__core.iterate()
|
self.__core.iterate()
|
||||||
|
@ -102,6 +144,9 @@ class PhoneInterface(object):
|
||||||
t.start()
|
t.start()
|
||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
|
self.stop_playing()
|
||||||
|
if self.__ttsproc is not None:
|
||||||
|
self.__ttsproc.terminate()
|
||||||
self.__running = False
|
self.__running = False
|
||||||
|
|
||||||
def add_event_cb(self, cb):
|
def add_event_cb(self, cb):
|
||||||
|
@ -123,24 +168,28 @@ class PhoneInterface(object):
|
||||||
self.stop_playing()
|
self.stop_playing()
|
||||||
self.__audioproc = subprocess.Popen(['play', '-nq', 'synth', 'sine', '425'],
|
self.__audioproc = subprocess.Popen(['play', '-nq', 'synth', 'sine', '425'],
|
||||||
env = {'AUDIODRIVER': 'alsa',
|
env = {'AUDIODRIVER': 'alsa',
|
||||||
'AUDIODEV': 'default:CARD=Device'})
|
'AUDIODEV': self.__config.sound_device})
|
||||||
|
|
||||||
def play_ringback_tone(self):
|
def play_ringback_tone(self):
|
||||||
self.stop_playing()
|
self.stop_playing()
|
||||||
self.__audioproc = subprocess.Popen(['play', '-nq', 'synth', '1', 'sine', '425', 'pad', '4@1', 'repeat', '1000'],
|
self.__audioproc = subprocess.Popen(['play', '-nq', 'synth', '1', 'sine', '425', 'pad', '4@1', 'repeat', '1000'],
|
||||||
env = {'AUDIODRIVER': 'alsa',
|
env = {'AUDIODRIVER': 'alsa',
|
||||||
'AUDIODEV': 'default:CARD=Device'})
|
'AUDIODEV': self.__config.sound_device})
|
||||||
|
|
||||||
def play_busy_tone(self):
|
def play_busy_tone(self):
|
||||||
self.stop_playing()
|
self.stop_playing()
|
||||||
self.__audioproc = subprocess.Popen(['play', '-nq', 'synth', '0.48', 'sine', '425', 'pad', '0.48@0.48', 'repeat', '1000'],
|
self.__audioproc = subprocess.Popen(['play', '-nq', 'synth', '0.48', 'sine', '425', 'pad', '0.48@0.48', 'repeat', '1000'],
|
||||||
env = {'AUDIODRIVER': 'alsa',
|
env = {'AUDIODRIVER': 'alsa',
|
||||||
'AUDIODEV': 'default:CARD=Device'})
|
'AUDIODEV': self.__config.sound_device})
|
||||||
|
|
||||||
def stop_playing(self):
|
def stop_playing(self):
|
||||||
if self.__audioproc is not None:
|
if self.__audioproc is not None:
|
||||||
self.__audioproc.terminate()
|
self.__audioproc.terminate()
|
||||||
|
|
||||||
|
def read_text(self, text):
|
||||||
|
self.__ttsproc.stdin.write(text + '\n')
|
||||||
|
self.__ttsproc.stdin.flush()
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
def event_cb(evt):
|
def event_cb(evt):
|
||||||
print 'Got event:', PhoneEvent.string(evt)
|
print 'Got event:', PhoneEvent.string(evt)
|
||||||
|
|
Loading…
Reference in a new issue