Files
Iris/src/js/services/spotify/middleware.js

37 lines
1.0 KiB
JavaScript
Raw Normal View History

2016-10-24 21:26:01 +13:00
var actions = require('./actions.js')
const SpotifyMiddleware = (function(){
/**
* The actual middleware inteceptor
**/
return store => next => action => {
var state = store.getState();
switch(action.type){
2016-11-06 15:47:37 +13:00
case 'SPOTIFY_CONNECT':
store.dispatch( actions.getMe() )
2016-10-24 21:26:01 +13:00
// when our mopidy server current track changes
2016-11-03 18:22:26 +13:00
case 'MOPIDY_CURRENTTLTRACK':
2016-10-24 21:26:01 +13:00
// proceed as usual so we don't inhibit default functionality
next(action)
2016-10-24 21:26:01 +13:00
// if the current track is a spotify track
2016-11-03 18:22:26 +13:00
if( action.data && action.data.track.uri.substring(0,14) == 'spotify:track:' ){
2016-10-24 21:26:01 +13:00
store.dispatch( actions.getTrack( action.data.track.uri ) )
}
2016-10-19 14:09:34 +13:00
// This action is irrelevant to us, pass it on to the next middleware
default:
return next(action);
}
}
})();
export default SpotifyMiddleware