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-04-19 13:34:16 +12:00
|
|
|
import VolumeControl from './Fields/VolumeControl'
|
|
|
|
|
import LatencyControl from './Fields/LatencyControl'
|
|
|
|
|
import TextField from './Fields/TextField'
|
2018-03-23 16:54:56 +13:00
|
|
|
|
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);
|
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-04-03 17:01:40 +12:00
|
|
|
if (newProps.snapcast_enabled && !this.props.pusher_connected && newProps.pusher_connected){
|
2018-03-26 10:36:13 +13:00
|
|
|
this.props.pusherActions.getSnapcast();
|
2018-04-19 06:20:54 +12:00
|
|
|
|
|
|
|
|
// Just enabled
|
|
|
|
|
// This is the more probable scenario as we don't know if we're enabled until pusher connects
|
|
|
|
|
// and then gets the config from the server
|
|
|
|
|
} else if (!this.props.snapcast_enabled && newProps.snapcast_enabled && newProps.pusher_connected){
|
|
|
|
|
this.props.pusherActions.getSnapcast();
|
2018-03-21 21:40:47 +13:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-12 21:39:27 +13:00
|
|
|
render(){
|
2018-04-03 17:01:40 +12:00
|
|
|
if (!this.props.snapcast_enabled){
|
|
|
|
|
return (
|
|
|
|
|
<div>
|
|
|
|
|
To enable Snapcast, edit your <code>mopidy.conf</code> file
|
|
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-22 16:59:04 +13:00
|
|
|
if (!this.props.snapcast_clients || !this.props.snapcast_groups){
|
2018-04-03 17:01:40 +12:00
|
|
|
return (
|
|
|
|
|
<div className="lazy-loader body-loader loading">
|
|
|
|
|
<div className="loader"></div>
|
|
|
|
|
</div>
|
|
|
|
|
)
|
2018-03-12 21:39:27 +13:00
|
|
|
}
|
|
|
|
|
|
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 (
|
2018-04-18 17:01:57 +12:00
|
|
|
<div className="list group" key={group.id}>
|
|
|
|
|
<div className="list-item header">
|
2018-04-19 06:20:54 +12:00
|
|
|
<div className="col name">
|
2018-03-23 16:54:56 +13:00
|
|
|
{group.name ? group.name : 'Untitled group'}
|
|
|
|
|
</div>
|
2018-04-19 06:20:54 +12:00
|
|
|
<div className="col volume">
|
2018-04-18 17:01:57 +12:00
|
|
|
Volume
|
|
|
|
|
</div>
|
2018-04-19 06:20:54 +12:00
|
|
|
<div className="col latency">
|
2018-04-18 17:01:57 +12:00
|
|
|
Latency
|
|
|
|
|
</div>
|
2018-03-23 16:54:56 +13:00
|
|
|
</div>
|
2018-04-18 17:01:57 +12:00
|
|
|
{
|
|
|
|
|
group.clients.map(client => {
|
|
|
|
|
var name = client.config.name ? client.config.name : client.host.name;
|
|
|
|
|
return (
|
2018-04-19 06:20:54 +12:00
|
|
|
<div className="list-item client" key={client.id}>
|
|
|
|
|
<div className="col name">
|
2018-04-18 17:01:57 +12:00
|
|
|
<TextField
|
|
|
|
|
onChange={value => this.props.pusherActions.setSnapcastClientName(client.id, value)}
|
|
|
|
|
value={name}
|
|
|
|
|
/>
|
2018-04-19 06:20:54 +12:00
|
|
|
{client.connected ? <span className="status has-tooltip">
|
|
|
|
|
<FontAwesome className="green-text" name="circle" />
|
|
|
|
|
<span className="tooltip">Connected</span>
|
|
|
|
|
</span> : <span className="status has-tooltip">
|
|
|
|
|
<FontAwesome className="grey-text" name="circle" />
|
|
|
|
|
<span className="tooltip">Not connected</span>
|
|
|
|
|
</span>}
|
2018-03-12 21:39:27 +13:00
|
|
|
</div>
|
2018-04-19 06:20:54 +12:00
|
|
|
<div className="col volume">
|
2018-04-18 17:01:57 +12:00
|
|
|
<VolumeControl
|
|
|
|
|
volume={client.config.volume.percent}
|
|
|
|
|
mute={client.config.volume.muted}
|
|
|
|
|
onVolumeChange={percent => this.props.pusherActions.setSnapcastClientVolume(client.id, percent)}
|
|
|
|
|
onMuteChange={mute => this.props.pusherActions.setSnapcastClientMute(client.id, mute)}
|
|
|
|
|
/>
|
|
|
|
|
<TextField
|
|
|
|
|
className="tiny"
|
|
|
|
|
onChange={value => this.props.pusherActions.setSnapcastClientVolume(client.id, parseInt(value))}
|
|
|
|
|
value={client.config.volume.percent}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
2018-04-19 06:20:54 +12:00
|
|
|
<div className="col latency">
|
2018-04-18 17:01:57 +12:00
|
|
|
<LatencyControl
|
|
|
|
|
max="100"
|
|
|
|
|
value={client.config.latency}
|
|
|
|
|
onChange={value => this.props.pusherActions.setSnapcastClientLatency(client.id, parseInt(value))}
|
|
|
|
|
/>
|
|
|
|
|
<TextField
|
|
|
|
|
className="tiny"
|
|
|
|
|
onChange={value => this.props.pusherActions.setSnapcastClientLatency(client.id, parseInt(value))}
|
2018-04-19 06:20:54 +12:00
|
|
|
value={String(client.config.latency)}
|
2018-04-18 17:01:57 +12:00
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
})
|
|
|
|
|
}
|
2018-03-12 21:39:27 +13:00
|
|
|
</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)
|