Browse Source

Merge pull request 'Replace linphone with pylinphone' (#1) from sqozz/fetapi:pylinphone into pylinphone

Reviewed-on: https://git.blinkenbunt.org/LUG-Saar/fetapi/pulls/1
pylinphone
klonfish 4 years ago
parent
commit
c882bcd59f
  1. 46
      phoneinterface.py

46
phoneinterface.py

@ -2,6 +2,7 @@ import linphone
import time import time
import threading import threading
import subprocess import subprocess
from pylinphone import LinphoneCommunicationSocket
class PhoneProxyConfiguration(object): class PhoneProxyConfiguration(object):
@ -56,30 +57,14 @@ class PhoneInterface(object):
self.__event_cbs = [] self.__event_cbs = []
self.__config = config self.__config = config
self.__core = linphone.Core.new(cbs, None, config.linphone_config) self.__core = LinphoneCommunicationSocket("/tmp/lpdaemon")
# 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, ainfo = self.__core.create_auth_info(p.username, p.username,
p.password, None, p.realm, p.password, None, p.realm,
None) None)
self.__core.add_auth_info(ainfo) aid = self.__core.register(p.username, p.proxy_address, p.password, p.username) # sip:XXXX@hg.eventphone.de, hg.eventphone.de, MySecretPassword, XXXX
pconf = self.__core.create_proxy_config()
pconf.edit()
if self.__core.version < '3.9.0':
pconf.identity = p.identity
else:
pconf.identity_address = pconf.normalize_sip_uri(p.identity)
pconf.publish_enabled = False
pconf.realm = p.realm
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], aplay = subprocess.Popen(['aplay', '-qD%s' % config.sound_device],
@ -89,16 +74,17 @@ class PhoneInterface(object):
stdout=aplay.stdin) 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') # TODO: figure out how to set at least some of these settings through the unix socket
self.__core.stun_server = config.stun_server #self.__core.set_user_agent('FeTAp 615', '0.1')
self.__core.ringback = '' #self.__core.stun_server = config.stun_server
self.__core.max_calls = 1 #self.__core.ringback = ''
self.__core.inc_timeout = config.incoming_timeout #self.__core.max_calls = 1
self.__core.set_call_error_tone(linphone.Reason.Busy, '') #self.__core.inc_timeout = config.incoming_timeout
self.__core.disable_chat(linphone.Reason.None) #self.__core.set_call_error_tone(linphone.Reason.Busy, '')
self.__core.echo_cancellation_enabled = False #self.__core.disable_chat(linphone.Reason.None)
self.__core.video_capture_enabled = False #self.__core.echo_cancellation_enabled = False
self.__core.video_display_enabled = False #self.__core.video_capture_enabled = False
#self.__core.video_display_enabled = False
def __global_state_changed(self, core, state, msg): def __global_state_changed(self, core, state, msg):
print 'Global state changed:', state, msg print 'Global state changed:', state, msg
@ -149,8 +135,8 @@ class PhoneInterface(object):
def __pollthread(self): def __pollthread(self):
while self.__running: while self.__running:
self.__core.iterate() self.__core.process_event()
time.sleep(0.02) # Value from example code time.sleep(0.2) # Value for good measure
def start(self): def start(self):
self.__running = True self.__running = True

Loading…
Cancel
Save