diff --git a/openlp/core/api/zeroconf.py b/openlp/core/api/zeroconf.py index d43e13aa6..5d8c3c627 100644 --- a/openlp/core/api/zeroconf.py +++ b/openlp/core/api/zeroconf.py @@ -23,6 +23,8 @@ The :mod:`~openlp.core.api.zeroconf` module runs a Zerconf server so that OpenLP can advertise the RESTful API for devices on the network to discover. """ +import logging +import re import socket from time import sleep @@ -33,6 +35,11 @@ from openlp.core.common.registry import Registry from openlp.core.common.settings import Settings from openlp.core.threading import ThreadWorker, run_thread +# Skip names like "docker0", "tun0", "loopback_0", etc +INTERFACE_FILTER = re.compile('loopback|docker|tun', re.IGNORECASE) + +log = logging.getLogger(__name__) + class ZeroconfWorker(ThreadWorker): """ @@ -76,6 +83,7 @@ class ZeroconfWorker(ThreadWorker): zc.unregister_service(http_info) zc.unregister_service(ws_info) zc.close() + self.quit.emit() def stop(self): """ @@ -91,11 +99,11 @@ def start_zeroconf(): # When we're running tests, just skip this set up if this flag is set if Registry().get_flag('no_web_server'): return - ifaces = get_local_ip4() - for key in iter(ifaces): - address = ifaces.get(key)['ip'] - break http_port = Settings().value('api/port') ws_port = Settings().value('api/websocket port') - worker = ZeroconfWorker(address, http_port, ws_port) - run_thread(worker, 'api_zeroconf') + for name, interface in get_local_ip4().items(): + log.debug('Interface {name}: {interface}'.format(name=name, interface=interface)) + if not INTERFACE_FILTER.search(name): + # Only advertise on real interfaces + worker = ZeroconfWorker(interface['ip'], http_port, ws_port) + run_thread(worker, 'api_zeroconf_{name}'.format(name=name)) diff --git a/scripts/appveyor.yml b/scripts/appveyor.yml index 3e0e0ce3a..90644c733 100644 --- a/scripts/appveyor.yml +++ b/scripts/appveyor.yml @@ -18,7 +18,7 @@ environment: install: # Install dependencies from pypi - - "%PYTHON%\\python.exe -m pip install sqlalchemy alembic appdirs chardet beautifulsoup4 lxml Mako mysql-connector-python pytest mock pyodbc psycopg2 pypiwin32 websockets asyncio waitress six webob requests QtAwesome PyQt5 PyQtWebEngine pymediainfo PyMuPDF QDarkStyle python-vlc Pyro4" + - "%PYTHON%\\python.exe -m pip install sqlalchemy alembic appdirs chardet beautifulsoup4 lxml Mako mysql-connector-python pytest mock pyodbc psycopg2 pypiwin32 websockets asyncio waitress six webob requests QtAwesome PyQt5 PyQtWebEngine pymediainfo PyMuPDF QDarkStyle python-vlc Pyro4 zeroconf" build: off diff --git a/setup.py b/setup.py index 260f0f8be..75e343f45 100644 --- a/setup.py +++ b/setup.py @@ -185,7 +185,8 @@ using a computer and a data projector.""", 'SQLAlchemy >= 0.5', 'waitress', 'WebOb', - 'websockets' + 'websockets', + 'zeroconf' ], extras_require={ 'agpl-pdf': ['PyMuPDF'],