Google as new provider (using Mopidy core), starting #266
This commit is contained in:
13
src/js/services/google/actions.js
Executable file
13
src/js/services/google/actions.js
Executable file
@ -0,0 +1,13 @@
|
||||
|
||||
export function set(data){
|
||||
return {
|
||||
type: 'GOOGLE_SET',
|
||||
data: data
|
||||
}
|
||||
}
|
||||
|
||||
export function getLibraryArtists(){
|
||||
return {
|
||||
'type': 'GOOGLE_GET_LIBRARY_ARTISTS'
|
||||
}
|
||||
}
|
||||
38
src/js/services/google/middleware.js
Executable file
38
src/js/services/google/middleware.js
Executable file
@ -0,0 +1,38 @@
|
||||
|
||||
import ReactGA from 'react-ga'
|
||||
|
||||
var helpers = require('../../helpers');
|
||||
var coreActions = require('../core/actions');
|
||||
var mopidyActions = require('../mopidy/actions');
|
||||
var uiActions = require('../ui/actions');
|
||||
|
||||
const GoogleMiddleware = (function(){
|
||||
|
||||
// A snapcast request is an alias of the Pusher request
|
||||
const request = (store, params = null, response_callback = null, error_callback = null) => {
|
||||
store.dispatch(
|
||||
pusherActions.request(
|
||||
'snapcast_instruct',
|
||||
params,
|
||||
response_callback,
|
||||
error_callback
|
||||
)
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
return store => next => action => {
|
||||
var google = store.getState().google;
|
||||
|
||||
switch(action.type){
|
||||
|
||||
|
||||
// This action is irrelevant to us, pass it on to the next middleware
|
||||
default:
|
||||
return next(action);
|
||||
}
|
||||
}
|
||||
|
||||
})();
|
||||
|
||||
export default GoogleMiddleware
|
||||
14
src/js/services/google/reducer.js
Executable file
14
src/js/services/google/reducer.js
Executable file
@ -0,0 +1,14 @@
|
||||
|
||||
export default function reducer(google = {}, action){
|
||||
switch (action.type){
|
||||
|
||||
case 'GOOGLE_SET':
|
||||
return Object.assign({}, google, action.data);
|
||||
|
||||
default:
|
||||
return google
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -357,9 +357,10 @@ export function getTrack(uri){
|
||||
}
|
||||
}
|
||||
|
||||
export function getLibraryArtists(){
|
||||
export function getLibraryArtists(uri = null){
|
||||
return {
|
||||
type: 'MOPIDY_GET_LIBRARY_ARTISTS'
|
||||
type: 'MOPIDY_GET_LIBRARY_ARTISTS',
|
||||
uri: uri
|
||||
}
|
||||
}
|
||||
|
||||
@ -399,9 +400,10 @@ export function getAlbums(uris, processor = null){
|
||||
}
|
||||
}
|
||||
|
||||
export function getLibraryAlbums(){
|
||||
export function getLibraryAlbums(uri = null){
|
||||
return {
|
||||
type: 'MOPIDY_GET_LIBRARY_ALBUMS'
|
||||
type: 'MOPIDY_GET_LIBRARY_ALBUMS',
|
||||
uri: uri
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1,16 +1,17 @@
|
||||
|
||||
import ReactGA from 'react-ga'
|
||||
import Mopidy from 'mopidy'
|
||||
import ReactGA from 'react-ga';
|
||||
import Mopidy from 'mopidy';
|
||||
import md5 from 'md5';
|
||||
import { hashHistory } from 'react-router'
|
||||
import * as helpers from '../../helpers'
|
||||
import { hashHistory } from 'react-router';
|
||||
import * as helpers from '../../helpers';
|
||||
|
||||
var mopidyActions = require('./actions.js')
|
||||
var coreActions = require('../core/actions.js')
|
||||
var uiActions = require('../ui/actions.js')
|
||||
var spotifyActions = require('../spotify/actions.js')
|
||||
var pusherActions = require('../pusher/actions.js')
|
||||
var lastfmActions = require('../lastfm/actions.js')
|
||||
var mopidyActions = require('./actions.js');
|
||||
var coreActions = require('../core/actions.js');
|
||||
var uiActions = require('../ui/actions.js');
|
||||
var spotifyActions = require('../spotify/actions.js');
|
||||
var pusherActions = require('../pusher/actions.js');
|
||||
var googleActions = require('../google/actions.js');
|
||||
var lastfmActions = require('../lastfm/actions.js');
|
||||
|
||||
const MopidyMiddleware = (function(){
|
||||
|
||||
@ -530,21 +531,8 @@ const MopidyMiddleware = (function(){
|
||||
}
|
||||
|
||||
// Enable Iris providers when the backend is available
|
||||
if (uri_schemes.includes('spotify:')){
|
||||
store.dispatch({
|
||||
type: 'SPOTIFY_SET',
|
||||
data: {
|
||||
enabled: true
|
||||
}
|
||||
});
|
||||
} else {
|
||||
store.dispatch({
|
||||
type: 'SPOTIFY_SET',
|
||||
data: {
|
||||
enabled: false
|
||||
}
|
||||
});
|
||||
}
|
||||
store.dispatch(spotifyActions.set({enabled: uri_schemes.includes('spotify:')}));
|
||||
store.dispatch(googleActions.set({enabled: uri_schemes.includes('gmusic:')}));
|
||||
|
||||
// If we haven't customised our search schemes, add all to search
|
||||
if (store.getState().ui.uri_schemes_search_enabled === undefined){
|
||||
@ -1715,22 +1703,7 @@ const MopidyMiddleware = (function(){
|
||||
var last_run = store.getState().ui.processes.MOPIDY_LIBRARY_ALBUMS_PROCESSOR
|
||||
|
||||
if (!last_run){
|
||||
var uris = store.getState().mopidy.library_albums_uris.split(',');
|
||||
var promises = [];
|
||||
|
||||
// Construct an array of promises
|
||||
for (var uri of uris){
|
||||
promises.push(
|
||||
request(socket, store, 'library.browse', { uri: uri })
|
||||
);
|
||||
}
|
||||
|
||||
// Now run the requests
|
||||
Promise.all(promises).then(responses => {
|
||||
console.log(responses);
|
||||
});
|
||||
|
||||
request(socket, store, 'library.browse', { uri: store.getState().mopidy.library_albums_uris })
|
||||
request(socket, store, 'library.browse', { uri: store.getState().mopidy.library_albums_uri })
|
||||
.then(response => {
|
||||
if (response.length <= 0) return
|
||||
|
||||
|
||||
Reference in New Issue
Block a user