Few more fixes on mopidy backend
This commit is contained in:
parent
9a4963a48a
commit
c18515bd3c
1 changed files with 5 additions and 16 deletions
|
@ -87,7 +87,9 @@ class MusicMopidyBackend(Backend):
|
|||
|
||||
ws = websocket.create_connection(self.url)
|
||||
ws.send(msg)
|
||||
return json.loads(ws.recv()).get('result')
|
||||
response = json.loads(ws.recv()).get('result')
|
||||
ws.close()
|
||||
return response
|
||||
|
||||
|
||||
def _get_tracklist_status(self):
|
||||
|
@ -102,21 +104,6 @@ class MusicMopidyBackend(Backend):
|
|||
'method': 'core.tracklist.get_consume'}),
|
||||
}
|
||||
|
||||
async def _poll_events(self):
|
||||
import websocket
|
||||
|
||||
try:
|
||||
while not self.should_stop():
|
||||
async with websockets.connect(self.url) as ws:
|
||||
msg = await ws.recv()
|
||||
if isinstance(msg, bytes):
|
||||
msg = msg.decode()
|
||||
self._handle_msg(msg)
|
||||
except Exception as e:
|
||||
self.logger.warning('The Mopidy backend raised an exception')
|
||||
self.logger.exception(e)
|
||||
time.sleep(2) # Wait a bit before retrying
|
||||
|
||||
def _on_msg(self):
|
||||
def hndl(msg):
|
||||
msg = json.loads(msg)
|
||||
|
@ -210,6 +197,8 @@ class MusicMopidyBackend(Backend):
|
|||
return hndl
|
||||
|
||||
def _connect(self):
|
||||
import websocket
|
||||
|
||||
if not self._ws:
|
||||
self._ws = websocket.WebSocketApp(self.url,
|
||||
on_message=self._on_msg(),
|
||||
|
|
Loading…
Reference in a new issue