-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstream.html
More file actions
70 lines (64 loc) · 2.26 KB
/
stream.html
File metadata and controls
70 lines (64 loc) · 2.26 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
</head>
<body>
<img id="image" />
<button id="start-btn">start stream</button>
<button id="stop-btn">stop stream</button>
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/4.7.4/socket.io.js"></script>
<script>
const online_server = "http://13.51.86.179:5500";
const local_server = "http://localhost:5500";
const socket = io.connect(local_server);
const buffer = [];
socket.on("connect", () => {
console.log("connected");
socket.emit("join room", { deviceID: "abc" });
socket.emit("cameras:add", {
deviceID: "abc",
cameraIP: "192.168.1.7:8554",
username: "admin",
password: "admin",
});
});
socket.on("disconnect", () => {
console.log("disconnected");
});
socket.on("stream:send", ({ frame }) => {
let base64 = btoa(
new Uint8Array(frame).reduce((data, byte) => data + String.fromCharCode(byte), "")
);
base64 = atob(base64);
buffer.push(base64);
// console.log("Stream", buffer);
});
let interval = undefined;
document.getElementById("start-btn").addEventListener("click", () => {
socket.emit("stream:start", { deviceID: "abc", cameraIP: "192.168.1.7:8554" });
interval = setInterval(() => {
//console.log(buffer.length);
if (buffer.length > 60) {
console.log("buffer length is now greater");
let frame = buffer.shift();
//console.log("Frame", frame);
document.getElementById("image").src = "data:image/jpeg;base64," + frame;
} else {
console.log("buffer length is less ");
}
}, 1000 / 60);
});
document.getElementById("stop-btn").addEventListener("click", () => {
socket.emit("stream:end", { deviceID: "abc", cameraIP: "192.168.1.7:8554" });
console.log(interval);
if (typeof interval !== "undefined") {
console.log("clearing interval");
clearInterval(interval);
}
});
</script>
</body>
</html>