config.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. var feed_interval_frequency = 1000;
  2. var mac_re = /^[0-9a-f]{1,2}([\.:-])(?:[0-9a-f]{1,2}\1){4}[0-9a-f]{1,2}$/mi;
  3. // https://stackoverflow.com/questions/14636536/how-to-check-if-a-variable-is-an-integer-in-javascript#14794066
  4. function isInt(value) {
  5. return !isNaN(value) &&
  6. parseInt(Number(value)) == value &&
  7. !isNaN(parseInt(value, 10));
  8. }
  9. function scrollTop()
  10. {
  11. window.scrollTo({
  12. top: 0,
  13. behavior: "smooth"
  14. });
  15. }
  16. function compose_rtsp_block(stype)
  17. {
  18. const formElement = document.querySelector("form");
  19. var fdata = new FormData(formElement);
  20. var stype = (typeof stype !== "undefined") ? stype: "RTSP_HI_RES";
  21. if (fdata.get(stype + "_ENABLED") != "true") {
  22. console.log(stype + " not enabled");
  23. return false;
  24. }
  25. var auth = "";
  26. if (fdata.get('RTSP_AUTH_DISABLE') != "true") {
  27. auth = fdata.get('RTSP_LOGIN') + ':';
  28. if (fdata.get('RTSP_PASSWORD') != '') {
  29. auth += fdata.get('RTSP_PASSWORD');
  30. } else {
  31. auth += document.body.getAttribute('mac');
  32. }
  33. auth += "@";
  34. }
  35. stream = "/unicast";
  36. if ((fdata.get('RTSP_HI_RES_ENABLED') == "true") && (fdata.get('RTSP_LOW_RES_ENABLED') == "true")) {
  37. if (stype == "RTSP_HI_RES") { stream = "/video1_unicast" } else { stream ="/video2_unicast" }
  38. }
  39. var link = "rtsp://" + auth + document.body.getAttribute("ip") + ":" + fdata.get('RTSP_PORT') + stream;
  40. var vb = document.querySelectorAll('[block_name="VIDEOSTREAM"]')[0];
  41. var url_block = document.createElement('DIV');
  42. url_block.innerHTML = 'Stream ' + stype + ' URL: ' + '<a href="' + link + '">' + link + '</a>' ;
  43. vb.appendChild(url_block);
  44. }
  45. window.onload = function()
  46. {
  47. var feed = document.getElementById("current_feed");
  48. function update_image()
  49. {
  50. feed.src = feed.src.split("&")[0] + "&load=" + new Date().getTime();
  51. }
  52. feed_interval = setInterval(update_image, feed_interval_frequency);
  53. compose_rtsp_block('RTSP_HI_RES');
  54. compose_rtsp_block('RTSP_LOW_RES');
  55. document.querySelector('[name="update_config"]').addEventListener('submit',
  56. function(e){
  57. const mac_addrs = document.getElementsByClassName('mac_addr');
  58. for (let i=0; i < mac_addrs.length; i++) {
  59. mac_addrs[i].classList.remove("fail_val");
  60. if (mac_addrs[i].value == "") { continue; }
  61. if (!mac_re.test(mac_addrs[i].value)) {
  62. mac_addrs[i].classList.add("fail_val");
  63. scrollTop();
  64. console.log("failed on mac address test for " + mac_addrs[i].name + " for value " + mac_addrs[i].value);
  65. e.preventDefault();
  66. }
  67. }
  68. const numerics = document.getElementsByClassName('numeric');
  69. for (let i=0; i < numerics.length; i++) {
  70. numerics[i].classList.remove("fail_val");
  71. if (numerics[i].value == "") { continue; }
  72. if (!isInt(numerics[i].value)) {
  73. numerics[i].classList.add("fail_val");
  74. scrollTop();
  75. console.log("failed on integer test for " + numerics[i].name);
  76. e.preventDefault();
  77. }
  78. }
  79. }
  80. );
  81. }