Add extra zeroconf stuff in http to announce mopidy-http as it's own service
This is intended to help clients using the websocket api discover mopidy
This commit is contained in:
parent
203b13aad7
commit
4e8f1c7d54
@ -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()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user