diff --git a/src/actions/mopidy.js b/src/actions/mopidy.js index b0814aaf..ae3a2239 100755 --- a/src/actions/mopidy.js +++ b/src/actions/mopidy.js @@ -10,6 +10,20 @@ export function updateStatus( online ){ } } +export function updateState( state ){ + return { + type: 'STATE', + state: state + } +} + +export function updateConsume( consume ){ + return { + type: 'CONSUME', + consume: consume + } +} + export function updateTracklist( tracks ){ return { type: 'TRACKLIST', diff --git a/src/reducers/mopidy.js b/src/reducers/mopidy.js index 17ebbb47..f52fa120 100755 --- a/src/reducers/mopidy.js +++ b/src/reducers/mopidy.js @@ -4,7 +4,17 @@ export default function reducer(mopidy = {}, action){ case 'STATUS': return Object.assign({}, mopidy, { - online: action.online + online: action.online + }); + + case 'STATE': + return Object.assign({}, mopidy, { + state: action.state + }); + + case 'CONSUME': + return Object.assign({}, mopidy, { + consume: action.consume }); case 'TRACKLIST': diff --git a/src/services/MopidyService.js b/src/services/MopidyService.js index 2e49ec80..ef58186f 100755 --- a/src/services/MopidyService.js +++ b/src/services/MopidyService.js @@ -18,7 +18,7 @@ class MopidyService extends React.Component{ super(props) this.connection = new Mopidy({ - webSocketUrl: "ws://music.barnsley.nz:6680/mopidy/ws", + webSocketUrl: "ws://music.james:6680/mopidy/ws", callingConvention: 'by-position-or-by-name' }); @@ -30,9 +30,13 @@ class MopidyService extends React.Component{ case 'state:online': this.props.actions.updateStatus( true ); + this.getState(); this.getTracklist(); this.getTrackInFocus(); this.getVolume(); + this.getConsume(); + //this.getShuffle(); + //this.getRandom(); break; case 'state:offline': @@ -44,14 +48,22 @@ class MopidyService extends React.Component{ break; //case 'event:trackPlaybackEnded': + case 'event:playbackStateChanged': case 'event:trackPlaybackStarted': this.getTrackInFocus(); + this.getState(); break; case 'event:volumeChanged': this.props.actions.updateVolume( data.volume ); break; + case 'event:optionsChanged': + this.getConsume(); + //this.getShuffle(); + //this.getRandom(); + break; + default: //console.log( 'MopidyService: Unhandled event', type, message ); } @@ -85,8 +97,42 @@ class MopidyService extends React.Component{ }); } + getState(){ + let self = this; + this.connection.playback.getState() + .then( function( state ){ + self.props.actions.updateState( state ); + }); + } + + getConsume(){ + let self = this; + this.connection.tracklist.getConsume() + .then( function( consume ){ + self.props.actions.updateConsume( consume ); + }); + } + render(){ - return null + console.log( this.props.mopidy ); + var playButton = this.connection.playback.play()}>Play; + if( this.props.mopidy.state == 'playing' ){ + playButton = this.connection.playback.pause()}>Pause; + } + + var consumeButton = this.connection.tracklist.setConsume(true)}>Consume; + if( this.props.mopidy.consume ){ + consumeButton = this.connection.tracklist.setConsume(false)}>Un-Consume; + } + + return ( +