mirror of
https://github.com/AlexxIT/go2rtc.git
synced 2025-10-06 08:46:57 +08:00
157 lines
4.5 KiB
HTML
157 lines
4.5 KiB
HTML
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<meta name="viewport" content="width=device-width, user-scalable=yes, initial-scale=1, maximum-scale=1">
|
|
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
|
|
|
<title>go2rtc</title>
|
|
|
|
<style>
|
|
body {
|
|
font-family: Arial, Helvetica, sans-serif;
|
|
}
|
|
|
|
table {
|
|
background-color: white;
|
|
text-align: left;
|
|
border-collapse: collapse;
|
|
}
|
|
|
|
table td, table th {
|
|
border: 1px solid black;
|
|
padding: 5px 5px;
|
|
}
|
|
|
|
table tbody td {
|
|
font-size: 13px;
|
|
}
|
|
|
|
table thead {
|
|
background: #CFCFCF;
|
|
background: linear-gradient(to bottom, #dbdbdb 0%, #d3d3d3 66%, #CFCFCF 100%);
|
|
border-bottom: 3px solid black;
|
|
}
|
|
|
|
table thead th {
|
|
font-size: 15px;
|
|
font-weight: bold;
|
|
color: black;
|
|
text-align: center;
|
|
}
|
|
|
|
label {
|
|
display: flex;
|
|
align-items: center;
|
|
}
|
|
|
|
.header {
|
|
padding: 5px 5px;
|
|
}
|
|
|
|
.controls {
|
|
display: flex;
|
|
padding: 5px;
|
|
}
|
|
|
|
.controls > label {
|
|
margin-left: 10px;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<script src="main.js"></script>
|
|
<div class="header">
|
|
<input id="src" type="text" placeholder="url">
|
|
<a id="add" href="#">add</a>
|
|
</div>
|
|
<div class="controls">
|
|
<button>stream</button>
|
|
<label><input type="checkbox" name="webrtc" checked>webrtc</label>
|
|
<label><input type="checkbox" name="mse" checked>mse</label>
|
|
<label><input type="checkbox" name="mp4" checked>mp4</label>
|
|
<label><input type="checkbox" name="mjpeg" checked>mjpeg</label>
|
|
</div>
|
|
<table id="streams">
|
|
<thead>
|
|
<tr>
|
|
<th>Name</th>
|
|
<th>Online</th>
|
|
<th>Commands</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
</tbody>
|
|
</table>
|
|
<script>
|
|
const templates = [
|
|
'<a href="stream.html?src={name}">stream</a>',
|
|
'<a href="webrtc.html?src={name}">2-way-aud</a>',
|
|
'<a href="api/stream.mp4?src={name}">mp4</a>',
|
|
'<a href="api/stream.mjpeg?src={name}">mjpeg</a>',
|
|
`<a href="rtsp://${location.hostname}:8554/{name}">rtsp</a>`,
|
|
'<a href="api/streams?src={name}">info</a>',
|
|
'<a href="#" data-name="{name}">delete</a>',
|
|
];
|
|
|
|
document.querySelector("#add")
|
|
.addEventListener("click", () => {
|
|
const src = document.querySelector("#src");
|
|
const url = new URL("api/streams", location.href);
|
|
url.searchParams.set("src", src.value);
|
|
fetch(url, {method: "PUT"}).then(reload);
|
|
});
|
|
|
|
document.querySelector(".controls > button")
|
|
.addEventListener("click", () => {
|
|
const url = new URL("stream.html", location.href);
|
|
|
|
const streams = document.querySelectorAll("#streams input");
|
|
streams.forEach(i => {
|
|
if (i.checked) url.searchParams.append("src", i.name);
|
|
});
|
|
|
|
if (!url.searchParams.has("src")) return;
|
|
|
|
let mode = document.querySelectorAll(".controls input");
|
|
mode = Array.from(mode).filter(i => i.checked).map(i => i.name).join(",");
|
|
|
|
window.location.href = `${url}&mode=${mode}`;
|
|
});
|
|
|
|
const tbody = document.querySelector("#streams > tbody");
|
|
tbody.addEventListener("click", ev => {
|
|
if (ev.target.innerText !== "delete") return;
|
|
|
|
ev.preventDefault();
|
|
|
|
const url = new URL("api/streams", location.href);
|
|
url.searchParams.set("src", ev.target.dataset.name);
|
|
fetch(url, {method: "DELETE"}).then(reload);
|
|
});
|
|
|
|
function reload() {
|
|
const url = new URL("api/streams", location.href);
|
|
fetch(url).then(r => r.json()).then(data => {
|
|
tbody.innerHTML = "";
|
|
|
|
for (const [name, value] of Object.entries(data)) {
|
|
const online = value ? value.length : 0;
|
|
const links = templates.map(link => {
|
|
return link.replace("{name}", encodeURIComponent(name));
|
|
}).join(" ");
|
|
|
|
const tr = document.createElement("tr");
|
|
tr.dataset["id"] = name;
|
|
tr.innerHTML =
|
|
`<td><label><input type="checkbox" name="${name}">${name}</label></td>` +
|
|
`<td>${online}</td><td>${links}</td>`;
|
|
tbody.appendChild(tr);
|
|
}
|
|
});
|
|
}
|
|
|
|
reload();
|
|
</script>
|
|
</body>
|
|
</html> |