Moving commands out of Snapcast
This commit is contained in:
@ -240,11 +240,11 @@ const localstorageMiddleware = (function(){
|
||||
);
|
||||
break;
|
||||
|
||||
case 'SNAPCAST_CLIENT_COMMANDS_UPDATED':
|
||||
case 'SNAPCAST_COMMANDS_UPDATED':
|
||||
helpers.setStorage(
|
||||
'snapcast',
|
||||
{
|
||||
client_commands: action.client_commands
|
||||
commands: action.commands
|
||||
}
|
||||
);
|
||||
break;
|
||||
|
||||
@ -192,97 +192,28 @@ export function addQueueMetadata(tlids = [], from_uri = null){
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Snapcast actions
|
||||
* TODO: Figure out how to cleanly split this out to it's own service
|
||||
* but still share the pusher middleware connection
|
||||
* Commands (buttons)
|
||||
**/
|
||||
|
||||
export function getSnapcast(){
|
||||
return {
|
||||
type: 'PUSHER_GET_SNAPCAST',
|
||||
data: {
|
||||
method: 'Server.GetStatus'
|
||||
}
|
||||
}
|
||||
export function setCommand(command){
|
||||
return {
|
||||
type: 'PUSHER_SET_COMMAND',
|
||||
command: command
|
||||
}
|
||||
}
|
||||
|
||||
export function snapcastServerLoaded(server){
|
||||
return {
|
||||
type: 'PUSHER_SNAPCAST_SERVER_LOADED',
|
||||
server: server
|
||||
}
|
||||
}
|
||||
|
||||
export function setSnapcastClientName(id, name){
|
||||
return {
|
||||
type: 'PUSHER_SET_SNAPCAST_CLIENT_NAME',
|
||||
id: id,
|
||||
name: name
|
||||
}
|
||||
}
|
||||
|
||||
export function setSnapcastClientMute(id, mute){
|
||||
return {
|
||||
type: 'PUSHER_SET_SNAPCAST_CLIENT_MUTE',
|
||||
id: id,
|
||||
mute: mute
|
||||
}
|
||||
}
|
||||
|
||||
export function setSnapcastClientVolume(id, percent){
|
||||
return {
|
||||
type: 'PUSHER_SET_SNAPCAST_CLIENT_VOLUME',
|
||||
id: id,
|
||||
percent: percent
|
||||
}
|
||||
}
|
||||
|
||||
export function setSnapcastClientLatency(id, latency){
|
||||
return {
|
||||
type: 'PUSHER_SET_SNAPCAST_CLIENT_LATENCY',
|
||||
id: id,
|
||||
latency: latency
|
||||
}
|
||||
}
|
||||
|
||||
export function setSnapcastClientGroup(id, group_id){
|
||||
return {
|
||||
type: 'PUSHER_SET_SNAPCAST_CLIENT_GROUP',
|
||||
id: id,
|
||||
group_id: group_id
|
||||
}
|
||||
}
|
||||
|
||||
export function deleteSnapcastClient(id){
|
||||
return {
|
||||
type: 'PUSHER_DELETE_SNAPCAST_CLIENT',
|
||||
id: id
|
||||
}
|
||||
}
|
||||
|
||||
export function setSnapcastGroupStream(id, stream_id){
|
||||
return {
|
||||
type: 'PUSHER_SET_SNAPCAST_GROUP_STREAM',
|
||||
id: id,
|
||||
stream_id: stream_id
|
||||
}
|
||||
}
|
||||
|
||||
export function setSnapcastGroupMute(id, mute){
|
||||
return {
|
||||
type: 'PUSHER_SET_SNAPCAST_GROUP_MUTE',
|
||||
id: id,
|
||||
mute: mute
|
||||
}
|
||||
}
|
||||
|
||||
export function setSnapcastGroupVolume(id, percent, old_percent = 0){
|
||||
return {
|
||||
type: 'PUSHER_SET_SNAPCAST_GROUP_VOLUME',
|
||||
id: id,
|
||||
percent: percent,
|
||||
old_percent: old_percent
|
||||
}
|
||||
export function sendCommand(id){
|
||||
return {
|
||||
type: 'PUSHER_SEND_COMMAND',
|
||||
id: id
|
||||
}
|
||||
}
|
||||
|
||||
export function commandsUpdated(commands){
|
||||
return {
|
||||
type: 'PUSHER_COMMANDS_UPDATED',
|
||||
commands: commands
|
||||
}
|
||||
}
|
||||
@ -387,6 +387,51 @@ const PusherMiddleware = (function(){
|
||||
return next(action);
|
||||
break;
|
||||
|
||||
|
||||
/**
|
||||
* Commands
|
||||
**/
|
||||
|
||||
case 'PUSHER_SET_COMMAND':
|
||||
var commands_index = Object.assign({}, store.getState().pusher.commands);
|
||||
|
||||
if (commands_index[action.command.id]){
|
||||
var command = Object.assign({}, commands_index[action.command.id], action.command);
|
||||
} else {
|
||||
var command = action.command;
|
||||
}
|
||||
commands_index[action.command.id] = command;
|
||||
|
||||
store.dispatch(pusherActions.commandsUpdated(commands_index));
|
||||
|
||||
next(action);
|
||||
break
|
||||
|
||||
case 'PUSHER_SEND_COMMAND':
|
||||
var commands_index = Object.assign({}, pusher.commands);
|
||||
|
||||
// Prepare our command
|
||||
// We try and make it cross-origin compatible
|
||||
var command = JSON.parse(commands_index[action.id]);
|
||||
command.crossDomain = true;
|
||||
command.dataType = "jsonp";
|
||||
command.success = function(response){
|
||||
store.dispatch(uiActions.createNotification({type: 'info', content: 'Command sent', description: command.url}));
|
||||
}
|
||||
command.fail = function(xhr, status, error){
|
||||
store.dispatch(uiActions.createNotification({type: 'bad', content: 'Command failed', description: error}));
|
||||
}
|
||||
|
||||
// Actually send the request
|
||||
$.ajax(command);
|
||||
|
||||
break
|
||||
|
||||
|
||||
/**
|
||||
* Radio
|
||||
**/
|
||||
|
||||
case 'PUSHER_GET_RADIO':
|
||||
request(store, 'get_radio')
|
||||
.then(
|
||||
|
||||
@ -54,30 +54,8 @@ export default function reducer(pusher = {}, action){
|
||||
case 'PUSHER_CONFIG':
|
||||
return Object.assign({}, pusher, { config: action.config });
|
||||
|
||||
case 'PUSHER_SNAPCAST':
|
||||
return Object.assign({}, pusher, {
|
||||
snapcast_streams: action.snapcast_streams,
|
||||
snapcast_groups: action.snapcast_groups,
|
||||
snapcast_clients: action.snapcast_clients
|
||||
});
|
||||
|
||||
case 'PUSHER_SNAPCAST_GROUP_UPDATED':
|
||||
var snapcast_groups = Object.assign({}, pusher.snapcast_groups);
|
||||
var group = snapcast_groups[action.key];
|
||||
snapcast_groups[action.key] = Object.assign({}, group, action.group);
|
||||
return Object.assign({}, pusher, { snapcast_groups: snapcast_groups });
|
||||
|
||||
case 'PUSHER_SNAPCAST_CLIENT_UPDATED':
|
||||
var snapcast_clients = Object.assign({}, pusher.snapcast_clients);
|
||||
var client = snapcast_clients[action.key];
|
||||
client.config = Object.assign({}, client.config, action.client.config);
|
||||
snapcast_clients[action.key] = client;
|
||||
return Object.assign({}, pusher, { snapcast_clients: snapcast_clients });
|
||||
|
||||
case 'PUSHER_SNAPCAST_CLIENT_REMOVED':
|
||||
var snapcast_clients = Object.assign({}, pusher.snapcast_clients);
|
||||
delete snapcast_clients[action.key];
|
||||
return Object.assign({}, pusher, { snapcast_clients: snapcast_clients });
|
||||
case 'PUSHER_COMMANDS_UPDATED':
|
||||
return Object.assign({}, pusher, { commands: action.commands });
|
||||
|
||||
default:
|
||||
return pusher
|
||||
|
||||
@ -37,29 +37,6 @@ export function setClientLatency(id, latency){
|
||||
}
|
||||
}
|
||||
|
||||
export function setClientCommand(id, command){
|
||||
return {
|
||||
type: 'SNAPCAST_SET_CLIENT_COMMAND',
|
||||
id: id,
|
||||
command: command
|
||||
}
|
||||
}
|
||||
|
||||
export function sendClientCommand(id, command){
|
||||
return {
|
||||
type: 'SNAPCAST_SEND_CLIENT_COMMAND',
|
||||
id: id,
|
||||
command: command
|
||||
}
|
||||
}
|
||||
|
||||
export function clientCommandsUpdated(client_commands){
|
||||
return {
|
||||
type: 'SNAPCAST_CLIENT_COMMANDS_UPDATED',
|
||||
client_commands: client_commands
|
||||
}
|
||||
}
|
||||
|
||||
export function setClientGroup(id, group_id){
|
||||
return {
|
||||
type: 'SNAPCAST_SET_CLIENT_GROUP',
|
||||
|
||||
@ -228,37 +228,6 @@ const SnapcastMiddleware = (function(){
|
||||
);
|
||||
break
|
||||
|
||||
case 'SNAPCAST_SET_CLIENT_COMMAND':
|
||||
var client_commands_index = Object.assign({}, snapcast.client_commands);
|
||||
|
||||
if (client_commands_index[action.id]){
|
||||
var client_command = Object.assign({}, client_commands_index[action.id], action.command);
|
||||
} else {
|
||||
var client_command = action.command;
|
||||
}
|
||||
client_commands_index[action.id] = client_command;
|
||||
|
||||
store.dispatch(snapcastActions.clientCommandsUpdated(client_commands_index));
|
||||
|
||||
next(action);
|
||||
break
|
||||
|
||||
case 'SNAPCAST_SEND_CLIENT_COMMAND':
|
||||
|
||||
// Prepare our command
|
||||
// We try and make it cross-origin compatible
|
||||
var command = JSON.parse(action.command);
|
||||
command.crossDomain = true;
|
||||
command.dataType = "jsonp";
|
||||
command.success = function(response){
|
||||
store.dispatch(uiActions.createNotification({type: 'info', content: 'Command sent', description: command.url}));
|
||||
}
|
||||
|
||||
// Actually send the request
|
||||
$.ajax(command);
|
||||
|
||||
break
|
||||
|
||||
case 'SNAPCAST_SET_CLIENT_GROUP':
|
||||
|
||||
var group = snapcast.groups[action.group_id];
|
||||
|
||||
@ -6,9 +6,6 @@ export default function reducer(snapcast = {}, action){
|
||||
var server = Object.assign({}, action.server);
|
||||
return Object.assign({}, snapcast, { server: server });
|
||||
|
||||
case 'SNAPCAST_CLIENT_COMMANDS_UPDATED':
|
||||
return Object.assign({}, snapcast, { client_commands: action.client_commands });
|
||||
|
||||
case 'SNAPCAST_CLIENTS_LOADED':
|
||||
if (action.flush){
|
||||
var clients = {};
|
||||
|
||||
Reference in New Issue
Block a user