All files / src/js/store index.js

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165                                                          1x                                                                                                                                                                                         1x 1x 1x 1x 1x 1x 1x 1x 1x     1x   1x                                                          
 
import { createStore, applyMiddleware, combineReducers } from 'redux';
import thunk from 'redux-thunk';
 
import { generateGuid } from '../util/helpers';
import storage from '../util/storage';
import core from '../services/core/reducer';
import ui from '../services/ui/reducer';
import pusher from '../services/pusher/reducer';
import mopidy from '../services/mopidy/reducer';
import lastfm from '../services/lastfm/reducer';
import spotify from '../services/spotify/reducer';
import snapcast from '../services/snapcast/reducer';
import google from '../services/google/reducer';
import genius from '../services/genius/reducer';
 
import migration from './migration';
 
import coreMiddleware from '../services/core/middleware';
import uiMiddleware from '../services/ui/middleware';
import pusherMiddleware from '../services/pusher/middleware';
import mopidyMiddleware from '../services/mopidy/middleware';
import lastfmMiddleware from '../services/lastfm/middleware';
import geniusMiddleware from '../services/genius/middleware';
import spotifyMiddleware from '../services/spotify/middleware';
import googleMiddleware from '../services/google/middleware';
import snapcastMiddleware from '../services/snapcast/middleware';
import localstorageMiddleware from '../services/localstorage/middleware';
 
let state = {
  core: {
    outputs: [],
    queue: [],
    queue_metadata: {},
    current_track: null,
    albums: {},
    artists: {},
    playlists: {},
    users: {},
    tracks: {},
    http_streaming_enabled: false,
    http_streaming_cachebuster: null,
    http_streaming_url: `http://${window.location.hostname}:8000/mopidy`,
  },
  ui: {
    language: 'en',
    theme: 'auto',
    smooth_scrolling_enabled: true,
    hotkeys_enabled: true,
    playback_controls_touch_enabled: true,
    allow_reporting: true,
    wide_scrollbar_enabled: false,
    window_focus: true,
    slim_mode: false,
    selected_tracks: [],
    notifications: {},
    processes: {},
  },
  mopidy: {
    connected: false,
    host: window.location.hostname,
    port: (window.location.port ? window.location.port : (window.location.protocol === 'https:' ? '443' : '80')),
    ssl: window.location.protocol === 'https:',
    current_server: 'default',
    servers: {
      default: {
        id: 'default',
        name: 'Default',
        host: window.location.hostname,
        port: (window.location.port ? window.location.port : (window.location.protocol === 'https:' ? '443' : '80')),
        ssl: window.location.protocol === 'https:',
      },
    },
    mute: false,
    volume: 0,
    progress: 0,
    play_state: null,
    uri_schemes: [],
    library_albums_uri: 'local:directory?type=album',
    library_artists_uri: 'local:directory?type=artist&role=albumartist',
  },
  pusher: {
    connected: false,
    username: generateGuid(),
    client_id: generateGuid(),
    connections: {},
    version: {
      current: null,
    },
    config: {},
  },
  lastfm: {
    me: null,
    authorization_url: 'https://jamesbarnsley.co.nz/iris/auth_lastfm.php',
  },
  genius: {
    me: null,
    authorization_url: 'https://jamesbarnsley.co.nz/iris/auth_genius.php',
  },
  spotify: {
    me: null,
    autocomplete_results: {},
    authorization_url: 'https://jamesbarnsley.co.nz/iris/auth_spotify.php',
  },
  google: {
    enabled: false,
  },
  snapcast: {
    enabled: false,
    connected: false,
    host: window.location.hostname,
    port: '1780',
    ssl: (window.location.protocol === 'https:'),
    streams: {},
    groups: {},
    clients: {},
    server: null,
    commands: {},
  },
};
 
// load all our stored values from LocalStorage
state.core = { ...state.core, ...storage.get('core') };
state.ui = { ...state.ui, ...storage.get('ui') };
state.mopidy = { ...state.mopidy, ...storage.get('mopidy') };
state.pusher = { ...state.pusher, ...storage.get('pusher') };
state.spotify = { ...state.spotify, ...storage.get('spotify') };
state.lastfm = { ...state.lastfm, ...storage.get('lastfm') };
state.genius = { ...state.genius, ...storage.get('genius') };
state.google = { ...state.google, ...storage.get('google') };
state.snapcast = { ...state.snapcast, ...storage.get('snapcast') };
 
// Run any migrations
state = migration(state);
 
const reducers = combineReducers({
  core,
  ui,
  pusher,
  mopidy,
  lastfm,
  genius,
  spotify,
  google,
  snapcast,
});
 
export default createStore(
  reducers,
  state,
  applyMiddleware(
    thunk,
    localstorageMiddleware,
    coreMiddleware,
    uiMiddleware,
    mopidyMiddleware,
    pusherMiddleware,
    spotifyMiddleware,
    lastfmMiddleware,
    geniusMiddleware,
    googleMiddleware,
    snapcastMiddleware,
  ),
);