Radio starting and stopping

This commit is contained in:
James Barnsley
2016-12-20 19:54:19 +13:00
parent bf3b2bfba1
commit 005e2b58b5
6 changed files with 22 additions and 10 deletions

View File

@ -98,7 +98,7 @@ class IrisFrontend(pykka.ThreadingActor, CoreListener):
self.load_more_tracks()
except RuntimeError:
logger.warning('RadioHandler: Could not fetch tracklist length')
logger.warning('IrisFrontend: Could not fetch tracklist length')
pass
@ -156,7 +156,7 @@ class IrisFrontend(pykka.ThreadingActor, CoreListener):
self.core.playback.play()
# notify clients
pusher.broadcast( 'radio_started', { 'radio': self.radio })
pusher.broadcast( 'radio', { 'radio': self.radio })
# return new radio state to initial call
return self.radio
@ -178,7 +178,7 @@ class IrisFrontend(pykka.ThreadingActor, CoreListener):
self.core.playback.stop()
# notify clients
pusher.broadcast( 'radio_stopped', { 'radio': self.radio })
pusher.broadcast( 'radio', { 'radio': self.radio })
# return new radio state to initial call
return self.radio

View File

@ -194,7 +194,7 @@ class PusherWebsocketHandler(tornado.websocket.WebSocketHandler):
send_message(
self.connectionid,
'response',
'radio_started',
'radio',
messageJson['message_id'],
{ 'radio': radio }
)
@ -205,7 +205,7 @@ class PusherWebsocketHandler(tornado.websocket.WebSocketHandler):
send_message(
self.connectionid,
'response',
messageJson['action'],
'radio',
messageJson['message_id'],
{ 'radio': self.frontend.radio }
)
@ -215,7 +215,7 @@ class PusherWebsocketHandler(tornado.websocket.WebSocketHandler):
send_message(
self.connectionid,
'response',
messageJson['action'],
'radio',
messageJson['message_id'],
{ 'radio': self.frontend.radio }
)

View File

@ -50,7 +50,7 @@ export function startRadio( uris ){
}
}
export function stopRadio( uris ){
export function stopRadio(){
return {
type: 'PUSHER_STOP_RADIO'
}

View File

@ -189,6 +189,16 @@ const PusherMiddleware = (function(){
makeRequest( data )
break
case 'PUSHER_STOP_RADIO':
var data = {
action: 'stop_radio',
seed_artists: [],
seed_genres: [],
seed_tracks: []
}
makeRequest( data )
break
// This action is irrelevant to us, pass it on to the next middleware
default:
return next(action);

View File

@ -119,7 +119,7 @@ export default function reducer(ui = {}, action){
case 'PUSHER_RADIO':
case 'PUSHER_START_RADIO':
return Object.assign({}, ui, { radio: action.data })
return Object.assign({}, ui, { radio: action.data.radio })

View File

@ -12,6 +12,7 @@ import ArtistSentence from '../components/ArtistSentence'
import Header from '../components/Header'
import * as uiActions from '../services/ui/actions'
import * as pusherActions from '../services/pusher/actions'
import * as spotifyActions from '../services/spotify/actions'
import * as mopidyActions from '../services/mopidy/actions'
@ -42,12 +43,12 @@ class Queue extends React.Component{
}
renderRadio(){
if (!this.props.radio) return null
if (!this.props.radio || !this.props.radio.enabled) return null
return (
<div className="radio">
Playing radio
<button onClick={ e => this.props.pusherActions.instruct('stop_radio') }>Stop radio</button>
<a onClick={ e => this.props.pusherActions.stopRadio() }>Stop radio</a>
</div>
)
}
@ -95,6 +96,7 @@ const mapStateToProps = (state, ownProps) => {
const mapDispatchToProps = (dispatch) => {
return {
uiActions: bindActionCreators(uiActions, dispatch),
pusherActions: bindActionCreators(pusherActions, dispatch),
spotifyActions: bindActionCreators(spotifyActions, dispatch),
mopidyActions: bindActionCreators(mopidyActions, dispatch)
}