Client commands stored in localStorage
This commit is contained in:
@ -37,15 +37,29 @@ export function setClientLatency(id, latency){
|
||||
}
|
||||
}
|
||||
|
||||
export function setClientCommand(id, name, command){
|
||||
export function setClientCommand(id, command){
|
||||
return {
|
||||
type: 'SNAPCAST_SET_CLIENT_COMMAND',
|
||||
id: id,
|
||||
name: name,
|
||||
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',
|
||||
|
||||
@ -231,12 +231,37 @@ const SnapcastMiddleware = (function(){
|
||||
break
|
||||
|
||||
case 'SNAPCAST_SET_CLIENT_COMMAND':
|
||||
var client = snapcast.clients[action.id];
|
||||
if (!client.commands){
|
||||
client.commands = {};
|
||||
}
|
||||
client.commands[action.name] = action.command;
|
||||
store.dispatch(snapcastActions.clientLoaded(client));
|
||||
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));
|
||||
break
|
||||
|
||||
case 'SNAPCAST_SEND_CLIENT_COMMAND':
|
||||
store.dispatch(
|
||||
pusherActions.request(
|
||||
'send_broadlink_command',
|
||||
{
|
||||
command: action.command
|
||||
},
|
||||
response => {
|
||||
console.log(response);
|
||||
},
|
||||
error => {
|
||||
store.dispatch(coreActions.handleException(
|
||||
'Could not send command',
|
||||
error,
|
||||
error.message
|
||||
));
|
||||
}
|
||||
)
|
||||
);
|
||||
break
|
||||
|
||||
case 'SNAPCAST_SET_CLIENT_GROUP':
|
||||
|
||||
@ -6,6 +6,19 @@ export default function reducer(snapcast = {}, action){
|
||||
var server = Object.assign({}, action.server);
|
||||
return Object.assign({}, snapcast, { server: server });
|
||||
|
||||
|
||||
case 'SNAPCAST_SET_CLIENT_COMMAND':
|
||||
var client_commands = snapcast.client_commands[action.id];
|
||||
if (!client_commands){
|
||||
client.commands = {};
|
||||
}
|
||||
client_commands[action.name] = action.command;
|
||||
action.client_commands = client_commands;
|
||||
break
|
||||
|
||||
case 'SNAPCAST_CLIENT_COMMANDS_UPDATED':
|
||||
return Object.assign({}, snapcast, { client_commands: action.client_commands });
|
||||
|
||||
case 'SNAPCAST_CLIENTS_LOADED':
|
||||
var clients = Object.assign({}, snapcast.clients);
|
||||
for (var client of action.clients){
|
||||
|
||||
Reference in New Issue
Block a user