Update from initial post.
After letting other people use the remote – I realized that – well, they don’t think like me. So I needed to add a functionality to send single commands to devices – in case someone decided to bypass the server and change the power state of a device.
function showTools(){ $("#main").load("src/html/tools.html", function () { $('.panel-collapse').on('show.bs.collapse', function () { $(this).siblings('.panel-heading').addClass('active'); }); $('.panel-collapse').on('hide.bs.collapse', function () { $(this).siblings('.panel-heading').removeClass('active'); }); if( $(".button-power").is(":visible")) $(".button-power").toggle(); $(".indicator").prop('disabled', true); $(".button-tool-back").toggle() .off("click").click(function(evt){ location.reload(); }); $.each(arrCommands, function(index, val) { $.each(arrCommands[index], function(i, val) { $("." + index + "-tools").append( $("<button class="btn btn-light btn-lg btn-block" data-cmd="" + val[1] + "">" + val[0] + "</button>") .off("click").click(function(evt){ fireCommand(index, val[1]); }) ); }); }); }) }
"commands": { "Receiver": [ ["Power Toggle", "KEY_POWER"], ["Input - CBL", "KEY_CBL"], ["Input - XBOX", "KEY_XBOX"], ["Input - Switch", "KEY_GAME"], ["Input - Bluetooth", "KEY_BLUE"] ], "Cox": [ ["Power On", "KEY_CONTOUR"] ], "Xbox": [ ["Power On", "PowerOn"], ["Power Off", "PowerOff"] ] }