http: Polish Mopidy-HTTP Zeroconf service
Builds upon #725 to: - Remove extra config for Mopidy-HTTP Zeroconf service - Refactor Zeroconf setup code in the HTTP frontend a bit - Add documentation
This commit is contained in:
parent
1b5c21452f
commit
2979de0f94
@ -33,6 +33,13 @@ Feature release.
|
|||||||
:meth:`~mopidy.ext.Extension.register_gstreamer_elements`. Use
|
:meth:`~mopidy.ext.Extension.register_gstreamer_elements`. Use
|
||||||
:meth:`mopidy.ext.Extension.setup` instead, as most extensions already do.
|
:meth:`mopidy.ext.Extension.setup` instead, as most extensions already do.
|
||||||
|
|
||||||
|
**HTTP frontend**
|
||||||
|
|
||||||
|
- If Zeroconf is enabled, we now announce the ``_mopidy-http._tcp`` service in
|
||||||
|
addition to ``_http._tcp``. This is to make it easier to automatically find
|
||||||
|
Mopidy's HTTP server among other Zeroconf-published HTTP servers on the
|
||||||
|
local network.
|
||||||
|
|
||||||
**MPD frontend**
|
**MPD frontend**
|
||||||
|
|
||||||
- Proper command tokenization for MPD requests. This replaces the old regex
|
- Proper command tokenization for MPD requests. This replaces the old regex
|
||||||
|
|||||||
@ -108,4 +108,7 @@ See :ref:`config` for general help on configuring Mopidy.
|
|||||||
Name of the HTTP service when published through Zeroconf. The variables
|
Name of the HTTP service when published through Zeroconf. The variables
|
||||||
``$hostname`` and ``$port`` can be used in the name.
|
``$hostname`` and ``$port`` can be used in the name.
|
||||||
|
|
||||||
|
If set, the Zeroconf services ``_http._tcp`` and ``_mopidy-http._tcp`` will
|
||||||
|
be published.
|
||||||
|
|
||||||
Set to an empty string to disable Zeroconf for HTTP.
|
Set to an empty string to disable Zeroconf for HTTP.
|
||||||
|
|||||||
@ -22,7 +22,6 @@ class Extension(ext.Extension):
|
|||||||
schema['port'] = config.Port()
|
schema['port'] = config.Port()
|
||||||
schema['static_dir'] = config.Path(optional=True)
|
schema['static_dir'] = config.Path(optional=True)
|
||||||
schema['zeroconf'] = config.String(optional=True)
|
schema['zeroconf'] = config.String(optional=True)
|
||||||
schema['zeroconf-websocket'] = config.String(optional=True)
|
|
||||||
return schema
|
return schema
|
||||||
|
|
||||||
def validate_environment(self):
|
def validate_environment(self):
|
||||||
|
|||||||
@ -25,10 +25,8 @@ class HttpFrontend(pykka.ThreadingActor, CoreListener):
|
|||||||
|
|
||||||
self.hostname = config['http']['hostname']
|
self.hostname = config['http']['hostname']
|
||||||
self.port = config['http']['port']
|
self.port = config['http']['port']
|
||||||
self.zeroconf_http_name = config['http']['zeroconf']
|
self.zeroconf_name = config['http']['zeroconf']
|
||||||
self.zeroconf_http_service = None
|
self.zeroconf_service = None
|
||||||
self.zeroconf_websocket_name = config['http']['zeroconf-websocket']
|
|
||||||
self.zeroconf_websocket_service = None
|
|
||||||
|
|
||||||
self._setup_server()
|
self._setup_server()
|
||||||
self._setup_websocket_plugin()
|
self._setup_websocket_plugin()
|
||||||
@ -95,39 +93,11 @@ class HttpFrontend(pykka.ThreadingActor, CoreListener):
|
|||||||
logger.debug('Starting HTTP server')
|
logger.debug('Starting HTTP server')
|
||||||
cherrypy.engine.start()
|
cherrypy.engine.start()
|
||||||
logger.info('HTTP server running at %s', cherrypy.server.base())
|
logger.info('HTTP server running at %s', cherrypy.server.base())
|
||||||
|
self._publish_zeroconf()
|
||||||
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_http_service.publish():
|
|
||||||
logger.debug(
|
|
||||||
'Registered HTTP with Zeroconf as "%s"',
|
|
||||||
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):
|
def on_stop(self):
|
||||||
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')
|
logger.debug('Stopping HTTP server')
|
||||||
|
self._unpublish_zeroconf()
|
||||||
cherrypy.engine.exit()
|
cherrypy.engine.exit()
|
||||||
logger.info('Stopped HTTP server')
|
logger.info('Stopped HTTP server')
|
||||||
|
|
||||||
@ -137,6 +107,39 @@ class HttpFrontend(pykka.ThreadingActor, CoreListener):
|
|||||||
message = json.dumps(event, cls=models.ModelJSONEncoder)
|
message = json.dumps(event, cls=models.ModelJSONEncoder)
|
||||||
cherrypy.engine.publish('websocket-broadcast', TextMessage(message))
|
cherrypy.engine.publish('websocket-broadcast', TextMessage(message))
|
||||||
|
|
||||||
|
def _publish_zeroconf(self):
|
||||||
|
if not self.zeroconf_name:
|
||||||
|
return
|
||||||
|
|
||||||
|
self.zeroconf_http_service = zeroconf.Zeroconf(
|
||||||
|
stype='_http._tcp', name=self.zeroconf_name,
|
||||||
|
host=self.hostname, port=self.port)
|
||||||
|
|
||||||
|
if self.zeroconf_http_service.publish():
|
||||||
|
logger.debug(
|
||||||
|
'Registered HTTP with Zeroconf as "%s"',
|
||||||
|
self.zeroconf_http_service.name)
|
||||||
|
else:
|
||||||
|
logger.debug('Registering HTTP with Zeroconf failed.')
|
||||||
|
|
||||||
|
self.zeroconf_mopidy_http_service = zeroconf.Zeroconf(
|
||||||
|
stype='_mopidy-http._tcp', name=self.zeroconf_name,
|
||||||
|
host=self.hostname, port=self.port)
|
||||||
|
|
||||||
|
if self.zeroconf_mopidy_http_service.publish():
|
||||||
|
logger.debug(
|
||||||
|
'Registered Mopidy-HTTP with Zeroconf as "%s"',
|
||||||
|
self.zeroconf_mopidy_http_service.name)
|
||||||
|
else:
|
||||||
|
logger.debug('Registering Mopidy-HTTP with Zeroconf failed.')
|
||||||
|
|
||||||
|
def _unpublish_zeroconf(self):
|
||||||
|
if self.zeroconf_http_service:
|
||||||
|
self.zeroconf_http_service.unpublish()
|
||||||
|
|
||||||
|
if self.zeroconf_mopidy_http_service:
|
||||||
|
self.zeroconf_mopidy_http_service.unpublish()
|
||||||
|
|
||||||
|
|
||||||
class RootResource(object):
|
class RootResource(object):
|
||||||
pass
|
pass
|
||||||
|
|||||||
@ -4,4 +4,3 @@ hostname = 127.0.0.1
|
|||||||
port = 6680
|
port = 6680
|
||||||
static_dir =
|
static_dir =
|
||||||
zeroconf = Mopidy HTTP server on $hostname
|
zeroconf = Mopidy HTTP server on $hostname
|
||||||
zeroconf-websocket = Mopidy websocket server on $hostname
|
|
||||||
@ -29,7 +29,6 @@ class HttpEventsTest(unittest.TestCase):
|
|||||||
'port': 6680,
|
'port': 6680,
|
||||||
'static_dir': None,
|
'static_dir': None,
|
||||||
'zeroconf': '',
|
'zeroconf': '',
|
||||||
'zeroconf-websocket': '',
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
self.http = actor.HttpFrontend(config=config, core=mock.Mock())
|
self.http = actor.HttpFrontend(config=config, core=mock.Mock())
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user