import React, { PropTypes } from 'react' import { connect } from 'react-redux' import { bindActionCreators } from 'redux' import VolumeControl from './VolumeControl' import MuteControl from './MuteControl' import SnapcastPowerButton from './SnapcastPowerButton' import Icon from '../Icon' import * as helpers from '../../helpers'; import * as coreActions from '../../services/core/actions'; import * as pusherActions from '../../services/pusher/actions'; import * as snapcastActions from '../../services/snapcast/actions'; class OutputControl extends React.Component{ constructor(props){ super(props); this.state = { expanded: false } this.handleClick = this.handleClick.bind(this); } handleClick(e){ if (!this.props.force_expanded && $(e.target).closest('.output-control').length <= 0){ this.setExpanded(false); } } componentWillReceiveProps(nextProps){ // When force expanded triggered if (!this.props.force_expanded && nextProps.force_expanded){ this.setExpanded(true, nextProps); } } setExpanded(expanded = !this.state.expanded, props = this.props){ if (expanded){ this.setState({expanded: expanded}); window.addEventListener("click", this.handleClick, false); // Re-check our snapcast clients // TODO: Once we have push events, remove this as it'll (marginally) // slow down the reveal/render if (props.pusher_connected && props.snapcast_enabled){ this.props.snapcastActions.getServer(); } } else { this.setState({expanded: expanded}); window.removeEventListener("click", this.handleClick, false); } } renderOutputs(){ var clients = []; for (var key in this.props.snapcast_clients){ if (this.props.snapcast_clients.hasOwnProperty(key)){ var client = this.props.snapcast_clients[key]; if (client.connected){ clients.push(client); } } } var snapcast_clients = null; if (clients.length > 0){ snapcast_clients = (
No outputs