Browser notifications now working
This commit is contained in:
@ -198,43 +198,23 @@ const MopidyMiddleware = (function(){
|
||||
**/
|
||||
|
||||
case 'MOPIDY_NEXT':
|
||||
var icon = false
|
||||
if( store.getState().ui.current_track ){
|
||||
icon = helpers.getTrackIcon( store.getState().ui.current_track )
|
||||
var data = {
|
||||
type: 'browser_notification',
|
||||
title: 'Track skipped',
|
||||
body: store.getState().pusher.username +' skipped this track',
|
||||
icon: (store.getState().ui.current_track ? helpers.getTrackIcon( store.getState().ui.current_track ) : false)
|
||||
}
|
||||
store.dispatch({
|
||||
type: 'PUSHER_SEND_BROADCAST',
|
||||
action: 'broadcast',
|
||||
ignore_self: true,
|
||||
data: {
|
||||
type: 'notification',
|
||||
data: {
|
||||
title: 'Track skipped',
|
||||
body: store.getState().pusher.username +' skipped this track',
|
||||
icon: icon
|
||||
}
|
||||
}
|
||||
})
|
||||
store.dispatch( pusherActions.deliverBroadcast(data) )
|
||||
break;
|
||||
|
||||
case 'MOPIDY_STOP':
|
||||
var icon = false
|
||||
if( store.getState().ui.current_track ){
|
||||
icon = helpers.getTrackIcon( store.getState().ui.current_track )
|
||||
var data = {
|
||||
type: 'browser_notification',
|
||||
title: 'Playback stopped',
|
||||
body: store.getState().pusher.username +' stopped playback',
|
||||
icon: (store.getState().ui.current_track ? helpers.getTrackIcon( store.getState().ui.current_track ) : false)
|
||||
}
|
||||
store.dispatch({
|
||||
type: 'PUSHER_SEND_BROADCAST',
|
||||
action: 'broadcast',
|
||||
ignore_self: true,
|
||||
data: {
|
||||
type: 'notification',
|
||||
data: {
|
||||
title: 'Playback stopped',
|
||||
body: store.getState().pusher.username +' stopped playback',
|
||||
icon: icon
|
||||
}
|
||||
}
|
||||
})
|
||||
store.dispatch( pusherActions.deliverBroadcast(data) )
|
||||
break;
|
||||
|
||||
case 'MOPIDY_ENQUEUE_URIS':
|
||||
|
||||
@ -48,6 +48,13 @@ export function instruct( data = null ){
|
||||
}
|
||||
}
|
||||
|
||||
export function deliverBroadcast( data = null ){
|
||||
return {
|
||||
type: 'PUSHER_DELIVER_BROADCAST',
|
||||
data: data
|
||||
}
|
||||
}
|
||||
|
||||
export function sendAuthorization( recipient_connectionid, authorization, me ){
|
||||
return {
|
||||
type: 'PUSHER_DELIVER_MESSAGE',
|
||||
|
||||
@ -159,7 +159,7 @@ const PusherMiddleware = (function(){
|
||||
break
|
||||
|
||||
case 'PUSHER_DELIVER_MESSAGE':
|
||||
request('deliver_message', action)
|
||||
request('deliver_message', action.data)
|
||||
.then(
|
||||
response => {
|
||||
store.dispatch( uiActions.createNotification('Message delivered') )
|
||||
@ -167,6 +167,10 @@ const PusherMiddleware = (function(){
|
||||
)
|
||||
break
|
||||
|
||||
case 'PUSHER_DELIVER_BROADCAST':
|
||||
request('broadcast', action.data)
|
||||
break
|
||||
|
||||
case 'PUSHER_GET_QUEUE_METADATA':
|
||||
request('get_queue_metadata')
|
||||
.then(
|
||||
@ -276,10 +280,18 @@ const PusherMiddleware = (function(){
|
||||
}
|
||||
}
|
||||
|
||||
// we don't need to wait for response, as change will be broadcast
|
||||
request( 'start_radio', data )
|
||||
.then(response => {
|
||||
console.log(response)
|
||||
})
|
||||
break
|
||||
|
||||
case 'PUSHER_RADIO_STARTED':
|
||||
var data = {
|
||||
type: 'browser_notification',
|
||||
title: 'Radio',
|
||||
body: 'Radio mode started',
|
||||
icon: (store.getState().ui.current_track ? helpers.getTrackIcon( store.getState().ui.current_track ) : false)
|
||||
}
|
||||
store.dispatch( pusherActions.deliverBroadcast(data) )
|
||||
break
|
||||
|
||||
case 'PUSHER_STOP_RADIO':
|
||||
@ -291,10 +303,20 @@ const PusherMiddleware = (function(){
|
||||
seed_tracks: []
|
||||
}
|
||||
|
||||
// we don't need to wait for request, as change will be broadcast
|
||||
// we don't need to wait for response, as change will be broadcast
|
||||
request( 'stop_radio', data )
|
||||
break
|
||||
|
||||
case 'PUSHER_RADIO_STOPPED':
|
||||
var data = {
|
||||
type: 'browser_notification',
|
||||
title: 'Radio',
|
||||
body: 'Radio mode stopped',
|
||||
icon: (store.getState().ui.current_track ? helpers.getTrackIcon( store.getState().ui.current_track ) : false)
|
||||
}
|
||||
store.dispatch( pusherActions.deliverBroadcast(data) )
|
||||
break
|
||||
|
||||
case 'PUSHER_BROWSER_NOTIFICATION':
|
||||
store.dispatch(uiActions.createBrowserNotification(action))
|
||||
break
|
||||
|
||||
Reference in New Issue
Block a user