2018-03-12 21:39:27 +13:00
|
|
|
|
|
|
|
|
import React, { PropTypes } from 'react'
|
|
|
|
|
import { connect } from 'react-redux'
|
|
|
|
|
import { bindActionCreators } from 'redux'
|
|
|
|
|
import { Link, hashHistory } from 'react-router'
|
|
|
|
|
import FontAwesome from 'react-fontawesome'
|
|
|
|
|
|
|
|
|
|
import ArtistSentence from './ArtistSentence'
|
2018-03-23 16:54:56 +13:00
|
|
|
import VolumeControl from './VolumeControl'
|
|
|
|
|
|
2018-03-12 21:39:27 +13:00
|
|
|
import * as helpers from '../helpers'
|
|
|
|
|
import * as coreActions from '../services/core/actions'
|
|
|
|
|
import * as uiActions from '../services/ui/actions'
|
|
|
|
|
import * as pusherActions from '../services/pusher/actions'
|
|
|
|
|
|
|
|
|
|
class Snapcast extends React.Component{
|
|
|
|
|
|
|
|
|
|
constructor(props){
|
2018-03-23 16:54:56 +13:00
|
|
|
super(props);
|
|
|
|
|
|
|
|
|
|
this.state = {
|
|
|
|
|
editing_client: null
|
|
|
|
|
}
|
2018-03-12 21:39:27 +13:00
|
|
|
}
|
|
|
|
|
|
2018-03-21 21:40:47 +13:00
|
|
|
componentDidMount(){
|
2018-03-26 10:36:13 +13:00
|
|
|
if (this.props.pusher_connected && this.props.snapcast_enabled){
|
2018-03-21 21:40:47 +13:00
|
|
|
this.props.pusherActions.getSnapcast();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
componentWillReceiveProps(newProps){
|
2018-03-26 10:36:13 +13:00
|
|
|
|
|
|
|
|
// Just connected
|
2018-03-21 21:40:47 +13:00
|
|
|
if (!this.props.pusher_connected && newProps.pusher_connected){
|
|
|
|
|
this.props.pusherActions.getSnapcast();
|
2018-03-26 10:36:13 +13:00
|
|
|
|
|
|
|
|
// Just enabled (well, identified as being enabled)
|
|
|
|
|
} else if (!this.props.pusher_enabled && newProps.pusher_enabled && newProps.pusher_connected){
|
|
|
|
|
this.props.pusherActions.getSnapcast();
|
2018-03-21 21:40:47 +13:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-23 16:54:56 +13:00
|
|
|
saveEditingClient(){
|
|
|
|
|
this.props.pusherActions.setSnapcastClientName(this.state.editing_client.id, this.state.editing_client.name);
|
|
|
|
|
this.setState({editing_client: null});
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-12 21:39:27 +13:00
|
|
|
render(){
|
2018-03-22 16:59:04 +13:00
|
|
|
if (!this.props.snapcast_clients || !this.props.snapcast_groups){
|
2018-03-12 21:39:27 +13:00
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-22 16:59:04 +13:00
|
|
|
// Construct a simple array of our groups index
|
|
|
|
|
var groups = [];
|
|
|
|
|
for (var group_id in this.props.snapcast_groups){
|
|
|
|
|
if (this.props.snapcast_groups.hasOwnProperty(group_id)){
|
|
|
|
|
var group = this.props.snapcast_groups[group_id];
|
2018-03-21 22:08:53 +13:00
|
|
|
|
2018-03-22 16:59:04 +13:00
|
|
|
// Merge the group's clients into this group (also as a simple array)
|
|
|
|
|
var clients = [];
|
|
|
|
|
for (var i = 0; i < group.clients_ids.length; i++){
|
|
|
|
|
if (this.props.snapcast_clients.hasOwnProperty(group.clients_ids[i])){
|
|
|
|
|
clients.push(this.props.snapcast_clients[group.clients_ids[i]]);
|
2018-03-21 22:08:53 +13:00
|
|
|
}
|
2018-03-22 16:59:04 +13:00
|
|
|
}
|
2018-03-21 22:08:53 +13:00
|
|
|
|
2018-03-22 16:59:04 +13:00
|
|
|
groups.push(Object.assign(
|
|
|
|
|
{},
|
|
|
|
|
group,
|
|
|
|
|
{
|
|
|
|
|
clients: clients
|
|
|
|
|
}
|
|
|
|
|
));
|
2018-03-21 22:08:53 +13:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-12 21:39:27 +13:00
|
|
|
return (
|
|
|
|
|
<div className="snapcast">
|
|
|
|
|
{
|
2018-03-22 16:59:04 +13:00
|
|
|
groups.map(group => {
|
2018-03-12 21:39:27 +13:00
|
|
|
return (
|
|
|
|
|
<div className="group" key={group.id}>
|
2018-03-23 16:54:56 +13:00
|
|
|
<div className="inner">
|
|
|
|
|
<div className="name">
|
|
|
|
|
{group.name ? group.name : 'Untitled group'}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2018-03-12 21:39:27 +13:00
|
|
|
<div className="clients">
|
|
|
|
|
{
|
|
|
|
|
group.clients.map(client => {
|
2018-03-23 22:06:12 +13:00
|
|
|
var name = client.config.name ? client.config.name : client.host.name;
|
2018-03-12 21:39:27 +13:00
|
|
|
return (
|
2018-03-23 16:54:56 +13:00
|
|
|
<div className={"client "+(client.connected ? 'connected' : 'disconnected')} key={client.id}>
|
|
|
|
|
<div className="inner">
|
2018-03-23 22:06:12 +13:00
|
|
|
<div className="name">
|
|
|
|
|
{name} {!client.connected ? '(disconnected)' : null}
|
|
|
|
|
</div>
|
2018-03-23 16:54:56 +13:00
|
|
|
<div className="controls">
|
2018-03-23 22:06:12 +13:00
|
|
|
<div className="control edit" onClick={e => this.props.uiActions.openModal('edit_snapcast_client',{id: client.id})}>
|
|
|
|
|
<FontAwesome name="cog" />
|
|
|
|
|
</div>
|
2018-03-23 16:54:56 +13:00
|
|
|
<VolumeControl
|
|
|
|
|
volume={client.config.volume.percent}
|
|
|
|
|
mute={client.config.volume.muted}
|
|
|
|
|
onVolumeChange={percent => this.props.pusherActions.setSnapcastClientVolume(client.id, client.config.volume.muted, percent)}
|
|
|
|
|
onMuteChange={mute => this.props.pusherActions.setSnapcastClientVolume(client.id, mute, client.config.volume.percent)}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2018-03-12 21:39:27 +13:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const mapStateToProps = (state, ownProps) => {
|
|
|
|
|
return {
|
2018-03-26 10:36:13 +13:00
|
|
|
snapcast_enabled: state.pusher.config.snapcast_enabled,
|
2018-03-21 21:40:47 +13:00
|
|
|
pusher_connected: state.pusher.connected,
|
2018-03-21 22:08:53 +13:00
|
|
|
snapcast_groups: state.pusher.snapcast_groups,
|
|
|
|
|
snapcast_clients: state.pusher.snapcast_clients
|
2018-03-12 21:39:27 +13:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const mapDispatchToProps = (dispatch) => {
|
|
|
|
|
return {
|
|
|
|
|
coreActions: bindActionCreators(coreActions, dispatch),
|
|
|
|
|
uiActions: bindActionCreators(uiActions, dispatch),
|
|
|
|
|
pusherActions: bindActionCreators(pusherActions, dispatch)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(Snapcast)
|