Polishing spotify actions, removing middleware; Mopidy current track selection

This commit is contained in:
James Barnsley
2016-10-21 09:56:07 +13:00
parent daab2133df
commit afb6bb7a0d
19 changed files with 444 additions and 102 deletions

View File

@ -24,7 +24,7 @@ export function disconnect(){
export function changeTrack( tlid ){
return {
type: 'MOPIDY_CHANGE_TRACK',
type: 'MOPIDY_INSTRUCT',
call: 'playback.play',
value: { tlid: tlid }
}
@ -38,11 +38,11 @@ export function playTracks( uris ){
}
export function enqueueTracks( uris, at_position = false ){
if( typeof(uris) !== 'array' ) uris = [uris];
if( typeof(uris) !== 'object' ) uris = [uris];
var value = { uris: uris };
if( at_position ) value.at_position = at_position;
return {
type: 'MOPIDY_ENQUEUE_TRACKS',
type: 'MOPIDY_INSTRUCT',
call: 'tracklist.add',
value: value
}
@ -50,7 +50,7 @@ export function enqueueTracks( uris, at_position = false ){
export function removeTracks( tlids ){
return {
type: 'MOPIDY_REMOVE_TRACKS',
type: 'MOPIDY_INSTRUCT',
call: 'tracklist.remove',
value: { tlid: tlids }
}

View File

@ -19,7 +19,10 @@ const MopidyMiddleware = (function(){
instruct( ws, store, 'tracklist.getRandom' );
instruct( ws, store, 'tracklist.getRepeat' );
instruct( ws, store, 'tracklist.getTlTracks' );
instruct( ws, store, 'playback.getCurrentTlTrack' );
instruct( ws, store, 'playback.getCurrentTlTrack' )
.then( currentTlTrack => {
store.dispatch({ type: 'MOPIDY_HIGHLIGHT_CURRENT_TLTRACK', data: currentTlTrack })
});
break;
case 'state:offline':
@ -27,14 +30,20 @@ const MopidyMiddleware = (function(){
break;
case 'event:tracklistChanged':
instruct( ws, store, 'tracklist.getTlTracks' );
instruct( ws, store, 'tracklist.getTlTracks' )
.then( currentTlTrack => {
store.dispatch({ type: 'MOPIDY_HIGHLIGHT_CURRENT_TLTRACK', data: currentTlTrack })
});
break;
//case 'event:trackPlaybackEnded':
case 'event:playbackStateChanged':
case 'event:trackPlaybackStarted':
instruct( ws, store, 'playback.getState' );
instruct( ws, store, 'playback.getCurrentTlTrack' );
instruct( ws, store, 'playback.getCurrentTlTrack' )
.then( currentTlTrack => {
store.dispatch({ type: 'MOPIDY_HIGHLIGHT_CURRENT_TLTRACK', data: currentTlTrack })
});
break;
case 'event:volumeChanged':
@ -122,8 +131,6 @@ const MopidyMiddleware = (function(){
// send an instruction to the websocket
case 'MOPIDY_INSTRUCT':
case 'MOPIDY_CHANGE_TRACK':
case 'MOPIDY_REMOVE_TRACKS':
instruct( socket, store, action.call, action.value )
break;

View File

@ -16,9 +16,20 @@ export default function reducer(mopidy = {}, action){
case 'MOPIDY_CHANGE_TRACK':
return Object.assign({}, mopidy, {
tlid: action.tlid
tlid: action.tlid
});
case 'MOPIDY_HIGHLIGHT_CURRENT_TLTRACK':
for( var i = 0; i < mopidy.tracks.length; i++ ){
if( mopidy.tracks[i].tlid == action.data.tlid ){
action.data.track.playing = true;
Object.assign(mopidy.tracks[i], action.data);
}else{
mopidy.tracks[i].track.playing = false;
}
}
return Object.assign({}, mopidy, { tracks: mopidy.tracks });
/**
* Websocket-initiated actions
**/