nixamp 0.7.41 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/catalogs.d.ts +100 -0
- package/dist/catalogs.js +0 -0
- package/dist/channels.d.ts +17 -0
- package/dist/channels.js +45 -0
- package/dist/owner.js +4 -0
- package/dist/server.d.ts +9 -0
- package/dist/server.js +141 -0
- package/package.json +1 -1
- package/src/catalogs.ts +0 -0
- package/src/channels.ts +41 -0
- package/src/owner.ts +3 -0
- package/src/server.ts +151 -0
- package/web/dist/assets/{hls-3VKVEQE3-70uzupqn.js → hls-3VKVEQE3-DIpul2Yc.js} +1 -1
- package/web/dist/assets/index-BqirNVEK.js +1 -0
- package/web/dist/assets/index-C-gJFEFf.css +1 -0
- package/web/dist/assets/{mpegts-DQqgM7pi.js → mpegts-DQ14PwSl.js} +1 -1
- package/web/dist/assets/{mpegts-LO6RVLD6-CzrQKX7m.js → mpegts-LO6RVLD6-Cq2NKawM.js} +1 -1
- package/web/dist/index.html +23 -2
- package/web/dist/sw.js +6 -6
- package/web/dist/assets/index-ComwKkzf.js +0 -1
- package/web/dist/assets/index-D3xGDAOd.css +0 -1
package/src/server.ts
CHANGED
|
@@ -55,6 +55,7 @@ import { CALL_IN_NUMBER, OPT_IN_PATH, optInPage } from "./optin.ts";
|
|
|
55
55
|
import pg from "pg";
|
|
56
56
|
import { Follows, phoneFrom } from "./follows.ts";
|
|
57
57
|
import { Favorites, favoriteUrl } from "./favorites.ts";
|
|
58
|
+
import { Catalogs, shownCatalog, shownEntry } from "./catalogs.ts";
|
|
58
59
|
import { Durable } from "./durable.ts";
|
|
59
60
|
import { notifyAll, resendEmail, webPush, type Notification } from "./notify.ts";
|
|
60
61
|
import { confirm, DEFAULT_DIRECTORY, Publisher } from "./publish.ts";
|
|
@@ -912,6 +913,13 @@ export class PlayerEngine implements Engine {
|
|
|
912
913
|
* looking at what is on wants "that album from the web", not every track in
|
|
913
914
|
* it. An entry names where to start, so clicking it plays.
|
|
914
915
|
*/
|
|
916
|
+
/**
|
|
917
|
+
* How many channels a server will start on demand at once. Each is an ffmpeg,
|
|
918
|
+
* and a catalog has thousands of entries; this is what keeps a room full of
|
|
919
|
+
* curious people from becoming a room full of decoders.
|
|
920
|
+
*/
|
|
921
|
+
export const MAX_ON_DEMAND = 4;
|
|
922
|
+
|
|
915
923
|
/**
|
|
916
924
|
* Probe a source and start carrying it as a channel of its own.
|
|
917
925
|
*
|
|
@@ -1095,6 +1103,8 @@ export interface HandlerOptions {
|
|
|
1095
1103
|
channels?: Channels;
|
|
1096
1104
|
/** Write down the channels this server pulls, so a restart puts them back. */
|
|
1097
1105
|
rememberChannels?: (list: RememberedChannel[]) => void;
|
|
1106
|
+
/** The m3u catalogs this server keeps, browsable by group. */
|
|
1107
|
+
catalogs?: Catalogs;
|
|
1098
1108
|
/** Live audio going out to RTMP. */
|
|
1099
1109
|
broadcaster?: Broadcaster;
|
|
1100
1110
|
/** Where a broadcast should send, and what it should look like. */
|
|
@@ -2293,6 +2303,140 @@ export function createHandler(engine: Engine, options: HandlerOptions) {
|
|
|
2293
2303
|
|
|
2294
2304
|
// --- several streams at once ------------------------------------------
|
|
2295
2305
|
//
|
|
2306
|
+
// --- catalogs: m3u lists you can browse ---------------------------------
|
|
2307
|
+
//
|
|
2308
|
+
// An IPTV list is thousands of entries with groups and logos. Kept as a
|
|
2309
|
+
// catalog it stays browsable; poured into the playlist it was three
|
|
2310
|
+
// thousand flat rows. Anyone with the link browses and plays; adding,
|
|
2311
|
+
// refreshing and removing is administering (see needsAdmin).
|
|
2312
|
+
if ((path === "/api/catalogs" || path.startsWith("/api/catalogs/")) && options.catalogs) {
|
|
2313
|
+
const catalogs = options.catalogs;
|
|
2314
|
+
|
|
2315
|
+
if (path === "/api/catalogs" && request.method === "GET") {
|
|
2316
|
+
// Where a list is read from is the administrator's business, not a
|
|
2317
|
+
// listener's: it can carry a provider's credentials in the URL.
|
|
2318
|
+
const holdsControl = key === null || scopeOf(keyFrom(request, url), key, null) === "control";
|
|
2319
|
+
const admin = options.owner
|
|
2320
|
+
? (await options.owner.check(holdsControl, tokenFrom(request.headers))).allowed
|
|
2321
|
+
: holdsControl;
|
|
2322
|
+
json(response, 200, { catalogs: catalogs.list().map((one) => shownCatalog(one, admin)) });
|
|
2323
|
+
return;
|
|
2324
|
+
}
|
|
2325
|
+
|
|
2326
|
+
if (path === "/api/catalogs" && request.method === "POST") {
|
|
2327
|
+
let body: { source?: unknown; name?: unknown } = {};
|
|
2328
|
+
try {
|
|
2329
|
+
body = JSON.parse(await readBody(request)) as typeof body;
|
|
2330
|
+
} catch {
|
|
2331
|
+
json(response, 400, { error: "bad JSON" });
|
|
2332
|
+
return;
|
|
2333
|
+
}
|
|
2334
|
+
try {
|
|
2335
|
+
const added = await catalogs.add(String(body.source ?? ""), String(body.name ?? ""));
|
|
2336
|
+
json(response, added.error ? 422 : 200, {
|
|
2337
|
+
ok: !added.error,
|
|
2338
|
+
catalog: shownCatalog(added, true),
|
|
2339
|
+
...(added.error ? { error: added.error } : {}),
|
|
2340
|
+
});
|
|
2341
|
+
} catch (error) {
|
|
2342
|
+
json(response, 422, { error: (error as Error).message.replace(/^nixamp: /, "") });
|
|
2343
|
+
}
|
|
2344
|
+
return;
|
|
2345
|
+
}
|
|
2346
|
+
|
|
2347
|
+
const [rawId = "", action = "", entryId = "", sub = ""] = path.slice("/api/catalogs/".length).split("/");
|
|
2348
|
+
const id = decodeURIComponent(rawId);
|
|
2349
|
+
if (!catalogs.get(id)) {
|
|
2350
|
+
json(response, 404, { error: "no such catalog" });
|
|
2351
|
+
return;
|
|
2352
|
+
}
|
|
2353
|
+
|
|
2354
|
+
if (action === "" && request.method === "DELETE") {
|
|
2355
|
+
json(response, 200, { ok: catalogs.remove(id) });
|
|
2356
|
+
return;
|
|
2357
|
+
}
|
|
2358
|
+
if (action === "refresh" && request.method === "POST") {
|
|
2359
|
+
const refreshed = await catalogs.refresh(id);
|
|
2360
|
+
json(response, refreshed && !refreshed.error ? 200 : 422, {
|
|
2361
|
+
ok: refreshed !== null && !refreshed.error,
|
|
2362
|
+
...(refreshed ? { catalog: shownCatalog(refreshed, true) } : {}),
|
|
2363
|
+
...(refreshed?.error ? { error: refreshed.error } : {}),
|
|
2364
|
+
});
|
|
2365
|
+
return;
|
|
2366
|
+
}
|
|
2367
|
+
if (action === "groups" && request.method === "GET") {
|
|
2368
|
+
json(response, 200, { groups: catalogs.groups(id) ?? [] });
|
|
2369
|
+
return;
|
|
2370
|
+
}
|
|
2371
|
+
if (action === "entries" && entryId === "" && request.method === "GET") {
|
|
2372
|
+
const page = catalogs.entries_(id, {
|
|
2373
|
+
group: url.searchParams.get("group") ?? "",
|
|
2374
|
+
q: url.searchParams.get("q") ?? "",
|
|
2375
|
+
offset: Number(url.searchParams.get("offset") ?? "0") || 0,
|
|
2376
|
+
limit: Number(url.searchParams.get("limit") ?? "200") || 200,
|
|
2377
|
+
}) ?? { total: 0, entries: [] };
|
|
2378
|
+
json(response, 200, { total: page.total, entries: page.entries.map(shownEntry) });
|
|
2379
|
+
return;
|
|
2380
|
+
}
|
|
2381
|
+
|
|
2382
|
+
const entry = action === "entries" && entryId !== "" ? catalogs.entry(id, decodeURIComponent(entryId)) : null;
|
|
2383
|
+
if (!entry) {
|
|
2384
|
+
json(response, 404, { error: "no such entry" });
|
|
2385
|
+
return;
|
|
2386
|
+
}
|
|
2387
|
+
|
|
2388
|
+
// Play. A live entry becomes a channel, started for whoever asked and
|
|
2389
|
+
// stopped a minute after the last viewer leaves; a film is played on
|
|
2390
|
+
// its own, straight from the source through ffmpeg.
|
|
2391
|
+
if (sub === "play" && request.method === "POST") {
|
|
2392
|
+
if (!entry.live) {
|
|
2393
|
+
json(response, 200, {
|
|
2394
|
+
kind: "vod",
|
|
2395
|
+
url: `/api/catalogs/${encodeURIComponent(id)}/entries/${encodeURIComponent(entry.id)}/stream`,
|
|
2396
|
+
name: entry.title,
|
|
2397
|
+
});
|
|
2398
|
+
return;
|
|
2399
|
+
}
|
|
2400
|
+
if (!options.channels) {
|
|
2401
|
+
json(response, 503, { error: "this server cannot carry channels" });
|
|
2402
|
+
return;
|
|
2403
|
+
}
|
|
2404
|
+
const channelId = cleanId(`cat-${entry.id}`);
|
|
2405
|
+
if (!options.channels.has(channelId)) {
|
|
2406
|
+
if (options.channels.ephemeralCount >= MAX_ON_DEMAND) {
|
|
2407
|
+
json(response, 429, { error: `this server is already carrying ${MAX_ON_DEMAND} channels on demand; try again in a minute` });
|
|
2408
|
+
return;
|
|
2409
|
+
}
|
|
2410
|
+
const started = await pullChannel(options.channels, options.ffprobe ?? ["ffprobe"], channelId, entry.title, entry.source);
|
|
2411
|
+
if (!started) {
|
|
2412
|
+
json(response, 409, { error: "that channel is already starting" });
|
|
2413
|
+
return;
|
|
2414
|
+
}
|
|
2415
|
+
options.channels.ephemeral(channelId);
|
|
2416
|
+
}
|
|
2417
|
+
json(response, 200, { kind: "live", channel: channelId, name: entry.title });
|
|
2418
|
+
return;
|
|
2419
|
+
}
|
|
2420
|
+
|
|
2421
|
+
if (sub === "stream" && request.method === "GET") {
|
|
2422
|
+
if (!options.media) {
|
|
2423
|
+
json(response, 403, { error: "media streaming is off" });
|
|
2424
|
+
return;
|
|
2425
|
+
}
|
|
2426
|
+
watch(request, response, "stream", entry.title);
|
|
2427
|
+
const codecs = await codecsOf({ ffmpeg: [], ffprobe: options.ffprobe ?? ["ffprobe"], play: null }, entry.source);
|
|
2428
|
+
if (codecs.video !== "") {
|
|
2429
|
+
pipeFfmpeg(request, response, entry.source, options.ffmpeg ?? ["ffmpeg"], videoArgs(codecs), "video/mp4");
|
|
2430
|
+
} else {
|
|
2431
|
+
transcode(request, response, entry.source, options.ffmpeg ?? ["ffmpeg"]);
|
|
2432
|
+
}
|
|
2433
|
+
return;
|
|
2434
|
+
}
|
|
2435
|
+
|
|
2436
|
+
json(response, 404, { error: "no such endpoint" });
|
|
2437
|
+
return;
|
|
2438
|
+
}
|
|
2439
|
+
|
|
2296
2440
|
// A channel is one publisher and everybody listening to them. Two or three
|
|
2297
2441
|
// devices can publish at once, each to their own channel, and a listener
|
|
2298
2442
|
// picks which to hear.
|
|
@@ -3393,6 +3537,12 @@ export async function serve(argv: string[], version = "0.1.0"): Promise<void> {
|
|
|
3393
3537
|
});
|
|
3394
3538
|
}
|
|
3395
3539
|
|
|
3540
|
+
// The m3u catalogs kept here: read from disk now, and any that were never
|
|
3541
|
+
// read are fetched in the background so browsing does not wait on a provider.
|
|
3542
|
+
const catalogs = new Catalogs(stateDir(), options.port);
|
|
3543
|
+
catalogs.load();
|
|
3544
|
+
void catalogs.warm().catch(() => undefined);
|
|
3545
|
+
|
|
3396
3546
|
const destinations = parseDestinations(options.rtmp);
|
|
3397
3547
|
const broadcaster = new Broadcaster(tools.ffmpeg);
|
|
3398
3548
|
const ingest = options.ingest
|
|
@@ -3595,6 +3745,7 @@ export async function serve(argv: string[], version = "0.1.0"): Promise<void> {
|
|
|
3595
3745
|
owner,
|
|
3596
3746
|
channels,
|
|
3597
3747
|
rememberChannels: remembering,
|
|
3748
|
+
catalogs,
|
|
3598
3749
|
publishUrls: () => publishUrls,
|
|
3599
3750
|
serverName: options.name || hostname(),
|
|
3600
3751
|
homeSource: root,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{t as e}from"./index-
|
|
1
|
+
import{t as e}from"./index-BqirNVEK.js";var t=3;async function n(n){let{media:r,src:i,isTv:a}=n,{default:o}=await e(async()=>{let{default:e}=await import(`./hls-n74Cnh8A.js`);return{default:e}},[]);if(!o.isSupported())return n.onError(`This browser cannot play HLS streams.`),{destroy:()=>void 0,levels:()=>[]};let s=new o({...a?{maxBufferLength:60,maxMaxBufferLength:120,backBufferLength:30,liveSyncDurationCount:4}:{backBufferLength:90},enableWorker:!0}),c=0,l=!1;s.on(o.Events.ERROR,(e,r)=>{if(!l&&r.fatal){if(c>=t){n.onError(`This stream kept failing and has been stopped.`),s.destroy();return}switch(c+=1,r.type){case o.ErrorTypes.NETWORK_ERROR:n.onNotice(`Reconnecting…`),s.startLoad();break;case o.ErrorTypes.MEDIA_ERROR:n.onNotice(`Recovering…`),s.recoverMediaError();break;default:n.onError(`This stream could not be played.`),s.destroy()}}}),s.on(o.Events.MANIFEST_PARSED,()=>{l||(n.onNotice(null),n.onReady?.({live:s.levels.length>0&&!Number.isFinite(r.duration),levels:u()}))}),s.on(o.Events.LEVEL_LOADED,(e,t)=>{l||n.onReady?.({live:t.details.live,levels:u()})}),s.on(o.Events.FRAG_BUFFERED,()=>{l||n.onNotice(null)});function u(){return s.levels.map((e,t)=>({index:t,height:e.height||null,bitrate:e.bitrate||null,label:e.height?`${String(e.height)}p`:`${String(Math.round((e.bitrate||0)/1e3))}k`}))}return s.loadSource(i),s.attachMedia(r),{destroy(){l=!0,s.destroy()},levels:u,setLevel(e){s.currentLevel=e},currentLevel:()=>s.autoLevelEnabled?-1:s.currentLevel}}export{n as createHlsEngine};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(function(){let e=document.createElement(`link`).relList;if(e&&e.supports&&e.supports(`modulepreload`))return;for(let e of document.querySelectorAll(`link[rel="modulepreload"]`))n(e);new MutationObserver(e=>{for(let t of e)if(t.type===`childList`)for(let e of t.addedNodes)e.tagName===`LINK`&&e.rel===`modulepreload`&&n(e)}).observe(document,{childList:!0,subtree:!0});function t(e){let t={};return e.integrity&&(t.integrity=e.integrity),e.referrerPolicy&&(t.referrerPolicy=e.referrerPolicy),t.credentials=e.crossOrigin===`use-credentials`?`include`:e.crossOrigin===`anonymous`?`omit`:`same-origin`,t}function n(e){if(e.ep)return;e.ep=!0;let n=t(e);fetch(e.href,n)}})();function e(e){if(!Number.isFinite(e)||e<0)return`--:--`;let t=Math.floor(e),n=Math.floor(t/60),r=t%60;return`${String(n).padStart(2,`0`)}:${String(r).padStart(2,`0`)}`}function t(e){return e.artist?`${e.artist} — ${e.title}`:e.title}function n(e){let t=e.split(`/`).pop()??e,n=t.lastIndexOf(`.`);return n>0?t.slice(0,n):t}var r=new Set([`mp4`,`webm`,`mkv`,`mov`,`m4v`,`ogv`,`avi`]);function i(e,t=``){if(t.startsWith(`video/`))return!0;if(t.startsWith(`audio/`))return!1;let n=e.lastIndexOf(`.`);return n>0&&r.has(e.slice(n+1).toLowerCase())}var a=`modulepreload`,o=function(e){return`/`+e},s={},c=function(e,t,n){let r=Promise.resolve();if(t&&t.length>0){let e=document.getElementsByTagName(`link`),i=document.querySelector(`meta[property=csp-nonce]`),c=i?.nonce||i?.getAttribute(`nonce`);function l(e){return Promise.all(e.map(e=>Promise.resolve(e).then(e=>({status:`fulfilled`,value:e}),e=>({status:`rejected`,reason:e}))))}function u(e){return import.meta.resolve?import.meta.resolve(e):new URL(e,import.meta.url).href}r=l(t.map(t=>{if(t=o(t,n),t=u(t),t in s)return;s[t]=!0;let r=t.endsWith(`.css`);for(let n=e.length-1;n>=0;n--){let i=e[n];if(i.href===t&&(!r||i.rel===`stylesheet`))return}let i=document.createElement(`link`);if(i.rel=r?`stylesheet`:a,r||(i.as=`script`),i.crossOrigin=``,i.href=t,c&&i.setAttribute(`nonce`,c),document.head.appendChild(i),r)return new Promise((e,n)=>{i.addEventListener(`load`,e),i.addEventListener(`error`,()=>n(Error(`Unable to preload CSS for ${t}`)))})}))}function i(e){let t=new Event(`vite:preloadError`,{cancelable:!0});if(t.payload=e,window.dispatchEvent(t),!t.defaultPrevented)throw e}return r.then(t=>{for(let e of t||[])e.status===`rejected`&&i(e.reason);return e().catch(i)})},l=[[/\.m3u8$/i,`hls`],[/\.(ts|mts|m2ts|mpegts)$/i,`mpegts`],[/\.(mp3|m4a|aac|oga|ogg|opus|wav|flac)$/i,`audio`],[/\.(mp4|m4v|webm|mov|ogv)$/i,`mp4`]],u=[[/mpegurl/i,`hls`],[/mp2t|mpeg-?ts/i,`mpegts`],[/^audio\//i,`audio`],[/^video\//i,`mp4`]];function d(e){if(e.kind)return e.kind;if(e.mimeType){for(let[t,n]of u)if(t.test(e.mimeType))return n}let t=f(e.src);for(let[e,n]of l)if(e.test(t))return n;return`unknown`}function f(e){try{return new URL(e,`https://placeholder.invalid`).pathname}catch{return e.split(/[?#]/)[0]??e}}function p(e=globalThis,t=null){let n=e.MediaSource!==void 0,r=!1;try{let e=t??(typeof document>`u`?null:document.createElement(`video`));r=e?e.canPlayType(`application/vnd.apple.mpegurl`)!==``||e.canPlayType(`application/x-mpegURL`)!==``:!1}catch{r=!1}return{mediaSource:n,nativeHls:r}}function m(e,t){let n=d(e);switch(n){case`hls`:return t.mediaSource?{engine:`hls`,kind:n}:t.nativeHls?{engine:`native`,kind:n}:{engine:`native`,kind:n,unplayable:`This browser cannot play HLS streams.`};case`mpegts`:return t.mediaSource?{engine:`mpegts`,kind:n}:{engine:`mpegts`,kind:n,unplayable:`This browser cannot play transport streams.`};default:return{engine:`native`,kind:n}}}async function h(e,t){let n=t.capabilities??p(),r=m({src:t.src,...t.kind?{kind:t.kind}:{},...t.mimeType?{mimeType:t.mimeType}:{}},n),i=()=>void 0,a={media:e,src:t.src,isTv:t.isTv??!1,live:t.live??r.kind===`mpegts`,onError:t.onError??i,onNotice:t.onNotice??i,...t.onReady?{onReady:t.onReady}:{}};if(r.unplayable)return t.onError?.(r.unplayable),{destroy:i,engine:r.engine,kind:r.kind,levels:()=>[],unplayable:r.unplayable};let o,s=t.engines?.[r.engine];if(s)o=await s(a);else if(r.engine===`hls`){let{createHlsEngine:e}=await c(async()=>{let{createHlsEngine:e}=await import(`./hls-3VKVEQE3-DIpul2Yc.js`);return{createHlsEngine:e}},[]);o=await e(a)}else if(r.engine===`mpegts`){let{createMpegtsEngine:e}=await c(async()=>{let{createMpegtsEngine:e}=await import(`./mpegts-LO6RVLD6-Cq2NKawM.js`);return{createMpegtsEngine:e}},[]);o=await e(a,{withCredentials:t.withCredentials??!1,unplayableAdvice:t.unplayableAdvice??``})}else{let{createNativeEngine:e}=await c(async()=>{let{createNativeEngine:e}=await import(`./native-C7JTKWJH-BUyIoj0P.js`);return{createNativeEngine:e}},[]);o=await e(a)}return{destroy:()=>{o.destroy()},engine:r.engine,kind:r.kind,levels:o.levels,...o.setLevel?{setLevel:o.setLevel}:{},...o.currentLevel?{currentLevel:o.currentLevel}:{}}}var g=new Set([`mp3`,`flac`,`ogg`,`oga`,`opus`,`m4a`,`aac`,`wav`,`wma`,`aiff`,`aif`,`alac`,`mp4`,`webm`,`mkv`,`mov`,`m4v`,`ogv`]);function _(e,t=``){if(t.startsWith(`audio/`)||t.startsWith(`video/`))return!0;let n=e.lastIndexOf(`.`);return n>0&&g.has(e.slice(n+1).toLowerCase())}function v(e,t){return e.localeCompare(t,void 0,{numeric:!0,sensitivity:`base`})}function ee(e){return e.filter(e=>_(e.name,e.type)).sort((e,t)=>v(y(e),y(t))).map(e=>({title:n(e.name),artist:``,album:te(y(e)),duration:0,url:URL.createObjectURL(e),video:i(e.name,e.type),objectUrl:!0}))}function y(e){return e.webkitRelativePath||e.name}function te(e){let t=e.split(`/`);return t.length>1?t[t.length-2]:``}function ne(e){for(let t of e)t.objectUrl&&URL.revokeObjectURL(t.url)}var b=2048;function x(e,t){return e||t===`hls`||t===`mpegts`}var re=class{elements;handlers;attached=null;context=null;analyser=null;wired=new WeakSet;active;frequencies=new Uint8Array;constructor(e,t){this.elements=e,this.handlers=t,this.active=e.audio;for(let t of[e.audio,e.video])t.crossOrigin=`anonymous`,t.addEventListener(`timeupdate`,()=>{t===this.active&&this.handlers.onTime(t.currentTime,Number.isFinite(t.duration)?t.duration:0)}),t.addEventListener(`loadedmetadata`,()=>{t===this.active&&this.handlers.onTime(t.currentTime,Number.isFinite(t.duration)?t.duration:0)}),t.addEventListener(`ended`,()=>{t===this.active&&this.handlers.onEnded()}),t.addEventListener(`play`,()=>{t===this.active&&this.handlers.onState(!0)}),t.addEventListener(`pause`,()=>{t===this.active&&this.handlers.onState(!1)}),t.addEventListener(`error`,()=>{t===this.active&&this.handlers.onError(S(t))})}get playing(){return!this.active.paused&&!this.active.ended}get position(){return this.active.currentTime}get duration(){return Number.isFinite(this.active.duration)?this.active.duration:0}get showingVideo(){return this.active===this.elements.video}ensureGraph(e){let t=globalThis.AudioContext??globalThis.webkitAudioContext;if(t){if(this.context??=new t,this.analyser||(this.analyser=this.context.createAnalyser(),this.analyser.fftSize=b,this.analyser.smoothingTimeConstant=.6,this.analyser.connect(this.context.destination),this.frequencies=new Uint8Array(this.analyser.frequencyBinCount)),!this.wired.has(e))try{this.context.createMediaElementSource(e).connect(this.analyser),this.wired.add(e)}catch{this.wired.add(e)}this.context.resume()}}read(){return this.analyser&&this.analyser.getByteFrequencyData(this.frequencies),this.frequencies}levels(){if(!this.analyser)return[0,0];let e=this.read(),t=0;for(let n of e)t+=n;let n=e.length===0?0:t/e.length/255;return[Math.min(1,n*2.2),Math.min(1,n*2.2)]}async load(e,t){let n=e.objectUrl?e.video?`mp4`:`audio`:d({src:e.url}),r=x(e.video,n)?this.elements.video:this.elements.audio;r!==this.active&&(this.active.pause(),this.active.removeAttribute(`src`),this.active.load(),this.active=r),this.attached?.destroy(),this.attached=null;try{this.attached=await h(this.active,{src:e.url,kind:n,unplayableAdvice:`VLC or mpv will play it; nixamp can only hand it to your browser.`,onError:e=>this.handlers.onError(e),onNotice:e=>{e&&this.handlers.onError(e)}})}catch(e){this.handlers.onError(e instanceof Error?e.message:`that would not play`);return}t&&await this.play()}async play(){this.ensureGraph(this.active);try{await this.active.play()}catch(e){this.handlers.onError(e instanceof Error?e.message:`playback was refused`)}}pause(){this.active.pause()}stop(){this.active.pause(),this.active.currentTime=0,this.attached?.destroy(),this.attached=null}seek(e){Number.isFinite(e)&&(this.active.currentTime=Math.max(0,e))}set volume(e){this.elements.audio.volume=e,this.elements.video.volume=e}get volume(){return this.active.volume}};function S(e){switch(e.error?.code){case MediaError.MEDIA_ERR_ABORTED:return`playback was aborted`;case MediaError.MEDIA_ERR_NETWORK:return`the network dropped mid-track`;case MediaError.MEDIA_ERR_DECODE:return`this browser could not decode that`;case MediaError.MEDIA_ERR_SRC_NOT_SUPPORTED:return`this browser cannot play that format`;default:return`playback failed`}}function ie(){return{revision:0,tracks:[],trackCount:0,index:0,playing:!1,position:0,bars:[],levels:[0,0],silent:!0,note:``,root:``}}function ae(e,t){return{...t,tracks:t.tracks??e.tracks}}function C(e){let t=e.trim();if(t===``)return``;/^https?:\/\//i.test(t)||(t=`http://${t}`);let n;try{n=new URL(t)}catch{return``}let r=n.pathname.replace(/\/+$/,``);return r=r.replace(/\/api(\/.*)?$/,``),`${n.origin}${r}`}function w(e,t,n=``){let r=`${e===``?``:C(e)}${t.startsWith(`/`)?t:`/${t}`}`;return n?`${r}${r.includes(`?`)?`&`:`?`}k=${encodeURIComponent(n)}`:r}function oe(e){let t=e.trim();if(t===``)return{base:``,key:``};let n;try{n=new URL(/^https?:\/\//i.test(t)?t:`http://${t}`)}catch{return{base:``,key:``}}let r=/^\/(?:admin|view|a|v)\/([^/]+)\/?$/.exec(n.pathname),i=r?.[1]??n.searchParams.get(`k`)??``;return r&&(n.pathname=`/`),n.searchParams.delete(`k`),{base:C(`${n.origin}${n.pathname}`),key:decodeURIComponent(i)}}function se(e,t,n=0,r=``){return w(e,n>0?`/api/media/${t}?kbps=${Math.round(n)}`:`/api/media/${t}`,r)}function T(e){if(typeof e!=`object`||!e)return null;let t=e,n=ie(),r=(e,t)=>typeof e==`number`&&Number.isFinite(e)?e:t,i=Array.isArray(t.levels)?t.levels:[],a=Array.isArray(t.tracks)?t.tracks.map(e=>{let t=typeof e==`object`&&e?e:{};return{title:typeof t.title==`string`?t.title:`Untitled`,artist:typeof t.artist==`string`?t.artist:``,album:typeof t.album==`string`?t.album:``,duration:r(t.duration,0),...t.video===!0?{video:!0}:{},...typeof t.group==`string`&&t.group!==``?{group:t.group}:{},...typeof t.folder==`string`&&t.folder!==``?{folder:t.folder}:{},...t.remote===!0?{remote:!0}:{}}}):void 0;return{revision:r(t.revision,0),...a?{tracks:a}:{},trackCount:r(t.trackCount,a?.length??0),index:r(t.index,0),playing:t.playing===!0,position:r(t.position,0),bars:Array.isArray(t.bars)?t.bars.map(e=>r(e,0)):[],levels:[r(i[0],0),r(i[1],0)],silent:t.silent===!0,note:typeof t.note==`string`?t.note:``,root:typeof t.root==`string`?t.root:n.root}}var ce=class{handlers;source=null;base=``;key=``;shape=`/admin/`;lastRevision=-1;constructor(e){this.handlers=e}get address(){return this.base}url(e){return w(this.base,e,this.key)}get shareLink(){return this.base===``?``:this.key===``?this.base:`${this.base}${this.shape}${this.key}`}get connected(){return this.source!==null}connect(e){let{base:t,key:n}=oe(e);this.close(),this.base=t,this.key=n,this.shape=/\/(?:view|v)\/[^/]+\/?$/.test(e.trim())?`/view/`:`/admin/`,this.lastRevision=-1,this.handlers.onStatus(`connecting`);let r=new EventSource(w(t,`/api/events`,n));this.source=r,r.onopen=()=>this.handlers.onStatus(`live`),r.onmessage=e=>{let t=T(le(e.data));t&&(t.revision<this.lastRevision||(this.lastRevision=t.revision,this.handlers.onStatus(`live`),this.handlers.onSnapshot(t)))},r.onerror=()=>{this.handlers.onStatus(`error`,`reconnecting…`)}}async send(e){if(this.base===``&&!this.connected)return;let t=await fetch(w(this.base,`/api/command`,this.key),{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(e)});if(!t.ok){this.handlers.onStatus(`error`,`command refused (${t.status})`);return}let n=T(await t.json());n&&this.handlers.onSnapshot(n)}media(e,t=0){return se(this.base,e,t,this.key)}close(){this.source?.close(),this.source=null}};function le(e){try{return JSON.parse(e)}catch{return null}}async function ue(e,t,n=``){try{let r=await fetch(w(e,`/api/state`,n),{signal:t});return r.ok?T(await r.json()):null}catch{return null}}function de(e){if(!/^https:\/\//i.test(e))return``;let t;try{t=new URL(e).hostname.replace(/^\[|\]$/g,``)}catch{return``}return/^\d{1,3}(\.\d{1,3}){3}$/.test(t)||t.includes(`:`)?`That is an https address for a bare IP, and a certificate is issued for a name — a browser refuses it before it asks anything. Use the server's name instead (the address it printed first), or connect over http.`:``}async function fe(e,t=``,n){let r;try{r=await fetch(w(e,`/api/state`,t),{signal:n})}catch{return``}return r.ok?``:r.status===401?t===``?`That server needs its share link. Paste the whole link — the one with /admin/ or /view/ in it — or sign in as its owner.`:`That share link is not accepted by that server. It may have been restarted, which gives it a new one.`:r.status===403?`That link can listen but not drive this server.`:r.status===429?`That server is asking us to slow down. Try again in a moment.`:``}async function pe(e,t,n=``){try{let r=await fetch(w(e,`/api/health`,n),{signal:t});if(!r.ok)return null;let i=await r.json();return i.name===`nixamp`?i.version??`unknown`:null}catch{return null}}function me(e,t=globalThis.location?.protocol){return t!==`https:`||!/^http:\/\//i.test(e.trim())?``:`This page is https, and a browser refuses every request from an https page to an http one. Open that address directly, or give the server a certificate: nixamp serve --tls-cert cert.pem --tls-key key.pem.`}var he=.14,ge=.02;function _e(e,t){let n=[];for(let r=0;r<=e;r++){let i=r/e,a=Math.round(1*(t/1)**i),o=n[n.length-1];n.push(o===void 0?a:Math.max(a,o+1))}return n}function ve(e,t){let n=[];for(let r=0;r+1<t.length;r++){let i=Math.min(t[r],e.length),a=Math.min(Math.max(t[r+1],i+1),e.length),o=0,s=0;for(let t=i;t<a;t++)o+=e[t],s++;n.push(s===0?0:o/s/255)}return n}function ye(e,t,n=he){return t.map((t,r)=>{let i=e[r]??0;return t>=i?t:Math.max(t,i-n)})}function be(e,t,n=ge){return t.map((t,r)=>Math.max(t,(e[r]??0)-n))}function xe(e,t,n,r,i){let{width:a,height:o}=t;if(a<=0||o<=0||n.length===0)return;e.clearRect(0,0,a,o);let s=a/n.length,c=Math.max(1,s*.72),l=Math.max(2,o*.012);e.fillStyle=i.bar,n.forEach((t,n)=>{let r=Math.max(1,t*(o-l*2));e.fillRect(n*s+(s-c)/2,o-r,c,r)}),e.fillStyle=i.peak,r.forEach((t,n)=>{let r=o-Math.max(1,t*(o-l*2))-l*2;e.fillRect(n*s+(s-c)/2,Math.max(0,r),c,l)})}var Se=`nixamp.remote`,Ce=`nixamp.volume`,we=`nixamp.listenHere`,Te=!1;function E(e){let t=document.getElementById(e);if(!t)throw Error(`nixamp: #${e} is missing from the shell`);return t}function D(){let n={status:E(`status`),source:E(`source`),install:E(`install`),video:E(`video`),audio:E(`audio`),title:E(`title-line`),album:E(`album-line`),elapsed:E(`elapsed`),total:E(`total`),seek:E(`seek`),fullscreen:E(`fullscreen`),canvas:E(`spectrum`),glyphs:E(`glyphs`),levels:E(`levels`),playlist:E(`playlist`),crumbs:E(`crumbs`),filter:E(`filter`),playlistTitle:E(`playlist-panel`),note:E(`note`),files:E(`files`),folder:E(`folder`),remoteUrl:E(`remote-url`),remoteForm:E(`remote-form`),remoteState:E(`remote-state`),disconnect:E(`disconnect`),browse:E(`browse`),accountForm:E(`account-form`),accountEmail:E(`account-email`),accountPassword:E(`account-password`),accountSubmit:E(`account-submit`),accountToggle:E(`account-toggle`),accountProviders:E(`account-providers`),accountPanel:E(`account-panel`),accountElsewhere:E(`account-elsewhere`),accountSignOut:E(`account-signout`),accountNote:E(`account-note`),adminPanel:E(`admin-panel`),adminNote:E(`admin-note`),adminSaid:E(`admin-said`),adminConnections:E(`admin-connections`),publishPanel:E(`publish-panel`),publishNote:E(`publish-note`),publishList:E(`publish-list`),adminRestream:E(`admin-restream`),adminReplace:E(`admin-replace`),adminSource:E(`admin-source`),adminName:E(`admin-name`),adminAdd:E(`admin-add`),homeNote:E(`home-note`),loadHome:E(`load-home`),directory:E(`directory`),recentNote:E(`recent-note`),recentList:E(`recent-list`),followingNote:E(`following-note`),followingList:E(`following-list`),serversPanel:E(`servers-panel`),serversNote:E(`servers-note`),serversList:E(`servers-list`),favoritesPanel:E(`favorites-panel`),favoritesNote:E(`favorites-note`),favoritesList:E(`favorites-list`),favHere:E(`fav-here`),catalogsPanel:E(`catalogs-panel`),catalogsNote:E(`catalogs-note`),catalogsForm:E(`catalogs-form`),catalogSource:E(`catalog-source`),catalogName:E(`catalog-name`),catalogsList:E(`catalogs-list`),catalogsCrumbs:E(`catalogs-crumbs`),catalogsFilter:E(`catalogs-filter`),catalogsEntries:E(`catalogs-entries`),notifyPanel:E(`notify-panel`),notifyNote:E(`notify-note`),notifyWeb:E(`notify-web`),notifyEmail:E(`notify-email`),notifySms:E(`notify-sms`),notifyPhone:E(`notify-phone`),notifyPhoneForm:E(`notify-phone-form`),notifyPhoneNote:E(`notify-phone-note`),directoryNote:E(`directory-note`),directoryList:E(`directory-list`),onairPanel:E(`onair-panel`),onairNote:E(`onair-note`),onairList:E(`onair-list`),sharePanel:E(`share-panel`),shareNote:E(`share-note`),shareLink:E(`share-link`),shareCopy:E(`share-copy`),sharePhone:E(`share-phone`),shareSend:E(`share-send`),liveControls:E(`live-controls`),goLive:E(`go-live`),stopLive:E(`stop-live`),shareTo:E(`share-to`),listenOnly:E(`listen-only`),listenHere:E(`listen-here`),volume:E(`volume`),prev:E(`prev`),playPause:E(`play-pause`),stop:E(`stop`),next:E(`next`)},r=document.title||`nixamp`,i=`local`,a=``,o=[],s=0,c=ie(),l=`idle`,u=``,d=`Pick files, or connect to a nixamp running somewhere else.`,f=!1,p=-1,m=null,h=0,g=null,_=``,v=Array(24).fill(0),y=Array(24).fill(0),te=[],b=()=>i===`remote`&&!n.listenHere.checked,x=new re({audio:n.audio,video:n.video},{onTime:(e,t)=>{let n=o[s];i===`local`&&n&&t>0&&n.duration!==t&&(n.duration=t),k()},onEnded:()=>{At()||O(1)},onState:()=>k(),onError:e=>{At()||(d=e,k(),Et())}}),S=new ce({onSnapshot:e=>{c=ae(c,e),b()&&(v=e.bars.length>0?e.bars:v,y=be(y,v)),k()},onStatus:(e,t)=>{l=e,u=t??``,k()}}),C=()=>i===`remote`?c.tracks.length:o.length,w=()=>i===`remote`?b()||p<0?c.index:Math.min(p,Math.max(0,c.tracks.length-1)):s,se=()=>{if(m)return m.name;let e=i===`remote`?c.tracks[w()]:o[w()];return e?t(e):`Nothing loaded.`},T=()=>m?`live on this server`:(i===`remote`?c.tracks[w()]:o[w()])?.album||`—`,le=()=>b()?c.tracks[w()]?.duration??0:x.duration,he=()=>b()?c.position:x.position,ge=()=>b()?c.playing:x.playing;async function D(e){if(i===`remote`){if(b()){await S.send({type:`play`,index:e});return}await Ee(e);return}let t=o[e];t&&(s=e,m=null,await x.load(t,!0),M(t.video),Re(),k())}async function Ee(e){let t=c.tracks[e];t&&(p=e,m=null,await x.load({title:t.title,artist:t.artist,album:t.album,duration:t.duration,url:S.media(e,0),video:t.video===!0,objectUrl:!1},!0),M(t.video===!0),Re())}async function De(){if(b()){await S.send({type:`toggle`});return}C()!==0&&(x.playing?x.pause():x.position>0?await x.play():await D(w()),k())}async function O(e){let t=C();if(t!==0){if(b()){await S.send({type:e>0?`next`:`prev`});return}await D((w()+e+t)%t)}}async function Oe(){if(b()){await S.send({type:`stop`});return}m=null,x.stop(),v=Array(24).fill(0),y=[...v],k()}let ke=(e,t)=>`L${`▮`.repeat(Math.round(e*6)).padEnd(6,`·`)} R${`▮`.repeat(Math.round(t*6)).padEnd(6,`·`)}`,Ae=e=>`▁▂▃▄▅▆▇█`[Math.max(0,Math.min(7,Math.round(e*7)))];function k(){let t=C(),s=ge();n.status.textContent=s?`▶ PLAYING`:`■ STOPPED`,n.status.dataset.playing=String(s),n.title.textContent=se();let p=s?`${se()} · ${r}`:r;document.title!==p&&(document.title=p),n.album.textContent=T();let m=he(),h=le();n.elapsed.textContent=e(m),n.total.textContent=h>0?e(h):`--:--`,f||(n.seek.value=String(h>0?Math.round(m/h*1e3):0),n.seek.disabled=h<=0||b()),n.playPause.textContent=s?`❚❚`:`▶`,n.playPause.setAttribute(`aria-label`,s?`Pause`:`Play`),n.playlistTitle.dataset.title=i===`remote`?`Files on ${a||`this server`} (${t.toLocaleString()})`:`Playlist (${t})`,n.source.textContent=i===`remote`?`connected · ${a||S.address.replace(/^https?:\/\//,``)||`—`}`:o.length>0?`local · ${o.length} files`:`no source`,n.remoteState.textContent=i===`remote`?`${l}${u?` — ${u}`:``}`:`not connected`,n.remoteState.dataset.status=i===`remote`?l:`idle`,n.disconnect.hidden=i!==`remote`;let g=i===`remote`&&c.note!==``?c.note:d;n.note.textContent=g,n.note.hidden=g===``,Pe(),n.glyphs.textContent=v.map(Ae).join(``);let[_,ee]=b()?c.levels:x.levels();n.levels.textContent=ke(_,ee)}let A=``,je=-1,j=``;function Me(e){if(n.crumbs.hidden=!e,!e)return;let t=j===``?[]:j.split(`/`),r=(e,t,n)=>{if(n){let t=document.createElement(`span`);return t.className=`here`,t.textContent=e,t}let r=document.createElement(`button`);return r.type=`button`,r.textContent=e,r.addEventListener(`click`,()=>{j=t,A=``,Pe()}),r},i=[r(`All files`,``,t.length===0)],a=``;t.forEach((e,n)=>{a=a===``?e:`${a}/${e}`;let o=document.createElement(`span`);o.textContent=`/`,i.push(o,r(e,a,n===t.length-1))}),n.crumbs.replaceChildren(...i)}function Ne(e,t){let n=document.createElement(`li`);n.className=`folder`;let r=document.createElement(`span`);r.className=`name`,r.textContent=`${e}/`;let i=document.createElement(`span`);return i.className=`count`,i.textContent=`${t} file${t===1?``:`s`}`,n.append(r,i),n.addEventListener(`click`,()=>{j=j===``?e:`${j}/${e}`,A=``,Pe()}),n}function Pe(){let r=i===`remote`?c.tracks.map(e=>({name:t(e),seconds:e.duration,group:e.group??``,folder:e.folder??``,remote:e.remote===!0})):o.map(e=>({name:t(e),seconds:e.duration,group:``,folder:``,remote:!1})),a=n.filter.value.trim().toLowerCase(),s=r.map((e,t)=>({...e,index:t})).filter(e=>!e.remote).filter(e=>a===``||`${e.folder}/${e.name}`.toLowerCase().includes(a)),l=e=>a!==``||j===``||e===j||e.startsWith(`${j}/`),u=e=>a!==``||e===j,d=e=>{let t=j===``?e:e.slice(j.length+1),n=t.indexOf(`/`);return n===-1?t:t.slice(0,n)},f=new Map;for(let e of s){if(!l(e.folder)||u(e.folder))continue;let t=d(e.folder);t!==``&&f.set(t,(f.get(t)??0)+1)}let p=s.filter(e=>u(e.folder)&&l(e.folder)),m=`${i}:${j}:${a}:${[...f].join(`,`)}:${p.map(e=>`${e.index}@${e.name}@${e.seconds}@${e.group}`).join(`|`)}`;if(m!==A){A=m,Me(a===``&&([...f.keys()].length>0||j!==``));let t=[];for(let[e,n]of[...f].sort((e,t)=>e[0].localeCompare(t[0],void 0,{numeric:!0})))t.push(Ne(e,n));let r=``,o=p.some(e=>e.group!==``);for(let n of p){n.group!==r&&(o||n.group!==``)&&(r=n.group,t.push(Fe(n.group)));let a=document.createElement(`li`);a.className=`row`,a.dataset.index=String(n.index);let s=document.createElement(`span`);s.className=`n`,s.textContent=String(n.index+1).padStart(2,` `);let c=document.createElement(`span`);c.className=`name`,c.textContent=n.name;let l=document.createElement(`span`);if(l.className=`time`,l.textContent=n.seconds>0?e(n.seconds):`--:--`,a.append(s,c,l),i===`remote`){let e=document.createElement(`button`);e.type=`button`,e.className=`row-copy`,e.textContent=`⧉`,e.title=`Copy this file's URL`,e.setAttribute(`aria-label`,`Copy the URL of ${n.name}`),e.addEventListener(`click`,t=>{t.stopPropagation(),Nt(S.media(n.index),e,`✓`)}),a.append(e)}t.push(a)}n.playlist.replaceChildren(...t)}let h=w(),g=ge(),_;for(let e of Array.from(n.playlist.children)){let t=e,n=Number(t.dataset.index),r=Number.isInteger(n)&&n===h;t.classList.toggle(`selected`,r),t.classList.toggle(`playing`,r&&g),r&&(_=t)}h!==je&&(je=h,_?.scrollIntoView({block:`nearest`}))}function Fe(e){let t=document.createElement(`li`);t.className=`group`;let r=document.createElement(`span`);if(r.className=`group-name`,r.textContent=e===``?`This server's library`:e,t.append(r),e!==``&&!n.adminPanel.hidden){let n=document.createElement(`button`);n.type=`button`,n.className=`group-remove`,n.textContent=`×`,n.title=`Remove ${e} from the playlist`,n.setAttribute(`aria-label`,`Remove ${e} from the playlist`),n.addEventListener(`click`,t=>{t.stopPropagation(),Ie(e)}),t.append(n)}return t}async function Ie(e){try{let t=await fetch(S.url(`/api/source/remove`),{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({group:e})}),n=await t.json();P(t.ok?`Removed ${n.removed??0} tracks from ${e}.`:n.error??`that did not work`)}catch{P(`could not reach the server`)}}function Le(){let t=n.canvas,r=Math.min(2,globalThis.devicePixelRatio||1),i=Math.round(t.clientWidth*r),a=Math.round(t.clientHeight*r);i>0&&a>0&&(t.width!==i||t.height!==a)&&(t.width=i,t.height=a);let o=t.getContext(`2d`);if(b())y=be(y,v);else{let e=x.read();e.length>0&&(te.length!==25&&(te=_e(24,e.length)),v=ye(v,ve(e,te)),y=be(y,v))}if(o){let e=getComputedStyle(document.documentElement);xe(o,{width:t.width,height:t.height},v,y,{bar:e.getPropertyValue(`--green`).trim()||`#4af689`,peak:e.getPropertyValue(`--green-dim`).trim()||`#227a4a`,background:`transparent`})}if(ge()){n.glyphs.textContent=v.map(Ae).join(``);let[t,r]=b()?c.levels:x.levels();n.levels.textContent=ke(t,r),n.elapsed.textContent=e(he());let i=le();!f&&i>0&&(n.seek.value=String(Math.round(he()/i*1e3)))}requestAnimationFrame(Le)}function M(e){n.video.hidden=!e,n.fullscreen.hidden=!e}function Re(){`mediaSession`in navigator&&(navigator.mediaSession.metadata=new MediaMetadata({title:se(),album:T(),artist:`nixamp`,artwork:[{src:`/icons/icon-512.png`,sizes:`512x512`,type:`image/png`}]}),navigator.mediaSession.setActionHandler(`play`,()=>void De()),navigator.mediaSession.setActionHandler(`pause`,()=>void De()),navigator.mediaSession.setActionHandler(`nexttrack`,()=>void O(1)),navigator.mediaSession.setActionHandler(`previoustrack`,()=>void O(-1)))}n.filter.addEventListener(`input`,()=>{A=``,Pe()}),n.playlist.addEventListener(`click`,e=>{let t=e.target.closest(`li`),n=Number(t?.dataset.index);Number.isInteger(n)&&D(n)}),n.fullscreen.addEventListener(`click`,()=>{let e=n.video;if(document.fullscreenElement){document.exitFullscreen().catch(()=>{});return}if(typeof e.requestFullscreen==`function`){e.requestFullscreen().catch(()=>{e.webkitEnterFullscreen?.()});return}e.webkitEnterFullscreen?.()}),n.prev.addEventListener(`click`,()=>void O(-1)),n.next.addEventListener(`click`,()=>void O(1)),n.stop.addEventListener(`click`,()=>void Oe()),n.playPause.addEventListener(`click`,()=>void De()),n.seek.addEventListener(`input`,()=>{f=!0}),n.seek.addEventListener(`change`,()=>{let e=le();e>0&&x.seek(Number(n.seek.value)/1e3*e),f=!1}),n.volume.addEventListener(`input`,()=>{let e=Number(n.volume.value)/100;x.volume=e;try{localStorage.setItem(Ce,String(e))}catch{}});let ze=e=>{e.addEventListener(`change`,()=>{let t=ee(Array.from(e.files??[]));if(t.length===0){d=`Nothing playable in that selection.`,k();return}ne(o),o=t,s=0,i=`local`,S.close(),d=``,D(0)})};ze(n.files),ze(n.folder),n.remoteForm.addEventListener(`submit`,e=>{e.preventDefault();let t=n.remoteUrl.value,{base:r,key:a}=oe(t);if(r===``){d=`That is not an address.`,k();return}(async()=>{l=`connecting`,k();let e=me(r);if(e){l=`error`,u=e,d=e,i=`local`,k();return}if(await pe(r,void 0,a)===null){l=`error`;let e=de(r);u=e?`needs the server's name`:`not answering`,d=e||`Nothing answered at ${r}. If that is your machine, it is off or nixamp is not running on it; otherwise check the address.`,i=`local`,k();return}let n=await fe(r,a);if(n){l=`error`,u=n,d=n,i=`local`,k();return}i=`remote`,d=``;try{localStorage.setItem(Se,t.trim())}catch{}S.connect(t),$(),G(),Tt(!0),Je(),Z(),k()})()});let Be=async()=>{n.directory.hidden=!1,n.directoryNote.textContent=`Looking for live streams…`,n.directoryList.replaceChildren();let e;try{let t=await fetch(`/api/directory`);if(!t.ok)throw Error(String(t.status));let n=await t.json();e=n.streams??[],Ze(n.recent??[])}catch{n.directoryNote.textContent=`The directory is not answering. Type an address instead.`;return}if(e.length===0){n.directoryNote.textContent=`Nobody is streaming right now.`;return}n.directoryNote.textContent=`${e.length} ${e.length===1?`server is`:`servers are`} on. Connect to one to browse its files and watch what is live on it. No account needed.`;for(let t of e){let e=document.createElement(`li`),r=document.createElement(`span`);r.className=`server-label`;let i=document.createElement(`span`);i.className=`name`,i.textContent=t.name;let a=document.createElement(`span`);a.className=`detail`;let o=[`${t.tracks.toLocaleString()} files to browse`];if(t.playing!==!1&&t.nowPlaying?o.push(`playing ${t.nowPlaying}`):o.push(`player idle`),t.code&&o.push(t.callers?`☎ ${t.code} · ${t.callers} on the phone`:`☎ ${t.code}`),a.textContent=o.join(` · `),r.append(i,a),t.channels&&t.channels.length>0){let e=document.createElement(`span`);e.className=`detail live`,e.textContent=`● live: ${t.channels.join(`, `)}`,r.append(e)}let s=document.createElement(`button`);if(s.type=`button`,s.className=`button`,s.textContent=`Connect`,s.addEventListener(`click`,()=>{n.remoteUrl.value=t.url,n.directory.hidden=!0,n.remoteForm.requestSubmit()}),e.append(r,s),Y&&e.append(et(t.url,t.name)),t.ownerId&&Y&&t.ownerId!==Y&&e.append(ht(t.ownerId,t.name)),t.ownerId&&Y&&t.ownerId===Y){let r=document.createElement(`button`);r.type=`button`,r.className=`ghost`,r.textContent=`Take off the list`,r.addEventListener(`click`,e=>{e.stopPropagation(),r.disabled=!0,(async()=>{try{let e=await fetch(`/api/directory?id=${encodeURIComponent(t.id)}`,{method:`DELETE`}),r=await e.json().catch(()=>({}));n.directoryNote.textContent=e.ok?`${t.name} is off the list.`:r.error??`that did not work`}catch{n.directoryNote.textContent=`could not reach the directory`}finally{await Be()}})()}),e.append(r)}n.directoryList.append(e)}};if(location.pathname.replace(/\/+$/,``)===`/directory`){document.body.classList.add(`route-directory`);let e=document.getElementById(`directory-back`);e&&(e.hidden=!1),Be()}let N=null,Ve=e=>e===`cgnat`?`mobile or tailscale`:e===`private`?`your network`:e===`local`?`this machine`:e===`public`?`the internet`:e,He=e=>e===`events`?`watching the panel`:e===`page`?`opened the page`:e===`media`?`playing a track`:e===`stream`?`listening live`:e,Ue=``,We=``,Ge=e=>{let t=e.map(e=>`${e.address}|${e.kind}|${e.track}|${Math.round(e.bytes/4096)}|${e.endedAt}`).join(`~`);if(t===Ue)return;Ue=t,n.adminConnections.replaceChildren();let r=document.createElement(`tr`);for(let e of[`Where`,`Network`,`Kind`,`Client`,`Track`,`Sent`]){let t=document.createElement(`th`);t.textContent=e,r.append(t)}n.adminConnections.append(r);for(let t of e.slice(0,40)){let e=document.createElement(`tr`);t.endedAt!==null&&(e.className=`ended`);let r=[[t.address,``],[Ve(t.network),`network-${t.network}`],[He(t.kind),``],[t.agent,``],[t.track||`—`,``],[`${Math.round(t.bytes/1024)} KiB`,``]];for(let[t,n]of r){let r=document.createElement(`td`);r.textContent=t,n&&(r.className=n),e.append(r)}n.adminConnections.append(e)}};function P(e){n.adminSaid.textContent=e,n.adminSaid.hidden=e===``}let Ke=async()=>{try{let e=await fetch(S.url(`/api/connections`));if(!e.ok)return;let t=await e.json(),r=(t.connections??[]).filter(e=>e.endedAt===null&&e.kind!==`media`&&e.kind!==`stream`).length,i=t.active??0;n.adminNote.textContent=r===0?`${i} listening now.`:`${i} listening now, and ${r} with the page open.`,Ge(t.connections??[]),qe(t.publish??[],(t.channels??[]).map(e=>e.id)),It(t.home??``,t.root??``),$()}catch{n.adminNote.textContent=`lost touch with the server`}};function qe(e,t){n.publishPanel.hidden=e.length===0;let r=`${e.map(e=>`${e.id}=${e.url}`).join(`~`)}::${t.join(`,`)}`;if(r===We)return;if(We=r,e.length===0){n.publishList.replaceChildren();return}let i=e.length-t.length;n.publishNote.textContent=`Point OBS, Larix or ffmpeg at one of these. One publisher per URL — ${e.length} at once, ${i} free right now.`,n.publishList.replaceChildren(...e.map(e=>{let n=t.includes(e.id),r=document.createElement(`li`);n&&(r.className=`in-use`);let i=document.createElement(`span`);i.className=`slot`,i.textContent=n?`${e.id} · live`:e.id;let a=document.createElement(`input`);a.type=`text`,a.readOnly=!0,a.value=e.url,a.setAttribute(`aria-label`,`RTMP URL for ${e.id}`);let o=document.createElement(`button`);return o.type=`button`,o.className=`ghost`,o.textContent=`Copy`,o.addEventListener(`click`,()=>{a.select(),navigator.clipboard?.writeText(e.url).catch(()=>{})}),r.append(i,a,o),r}))}let Je=async()=>{if(i!==`remote`){n.adminPanel.hidden=!0,n.publishPanel.hidden=!0,N&&clearInterval(N),N=null;return}let e=!1,t=null,r=!1;try{let n=await fetch(S.url(`/api/admin`));if(n.ok){let i=await n.json();e=i.allowed===!0,t=i.as??null,r=i.claimed===!0}}catch{e=!1}if(n.adminPanel.hidden=!e,N&&clearInterval(N),N=null,$(),G(),Z(),n.listenOnly.hidden=e,!e){n.listenOnly.textContent=r?`This is a listen-only link: you can hear this server but not change what it plays. Use its control link — the first one it printed — or sign in as its owner.`:`This is a listen-only link: you can hear this server but not change what it plays. Use its control link, the first one it printed.`;return}n.adminNote.textContent=t===`owner`?`You own this server.`:`You hold this server's control link.`,Ke(),N=setInterval(()=>void Ke(),2e3)};function Ye(e,t,r){let i=(t||e).toLowerCase().replace(/[^a-z0-9_-]+/g,`-`).replace(/^-+|-+$/g,``).slice(0,40)||`s${Math.random().toString(16).slice(2,8)}`;P(`Starting ${t||e}…`),(async()=>{try{let a=await fetch(S.url(`/api/channels/${encodeURIComponent(i)}/pull`),{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({...r===void 0?{source:e}:{at:r},...t?{name:t}:{}})}),o=await a.json();if(!a.ok){P(o.error??`that did not work`);return}P(`${o.channel?.name||t||e} is on the air.`),n.adminSource.value=``,n.adminName.value=``,Z(),$()}catch{P(`could not reach the server`)}})()}n.adminRestream.addEventListener(`submit`,e=>{e.preventDefault();let t=n.adminSource.value.trim();t&&Ye(t,n.adminName.value.trim())}),n.adminAdd.addEventListener(`click`,()=>{let e=n.adminSource.value.trim();if(!e)return;P(`Reading ${e}…`);let t=n.adminReplace.checked,r=n.adminName.value.trim();(async()=>{try{let i=await fetch(S.url(`/api/source`),{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({source:e,...r?{name:r}:{},...t?{replace:!0}:{}})}),a=await i.json();P(i.ok?t?`Now serving ${e}.`:a.added===0?`Everything there was already in the playlist.`:`Added ${a.added??0} tracks from ${e}.`:a.error??`that did not work`),i.ok&&(n.adminSource.value=``,n.adminName.value=``,Z(),$())}catch{P(`could not reach the server`)}})()});let Xe=e=>{let t=Math.max(1,Math.round((Date.now()-e)/6e4));if(t<60)return`${t} minute${t===1?``:`s`} ago`;let n=Math.round(t/60);return`${n} hour${n===1?``:`s`} ago`},Ze=e=>{n.recentList.replaceChildren();let t=Y?e.filter(e=>e.ownerId&&e.ownerId!==Y):[];if(n.recentNote.hidden=t.length===0,t.length!==0)for(let e of t){let t=document.createElement(`li`),r=document.createElement(`span`);r.className=`recent-label`;let i=document.createElement(`span`);i.className=`name`,i.textContent=e.name;let a=document.createElement(`span`);a.className=`detail`,a.textContent=e.nowPlaying?`${e.nowPlaying} · ended ${Xe(e.endedAt)}`:`ended ${Xe(e.endedAt)}`,r.append(i,a),t.append(r,ht(e.ownerId,e.name)),n.recentList.append(t)}},F=new Set,I=e=>{try{return new URL(e).origin}catch{return e}},L=e=>[...F].some(t=>I(t)===I(e));async function Qe(){if(!Y){F=new Set,n.favoritesPanel.hidden=!0,R();return}try{let e=await fetch(`/api/v1/favorites`);if(!e.ok){n.favoritesPanel.hidden=!0;return}let t=(await e.json()).favorites??[];F=new Set(t.map(e=>e.url)),n.favoritesPanel.hidden=t.length===0,n.favoritesNote.textContent=`Servers you hearted. Connect to one, or let it go.`,n.favoritesList.replaceChildren(...t.map(e=>{let t=document.createElement(`li`),r=document.createElement(`span`);r.className=`server-label`;let i=document.createElement(`span`);i.className=`name`,i.textContent=e.name||e.url.replace(/^https?:\/\//,``);let a=document.createElement(`span`);a.className=e.live?`detail live`:`detail`,a.textContent=e.live?[`● on now`,e.nowPlaying?`playing ${e.nowPlaying}`:``,e.channels.length>0?`live: ${e.channels.join(`, `)}`:``].filter(Boolean).join(` · `):`not on right now`,r.append(i,a);let o=document.createElement(`button`);return o.type=`button`,o.className=`button`,o.textContent=`Connect`,o.addEventListener(`click`,()=>{n.remoteUrl.value=e.url,n.remoteForm.requestSubmit()}),t.append(r,o,et(e.url,e.name)),t}))}catch{n.favoritesPanel.hidden=!0}R()}async function $e(e,t,n){try{if(!(n?await fetch(`/api/v1/favorites`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify({url:e,name:t})}):await fetch(`/api/v1/favorites?url=${encodeURIComponent(e)}`,{method:`DELETE`})).ok){d=n?`Could not save that favourite.`:`Could not remove that favourite.`,k();return}}catch{d=`could not reach nixamp.com`,k();return}if(n)F.add(e);else for(let t of[...F])I(t)===I(e)&&F.delete(t);await Qe()}function et(e,t){let n=document.createElement(`button`);n.type=`button`,n.className=`heart`;let r=()=>{let t=L(e);n.textContent=t?`♥`:`♡`,n.dataset.on=t?`yes`:`no`,n.title=t?`Remove from favourites`:`Add to favourites`,n.setAttribute(`aria-label`,n.title)};return r(),n.addEventListener(`click`,n=>{n.stopPropagation();let i=[...F].find(t=>I(t)===I(e))??e;$e(L(e)?i:e,t,!L(e)).then(r)}),n}function R(){let e=i===`remote`?S.shareLink:``;if(n.favHere.hidden=!(Y&&e),n.favHere.hidden)return;let t=L(e);n.favHere.textContent=t?`♥`:`♡`,n.favHere.dataset.on=t?`yes`:`no`,n.favHere.title=t?`Remove this server from your favourites`:`Add this server to your favourites`,n.favHere.setAttribute(`aria-label`,n.favHere.title)}n.favHere.addEventListener(`click`,()=>{let e=S.shareLink;if(!e)return;let t=[...F].find(t=>I(t)===I(e))??e;$e(L(e)?t:e,a||S.address,!L(e)).then(R)});let z=[],B=null,V=null,H=``,U=[],W=0,tt=null,nt=0;function rt(e){if(!e)return`never`;let t=Math.max(0,Math.round((Date.now()-e)/1e3));if(t<90)return`just now`;let n=Math.round(t/60);if(n<90)return`${n} min ago`;let r=Math.round(n/60);return r<36?`${r} h ago`:`${Math.round(r/24)} d ago`}async function G(){if(i!==`remote`){n.catalogsPanel.hidden=!0;return}let e;try{e=await fetch(S.url(`/api/catalogs`))}catch{n.catalogsPanel.hidden=!0;return}if(!e.ok){n.catalogsPanel.hidden=!0;return}z=(await e.json().catch(()=>({}))).catalogs??[],B&&=z.find(e=>e.id===B?.id)??null,B||(V=null),n.catalogsPanel.hidden=!1,K()}function K(){let e=!n.adminPanel.hidden;n.catalogsForm.hidden=!e;let t=z.reduce((e,t)=>e+t.live,0),r=z.reduce((e,t)=>e+t.vod,0);n.catalogsNote.textContent=z.length===0?e?`No catalogs yet. Add an m3u list of channels or films.`:`No catalogs yet.`:`${z.length} ${z.length===1?`catalog`:`catalogs`} · ${t} live ${t===1?`channel`:`channels`} · ${r} on demand`,it();let i=B!==null&&V!==null;if(n.catalogsList.hidden=i,n.catalogsFilter.hidden=!i,n.catalogsEntries.hidden=!i,i){lt();return}if(B){ot(B);return}n.catalogsList.replaceChildren(...z.map(t=>at(t,e)))}function it(){let e=B!==null;if(n.catalogsCrumbs.hidden=!e,!e)return;let t=(e,t,n)=>{if(n){let t=document.createElement(`span`);return t.className=`here`,t.textContent=e,t}let r=document.createElement(`button`);return r.type=`button`,r.textContent=e,r.addEventListener(`click`,t),r},r=()=>{let e=document.createElement(`span`);return e.textContent=`/`,e},i=[t(`All catalogs`,()=>{B=null,V=null,K()},!1),r(),t(B?.name??``,()=>{V=null,K()},V===null)];V!==null&&i.push(r(),t(V===``?`All groups`:V,()=>void 0,!0)),n.catalogsCrumbs.replaceChildren(...i)}function at(e,t){let n=document.createElement(`li`),r=document.createElement(`span`);r.className=`server-label`;let i=document.createElement(`span`);i.className=`name`,i.textContent=e.name;let a=document.createElement(`span`);if(a.className=`detail`,a.textContent=[`${e.entries.toLocaleString()} ${e.entries===1?`entry`:`entries`}`,`${e.live.toLocaleString()} live`,`${e.vod.toLocaleString()} on demand`,`refreshed ${rt(e.refreshedAt)}`].join(` · `),r.append(i,a),t&&e.error){let t=document.createElement(`span`);t.className=`detail`,t.textContent=e.error,r.append(t)}let o=document.createElement(`button`);if(o.type=`button`,o.className=`button`,o.textContent=`Browse`,o.addEventListener(`click`,()=>{B=e,V=null,K()}),n.append(r,o),t){let t=document.createElement(`button`);t.type=`button`,t.className=`ghost`,t.textContent=`Refresh`,t.title=`Read the list again`,t.addEventListener(`click`,()=>{dt(e)});let r=document.createElement(`button`);r.type=`button`,r.className=`ghost`,r.textContent=`Remove`,r.title=`Take this catalog off the server`,r.addEventListener(`click`,()=>{confirm(`Remove ${e.name} from this server?`)&&ft(e)}),n.append(t,r)}return n}async function ot(e){n.catalogsList.replaceChildren();let t=[];try{let n=await fetch(S.url(`/api/catalogs/${encodeURIComponent(e.id)}/groups`));if(!n.ok)throw Error(String(n.status));t=(await n.json()).groups??[]}catch{d=`Could not read the groups in ${e.name}.`,k();return}if(B?.id!==e.id||V!==null)return;let r=[st(`All groups`,``,e.entries,e.live,e.vod),...t.map(e=>st(e.name||`(no group)`,e.name,e.count,e.live,e.vod))];n.catalogsList.replaceChildren(...r)}function st(e,t,r,i,a){let o=document.createElement(`li`),s=document.createElement(`span`);s.className=`server-label`;let c=document.createElement(`span`);c.className=`name`,c.textContent=e;let l=document.createElement(`span`);l.className=`detail`,l.textContent=`${r.toLocaleString()} · ${i.toLocaleString()} live · ${a.toLocaleString()} on demand`,s.append(c,l);let u=document.createElement(`button`);return u.type=`button`,u.className=`button`,u.textContent=`Open`,u.addEventListener(`click`,()=>{V=t,H=``,n.catalogsFilter.value=``,U=[],W=0,K(),ct(0)}),o.append(s,u),o}async function ct(e){let t=B,n=V;if(!t||n===null)return;let r=++nt,i=new URLSearchParams({group:n,q:H,offset:String(e),limit:`200`}),a;try{let e=await fetch(S.url(`/api/catalogs/${encodeURIComponent(t.id)}/entries?${i}`));if(!e.ok)throw Error(String(e.status));a=await e.json()}catch{d=`Could not read ${t.name}.`,k();return}r===nt&&(W=a.total??0,U=e===0?a.entries??[]:[...U,...a.entries??[]],lt())}function lt(){let t=B;if(!t)return;let r=U.map(n=>{let r=document.createElement(`li`);r.className=`row`;let i=document.createElement(`span`);i.className=`name`,i.textContent=n.title;let a=document.createElement(`span`);if(a.className=n.live?`catalog-tag catalog-live`:`catalog-tag`,a.textContent=n.live?`LIVE`:n.duration>0?e(n.duration):`VOD`,r.append(i,a),!n.live){let e=document.createElement(`button`);e.type=`button`,e.className=`row-copy`,e.textContent=`⧉`,e.title=`Copy this entry's URL`,e.setAttribute(`aria-label`,`Copy the URL of ${n.title}`),e.addEventListener(`click`,r=>{r.stopPropagation();let i=`/api/catalogs/${encodeURIComponent(t.id)}/entries/${encodeURIComponent(n.id)}/stream`;Nt(S.url(i),e,`✓`)}),r.append(e)}return r.addEventListener(`click`,()=>{ut(t,n)}),r});if(U.length===0){let e=document.createElement(`li`);e.className=`group`;let t=document.createElement(`span`);t.className=`group-name`,t.textContent=H?`Nothing called "${H}" here.`:`Nothing in this group.`,e.append(t),r.push(e)}else if(U.length<W){let e=document.createElement(`li`);e.className=`group`;let t=document.createElement(`button`);t.type=`button`,t.className=`ghost`,t.textContent=`Show more (${U.length.toLocaleString()} of ${W.toLocaleString()})`,t.addEventListener(`click`,e=>{e.stopPropagation(),ct(U.length)}),e.append(t),r.push(e)}n.catalogsEntries.replaceChildren(...r)}async function ut(e,t){let n,r={};try{n=await fetch(S.url(`/api/catalogs/${encodeURIComponent(e.id)}/entries/${encodeURIComponent(t.id)}/play`),{method:`POST`}),r=await n.json().catch(()=>({}))}catch{d=`could not reach the server`,k();return}if(!n.ok){d=r.error??`${t.title} would not play.`,k();return}let i=r.name||t.title;if(r.kind===`live`&&r.channel){await kt({id:r.channel,name:i,video:!0});return}if(r.kind===`vod`&&r.url){m=null,p=-1,await x.load({title:i,artist:``,album:``,duration:0,url:S.url(r.url),video:!0,objectUrl:!1},!0),M(!0),d=`Playing ${i}.`,k();return}d=`${t.title} would not play.`,k()}async function dt(e){P(`Reading ${e.name} again…`);try{let t=await fetch(S.url(`/api/catalogs/${encodeURIComponent(e.id)}/refresh`),{method:`POST`}),n=await t.json().catch(()=>({}));P(t.ok?`${n.catalog?.name??e.name}: ${(n.catalog?.entries??0).toLocaleString()} entries.`:n.error??`that did not work`)}catch{P(`could not reach the server`)}G()}async function ft(e){try{P((await fetch(S.url(`/api/catalogs/${encodeURIComponent(e.id)}`),{method:`DELETE`})).ok?`${e.name} is off the server.`:`that did not work`)}catch{P(`could not reach the server`)}B?.id===e.id&&(B=null,V=null),G()}n.catalogsForm.addEventListener(`submit`,e=>{e.preventDefault();let t=n.catalogSource.value.trim(),r=n.catalogName.value.trim();t&&(async()=>{P(`Reading ${r||t}…`);try{let e=await fetch(S.url(`/api/catalogs`),{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({source:t,name:r})}),i=await e.json().catch(()=>({}));if(!e.ok){P(i.error??`that did not work`);return}P(`${i.catalog?.name??r??t}: ${(i.catalog?.entries??0).toLocaleString()} entries.`),n.catalogSource.value=``,n.catalogName.value=``}catch{P(`could not reach the server`)}G()})()}),n.catalogsFilter.addEventListener(`input`,()=>{tt&&clearTimeout(tt),tt=setTimeout(()=>{tt=null,H=n.catalogsFilter.value.trim(),ct(0)},250)});let pt=async()=>{n.serversList.replaceChildren();try{let e=await fetch(`/api/v1/servers`);if(!e.ok){n.serversPanel.hidden=!0;return}let t=(await e.json()).servers??[];n.serversPanel.hidden=!1,n.serversNote.textContent=t.length===0?"No servers yet. `nixamp server add --here` remembers the one you are running.":`The machines on your account. Open one, or forget it.`;for(let e of t){let t=document.createElement(`li`),r=document.createElement(`span`);r.className=`recent-label`;let i=document.createElement(`span`);i.className=`name`,i.textContent=e.name;let a=document.createElement(`span`);a.className=`detail`,a.textContent=e.url,r.append(i,a);let o=document.createElement(`button`);o.type=`button`,o.className=`button`,o.textContent=`Open`,o.addEventListener(`click`,()=>{n.remoteUrl.value=e.key?`${e.url}/admin/${e.key}`:e.url,n.remoteForm.requestSubmit()}),pe(e.url).then(n=>{if(n!==null){a.textContent=`${e.url} · ${n}`;return}a.textContent=`${e.url} · not answering`,t.classList.add(`offline`),o.disabled=!0,o.title=`That machine is not answering. Start nixamp on it.`});let s=document.createElement(`button`);s.type=`button`,s.className=`ghost`,s.textContent=`Forget`,s.addEventListener(`click`,()=>{(async()=>{s.disabled=!0;try{await fetch(`/api/v1/servers/${encodeURIComponent(e.id)}`,{method:`DELETE`}),await pt()}catch{s.disabled=!1}})()}),t.append(r,o,s),n.serversList.append(t)}}catch{n.serversPanel.hidden=!0}},mt=async()=>{n.followingList.replaceChildren();try{let e=await fetch(`/api/v1/follows`);if(!e.ok){n.followingNote.hidden=!0;return}let t=(await e.json()).following??[];n.followingNote.hidden=t.length===0;for(let e of t){let t=document.createElement(`li`),r=document.createElement(`span`);r.className=`recent-label`;let i=document.createElement(`span`);i.className=`name`,i.textContent=e.name||`a nixamp`;let a=document.createElement(`span`);a.className=`detail`,a.textContent=e.live?`live now`:`not streaming`,r.append(i,a);let o=document.createElement(`button`);o.type=`button`,o.className=`ghost follow`,o.textContent=`Unfollow`,o.addEventListener(`click`,()=>{(async()=>{o.disabled=!0;try{await fetch(`/api/v1/follows/${encodeURIComponent(e.id)}`,{method:`DELETE`}),t.remove(),n.followingList.children.length===0&&(n.followingNote.hidden=!0)}finally{o.disabled=!1}})()}),t.append(r,o),n.followingList.append(t)}}catch{n.followingNote.hidden=!0}},ht=(e,t)=>{let n=document.createElement(`button`);n.type=`button`,n.className=`ghost follow`,n.textContent=`Follow`,n.setAttribute(`aria-label`,`Follow ${t}`);let r=e=>{n.textContent=e?`Following`:`Follow`,n.dataset.following=e?`yes`:`no`};return(async()=>{try{let t=await fetch(`/api/v1/follows/${encodeURIComponent(e)}`);t.ok&&r((await t.json()).following===!0)}catch{}})(),n.addEventListener(`click`,()=>{(async()=>{let t=n.dataset.following===`yes`;n.disabled=!0;try{(await fetch(`/api/v1/follows/${encodeURIComponent(e)}`,{method:t?`DELETE`:`PUT`,headers:{"content-type":`application/json`},body:t?void 0:`{}`})).ok&&(r(!t),mt())}catch{}finally{n.disabled=!1}})()}),n},gt=e=>{let t=(e+`=`.repeat((4-e.length%4)%4)).replace(/-/g,`+`).replace(/_/g,`/`),n=atob(t),r=new Uint8Array(new ArrayBuffer(n.length));for(let e=0;e<n.length;e+=1)r[e]=n.charCodeAt(e);return r},_t=()=>`serviceWorker`in navigator&&`PushManager`in window&&`Notification`in window,vt=async()=>{if(!_t())return n.notifyNote.textContent=`This browser cannot show notifications.`,!1;if(Notification.permission===`denied`)return n.notifyNote.textContent=`This browser is blocking notifications. Allow them in site settings first.`,!1;if(await Notification.requestPermission()!==`granted`)return n.notifyNote.textContent=`Not allowed, so nothing will be sent here.`,!1;try{let e=await navigator.serviceWorker.ready,{publicKey:t}=await(await fetch(`/api/v1/notify/key`)).json();if(!t)return n.notifyNote.textContent=`This server is not set up to send notifications.`,!1;let r=await e.pushManager.getSubscription()??await e.pushManager.subscribe({userVisibleOnly:!0,applicationServerKey:gt(t)}),i=await fetch(`/api/v1/notify/subscribe`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(r.toJSON())});if(!i.ok)throw Error(String(i.status));return n.notifyNote.textContent=`This device will be told.`,!0}catch{return n.notifyNote.textContent=`Could not set this device up.`,!1}},yt=async()=>{try{let e=await(await navigator.serviceWorker.ready).pushManager.getSubscription();if(!e)return;await fetch(`/api/v1/notify/subscribe?endpoint=${encodeURIComponent(e.endpoint)}`,{method:`DELETE`}),await e.unsubscribe()}catch{}},q=async e=>{try{let t=await fetch(`/api/v1/notify/prefs`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify(e)}),r=await t.json();n.notifyPhoneNote.textContent=t.ok?``:r.error??`that did not save`,t.ok&&typeof r.phone==`string`&&(n.notifyPhone.value=r.phone)}catch{n.notifyPhoneNote.textContent=`could not reach nixamp.com`}},bt=async()=>{try{let e=await fetch(`/api/v1/notify/prefs`);if(!e.ok)return;let t=await e.json();n.notifyEmail.checked=t.wantsEmail!==!1,n.notifySms.checked=t.wantsSms===!0,n.notifyPhone.value=t.phone??``;let r=_t()&&Notification.permission===`granted`?await(await navigator.serviceWorker.ready).pushManager.getSubscription()!==null:!1;n.notifyWeb.checked=t.wantsWeb!==!1&&r,n.notifyNote.textContent=r?`Get told when someone you follow goes live.`:`Turn on “On this device” to be told here.`}catch{}};n.notifyWeb.addEventListener(`change`,()=>{(async()=>{if(n.notifyWeb.checked){let e=await vt();n.notifyWeb.checked=e,await q({wantsWeb:e});return}await yt(),await q({wantsWeb:!1}),n.notifyNote.textContent=`Turn on “On this device” to be told here.`})()}),n.notifyEmail.addEventListener(`change`,()=>{q({wantsEmail:n.notifyEmail.checked})}),n.notifySms.addEventListener(`change`,()=>{(async()=>{if(n.notifySms.checked&&!n.notifyPhone.value.trim()){n.notifyPhoneNote.textContent=`Add a phone number first.`,n.notifySms.checked=!1,n.notifyPhone.focus();return}await q({wantsSms:n.notifySms.checked})})()}),n.notifyPhoneForm.addEventListener(`submit`,e=>{e.preventDefault(),q({phone:n.notifyPhone.value.trim()})});let J=!1,Y=``,X=e=>{let t=e!==null;n.notifyPanel.hidden=!t,t?(bt(),mt(),pt()):(n.serversPanel.hidden=!0,n.followingNote.hidden=!0,n.followingList.replaceChildren(),n.recentNote.hidden=!0,n.recentList.replaceChildren()),n.accountForm.hidden=t,n.accountProviders.hidden=t||n.accountProviders.childElementCount===0,n.accountSignOut.hidden=!t,n.accountNote.textContent=t?`Signed in as ${e}.`:J?`Create an account on nixamp.com.`:`Listening needs no account. Sign in to keep favourites, follow people, and publish.`,n.accountSubmit.textContent=J?`Create account`:`Sign in`,n.accountToggle.textContent=J?`I have one`:`Create one`,n.accountPassword.autocomplete=J?`new-password`:`current-password`},xt=async()=>{let e=[],t=!1;try{let n=await fetch(`/api/v1/auth/providers`);n.ok&&(t=!0,e=(await n.json()).providers??[])}catch{}n.accountProviders.replaceChildren(),n.accountProviders.hidden=e.length===0,n.accountPanel.hidden=!t,n.accountElsewhere.hidden=t;for(let t of e){let e=document.createElement(`a`);e.className=`button`,e.href=`/api/v1/${encodeURIComponent(t.id)}/oauth/start`,e.textContent=`Continue with ${t.name}`,n.accountProviders.append(e)}},St=async()=>{try{let e=await fetch(`/api/v1/auth/me`),t=await e.json();Y=e.ok?t.account?.id??``:``,X(e.ok?t.account?.email??`you`:null)}catch{Y=``,X(null)}Qe(),Ct()};function Ct(){if(_===``)return;let e=_;_=``,n.remoteUrl.value=e,n.remoteForm.requestSubmit()}n.accountToggle.addEventListener(`click`,()=>{J=!J,X(null)}),n.accountForm.addEventListener(`submit`,e=>{e.preventDefault();let t=n.accountEmail.value.trim(),r=n.accountPassword.value;(async()=>{n.accountSubmit.disabled=!0;try{let e=await fetch(`/api/v1/auth/${J?`signup`:`login`}`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({email:t,password:r})}),i=await e.json();if(!e.ok){n.accountNote.textContent=i.error??`that did not work`;return}Y=i.account?.id??``,n.accountPassword.value=``,X(i.account?.email??t),Je(),Ct()}catch{n.accountNote.textContent=`could not reach nixamp.com`}finally{n.accountSubmit.disabled=!1}})()}),n.accountSignOut.addEventListener(`click`,()=>{(async()=>{try{await fetch(`/api/v1/auth/logout`,{method:`POST`})}catch{}Y=``,X(null),S.close(),p=-1,i=`local`,l=`idle`,u=``,n.remoteUrl.value=``,n.sharePanel.hidden=!0,n.publishPanel.hidden=!0,n.adminPanel.hidden=!0,n.onairPanel.hidden=!0,n.catalogsPanel.hidden=!0,n.listenOnly.hidden=!0,Tt(!1);try{localStorage.removeItem(Se)}catch{}d=`Signed out, and disconnected from the server.`,Je(),k()})()});try{let e=new URL(globalThis.location.href).searchParams.get(`url`)??``;e!==``&&(_=e,n.remoteUrl.value=e,d=`Opening the stream you were sent…`,globalThis.history?.replaceState(null,``,globalThis.location.pathname))}catch{}xt(),St(),Je(),n.browse.addEventListener(`click`,()=>{if(!n.directory.hidden){n.directory.hidden=!0;return}Be(),n.directory.scrollIntoView({behavior:`smooth`,block:`nearest`})}),n.disconnect.addEventListener(`click`,()=>{S.close(),n.listenOnly.hidden=!0,p=-1,n.sharePanel.hidden=!0,n.publishPanel.hidden=!0,n.adminPanel.hidden=!0,n.onairPanel.hidden=!0,n.onairPanel.dataset.title=`Live on this server`,n.catalogsPanel.hidden=!0,n.catalogsPanel.dataset.title=`Catalogs on this server`,a=``,R(),Tt(!1),i=`local`,l=`idle`,u=``,k()});async function Z(){if(i!==`remote`||S.shareLink===``){n.sharePanel.hidden=!0;return}n.sharePanel.hidden=!1;let e=S.shareLink,t=globalThis.location.origin;n.shareLink.value=e.startsWith(`https://`)?`${t}/?url=${encodeURIComponent(e)}`:e,n.shareNote.textContent=`Anyone with this link can watch. They sign in once, then it opens.`,n.sharePhone.hidden=!0,n.shareSend.hidden=!0,n.liveControls.hidden=!0;let r=``;try{let e=await fetch(`/api/directory`);e.ok&&(r=(await e.json()).callIn??``)}catch{}let a=null;try{let r=await fetch(S.url(`/api/live/state`));r.ok&&(a=await r.json()),a?.url&&(e=a.url,n.shareLink.value=e.startsWith(`https://`)?`${t}/?url=${encodeURIComponent(e)}`:e)}catch{}if(a){if(n.liveControls.hidden=n.adminPanel.hidden||!a.possible,n.goLive.hidden=a.live,n.stopLive.hidden=!a.live,n.sharePhone.hidden=!1,!a.live){n.sharePhone.textContent=a.possible?`Not listed, so nobody can find this in the directory. Go live to list it, with a phone number and a code anyone can call.`:`This machine has no address the world can reach, so it cannot be listed.`;return}if(!r){n.sharePhone.textContent=`Listed. The code for the phone line is ${a.code}.`,n.shareSend.hidden=!1;return}n.sharePhone.replaceChildren(document.createTextNode(`To talk about it, call `),Rt(r),document.createTextNode(` and key `),Rt(a.code),document.createTextNode(`. That is a room with everyone else watching — not the stream itself.`)),n.shareSend.hidden=!1}}let wt=``,Q=null,Tt=e=>{Q&&clearInterval(Q),Q=null,e&&(Q=setInterval(()=>void $(),6e3))};async function $(){if(i!==`remote`){n.onairPanel.hidden=!0;return}let e;try{let t=await fetch(S.url(`/api/streams`));if(!t.ok){n.onairPanel.hidden=!0;return}e=await t.json(),e.server.name&&e.server.name!==a&&(a=e.server.name,n.onairPanel.dataset.title=`Live on ${a}`,n.catalogsPanel.dataset.title=`Catalogs on ${a}`,R(),k())}catch{n.onairPanel.hidden=!0;return}n.onairPanel.hidden=!1;let t=`${n.adminPanel.hidden?`view`:`drive`}:${JSON.stringify(e)}`;if(t===wt)return;wt=t;let r=e.restreams??[],o=e.channels.length+r.length;n.onairNote.textContent=o===0?`One stream, from this server's own files.`:`${o+1} streams: this server's own files, and ${o} more on it.`;let s=[],c=e.server.playing,l=!n.adminPanel.hidden;s.push(Pt({title:e.server.name,detail:[c?`playing ${e.server.nowPlaying}`:e.server.nowPlaying?`stopped on ${e.server.nowPlaying}`:`nothing loaded`,`${e.server.tracks} track${e.server.tracks===1?``:`s`}`,e.server.code?`☎ ${e.server.code}`:`not listed`].join(` · `),playLabel:c?`Join live`:l?`Start the stream`:`Nothing playing`,onPlay:()=>{if(c){Ot(e.server.nowPlaying);return}l&&Dt()},link:e.server.live?e.server.url:``,direct:c?S.url(`/api/live`):``}));for(let e of r)s.push(Pt({title:e.name,detail:e.tracks===1?`re-streamed from the web`:`re-streamed from the web · ${e.tracks} tracks`,onPlay:()=>{D(e.at)},link:``,direct:S.media(e.at)}));for(let t of e.channels){let e=t.kind!==`audio`,n=S.url(`/api/channels/${encodeURIComponent(t.id)}`),r=[t.via===`pull`?`on the air · ${t.listeners} watching`:`live over ${t.via} · ${t.listeners} listening`];t.redials&&r.push(`redialled ${t.redials}×`),l&&t.error&&r.push(t.error),s.push(Pt({title:t.name,detail:r.join(` · `),onPlay:()=>{kt({id:t.id,name:t.name,video:e})},link:n,direct:n,onRestart:l&&t.via===`pull`?()=>{jt(t.id,t.name)}:void 0,onStop:l?()=>{Mt(t.id,t.name)}:void 0}))}n.onairList.replaceChildren(...s)}async function Et(){if(i===`remote`)try{if((await fetch(S.media(w(),0),{method:`GET`,headers:{range:`bytes=0-1`}})).status!==402)return;d=Y===``?`This stream is busy enough to be charging for. Sign in to nixamp.com to pay for a pass.`:`This stream is charging for a pass. Follow the payment prompt to keep listening.`,Y===``&&n.accountPanel.scrollIntoView({behavior:`smooth`,block:`center`}),k()}catch{}}async function Dt(){P(`Starting the stream on the server…`);try{await S.send({type:`play`,index:Math.max(0,w())})}catch{P(`could not reach the server`);return}await Ot(c.tracks[w()]?.title??``),P(`Playing to the room. Anybody with the view link sees this.`),await $()}async function Ot(e){p=-1,m=null,await x.load({title:e||`Live`,artist:``,album:``,duration:0,url:S.url(`/api/live`),video:!0,objectUrl:!1},!0),M(!0),d=`Watching what this server is playing. Everyone here sees the same thing.`,k()}async function kt(e,t=!0){p=-1,m=e,t&&(h=0),await x.load({title:e.name,artist:``,album:``,duration:0,url:S.url(`/api/channels/${encodeURIComponent(e.id)}`),video:e.video,objectUrl:!1},!0),M(e.video),d=`Watching ${e.name}, live on this server.`,k()}function At(){let e=m;return e?g?!0:h>=5?(d=`${e.name} stopped, and did not come back.`,m=null,k(),!0):(h+=1,d=`${e.name} started over; rejoining…`,k(),g=setTimeout(()=>{g=null,m===e&&kt(e,!1)},2e3),!0):!1}async function jt(e,t){P(`Restarting ${t}…`);try{let n=await fetch(S.url(`/api/channels/${encodeURIComponent(e)}/restart`),{method:`POST`}),r=await n.json().catch(()=>({}));P(n.ok?`${t} is dialling its source again.`:r.error??`that did not work`)}catch{P(`could not reach the server`)}wt=``,$()}async function Mt(e,t){try{P((await fetch(S.url(`/api/channels/${encodeURIComponent(e)}`),{method:`DELETE`})).ok?`${t} is off the air.`:`that did not work`)}catch{P(`could not reach the server`)}m?.id===e&&(m=null,x.stop()),wt=``,$()}async function Nt(e,t,n=`Copied`){if(!e)return;let r=t.textContent;try{await navigator.clipboard.writeText(e)}catch{d=e,k();return}t.textContent=n,setTimeout(()=>{t.textContent=r},1200)}function Pt(e){let t=document.createElement(`li`),n=document.createElement(`span`);n.className=`recent-label`;let r=document.createElement(`span`);r.className=`name`,r.textContent=e.title;let i=document.createElement(`span`);i.className=`detail`,i.textContent=e.detail,n.append(r,i);let a=document.createElement(`button`);if(a.type=`button`,a.className=`button`,a.textContent=e.playLabel??`Play`,a.addEventListener(`click`,e.onPlay),t.append(n,a),e.link){let n=document.createElement(`button`);n.type=`button`,n.className=`ghost`,n.textContent=`Copy link`,n.title=`A link that opens this in the player`,n.addEventListener(`click`,()=>{let t=globalThis.location.origin;Nt(e.link.startsWith(`https://`)?`${t}/?url=${encodeURIComponent(e.link)}`:e.link,n)}),t.append(n)}if(e.direct){let n=document.createElement(`button`);n.type=`button`,n.className=`ghost`,n.textContent=`Copy URL`,n.title=`The stream's own address, for VLC or mpv`,n.addEventListener(`click`,()=>{Nt(e.direct??``,n)}),t.append(n)}if(e.onRestart){let n=document.createElement(`button`);n.type=`button`,n.className=`ghost`,n.textContent=`Restart`,n.title=`Dial the source again`,n.addEventListener(`click`,e.onRestart),t.append(n)}if(e.onStop){let n=document.createElement(`button`);n.type=`button`,n.className=`ghost`,n.textContent=`Remove`,n.title=`Take it off the air`,n.addEventListener(`click`,e.onStop),t.append(n)}return t}let Ft=``;function It(e,t){Ft=e;let r=e!==``&&t===e;n.loadHome.hidden=e===``,n.homeNote.hidden=e===``,e!==``&&(n.homeNote.textContent=r?`This server's own files: ${e}`:`This server's own files are ${e}, and are not in the playlist.`,n.loadHome.disabled=!1)}n.loadHome.addEventListener(`click`,()=>{Ft!==``&&(n.loadHome.disabled=!0,P(`Reading this server's files…`),(async()=>{try{let e=await fetch(S.url(`/api/source`),{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({source:Ft})}),t=await e.json();P(e.ok?t.added===0?`This server's files are already in the playlist.`:`Loaded ${t.added??0} of this server's own files.`:t.error??`that did not work`)}catch{P(`could not reach the server`)}finally{n.loadHome.disabled=!1}})())});let Lt=async e=>{n.goLive.disabled=!0,n.stopLive.disabled=!0,n.shareNote.textContent=e?`Going live…`:`Taking it off the list…`;try{let t=await fetch(S.url(e?`/api/live/start`:`/api/live/stop`),{method:`POST`}),r=await t.json();n.shareNote.textContent=t.ok?e?`Live. Anyone can call and key ${r.code??``} to talk about it.`:`Taken off the list. The link still works for anybody who has it.`:r.error??`that did not work`}catch{n.shareNote.textContent=`could not reach the server`}finally{n.goLive.disabled=!1,n.stopLive.disabled=!1,await Z()}};n.goLive.addEventListener(`click`,()=>void Lt(!0)),n.stopLive.addEventListener(`click`,()=>void Lt(!1));function Rt(e){let t=document.createElement(`b`);return t.textContent=e,t}n.shareCopy.addEventListener(`click`,()=>{n.shareLink.select(),navigator.clipboard?.writeText(n.shareLink.value).then(()=>{n.shareNote.textContent=`Copied. Send it to anybody.`},()=>{n.shareNote.textContent=`Copy it from the box above.`})}),n.shareSend.addEventListener(`submit`,e=>{e.preventDefault();let t=n.shareTo.value.trim();t!==``&&(async()=>{n.shareNote.textContent=`Sending…`;try{let e=await fetch(`/api/v1/invite`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({to:t,stream:S.shareLink})}),r=await e.json();n.shareNote.textContent=e.ok?`Sent to ${r.sent??t}.`:r.error??`that did not send`,e.ok&&(n.shareTo.value=``)}catch{n.shareNote.textContent=`could not send that`}})()}),n.listenHere.addEventListener(`change`,()=>{try{localStorage.setItem(we,n.listenHere.checked?`1`:`0`)}catch{}i===`remote`&&(async()=>{n.listenHere.checked?(await S.send({type:`stop`}),await Ee(c.index)):(x.stop(),p=-1),k()})()}),document.addEventListener(`keydown`,e=>{let t=e.target;if(!(t&&/^(INPUT|TEXTAREA|SELECT)$/.test(t.tagName)))switch(e.key){case` `:e.preventDefault(),De();return;case`s`:Oe();return;case`n`:case`ArrowRight`:O(1);return;case`p`:case`ArrowLeft`:O(-1);return;case`ArrowDown`:e.preventDefault(),D(Math.min(C()-1,w()+1));return;case`ArrowUp`:e.preventDefault(),D(Math.max(0,w()-1));return}});let zt=null;globalThis.addEventListener(`beforeinstallprompt`,e=>{e.preventDefault(),zt=e,n.install.hidden=!1}),n.install.addEventListener(`click`,()=>{zt?.prompt(),zt=null,n.install.hidden=!0});try{let e=localStorage.getItem(Ce);e!==null&&(n.volume.value=String(Math.round(Number(e)*100)),x.volume=Number(e));let t=localStorage.getItem(Se);t&&(n.remoteUrl.value=t),localStorage.getItem(we)===`0`&&(n.listenHere.checked=!1)}catch{}(async()=>{if(n.remoteUrl.value!==``)return;let e=globalThis.location.origin;if(await pe(e)===null)return;let t=await ue(e);t&&t.trackCount!==0&&(n.remoteUrl.value=e,i=`remote`,d=``,S.connect(e),k())})(),(()=>{if(Te)return;let e=async()=>{try{let e=await(await fetch(`/jingles/index.json`)).json();if(Array.isArray(e)&&e.length>0){let t=e[Math.floor(Math.random()*e.length)];if(typeof t==`string`)return`/jingles/${t}`}}catch{}return``},t=new Audio;t.volume=.7;let n=()=>{Te=!0},r=()=>{document.removeEventListener(`pointerdown`,r),document.removeEventListener(`keydown`,r),n(),t.play().catch(()=>{})};e().then(e=>{if(e!==``)return t.src=e,t.play().then(n,()=>{document.addEventListener(`pointerdown`,r,{once:!0}),document.addEventListener(`keydown`,r,{once:!0})})})})(),k(),requestAnimationFrame(Le)}D(),`serviceWorker`in navigator&&globalThis.addEventListener(`load`,()=>{navigator.serviceWorker.register(`/sw.js`).catch(()=>{})});export{c as t};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
:root{--bg:#080c09;--panel:#0c120e;--edge:#1d2c22;--green:#4af689;--green-dim:#227a4a;--fg:#cfe8d8;--muted:#6d8a79;--warn:#e8c35a;--accent:#7ef0c4;--lightningcss-light: ;--lightningcss-dark:initial;color-scheme:dark}*{box-sizing:border-box}[hidden]{display:none!important}html,body{background:var(--bg);min-height:100%;color:var(--fg);margin:0;font:14px/1.45 ui-monospace,SFMono-Regular,SF Mono,Menlo,Consolas,Liberation Mono,monospace}body{background-image:repeating-linear-gradient(#4af68906 0 1px,#0000 1px 3px)}#app{max-width:1100px;padding:calc(12px + env(safe-area-inset-top)) calc(12px + env(safe-area-inset-right)) calc(16px + env(safe-area-inset-bottom)) calc(12px + env(safe-area-inset-left));flex-direction:column;gap:10px;margin:0 auto;display:flex}.bar{flex-wrap:wrap;align-items:center;gap:10px;display:flex}.brand{color:var(--green);letter-spacing:.14em;font-weight:700}.status{color:var(--muted)}.status[data-playing=true]{color:var(--green)}.chip{color:var(--muted);border:1px solid var(--edge);text-overflow:ellipsis;white-space:nowrap;border-radius:999px;max-width:46vw;margin-left:auto;padding:1px 10px;font-size:12px;overflow:hidden}.panel{border:1px solid var(--edge);background:var(--panel);border-radius:6px;min-width:0;padding:14px 12px 12px;position:relative}.panel:before{content:attr(data-title);background:var(--panel);color:var(--green-dim);letter-spacing:.06em;padding:0 6px;font-size:12px;position:absolute;top:-.72em;left:10px}.split{grid-template-columns:1.3fr 1fr;gap:10px;display:grid}.split>.col-a{grid-column:1}.split>.col-b{grid-column:2}.stack{align-content:start;gap:14px;min-width:0;display:grid}.heart{color:var(--muted);cursor:pointer;background:0 0;border:1px solid #0000;border-radius:3px;padding:2px 6px;font-size:1.1em;line-height:1}.heart:hover{color:var(--accent);border-color:var(--accent)}.heart[data-on=yes]{color:var(--accent)}.directory-list li>.server-label{flex-direction:column;flex:auto;gap:2px;min-width:0;padding:4px 2px;display:flex}.directory-list li>.server-label .name{font-weight:600}.directory-list li>.server-label .detail{color:var(--muted);white-space:normal}.directory-list li>.server-label .live{color:var(--green)}@media (max-width:720px){.split{grid-template-columns:1fr}.split>.col-a,.split>.col-b{grid-column:auto}}.track-title{color:var(--accent);text-overflow:ellipsis;white-space:nowrap;font-weight:700;overflow:hidden}.track-sub{color:var(--muted);text-overflow:ellipsis;white-space:nowrap;overflow:hidden}#video{border:1px solid var(--edge);background:#000;border-radius:4px;width:100%;max-height:46vh;margin-bottom:8px}.scrub{align-items:center;gap:10px;margin-top:6px;display:flex}.time{color:var(--fg);font-variant-numeric:tabular-nums}.muted{color:var(--muted)}input[type=range]{appearance:none;cursor:pointer;background:0 0;flex:1;min-width:0;height:14px}input[type=range]::-webkit-slider-runnable-track{background:linear-gradient(var(--edge), var(--edge));border:1px solid var(--edge);border-radius:3px;height:6px}input[type=range]::-moz-range-track{background:var(--edge);border-radius:3px;height:6px}input[type=range]::-webkit-slider-thumb{appearance:none;background:var(--green);border-radius:2px;width:10px;height:16px;margin-top:-6px}input[type=range]::-moz-range-thumb{background:var(--green);border:0;border-radius:2px;width:10px;height:16px}input[type=range]:disabled{opacity:.45;cursor:default}#spectrum{border:1px solid var(--edge);background:#060a07;border-radius:4px;width:100%;height:190px;display:block}.meters{align-items:baseline;gap:10px;margin-top:6px;display:flex;overflow:hidden}.glyphs{color:var(--green);letter-spacing:1px;white-space:pre;flex:auto;min-width:0;min-height:1.4em;font-family:ui-monospace,SF Mono,Menlo,Consolas,monospace;overflow:hidden}.levelmeter{color:var(--accent);white-space:pre;font-variant-ligatures:none;text-align:right;flex:none;min-width:15ch;margin-left:auto;font-family:ui-monospace,SF Mono,Menlo,Consolas,monospace}.filter{border:1px solid var(--edge);width:100%;color:var(--fg);font:inherit;background:#0a100c;border-radius:4px;margin-bottom:6px;padding:4px 8px}.filter:focus{border-color:var(--accent);outline:none}.crumbs{color:var(--muted);flex-wrap:wrap;align-items:center;gap:4px;margin-bottom:6px;font-size:12px;display:flex}.crumbs button{font:inherit;color:var(--accent);cursor:pointer;background:0 0;border:0;padding:0 2px}.crumbs button:hover{text-decoration:underline}.crumbs .here{color:var(--fg)}.catalog-tag{color:var(--muted);letter-spacing:.06em;flex:none;font-size:11px}.catalog-live{color:var(--green)}#catalogs-entries{max-height:320px;overflow-y:auto}.folder{cursor:pointer;white-space:nowrap;color:var(--accent);border-radius:3px;gap:8px;padding:2px 6px;display:flex}.folder:hover{background:#142019}.folder .name{text-overflow:ellipsis;flex:1;overflow:hidden}.folder .count{color:var(--muted);flex:none}.playlist{scrollbar-color:var(--green-dim) transparent;max-height:214px;margin:0;padding:0;list-style:none;overflow-y:auto}.row{cursor:pointer;white-space:nowrap;border-radius:3px;gap:8px;padding:2px 6px;display:flex}.row:hover{background:#142019}.row.selected{background:#16241c}.row.selected .name{color:var(--accent)}.row.playing .name{color:var(--green)}.group{color:var(--muted);letter-spacing:.08em;text-transform:uppercase;border-top:1px solid var(--edge);align-items:center;gap:8px;margin-top:4px;padding:6px 6px 2px;font-size:11px;display:flex}.group:first-child{border-top:0;margin-top:0}.group-name{text-overflow:ellipsis;white-space:nowrap;flex:1;overflow:hidden}.group-remove{border:1px solid var(--edge);color:var(--muted);cursor:pointer;background:0 0;border-radius:3px;flex:none;padding:0 6px;line-height:1.4}.group-remove:hover{color:var(--accent);border-color:var(--accent)}.row .n{color:var(--muted);text-align:right;flex:none;width:2.4em}.row .name{text-overflow:ellipsis;flex:1;overflow:hidden}.row .time{color:var(--muted);flex:none}.row-copy{color:var(--muted);cursor:pointer;opacity:.55;background:0 0;border:1px solid #0000;border-radius:3px;flex:none;padding:0 5px;line-height:1.4}.row:hover .row-copy,.row.selected .row-copy{opacity:1}.row-copy:hover{color:var(--accent);border-color:var(--accent)}.transport{border:1px solid var(--edge);background:var(--panel);border-radius:6px;flex-wrap:wrap;align-items:center;gap:8px;padding:8px 10px;display:flex}button{font:inherit;color:var(--fg);border:1px solid var(--edge);cursor:pointer;background:#121a15;border-radius:4px;padding:6px 12px}button:hover{border-color:var(--green-dim);color:var(--green)}button:active{transform:translateY(1px)}button:focus-visible,input:focus-visible,a:focus-visible{outline:2px solid var(--green);outline-offset:2px}button.primary{color:var(--green);border-color:var(--green-dim);min-width:64px}button.ghost{color:var(--muted);background:0 0}.volume{flex:1;align-items:center;gap:8px;min-width:120px;max-width:220px;margin-left:auto;display:flex}.vol{color:var(--muted);letter-spacing:.08em;font-size:12px}.picker{flex-wrap:wrap;align-items:center;gap:8px;display:flex}.button{border:1px solid var(--edge);cursor:pointer;color:var(--fg);background:#121a15;border-radius:4px;padding:6px 12px;display:inline-block}.button:hover{border-color:var(--green-dim);color:var(--green)}.button input[type=file]{display:none}#remote-url{font:inherit;min-width:12ch;color:var(--fg);border:1px solid var(--edge);background:#060a07;border-radius:4px;flex:1;padding:6px 10px}.check{color:var(--muted);align-items:center;gap:8px;margin-top:10px;display:flex}.check input{accent-color:var(--green)}.hint{color:var(--muted);margin:0 0 8px;font-size:13px}.hint code{color:var(--accent)}#remote-state[data-status=live]{color:var(--green)}#remote-state[data-status=connecting],#remote-state[data-status=error]{color:var(--warn)}.note{color:var(--warn);border-left:2px solid var(--warn);margin:0;padding-left:8px}.statusbar{color:var(--muted);border-top:1px solid var(--edge);flex-wrap:wrap;gap:14px;padding-top:8px;font-size:12px;display:flex}.statusbar b{color:var(--green);font-weight:700}.statusbar .spacer{flex:1}.statusbar a{color:var(--muted)}.directory{border-top:1px solid var(--line);margin-top:.6rem;padding-top:.6rem}.directory-list{max-height:12rem;margin:0;padding:0;list-style:none;overflow-y:auto}.directory-list li+li{margin-top:.3rem}.directory-list button{border:1px solid var(--line);color:inherit;font:inherit;cursor:pointer;background:0 0;border-radius:4px;padding:.4rem .5rem}.directory-list button:hover,.directory-list button:focus-visible{border-color:var(--accent);background:#ffffff0a}.directory-list .name{color:var(--accent);display:block}.directory-list .detail{opacity:.7;text-overflow:ellipsis;white-space:nowrap;font-size:.85em;display:block;overflow:hidden}.publish-list{margin:.3rem 0 0;padding:0;list-style:none}.publish-list li{align-items:center;gap:8px;margin-top:.3rem;display:flex}.publish-list li.in-use .slot{color:var(--green)}.publish-list .slot{color:var(--muted);flex:none;min-width:4.5em;font-size:12px}.publish-list input{flex:auto;min-width:0}.said{color:var(--accent);margin:.3rem 0 0}.directory-list li.offline .recent-label{opacity:.55}.directory-list li.offline .detail{color:var(--warn)}.share-line{align-items:center;gap:8px;margin:.4rem 0;display:flex}.share-what{color:var(--muted);letter-spacing:.06em;text-transform:uppercase;flex:none;font-size:12px}.share-line input{flex:auto;min-width:0}#share-phone{color:var(--fg);font-size:1.05em}#share-phone b{color:var(--accent)}.admin-table{border-collapse:collapse;width:100%;min-height:5.5em;max-height:14rem;margin:.4rem 0;font-size:.85em;display:block;overflow-y:auto}.admin-table th{text-align:left;opacity:.6;padding:.2rem .4rem .2rem 0;font-weight:400}.admin-table td{white-space:nowrap;text-overflow:ellipsis;max-width:12rem;padding:.2rem .4rem .2rem 0;overflow:hidden}.admin-table td.network-public{color:var(--warning,#e0b341)}.admin-table td.network-private{color:var(--success,#7fd18b)}.admin-table tr.ended{opacity:.45}body.route-directory .player-only{display:none}.directory-list li{align-items:stretch;gap:.4rem;display:flex}.directory-list li>:first-child{flex:auto;min-width:0}.directory-list li>button:first-child{text-align:left;width:100%}.directory-list li>.button,.directory-list li>.ghost{white-space:nowrap;flex:none;align-items:center;display:flex}.directory-list .follow{white-space:nowrap;width:auto;color:var(--muted);flex:none;padding-inline:.6rem}.directory-list .follow[data-following=yes]{border-color:var(--accent);color:var(--accent)}.toggle{color:var(--muted);cursor:pointer;align-items:center;gap:.35rem;display:inline-flex}.toggle input{accent-color:var(--accent)}.recent-label{border:1px solid var(--line);border-radius:4px;flex:auto;min-width:0;padding:.4rem .5rem}
|