http: Pass core to WebSocket handler

This commit is contained in:
Stein Magnus Jodal 2012-11-16 22:35:00 +01:00
parent df4d7cd4c9
commit 97ca863c5d
2 changed files with 8 additions and 1 deletions

View File

@ -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

View File

@ -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())