Dynamic action creation from pusher broadcasts
This commit is contained in:
@ -318,7 +318,7 @@ class IrisCore(object):
|
||||
self.send_message(
|
||||
connection_id=connection_id,
|
||||
message={
|
||||
'method': "pusher_connection_added",
|
||||
'method': 'pusher.connectionAdded',
|
||||
'params': {
|
||||
'connection': {
|
||||
'connection_id': connection_id,
|
||||
@ -331,7 +331,7 @@ class IrisCore(object):
|
||||
)
|
||||
|
||||
self.broadcast(data={
|
||||
'method': 'pusher_connection_added',
|
||||
'method': 'pusher.connectionAdded',
|
||||
'params': {
|
||||
'connection': client
|
||||
}
|
||||
@ -343,7 +343,7 @@ class IrisCore(object):
|
||||
client = self.connections[connection_id]['client']
|
||||
del self.connections[connection_id]
|
||||
self.broadcast(data={
|
||||
'method': "pusher_connection_removed",
|
||||
'method': "pusher.connectionRemoved",
|
||||
'params': {
|
||||
'connection': client
|
||||
}
|
||||
@ -359,7 +359,7 @@ class IrisCore(object):
|
||||
if connection_id in self.connections:
|
||||
self.connections[connection_id]['client']['username'] = data['username']
|
||||
self.broadcast(data={
|
||||
'method': "pusher_connection_updated",
|
||||
'method': "pusher.connectionChanged",
|
||||
'params': {
|
||||
'connection': self.connections[connection_id]['client']
|
||||
}
|
||||
@ -571,14 +571,14 @@ class IrisCore(object):
|
||||
if starting:
|
||||
self.core.playback.play()
|
||||
self.broadcast(data={
|
||||
'method': "radio_started",
|
||||
'method': "pusher.radioStarted",
|
||||
'params': {
|
||||
'radio': self.radio
|
||||
}
|
||||
})
|
||||
else:
|
||||
self.broadcast(data={
|
||||
'method': "radio_changed",
|
||||
'method': "pusher.radioChanged",
|
||||
'params': {
|
||||
'radio': self.radio
|
||||
}
|
||||
@ -620,7 +620,7 @@ class IrisCore(object):
|
||||
self.core.playback.stop()
|
||||
|
||||
self.broadcast(data={
|
||||
'method': "radio_stopped",
|
||||
'method': "pusher.radioStopped",
|
||||
'params': {
|
||||
'radio': self.radio
|
||||
}
|
||||
@ -722,7 +722,7 @@ class IrisCore(object):
|
||||
self.queue_metadata['tlid_'+str(tlid)] = item
|
||||
|
||||
self.broadcast(data={
|
||||
'method': 'queue_metadata_changed',
|
||||
'method': 'pusher.queueMetadataChanged',
|
||||
'params': {
|
||||
'queue_metadata': self.queue_metadata
|
||||
}
|
||||
@ -795,7 +795,7 @@ class IrisCore(object):
|
||||
self.spotify_token = token
|
||||
|
||||
self.broadcast(data={
|
||||
'method': 'spotify_token_changed',
|
||||
'method': 'spotify.tokenChanged',
|
||||
'params': {
|
||||
'spotify_token': self.spotify_token
|
||||
}
|
||||
|
||||
@ -15554,6 +15554,9 @@ exports.connect = connect;
|
||||
exports.disconnect = disconnect;
|
||||
exports.startUpgrade = startUpgrade;
|
||||
exports.getConnections = getConnections;
|
||||
exports.connectionAdded = connectionAdded;
|
||||
exports.connectionChanged = connectionChanged;
|
||||
exports.connectionRemoved = connectionRemoved;
|
||||
exports.instruct = instruct;
|
||||
exports.getConfig = getConfig;
|
||||
exports.getVersion = getVersion;
|
||||
@ -15611,6 +15614,27 @@ function getConnections() {
|
||||
};
|
||||
}
|
||||
|
||||
function connectionAdded(connection) {
|
||||
return {
|
||||
type: 'PUSHER_CONNECTION_ADDED',
|
||||
connection: connection
|
||||
};
|
||||
}
|
||||
|
||||
function connectionChanged(connection) {
|
||||
return {
|
||||
type: 'PUSHER_CONNECTION_CHANGED',
|
||||
connection: connection
|
||||
};
|
||||
}
|
||||
|
||||
function connectionRemoved(connection) {
|
||||
return {
|
||||
type: 'PUSHER_CONNECTION_REMOVED',
|
||||
connection: connection
|
||||
};
|
||||
}
|
||||
|
||||
function instruct() {
|
||||
var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
|
||||
|
||||
@ -53087,9 +53111,45 @@ var PusherMiddleware = function () {
|
||||
if (message.error !== undefined) {
|
||||
store.dispatch(coreActions.handleException('Pusher: ' + message.error.message, message));
|
||||
} else {
|
||||
store.dispatch(Object.assign({}, message.params, {
|
||||
type: message.method.toUpperCase()
|
||||
}));
|
||||
|
||||
console.log(message.method);
|
||||
|
||||
// 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]];
|
||||
break;
|
||||
case 'ui':
|
||||
var action = uiActions[method[1]];
|
||||
break;
|
||||
case 'pusher':
|
||||
var action = pusherActions[method[1]];
|
||||
break;
|
||||
case 'lastfm':
|
||||
var action = lastfmActions[method[1]];
|
||||
break;
|
||||
case 'mopidy':
|
||||
var action = mopidyActions[method[1]];
|
||||
break;
|
||||
case 'spotify':
|
||||
var action = spotifyActions[method[1]];
|
||||
break;
|
||||
}
|
||||
|
||||
if (!action) {
|
||||
return;
|
||||
}
|
||||
|
||||
console.log(action);
|
||||
|
||||
if (message.params) {
|
||||
store.dispatch(action(message.params));
|
||||
} else {
|
||||
store.dispatch(action());
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
File diff suppressed because one or more lines are too long
@ -41,6 +41,27 @@ export function getConnections(){
|
||||
}
|
||||
}
|
||||
|
||||
export function connectionAdded(connection){
|
||||
return {
|
||||
type: 'PUSHER_CONNECTION_ADDED',
|
||||
connection: connection
|
||||
}
|
||||
}
|
||||
|
||||
export function connectionChanged(connection){
|
||||
return {
|
||||
type: 'PUSHER_CONNECTION_CHANGED',
|
||||
connection: connection
|
||||
}
|
||||
}
|
||||
|
||||
export function connectionRemoved(connection){
|
||||
return {
|
||||
type: 'PUSHER_CONNECTION_REMOVED',
|
||||
connection: connection
|
||||
}
|
||||
}
|
||||
|
||||
export function instruct(data = null){
|
||||
return {
|
||||
type: 'PUSHER_INSTRUCT',
|
||||
|
||||
@ -58,13 +58,45 @@ const PusherMiddleware = (function(){
|
||||
message
|
||||
));
|
||||
} else {
|
||||
store.dispatch(Object.assign(
|
||||
{},
|
||||
message.params,
|
||||
{
|
||||
type: message.method.toUpperCase()
|
||||
}
|
||||
));
|
||||
|
||||
console.log(message.method);
|
||||
|
||||
// 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]];
|
||||
break;
|
||||
case 'ui':
|
||||
var action = uiActions[method[1]];
|
||||
break;
|
||||
case 'pusher':
|
||||
var action = pusherActions[method[1]];
|
||||
break;
|
||||
case 'lastfm':
|
||||
var action = lastfmActions[method[1]];
|
||||
break;
|
||||
case 'mopidy':
|
||||
var action = mopidyActions[method[1]];
|
||||
break;
|
||||
case 'spotify':
|
||||
var action = spotifyActions[method[1]];
|
||||
break;
|
||||
}
|
||||
|
||||
if (!action){
|
||||
return;
|
||||
}
|
||||
|
||||
console.log(action);
|
||||
|
||||
if (message.params){
|
||||
store.dispatch(action(message.params));
|
||||
} else {
|
||||
store.dispatch(action());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user