Country/Locale now settable via config (fixes #19); New get_config endpoint for Pusher
This commit is contained in:
@ -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):
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
[iris]
|
||||
enabled = true
|
||||
debug = false
|
||||
pusherport = 6681
|
||||
country = NZ
|
||||
locale = en_NZ
|
||||
@ -190,6 +190,16 @@ class IrisFrontend(pykka.ThreadingActor, CoreListener):
|
||||
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
|
||||
#
|
||||
|
||||
@ -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):
|
||||
|
||||
2
setup.py
2
setup.py
@ -37,7 +37,7 @@ setup(
|
||||
],
|
||||
entry_points={
|
||||
'mopidy.ext': [
|
||||
'iris = mopidy_iris:IrisExtension',
|
||||
'iris = mopidy_iris:Extension',
|
||||
],
|
||||
},
|
||||
)
|
||||
|
||||
2
src/js/bootstrap.js
vendored
2
src/js/bootstrap.js
vendored
@ -49,8 +49,6 @@ var initialState = {
|
||||
},
|
||||
spotify: {
|
||||
connected: false,
|
||||
country: 'NZ',
|
||||
locale: 'en_NZ',
|
||||
me: false
|
||||
},
|
||||
ui: {
|
||||
|
||||
@ -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;
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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, {
|
||||
|
||||
@ -34,7 +34,8 @@ class Settings extends React.Component{
|
||||
|
||||
resetAllSettings(){
|
||||
localStorage.clear();
|
||||
window.location.reload(true);
|
||||
window.location = '#'
|
||||
window.location.reload(true)
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user