From a349b45ba49347ed2acf1ddf940f67737fbec9f3 Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Thu, 10 Jan 2019 11:52:39 +0100 Subject: [PATCH] Removed get_plugin utils method from web server, it messes up with also with the reentrant locks as it runs in another process. Refactored Snapcast frontend to get the backend hosts asynchronously through a plugin method --- platypush/backend/http/__init__.py | 7 +-- .../backend/http/static/js/music.snapcast.js | 55 +++++++++++-------- .../templates/plugins/music.snapcast.html | 5 -- platypush/plugins/music/snapcast.py | 16 ++++-- 4 files changed, 46 insertions(+), 37 deletions(-) diff --git a/platypush/backend/http/__init__.py b/platypush/backend/http/__init__.py index c463b2944..7ac371d68 100644 --- a/platypush/backend/http/__init__.py +++ b/platypush/backend/http/__init__.py @@ -15,7 +15,7 @@ from flask import Flask, Response, abort, jsonify, request as http_request, \ from redis import Redis from platypush.config import Config -from platypush.context import get_backend, get_plugin, get_or_create_event_loop +from platypush.context import get_backend, get_or_create_event_loop from platypush.message import Message from platypush.message.event import Event, StopEvent from platypush.message.event.web.widget import WidgetUpdateEvent @@ -550,9 +550,4 @@ class HttpUtils(object): return json.loads(data) - @classmethod - def get_plugin(cls, plugin): - return get_plugin(plugin) - - # vim:sw=4:ts=4:et: diff --git a/platypush/backend/http/static/js/music.snapcast.js b/platypush/backend/http/static/js/music.snapcast.js index 5c57ec72b..d22e93ce3 100644 --- a/platypush/backend/http/static/js/music.snapcast.js +++ b/platypush/backend/http/static/js/music.snapcast.js @@ -225,32 +225,43 @@ $(document).ready(function() { }; var redraw = function() { - var promises = []; + execute( + { + type: 'request', + action: 'music.snapcast.get_backend_hosts', + }, - for (var host of Object.keys(window.config.snapcast_hosts)) { - promises.push( - execute({ - type: 'request', - action: 'music.snapcast.status', - args: { - host: host, - port: window.config.snapcast_hosts[host], + (response) => { + window.config = window.config || {}; + window.config.snapcast_hosts = response.response.output; + var promises = []; + + for (var host of Object.keys(window.config.snapcast_hosts)) { + promises.push( + execute({ + type: 'request', + action: 'music.snapcast.status', + args: { + host: host, + port: window.config.snapcast_hosts[host], + } + }) + ); + } + + $.when.apply($, promises) + .done(function() { + var statuses = []; + for (var status of arguments) { + statuses.push(status[0].response.output); } - }) - ); - } - $.when.apply($, promises) - .done(function() { - var statuses = []; - for (var status of arguments) { - statuses.push(status[0].response.output); + update(statuses); + }).then(function() { + initBindings(); + }); } - - update(statuses); - }).then(function() { - initBindings(); - }); + ); }; var initBindings = function() { diff --git a/platypush/backend/http/templates/plugins/music.snapcast.html b/platypush/backend/http/templates/plugins/music.snapcast.html index 16b48cbb0..2aedf3520 100644 --- a/platypush/backend/http/templates/plugins/music.snapcast.html +++ b/platypush/backend/http/templates/plugins/music.snapcast.html @@ -1,11 +1,6 @@ - -