No need for serverside broadlink API - use ajax config; Power button style
This commit is contained in:
@ -119,29 +119,32 @@ export function serverLoaded(server){
|
||||
export function clientLoaded(client){
|
||||
return clientsLoaded([client]);
|
||||
}
|
||||
export function clientsLoaded(clients){
|
||||
export function clientsLoaded(clients, flush = false){
|
||||
return {
|
||||
type: 'SNAPCAST_CLIENTS_LOADED',
|
||||
clients: clients
|
||||
clients: clients,
|
||||
flush: flush
|
||||
}
|
||||
}
|
||||
|
||||
export function groupLoaded(group){
|
||||
return groupsLoaded([group]);
|
||||
}
|
||||
export function groupsLoaded(groups){
|
||||
export function groupsLoaded(groups, flush = false){
|
||||
return {
|
||||
type: 'SNAPCAST_GROUPS_LOADED',
|
||||
groups: groups
|
||||
groups: groups,
|
||||
flush: flush
|
||||
}
|
||||
}
|
||||
|
||||
export function streamLoaded(stream){
|
||||
return streamsLoaded([stream]);
|
||||
}
|
||||
export function streamsLoaded(streams){
|
||||
export function streamsLoaded(streams, flush = false){
|
||||
return {
|
||||
type: 'SNAPCAST_STREAMS_LOADED',
|
||||
streams: streams
|
||||
streams: streams,
|
||||
flush: flush
|
||||
}
|
||||
}
|
||||
@ -47,8 +47,8 @@ const SnapcastMiddleware = (function(){
|
||||
break
|
||||
|
||||
case 'SNAPCAST_SERVER_LOADED':
|
||||
store.dispatch(snapcastActions.groupsLoaded(action.server.groups));
|
||||
store.dispatch(snapcastActions.streamsLoaded(action.server.streams));
|
||||
store.dispatch(snapcastActions.groupsLoaded(action.server.groups, true));
|
||||
store.dispatch(snapcastActions.streamsLoaded(action.server.streams, true));
|
||||
|
||||
// Snapcast double-nests the server object
|
||||
action.server = action.server.server;
|
||||
@ -244,24 +244,21 @@ const SnapcastMiddleware = (function(){
|
||||
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
|
||||
));
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
// Prepare our command
|
||||
// We try and make it cross-origin compatible
|
||||
var command = JSON.parse(action.command);
|
||||
command.crossDomain = true;
|
||||
|
||||
$.ajax(command)
|
||||
.then(
|
||||
response => {
|
||||
console.log(response);
|
||||
},
|
||||
(xhr, status, error) => {
|
||||
console.error(error);
|
||||
}
|
||||
);
|
||||
break
|
||||
|
||||
case 'SNAPCAST_SET_CLIENT_GROUP':
|
||||
|
||||
@ -5,36 +5,51 @@ export default function reducer(snapcast = {}, action){
|
||||
case 'SNAPCAST_SERVER_LOADED':
|
||||
var server = Object.assign({}, action.server);
|
||||
return Object.assign({}, snapcast, { server: server });
|
||||
break;
|
||||
|
||||
|
||||
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_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);
|
||||
if (action.flush){
|
||||
var clients = {};
|
||||
} else {
|
||||
var clients = Object.assign({}, snapcast.clients);
|
||||
}
|
||||
|
||||
for (var client of action.clients){
|
||||
clients[client.id] = client;
|
||||
}
|
||||
return Object.assign({}, snapcast, { clients: clients });
|
||||
|
||||
case 'SNAPCAST_GROUPS_LOADED':
|
||||
var groups = Object.assign({}, snapcast.groups);
|
||||
if (action.flush){
|
||||
var groups = {};
|
||||
} else {
|
||||
var groups = Object.assign({}, snapcast.groups);
|
||||
}
|
||||
|
||||
for (var group of action.groups){
|
||||
groups[group.id] = group;
|
||||
}
|
||||
return Object.assign({}, snapcast, { groups: groups });
|
||||
|
||||
case 'SNAPCAST_STREAMS_LOADED':
|
||||
var streams = Object.assign({}, snapcast.streams);
|
||||
if (action.flush){
|
||||
var streams = {};
|
||||
} else {
|
||||
var streams = Object.assign({}, snapcast.streams);
|
||||
}
|
||||
|
||||
for (var stream of action.streams){
|
||||
streams[stream.id] = stream;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user