aboutsummaryrefslogtreecommitdiff
path: root/templates/client.html
blob: e03394a1778991ae49cc2f0c5e8ec726f336d2fe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<!DOCTYPE html>
<html>
<head>
    <title>Client {{ client_id }} - Camera Streams</title>
    <style>
        .camera-stream { display: inline-block; margin: 10px; }
        video { border: 1px solid #333; }
    </style>
</head>
<body>
    <h1>Camera Streams for client: {{ client_id }}</h1>
    <div class="streams-container">
        {% for camera_id in camera_ids %}
        <div class="camera-stream">
            <h2>Camera {{ camera_id }}</h2>
            <img id="video-{{ camera_id }}" width="640" height="480" />
        </div>
        {% endfor %}
    </div> 
    <script>
    // For each camera, open a WebSocket and update the corresponding <img>
    {% for camera_id in camera_ids %}
    (function() {
        let ws = new WebSocket('ws://' + window.location.host + '/ws/{{ client_id }}/{{ camera_id }}');
        let image = document.getElementById('video-{{ camera_id }}');
        let currentUrl = null;
        ws.onmessage = function(event) {
            if (currentUrl) {
                URL.revokeObjectURL(currentUrl);
            }
            currentUrl = URL.createObjectURL(event.data);
            image.src = currentUrl;
        };
        ws.onclose = function(event) {
            console.log('WebSocket closed for camera {{ camera_id }}:', event);
        };
        ws.onerror = function(event) {
            console.log('WebSocket error for camera {{ camera_id }}:', event);
        };
        window.addEventListener('beforeunload', function() {
            ws.close();
        });
    })();
    {% endfor %}
    </script>
</body>
</html>