streamd: copyable m3u8 links + FHD/HD/SD output variants
Some checks failed
release / build-and-upload (push) Failing after 3m33s
Some checks failed
release / build-and-upload (push) Failing after 3m33s
- WebUI Copy button for absolute m3u8 URLs (no player) - Per-stream variants ladder; HD/SD live-transcoded as sibling HLS - variants_json in DB/API; supervisor spawns scaled ffmpeg packagers
This commit is contained in:
parent
ac8701b5a6
commit
3cb259c9b6
12 changed files with 913 additions and 62 deletions
|
|
@ -9,6 +9,7 @@
|
|||
--degraded: #f5a524;
|
||||
--down: #f07178;
|
||||
--stopped: #6b7280;
|
||||
--chip: #1c2230;
|
||||
}
|
||||
* { box-sizing: border-box; }
|
||||
body {
|
||||
|
|
@ -26,7 +27,7 @@ header {
|
|||
}
|
||||
h1 { margin: 0; font-size: 18px; font-weight: 600; }
|
||||
h2 { margin: 0 0 12px; font-size: 15px; font-weight: 600; }
|
||||
.header-right { display: flex; gap: 16px; align-items: center; }
|
||||
.header-right { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; }
|
||||
.muted { color: var(--muted); }
|
||||
.card {
|
||||
margin: 16px 20px;
|
||||
|
|
@ -66,12 +67,17 @@ button {
|
|||
button:hover { border-color: var(--accent); }
|
||||
button.ghost { background: transparent; }
|
||||
button.danger { border-color: #7f1d1d; color: #fecaca; }
|
||||
button.tiny {
|
||||
padding: 3px 8px;
|
||||
font-size: 11px;
|
||||
line-height: 1.2;
|
||||
}
|
||||
.actions { display: flex; gap: 8px; align-items: end; }
|
||||
.token-box input { width: 180px; }
|
||||
.row-between { display: flex; justify-content: space-between; align-items: center; }
|
||||
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
|
||||
.table-wrap { overflow-x: auto; }
|
||||
table { width: 100%; border-collapse: collapse; }
|
||||
th, td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--border); vertical-align: middle; }
|
||||
th, td { text-align: left; padding: 10px 6px; border-bottom: 1px solid var(--border); vertical-align: top; }
|
||||
th { color: var(--muted); font-weight: 500; font-size: 12px; }
|
||||
.pill {
|
||||
display: inline-block;
|
||||
|
|
@ -82,25 +88,124 @@ th { color: var(--muted); font-weight: 500; font-size: 12px; }
|
|||
}
|
||||
.pill.ok { color: var(--ok); }
|
||||
.pill.degraded { color: var(--degraded); }
|
||||
.pill.down, .pill.starting { color: var(--down); }
|
||||
.pill.stopped { color: var(--stopped); }
|
||||
.pill.down, .pill.starting, .pill.pending { color: var(--down); }
|
||||
.pill.stopped, .pill.off { color: var(--stopped); }
|
||||
.pill.claim { color: #c4b5fd; background: #1f1635; }
|
||||
.row-actions { display: flex; flex-wrap: wrap; gap: 6px; }
|
||||
.row-actions { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
|
||||
.row-actions button { padding: 4px 8px; font-size: 12px; }
|
||||
.msg { min-height: 1.2em; margin: 8px 0 0; }
|
||||
.msg.err { color: var(--down); }
|
||||
a { color: var(--accent); }
|
||||
code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; }
|
||||
|
||||
.variants-field {
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 8px;
|
||||
padding: 12px;
|
||||
margin: 0;
|
||||
}
|
||||
.variants-field legend {
|
||||
padding: 0 6px;
|
||||
color: var(--text);
|
||||
font-size: 12px;
|
||||
font-weight: 600;
|
||||
}
|
||||
.hint { margin: 0 0 10px; color: var(--muted); font-size: 12px; }
|
||||
.variant-toggles {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(3, minmax(0, 1fr));
|
||||
gap: 8px;
|
||||
}
|
||||
.variant-card {
|
||||
display: grid;
|
||||
grid-template-columns: auto 1fr;
|
||||
grid-template-rows: auto auto;
|
||||
column-gap: 8px;
|
||||
row-gap: 2px;
|
||||
align-items: center;
|
||||
padding: 10px 12px;
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 8px;
|
||||
background: #12151c;
|
||||
cursor: pointer;
|
||||
color: var(--text);
|
||||
}
|
||||
.variant-card input {
|
||||
grid-row: 1 / span 2;
|
||||
width: 16px;
|
||||
height: 16px;
|
||||
accent-color: var(--accent);
|
||||
}
|
||||
.variant-card .v-title { font-weight: 600; font-size: 13px; color: var(--text); }
|
||||
.variant-card .v-meta { font-size: 11px; color: var(--muted); }
|
||||
.variant-card.on,
|
||||
.variant-card:has(input:checked) {
|
||||
border-color: #3b82f6;
|
||||
background: #152033;
|
||||
box-shadow: inset 0 0 0 1px rgba(59, 130, 246, 0.25);
|
||||
}
|
||||
.variant-card.locked {
|
||||
opacity: 0.92;
|
||||
cursor: default;
|
||||
}
|
||||
|
||||
.link-stack { display: flex; flex-direction: column; gap: 6px; min-width: 180px; }
|
||||
.link-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
flex-wrap: wrap;
|
||||
padding: 6px 8px;
|
||||
background: var(--chip);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 8px;
|
||||
}
|
||||
.link-row .v-label {
|
||||
font-size: 11px;
|
||||
font-weight: 700;
|
||||
letter-spacing: 0.02em;
|
||||
min-width: 2.4em;
|
||||
color: var(--accent);
|
||||
}
|
||||
.link-row .v-path {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
|
||||
font-size: 11px;
|
||||
color: var(--muted);
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.link-row .pill { margin-left: auto; }
|
||||
|
||||
.toast {
|
||||
position: fixed;
|
||||
right: 16px;
|
||||
bottom: 16px;
|
||||
background: #1e293b;
|
||||
border: 1px solid #334155;
|
||||
color: var(--text);
|
||||
padding: 10px 14px;
|
||||
border-radius: 8px;
|
||||
box-shadow: 0 8px 24px rgba(0,0,0,.35);
|
||||
z-index: 50;
|
||||
font-size: 13px;
|
||||
}
|
||||
.toast.show { display: block; }
|
||||
|
||||
dialog {
|
||||
border: 1px solid var(--border);
|
||||
background: var(--card);
|
||||
color: var(--text);
|
||||
border-radius: 8px;
|
||||
padding: 16px;
|
||||
min-width: min(560px, 92vw);
|
||||
min-width: min(640px, 94vw);
|
||||
}
|
||||
dialog::backdrop { background: rgba(0,0,0,.55); }
|
||||
@media (max-width: 720px) {
|
||||
.grid { grid-template-columns: 1fr; }
|
||||
.span2 { grid-column: span 1; }
|
||||
.variant-toggles { grid-template-columns: 1fr; }
|
||||
header { flex-direction: column; align-items: flex-start; gap: 8px; }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@
|
|||
const agentsEl = document.getElementById("agents-status");
|
||||
const dlg = document.getElementById("edit-dlg");
|
||||
const editForm = document.getElementById("edit-form");
|
||||
const toastEl = document.getElementById("toast");
|
||||
|
||||
tokenEl.value = localStorage.getItem("streamd_token") || "";
|
||||
tokenEl.addEventListener("change", () => {
|
||||
|
|
@ -43,6 +44,42 @@
|
|||
return Number(s).toFixed(1) + "s";
|
||||
}
|
||||
|
||||
function absURL(path) {
|
||||
if (!path) return "";
|
||||
try { return new URL(path, location.origin).href; } catch { return path; }
|
||||
}
|
||||
|
||||
let toastTimer = null;
|
||||
function toast(msg) {
|
||||
if (!toastEl) return;
|
||||
toastEl.hidden = false;
|
||||
toastEl.classList.add("show");
|
||||
toastEl.textContent = msg;
|
||||
clearTimeout(toastTimer);
|
||||
toastTimer = setTimeout(() => {
|
||||
toastEl.hidden = true;
|
||||
toastEl.classList.remove("show");
|
||||
}, 1800);
|
||||
}
|
||||
|
||||
async function copyText(text) {
|
||||
if (!text) return;
|
||||
try {
|
||||
await navigator.clipboard.writeText(text);
|
||||
toast("Copied m3u8 link");
|
||||
} catch {
|
||||
const ta = document.createElement("textarea");
|
||||
ta.value = text;
|
||||
ta.style.position = "fixed";
|
||||
ta.style.left = "-9999px";
|
||||
document.body.appendChild(ta);
|
||||
ta.select();
|
||||
try { document.execCommand("copy"); toast("Copied m3u8 link"); }
|
||||
catch { toast("Copy failed"); }
|
||||
ta.remove();
|
||||
}
|
||||
}
|
||||
|
||||
function claimLabel(s) {
|
||||
if (!s.claimed_by) return '<span class="muted">—</span>';
|
||||
let exp = "";
|
||||
|
|
@ -55,6 +92,37 @@
|
|||
return `<span class="pill claim">${esc(s.claimed_by)}${esc(exp)}</span>`;
|
||||
}
|
||||
|
||||
function enabledVariants(s) {
|
||||
const list = Array.isArray(s.variants) ? s.variants : [];
|
||||
const enabled = list.filter((v) => v && v.enabled !== false && v.health !== "off");
|
||||
if (enabled.length) return enabled;
|
||||
return [{
|
||||
id: "fhd",
|
||||
label: "FHD",
|
||||
enabled: true,
|
||||
height: 0,
|
||||
play_path: s.play_path || ("/hls/" + s.name + "/index.m3u8"),
|
||||
health: s.health || "stopped",
|
||||
playlist_age_s: s.playlist_age_s,
|
||||
}];
|
||||
}
|
||||
|
||||
function linksCell(s) {
|
||||
const vars = enabledVariants(s);
|
||||
return `<div class="link-stack">${vars.map((v) => {
|
||||
const path = v.play_path || "";
|
||||
const url = absURL(path);
|
||||
const label = v.label || v.id || "FHD";
|
||||
const health = v.health || s.health || "stopped";
|
||||
return `<div class="link-row">
|
||||
<span class="v-label">${esc(label)}</span>
|
||||
<span class="v-path" title="${esc(url)}">${esc(path)}</span>
|
||||
<span class="pill ${esc(health)}">${esc(health)}</span>
|
||||
<button type="button" class="tiny ghost" data-act="copy-link" data-url="${esc(url)}" title="Copy m3u8 URL">Copy</button>
|
||||
</div>`;
|
||||
}).join("")}</div>`;
|
||||
}
|
||||
|
||||
function render(streams) {
|
||||
if (!streams.length) {
|
||||
rowsEl.innerHTML = "";
|
||||
|
|
@ -70,7 +138,7 @@
|
|||
<td><span class="pill ${esc(s.health || "stopped")}">${esc(s.health || "stopped")}</span></td>
|
||||
<td>${claimLabel(s)}</td>
|
||||
<td>${age(s.playlist_age_s)}</td>
|
||||
<td><a href="${esc(s.play_path)}" target="_blank" rel="noopener">hls</a></td>
|
||||
<td>${linksCell(s)}</td>
|
||||
<td class="row-actions">
|
||||
<button data-act="start" data-id="${s.id}">Start</button>
|
||||
<button data-act="stop" data-id="${s.id}" class="ghost">Stop</button>
|
||||
|
|
@ -89,6 +157,60 @@
|
|||
}[c]));
|
||||
}
|
||||
|
||||
function readVariantToggles(root) {
|
||||
const cards = root.querySelectorAll(".variant-card input[data-id]");
|
||||
const out = [];
|
||||
cards.forEach((input) => {
|
||||
const id = input.dataset.id;
|
||||
const height = Number(input.dataset.height || 0);
|
||||
const enabled = id === "fhd" ? true : !!input.checked;
|
||||
const item = {
|
||||
id,
|
||||
label: id.toUpperCase(),
|
||||
enabled,
|
||||
height: id === "fhd" ? 0 : height,
|
||||
};
|
||||
if (height > 0) {
|
||||
item.video_bitrate = input.dataset.vbr || "";
|
||||
item.audio_bitrate = input.dataset.abr || "";
|
||||
}
|
||||
out.push(item);
|
||||
});
|
||||
return out;
|
||||
}
|
||||
|
||||
function setVariantToggles(root, variants) {
|
||||
const byId = {};
|
||||
(variants || []).forEach((v) => { byId[v.id] = v; });
|
||||
root.querySelectorAll(".variant-card input[data-id]").forEach((input) => {
|
||||
const id = input.dataset.id;
|
||||
if (id === "fhd") {
|
||||
input.checked = true;
|
||||
return;
|
||||
}
|
||||
const v = byId[id];
|
||||
input.checked = !!(v && v.enabled);
|
||||
const card = input.closest(".variant-card");
|
||||
if (card) card.classList.toggle("on", input.checked);
|
||||
});
|
||||
}
|
||||
|
||||
function wireVariantCards(root) {
|
||||
root.querySelectorAll(".variant-card").forEach((card) => {
|
||||
const input = card.querySelector("input[type=checkbox]");
|
||||
if (!input || input.disabled) {
|
||||
card.classList.add("on");
|
||||
return;
|
||||
}
|
||||
const sync = () => card.classList.toggle("on", input.checked);
|
||||
input.addEventListener("change", sync);
|
||||
sync();
|
||||
});
|
||||
}
|
||||
|
||||
wireVariantCards(document.getElementById("create-variants"));
|
||||
wireVariantCards(document.getElementById("edit-variants"));
|
||||
|
||||
function renderAgents(list) {
|
||||
if (!agentsEl) return;
|
||||
if (!list || !list.length) {
|
||||
|
|
@ -135,8 +257,6 @@
|
|||
}
|
||||
}
|
||||
|
||||
// App/channel pickers come from the binary's compiled-in modules, so the UI
|
||||
// never hardcodes a provider.
|
||||
const appSel = document.getElementById("app-select");
|
||||
const chanSel = document.getElementById("channel-select");
|
||||
let apps = [];
|
||||
|
|
@ -193,6 +313,7 @@
|
|||
formMsg.classList.remove("err");
|
||||
const fd = new FormData(ev.target);
|
||||
const body = Object.fromEntries(fd.entries());
|
||||
body.variants = readVariantToggles(document.getElementById("create-variants"));
|
||||
try {
|
||||
await api("/api/streams", {
|
||||
method: "POST",
|
||||
|
|
@ -201,6 +322,11 @@
|
|||
});
|
||||
ev.target.reset();
|
||||
ev.target.headers_json.value = "{}";
|
||||
setVariantToggles(document.getElementById("create-variants"), [
|
||||
{ id: "fhd", enabled: true },
|
||||
{ id: "hd", enabled: false },
|
||||
{ id: "sd", enabled: false },
|
||||
]);
|
||||
fillChannels();
|
||||
formMsg.textContent = "Created.";
|
||||
refresh();
|
||||
|
|
@ -213,8 +339,12 @@
|
|||
rowsEl.addEventListener("click", async (ev) => {
|
||||
const btn = ev.target.closest("button[data-act]");
|
||||
if (!btn) return;
|
||||
const id = btn.dataset.id;
|
||||
const act = btn.dataset.act;
|
||||
if (act === "copy-link") {
|
||||
copyText(btn.dataset.url || "");
|
||||
return;
|
||||
}
|
||||
const id = btn.dataset.id;
|
||||
try {
|
||||
if (act === "delete") {
|
||||
if (!confirm("Delete stream #" + id + "?")) return;
|
||||
|
|
@ -234,6 +364,7 @@
|
|||
editForm.key.value = st.key || "";
|
||||
if (editForm.proxy) editForm.proxy.value = st.proxy || "";
|
||||
editForm.headers_json.value = st.headers_json || "{}";
|
||||
setVariantToggles(document.getElementById("edit-variants"), st.variants || []);
|
||||
dlg.showModal();
|
||||
return;
|
||||
} else {
|
||||
|
|
@ -261,6 +392,7 @@
|
|||
key: editForm.key.value,
|
||||
proxy: editForm.proxy ? editForm.proxy.value : "",
|
||||
headers_json: editForm.headers_json.value,
|
||||
variants: readVariantToggles(document.getElementById("edit-variants")),
|
||||
};
|
||||
try {
|
||||
await api("/api/streams/" + id, {
|
||||
|
|
|
|||
|
|
@ -31,6 +31,27 @@
|
|||
<label class="span2">key <textarea name="key" rows="3" placeholder="optional — KID:KEY lines (clear streams like BBC need no keys)" spellcheck="false"></textarea></label>
|
||||
<label class="span2">proxy <input name="proxy" placeholder="optional — socks5://127.0.0.1:1080 or http://127.0.0.1:8080 (origin fetch)" /></label>
|
||||
<label class="span2">headers JSON <input name="headers_json" value="{}" /></label>
|
||||
<fieldset class="span2 variants-field">
|
||||
<legend>Output variants</legend>
|
||||
<p class="hint">FHD is the source copy. Enable HD / SD to also publish scaled HLS playlists as separate streams.</p>
|
||||
<div class="variant-toggles" id="create-variants">
|
||||
<label class="variant-card on locked">
|
||||
<input type="checkbox" data-id="fhd" checked disabled />
|
||||
<span class="v-title">FHD</span>
|
||||
<span class="v-meta">source · copy</span>
|
||||
</label>
|
||||
<label class="variant-card">
|
||||
<input type="checkbox" data-id="hd" data-height="720" data-vbr="2800k" data-abr="128k" />
|
||||
<span class="v-title">HD</span>
|
||||
<span class="v-meta">720p · 2800k</span>
|
||||
</label>
|
||||
<label class="variant-card">
|
||||
<input type="checkbox" data-id="sd" data-height="480" data-vbr="1200k" data-abr="96k" />
|
||||
<span class="v-title">SD</span>
|
||||
<span class="v-meta">480p · 1200k</span>
|
||||
</label>
|
||||
</div>
|
||||
</fieldset>
|
||||
<div class="span2 actions">
|
||||
<button type="submit">Create</button>
|
||||
</div>
|
||||
|
|
@ -55,7 +76,7 @@
|
|||
<th>health</th>
|
||||
<th>claim</th>
|
||||
<th>age</th>
|
||||
<th>play</th>
|
||||
<th>links</th>
|
||||
<th>actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
|
@ -75,6 +96,27 @@
|
|||
<label class="span2">key <textarea name="key" rows="3" placeholder="optional — KID:KEY (one per line)" spellcheck="false"></textarea></label>
|
||||
<label class="span2">proxy <input name="proxy" placeholder="socks5://127.0.0.1:1080" /></label>
|
||||
<label class="span2">headers JSON <input name="headers_json" /></label>
|
||||
<fieldset class="span2 variants-field">
|
||||
<legend>Output variants</legend>
|
||||
<p class="hint">Each enabled rung publishes its own <code>m3u8</code>. FHD stays the source; HD/SD are live-transcoded.</p>
|
||||
<div class="variant-toggles" id="edit-variants">
|
||||
<label class="variant-card on locked">
|
||||
<input type="checkbox" data-id="fhd" checked disabled />
|
||||
<span class="v-title">FHD</span>
|
||||
<span class="v-meta">source · copy</span>
|
||||
</label>
|
||||
<label class="variant-card">
|
||||
<input type="checkbox" data-id="hd" data-height="720" data-vbr="2800k" data-abr="128k" />
|
||||
<span class="v-title">HD</span>
|
||||
<span class="v-meta">720p · 2800k</span>
|
||||
</label>
|
||||
<label class="variant-card">
|
||||
<input type="checkbox" data-id="sd" data-height="480" data-vbr="1200k" data-abr="96k" />
|
||||
<span class="v-title">SD</span>
|
||||
<span class="v-meta">480p · 1200k</span>
|
||||
</label>
|
||||
</div>
|
||||
</fieldset>
|
||||
<div class="span2 actions">
|
||||
<button type="submit" value="save">Save</button>
|
||||
<button type="button" id="edit-cancel" class="ghost">Cancel</button>
|
||||
|
|
@ -82,6 +124,8 @@
|
|||
</form>
|
||||
</dialog>
|
||||
|
||||
<div id="toast" class="toast" hidden></div>
|
||||
|
||||
<script src="/static/app.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue