Digesting snapcast structure into iris-friendly structure
This commit is contained in:
@ -34,6 +34,36 @@ class Snapcast extends React.Component{
|
||||
return null;
|
||||
}
|
||||
|
||||
var clients = [];
|
||||
for (var client_id in this.props.snapcast_clients){
|
||||
if (this.props.snapcast_clients.hasOwnProperty(client_id)){
|
||||
clients.push(this.props.snapcast_clients[client_id]);
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="snapcast">
|
||||
<div className="clients">
|
||||
{
|
||||
clients.map(client => {
|
||||
return (
|
||||
<div key={client.id}>
|
||||
{client.config.volume.muted ? <FontAwesome name="volume-off" onClick={e => this.props.pusherActions.setSnapcastClientVolume(client.id, false, client.config.volume.percent)} /> : <FontAwesome name="volume-up" onClick={e => this.props.pusherActions.setSnapcastClientVolume(client.id, true, client.config.volume.percent)} />} {client.config.name ? client.config.name : client.host.name} {client.config.volume.percent}
|
||||
</div>
|
||||
);
|
||||
})
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
var groups = [];
|
||||
for (var group_id in this.props.snapcast_groups){
|
||||
if (this.props.connections.hasOwnProperty(group_id)){
|
||||
groups.push(this.props.snapcast_groups[group_id]);
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="snapcast">
|
||||
{
|
||||
@ -46,7 +76,7 @@ class Snapcast extends React.Component{
|
||||
group.clients.map(client => {
|
||||
return (
|
||||
<div key={client.id}>
|
||||
{client.config.volume.muted ? <FontAwesome name="volume-off" onClick={e => this.props.pusherActions.setSnapcastClientVolume(client.id, false, client.config.volume.percent)} /> : <FontAwesome name="volume-up" onClick={e => this.props.pusherActions.setSnapcastClientVolume(client.id, true, client.config.volume.percent)} />} {client.config.name} {client.config.volume.percent}
|
||||
{client.config.volume.muted ? <FontAwesome name="volume-off" onClick={e => this.props.pusherActions.setSnapcastClientVolume(client.id, false, client.config.volume.percent)} /> : <FontAwesome name="volume-up" onClick={e => this.props.pusherActions.setSnapcastClientVolume(client.id, true, client.config.volume.percent)} />} {client.config.name ? client.config.name : client.host.name} {client.config.volume.percent}
|
||||
</div>
|
||||
);
|
||||
})
|
||||
@ -64,7 +94,8 @@ class Snapcast extends React.Component{
|
||||
const mapStateToProps = (state, ownProps) => {
|
||||
return {
|
||||
pusher_connected: state.pusher.connected,
|
||||
snapcast: state.pusher.snapcast
|
||||
snapcast_groups: state.pusher.snapcast_groups,
|
||||
snapcast_clients: state.pusher.snapcast_clients
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -516,7 +516,37 @@ const PusherMiddleware = (function(){
|
||||
request(store, 'snapcast_instruct', action.data)
|
||||
.then(
|
||||
response => {
|
||||
store.dispatch({type: 'PUSHER_SNAPCAST', snapcast: response.server})
|
||||
var groups = {};
|
||||
var clients = {};
|
||||
|
||||
// Loop all the groups
|
||||
for (var i = 0; i < response.server.groups.length; i++){
|
||||
var group = response.server.groups[i];
|
||||
groups[group.id] = {
|
||||
id: group.id,
|
||||
muted: group.muted,
|
||||
name: group.name,
|
||||
stream_id: group.stream_id
|
||||
}
|
||||
|
||||
// And now this groups' clients
|
||||
for (var i = 0; i < group.clients.length; i++){
|
||||
var client = group.clients[i];
|
||||
clients[client.id] = Object.assign(
|
||||
{},
|
||||
client,
|
||||
{
|
||||
group_id: group.id
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
store.dispatch({
|
||||
type: 'PUSHER_SNAPCAST',
|
||||
snapcast_clients: clients,
|
||||
snapcast_groups: groups
|
||||
})
|
||||
},
|
||||
error => {
|
||||
store.dispatch(coreActions.handleException(
|
||||
@ -536,7 +566,11 @@ const PusherMiddleware = (function(){
|
||||
store.dispatch({
|
||||
type: 'PUSHER_SNAPCAST_CLIENT_UPDATED',
|
||||
key: response.client.id,
|
||||
client: response.client
|
||||
client: {
|
||||
config: {
|
||||
volume: response.volume
|
||||
}
|
||||
}
|
||||
})
|
||||
},
|
||||
error => {
|
||||
|
||||
@ -52,7 +52,12 @@ export default function reducer(pusher = {}, action){
|
||||
return Object.assign({}, pusher, { upgrading: true });
|
||||
|
||||
case 'PUSHER_SNAPCAST':
|
||||
return Object.assign({}, pusher, { snapcast: action.snapcast });
|
||||
return Object.assign({}, pusher, { snapcast_clients: action.snapcast_clients, snapcast_groups: action.snapcast_groups });
|
||||
|
||||
case 'PUSHER_SNAPCAST_CLIENT_UPDATED':
|
||||
var snapcast_clients = Object.assign({}, pusher.snapcast_clients);
|
||||
snapcast_clients[action.key] = Object.assign({}, snapcast_clients[action.key], action.client);
|
||||
return Object.assign({}, pusher, { snapcast_clients: snapcast_clients });
|
||||
|
||||
default:
|
||||
return pusher
|
||||
|
||||
Reference in New Issue
Block a user