146 lines
4.0 KiB
HTML
146 lines
4.0 KiB
HTML
<html>
|
|
<head>
|
|
<title>RTSP Stream</title>
|
|
</head>
|
|
|
|
<style>
|
|
#container {
|
|
position: relative;
|
|
width: 640px;
|
|
height: 480px;
|
|
}
|
|
#video {
|
|
position: absolute;
|
|
top: 0;
|
|
left: 0;
|
|
}
|
|
#overlay {
|
|
position: absolute;
|
|
top: 0;
|
|
left: 0;
|
|
cursor: crosshair;
|
|
}
|
|
</style>
|
|
|
|
<div id="container">
|
|
<img id="video" width="640" height="480"/>
|
|
<canvas id="overlay" width="640" height="480"></canvas>
|
|
</div>
|
|
|
|
<body>
|
|
<!-- <h1>Stream</h1> -->
|
|
<!-- <img id="video" width="640" height="480"/> -->
|
|
<br>
|
|
<button onclick="markGood()">Хорошая жижа</button>
|
|
<button onclick="markBad()">Плохая жижа</button>
|
|
|
|
<div id="status" style="color:red; font-weight:bold; margin-top:10px;"></div>
|
|
<div id="color-status" style="width: 300px; height: 40px; background-color: green; color: white; text-align: center; line-height: 40px; font-weight: bold;">
|
|
Всё хорошо
|
|
</div>
|
|
<script>
|
|
let socket = new WebSocket("ws://localhost:8000/ws/stream/");
|
|
let statusDiv = document.getElementById("status");
|
|
|
|
let startX, startY, endX, endY;
|
|
let isDrawing = false;
|
|
|
|
const canvas = document.getElementById('overlay');
|
|
const ctx = canvas.getContext('2d');
|
|
|
|
canvas.onmousedown = e => {
|
|
isDrawing = true;
|
|
startX = e.offsetX;
|
|
startY = e.offsetY;
|
|
};
|
|
|
|
canvas.onmousemove = e => {
|
|
if (!isDrawing) return;
|
|
endX = e.offsetX;
|
|
endY = e.offsetY;
|
|
|
|
const width = endX - startX;
|
|
const height = endY - startY;
|
|
|
|
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
|
ctx.strokeStyle = 'lime';
|
|
ctx.lineWidth = 2;
|
|
ctx.strokeRect(startX, startY, width, height);
|
|
};
|
|
|
|
canvas.onmouseup = () => {
|
|
isDrawing = false;
|
|
};
|
|
|
|
function mark(type) {
|
|
if (startX == null || endX == null) {
|
|
alert("Сначала выделите область!");
|
|
return;
|
|
}
|
|
|
|
const scaleX = 2560 / 640;
|
|
const scaleY = 1440 / 480;
|
|
|
|
const cropX = Math.round(Math.min(startX, endX) * scaleX);
|
|
const cropY = Math.round(Math.min(startY, endY) * scaleY);
|
|
const cropW = Math.round(Math.abs(endX - startX) * scaleX);
|
|
const cropH = Math.round(Math.abs(endY - startY) * scaleY);
|
|
|
|
socket.send(JSON.stringify({type, cropX, cropY, cropW, cropH}));
|
|
statusDiv.innerText = "🔴 Запись идет...";
|
|
|
|
setTimeout(() => {
|
|
statusDiv.innerText = "";
|
|
}, 1 * 60 * 1000); // 10 минут
|
|
}
|
|
|
|
function markGood() { mark("good"); }
|
|
function markBad() { mark("bad"); }
|
|
|
|
socket.onmessage = event => {
|
|
if (event.data === "recording_started") {
|
|
statusDiv.innerText = "🔴 Запись идет...";
|
|
} else {
|
|
document.getElementById("video").src = 'data:image/jpeg;base64,' + event.data;
|
|
}
|
|
};
|
|
|
|
socket.onmessage = event => {
|
|
try {
|
|
const data = JSON.parse(event.data);
|
|
|
|
if (data.status === "danger") {
|
|
document.getElementById("color-status").style.backgroundColor = "red";
|
|
document.getElementById("color-status").innerText = data.message;
|
|
} else if (data.status === "ok") {
|
|
document.getElementById("color-status").style.backgroundColor = "green";
|
|
document.getElementById("color-status").innerText = data.message;
|
|
}
|
|
} catch {
|
|
document.getElementById("video").src = 'data:image/jpeg;base64,' + event.data;
|
|
}
|
|
};
|
|
|
|
// socket.onmessage = function(event) {
|
|
// const data = event.data;
|
|
// try {
|
|
// const parsed = JSON.parse(data);
|
|
// if (parsed.alert) {
|
|
// // Показываем уведомление
|
|
// const notification = document.getElementById('notification');
|
|
// notification.textContent = parsed.alert;
|
|
// notification.style.display = 'block';
|
|
// // Скрываем через 3 секунды
|
|
// setTimeout(() => {
|
|
// notification.style.display = 'none';
|
|
// }, 3000);
|
|
// } else {
|
|
// // обработка кадра
|
|
// }
|
|
// } catch (e) {
|
|
// // обработка обычного изображения
|
|
// }
|
|
// };
|
|
</script>
|
|
</body>
|
|
</html> |