diff --git a/mopidy/frontends/http/actor.py b/mopidy/frontends/http/actor.py index f6a9a441..181eb93c 100644 --- a/mopidy/frontends/http/actor.py +++ b/mopidy/frontends/http/actor.py @@ -45,7 +45,7 @@ class HttpFrontend(pykka.ThreadingActor, CoreListener): def _create_app(self): root = RootResource() root.api = api.ApiResource(self.core) - root.ws = ws.WebSocketResource() + root.ws = ws.WebSocketResource(self.core) if settings.HTTP_SERVER_STATIC_DIR: static_dir = settings.HTTP_SERVER_STATIC_DIR diff --git a/mopidy/frontends/http/ws.py b/mopidy/frontends/http/ws.py index 98fe8562..581eb849 100644 --- a/mopidy/frontends/http/ws.py +++ b/mopidy/frontends/http/ws.py @@ -15,9 +15,13 @@ logger = logging.getLogger('mopidy.frontends.http') class WebSocketResource(object): + def __init__(self, core): + self.core = core + @cherrypy.expose def index(self): logger.debug('WebSocket handler created') + cherrypy.request.ws_handler.core = self.core class WebSocketHandler(WebSocket): @@ -40,3 +44,6 @@ class WebSocketHandler(WebSocket): 'Received WebSocket message from %s:%d: %s', remote.ip, remote.port, message) # This is where we would handle incoming messages from the clients + + # This is just for demonstration purposes + self.send('Playback state: %s' % self.core.playback.state.get())