Merge remote-tracking branch 'upstream/master' into dark-mode

This commit is contained in:
Sergey Krashevich
2024-04-20 13:14:48 +03:00
4 changed files with 38 additions and 9 deletions

View File

@@ -1352,6 +1352,7 @@ streams:
**Distributions** **Distributions**
- [Alpine Linux](https://pkgs.alpinelinux.org/packages?name=go2rtc) - [Alpine Linux](https://pkgs.alpinelinux.org/packages?name=go2rtc)
- [Arch User Repository](https://linux-packages.com/aur/package/go2rtc)
- [Gentoo](https://github.com/inode64/inode64-overlay/tree/main/media-video/go2rtc) - [Gentoo](https://github.com/inode64/inode64-overlay/tree/main/media-video/go2rtc)
- [NixOS](https://search.nixos.org/packages?query=go2rtc) - [NixOS](https://search.nixos.org/packages?query=go2rtc)
- [Proxmox Helper Scripts](https://tteck.github.io/Proxmox/) - [Proxmox Helper Scripts](https://tteck.github.io/Proxmox/)

View File

@@ -7,6 +7,7 @@ import (
"fmt" "fmt"
"os" "os"
"os/exec" "os/exec"
"strings"
"sync" "sync"
"time" "time"
@@ -108,7 +109,7 @@ func handleRTSP(url, path string, cmd *exec.Cmd) (core.Producer, error) {
waitersMu.Unlock() waitersMu.Unlock()
}() }()
log.Debug().Str("url", url).Msg("[exec] run") log.Debug().Str("url", url).Str("cmd", fmt.Sprintf("%s", strings.Join(cmd.Args, " "))).Msg("[exec] run")
ts := time.Now() ts := time.Now()

View File

@@ -132,6 +132,9 @@ func (c *Client) Handle() error {
case "stream-init": case "stream-init":
continue continue
case "metadata":
continue
case "fragment": case "fragment":
_, data, err = c.conn.ReadMessage() _, data, err = c.conn.ReadMessage()
if err != nil { if err != nil {
@@ -183,6 +186,9 @@ func (c *Client) getTracks() error {
} }
switch msg.Type { switch msg.Type {
case "metadata":
continue
case "stream-init": case "stream-init":
s := msg.CodecString s := msg.CodecString
i := strings.IndexByte(s, '.') i := strings.IndexByte(s, '.')

View File

@@ -100,28 +100,49 @@
function reload() { function reload() {
const url = new URL('api/streams', location.href); const url = new URL('api/streams', location.href);
const checkboxStates = {};
tbody.querySelectorAll('input[type="checkbox"][name]').forEach(checkbox => {
checkboxStates[checkbox.name] = checkbox.checked;
});
fetch(url, {cache: 'no-cache'}).then(r => r.json()).then(data => { fetch(url, {cache: 'no-cache'}).then(r => r.json()).then(data => {
tbody.innerHTML = ''; const existingIds = Array.from(tbody.querySelectorAll('tr')).map(tr => tr.dataset['id']);
const fetchedIds = [];
for (const [key, value] of Object.entries(data)) { for (const [key, value] of Object.entries(data)) {
const name = key.replace(/[<">]/g, ''); // sanitize const name = key.replace(/[<">]/g, ''); // sanitize
fetchedIds.push(name);
let tr = tbody.querySelector(`tr[data-id="${name}"]`);
const online = value && value.consumers ? value.consumers.length : 0; const online = value && value.consumers ? value.consumers.length : 0;
const src = encodeURIComponent(name); const src = encodeURIComponent(name);
const links = templates.map(link => { const links = templates.map(link => link.replace('{name}', src)).join(' ');
return link.replace('{name}', src);
}).join(' ');
const tr = document.createElement('tr'); if (!tr) {
tr.dataset['id'] = name; tr = document.createElement('tr');
tr.dataset['id'] = name;
tbody.appendChild(tr);
}
const isChecked = checkboxStates[name] ? 'checked' : '';
tr.innerHTML = tr.innerHTML =
`<td><label><input type="checkbox" name="${name}">${name}</label></td>` + `<td><label><input type="checkbox" name="${name}" ${isChecked}>${name}</label></td>` +
`<td><a href="api/streams?src=${src}">${online} / info</a></td>` + `<td><a href="api/streams?src=${src}">${online} / info</a></td>` +
`<td>${links}</td>`; `<td>${links}</td>`;
tbody.appendChild(tr);
} }
// Remove old rows
existingIds.forEach(id => {
if (!fetchedIds.includes(id)) {
const trToRemove = tbody.querySelector(`tr[data-id="${id}"]`);
tbody.removeChild(trToRemove);
}
});
}); });
} }
// Auto-reload
setInterval(reload, 1000);
const url = new URL('api', location.href); const url = new URL('api', location.href);
fetch(url, {cache: 'no-cache'}).then(r => r.json()).then(data => { fetch(url, {cache: 'no-cache'}).then(r => r.json()).then(data => {
const info = document.querySelector('.info'); const info = document.querySelector('.info');