Merge wlcx/feature/zeroconf-announce-mopidy into develop
This commit is contained in:
commit
1b5c21452f
@ -22,6 +22,7 @@ class Extension(ext.Extension):
|
||||
schema['port'] = config.Port()
|
||||
schema['static_dir'] = config.Path(optional=True)
|
||||
schema['zeroconf'] = config.String(optional=True)
|
||||
schema['zeroconf-websocket'] = config.String(optional=True)
|
||||
return schema
|
||||
|
||||
def validate_environment(self):
|
||||
|
||||
@ -25,8 +25,10 @@ class HttpFrontend(pykka.ThreadingActor, CoreListener):
|
||||
|
||||
self.hostname = config['http']['hostname']
|
||||
self.port = config['http']['port']
|
||||
self.zeroconf_name = config['http']['zeroconf']
|
||||
self.zeroconf_service = None
|
||||
self.zeroconf_http_name = config['http']['zeroconf']
|
||||
self.zeroconf_http_service = None
|
||||
self.zeroconf_websocket_name = config['http']['zeroconf-websocket']
|
||||
self.zeroconf_websocket_service = None
|
||||
|
||||
self._setup_server()
|
||||
self._setup_websocket_plugin()
|
||||
@ -94,21 +96,36 @@ class HttpFrontend(pykka.ThreadingActor, CoreListener):
|
||||
cherrypy.engine.start()
|
||||
logger.info('HTTP server running at %s', cherrypy.server.base())
|
||||
|
||||
if self.zeroconf_name:
|
||||
self.zeroconf_service = zeroconf.Zeroconf(
|
||||
stype='_http._tcp', name=self.zeroconf_name,
|
||||
if self.zeroconf_http_name:
|
||||
self.zeroconf_http_service = zeroconf.Zeroconf(
|
||||
stype='_http._tcp', name=self.zeroconf_http_name,
|
||||
host=self.hostname, port=self.port)
|
||||
|
||||
if self.zeroconf_service.publish():
|
||||
if self.zeroconf_http_service.publish():
|
||||
logger.debug(
|
||||
'Registered HTTP with Zeroconf as "%s"',
|
||||
self.zeroconf_service.name)
|
||||
self.zeroconf_http_service.name)
|
||||
else:
|
||||
logger.debug('Registering HTTP with Zeroconf failed.')
|
||||
|
||||
if self.zeroconf_websocket_name:
|
||||
self.zeroconf_websocket_service = zeroconf.Zeroconf(
|
||||
stype='_mopidy-http._tcp', name=self.zeroconf_websocket_name,
|
||||
host=self.hostname, port=self.port)
|
||||
|
||||
if self.zeroconf_websocket_service.publish():
|
||||
logger.debug(
|
||||
'Registered mopidy-http with Zeroconf as "%s"',
|
||||
self.zeroconf_websocket_service.name)
|
||||
else:
|
||||
logger.debug('Registering mopidy-http with Zeroconf failed.')
|
||||
|
||||
def on_stop(self):
|
||||
if self.zeroconf_service:
|
||||
self.zeroconf_service.unpublish()
|
||||
if self.zeroconf_http_service:
|
||||
self.zeroconf_http_service.unpublish()
|
||||
|
||||
if self.zeroconf_websocket_service:
|
||||
self.zeroconf_websocket_service.unpublish()
|
||||
|
||||
logger.debug('Stopping HTTP server')
|
||||
cherrypy.engine.exit()
|
||||
|
||||
@ -4,3 +4,4 @@ hostname = 127.0.0.1
|
||||
port = 6680
|
||||
static_dir =
|
||||
zeroconf = Mopidy HTTP server on $hostname
|
||||
zeroconf-websocket = Mopidy websocket server on $hostname
|
||||
@ -29,6 +29,7 @@ class HttpEventsTest(unittest.TestCase):
|
||||
'port': 6680,
|
||||
'static_dir': None,
|
||||
'zeroconf': '',
|
||||
'zeroconf-websocket': '',
|
||||
}
|
||||
}
|
||||
self.http = actor.HttpFrontend(config=config, core=mock.Mock())
|
||||
|
||||
Loading…
Reference in New Issue
Block a user