| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- var feed_interval_frequency = 1000;
- var mac_re = /^[0-9a-f]{1,2}([\.:-])(?:[0-9a-f]{1,2}\1){4}[0-9a-f]{1,2}$/mi;
- // https://stackoverflow.com/questions/14636536/how-to-check-if-a-variable-is-an-integer-in-javascript#14794066
- function isInt(value) {
- return !isNaN(value) &&
- parseInt(Number(value)) == value &&
- !isNaN(parseInt(value, 10));
- }
- function scrollTop()
- {
- window.scrollTo({
- top: 0,
- behavior: "smooth"
- });
- }
- function compose_rtsp_block(stype)
- {
- const formElement = document.querySelector("form");
- var fdata = new FormData(formElement);
- var stype = (typeof stype !== "undefined") ? stype: "RTSP_HI_RES";
- if (fdata.get(stype + "_ENABLED") != "true") {
- console.log(stype + " not enabled");
- return false;
- }
-
- var auth = "";
- if (fdata.get('RTSP_AUTH_DISABLE') != "true") {
- auth = fdata.get('RTSP_LOGIN') + ':';
- if (fdata.get('RTSP_PASSWORD') != '') {
- auth += fdata.get('RTSP_PASSWORD');
- } else {
- auth += document.body.getAttribute('mac');
- }
- auth += "@";
- }
-
- stream = "/unicast";
- if ((fdata.get('RTSP_HI_RES_ENABLED') == "true") && (fdata.get('RTSP_LOW_RES_ENABLED') == "true")) {
- if (stype == "RTSP_HI_RES") { stream = "/video1_unicast" } else { stream ="/video2_unicast" }
- }
- var link = "rtsp://" + auth + document.body.getAttribute("ip") + ":" + fdata.get('RTSP_PORT') + stream;
- var vb = document.querySelectorAll('[block_name="VIDEOSTREAM"]')[0];
- var url_block = document.createElement('DIV');
- url_block.innerHTML = 'Stream ' + stype + ' URL: ' + '<a href="' + link + '">' + link + '</a>' ;
- vb.appendChild(url_block);
- }
- window.onload = function()
- {
- var feed = document.getElementById("current_feed");
- function update_image()
- {
- feed.src = feed.src.split("&")[0] + "&load=" + new Date().getTime();
- }
- feed_interval = setInterval(update_image, feed_interval_frequency);
-
- compose_rtsp_block('RTSP_HI_RES');
- compose_rtsp_block('RTSP_LOW_RES');
- document.querySelector('[name="update_config"]').addEventListener('submit',
- function(e){
- const mac_addrs = document.getElementsByClassName('mac_addr');
- for (let i=0; i < mac_addrs.length; i++) {
- mac_addrs[i].classList.remove("fail_val");
- if (mac_addrs[i].value == "") { continue; }
- if (!mac_re.test(mac_addrs[i].value)) {
- mac_addrs[i].classList.add("fail_val");
- scrollTop();
- console.log("failed on mac address test for " + mac_addrs[i].name + " for value " + mac_addrs[i].value);
- e.preventDefault();
- }
- }
- const numerics = document.getElementsByClassName('numeric');
- for (let i=0; i < numerics.length; i++) {
- numerics[i].classList.remove("fail_val");
- if (numerics[i].value == "") { continue; }
- if (!isInt(numerics[i].value)) {
- numerics[i].classList.add("fail_val");
- scrollTop();
- console.log("failed on integer test for " + numerics[i].name);
- e.preventDefault();
- }
- }
- }
- );
- }
|