Adding multi-server support

This commit is contained in:
James Barnsley
2020-04-30 15:45:55 +12:00
parent 31652b09f6
commit 5388f6a59e
16 changed files with 146 additions and 53 deletions

View File

@ -264,8 +264,7 @@ export function getAlbum(uri, artist, album, mbid = false) {
(response) => {
if (response.album) {
const existing_album = getState().core.albums[uri];
const album = {
const album = {
uri,
images: response.album.image,
listeners: parseInt(response.album.listeners),
@ -342,8 +341,7 @@ export function getImages(context, uri) {
.then(
(response) => {
if (response.album) {
record = { ...record, images: response.album.image };
dispatch(coreActions.albumLoaded(record));
dispatch(coreActions.albumLoaded({ uri, images: response.album.image }));
}
},
);

View File

@ -31,7 +31,8 @@ export function addServer() {
name: 'New server',
host: window.location.hostname,
port: (window.location.port ? window.location.port : (window.location.protocol === 'https:' ? '443' : '80')),
}
ssl: window.location.protocol === 'https:',
},
};
}

View File

@ -249,7 +249,7 @@ const MopidyMiddleware = (function () {
var state = store.getState();
socket = new Mopidy({
webSocketUrl: `ws${window.location.protocol === 'https:' ? 's' : ''}://${state.mopidy.host}:${state.mopidy.port}/mopidy/ws/`,
webSocketUrl: `ws${state.mopidy.ssl ? 's' : ''}://${state.mopidy.host}:${state.mopidy.port}/mopidy/ws/`,
callingConvention: 'by-position-or-by-name',
});
@ -294,7 +294,10 @@ const MopidyMiddleware = (function () {
store.dispatch(mopidyActions.set({
current_server: action.server.id,
host: action.server.host,
port: action.server.port
port: action.server.port,
ssl: action.server.ssl,
connected: false,
connecting: false,
}));
// Wait a moment for store to update, then attempt connection
@ -2371,11 +2374,13 @@ const MopidyMiddleware = (function () {
}
}
const action_data = {
type: (`${action.context}_LOADED`).toUpperCase(),
};
action_data[action.context] = records;
store.dispatch(action_data);
if (records.length) {
const action_data = {
type: (`${action.context}_LOADED`).toUpperCase(),
};
action_data[action.context] = records;
store.dispatch(action_data);
}
});
}