From b4ad0b08308fc93721536e8f325e3a8f9636f510 Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Wed, 28 Nov 2012 15:59:08 +0100 Subject: [PATCH] http: Move WebSocket to /mopidy/ws/ --- mopidy/frontends/http/__init__.py | 6 +++--- mopidy/frontends/http/actor.py | 9 +++++++-- mopidy/frontends/http/data/index.html | 11 ++++++----- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/mopidy/frontends/http/__init__.py b/mopidy/frontends/http/__init__.py index 234f30b4..fd1d2b01 100644 --- a/mopidy/frontends/http/__init__.py +++ b/mopidy/frontends/http/__init__.py @@ -29,9 +29,9 @@ of Mopidy. Thus, you probably only want to make the web server available from your local network or place it behind a web proxy which takes care or user authentication. You have been warned. -This web server exposes a WebSocket at ``/ws``. The WebSocket gives you access -to Mopidy's full API and enables Mopidy to instantly push events to the client, -as they happen. +This web server exposes a WebSocket at ``/mopidy/ws/``. The WebSocket gives you +access to Mopidy's full API and enables Mopidy to instantly push events to the +client, as they happen. The web server can also host any static files, for example the HTML, CSS, JavaScript and images needed by a web based Mopidy client. To host static diff --git a/mopidy/frontends/http/actor.py b/mopidy/frontends/http/actor.py index ce48b8b3..3f7fa1aa 100644 --- a/mopidy/frontends/http/actor.py +++ b/mopidy/frontends/http/actor.py @@ -45,7 +45,8 @@ class HttpFrontend(pykka.ThreadingActor, CoreListener): def _create_app(self): root = RootResource() - root.ws = ws.WebSocketResource(self.core) + root.mopidy = MopidyResource() + root.mopidy.ws = ws.WebSocketResource(self.core) if settings.HTTP_SERVER_STATIC_DIR: static_dir = settings.HTTP_SERVER_STATIC_DIR @@ -59,7 +60,7 @@ class HttpFrontend(pykka.ThreadingActor, CoreListener): 'tools.staticdir.index': 'index.html', 'tools.staticdir.dir': static_dir, }, - b'/ws': { + b'/mopidy/ws': { 'tools.websocket.on': True, 'tools.websocket.handler_cls': ws.WebSocketHandler, }, @@ -128,3 +129,7 @@ class HttpFrontend(pykka.ThreadingActor, CoreListener): class RootResource(object): pass + + +class MopidyResource(object): + pass diff --git a/mopidy/frontends/http/data/index.html b/mopidy/frontends/http/data/index.html index 74d85dd6..f706a317 100644 --- a/mopidy/frontends/http/data/index.html +++ b/mopidy/frontends/http/data/index.html @@ -82,7 +82,7 @@

WebSocket endpoint

-

Mopidy has a WebSocket endpoint at /ws/. You can +

Mopidy has a WebSocket endpoint at /mopidy/ws/. You can use WebSockets to get notified about events happening in Mopidy. The alternative would be to regularly poll the conventional web service for updates.

@@ -90,7 +90,7 @@

To connect to the endpoint from a browser with WebSocket support, simply enter the following JavaScript code in the browser's console:

-
var ws = new WebSocket("ws://myhost:myport/ws/');
+      
var ws = new WebSocket("ws://myhost:myport/mopidy/ws/');
 ws.onmessage = function (event) {
   console.log("Incoming message: ", event.data);
 };
@@ -110,9 +110,10 @@ ws.send("Message to the server, ahoy!");