Averaging group volume for state

This commit is contained in:
James Barnsley
2019-11-08 16:39:25 +13:00
parent 0efa8a2277
commit 6cbb8823e5
11 changed files with 10063 additions and 5476 deletions

View File

@ -297,6 +297,7 @@ const SnapcastMiddleware = (function () {
if (raw_group.clients) {
group.clients_ids = helpers.arrayOf('id', raw_group.clients);
clients_loaded = [...clients_loaded, ...raw_group.clients];
store.dispatch(snapcastActions.calculateGroupVolume(group.id, raw_group.clients));
}
// Create a name (display only) based on it's ID
@ -316,6 +317,17 @@ const SnapcastMiddleware = (function () {
next(action);
break;
case 'SNAPCAST_CALCULATE_GROUP_VOLUME':
const totalVolume = action.clients.reduce((accumulator, client) => {
return accumulator += helpers.formatClient(client).volume;
}, 0);
store.dispatch(snapcastActions.groupLoaded({
id: action.id,
volume: totalVolume / action.clients.length,
}));
break;
case 'SNAPCAST_CLIENTS_LOADED':
var clients_index = { ...snapcast.clients };
var clients_loaded = [];
@ -405,6 +417,15 @@ const SnapcastMiddleware = (function () {
volume: response.volume.percent,
},
));
/*
// A group was referenced, so we should update the group's averaged volume
if (action.group_id) {
const group = snapcast.groups[action.group_id];
const clients = [];
snapcast.groups.filter
store.dispatch(snapcastActions.calculateGroupVolume(group.id, clients));
}
*/
},
(error) => {
store.dispatch(coreActions.handleException(