Handling new api structure with client-triggered broadcasts
This commit is contained in:
@ -33,7 +33,7 @@ export default class Notifications extends React.Component{
|
||||
default:
|
||||
return (
|
||||
<div className={notification.type+" notification"+(notification.closing ? ' closing' : '')} key={notification.key} data-key={notification.key} data-duration={notification.duration}>
|
||||
<FontAwesome name="close" className="close-button" onClick={ e => this.props.uiActions.removeNotification(notification.key) } />
|
||||
<FontAwesome name="close" className="close-button" onClick={ e => this.props.uiActions.removeNotification(notification.key, true) } />
|
||||
{notification.title ? <h4>{notification.title}</h4> : null}
|
||||
<p className="content" dangerouslySetInnerHTML={{__html: notification.content}}></p>
|
||||
{notification.description ? <p className="description" dangerouslySetInnerHTML={{__html: notification.description}}></p> : null }
|
||||
|
||||
@ -76,7 +76,6 @@ const MopidyMiddleware = (function(){
|
||||
break;
|
||||
|
||||
case 'event:playbackStateChanged':
|
||||
console.log(type,data);
|
||||
store.dispatch({
|
||||
type: 'MOPIDY_PLAY_STATE',
|
||||
play_state: data.new_state
|
||||
@ -262,12 +261,14 @@ const MopidyMiddleware = (function(){
|
||||
}
|
||||
);
|
||||
|
||||
store.dispatch(pusherActions.deliverBroadcast({
|
||||
type: 'notification',
|
||||
notification_type: 'info',
|
||||
content: store.getState().pusher.username +(store.getState().mopidy.play_state == 'paused' ? ' resumed' : ' started')+' playback',
|
||||
icon: (store.getState().core.current_track ? helpers.getTrackIcon(store.getState().core.current_track, store.getState().core) : false)
|
||||
}));
|
||||
store.dispatch(pusherActions.deliverBroadcast(
|
||||
'notification',
|
||||
{
|
||||
notification_type: 'info',
|
||||
content: store.getState().pusher.username +(store.getState().mopidy.play_state == 'paused' ? ' resumed' : ' started')+' playback',
|
||||
icon: (store.getState().core.current_track ? helpers.getTrackIcon(store.getState().core.current_track, store.getState().core) : false)
|
||||
}
|
||||
));
|
||||
break;
|
||||
|
||||
case 'MOPIDY_PAUSE':
|
||||
@ -281,23 +282,27 @@ const MopidyMiddleware = (function(){
|
||||
}
|
||||
);
|
||||
|
||||
store.dispatch(pusherActions.deliverBroadcast({
|
||||
type: 'notification',
|
||||
notification_type: 'info',
|
||||
content: store.getState().pusher.username +' paused playback',
|
||||
icon: (store.getState().core.current_track ? helpers.getTrackIcon(store.getState().core.current_track, store.getState().core) : false)
|
||||
}));
|
||||
store.dispatch(pusherActions.deliverBroadcast(
|
||||
'notification',
|
||||
{
|
||||
notification_type: 'info',
|
||||
content: store.getState().pusher.username +' paused playback',
|
||||
icon: (store.getState().core.current_track ? helpers.getTrackIcon(store.getState().core.current_track, store.getState().core) : false)
|
||||
}
|
||||
));
|
||||
break
|
||||
|
||||
case 'MOPIDY_NEXT':
|
||||
instruct(socket, store, 'playback.next');
|
||||
|
||||
store.dispatch(pusherActions.deliverBroadcast({
|
||||
type: 'notification',
|
||||
notification_type: 'info',
|
||||
content: store.getState().pusher.username +' skipped <em>'+store.getState().core.current_track.name+'</em>',
|
||||
icon: (store.getState().core.current_track ? helpers.getTrackIcon(store.getState().core.current_track, store.getState().core) : false)
|
||||
}));
|
||||
store.dispatch(pusherActions.deliverBroadcast(
|
||||
'notification',
|
||||
{
|
||||
notification_type: 'info',
|
||||
content: store.getState().pusher.username +' skipped <em>'+store.getState().core.current_track.name+'</em>',
|
||||
icon: (store.getState().core.current_track ? helpers.getTrackIcon(store.getState().core.current_track, store.getState().core) : false)
|
||||
}
|
||||
));
|
||||
break
|
||||
|
||||
case 'MOPIDY_STOP':
|
||||
@ -314,20 +319,24 @@ const MopidyMiddleware = (function(){
|
||||
case 'MOPIDY_CHANGE_TRACK':
|
||||
instruct(socket, store, 'playback.play', {tlid: action.tlid});
|
||||
|
||||
store.dispatch(pusherActions.deliverBroadcast({
|
||||
type: 'notification',
|
||||
notification_type: 'info',
|
||||
content: store.getState().pusher.username +' changed track'
|
||||
}));
|
||||
store.dispatch(pusherActions.deliverBroadcast(
|
||||
'notification',
|
||||
{
|
||||
notification_type: 'info',
|
||||
content: store.getState().pusher.username +' changed track'
|
||||
}
|
||||
));
|
||||
break;
|
||||
|
||||
case 'MOPIDY_REMOVE_TRACKS':
|
||||
instruct(socket, store, 'tracklist.remove', {tlid: action.tlids});
|
||||
store.dispatch(pusherActions.deliverBroadcast({
|
||||
type: 'notification',
|
||||
notification_type: 'info',
|
||||
content: store.getState().pusher.username +' removed '+action.tlids.length+' tracks'
|
||||
}));
|
||||
store.dispatch(pusherActions.deliverBroadcast(
|
||||
'notification',
|
||||
{
|
||||
notification_type: 'info',
|
||||
content: store.getState().pusher.username +' removed '+action.tlids.length+' tracks'
|
||||
}
|
||||
));
|
||||
break;
|
||||
|
||||
case 'MOPIDY_GET_REPEAT':
|
||||
@ -439,7 +448,6 @@ const MopidyMiddleware = (function(){
|
||||
instruct(socket, store, 'playback.getTimePosition')
|
||||
.then(
|
||||
response => {
|
||||
console.log('playback.getTimePosition',response);
|
||||
store.dispatch({
|
||||
type: 'MOPIDY_TIME_POSITION',
|
||||
time_position: response
|
||||
|
||||
@ -60,10 +60,13 @@ export function getVersion(){
|
||||
}
|
||||
}
|
||||
|
||||
export function deliverBroadcast(data = null){
|
||||
export function deliverBroadcast(method, params){
|
||||
return {
|
||||
type: 'PUSHER_DELIVER_BROADCAST',
|
||||
data: data
|
||||
data: {
|
||||
method: method,
|
||||
params: params
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -136,7 +136,10 @@ const PusherMiddleware = (function(){
|
||||
|
||||
socket.onopen = () => {
|
||||
store.dispatch({
|
||||
type: 'PUSHER_CONNECTED'
|
||||
type: 'PUSHER_CONNECTED',
|
||||
connection_id: connection.connection_id,
|
||||
client_id: connection.client_id,
|
||||
username: connection.username
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@ -162,16 +162,27 @@ function refreshToken(dispatch, getState){
|
||||
|
||||
$.ajax(config)
|
||||
.then(
|
||||
response => {
|
||||
var token = response.spotify_token;
|
||||
token.token_expiry = new Date().getTime() + (token.expires_in * 1000 );
|
||||
token.source = 'mopidy';
|
||||
dispatch({
|
||||
type: 'SPOTIFY_TOKEN_REFRESHED',
|
||||
access_token_provider: 'backend',
|
||||
data: token
|
||||
});
|
||||
resolve(token);
|
||||
(response, status, xhr) => {
|
||||
if (response.error){
|
||||
dispatch({ type: 'SPOTIFY_DISCONNECTED' })
|
||||
reject({
|
||||
config: config,
|
||||
xhr: xhr,
|
||||
status: status,
|
||||
error: response.error
|
||||
});
|
||||
|
||||
} else {
|
||||
var token = response.result.spotify_token;
|
||||
token.token_expiry = new Date().getTime() + (token.expires_in * 1000 );
|
||||
token.source = 'mopidy';
|
||||
dispatch({
|
||||
type: 'SPOTIFY_TOKEN_REFRESHED',
|
||||
access_token_provider: 'backend',
|
||||
data: token
|
||||
});
|
||||
resolve(token);
|
||||
}
|
||||
|
||||
},
|
||||
(xhr, status, error) => {
|
||||
|
||||
@ -203,10 +203,11 @@ export function closeNotification(key){
|
||||
}
|
||||
}
|
||||
|
||||
export function removeNotification(key){
|
||||
export function removeNotification(key, manual = false){
|
||||
return {
|
||||
type: 'REMOVE_NOTIFICATION',
|
||||
key: key
|
||||
key: key,
|
||||
manual: manual
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -86,14 +86,6 @@ const UIMiddleware = (function(){
|
||||
case 'CLOSE_NOTIFICATION':
|
||||
var notifications = Object.assign({}, store.getState().ui.notifications);
|
||||
|
||||
// If a broadcast, add to suppressed_broadcasts
|
||||
if (notifications[action.key] && notifications[action.key].type == 'broadcast'){
|
||||
store.dispatch({
|
||||
type: 'SUPPRESS_BROADCAST',
|
||||
key: action.key
|
||||
})
|
||||
}
|
||||
|
||||
// start a timeout to remove this notification
|
||||
// This gives us time to animate out the notification before we remove the data
|
||||
var timeout = setTimeout(
|
||||
@ -106,6 +98,24 @@ const UIMiddleware = (function(){
|
||||
next(action);
|
||||
break;
|
||||
|
||||
case 'REMOVE_NOTIFICATION':
|
||||
|
||||
// Manual removal
|
||||
if (action.manual){
|
||||
var notifications = Object.assign({}, store.getState().ui.notifications);
|
||||
|
||||
// If a broadcast, add to suppressed_broadcasts
|
||||
if (notifications[action.key] && notifications[action.key].type == 'broadcast'){
|
||||
store.dispatch({
|
||||
type: 'SUPPRESS_BROADCAST',
|
||||
key: action.key
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
next(action);
|
||||
break;
|
||||
|
||||
case 'BROADCASTS_LOADED':
|
||||
var suppressed_broadcasts = []
|
||||
if (typeof(store.getState().ui.suppressed_broadcasts) !== 'undefined'){
|
||||
|
||||
Reference in New Issue
Block a user