דברים שרואים מכאן לא רואים בכלל
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

neo.html 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <!doctype html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1">
  6. <title>Bystander</title>
  7. <link href="/static/bootstrap/css/bootstrap.min.css" rel="stylesheet">
  8. <link rel="icon" href="/static/gfx/eye-horus.png">
  9. </head>
  10. <body data-bs-theme="dark">
  11. <div class="select" style="position:absolute; top:0;right:0; z-index:23">
  12. <label for="videoSource">Video source: </label><select id="videoSource"></select>
  13. </div>
  14. <div class="container-fluid text-center">
  15. <div class="row" style="background-image:url(/static/gfx/vest-funeral.jpg); backgroud-color:red; background-size:cover">
  16. <div class="col12" id="the-reporter" style="background-image:url(/static/gfx/anas-al-sharif.jpg); backgroud-color:red; background-size:cover">
  17. <video class="w-100" id="the-video" autoplay muted playsinline></video>
  18. </video>
  19. </div>
  20. </div>
  21. </div>
  22. <script src="/static/js/config.js"></script>
  23. <script src="/static/js/jquery-3.7.1.min.js"></script>
  24. <script src="/static/bootstrap/js/bootstrap.bundle.min.js"></script>
  25. <script>
  26. 'use strict';
  27. var videoElement = document.querySelector('video');
  28. var videoSelect = document.querySelector('select#videoSource');
  29. videoSelect.onchange = getStream;
  30. getStream().then(getDevices).then(gotDevices);
  31. function getDevices() {
  32. // AFAICT in Safari this only gets default devices until gUM is called :/
  33. return navigator.mediaDevices.enumerateDevices();
  34. }
  35. function gotDevices(deviceInfos) {
  36. window.deviceInfos = deviceInfos; // make available to console
  37. console.log('Available input and output devices:', deviceInfos);
  38. for (const deviceInfo of deviceInfos) {
  39. const option = document.createElement('option');
  40. option.value = deviceInfo.deviceId;
  41. if (deviceInfo.kind === 'videoinput') {
  42. option.text = deviceInfo.label || `Camera ${videoSelect.length + 1}`;
  43. videoSelect.appendChild(option);
  44. }
  45. }
  46. }
  47. function getStream() {
  48. if (window.stream) {
  49. window.stream.getTracks().forEach(track => {
  50. track.stop();
  51. });
  52. }
  53. const videoSource = videoSelect.value;
  54. const constraints = {
  55. video: {deviceId: videoSource ? {exact: videoSource} : undefined}
  56. };
  57. return navigator.mediaDevices.getUserMedia(constraints).
  58. then(gotStream).catch(handleError);
  59. }
  60. function gotStream(stream) {
  61. window.stream = stream; // make stream available to console
  62. videoSelect.selectedIndex = [...videoSelect.options].
  63. findIndex(option => option.text === stream.getVideoTracks()[0].label);
  64. videoElement.srcObject = stream;
  65. }
  66. function handleError(error) {
  67. console.error('Error: ', error);
  68. }
  69. </script>
  70. <script>
  71. async function getDistance() {
  72. try {
  73. let response = await fetch("/d");
  74. let data = await response.json();
  75. return data.distance;
  76. } catch {
  77. return 0;
  78. }
  79. };
  80. async function updateDistance() {
  81. var dist = await getDistance();
  82. if (dist>NEO_FAR) {
  83. dist = NEO_FAR;
  84. }
  85. if (dist>NEO_MID) {
  86. var vidtransp = 1.0*(dist-NEO_MID)/(NEO_FAR-NEO_MID);
  87. $("#the-video").css("opacity",vidtransp);
  88. $("#the-reporter").css("opacity",1);
  89. } else {
  90. var reptransp = 1.0*(dist-NEO_NEAR)/(NEO_MID-NEO_NEAR);
  91. $("#the-video").css("opacity",0);
  92. $("#the-reporter").css("opacity",reptransp);
  93. }
  94. }
  95. window.update_interval = setInterval(updateDistance, 200);
  96. </script>
  97. </body>
  98. </html>