2016-10-16 12:37:37 +13:00
|
|
|
|
2016-10-24 21:26:01 +13:00
|
|
|
var actions = require('./actions.js')
|
2016-10-16 12:37:37 +13:00
|
|
|
|
|
|
|
|
const SpotifyMiddleware = (function(){
|
|
|
|
|
|
2016-10-17 10:39:11 +13:00
|
|
|
/**
|
|
|
|
|
* The actual middleware inteceptor
|
|
|
|
|
**/
|
|
|
|
|
return store => next => action => {
|
2016-10-18 21:57:29 +13:00
|
|
|
var state = store.getState();
|
|
|
|
|
|
|
|
|
|
switch(action.type){
|
2016-10-17 10:39:11 +13:00
|
|
|
|
2016-10-24 21:26:01 +13:00
|
|
|
// when our mopidy server current track changes
|
2016-10-28 09:14:29 +13:00
|
|
|
case 'MOPIDY_CURRENTTLTRACK_XX':
|
|
|
|
|
// DISABLED AS IT CAUSES ISSUE
|
2016-10-21 09:56:07 +13:00
|
|
|
|
2016-10-24 21:26:01 +13:00
|
|
|
// proceed as usual so we don't inhibit default functionality
|
2016-10-21 09:56:07 +13:00
|
|
|
next(action)
|
|
|
|
|
|
2016-10-24 21:26:01 +13:00
|
|
|
// if the current track is a spotify track
|
|
|
|
|
if( action.data.track.uri.substring(0,14) == 'spotify:track:' ){
|
|
|
|
|
store.dispatch( actions.getTrack( action.data.track.uri ) )
|
|
|
|
|
}
|
2016-10-19 14:09:34 +13:00
|
|
|
|
2016-10-16 12:37:37 +13:00
|
|
|
// This action is irrelevant to us, pass it on to the next middleware
|
|
|
|
|
default:
|
|
|
|
|
return next(action);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
})();
|
|
|
|
|
|
|
|
|
|
export default SpotifyMiddleware
|