UNPKG

htd-lync

Version:

This library is meant to be used to interact with an HTD Lync 12

412 lines (358 loc) 11.7 kB
function updateButtons(zoneNumber) { //console.log("updateButtons", zoneNumber); if (systems[systemIdx].zones[zoneNumber].powerOn == true) { //$('#powerBtn').addClass("active"); $("#powerBtn").attr("src", "images/power-off.png"); } else { //$('#powerBtn').removeClass("active"); $("#powerBtn").attr("src", "images/power-off-norm.png"); } if (systems[systemIdx].zones[zoneNumber].muteOn == true) { $('#muteBtn').addClass("active"); } else { $('#muteBtn').removeClass("active"); } if (systems[systemIdx].zones[zoneNumber].dndOn == true) { $('#dndBtn').addClass("active"); } else { $('#dndBtn').removeClass("active"); } $(".groupLink").on("click", function() { goToGroupControlPage(systems[systemIdx].system.defaultGroup); }); } function makeVolumeDropDownIndZone(zone, volume) { if (systems[systemIdx].zones[zone].dndOn == true) { alert("Zone is in DND"); return; } console.log("makeVolumeDropDown 34") var list = []; var obj = new Object(); for (var i = 1; i <= 60; i++) { var obj = new Object(); obj.text = i + ""; obj.value = i + ""; list.push(obj); } //console.log(list); var config = { title: "Select Volume", items: list, selectedValue: systems[systemIdx].zones[zone].vol + "", doneButtonLabel: "Select", cancelButtonLabel: "Cancel" }; // Show the picker window.plugins.listpicker.showPicker(config, function(volume) { if (volume == 0) { systems[systemIdx].zones[zone].muteOn = true; zoneMuteOn(zone); } else { //zones[zone].muteOn = false; setVolumeForZone(zone, volume); zonePowerOn(zone); } }, function() { //alert("You have cancelled"); } ); } function makeZoneDropDown(zone) { console.log("makeZoneDropDown:" + zone); var list = []; for (var i = 1; i <= systems[systemIdx].zones.length; i++) { if (systems[systemIdx].zones[i] && systems[systemIdx].zones[i].name) { var obj = new Object(); obj.text = systems[systemIdx].zones[i].appName; obj.value = i + ""; list.push(obj); } } //console.log(list); var config = { title: "Select a Zone", items: list, selectedValue: zone + "", doneButtonLabel: "Select", cancelButtonLabel: "Cancel" }; // Show the picker window.plugins.listpicker.showPicker(config, function(item) { goToMusicPage(item); }, function() { //alert("You have cancelled"); } ); } function makePageHeader(zone) { console.log("makePageHeader") var html = ''; html += '<h2 id="changeZone">' + systems[systemIdx].zones[zone].appName + '<img class="downArrow" src="images/arrowDown.png"></h2>' var exisitingHtml = $('#pageName').html(); if (exisitingHtml != html) { console.log("replace") $('#pageName').html(html); $('#changeZone').on('click', function() { var zone = ($(this).attr('zone')) makeZoneDropDown(zone); //createVolumeBar(); }); } } function makeSourceHeaderZonePage(zone) { console.log("makeSourceHeaderZonePage") //console.log("Zone: " + zone); //console.log("Source:" + systems[systemIdx].zones[zone].source) var html = ''; if (systems[systemIdx].sources[systems[systemIdx].zones[zone].source]) { html += '<h2 id="changeSource">' + systems[systemIdx].sources[systems[systemIdx].zones[zone].source].appName + '<img class="downArrow" src="images/arrowDown.png"></h2>' } else { html += '<h2 id="changeSource">Source ' + systems[systemIdx].zones[zone].source + '<img class="downArrow" src="images/arrowDown.png"></h2>' } var exisitingHtml = $('#sourceList').html(); if (exisitingHtml != html) { // console.log("replace") $('#sourceList').html(html); $('#changeSource').on('click', function() { makeSourceDropDown(zone); }); } } function makeSourceDropDown(zone) { //console.log(zone); var list = []; for (var i = 1; i <= systems[systemIdx].sources.length; i++) { if (systems[systemIdx].sources[i] && systems[systemIdx].sources[i].name) { var obj = new Object(); obj.text = systems[systemIdx].sources[i].appName; obj.value = i + ""; list.push(obj); } } //console.log(list); var config = { title: "Select a Source", items: list, selectedValue: systems[systemIdx].zones[zone].source + "", doneButtonLabel: "Select", cancelButtonLabel: "Cancel" }; // Show the picker window.plugins.listpicker.showPicker(config, function(source) { setSourceForZone(zone, source); systems[systemIdx].zones[zone].source = source; goToMusicPage(zone); }, function() { //alert("You have cancelled"); } ); } var volumeBarCreated = false; var lastVolume = 0; function createVolumeBar(zoneNumber) { if (!systems[systemIdx].zones || systems[systemIdx].zones.length == 0) { //console.log("no zones!") return; } //see if it already exists var volumeSlider = document.getElementById('volumeBarBlue'); //console.log(volumeSlider) if (volumeBarCreated) { //console.log("updating bar instead") updateVolumeBar(); return; } console.log('createVolumeBar') var html = '<div id="slidecontainer">'; html += '<div class="vol-icon" id="volIcon"><img id="volIconImg" src="images/vol3.png"></div>'; html += '<div class="vol-bar"><div class="player" id="volumeBarBlue"></div>'; html += '<div class="vol-value"><span id="volNumber">' + systems[systemIdx].zones[zoneNumber].vol * 1 + '</span></div>'; $('#volumeBar').html(html); $("#volNumber").on("click", function() { if (systems[systemIdx].zones[Gzone].dndOn == true) { alert("Take zone off DND first.") } else { makeVolumeDropDownIndZone(Gzone, systems[systemIdx].zones[Gzone].volume) } }); var orientation = screen.orientation.type; console.log("orientation: " + orientation) if (orientation.indexOf("portrait") >= 0) { orientation = "portrait" } else { orientation = "landscape"; } console.log("screen width:" + screen.width, orientation) if (screen.width <= 320) { console.log("volume width 320") $(".player").css("width", 180); } else if (screen.width <= 375) { console.log("volume width 230") $(".player").css("width", 230); } else if (screen.width <= 450 && orientation == "portrait") { console.log("volume width " + 270) $(".player").css("width", 270); } else if (screen.width <= 768 && orientation == "portrait") { console.log("volume width " + 6350) $(".player").css("width", 630); } else if (screen.width <= 840 && orientation == "portrait") { console.log("volume width " + 800) //this is for andoird tablets in portrait. $(".player").css("width", 630); } else { console.log("volume width 860") $(".player").css("width", 860); } var slider = document.getElementById("zoneVolumeBar"); //var output = document.getElementById("volNumber"); if (!systems[systemIdx].zones[zoneNumber]) { return; } var volumeSlider = document.getElementById('volumeBarBlue'); noUiSlider.create(volumeSlider, { start: [systems[systemIdx].zones[zoneNumber].vol * 1], step: 1, connect: [true, false], range: { 'min': 1, 'max': 60 } }); volumeBarCreated = true; volumeSlider.noUiSlider.on('slide', function() { //console.log(volumeSlider.noUiSlider.get()); var level = volumeSlider.noUiSlider.get(); level = level.replace('.00', ""); $('#volNumber').text(level); if (lastVolume != level) { lastVolume = level; systems[systemIdx].zones[Gzone].vol = level; //if (zones[Gzone].muteOn == false && zones[Gzone].powerOn == true) { if (level == 60) { setVolumeForZone(Gzone, level); } else { zoneSetVolume(Gzone); } //} } if (level == "0" || level == 0) { $('#volIconImg').attr("src", "images/mute.png") } else { $('#volIconImg').attr("src", "images/vol3.png") } }); volumeSlider.noUiSlider.on('click', function() { //console.log(volumeSlider.noUiSlider.get()); var level = volumeSlider.noUiSlider.get(); level = level.replace('.00', ""); $('#volNumber').text(level); lastVolume = level; systems[systemIdx].zones[Gzone].vol = level; //if (zones[Gzone].muteOn == false && zones[Gzone].powerOn == true) { zoneSetVolume(Gzone); updateCommand(Gzone); if (level == "0" || level == 0) { $('#volIconImg').attr("src", "images/mute.png") } else { $('#volIconImg').attr("src", "images/vol3.png") } }); volumeSlider.noUiSlider.on('start', function() { sliding = true; console.log("start sliding"); //zonePowerOn(Gzone); }); volumeSlider.noUiSlider.on('end', function() { sliding = false; console.log("end sliding") setTimeout(function() { //Added this back in 7/15/19 to fix mix to volume slide. updateCommand(Gzone); }, 500); }); $("#volIcon").on("click", function() { console.log("volIcon", systems[systemIdx].zones[Gzone].muteOn) //return; if (systems[systemIdx].zones[Gzone].muteOn == true) { systems[systemIdx].zones[Gzone].muteOn = false; $('#volIconImg').attr("src", "images/vol3.png") zoneMuteOff(); } else { systems[systemIdx].zones[Gzone].muteOn = true; $('#volIconImg').attr("src", "images/mute.png") zoneMuteOn(Gzone); } }); volumeSlider.noUiSlider.on('change', function() { var level = volumeSlider.noUiSlider.get(); level = level.replace('.00', ""); $('#volNumber').text(level); systems[systemIdx].zones[Gzone].vol = level; zoneSetVolume(Gzone); }); } function updateVolumeBar() { //console.log("update volume bar", zones[Gzone].vol) if (systems[systemIdx].zones[Gzone].muteOn == true) { $('#volIconImg').attr("src", "images/mute.png") } else { $('#volIconImg').attr("src", "images/vol3.png") } var volumeSlider = document.getElementById('volumeBarBlue'); //console.log(volumeSlider) if (volumeBarCreated) { if (sliding == false) { // console.log("UPDATE volume bar"); volumeSlider.noUiSlider.set(systems[systemIdx].zones[Gzone].vol); } else { console.log("sliding, dont update volume"); } $('#zoneVolumeBar').val(systems[systemIdx].zones[Gzone].vol); //$(".player").css("width", zones[Gzone].vol * 5); $('#volNumber').text(systems[systemIdx].zones[Gzone].vol); if (systems[systemIdx].zones[Gzone].muteOn == true) { $('#zoneVolumeBar').val(0); //$(".player").css("width", zones[Gzone].vol * 5); $('#volNumber').text("mute"); $('#volNumber').addClass("mute"); } else { $('#volNumber').removeClass("mute"); } } else { createVolumeBar(Gzone); } } $("#powerBtn").on("click", function() { if (systems[systemIdx].zones[Gzone].powerOn == true) { systems[systemIdx].zones[Gzone].powerOn = false; zonePowerOff(Gzone); //$('#powerBtn').removeClass("active"); $("#powerBtn").attr("src", "images/power-off-norm.png"); } else { systems[systemIdx].zones[Gzone].powerOn = true; zonePowerOn(Gzone); //$('#powerBtn').addClass("active"); $("#powerBtn").attr("src", "images/power-off.png"); } }); $("#settingsBtn").on("click", function() { goToZoneSettingsPage(); }); $("#dndBtn").on("click", function() { if (systems[systemIdx].zones[Gzone].dndOn == true) { systems[systemIdx].zones[Gzone].dndOn = false; zoneDNDOff(Gzone); $('#dndBtn').removeClass("active"); } else { systems[systemIdx].zones[Gzone].dndOn = true; zoneDNDOn(Gzone); $('#dndBtn').addClass("active"); } });