mirror of
https://github.com/AlexxIT/go2rtc.git
synced 2025-09-26 20:31:11 +08:00
382 lines
12 KiB
HTML
382 lines
12 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<title>go2rtc - Add Stream</title>
|
|
<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">
|
|
<style>
|
|
body {
|
|
margin: 0;
|
|
padding: 0;
|
|
display: flex;
|
|
flex-direction: column;
|
|
}
|
|
|
|
html, body {
|
|
width: 100%;
|
|
height: 100%;
|
|
}
|
|
|
|
.module {
|
|
display: none;
|
|
padding: 10px;
|
|
}
|
|
|
|
|
|
table tbody td {
|
|
font-size: 13px;
|
|
}
|
|
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<script src="main.js"></script>
|
|
<script>
|
|
function drawTable(table, data) {
|
|
const cols = ['id', 'name', 'info', 'url', 'location'];
|
|
const th = (row) => cols.reduce((html, k) => k in row ? `${html}<th>${k}</th>` : html, '<tr>') + '</tr>';
|
|
const td = (row) => cols.reduce((html, k) => k in row ? `${html}<td style="word-break: break-word;white-space: normal;">${row[k]}</td>` : html, '<tr>') + '</tr>';
|
|
|
|
const thead = th(data.sources[0]);
|
|
const tbody = data.sources.reduce((html, source) => `${html}${td(source)}`, '');
|
|
|
|
table.innerHTML = `<thead>${thead}</thead><tbody>${tbody}</tbody>`;
|
|
}
|
|
|
|
async function getSources(tableID, url) {
|
|
const table = document.getElementById(tableID);
|
|
table.innerText = 'loading...';
|
|
|
|
const r = typeof url === 'string' ? await fetch(url, {cache: 'no-cache'}) : url;
|
|
if (!r.ok) {
|
|
table.innerText = await r.text();
|
|
return;
|
|
}
|
|
|
|
drawTable(table, await r.json());
|
|
}
|
|
</script>
|
|
|
|
|
|
<button id="stream">Temporary stream</button>
|
|
<div class="module">
|
|
<form id="stream-form" style="padding: 10px">
|
|
<input type="text" name="name" placeholder="name">
|
|
<input type="text" name="src" placeholder="url">
|
|
<input type="submit" value="add">
|
|
</form>
|
|
</div>
|
|
<script>
|
|
document.getElementById('stream').addEventListener('click', async ev => {
|
|
ev.target.nextElementSibling.style.display = 'block';
|
|
});
|
|
|
|
document.getElementById('stream-form').addEventListener('submit', async ev => {
|
|
ev.preventDefault();
|
|
|
|
const url = new URL('api/streams', location.href);
|
|
url.searchParams.set('name', ev.target.elements['name'].value);
|
|
url.searchParams.set('src', ev.target.elements['src'].value);
|
|
|
|
const r = await fetch(url, {method: 'PUT'});
|
|
alert(r.ok ? 'OK' : 'ERROR: ' + await r.text());
|
|
});
|
|
</script>
|
|
|
|
|
|
<button id="alsa">ALSA (Linux audio)</button>
|
|
<div class="module">
|
|
<table id="alsa-table"></table>
|
|
</div>
|
|
<script>
|
|
document.getElementById('alsa').addEventListener('click', async ev => {
|
|
ev.target.nextElementSibling.style.display = 'block';
|
|
await getSources('alsa-table', 'api/alsa');
|
|
});
|
|
</script>
|
|
|
|
|
|
<button id="homekit">Apple HomeKit</button>
|
|
<div class="module">
|
|
<form id="homekit-pair" style="margin-bottom: 10px">
|
|
<input type="text" name="id" placeholder="stream id" size="20">
|
|
<input type="text" name="url" placeholder="url" size="40">
|
|
<input type="text" name="pin" placeholder="pin" size="10">
|
|
<input type="submit" value="Pair">
|
|
</form>
|
|
<form id="homekit-unpair" style="margin-bottom: 10px">
|
|
<input type="text" name="id" placeholder="stream id" size="20">
|
|
<input type="submit" value="Unpair">
|
|
</form>
|
|
<table id="homekit-table"></table>
|
|
</div>
|
|
<script>
|
|
async function reloadHomeKit() {
|
|
await getSources('homekit-table', 'api/homekit');
|
|
|
|
const rows = document.querySelectorAll('#homekit-table tr');
|
|
rows.forEach((row, i) => {
|
|
let commands = '';
|
|
if (row.children[2].innerText.indexOf('status=1') > 0) {
|
|
commands += '<a href="#">pair</a>';
|
|
} else if (i > 0 && row.children[3].innerText) {
|
|
commands += '<a href="#">unpair</a>';
|
|
}
|
|
row.innerHTML += `<td>${commands}</td>`;
|
|
});
|
|
}
|
|
|
|
document.getElementById('homekit').addEventListener('click', async ev => {
|
|
ev.target.nextElementSibling.style.display = 'block';
|
|
await reloadHomeKit();
|
|
});
|
|
|
|
document.getElementById('homekit-table').addEventListener('click', ev => {
|
|
if (ev.target.innerText === 'pair') {
|
|
const form = document.querySelector('#homekit-pair');
|
|
const row = ev.target.closest('tr');
|
|
form.children[0].value = row.children[0].innerText;
|
|
form.children[1].value = row.children[2].innerText;
|
|
} else if (ev.target.innerText === 'unpair') {
|
|
const form = document.querySelector('#homekit-unpair');
|
|
const row = ev.target.closest('tr');
|
|
form.children[0].value = row.children[3].innerText;
|
|
}
|
|
});
|
|
|
|
document.getElementById('homekit-pair').addEventListener('submit', async ev => {
|
|
ev.preventDefault();
|
|
|
|
const body = new FormData(ev.target);
|
|
body.set('url', body.get('url') + '&pin=' + body.get('pin'));
|
|
body.delete('pin');
|
|
|
|
const r = await fetch('api/homekit', {method: 'POST', body: body});
|
|
alert(r.ok ? 'OK' : 'ERROR: ' + await r.text());
|
|
|
|
await reloadHomeKit();
|
|
});
|
|
|
|
document.getElementById('homekit-unpair').addEventListener('submit', async ev => {
|
|
ev.preventDefault();
|
|
const r = await fetch('api/homekit', {method: 'DELETE', body: new FormData(ev.target)});
|
|
alert(r.ok ? 'OK' : 'ERROR: ' + await r.text());
|
|
|
|
await reloadHomeKit();
|
|
});
|
|
</script>
|
|
|
|
|
|
<button id="dvrip">DVRIP</button>
|
|
<div class="module">
|
|
<table id="dvrip-table"></table>
|
|
</div>
|
|
<script>
|
|
document.getElementById('dvrip').addEventListener('click', async ev => {
|
|
ev.target.nextElementSibling.style.display = 'block';
|
|
await getSources('dvrip-table', 'api/dvrip');
|
|
});
|
|
</script>
|
|
|
|
|
|
<button id="devices">FFmpeg Devices (USB)</button>
|
|
<div class="module">
|
|
<table id="devices-table"></table>
|
|
</div>
|
|
<script>
|
|
document.getElementById('devices').addEventListener('click', async ev => {
|
|
ev.target.nextElementSibling.style.display = 'block';
|
|
await getSources('devices-table', 'api/ffmpeg/devices');
|
|
});
|
|
</script>
|
|
|
|
|
|
<button id="hardware">FFmpeg Hardware</button>
|
|
<div class="module">
|
|
<table id="hardware-table"></table>
|
|
</div>
|
|
<script>
|
|
document.getElementById('hardware').addEventListener('click', async ev => {
|
|
ev.target.nextElementSibling.style.display = 'block';
|
|
await getSources('hardware-table', 'api/ffmpeg/hardware');
|
|
});
|
|
</script>
|
|
|
|
|
|
<button id="nest">Google Nest</button>
|
|
<div class="module">
|
|
<form id="nest-form" style="margin-bottom: 10px">
|
|
<input type="text" name="client_id" placeholder="client_id">
|
|
<input type="text" name="client_secret" placeholder="client_secret">
|
|
<input type="text" name="refresh_token" placeholder="refresh_token">
|
|
<input type="text" name="project_id" placeholder="project_id">
|
|
<input type="submit" value="Login">
|
|
</form>
|
|
<table id="nest-table"></table>
|
|
</div>
|
|
<script>
|
|
document.getElementById('nest').addEventListener('click', async ev => {
|
|
ev.target.nextElementSibling.style.display = 'block';
|
|
});
|
|
|
|
document.getElementById('nest-form').addEventListener('submit', async ev => {
|
|
ev.preventDefault();
|
|
|
|
const query = new URLSearchParams(new FormData(ev.target));
|
|
const url = new URL('api/nest?' + query.toString(), location.href);
|
|
|
|
const r = await fetch(url, {cache: 'no-cache'});
|
|
await getSources('nest-table', r);
|
|
});
|
|
</script>
|
|
|
|
<button id="ring">Ring</button>
|
|
<div class="module">
|
|
<form id="ring-credentials-form" style="margin-bottom: 10px">
|
|
<input type="email" name="email" placeholder="email">
|
|
<input type="password" name="password" placeholder="password">
|
|
<div id="tfa-field" style="display: none">
|
|
<input type="text" name="code" placeholder="2FA code">
|
|
<div id="tfa-prompt"></div>
|
|
</div>
|
|
<input type="submit" value="Login">
|
|
</form>
|
|
<form id="ring-token-form" style="margin-bottom: 10px">
|
|
<input type="text" name="refresh_token" placeholder="refresh_token">
|
|
<input type="submit" value="Login">
|
|
</form>
|
|
<table id="ring-table"></table>
|
|
</div>
|
|
<script>
|
|
document.getElementById('ring').addEventListener('click', async ev => {
|
|
ev.target.nextElementSibling.style.display = 'block';
|
|
});
|
|
|
|
async function handleRingAuth(ev) {
|
|
ev.preventDefault();
|
|
const query = new URLSearchParams(new FormData(ev.target));
|
|
const url = new URL('api/ring?' + query.toString(), location.href);
|
|
|
|
const r = await fetch(url, {cache: 'no-cache'});
|
|
const data = await r.json();
|
|
|
|
if (data.needs_2fa) {
|
|
document.getElementById('tfa-field').style.display = 'block';
|
|
document.getElementById('tfa-prompt').textContent = data.prompt || 'Enter 2FA code';
|
|
return;
|
|
}
|
|
|
|
if (!r.ok) {
|
|
const table = document.getElementById('ring-table');
|
|
table.innerText = data.error || 'Unknown error';
|
|
return;
|
|
}
|
|
|
|
const table = document.getElementById('ring-table');
|
|
drawTable(table, data);
|
|
}
|
|
|
|
document.getElementById('ring-credentials-form').addEventListener('submit', handleRingAuth);
|
|
document.getElementById('ring-token-form').addEventListener('submit', handleRingAuth);
|
|
</script>
|
|
|
|
<button id="gopro">GoPro</button>
|
|
<div class="module">
|
|
<table id="gopro-table"></table>
|
|
</div>
|
|
<script>
|
|
document.getElementById('gopro').addEventListener('click', async ev => {
|
|
ev.target.nextElementSibling.style.display = 'block';
|
|
await getSources('gopro-table', 'api/gopro');
|
|
});
|
|
</script>
|
|
|
|
|
|
<button id="hass">Home Assistant</button>
|
|
<div class="module">
|
|
<table id="hass-table"></table>
|
|
</div>
|
|
<script>
|
|
document.getElementById('hass').addEventListener('click', async ev => {
|
|
ev.target.nextElementSibling.style.display = 'block';
|
|
await getSources('hass-table', 'api/hass');
|
|
});
|
|
</script>
|
|
|
|
|
|
<button id="onvif">ONVIF</button>
|
|
<div class="module">
|
|
<form id="onvif-form" style="padding: 10px">
|
|
<input type="text" name="src" placeholder="onvif://user:pass@192.168.1.123:80" size="50">
|
|
<input type="submit" value="test">
|
|
</form>
|
|
<table id="onvif-table"></table>
|
|
</div>
|
|
<script>
|
|
document.getElementById('onvif').addEventListener('click', async ev => {
|
|
ev.target.nextElementSibling.style.display = 'block';
|
|
await getSources('onvif-table', 'api/onvif');
|
|
});
|
|
|
|
document.getElementById('onvif-form').addEventListener('submit', async ev => {
|
|
ev.preventDefault();
|
|
|
|
const url = new URL('api/onvif', location.href);
|
|
url.searchParams.set('src', ev.target.elements['src'].value);
|
|
|
|
await getSources('onvif-table', url.toString());
|
|
});
|
|
</script>
|
|
|
|
|
|
<button id="roborock">Roborock</button>
|
|
<div class="module">
|
|
<form id="roborock-form" style="margin-bottom: 10px">
|
|
<input type="text" name="username" placeholder="username">
|
|
<input type="password" name="password" placeholder="password">
|
|
<input type="submit" value="Login">
|
|
</form>
|
|
<table id="roborock-table">
|
|
</table>
|
|
</div>
|
|
<script>
|
|
document.getElementById('roborock').addEventListener('click', async ev => {
|
|
ev.target.nextElementSibling.style.display = 'block';
|
|
await getSources('roborock-table', 'api/roborock');
|
|
});
|
|
|
|
document.getElementById('roborock-form').addEventListener('submit', async ev => {
|
|
ev.preventDefault();
|
|
const r = await fetch('api/roborock', {method: 'POST', body: new FormData(ev.target)});
|
|
await getSources('roborock-table', r);
|
|
});
|
|
</script>
|
|
|
|
|
|
<button id="v4l2">V4L2 (Linux video)</button>
|
|
<div class="module">
|
|
<table id="v4l2-table"></table>
|
|
</div>
|
|
<script>
|
|
document.getElementById('v4l2').addEventListener('click', async ev => {
|
|
ev.target.nextElementSibling.style.display = 'block';
|
|
await getSources('v4l2-table', 'api/v4l2');
|
|
});
|
|
</script>
|
|
|
|
|
|
<button id="webtorrent">WebTorrent Shares</button>
|
|
<div class="module">
|
|
<table id="webtorrent-table"></table>
|
|
</div>
|
|
<script>
|
|
document.getElementById('webtorrent').addEventListener('click', async ev => {
|
|
ev.target.nextElementSibling.style.display = 'block';
|
|
await getSources('webtorrent-table', 'api/webtorrent');
|
|
});
|
|
</script>
|
|
|
|
|
|
</body>
|
|
</html>
|