http: Move WebSocket to /mopidy/ws/
This commit is contained in:
parent
b1fe802473
commit
b4ad0b0830
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -82,7 +82,7 @@
|
||||
<div class="box">
|
||||
<h2>WebSocket endpoint</h2>
|
||||
|
||||
<p>Mopidy has a WebSocket endpoint at <a href="/ws/">/ws/</a>. You can
|
||||
<p>Mopidy has a WebSocket endpoint at <code>/mopidy/ws/</code>. 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.</p>
|
||||
@ -90,7 +90,7 @@
|
||||
<p>To connect to the endpoint from a browser with WebSocket support,
|
||||
simply enter the following JavaScript code in the browser's console:</p>
|
||||
|
||||
<pre>var ws = new WebSocket("ws://myhost:myport/ws/');
|
||||
<pre>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!");</pre>
|
||||
<script type="text/javascript" src="jquery-1.8.3.min.js"></script>
|
||||
<script type="text/javascript">
|
||||
$(function () {
|
||||
var ws = new WebSocket("ws://" + document.location.host + "/ws/");
|
||||
ws.onmessage = function (event) {
|
||||
$("#ws-console").prepend((new Date()).toLocaleTimeString() + ": " + event.data + "\n");
|
||||
var ws = new WebSocket("ws://" + document.location.host + "/mopidy/ws/");
|
||||
ws.onmessage = function (message) {
|
||||
$("#ws-console").prepend(
|
||||
(new Date()).toLocaleTimeString() + ": " + message.data + "\n");
|
||||
};
|
||||
});
|
||||
</script>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user