From 4e8f1c7d54bbd3fc16de7e31ea3abb119cc3432d Mon Sep 17 00:00:00 2001 From: Sam Willcocks Date: Sun, 27 Apr 2014 03:30:16 +0100 Subject: [PATCH 1/3] 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 --- mopidy/http/__init__.py | 1 + mopidy/http/actor.py | 35 ++++++++++++++++++++++++++--------- 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/mopidy/http/__init__.py b/mopidy/http/__init__.py index 25e2dd46..c51eaf29 100644 --- a/mopidy/http/__init__.py +++ b/mopidy/http/__init__.py @@ -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): diff --git a/mopidy/http/actor.py b/mopidy/http/actor.py index c5787fec..6510e6cf 100644 --- a/mopidy/http/actor.py +++ b/mopidy/http/actor.py @@ -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() From f54377eb8afa4ec9c5f246d80bfccb6193f6b14a Mon Sep 17 00:00:00 2001 From: Sam Willcocks Date: Sun, 27 Apr 2014 17:37:51 +0100 Subject: [PATCH 2/3] Update default http config to add new zeroconf-websocket option --- mopidy/http/ext.conf | 1 + 1 file changed, 1 insertion(+) diff --git a/mopidy/http/ext.conf b/mopidy/http/ext.conf index d35229bc..39bd6866 100644 --- a/mopidy/http/ext.conf +++ b/mopidy/http/ext.conf @@ -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 \ No newline at end of file From 05089fba3b8d9dc0e94a17e4086770e76bbdc1a6 Mon Sep 17 00:00:00 2001 From: Sam Willcocks Date: Sun, 27 Apr 2014 17:50:41 +0100 Subject: [PATCH 3/3] Update tests to add zeroconf-websocket config option --- tests/http/test_events.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/http/test_events.py b/tests/http/test_events.py index dbfa8413..2d96b42f 100644 --- a/tests/http/test_events.py +++ b/tests/http/test_events.py @@ -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())