import React, { PropTypes } from 'react' import { connect } from 'react-redux' import { Link } from 'react-router' import { bindActionCreators } from 'redux' import FontAwesome from 'react-fontawesome' import Thumbnail from './Thumbnail' import Icon from './Icon' import URILink from './URILink' import SpotifyAuthenticationFrame from '../components/SpotifyAuthenticationFrame' import LastfmAuthenticationFrame from '../components/LastfmAuthenticationFrame' import Snapcast from '../components/Snapcast' import * as uiActions from '../services/ui/actions' import * as coreActions from '../services/core/actions' import * as mopidyActions from '../services/mopidy/actions' import * as pusherActions from '../services/pusher/actions' import * as spotifyActions from '../services/spotify/actions' import * as lastfmActions from '../services/lastfm/actions' class Services extends React.Component{ constructor(props){ super(props); this.state = { country: this.props.spotify.country, locale: this.props.spotify.locale, input_in_focus: null } } componentDidMount(){ if (this.props.lastfm.session && this.props.core.users["lastfm:user:"+this.props.lastfm.session.name] === undefined){ this.props.lastfmActions.getMe(); } } componentWillReceiveProps(newProps){ var changed = false var state = this.state if (newProps.spotify.country != this.state.country && this.state.input_in_focus != 'country'){ state.country = newProps.spotify.country changed = true } if (newProps.spotify.locale != this.state.locale && this.state.input_in_focus != 'locale'){ state.locale = newProps.spotify.locale changed = true } if (changed){ this.setState(state) } } handleBlur(name, value){ this.setState({input_in_focus: null}) var data = {} data[name] = value this.props.coreActions.set(data) } renderSpotify(){ var authorization_button = null; var send_authorization_button = null; if (this.props.spotify.authorization){ authorization_button = ( ); send_authorization_button = ( ); } var user_object = this.props.spotify.me; if (user_object){ var user = ( {user_object.display_name ? user_object.display_name : user_object.id} {!this.props.spotify.authorization ?   (Limited access) : null} ) } else { var user = ( Unknown ) } var not_installed = null; if (!this.props.mopidy.uri_schemes || !this.props.mopidy.uri_schemes.includes('spotify:')){ not_installed = (

Mopidy-Spotify extension is not running - you will not be able to play any Spotify tracks


); } return (
{not_installed}
Country
this.setState({country: e.target.value})} onFocus={e => this.setState({input_in_focus: 'country'})} onBlur={e => this.props.spotifyActions.set({country: e.target.value})} value={ this.state.country } />
An ISO 3166-1 alpha-2 country code (eg NZ)
Locale
this.setState({locale: e.target.value})} onFocus={e => this.setState({input_in_focus: 'locale'})} onBlur={e => this.props.spotifyActions.set({locale: e.target.value})} value={this.state.locale} />
Lowercase ISO 639 language code and an uppercase ISO 3166-1 alpha-2 country code, joined by an underscore (eg en_NZ)
Current user
{user}
Authorization
{send_authorization_button} {this.props.spotify.refreshing_token ? : }
); } renderLastfm(){ var user_object = (this.props.lastfm.session ? this.props.core.users["lastfm:user:"+this.props.lastfm.session.name] : null); if (user_object){ var user = ( {user_object.realname ? user_object.realname : user_object.name} ) } else { var user = ( Unknown ) } return (
{this.props.lastfm.session ?
Current user
{user}
: null}
Authorization
); } renderIcecast(){ return (
Enable
Encoding
Location
this.props.coreActions.set({http_streaming_url: e.target.value})} value={this.props.core.http_streaming_url} />
The full URL to your stream endpoint
); } renderMenu(){ if (this.props.spotify.me){ var spotify_icon = } else { var spotify_icon = } if (this.props.lastfm.session && this.props.core.users["lastfm:user:"+this.props.lastfm.session.name]){ var lastfm_icon = } else { var lastfm_icon = } return (
{spotify_icon}
Spotify
{this.props.spotify.authorization ? Authorized : Read-only}
{lastfm_icon}
LastFM
{this.props.lastfm.session ? Authorized : Read-only}
Snapcast
{this.props.pusher.config.snapcast_enabled ? Enabled : Disabled}
Icecast
{this.props.core.http_streaming_enabled ? Enabled : Disabled}
); } renderService(){ var service = null; switch (this.props.active){ case 'spotify': service = this.renderSpotify(); break; case 'lastfm': service = this.renderLastfm(); break; case 'icecast': service = this.renderIcecast(); break; case 'snapcast': service = break; } if (service){ return (
{service}
); } else { return null; } } render(){ return (
{this.renderMenu()} {this.renderService()}
); } } const mapStateToProps = (state, ownProps) => { return state } const mapDispatchToProps = (dispatch) => { return { coreActions: bindActionCreators(coreActions, dispatch), uiActions: bindActionCreators(uiActions, dispatch), pusherActions: bindActionCreators(pusherActions, dispatch), mopidyActions: bindActionCreators(mopidyActions, dispatch), spotifyActions: bindActionCreators(spotifyActions, dispatch), lastfmActions: bindActionCreators(lastfmActions, dispatch) } } export default connect(mapStateToProps, mapDispatchToProps)(Services)