|
@@ -0,0 +1,109 @@
|
|
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
|
+
|
|
27
|
+ 'use strict';
|
|
28
|
+
|
|
29
|
+ var videoElement = document.querySelector('video');
|
|
30
|
+ var videoSelect = document.querySelector('select#videoSource');
|
|
31
|
+
|
|
32
|
+ videoSelect.onchange = getStream;
|
|
33
|
+
|
|
34
|
+ getStream().then(getDevices).then(gotDevices);
|
|
35
|
+
|
|
36
|
+ function getDevices() {
|
|
37
|
+ // AFAICT in Safari this only gets default devices until gUM is called :/
|
|
38
|
+ return navigator.mediaDevices.enumerateDevices();
|
|
39
|
+ }
|
|
40
|
+
|
|
41
|
+ function gotDevices(deviceInfos) {
|
|
42
|
+ window.deviceInfos = deviceInfos; // make available to console
|
|
43
|
+ console.log('Available input and output devices:', deviceInfos);
|
|
44
|
+ for (const deviceInfo of deviceInfos) {
|
|
45
|
+ const option = document.createElement('option');
|
|
46
|
+ option.value = deviceInfo.deviceId;
|
|
47
|
+ if (deviceInfo.kind === 'videoinput') {
|
|
48
|
+ option.text = deviceInfo.label || `Camera ${videoSelect.length + 1}`;
|
|
49
|
+ videoSelect.appendChild(option);
|
|
50
|
+ }
|
|
51
|
+ }
|
|
52
|
+ }
|
|
53
|
+
|
|
54
|
+ function getStream() {
|
|
55
|
+ if (window.stream) {
|
|
56
|
+ window.stream.getTracks().forEach(track => {
|
|
57
|
+ track.stop();
|
|
58
|
+ });
|
|
59
|
+ }
|
|
60
|
+ const videoSource = videoSelect.value;
|
|
61
|
+ const constraints = {
|
|
62
|
+ video: {deviceId: videoSource ? {exact: videoSource} : undefined}
|
|
63
|
+ };
|
|
64
|
+ return navigator.mediaDevices.getUserMedia(constraints).
|
|
65
|
+ then(gotStream).catch(handleError);
|
|
66
|
+ }
|
|
67
|
+
|
|
68
|
+ function gotStream(stream) {
|
|
69
|
+ window.stream = stream; // make stream available to console
|
|
70
|
+ videoSelect.selectedIndex = [...videoSelect.options].
|
|
71
|
+ findIndex(option => option.text === stream.getVideoTracks()[0].label);
|
|
72
|
+ videoElement.srcObject = stream;
|
|
73
|
+ }
|
|
74
|
+
|
|
75
|
+ function handleError(error) {
|
|
76
|
+ console.error('Error: ', error);
|
|
77
|
+ }
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+ </script>
|
|
81
|
+ <script>
|
|
82
|
+ async function getDistance() {
|
|
83
|
+ try {
|
|
84
|
+ let response = await fetch("/d");
|
|
85
|
+ let data = await response.json();
|
|
86
|
+ return data.distance;
|
|
87
|
+ } catch {
|
|
88
|
+ return 0;
|
|
89
|
+ }
|
|
90
|
+ };
|
|
91
|
+ async function updateDistance() {
|
|
92
|
+ var dist = await getDistance();
|
|
93
|
+ if (dist>NEO_FAR) {
|
|
94
|
+ dist = NEO_FAR;
|
|
95
|
+ }
|
|
96
|
+ if (dist>NEO_MID) {
|
|
97
|
+ var vidtransp = 1.0*(dist-NEO_MID)/(NEO_FAR-NEO_MID);
|
|
98
|
+ $("#the-video").css("opacity",vidtransp);
|
|
99
|
+ $("#the-reporter").css("opacity",1);
|
|
100
|
+ } else {
|
|
101
|
+ var reptransp = 1.0*(dist-NEO_NEAR)/(NEO_MID-NEO_NEAR);
|
|
102
|
+ $("#the-video").css("opacity",0);
|
|
103
|
+ $("#the-reporter").css("opacity",reptransp);
|
|
104
|
+ }
|
|
105
|
+ }
|
|
106
|
+ window.update_interval = setInterval(updateDistance, 200);
|
|
107
|
+ </script>
|
|
108
|
+</body>
|
|
109
|
+</html>
|