Simplifying broadcasts (removing silly action namespacing)

This commit is contained in:
James Barnsley
2018-03-21 08:45:22 +13:00
parent 4b5c8a4420
commit 1761456e76
10 changed files with 1966 additions and 1022 deletions

View File

@ -370,7 +370,7 @@ class IrisCore(object):
self.send_message(data={
'recipient': connection_id,
'method': 'pusher.connectionAdded',
'method': 'connection_added',
'params': {
'connection': {
'connection_id': connection_id,
@ -382,7 +382,7 @@ class IrisCore(object):
})
self.broadcast(data={
'method': 'pusher.connectionAdded',
'method': 'connection_added',
'params': {
'connection': client
}
@ -394,7 +394,7 @@ class IrisCore(object):
client = self.connections[connection_id]['client']
del self.connections[connection_id]
self.broadcast(data={
'method': "pusher.connectionRemoved",
'method': "connection_removed",
'params': {
'connection': client
}
@ -410,7 +410,7 @@ class IrisCore(object):
if connection_id in self.connections:
self.connections[connection_id]['client']['username'] = data['username']
self.broadcast(data={
'method': "pusher.connectionChanged",
'method': "connection_changed",
'params': {
'connection': self.connections[connection_id]['client']
}
@ -593,14 +593,14 @@ class IrisCore(object):
if starting:
self.core.playback.play()
self.broadcast(data={
'method': "pusher.radioStarted",
'method': "radio_started",
'params': {
'radio': self.radio
}
})
else:
self.broadcast(data={
'method': "pusher.radioChanged",
'method': "radio_changed",
'params': {
'radio': self.radio
}
@ -642,7 +642,7 @@ class IrisCore(object):
self.core.playback.stop()
self.broadcast(data={
'method': "pusher.radioStopped",
'method': "radio_stopped",
'params': {
'radio': self.radio
}
@ -744,7 +744,7 @@ class IrisCore(object):
self.queue_metadata['tlid_'+str(tlid)] = item
self.broadcast(data={
'method': 'pusher.queueMetadataChanged',
'method': 'queue_metadata_changed',
'params': {
'queue_metadata': self.queue_metadata
}
@ -817,7 +817,7 @@ class IrisCore(object):
self.spotify_token = token
self.broadcast(data={
'method': 'spotify.tokenChanged',
'method': 'spotify_token_changed',
'params': {
'spotify_token': self.spotify_token
}

View File

@ -3447,8 +3447,11 @@ input[type="submit"] {
font-weight: 300;
color: inherit;
border-bottom: 1px solid #454440 !important; }
#context-menu .liner > span button .icon,
#context-menu .liner > span button .fa,
#context-menu .liner > span .button .icon,
#context-menu .liner > span .button .fa,
#context-menu .liner > span .dropdown-field .icon,
#context-menu .liner > span .dropdown-field .fa {
display: none; }
.notouch #context-menu .liner > span button:hover, .notouch

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

View File

@ -22,6 +22,7 @@ export default class extends React.Component{
}
render(){
console.log(this.props.data)
if (!this.props.data || !this.props.data.user || !this.props.data.authorization){
return null
}

View File

@ -19,10 +19,10 @@ class AuthorizationModal_Send extends React.Component{
e.preventDefault()
this.props.pusherActions.deliverMessage(
connection_id,
'spotify.authorizationReceived',
'spotify_authorization_received',
{
authorization: this.props.authorization,
me: this.props.me
user: this.props.me
}
);
this.props.uiActions.closeModal()

View File

@ -262,11 +262,13 @@ const MopidyMiddleware = (function(){
);
store.dispatch(pusherActions.deliverBroadcast(
'ui.createNotification',
'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)
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;
@ -283,7 +285,7 @@ const MopidyMiddleware = (function(){
);
store.dispatch(pusherActions.deliverBroadcast(
'ui.createNotification',
'notification',
{
type: 'info',
content: store.getState().pusher.username +' paused playback',
@ -296,11 +298,13 @@ const MopidyMiddleware = (function(){
instruct(socket, store, 'playback.next');
store.dispatch(pusherActions.deliverBroadcast(
'ui.createNotification',
'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)
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
@ -309,11 +313,13 @@ const MopidyMiddleware = (function(){
instruct(socket, store, 'playback.stop');
store.dispatch(pusherActions.deliverBroadcast(
'ui.createNotification',
'notification',
{
type: 'info',
content: store.getState().pusher.username +' stopped playback',
icon: (store.getState().core.current_track ? helpers.getTrackIcon(store.getState().core.current_track, store.getState().core) : false)
notification: {
type: 'info',
content: store.getState().pusher.username +' stopped playback',
icon: (store.getState().core.current_track ? helpers.getTrackIcon(store.getState().core.current_track, store.getState().core) : false)
}
}
));
break
@ -322,10 +328,12 @@ const MopidyMiddleware = (function(){
instruct(socket, store, 'playback.play', {tlid: action.tlid});
store.dispatch(pusherActions.deliverBroadcast(
'ui.createNotification',
'notification',
{
type: 'info',
content: store.getState().pusher.username +' changed track'
notification: {
type: 'info',
content: store.getState().pusher.username +' changed track'
}
}
));
break;
@ -333,10 +341,12 @@ const MopidyMiddleware = (function(){
case 'MOPIDY_REMOVE_TRACKS':
instruct(socket, store, 'tracklist.remove', {tlid: action.tlids});
store.dispatch(pusherActions.deliverBroadcast(
'ui.createNotification',
'notification',
{
type: 'info',
content: store.getState().pusher.username +' removed '+action.tlids.length+' tracks'
notification: {
type: 'info',
content: store.getState().pusher.username +' removed '+action.tlids.length+' tracks'
}
}
));
break;
@ -404,10 +414,12 @@ const MopidyMiddleware = (function(){
case 'MOPIDY_SET_MUTE':
instruct(socket, store, 'mixer.setMute', [action.mute]);
store.dispatch(pusherActions.deliverBroadcast(
'ui.createNotification',
'notification',
{
type: 'info',
content: store.getState().pusher.username +(action.mute ? ' muted' : ' unmuted')+' playback'
notification: {
type: 'info',
content: store.getState().pusher.username +(action.mute ? ' muted' : ' unmuted')+' playback'
}
}
));
break;
@ -559,11 +571,13 @@ const MopidyMiddleware = (function(){
}
store.dispatch(pusherActions.deliverBroadcast(
'ui.createNotification',
'notification',
{
type: 'info',
content: store.getState().pusher.username +' is adding '+action.uris.length+' URIs to queue',
icon: (store.getState().core.current_track ? helpers.getTrackIcon(store.getState().core.current_track, store.getState().core) : false)
notification: {
type: 'info',
content: store.getState().pusher.username +' is adding '+action.uris.length+' URIs to queue',
icon: (store.getState().core.current_track ? helpers.getTrackIcon(store.getState().core.current_track, store.getState().core) : false)
}
}
));

View File

@ -44,21 +44,21 @@ export function getConnections(){
export function connectionAdded(connection){
return {
type: 'PUSHER_CONNECTION_ADDED',
connection: connection.connection
connection: connection
}
}
export function connectionChanged(connection){
return {
type: 'PUSHER_CONNECTION_CHANGED',
connection: connection.connection
connection: connection
}
}
export function connectionRemoved(connection){
return {
type: 'PUSHER_CONNECTION_REMOVED',
connection: connection.connection
connection: connection
}
}
@ -144,7 +144,7 @@ export function getQueueMetadata(){
export function queueMetadataChanged(queue_metadata){
return {
type: 'PUSHER_QUEUE_METADATA_CHANGED',
queue_metadata: queue_metadata.queue_metadata
queue_metadata: queue_metadata
}
}

View File

@ -59,39 +59,28 @@ const PusherMiddleware = (function(){
));
} else {
// Split our method into our action creator reference (eg pusherActions.createNotification(params))
var method = message.method.split('.');
var actions_library = method[0]+'Actions';
switch (method[0]){
case 'core':
var action = coreActions[method[1]];
switch (message.method){
case 'connection_added':
store.dispatch(pusherActions.connectionAdded(message.params.connection));
break;
case 'ui':
var action = uiActions[method[1]];
case 'connection_changed':
store.dispatch(pusherActions.connectionChanged(message.params.connection));
break;
case 'pusher':
var action = pusherActions[method[1]];
case 'connection_removed':
store.dispatch(pusherActions.connectionRemoved(message.params.connection));
break;
case 'lastfm':
var action = lastfmActions[method[1]];
case 'queue_metadata_changed':
store.dispatch(pusherActions.queueMetadataChanged(message.params.queue_metadata));
break;
case 'mopidy':
var action = mopidyActions[method[1]];
case 'spotify_token_changed':
store.dispatch(spotifyActions.tokenChanged(message.params.spotify_token));
break;
case 'spotify':
var action = spotifyActions[method[1]];
case 'spotify_authorization_received':
store.dispatch(uiActions.openModal('receive_authorization', message.params));
break;
case 'notification':
store.dispatch(uiActions.createNotification(message.params.notification));
break;
}
if (!action){
return;
}
if (message.params){
store.dispatch(action(message.params));
} else {
store.dispatch(action());
}
}
}

View File

@ -167,6 +167,7 @@
color: inherit;
border-bottom: 1px solid lighten($grey, 5%) !important;
.icon,
.fa {
display: none;
}