Current track images to use Mopidy-Spotify so no immediate dependency on Spotify HTTP API

This commit is contained in:
James Barnsley
2017-08-03 15:26:54 +12:00
parent 48c37b3ddf
commit 5184d06f55
11 changed files with 166 additions and 77 deletions

View File

@ -24,16 +24,6 @@ const CoreMiddleware = (function(){
next(action)
break
case 'MOPIDY_CONNECTED':
ReactGA.event({ category: 'Mopidy', action: 'Connected', label: window.location.hostname })
next(action)
break
case 'PUSHER_CONNECTED':
ReactGA.event({ category: 'Pusher', action: 'Connected', label: action.username })
next(action)
break
case 'ALBUM_LOADED':
if (action.data) ReactGA.event({ category: 'Album', action: 'Load', label: action.album.uri })
@ -75,11 +65,6 @@ const CoreMiddleware = (function(){
next(action)
break
case 'MOPIDY_DIRECTORY':
if (action.data) ReactGA.event({ category: 'Directory', action: 'Load', label: action.data.uri })
next(action)
break
case 'PLAY_PLAYLIST':
ReactGA.event({ category: 'Playlist', action: 'Play', label: action.uri })
next(action)

View File

@ -164,6 +164,14 @@ export function setTimePosition(time_position){
* Asset-oriented actions
**/
export function getImages( context, uris ){
return {
type: 'MOPIDY_GET_IMAGES',
context: context,
uris: uris
}
}
export function deletePlaylist( uri ){
return {
type: 'MOPIDY_DELETE_PLAYLIST',

View File

@ -1,4 +1,5 @@
import ReactGA from 'react-ga'
import Mopidy from 'mopidy'
import { hashHistory } from 'react-router'
import * as helpers from '../../helpers'
@ -192,6 +193,11 @@ const MopidyMiddleware = (function(){
socket.on( (type, data) => handleMessage( socket, store, type, data ) )
break
case 'MOPIDY_CONNECTED':
ReactGA.event({ category: 'Mopidy', action: 'Connected', label: window.location.hostname })
next(action)
break
case 'MOPIDY_DISCONNECT':
if(socket != null) socket.close()
socket = null
@ -238,7 +244,7 @@ const MopidyMiddleware = (function(){
type: 'browser_notification',
title: 'Track skipped',
body: store.getState().pusher.username +' skipped this track',
icon: (store.getState().core.current_track ? helpers.getTrackIcon(store.getState().core.current_track, store.getState().ui) : false)
icon: (store.getState().core.current_track ? helpers.getTrackIcon(store.getState().core.current_track, store.getState().core) : false)
}
store.dispatch( pusherActions.deliverBroadcast(data) )
break
@ -248,7 +254,7 @@ const MopidyMiddleware = (function(){
type: 'browser_notification',
title: 'Playback stopped',
body: store.getState().pusher.username +' stopped playback',
icon: (store.getState().core.current_track ? helpers.getTrackIcon(store.getState().core.current_track, store.getState().ui) : false)
icon: (store.getState().core.current_track ? helpers.getTrackIcon(store.getState().core.current_track, store.getState().core) : false)
}
store.dispatch( pusherActions.deliverBroadcast(data) )
break
@ -400,13 +406,6 @@ const MopidyMiddleware = (function(){
break
case 'CANCEL_PROCESS':
if (action.key == 'MOPIDY_ENQUEUE_URIS'){
store.dispatch(mopidyActions.enqueueURIsCancel())
}
next(action)
break
case 'MOPIDY_PLAY_URIS':
// Stop the radio
@ -1033,17 +1032,49 @@ const MopidyMiddleware = (function(){
// Fire off our universal track index loader
store.dispatch({ type: 'TRACK_LOADED', key: action.data.track.uri, track: action.data.track })
// When current track is Spotify track, go get the full object
// This is because Mopidy doesn't give us full artist/album objects, without artwork
if (action.data.track.uri.substring(0,14) == 'spotify:track:'){
store.dispatch( spotifyActions.getTrack( action.data.track.uri ) )
}
// Get me some images
store.dispatch(mopidyActions.getImages('tracks',[action.data.track.uri]))
}
next(action)
break
/**
* =============================================================== IMAGES ===============
* ======================================================================================
**/
case 'MOPIDY_GET_IMAGES':
instruct( socket, store, 'library.getImages', {uris: action.uris})
.then( response => {
let records = []
for (var uri in response){
if (response.hasOwnProperty(uri)){
let images = response[uri]
images = helpers.digestMopidyImages(store.getState().mopidy, images)
records.push({
uri: uri,
images: images
})
}
}
let action_data = {
type: (action.context+'_LOADED').toUpperCase()
}
action_data[action.context] = records
store.dispatch(action_data)
})
next(action)
break
/**
* =============================================================== LOCAL ================
* ======================================================================================
@ -1060,6 +1091,11 @@ const MopidyMiddleware = (function(){
})
break
case 'MOPIDY_DIRECTORY':
if (action.data) ReactGA.event({ category: 'Directory', action: 'Load', label: action.data.uri })
next(action)
break
// This action is irrelevant to us, pass it on to the next middleware
default:
return next(action)

View File

@ -98,6 +98,7 @@ const PusherMiddleware = (function(){
break;
case 'PUSHER_CONNECTED':
ReactGA.event({ category: 'Pusher', action: 'Connected', label: action.username })
request(store, 'get_config')
.then(
response => {

View File

@ -123,6 +123,13 @@ const UIMiddleware = (function(){
next(action)
break
case 'CANCEL_PROCESS':
if (action.key == 'MOPIDY_ENQUEUE_URIS'){
store.dispatch(mopidyActions.enqueueURIsCancel())
}
next(action)
break
// This action is irrelevant to us, pass it on to the next middleware
default:
return next(action)