From 94c947e90ecb212d84663b1f6495f2547c49833d Mon Sep 17 00:00:00 2001 From: James Barnsley Date: Mon, 6 Feb 2017 10:07:32 +1300 Subject: [PATCH] Country/Locale now settable via config (fixes #19); New get_config endpoint for Pusher --- mopidy_iris/__init__.py | 8 +++++--- mopidy_iris/ext.conf | 5 +++-- mopidy_iris/frontend.py | 10 ++++++++++ mopidy_iris/pusher.py | 13 +++++++++++-- setup.py | 2 +- src/js/bootstrap.js | 2 -- src/js/services/pusher/middleware.js | 18 ++++++++++++------ src/js/services/spotify/middleware.js | 6 ++++++ src/js/services/spotify/reducer.js | 3 +++ src/js/views/Settings.js | 3 ++- 10 files changed, 53 insertions(+), 17 deletions(-) diff --git a/mopidy_iris/__init__.py b/mopidy_iris/__init__.py index 26b280aa..e54741b9 100755 --- a/mopidy_iris/__init__.py +++ b/mopidy_iris/__init__.py @@ -15,7 +15,7 @@ __version__ = '2.11.3' # # Loads config and gets the party started. Initiates any additional frontends, etc. ## -class IrisExtension( ext.Extension ): +class Extension( ext.Extension ): dist_name = 'Mopidy-Iris' ext_name = 'iris' @@ -26,9 +26,11 @@ class IrisExtension( ext.Extension ): return config.read(conf_file) def get_config_schema(self): - schema = super(IrisExtension, self).get_config_schema() - schema['debug'] = config.Boolean() + schema = config.ConfigSchema(self.ext_name) + schema['enabled'] = config.Boolean() schema['pusherport'] = config.String() + schema['country'] = config.String() + schema['locale'] = config.String() return schema def setup(self, registry): diff --git a/mopidy_iris/ext.conf b/mopidy_iris/ext.conf index 71f06613..8cd62fcf 100755 --- a/mopidy_iris/ext.conf +++ b/mopidy_iris/ext.conf @@ -1,4 +1,5 @@ [iris] enabled = true -debug = false -pusherport = 6681 \ No newline at end of file +pusherport = 6681 +country = NZ +locale = en_NZ \ No newline at end of file diff --git a/mopidy_iris/frontend.py b/mopidy_iris/frontend.py index da07748b..cc10c3a4 100755 --- a/mopidy_iris/frontend.py +++ b/mopidy_iris/frontend.py @@ -189,6 +189,16 @@ class IrisFrontend(pykka.ThreadingActor, CoreListener): def get_spotify_token( self ): return self.spotify_token + + # get our config values + def get_config( self ): + iris = self.config['iris'] + config = { + "country": iris['country'], + "locale": iris['locale'] + } + return config + ## # Get Spotmop version, and check for updates diff --git a/mopidy_iris/pusher.py b/mopidy_iris/pusher.py index 8adb767f..13047a14 100755 --- a/mopidy_iris/pusher.py +++ b/mopidy_iris/pusher.py @@ -188,6 +188,15 @@ class PusherWebsocketHandler(tornado.websocket.WebSocketHandler): { 'error': 'Could not send to that connection, does not exist' } ) + # fetch our pusher connections + elif messageJson['action'] == 'get_config': + send_message( + self.connectionid, + 'response', + messageJson['request_id'], + { 'config': self.frontend.get_config() } + ) + # fetch our pusher connections elif messageJson['action'] == 'get_connections': @@ -266,7 +275,7 @@ class PusherWebsocketHandler(tornado.websocket.WebSocketHandler): { 'version': version } ) - # get system version and check for upgrade + # perform upgrade elif messageJson['action'] == 'upgrade': version = self.frontend.get_version() upgrade_successful = self.frontend.perform_upgrade() @@ -290,7 +299,7 @@ class PusherWebsocketHandler(tornado.websocket.WebSocketHandler): { 'error': 'Unhandled action' } ) - logger.debug( 'Pusher: Message received from '+ self.connectionid ) + logger.debug( 'Pusher: Unhandled message received from '+ self.connectionid ) # connection closed def on_close(self): diff --git a/setup.py b/setup.py index 446656a7..3df0588c 100755 --- a/setup.py +++ b/setup.py @@ -37,7 +37,7 @@ setup( ], entry_points={ 'mopidy.ext': [ - 'iris = mopidy_iris:IrisExtension', + 'iris = mopidy_iris:Extension', ], }, ) diff --git a/src/js/bootstrap.js b/src/js/bootstrap.js index 477c24f1..b174b7df 100755 --- a/src/js/bootstrap.js +++ b/src/js/bootstrap.js @@ -49,8 +49,6 @@ var initialState = { }, spotify: { connected: false, - country: 'NZ', - locale: 'en_NZ', me: false }, ui: { diff --git a/src/js/services/pusher/middleware.js b/src/js/services/pusher/middleware.js index 00fb9715..0e4e9936 100755 --- a/src/js/services/pusher/middleware.js +++ b/src/js/services/pusher/middleware.js @@ -103,12 +103,6 @@ const PusherMiddleware = (function(){ socket.onopen = () => { store.dispatch({ type: 'PUSHER_CONNECTED', connection: connection }); store.dispatch({ type: 'PUSHER_SET_USERNAME', username: connection.username }); - request({ action: 'get_radio' }) - .then( - response => { - store.dispatch({ type: 'RADIO', data: response.data }) - } - ) }; socket.onmessage = (message) => { @@ -119,12 +113,24 @@ const PusherMiddleware = (function(){ break; case 'PUSHER_CONNECTED': + request({ action: 'get_config' }) + .then( + response => { + store.dispatch({ type: 'CONFIG', data: response.data }) + } + ) request({ action: 'get_version' }) .then( response => { store.dispatch({ type: 'VERSION', data: response.data }) } ) + request({ action: 'get_radio' }) + .then( + response => { + store.dispatch({ type: 'RADIO', data: response.data }) + } + ) return next(action); break; diff --git a/src/js/services/spotify/middleware.js b/src/js/services/spotify/middleware.js index d9a88b1a..a11ebbdf 100755 --- a/src/js/services/spotify/middleware.js +++ b/src/js/services/spotify/middleware.js @@ -13,6 +13,12 @@ const SpotifyMiddleware = (function(){ switch(action.type){ + case 'CONFIG': + if (!state.spotify.country || !state.spotify.locale){ + store.dispatch( spotifyActions.setConfig(action.data.config) ) + } + break + case 'SPOTIFY_CONNECT': store.dispatch( spotifyActions.getMe() ) break diff --git a/src/js/services/spotify/reducer.js b/src/js/services/spotify/reducer.js index 914f242b..33e3e84a 100755 --- a/src/js/services/spotify/reducer.js +++ b/src/js/services/spotify/reducer.js @@ -12,6 +12,9 @@ export default function reducer(spotify = {}, action){ case 'SPOTIFY_DISCONNECTED': return Object.assign({}, spotify, { connected: false, connecting: false }) + case 'SPOTIFY_SET_CONFIG': + return Object.assign({}, spotify, action.config) + case 'PUSHER_SPOTIFY_TOKEN': if( spotify.authorized ) return spotify; return Object.assign({}, spotify, { diff --git a/src/js/views/Settings.js b/src/js/views/Settings.js index 47ee71c8..b2d60c12 100755 --- a/src/js/views/Settings.js +++ b/src/js/views/Settings.js @@ -34,7 +34,8 @@ class Settings extends React.Component{ resetAllSettings(){ localStorage.clear(); - window.location.reload(true); + window.location = '#' + window.location.reload(true) return false; }