nixamp 0.80.1 → 0.80.2
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/ai-label.d.ts +1 -1
- package/dist/ai-label.js +3 -2
- package/package.json +1 -1
- package/src/ai-label.ts +3 -2
- package/web/dist/assets/{ar-C5qVRZh9.js → ar-jQ_1OaPw.js} +1 -1
- package/web/dist/assets/{cs-fajZsJrs.js → cs-_goMpUzl.js} +1 -1
- package/web/dist/assets/{da-fycV1k1N.js → da-BgRIZmHA.js} +1 -1
- package/web/dist/assets/{de-QUzTQ_9X.js → de-BzryMgxO.js} +1 -1
- package/web/dist/assets/{es-CQu2leAJ.js → es-Bspt-kuE.js} +1 -1
- package/web/dist/assets/{fi-AgKEsukC.js → fi-74bqR7jK.js} +1 -1
- package/web/dist/assets/{fr-CRbHnW4y.js → fr-C0yUFanu.js} +1 -1
- package/web/dist/assets/{hi-BuU7xy9L.js → hi-Bow4uBzj.js} +1 -1
- package/web/dist/assets/{hu-C40Z-HcJ.js → hu-C_2Dn0h7.js} +1 -1
- package/web/dist/assets/{id-2b7626UL.js → id-C8L6KxB3.js} +1 -1
- package/web/dist/assets/{it-7sr3nJuS.js → it-DMNQHxWL.js} +1 -1
- package/web/dist/assets/{main-zuI3sOLC.js → main-C5xMXFFr.js} +2 -2
- package/web/dist/assets/{nl-BdDGgfzj.js → nl-8e4KRSbc.js} +1 -1
- package/web/dist/assets/{ru-BMGI8Oa4.js → ru-VCpBV7hb.js} +1 -1
- package/web/dist/assets/{sv-BXASdl7c.js → sv-9BcESvUT.js} +1 -1
- package/web/dist/assets/{uk-urnhuqtG.js → uk-D0xNvfSC.js} +1 -1
- package/web/dist/assets/{vi-BhLPAKuD.js → vi-CTmBIxVv.js} +1 -1
- package/web/dist/assets/{zh-BaOCIB9u.js → zh-BQ28dg08.js} +1 -1
- package/web/dist/index.html +1 -1
- package/web/dist/sw.js +19 -19
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import"./modulepreload-polyfill-P2Xu9kJm.js";import{c as e,i as t,n,t as r}from"./chunk-NW3WDGEQ-CnyjTRUh.js";import{a as i,i as a,n as o,r as s,t as c}from"./client-D7waX8NA.js";import{n as l}from"./now-playing-DVQqWQIu.js";import{a as u,c as d,d as f,i as p,l as m,n as ee,o as te,r as ne,s as re,t as ie,u as ae}from"./remote-DJqvFdE6.js";var oe={"Nixamp Share link or HTTPS media URL":`Nixamp Share link or HTTPS media URL`,"For TV playback, use a Nixamp Share link or a direct HTTPS media URL. Pairux viewing opens separately.":`For TV playback, use a Nixamp Share link or a direct HTTPS media URL. Pairux viewing opens separately.`,Paused:`Paused`,"Broadcast ended":`Broadcast ended`,"Class broadcast":`Class broadcast`,Play:`Play`,Pause:`Pause`,"Retry playback":`Retry playback`,"Back 10 seconds":`Back 10 seconds`,"Forward 10 seconds":`Forward 10 seconds`,Mute:`Mute`,Unmute:`Unmute`,"Full screen":`Full screen`,"Exit full screen":`Exit full screen`,Playing:`Playing`,"Select Play to watch the broadcast.":`Select Play to watch the broadcast.`,"The broadcast could not be loaded. Try again.":`The broadcast could not be loaded. Try again.`,"This Pairux broadcast opens separately. For playback here on Fire TV, the host needs to share a Nixamp stream or direct media link.":`This Pairux broadcast opens separately. For playback here on Fire TV, the host needs to share a Nixamp stream or direct media link.`,"Open on Pairux":`Open on Pairux`,"Supported platforms":`Supported platforms`,"In review":`In review`,"Not available":`Not available`,"Install PWA":`Install PWA`,"PWA installed":`PWA installed`,"Web app":`Web app`,"Install the web app":`Install the web app`,"Keep BackToSchool on your home screen or desktop. No app store needed.":`Keep BackToSchool on your home screen or desktop. No app store needed.`,"iPhone or iPad: open this site in Safari, tap Share, then Add to Home Screen.":`iPhone or iPad: open this site in Safari, tap Share, then Add to Home Screen.`,"Android: open your browser menu and choose Install app or Add to Home screen.":`Android: open your browser menu and choose Install app or Add to Home screen.`,"Desktop: look for Install in the address bar or browser menu. The option depends on your browser.":`Desktop: look for Install in the address bar or browser menu. The option depends on your browser.`,"You can also keep using BackToSchool in this browser.":`You can also keep using BackToSchool in this browser.`,"The web app is installed. You can keep learning here.":`The web app is installed. You can keep learning here.`,"Continue learning":`Continue learning`,"The install prompt could not open. Select Web app again for installation instructions.":`The install prompt could not open. Select Web app again for installation instructions.`,"Follow host":`Follow host`,Following:`Following`,"You’ll get email and web notifications for this host.":`You’ll get email and web notifications for this host.`,"Notifications turned off for this host.":`Notifications turned off for this host.`,"Could not update notifications.":`Could not update notifications.`},se={...oe,"No parties live right now.":`No parties live right now.`,"Could not refresh parties.":`Could not refresh parties.`,"Pick a server in the directory, or paste its link here.":`Pick a server in the directory, or paste its link here.`,"Interface language":`Interface language`,Language:`Language`,"Translation language":`Translation language`,"Original (auto-detect)":`Original (auto-detect)`,Play:`Play`,Pause:`Pause`,Stop:`Stop`,Next:`Next`,Previous:`Previous`,Select:`Select`,"Next/Prev":`Next/Prev`,Quit:`Quit`,"Now Playing":`Now Playing`,"Spectrum Analyser":`Spectrum Analyser`,Playlist:`Playlist`,Files:`Files`,"Open files":`Open files`,"Open folder":`Open folder`,"Add to library":`Add to library`,"Replace playlist":`Replace playlist`,Filter:`Filter`,Search:`Search`,"Nothing loaded.":`Nothing loaded.`,"Empty.":`Empty.`,"Loading…":`Loading…`,"Connecting…":`Connecting…`,Connected:`Connected`,"Not connected":`Not connected`,"No source":`No source`,Playing:`Playing`,Stopped:`Stopped`,Volume:`Volume`,Seek:`Seek`,"Full screen":`Full screen`,Download:`Download`,Share:`Share`,Copy:`Copy`,"Copy link":`Copy link`,Copied:`Copied`,Save:`Save`,Cancel:`Cancel`,Close:`Close`,Remove:`Remove`,Delete:`Delete`,Edit:`Edit`,Add:`Add`,Send:`Send`,Retry:`Retry`,Back:`Back`,"Next page":`Next page`,"Previous page":`Previous page`,"Show more":`Show more`,Panels:`Panels`,"Reset layout":`Reset layout`,Show:`Show`,Hide:`Hide`,Collapse:`Collapse`,Expand:`Expand`,"Move up":`Move up`,"Move down":`Move down`,Install:`Install`,"TV mode":`TV mode`,On:`On`,Off:`Off`,Account:`Account`,"Sign in":`Sign in`,"Sign out":`Sign out`,"Create account":`Create account`,Email:`Email`,Password:`Password`,"Forgot password?":`Forgot password?`,"Welcome back":`Welcome back`,Profile:`Profile`,Handle:`Handle`,"Your servers":`Your servers`,Server:`Server`,Connect:`Connect`,Disconnect:`Disconnect`,Directory:`Directory`,Favourites:`Favourites`,Follow:`Follow`,Unfollow:`Unfollow`,Notifications:`Notifications`,"Phone number":`Phone number`,"Save number":`Save number`,Transcript:`Transcript`,Captions:`Captions`,"Translate audio":`Translate audio`,"Audio language":`Audio language`,"Audio options":`Audio options`,"Keep background sound":`Keep background sound`,"Background level":`Background level`,"Speaker voices":`Speaker voices`,"Any voice":`Any voice`,"Male voice":`Male voice`,"Female voice":`Female voice`,"Original audio.":`Original audio.`,"Buy translated audio":`Buy translated audio`,"Audio credit":`Audio credit`,"Buy pass":`Buy pass`,Pass:`Pass`,"Pay with":`Pay with`,"Check payment":`Check payment`,"Open checkout":`Open checkout`,"Free sessions":`Free sessions`,"Usage rates and expiry":`Usage rates and expiry`,Catalogs:`Catalogs`,"Add catalog":`Add catalog`,"Catalog name":`Catalog name`,Link:`Link`,"Play link":`Play link`,"Go live":`Go live`,Publish:`Publish`,Listen:`Listen`,"Live now":`Live now`,Upcoming:`Upcoming`,Parties:`Parties`,"Join party":`Join party`,"Invite code":`Invite code`,Invite:`Invite`,Chat:`Chat`,"Chat message":`Chat message`,People:`People`,Speaker:`Speaker`,Speakers:`Speakers`,Listener:`Listener`,Moderator:`Moderator`,"Raise hand":`Raise hand`,"Hand raises":`Hand raises`,Questions:`Questions`,Resources:`Resources`,Replay:`Replay`,Schedule:`Schedule`,Event:`Event`,Host:`Host`,About:`About`,Stage:`Stage`,Title:`Title`,Description:`Description`,Topic:`Topic`,Public:`Public`,"Anyone with the link":`Anyone with the link`,"Invited people":`Invited people`,"Who can join":`Who can join`,"Date and time":`Date and time`,"Expected length":`Expected length`,Repeat:`Repeat`,"Does not repeat":`Does not repeat`,"Every day":`Every day`,"Every week":`Every week`,Homepage:`Homepage`,"Host name":`Host name`,"Profile photo URL":`Profile photo URL`,"Broadcast link":`Broadcast link`,"Edit event":`Edit event`,"Save changes":`Save changes`,"Create live":`Create live`,"Schedule class":`Schedule class`,"Start class":`Start class`,"End event":`End event`,"End session":`End session`,"Session ended":`Session ended`,"Event ended":`Event ended`,Cancelled:`Cancelled`,"Replay available":`Replay available`,Join:`Join`,"Create invite":`Create invite`,"Invite as":`Invite as`,"Watch now":`Watch now`,"Start a room":`Start a room`,"Recent replays":`Recent replays`,"Your account":`Your account`,"Write with AI":`Write with AI`,"Suggested title":`Suggested title`,"Suggested description":`Suggested description`,"Suggested topic":`Suggested topic`,"Use these details":`Use these details`,"Learn something live.":`Learn something live.`,"Screen share":`Screen share`,"Upload and broadcast":`Upload and broadcast`,Help:`Help`,"Reload Player":`Reload Player`,"Copy Bundled CLI Path":`Copy Bundled CLI Path`,"Developer tools":`Developer tools`,Undo:`Undo`,Redo:`Redo`,Cut:`Cut`,Paste:`Paste`,"Select all":`Select all`,Status:`Status`,"Activity log":`Activity log`,Admin:`Admin`,"Playback controls":`Playback controls`,"Tracks and folders":`Tracks and folders`,"Original-language captions.":`Original-language captions.`,"Skip to playback controls":`Skip to playback controls`,"Skip to playlist":`Skip to playlist`,"Skip to transcript and translated audio":`Skip to transcript and translated audio`},ce={"■ STOPPED":`Stopped`,"▶ PLAYING":`Playing`,LOADING:`Loading…`,"no source":`No source`,"not connected":`Not connected`,"Now playing":`Now Playing`,"● GO LIVE":`Go live`,"● Go live":`Go live`,"⤓ Download":`Download`,"A man's voice":`Male voice`,"A woman's voice":`Female voice`,"Catalogs on this server":`Catalogs`,"Catalog folders":`Catalogs`,"Parties on this server":`Parties`,"Servers streaming now":`Directory`,"Playlist (0)":`Playlist`,"Playlist folders":`Playlist`,"Playlist pages":`Playlist`,"Filter these files":`Filter`,"Filter these entries":`Filter`,"Filter the entries":`Filter`,"Filter the playlist":`Filter`,"Create a free account":`Create account`,"Create one":`Create account`,"Create your account":`Create account`,"New here? Create an account":`Create account`,"Already have an account? Sign in":`Sign in`,"Your NixAmp account":`Your account`,"Your public handle":`Handle`,handle:`Handle`,password:`Password`,"Phone number for texts":`Phone number`,"Back to the player":`Back`,"Share what is playing":`Share`,"Share this stream":`Share`,"Link to this stream":`Link`,"Copy this stream's URL":`Copy link`,"A link to play":`Link`,"A server's link":`Server`,"Close translated audio purchase":`Close`,"Open secure checkout ↗ (new tab)":`Open checkout`,"Checking…":`Loading…`,"Browse the directory":`Directory`,"See what is live":`Live now`,"Join live":`Join`,"Raise Hand":`Raise hand`,"Hand Raises":`Hand raises`,"Hide this":`Hide`,Log:`Activity log`,"Status:":`Status`,"Nixamp player":`Playback controls`,"Nixamp audio and video player":`Playback controls`,"What is being said":`Transcript`,"The room's chat":`Chat`,Trollbox:`Chat`,"A line for the trollbox":`Chat message`,"Say something to the room…":`Chat message`,"Send it":`Send`,"Something to add":`Chat message`,"What to call it":`Catalog name`,"call it something":`Catalog name`,"An m3u catalog to add":`Catalogs`,"On this device":`Play`,"Play on this device":`Play`,"What this is":`About`,"Looking for servers…":`Loading…`,"Finding today’s conversations…":`Loading…`,"Coming up":`Upcoming`,"Listen after class":`Replay`,"Schedule live":`Schedule class`,"Schedule a class":`Schedule class`,"Plan a conversation":`Schedule class`,"Your classroom":`Event`,"Join in":`Join`,"Open a room →":`Start a room`,"Chat message":`Chat message`,"Add to the conversation":`Chat message`,"Create live":`Create live`,"Host stage":`Stage`,"Your host":`Host`,"Class host":`Host`,"Hand raised ✓":`Raise hand`,"Copied ✓":`Copied`,"Screen share with Pairux ↗":`Screen share`,"Upload & broadcast in Nixamp ↗":`Upload and broadcast`,"Open Music Folder…":`Open folder`,"Choose a music folder":`Open folder`,"Main navigation":`Panels`,"Skip to a section":`Panels`},le=[{code:`en`,label:`English`},{code:`de`,label:`Deutsch`},{code:`sv`,label:`Svenska`},{code:`es`,label:`Español`},{code:`fr`,label:`Français`},{code:`it`,label:`Italiano`},{code:`nl`,label:`Nederlands`},{code:`da`,label:`Dansk`},{code:`fi`,label:`Suomi`},{code:`ru`,label:`Русский`},{code:`uk`,label:`Українська`},{code:`cs`,label:`Čeština`},{code:`hu`,label:`Magyar`},{code:`zh`,label:`中文`},{code:`ar`,label:`العربية`},{code:`hi`,label:`हिन्दी`},{code:`vi`,label:`Tiếng Việt`},{code:`id`,label:`Bahasa Indonesia`}],h=`nixamp.ui.language`;function g(e){let t=typeof e==`string`?e.trim().toLowerCase().split(/[-_.@]/)[0]:``;return le.find(e=>e.code===t)?.code??`en`}function ue(e,t=[]){let n=e=>{let t=typeof e==`string`?e.trim().toLowerCase().split(/[-_.@]/)[0]:``;return le.find(e=>e.code===t)?.code};return n(e)??t.map(n).find(Boolean)??`en`}var de={en:async()=>({default:se}),de:()=>e(()=>import(`./de-QUzTQ_9X.js`),[]),sv:()=>e(()=>import(`./sv-BXASdl7c.js`),[]),es:()=>e(()=>import(`./es-CQu2leAJ.js`),[]),fr:()=>e(()=>import(`./fr-CRbHnW4y.js`),[]),it:()=>e(()=>import(`./it-7sr3nJuS.js`),[]),nl:()=>e(()=>import(`./nl-BdDGgfzj.js`),[]),da:()=>e(()=>import(`./da-fycV1k1N.js`),[]),fi:()=>e(()=>import(`./fi-AgKEsukC.js`),[]),ru:()=>e(()=>import(`./ru-BMGI8Oa4.js`),[]),uk:()=>e(()=>import(`./uk-urnhuqtG.js`),[]),cs:()=>e(()=>import(`./cs-fajZsJrs.js`),[]),hu:()=>e(()=>import(`./hu-C40Z-HcJ.js`),[]),zh:()=>e(()=>import(`./zh-BaOCIB9u.js`),[]),ar:()=>e(()=>import(`./ar-C5qVRZh9.js`),[]),hi:()=>e(()=>import(`./hi-BuU7xy9L.js`),[]),vi:()=>e(()=>import(`./vi-BhLPAKuD.js`),[]),id:()=>e(()=>import(`./id-2b7626UL.js`),[])},_=new class{load;code=`en`;get language(){return this.code}constructor(e=async e=>(await de[e]()).default){this.load=e}messages=se;revision=0;numberFormats=new Map;dateFormats=new Map;listeners=new Set;async setLanguage(e){let t=++this.revision,n=g(e),r=await this.load(n);if(t!==this.revision)return!1;this.code=n,this.messages=r,this.numberFormats.clear(),this.dateFormats.clear();for(let e of this.listeners)e();return!0}onChange(e){return this.listeners.add(e),()=>this.listeners.delete(e)}text(e,t={}){let n=this.language!==`en`&&Object.hasOwn(ce,e)?ce[e]:e,r=Object.hasOwn(this.messages,n)?this.messages[n]:e;return this.language!==`en`&&Object.hasOwn(ce,e)&&(r=(e.match(/^[▶■●⤓]\s+/)?.[0]??``)+r+(e.endsWith(` ✓`)?` ✓`:``)),r.replace(/\{([\w]+)\}/g,(e,n)=>Object.hasOwn(t,n)?String(t[n]):e)}number(e,t){let n=JSON.stringify(t??{}),r=this.numberFormats.get(n);return r||(this.numberFormats.size>=64&&this.numberFormats.clear(),r=new Intl.NumberFormat(this.language,t),this.numberFormats.set(n,r)),r.format(e)}date(e,t){let n=JSON.stringify(t??{}),r=this.dateFormats.get(n);return r||(this.dateFormats.size>=64&&this.dateFormats.clear(),r=new Intl.DateTimeFormat(this.language,t),this.dateFormats.set(n,r)),r.format(e)}get direction(){return this.language===`ar`?`rtl`:`ltr`}},v=(e,t)=>_.text(e,t),y=[`active`,`trialing`];function b(e,t,n=new Date){if(!e?.length)return!1;let r=new Set(y);return e.some(e=>{if(e.product!==t||!r.has(e.status))return!1;let i=e.period?.end?Date.parse(e.period.end):NaN;if(Number.isFinite(i)&&i<n.getTime())return!1;let a=e.period?.start?Date.parse(e.period.start):NaN;return!(Number.isFinite(a)&&a>n.getTime())})}async function fe(e){let t=null;try{t=await e.entitlements()??null}catch{return e.ads}let n=e.now?.()??new Date;return b(t,e.product,n)?null:e.ads}var pe=600,me=`https://crawlproof.com/api/ads/stream`,he=`nixamp.pro`;function ge(){let e=document.querySelector(`#video`);return e&&!e.hidden&&e.currentSrc&&!e.paused?`video`:`audio`}async function _e(){try{let e=await fetch(`/api/entitlements`,{credentials:`include`,headers:{accept:`application/json`}});if(!e.ok)return[];let t=await e.json();return Array.isArray(t)?t:t.entitlements??[]}catch{return[]}}var ve=`7e0ea02c-c40f-4cdd-b4d3-93b2baca8f2c`;function x(e){let t=new URLSearchParams(e),n=t.get(`ads`),r=Number(t.get(`adsEvery`)),i=t.get(`adNow`);return{enabled:i===null?n===null?null:n!==`0`&&n!==`false`:!0,everySeconds:Number.isFinite(r)&&r>0?Math.min(3600,Math.max(5,r)):null,adUrl:be(t.get(`adUrl`)),now:i!==null&&i!==`0`&&i!==`false`}}function ye(e=location.search){return x(e).now}function be(e){if(!e)return null;try{let t=new URL(e,location.origin);return t.protocol===`https:`?t.toString():null}catch{return null}}var xe=null;function Se(e){if(xe)try{let t=`${xe.endpoint}?d=${encodeURIComponent(xe.decision)}&t=${encodeURIComponent(e)}&s=player`;new Image().src=t}catch{}}async function Ce(e={},t=location.search){let n=x(t);if(n.enabled===!1)return null;let r={everySeconds:n.everySeconds??e.everySeconds??pe,next:async()=>{if(n.adUrl)return{url:n.adUrl};try{let t=`${me}?slot=${encodeURIComponent(e.slot??ve)}&kind=${ge()}`,n=await fetch(t,{headers:{accept:`application/json`}});if(!n.ok)return null;let r=await n.json();return r.url?(xe=r.decisionId&&r.eventsUrl?{decision:r.decisionId,endpoint:r.eventsUrl,url:r.url}:null,{url:r.url,kind:r.kind}):null}catch{return null}},onBreakStart:e=>{xe&&xe.url!==e.url&&(xe=null),Se(`start`)},onBreakEnd:e=>{Se(e.skipped?`abandon`:`complete`),xe=null},onError:e=>{Se(`error`),xe=null,console.warn(`advert failed`,e)}};return n.enabled===!0?r:e.paid===!0?null:fe({product:he,entitlements:_e,ads:r})}var S=new Map;function we(e,t,n){let r=S.get(e);r||(r=new Map,S.set(e,r)),r.set(t,n),n()}function C(e,t){e instanceof Element&&e.removeAttribute(`data-i18n`);let n=``,r;return we(e,`text`,()=>{r!==void 0&&e.textContent!==r?S.get(e)?.delete(`text`):(n=t()??``,r=n,e.textContent!==n&&(e.textContent=n))}),n}function w(e,t,n){e.removeAttribute(`data-i18n-${t}`);let r=``,i;return we(e,t,()=>{i!==void 0&&e.getAttribute(t)!==i?S.get(e)?.delete(t):(r=n()??``,i=r,e.getAttribute(t)!==r&&e.setAttribute(t,r))}),r}var T=[`aria-label`,`title`,`placeholder`,`data-title`],Te=[`[data-i18n]`,...T.map(e=>`[data-i18n-${e}]`)].join(`,`);function E(e){let t=[...e.querySelectorAll(Te)];e instanceof HTMLElement&&e.matches(Te)&&t.unshift(e);for(let e of t){if(e.closest(`[translate="no"], [contenteditable="true"]`))continue;let t=e.getAttribute(`data-i18n`);if(t){let n=e.textContent;we(e,`text`,()=>{e.textContent===n?(n=v(t),e.textContent!==n&&(e.textContent=n)):(S.get(e)?.delete(`text`),e.removeAttribute(`data-i18n`))})}for(let t of T){let n=e.getAttribute(`data-i18n-${t}`);if(n){let r=e.getAttribute(t);we(e,t,()=>{e.getAttribute(t)===r?(r=v(n),e.getAttribute(t)!==r&&e.setAttribute(t,r)):(S.get(e)?.delete(t),e.removeAttribute(`data-i18n-${t}`))})}}}}function Ee(){document.documentElement.lang=_.language,document.documentElement.dir=_.direction;for(let[e,t]of S)if(!e.isConnected)S.delete(e);else for(let e of t.values())e();for(let e of document.querySelectorAll(`[data-ui-language]`))e.value=_.language}var De=0;async function D(e){let t=++De;try{if(!await _.setLanguage(e)||t!==De)return;try{localStorage.setItem(h,_.language)}catch{}window.nixampLanguage?.set(_.language).catch(()=>{})}catch{Ee()}}async function Oe(){let e=ue(null,navigator.languages);try{e=ue(await window.nixampLanguage?.get()??localStorage.getItem(`nixamp.ui.language`),navigator.languages)}catch{}for(let e of document.querySelectorAll(`[data-ui-language]`))e.replaceChildren(...le.map(e=>{let t=new Option(e.label,e.code);return t.lang=e.code,t.dir=`auto`,t})),e.addEventListener(`change`,()=>{D(e.value)});E(document),Ee(),_.onChange(Ee),new MutationObserver(e=>{for(let t of e)for(let e of t.addedNodes)e instanceof Element&&E(e);for(let e of S.keys())e.isConnected||S.delete(e)}).observe(document.body,{childList:!0,subtree:!0}),window.addEventListener(`storage`,e=>{e.key===`nixamp.ui.language`&&_.setLanguage(ue(e.newValue,navigator.languages)).catch(()=>{})}),window.nixampLanguage?.subscribe(e=>{e!==_.language&&_.setLanguage(e).catch(()=>{})});try{await _.setLanguage(e)}catch{}}var ke={play:`<span aria-hidden="true">▶</span>`,party:`<svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m3 21 4-12 8 8Z"/><path d="m7 9 8 8M12 7l1-3M16 10l4-1M16 5l2-2M20 14l1 1M8 4l-1-1"/><circle cx="21" cy="4" r=".5" fill="currentColor"/></svg>`,rename:`<svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M12 20h9"/><path d="M16.5 3.5a2.1 2.1 0 0 1 3 3L7 19l-4 1 1-4Z"/></svg>`,eye:`<svg viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M2 12s3.5-7 10-7 10 7 10 7-3.5 7-10 7S2 12 2 12Z"/><circle cx="12" cy="12" r="3"/></svg>`,gear:`<svg viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="12" cy="12" r="3"/><path d="M19.4 15a1.7 1.7 0 0 0 .3 1.8l.1.1a2 2 0 1 1-2.8 2.8l-.1-.1a1.7 1.7 0 0 0-1.8-.3 1.7 1.7 0 0 0-1 1.5V21a2 2 0 1 1-4 0v-.1a1.7 1.7 0 0 0-1.1-1.5 1.7 1.7 0 0 0-1.8.3l-.1.1a2 2 0 1 1-2.8-2.8l.1-.1a1.7 1.7 0 0 0 .3-1.8 1.7 1.7 0 0 0-1.5-1H3a2 2 0 1 1 0-4h.1a1.7 1.7 0 0 0 1.5-1.1 1.7 1.7 0 0 0-.3-1.8l-.1-.1a2 2 0 1 1 2.8-2.8l.1.1a1.7 1.7 0 0 0 1.8.3H9a1.7 1.7 0 0 0 1-1.5V3a2 2 0 1 1 4 0v.1a1.7 1.7 0 0 0 1 1.5 1.7 1.7 0 0 0 1.8-.3l.1-.1a2 2 0 1 1 2.8 2.8l-.1.1a1.7 1.7 0 0 0-.3 1.8V9a1.7 1.7 0 0 0 1.5 1H21a2 2 0 1 1 0 4h-.1a1.7 1.7 0 0 0-1.5 1Z"/></svg>`,live:`<svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="12" cy="12" r="2.5"/><path d="M8.5 15.5a5 5 0 0 1 0-7"/><path d="M15.5 8.5a5 5 0 0 1 0 7"/><path d="M5.6 18.4a9 9 0 0 1 0-12.8"/><path d="M18.4 5.6a9 9 0 0 1 0 12.8"/></svg>`,link:`<svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M10 13a5 5 0 0 0 7.5.5l3-3a5 5 0 0 0-7-7l-1.7 1.7"/><path d="M14 11a5 5 0 0 0-7.5-.5l-3 3a5 5 0 0 0 7 7l1.7-1.7"/></svg>`,copy:`<svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="9" y="9" width="12" height="12" rx="2"/><path d="M5 15V5a2 2 0 0 1 2-2h10"/></svg>`,restart:`<svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M21 12a9 9 0 1 1-3-6.7"/><path d="M21 3v6h-6"/></svg>`,remove:`<svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" aria-hidden="true"><path d="M18 6 6 18"/><path d="m6 6 12 12"/></svg>`,check:`<svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m5 12 5 5L20 7"/></svg>`};function Ae(e,t){e.innerHTML=ke[t]}function je(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 Me(e){return e.artist?`${e.artist} — ${e.title}`:e.title}function Ne(e){let t=e.split(`/`).pop()??e,n=t.lastIndexOf(`.`);return n>0?t.slice(0,n):t}var Pe=new Set([`mp4`,`webm`,`mkv`,`mov`,`m4v`,`ogv`,`avi`,`ts`,`m2ts`,`mts`,`m2t`,`trp`,`tp`]);function O(e,t=``){if(t.startsWith(`video/`))return!0;if(t.startsWith(`audio/`))return!1;let n=e.lastIndexOf(`.`);return n>0&&Pe.has(e.slice(n+1).toLowerCase())}function Fe(){let e=document.getElementById(`sr-status`);if(!e)return;let t=[`note`,`account-note`,`remote-state`,`transcript-audio-note`,`notify-note`,`notify-phone-note`,`persona-note`],n=new Map,r,i=``;for(let a of t){let t=document.getElementById(a);t&&(n.set(a,t.textContent?.trim()??``),new MutationObserver(()=>{let o=t.textContent?.trim()??``;n.get(a)!==o&&(n.set(a,o),o&&!t.closest(`[hidden], [data-closed], [data-collapsed]`)&&(i=o,clearTimeout(r),r=setTimeout(()=>{e.textContent!==i&&(e.textContent=i)},200)))}).observe(t,{childList:!0,characterData:!0,subtree:!0}))}}var Ie=new WeakMap;function Le(e,t=!0){let n=e.contains(document.activeElement);Ie.delete(e),t&&e.replaceChildren(),n&&(e.tabIndex=-1,e.focus({preventScroll:!0}))}function k(e,...t){if(document.activeElement===e||!e.contains(document.activeElement)){Ie.delete(e),e.replaceChildren(...t);return}let n=Ie.has(e);if(Ie.set(e,t),n)return;let r=()=>{let t=Ie.get(e);t&&(document.activeElement!==e&&e.contains(document.activeElement)?e.addEventListener(`focusout`,i,{once:!0}):(Ie.delete(e),e.replaceChildren(...t)))},i=()=>{setTimeout(r,0)};e.addEventListener(`focusout`,i,{once:!0})}var Re=new WeakMap,ze=new WeakSet;function Be(e,t){let n=new Map([...e.children].map(e=>[e.dataset.liveKey,e])),r=new Set(t.map(e=>e.dataset.liveKey)),i=!1;for(let r of t){let t=n.get(r.dataset.liveKey);t?t!==r&&!t.isEqualNode(r)&&(t.contains(document.activeElement)||t.querySelector(`details[open]`)?i=!0:t.replaceWith(r)):e.append(r)}for(let[e,t]of n)r.has(e)||(t.contains(document.activeElement)?i=!0:t.remove());if(i?Re.set(e,t):Re.delete(e),ze.has(e))return;ze.add(e);let a=()=>{let t=Re.get(e);t&&Be(e,t)};e.addEventListener(`focusout`,()=>{setTimeout(a,0)}),e.addEventListener(`toggle`,a,!0)}function Ve(e){if(!/\.(?:mp4|m4v|mkv|webm|mov|avi|mp3|m4a|flac|ogg|opus|wav|aac)$/i.test(e))return e;let t=(e.split(/[\\/]/).pop()??e).replace(/\.[^.]+$/,``);return t.replace(/^0\d+[_ .-]+(?:\d+[_ .-]+)?/,``).replace(/_+/g,` `).trim()||t}function He(e){if(/^(?:[\\/]|[A-Za-z]:)/.test(e))return[];let t=e.split(/[\\/]/).filter(Boolean);return t.some(e=>e===`..`)?[]:t.filter(e=>e!==`.`).map(e=>e.replace(/_+/g,` `))}function Ue(e,t,n=`Live`){let r=e[t];if(!r){let e=Ve(n||`Live`);return{title:e,context:``,position:``,fullTitle:e}}let i=r.artist?`${r.artist} — ${Ve(r.title)}`:Ve(r.title),a=He(r.folder??``),o=He(r.group??``).join(` › `),s=[...o?[o]:[],...a],c=s.filter((e,t)=>t===0||e!==s[t-1]).join(` › `)||r.album,l=e.map((e,t)=>({one:e,at:t})).filter(({one:e})=>(e.group??``)===(r.group??``)&&(e.folder??``)===(r.folder??``)&&(s.length>0||e.album===r.album));return{title:i,context:c,position:`Playlist · ${l.findIndex(({at:e})=>e===t)+1} of ${l.length}`,fullTitle:c?`${c} › ${i}`:i}}function We(e,t=160){let n=e.replace(/[-]/g,` `).trim();if(n.length<=t)return n;let r=n.split(/\s›\s|[\\/]/).map(e=>e.replace(/_+/g,` `).trim()).filter(Boolean),i=Ve(r.pop()??``);if(r.length===0)return Ge(i,t);let a=r.shift(),o=e=>[a,...e,i].join(` › `),s=[];for(let e=r.length-1;e>=0&&!(o([r[e],...s]).length>t);--e)s.unshift(r[e]);let c=o(s);if(c.length<=t)return c;let l=t-i.length-3;return l>=12?`${Ge(a,l)} › ${i}`:Ge(i,t)}function Ge(e,t){if(e.length<=t)return e;let n=e.slice(0,t-1),r=e[t-1]===` `?n.length:n.lastIndexOf(` `);return`${(r>t/2?n.slice(0,r):n).trimEnd()}…`}var A=new Set([`mp3`,`flac`,`ogg`,`oga`,`opus`,`m4a`,`aac`,`wav`,`wma`,`aiff`,`aif`,`alac`,`mp4`,`webm`,`mkv`,`mov`,`m4v`,`ogv`,`ts`,`m2ts`,`mts`,`m2t`,`trp`,`tp`]),j=new Set([`ts`,`m2ts`,`mts`,`m2t`,`trp`,`tp`]);function Ke(e){let t=e.lastIndexOf(`.`);return t>0&&j.has(e.slice(t+1).toLowerCase())}function qe(e,t=``){if(t.startsWith(`audio/`)||t.startsWith(`video/`))return!0;let n=e.lastIndexOf(`.`);return n>0&&A.has(e.slice(n+1).toLowerCase())}function Je(e,t){return e.localeCompare(t,void 0,{numeric:!0,sensitivity:`base`})}function Ye(e){return e.filter(e=>qe(e.name,e.type)).sort((e,t)=>Je(M(e),M(t))).map(e=>({title:Ne(e.name),artist:``,album:Xe(M(e)),duration:0,url:URL.createObjectURL(e),video:O(e.name,e.type),objectUrl:!0,...Ke(e.name)?{kind:`mpegts`}:{}}))}function M(e){return e.webkitRelativePath||e.name}function Xe(e){let t=e.split(`/`);return t.length>1?t[t.length-2]:``}function Ze(e){for(let t of e)t.objectUrl&&URL.revokeObjectURL(t.url)}var Qe=2048;function $e(e){if(e.startsWith(`blob:`)||e.startsWith(`data:`))return!0;try{let t=globalThis.location?.origin;return t?new URL(e,t).origin===t:!1}catch{return!1}}function et(e,t){return e||t===`hls`||t===`mpegts`}var tt=class{elements;handlers;attach;playBlocked=!1;attached=null;source=``;context=null;analyser=null;output=null;translated=!1;wired=new WeakSet;active;jingle=null;ads=null;adOptions=null;adRoot=null;frequencies=new Uint8Array;analysable=!0;constructor(e,t,r=n){this.elements=e,this.handlers=t,this.attach=r,this.active=e.audio;for(let t of[e.audio,e.video]){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.attached&&this.attached.engine!==`native`||this.handlers.onError(nt(t))});let e=e=>()=>{t===this.active&&this.handlers.onBusy?.(e)};for(let n of[`loadstart`,`waiting`,`stalled`,`seeking`])t.addEventListener(n,e(!0));for(let n of[`playing`,`canplay`,`pause`,`ended`,`error`,`emptied`,`seeked`,`abort`])t.addEventListener(n,e(!1))}}get playing(){return!this.active.paused&&!this.active.ended}get jinglePlaying(){return!!this.jingle&&!this.jingle.paused&&!this.jingle.ended}async playJingle(e){this.jingle!==e&&this.stopJingle(),this.jingle=e,this.ensureGraph(e);try{if(await e.play(),this.context?.state===`suspended`)throw new DOMException(`Audio needs an interaction`,`NotAllowedError`)}catch(t){throw e.pause(),e.currentTime=0,t}}stopJingle(){this.jingle?.pause(),this.jingle=null}get needsInteraction(){return this.playBlocked}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}enableAds(e,t){this.adRoot=t?e:null,this.adOptions=t,this.rebindAds()}get adPlaying(){return this.ads?.playing??!1}async playAdNow(){await this.ads?.play()}rebindAds(){this.ads?.destroy(),this.ads=null,this.adOptions&&this.adRoot&&(this.ads=r(this.adRoot,this.active,this.adOptions))}ensureGraph(e){let t=globalThis.AudioContext??globalThis.webkitAudioContext;if(t){if(!this.context)try{this.context=new t({sampleRate:48e3})}catch{this.context=new t}if(this.analyser||(this.analyser=this.context.createAnalyser(),this.analyser.fftSize=Qe,this.analyser.smoothingTimeConstant=.6,this.output=this.context.createGain(),this.output.gain.value=+!this.translated,this.analyser.connect(this.output),this.output.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()}}audioInput(){if(!this.analysable)throw Error(`This source blocks audio access, so its audio cannot be translated here.`);if(this.ensureGraph(this.active),!this.context||!this.analyser)throw Error(`This browser cannot capture player audio.`);return{context:this.context,node:this.analyser}}translatedAudio(e){this.translated=e,this.output&&(this.output.gain.value=+!e)}get mediaKey(){return this.active.currentSrc||this.active.src}get loaded(){return!!(this.active.currentSrc||this.active.src)}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,n){this.stopJingle(),this.playBlocked=!1,this.source=e.objectUrl?``:e.url;let r=e.kind??(e.objectUrl?e.video?`mp4`:`audio`:t({src:e.url})),i=et(e.video,r)?this.elements.video:this.elements.audio,a=e.objectUrl||$e(e.url)||(this.handlers.readable?.(e.url)??!1);i.crossOrigin=a?`anonymous`:null,i!==this.active&&(this.active.pause(),this.active.removeAttribute(`src`),this.active.load(),this.active=i,this.rebindAds()),this.attached?.destroy(),this.attached=null;try{this.attached=await this.attach(this.active,{src:e.url,kind:r,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.onBusy?.(!0)}})}catch(e){this.handlers.onError(e instanceof Error?e.message:`that would not play`);return}let o=this.active.currentSrc||this.active.src||e.url;this.analysable=a||o.startsWith(`blob:`)||$e(o),n&&await this.play()}async play(){this.stopJingle(),this.analysable&&this.ensureGraph(this.active),this.playBlocked=!1;try{await this.active.play()}catch(e){if(e instanceof Error&&e.name===`NotAllowedError`){this.playBlocked=!0,this.handlers.onBusy?.(!1),this.handlers.onState(!1);return}if(e instanceof Error&&e.name===`AbortError`&&this.attached?.engine!==`native`)return;this.handlers.onError(e instanceof Error?e.message:`playback was refused`)}}pause(){this.stopJingle(),this.playBlocked=!1,this.active.pause()}async resumeAfterInteraction(){this.playBlocked?await this.play():this.playing&&this.context?.state===`suspended`&&await this.context.resume()}stop(){this.stopJingle(),this.playBlocked=!1,this.active.pause(),this.active.currentTime=0,this.source=``,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 nt(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`}}var rt=.14,it=.02;function at(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 ot(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 st(e,t,n=rt){return t.map((t,r)=>{let i=e[r]??0;return t>=i?t:Math.max(t,i-n)})}function ct(e,t,n=it){return t.map((t,r)=>Math.max(t,(e[r]??0)-n))}function lt(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)})}function ut(e,t){return{name:String(e?.name??e?.displayName??e?.abbreviation??``),score:typeof e?.score==`number`?e.score:typeof t==`number`?t:null,logo:typeof e?.logoUrl==`string`&&/^https?:\/\//.test(e.logoUrl)?e.logoUrl:``}}function dt(e){let t=String(e.data.state??e.tags?.find(e=>e.startsWith(`state:`))?.slice(6)??``);return t===`in`||t===`post`?t:`pre`}function ft(e,t={}){if(!e)return``;let n=new Date(e);if(Number.isNaN(n.getTime()))return``;let r=t.now??new Date,i=t.timeZone?{timeZone:t.timeZone}:{},a=n.toLocaleDateString(t.locale??_.language,i)===r.toLocaleDateString(t.locale??_.language,i);return n.toLocaleString(t.locale??_.language,{...i,...a?{}:{weekday:`short`},hour:`numeric`,minute:`2-digit`})}function pt(e,t={}){let n=e.data,r=ut(n.away,n.awayScore),i=ut(n.home,n.homeScore),a=dt(e),o=typeof n.statusDetail==`string`?n.statusDetail.trim():``,s;if(a===`in`)s=o?`LIVE · ${o}`:`LIVE`;else if(a===`post`)s=`FINAL`;else{let n=ft(e.published_at,t);s=n?`Kicks off ${n}`:o||`Upcoming`}let c=[],l=n.league,u=String(l?.abbreviation??l?.name??``);u&&c.push(u),typeof n.broadcast==`string`&&n.broadcast.trim()&&c.push(n.broadcast.trim());let d=a!==`pre`,f=e=>d&&e.score!==null?` ${e.score}`:``;return{away:r,home:i,state:a,status:s,chips:c,text:`${r.name}${f(r)} – ${i.name}${f(i)}`}}var mt=`nixamp.tv`,ht=/\bAFT\w*\b.*\bSilk\b|\bSilk\b.*\bAFT\w*\b|Android ?TV|Google ?TV|SMART-?TV|Tizen|Web0S|WebOS|BRAVIA|CrKey|Roku|Xbox|PlayStation|HbbTV|NetCast|VIDAA|Viera|AppleTV/i;function gt(e,t=``,n=1,r=null){let i=new URLSearchParams(t).get(`tv`);return i===null?r!==null&&r!==``?_t(r):/\bSilk\b/.test(e)&&n===0?!0:ht.test(e):_t(i)}function _t(e){return e!==`0`&&e!==`no`&&e!==`off`&&e!==`false`}function vt(e){return e?12:100}function yt(e,t,n){let r=Math.max(1,Math.ceil(e/n)),i=Math.min(Math.max(0,t),r-1),a=i*n;return{page:i,from:a,to:Math.min(e,a+n),pages:r}}var bt=/\.(mp3|m4a|aac|ogg|oga|opus|flac|wav)(\?.*)?$/i,xt=/\.(mp4|m4v|webm|mov|mkv)(\?.*)?$/i,St=/\.m3u8(\?.*)?$/i,N=/\.(m3u|pls)(\?.*)?$/i;function Ct(e){try{let t=new URL(e);return xt.test(t.pathname+t.search)}catch{return!1}}function wt(e){try{let t=new URL(e),n=t.pathname.split(`/`).filter(Boolean).map(e=>{try{return decodeURIComponent(e)}catch{return e}}),r=(n.pop()??``).replace(/\.(m3u|pls)$/i,``);return(/^(playlist|index|list|all|episodes|feed)?$/i.test(r)?n.pop()??``:r).replace(/[-_]+/g,` `).trim()||t.hostname}catch{return`Playlist`}}function Tt(e,t){let n=(/^#PLAYLIST:\s*(.+)$/im.exec(e)?.[1]?.replace(/[\u0000-\u001F]/g,` `).trim()??``)||wt(t),r=[],i=(e,n)=>{if(r.length>=1e3)return;let i;try{i=new URL(e.trim(),t)}catch{return}if(i.protocol!==`https:`&&i.protocol!==`http:`)return;let a=i.pathname+i.search;if(!bt.test(a)&&!xt.test(a))return;let o=decodeURIComponent(i.pathname.split(`/`).filter(Boolean).pop()??i.hostname);r.push({url:i.toString(),title:n||o})},a=!1;try{a=/\.pls$/i.test(new URL(t).pathname)}catch{a=!1}if(a){let t=new Map,a=new Map;for(let n of e.split(/\r?\n/)){let e=/^(File|Title)(\d+)\s*=\s*(.*)$/i.exec(n.trim());e&&(/^file$/i.test(e[1]??``)?t:a).set(e[2]??``,e[3]??``)}for(let[e,n]of[...t.entries()].sort((e,t)=>Number(e[0])-Number(t[0])))i(n,(a.get(e)??``).trim());return{title:n,entries:r}}let o=``;for(let t of e.split(/\r?\n/)){let e=t.trim();if(e!==``){if(e.startsWith(`#`)){let t=/^#EXTINF:\s*-?[\d.]+\s*(?:,(.*))?$/i.exec(e);t&&(o=(t[1]??``).trim())}else i(e,o),o=``}}return{title:n,entries:r}}function Et(e){let t=e.hostname.replace(/^www\.|^m\.|^music\./,``),n=e=>e&&/^[A-Za-z0-9_-]{11}$/.test(e)?e:``;if(t===`youtu.be`)return n(e.pathname.slice(1).split(`/`)[0]??null);if(t!==`youtube.com`&&t!==`youtube-nocookie.com`)return``;if(e.pathname===`/watch`)return n(e.searchParams.get(`v`));let r=/^\/(?:shorts|live|embed|v)\/([^/?]+)/.exec(e.pathname);return r?n(r[1]??null):``}function Dt(e,t=!1){let n;try{n=new URL(e.trim())}catch{return null}if(n.protocol!==`https:`&&n.protocol!==`http:`)return null;let r=Et(n);if(r){let e=n.searchParams.get(`t`);return{kind:`embed`,site:`youtube`,src:`https://www.youtube-nocookie.com/embed/${r}?autoplay=1&playsinline=1&rel=0${e&&/^\d+$/.test(e)?`&start=${e}`:``}`,label:`YouTube · ${r}`}}let i=n.hostname.replace(/^www\.|^player\./,``),a=i===`vimeo.com`?/^\/(?:video\/)?(\d+)/.exec(n.pathname)?.[1]:void 0;if(a)return{kind:`embed`,site:`vimeo`,src:`https://player.vimeo.com/video/${a}?autoplay=1&playsinline=1`,label:`Vimeo · ${a}`};if(i===`soundcloud.com`&&n.pathname.split(`/`).filter(Boolean).length>=2)return{kind:`embed`,site:`soundcloud`,src:`https://w.soundcloud.com/player/?url=${encodeURIComponent(n.toString())}&auto_play=true&visual=false`,label:`SoundCloud · ${n.pathname.split(`/`).filter(Boolean).slice(0,2).join(` / `)}`};let o=n.pathname+n.search,s=decodeURIComponent(n.pathname.split(`/`).filter(Boolean).pop()??n.hostname);return N.test(o)?{kind:`list`,url:n.toString(),label:wt(n.toString())}:bt.test(o)?{kind:`direct`,url:n.toString(),video:!1,label:s}:xt.test(o)||St.test(o)&&t?{kind:`direct`,url:n.toString(),video:!0,label:s}:null}var Ot=`nixamp.panels`;function kt(){return{order:[],placement:{},collapsed:[],closed:[]}}var P=/^[a-z][a-z0-9-]{0,63}$/,At=/^[a-z][a-z0-9-]{0,63}:[ab]?$/;function jt(e){if(!Array.isArray(e))return[];let t=new Set,n=[];for(let r of e)typeof r==`string`&&P.test(r)&&!t.has(r)&&(t.add(r),n.push(r));return n}function Mt(e){if(!e)return kt();let t;try{t=JSON.parse(e)}catch{return kt()}if(!t||typeof t!=`object`||Array.isArray(t))return kt();let n=t,r={};if(n.placement&&typeof n.placement==`object`)for(let[e,t]of Object.entries(n.placement))P.test(e)&&typeof t==`string`&&At.test(t)&&(r[e]=t);let i=e=>{let t=jt(e),n=t.includes(`parties-panel`)?t.filter(e=>e!==`onair-panel`):t;return[...new Set(n.map(e=>e===`onair-panel`?`parties-panel`:e))]};return!r[`parties-panel`]&&r[`onair-panel`]&&(r[`parties-panel`]=r[`onair-panel`]),delete r[`onair-panel`],{order:i(n.order),placement:r,collapsed:i(n.collapsed),closed:i(n.closed)}}function Nt(e){return JSON.stringify(e)}function Pt(e,t){let n=new Set(e),r=t.filter(e=>n.has(e)),i=new Set(r);return e.forEach((t,n)=>{if(i.has(t))return;let a=0;for(let t=n-1;t>=0;t--){let n=r.indexOf(e[t]);if(n>=0){a=n+1;break}}r.splice(a,0,t),i.add(t)}),r}function Ft(e,t,n){let r=e.filter(e=>e!==t);return n?[...r,t]:r}function It(e,t=16e3){let n=new Uint8Array(44+e.length*2),r=new DataView(n.buffer),i=(e,t)=>{for(let r=0;r<t.length;r++)n[e+r]=t.charCodeAt(r)};i(0,`RIFF`),r.setUint32(4,36+e.length*2,!0),i(8,`WAVE`),i(12,`fmt `),r.setUint32(16,16,!0),r.setUint16(20,1,!0),r.setUint16(22,1,!0),r.setUint32(24,t,!0),r.setUint32(28,t*2,!0),r.setUint16(32,2,!0),r.setUint16(34,16,!0),i(36,`data`),r.setUint32(40,e.length*2,!0);for(let t=0;t<e.length;t++){let n=Math.max(-1,Math.min(1,e[t]));r.setInt16(44+t*2,n<0?n*32768:n*32767,!0)}return n}function Lt(e){let t=e?.status;return typeof t==`number`?[408,502,503,504].includes(t):e instanceof TypeError||e instanceof Error&&[`AbortError`,`TimeoutError`].includes(e.name)}function F(e,t){return Object.assign(Error(e),{status:t})}var Rt=class{random;previous=[];sequence=0;speakers=new Map;constructor(e=Math.random){this.random=e}reset(){this.previous=[],this.sequence=0,this.speakers.clear()}reconcile(e,t,n){let r=new Map,i=new Set,a=[],o=new Map;for(let n of e)for(let e of this.previous){let r=Math.min(t+n.end*1e3,e.end)-Math.max(t+n.start*1e3,e.start);if(r>120){let t=`${n.speaker}|${e.speaker}`;o.set(t,(o.get(t)??0)+r)}}for(let[e,t]of o){let[n,r]=e.split(`|`);a.push({local:n,global:r,overlap:t})}for(let e of a.sort((e,t)=>t.overlap-e.overlap)){let t=this.speakers.get(e.global);t&&!r.has(e.local)&&!i.has(e.global)&&(r.set(e.local,t),i.add(e.global))}for(let t of e){let e=r.get(t.speaker);if(!e){let i=new Set([...this.speakers.values()].map(e=>e.voice)),a=n.filter(e=>!i.has(e.id)),o=a.length?a:n,s=o[Math.floor(this.random()*o.length)];e={id:`speaker-${++this.sequence}`,profile:t.profile,voice:s?.id??`auto`},this.speakers.set(e.id,e),r.set(t.speaker,e)}}this.previous=e.map(e=>({start:t+e.start*1e3,end:t+e.end*1e3,speaker:r.get(e.speaker).id}));let s=new Set(this.previous.map(e=>e.speaker));for(let e of this.speakers.keys())this.speakers.size>64&&!s.has(e)&&this.speakers.delete(e);return r}},zt=class{options;tracker=new Rt;generation=0;pending=null;committedUntil=null;running=null;controller=null;translating=null;translationController=null;recognitionFailures=0;translationFailures=0;translations=[];constructor(e){this.options=e}reset(){this.generation++,this.controller?.abort(),this.translationController?.abort(),this.pending=null,this.running=null,this.translating=null,this.recognitionFailures=this.translationFailures=0,this.translations=[],this.committedUntil=null,this.tracker.reset()}push(e){this.committedUntil??=e.freshAt,this.pending=e,this.running===null&&this.run(this.generation)}async json(e,t,n){let r=await(this.options.fetcher??fetch)(e,{...t,signal:n}),i=await r.json();if(!r.ok)throw F(i.error||`Audio translation is unavailable.`,r.status);return i}async run(e){this.running=e;try{for(;this.pending&&e===this.generation;){let t=this.pending;this.pending=null;try{if(Date.now()-t.until>12e3)continue;let n=new AbortController;this.controller=n;let r=AbortSignal.any([n.signal,AbortSignal.timeout(12e3)]),i=this.options.speakers(),a=this.options.language(),o=this.options.sourceLanguage?.()??``,s=new Uint8Array(It(i?t.samples:t.samples.slice(-8e4))),c=this.options.hear?await this.options.hear(s,{speakers:i,language:o,signal:r}):await this.json(Bt(i?this.options.paths?.speakers??`/api/v1/speech/speakers`:this.options.paths?.transcribe??`/api/v1/speech/transcribe?live=1`,o),{method:`POST`,headers:{"content-type":`audio/wav`},body:s},r);if(e!==this.generation)return;this.recognitionFailures=0;let l=c.language,u=[];if(i){let e=this.tracker.reconcile(c.turns??[],t.at,this.options.voices()),n=this.committedUntil??t.freshAt,r=c.turns??[];for(let[i,a]of r.entries()){let o=e.get(a.speaker),s=a.words.filter(e=>t.at+(e.start+e.end)*500>=n&&(t.at+e.end*1e3<=t.until-100||/[.!?。!?]$/.test(e.text))),c=[],d=()=>{c.length&&(u.push({channel:this.options.channel(),at:t.at+c[0].start*1e3,until:t.at+c.at(-1).end*1e3,text:c.map(e=>e.text).join(` `).trim(),language:l,speaker:o.id,voiceProfile:a.profile}),c=[])},f=(this.options.phrase?.gapMs??450)/1e3,p=this.options.phrase?.pauseMs??350,m=this.options.phrase?.maxMs??3e3;for(let e of s)c.length&&e.start-c.at(-1).end>=f&&d(),c.push(e),(/[.!?。!?]$/.test(e.text)||c.map(e=>e.text).join(` `).length>=400)&&d();c.length&&(i<r.length-1||t.until-(t.at+c.at(-1).end*1e3)>=p||t.until-(t.at+c[0].start*1e3)>=m)&&d()}}else c.text&&(u=[{channel:this.options.channel(),at:t.freshAt,until:t.until,text:c.text,language:l}]);if(!u.length)continue;this.committedUntil=Math.max(this.committedUntil??t.freshAt,...u.map(e=>e.until)),this.translations=this.translations.filter(e=>Date.now()-e.until<=12e3).slice(-11),this.translations.push({lines:u,language:l,target:a,until:t.until}),this.translating===null&&this.translate(this.generation)}catch(t){if(e!==this.generation)return;if(!Lt(t)||++this.recognitionFailures>=3)throw t;this.options.status(`Speech recognition interrupted · listening for the next phrase…`)}}}catch(t){if(e===this.generation){let e=t instanceof Error?t.message:`Live translation stopped.`;this.reset(),this.options.failed(e),this.options.status(e)}}finally{this.running===e&&(this.running=null)}}async translate(e){this.translating=e;try{for(;this.translations.length&&e===this.generation;){let t=this.translations.shift();try{let{lines:n}=t,{language:r,target:i,until:a}=t;if(Date.now()-a>12e3)continue;let o=new AbortController;if(this.translationController=o,i&&r!==i){if(!r)throw F(`The audio language could not be detected. Waiting for clearer speech.`,502);let e=AbortSignal.any([o.signal,AbortSignal.timeout(12e3)]),t=n.map(e=>e.text),a=this.options.translate?await this.options.translate(t,r,i,e):await this.json(this.options.paths?.translate??`/api/v1/translate?live=1`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({texts:t,from:r,to:i})},e);if(a.texts.length!==n.length||a.texts.some(e=>!e.trim()))throw F(`Translation omitted a phrase. Waiting for the next phrase.`,502);n=n.map((e,t)=>({...e,original:e.text,sourceLanguage:r,language:i,text:a.texts[t]}))}if(e!==this.generation)return;if(Date.now()-a>12e3)continue;this.translationFailures=0,this.options.lines(n.flatMap(e=>Vt(e))),this.options.status(i?`${r} → ${i} · live translation`:`Original audio language: ${r||`detecting…`}`)}catch(t){if(e!==this.generation)return;if(!Lt(t)||++this.translationFailures>=3)throw t;this.options.status(`Translation interrupted · catching up with live speech…`)}}}catch(t){if(e===this.generation){let e=t instanceof Error?t.message:`Live translation stopped.`;this.reset(),this.options.failed(e),this.options.status(e)}}finally{this.translating===e&&(this.translating=null)}}};function Bt(e,t){return/^[a-z]{2,3}$/.test(t)?`${e}${e.includes(`?`)?`&`:`?`}language=${t}`:e}function Vt(e){let t=e.text.trim();if(!t)return[];let n=[],r=t;for(;r.length>600;){let e=r.lastIndexOf(` `,600),t=e>300?e:600;n.push(r.slice(0,t)),r=r.slice(t).trimStart()}r&&n.push(r);let i=0;return n.map(n=>{let r=e.at+(e.until-e.at)*i/t.length;return i+=n.length+1,{...e,text:n,at:r,until:Math.min(e.until,e.at+(e.until-e.at)*i/t.length)}})}var Ht=16e3,Ut=3e4;function Wt(e){return[`audio/webm;codecs=opus`,`audio/ogg;codecs=opus`,`audio/webm`,`audio/mp4`,`audio/aac`].find(t=>e(t))??``}function Gt(e,t){return`● ${Math.max(0,Math.floor((t-e)/1e3))}s`}var Kt=`nixamp.captions`,qt=`nixamp.captions.native-v2.language`,Jt=[{code:``,label:`Original (auto-detect)`},...le];function Yt(e){try{let t=(e(`nixamp.captions.native-v2.language`)??``).trim().toLowerCase();return Jt.some(e=>e.code===t)?t:``}catch{return``}}function Xt(e){return e.original!==void 0&&e.language?`[${e.language}] `:``}function Zt(e,t){return(t?Math.max(e,6):Math.max(0,e))*1e3+1500}function Qt(e,t,n){let r=[],i=[];for(let a of e)(a.at<=t-n?r:i).push(a);return r.sort((e,t)=>e.at-t.at),{ready:r,still:i}}function $t(e,t,n,r=1500){let i=t-n;for(let t=e.length-1;t>=0;t--){let n=e[t];if(n.at<=i&&i<=n.until+r)return n;if(n.until+r<i)break}return null}function en(e){try{return e(Kt)!==`off`}catch{return!0}}function tn(e){let t=new Date(e);return Number.isNaN(t.getTime())?``:t.toLocaleTimeString(_.language,{hour:`2-digit`,minute:`2-digit`,second:`2-digit`})}var nn=`live-translate-audio-tap`,rn=`// The render thread copies small mono blocks. All networking stays off it.
|
|
1
|
+
import"./modulepreload-polyfill-P2Xu9kJm.js";import{c as e,i as t,n,t as r}from"./chunk-NW3WDGEQ-CnyjTRUh.js";import{a as i,i as a,n as o,r as s,t as c}from"./client-D7waX8NA.js";import{n as l}from"./now-playing-DVQqWQIu.js";import{a as u,c as d,d as f,i as p,l as m,n as ee,o as te,r as ne,s as re,t as ie,u as ae}from"./remote-DJqvFdE6.js";var oe={"Nixamp Share link or HTTPS media URL":`Nixamp Share link or HTTPS media URL`,"For TV playback, use a Nixamp Share link or a direct HTTPS media URL. Pairux viewing opens separately.":`For TV playback, use a Nixamp Share link or a direct HTTPS media URL. Pairux viewing opens separately.`,Paused:`Paused`,"Broadcast ended":`Broadcast ended`,"Class broadcast":`Class broadcast`,Play:`Play`,Pause:`Pause`,"Retry playback":`Retry playback`,"Back 10 seconds":`Back 10 seconds`,"Forward 10 seconds":`Forward 10 seconds`,Mute:`Mute`,Unmute:`Unmute`,"Full screen":`Full screen`,"Exit full screen":`Exit full screen`,Playing:`Playing`,"Select Play to watch the broadcast.":`Select Play to watch the broadcast.`,"The broadcast could not be loaded. Try again.":`The broadcast could not be loaded. Try again.`,"This Pairux broadcast opens separately. For playback here on Fire TV, the host needs to share a Nixamp stream or direct media link.":`This Pairux broadcast opens separately. For playback here on Fire TV, the host needs to share a Nixamp stream or direct media link.`,"Open on Pairux":`Open on Pairux`,"Supported platforms":`Supported platforms`,"In review":`In review`,"Not available":`Not available`,"Install PWA":`Install PWA`,"PWA installed":`PWA installed`,"Web app":`Web app`,"Install the web app":`Install the web app`,"Keep BackToSchool on your home screen or desktop. No app store needed.":`Keep BackToSchool on your home screen or desktop. No app store needed.`,"iPhone or iPad: open this site in Safari, tap Share, then Add to Home Screen.":`iPhone or iPad: open this site in Safari, tap Share, then Add to Home Screen.`,"Android: open your browser menu and choose Install app or Add to Home screen.":`Android: open your browser menu and choose Install app or Add to Home screen.`,"Desktop: look for Install in the address bar or browser menu. The option depends on your browser.":`Desktop: look for Install in the address bar or browser menu. The option depends on your browser.`,"You can also keep using BackToSchool in this browser.":`You can also keep using BackToSchool in this browser.`,"The web app is installed. You can keep learning here.":`The web app is installed. You can keep learning here.`,"Continue learning":`Continue learning`,"The install prompt could not open. Select Web app again for installation instructions.":`The install prompt could not open. Select Web app again for installation instructions.`,"Follow host":`Follow host`,Following:`Following`,"You’ll get email and web notifications for this host.":`You’ll get email and web notifications for this host.`,"Notifications turned off for this host.":`Notifications turned off for this host.`,"Could not update notifications.":`Could not update notifications.`},se={...oe,"No parties live right now.":`No parties live right now.`,"Could not refresh parties.":`Could not refresh parties.`,"Pick a server in the directory, or paste its link here.":`Pick a server in the directory, or paste its link here.`,"Interface language":`Interface language`,Language:`Language`,"Translation language":`Translation language`,"Original (auto-detect)":`Original (auto-detect)`,Play:`Play`,Pause:`Pause`,Stop:`Stop`,Next:`Next`,Previous:`Previous`,Select:`Select`,"Next/Prev":`Next/Prev`,Quit:`Quit`,"Now Playing":`Now Playing`,"Spectrum Analyser":`Spectrum Analyser`,Playlist:`Playlist`,Files:`Files`,"Open files":`Open files`,"Open folder":`Open folder`,"Add to library":`Add to library`,"Replace playlist":`Replace playlist`,Filter:`Filter`,Search:`Search`,"Nothing loaded.":`Nothing loaded.`,"Empty.":`Empty.`,"Loading…":`Loading…`,"Connecting…":`Connecting…`,Connected:`Connected`,"Not connected":`Not connected`,"No source":`No source`,Playing:`Playing`,Stopped:`Stopped`,Volume:`Volume`,Seek:`Seek`,"Full screen":`Full screen`,Download:`Download`,Share:`Share`,Copy:`Copy`,"Copy link":`Copy link`,Copied:`Copied`,Save:`Save`,Cancel:`Cancel`,Close:`Close`,Remove:`Remove`,Delete:`Delete`,Edit:`Edit`,Add:`Add`,Send:`Send`,Retry:`Retry`,Back:`Back`,"Next page":`Next page`,"Previous page":`Previous page`,"Show more":`Show more`,Panels:`Panels`,"Reset layout":`Reset layout`,Show:`Show`,Hide:`Hide`,Collapse:`Collapse`,Expand:`Expand`,"Move up":`Move up`,"Move down":`Move down`,Install:`Install`,"TV mode":`TV mode`,On:`On`,Off:`Off`,Account:`Account`,"Sign in":`Sign in`,"Sign out":`Sign out`,"Create account":`Create account`,Email:`Email`,Password:`Password`,"Forgot password?":`Forgot password?`,"Welcome back":`Welcome back`,Profile:`Profile`,Handle:`Handle`,"Your servers":`Your servers`,Server:`Server`,Connect:`Connect`,Disconnect:`Disconnect`,Directory:`Directory`,Favourites:`Favourites`,Follow:`Follow`,Unfollow:`Unfollow`,Notifications:`Notifications`,"Phone number":`Phone number`,"Save number":`Save number`,Transcript:`Transcript`,Captions:`Captions`,"Translate audio":`Translate audio`,"Audio language":`Audio language`,"Audio options":`Audio options`,"Keep background sound":`Keep background sound`,"Background level":`Background level`,"Speaker voices":`Speaker voices`,"Any voice":`Any voice`,"Male voice":`Male voice`,"Female voice":`Female voice`,"Original audio.":`Original audio.`,"Buy translated audio":`Buy translated audio`,"Audio credit":`Audio credit`,"Buy pass":`Buy pass`,Pass:`Pass`,"Pay with":`Pay with`,"Check payment":`Check payment`,"Open checkout":`Open checkout`,"Free sessions":`Free sessions`,"Usage rates and expiry":`Usage rates and expiry`,Catalogs:`Catalogs`,"Add catalog":`Add catalog`,"Catalog name":`Catalog name`,Link:`Link`,"Play link":`Play link`,"Go live":`Go live`,Publish:`Publish`,Listen:`Listen`,"Live now":`Live now`,Upcoming:`Upcoming`,Parties:`Parties`,"Join party":`Join party`,"Invite code":`Invite code`,Invite:`Invite`,Chat:`Chat`,"Chat message":`Chat message`,People:`People`,Speaker:`Speaker`,Speakers:`Speakers`,Listener:`Listener`,Moderator:`Moderator`,"Raise hand":`Raise hand`,"Hand raises":`Hand raises`,Questions:`Questions`,Resources:`Resources`,Replay:`Replay`,Schedule:`Schedule`,Event:`Event`,Host:`Host`,About:`About`,Stage:`Stage`,Title:`Title`,Description:`Description`,Topic:`Topic`,Public:`Public`,"Anyone with the link":`Anyone with the link`,"Invited people":`Invited people`,"Who can join":`Who can join`,"Date and time":`Date and time`,"Expected length":`Expected length`,Repeat:`Repeat`,"Does not repeat":`Does not repeat`,"Every day":`Every day`,"Every week":`Every week`,Homepage:`Homepage`,"Host name":`Host name`,"Profile photo URL":`Profile photo URL`,"Broadcast link":`Broadcast link`,"Edit event":`Edit event`,"Save changes":`Save changes`,"Create live":`Create live`,"Schedule class":`Schedule class`,"Start class":`Start class`,"End event":`End event`,"End session":`End session`,"Session ended":`Session ended`,"Event ended":`Event ended`,Cancelled:`Cancelled`,"Replay available":`Replay available`,Join:`Join`,"Create invite":`Create invite`,"Invite as":`Invite as`,"Watch now":`Watch now`,"Start a room":`Start a room`,"Recent replays":`Recent replays`,"Your account":`Your account`,"Write with AI":`Write with AI`,"Suggested title":`Suggested title`,"Suggested description":`Suggested description`,"Suggested topic":`Suggested topic`,"Use these details":`Use these details`,"Learn something live.":`Learn something live.`,"Screen share":`Screen share`,"Upload and broadcast":`Upload and broadcast`,Help:`Help`,"Reload Player":`Reload Player`,"Copy Bundled CLI Path":`Copy Bundled CLI Path`,"Developer tools":`Developer tools`,Undo:`Undo`,Redo:`Redo`,Cut:`Cut`,Paste:`Paste`,"Select all":`Select all`,Status:`Status`,"Activity log":`Activity log`,Admin:`Admin`,"Playback controls":`Playback controls`,"Tracks and folders":`Tracks and folders`,"Original-language captions.":`Original-language captions.`,"Skip to playback controls":`Skip to playback controls`,"Skip to playlist":`Skip to playlist`,"Skip to transcript and translated audio":`Skip to transcript and translated audio`},ce={"■ STOPPED":`Stopped`,"▶ PLAYING":`Playing`,LOADING:`Loading…`,"no source":`No source`,"not connected":`Not connected`,"Now playing":`Now Playing`,"● GO LIVE":`Go live`,"● Go live":`Go live`,"⤓ Download":`Download`,"A man's voice":`Male voice`,"A woman's voice":`Female voice`,"Catalogs on this server":`Catalogs`,"Catalog folders":`Catalogs`,"Parties on this server":`Parties`,"Servers streaming now":`Directory`,"Playlist (0)":`Playlist`,"Playlist folders":`Playlist`,"Playlist pages":`Playlist`,"Filter these files":`Filter`,"Filter these entries":`Filter`,"Filter the entries":`Filter`,"Filter the playlist":`Filter`,"Create a free account":`Create account`,"Create one":`Create account`,"Create your account":`Create account`,"New here? Create an account":`Create account`,"Already have an account? Sign in":`Sign in`,"Your NixAmp account":`Your account`,"Your public handle":`Handle`,handle:`Handle`,password:`Password`,"Phone number for texts":`Phone number`,"Back to the player":`Back`,"Share what is playing":`Share`,"Share this stream":`Share`,"Link to this stream":`Link`,"Copy this stream's URL":`Copy link`,"A link to play":`Link`,"A server's link":`Server`,"Close translated audio purchase":`Close`,"Open secure checkout ↗ (new tab)":`Open checkout`,"Checking…":`Loading…`,"Browse the directory":`Directory`,"See what is live":`Live now`,"Join live":`Join`,"Raise Hand":`Raise hand`,"Hand Raises":`Hand raises`,"Hide this":`Hide`,Log:`Activity log`,"Status:":`Status`,"Nixamp player":`Playback controls`,"Nixamp audio and video player":`Playback controls`,"What is being said":`Transcript`,"The room's chat":`Chat`,Trollbox:`Chat`,"A line for the trollbox":`Chat message`,"Say something to the room…":`Chat message`,"Send it":`Send`,"Something to add":`Chat message`,"What to call it":`Catalog name`,"call it something":`Catalog name`,"An m3u catalog to add":`Catalogs`,"On this device":`Play`,"Play on this device":`Play`,"What this is":`About`,"Looking for servers…":`Loading…`,"Finding today’s conversations…":`Loading…`,"Coming up":`Upcoming`,"Listen after class":`Replay`,"Schedule live":`Schedule class`,"Schedule a class":`Schedule class`,"Plan a conversation":`Schedule class`,"Your classroom":`Event`,"Join in":`Join`,"Open a room →":`Start a room`,"Chat message":`Chat message`,"Add to the conversation":`Chat message`,"Create live":`Create live`,"Host stage":`Stage`,"Your host":`Host`,"Class host":`Host`,"Hand raised ✓":`Raise hand`,"Copied ✓":`Copied`,"Screen share with Pairux ↗":`Screen share`,"Upload & broadcast in Nixamp ↗":`Upload and broadcast`,"Open Music Folder…":`Open folder`,"Choose a music folder":`Open folder`,"Main navigation":`Panels`,"Skip to a section":`Panels`},le=[{code:`en`,label:`English`},{code:`de`,label:`Deutsch`},{code:`sv`,label:`Svenska`},{code:`es`,label:`Español`},{code:`fr`,label:`Français`},{code:`it`,label:`Italiano`},{code:`nl`,label:`Nederlands`},{code:`da`,label:`Dansk`},{code:`fi`,label:`Suomi`},{code:`ru`,label:`Русский`},{code:`uk`,label:`Українська`},{code:`cs`,label:`Čeština`},{code:`hu`,label:`Magyar`},{code:`zh`,label:`中文`},{code:`ar`,label:`العربية`},{code:`hi`,label:`हिन्दी`},{code:`vi`,label:`Tiếng Việt`},{code:`id`,label:`Bahasa Indonesia`}],h=`nixamp.ui.language`;function g(e){let t=typeof e==`string`?e.trim().toLowerCase().split(/[-_.@]/)[0]:``;return le.find(e=>e.code===t)?.code??`en`}function ue(e,t=[]){let n=e=>{let t=typeof e==`string`?e.trim().toLowerCase().split(/[-_.@]/)[0]:``;return le.find(e=>e.code===t)?.code};return n(e)??t.map(n).find(Boolean)??`en`}var de={en:async()=>({default:se}),de:()=>e(()=>import(`./de-BzryMgxO.js`),[]),sv:()=>e(()=>import(`./sv-9BcESvUT.js`),[]),es:()=>e(()=>import(`./es-Bspt-kuE.js`),[]),fr:()=>e(()=>import(`./fr-C0yUFanu.js`),[]),it:()=>e(()=>import(`./it-DMNQHxWL.js`),[]),nl:()=>e(()=>import(`./nl-8e4KRSbc.js`),[]),da:()=>e(()=>import(`./da-BgRIZmHA.js`),[]),fi:()=>e(()=>import(`./fi-74bqR7jK.js`),[]),ru:()=>e(()=>import(`./ru-VCpBV7hb.js`),[]),uk:()=>e(()=>import(`./uk-D0xNvfSC.js`),[]),cs:()=>e(()=>import(`./cs-_goMpUzl.js`),[]),hu:()=>e(()=>import(`./hu-C_2Dn0h7.js`),[]),zh:()=>e(()=>import(`./zh-BQ28dg08.js`),[]),ar:()=>e(()=>import(`./ar-jQ_1OaPw.js`),[]),hi:()=>e(()=>import(`./hi-Bow4uBzj.js`),[]),vi:()=>e(()=>import(`./vi-CTmBIxVv.js`),[]),id:()=>e(()=>import(`./id-C8L6KxB3.js`),[])},_=new class{load;code=`en`;get language(){return this.code}constructor(e=async e=>(await de[e]()).default){this.load=e}messages=se;revision=0;numberFormats=new Map;dateFormats=new Map;listeners=new Set;async setLanguage(e){let t=++this.revision,n=g(e),r=await this.load(n);if(t!==this.revision)return!1;this.code=n,this.messages=r,this.numberFormats.clear(),this.dateFormats.clear();for(let e of this.listeners)e();return!0}onChange(e){return this.listeners.add(e),()=>this.listeners.delete(e)}text(e,t={}){let n=this.language!==`en`&&Object.hasOwn(ce,e)?ce[e]:e,r=Object.hasOwn(this.messages,n)?this.messages[n]:e;return this.language!==`en`&&Object.hasOwn(ce,e)&&(r=(e.match(/^[▶■●⤓]\s+/)?.[0]??``)+r+(e.endsWith(` ✓`)?` ✓`:``)),r.replace(/\{([\w]+)\}/g,(e,n)=>Object.hasOwn(t,n)?String(t[n]):e)}number(e,t){let n=JSON.stringify(t??{}),r=this.numberFormats.get(n);return r||(this.numberFormats.size>=64&&this.numberFormats.clear(),r=new Intl.NumberFormat(this.language,t),this.numberFormats.set(n,r)),r.format(e)}date(e,t){let n=JSON.stringify(t??{}),r=this.dateFormats.get(n);return r||(this.dateFormats.size>=64&&this.dateFormats.clear(),r=new Intl.DateTimeFormat(this.language,t),this.dateFormats.set(n,r)),r.format(e)}get direction(){return this.language===`ar`?`rtl`:`ltr`}},v=(e,t)=>_.text(e,t),y=[`active`,`trialing`];function b(e,t,n=new Date){if(!e?.length)return!1;let r=new Set(y);return e.some(e=>{if(e.product!==t||!r.has(e.status))return!1;let i=e.period?.end?Date.parse(e.period.end):NaN;if(Number.isFinite(i)&&i<n.getTime())return!1;let a=e.period?.start?Date.parse(e.period.start):NaN;return!(Number.isFinite(a)&&a>n.getTime())})}async function fe(e){let t=null;try{t=await e.entitlements()??null}catch{return e.ads}let n=e.now?.()??new Date;return b(t,e.product,n)?null:e.ads}var pe=600,me=`https://crawlproof.com/api/ads/stream`,he=`nixamp.pro`;function ge(){let e=document.querySelector(`#video`);return e&&!e.hidden&&e.currentSrc&&!e.paused?`video`:`audio`}async function _e(){try{let e=await fetch(`/api/entitlements`,{credentials:`include`,headers:{accept:`application/json`}});if(!e.ok)return[];let t=await e.json();return Array.isArray(t)?t:t.entitlements??[]}catch{return[]}}var ve=`7e0ea02c-c40f-4cdd-b4d3-93b2baca8f2c`;function x(e){let t=new URLSearchParams(e),n=t.get(`ads`),r=Number(t.get(`adsEvery`)),i=t.get(`adNow`);return{enabled:i===null?n===null?null:n!==`0`&&n!==`false`:!0,everySeconds:Number.isFinite(r)&&r>0?Math.min(3600,Math.max(5,r)):null,adUrl:be(t.get(`adUrl`)),now:i!==null&&i!==`0`&&i!==`false`}}function ye(e=location.search){return x(e).now}function be(e){if(!e)return null;try{let t=new URL(e,location.origin);return t.protocol===`https:`?t.toString():null}catch{return null}}var xe=null;function Se(e){if(xe)try{let t=`${xe.endpoint}?d=${encodeURIComponent(xe.decision)}&t=${encodeURIComponent(e)}&s=player`;new Image().src=t}catch{}}async function Ce(e={},t=location.search){let n=x(t);if(n.enabled===!1)return null;let r={everySeconds:n.everySeconds??e.everySeconds??pe,next:async()=>{if(n.adUrl)return{url:n.adUrl};try{let t=`${me}?slot=${encodeURIComponent(e.slot??ve)}&kind=${ge()}`,n=await fetch(t,{headers:{accept:`application/json`}});if(!n.ok)return null;let r=await n.json();return r.url?(xe=r.decisionId&&r.eventsUrl?{decision:r.decisionId,endpoint:r.eventsUrl,url:r.url}:null,{url:r.url,kind:r.kind}):null}catch{return null}},onBreakStart:e=>{xe&&xe.url!==e.url&&(xe=null),Se(`start`)},onBreakEnd:e=>{Se(e.skipped?`abandon`:`complete`),xe=null},onError:e=>{Se(`error`),xe=null,console.warn(`advert failed`,e)}};return n.enabled===!0?r:e.paid===!0?null:fe({product:he,entitlements:_e,ads:r})}var S=new Map;function we(e,t,n){let r=S.get(e);r||(r=new Map,S.set(e,r)),r.set(t,n),n()}function C(e,t){e instanceof Element&&e.removeAttribute(`data-i18n`);let n=``,r;return we(e,`text`,()=>{r!==void 0&&e.textContent!==r?S.get(e)?.delete(`text`):(n=t()??``,r=n,e.textContent!==n&&(e.textContent=n))}),n}function w(e,t,n){e.removeAttribute(`data-i18n-${t}`);let r=``,i;return we(e,t,()=>{i!==void 0&&e.getAttribute(t)!==i?S.get(e)?.delete(t):(r=n()??``,i=r,e.getAttribute(t)!==r&&e.setAttribute(t,r))}),r}var T=[`aria-label`,`title`,`placeholder`,`data-title`],Te=[`[data-i18n]`,...T.map(e=>`[data-i18n-${e}]`)].join(`,`);function E(e){let t=[...e.querySelectorAll(Te)];e instanceof HTMLElement&&e.matches(Te)&&t.unshift(e);for(let e of t){if(e.closest(`[translate="no"], [contenteditable="true"]`))continue;let t=e.getAttribute(`data-i18n`);if(t){let n=e.textContent;we(e,`text`,()=>{e.textContent===n?(n=v(t),e.textContent!==n&&(e.textContent=n)):(S.get(e)?.delete(`text`),e.removeAttribute(`data-i18n`))})}for(let t of T){let n=e.getAttribute(`data-i18n-${t}`);if(n){let r=e.getAttribute(t);we(e,t,()=>{e.getAttribute(t)===r?(r=v(n),e.getAttribute(t)!==r&&e.setAttribute(t,r)):(S.get(e)?.delete(t),e.removeAttribute(`data-i18n-${t}`))})}}}}function Ee(){document.documentElement.lang=_.language,document.documentElement.dir=_.direction;for(let[e,t]of S)if(!e.isConnected)S.delete(e);else for(let e of t.values())e();for(let e of document.querySelectorAll(`[data-ui-language]`))e.value=_.language}var De=0;async function D(e){let t=++De;try{if(!await _.setLanguage(e)||t!==De)return;try{localStorage.setItem(h,_.language)}catch{}window.nixampLanguage?.set(_.language).catch(()=>{})}catch{Ee()}}async function Oe(){let e=ue(null,navigator.languages);try{e=ue(await window.nixampLanguage?.get()??localStorage.getItem(`nixamp.ui.language`),navigator.languages)}catch{}for(let e of document.querySelectorAll(`[data-ui-language]`))e.replaceChildren(...le.map(e=>{let t=new Option(e.label,e.code);return t.lang=e.code,t.dir=`auto`,t})),e.addEventListener(`change`,()=>{D(e.value)});E(document),Ee(),_.onChange(Ee),new MutationObserver(e=>{for(let t of e)for(let e of t.addedNodes)e instanceof Element&&E(e);for(let e of S.keys())e.isConnected||S.delete(e)}).observe(document.body,{childList:!0,subtree:!0}),window.addEventListener(`storage`,e=>{e.key===`nixamp.ui.language`&&_.setLanguage(ue(e.newValue,navigator.languages)).catch(()=>{})}),window.nixampLanguage?.subscribe(e=>{e!==_.language&&_.setLanguage(e).catch(()=>{})});try{await _.setLanguage(e)}catch{}}var ke={play:`<span aria-hidden="true">▶</span>`,party:`<svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m3 21 4-12 8 8Z"/><path d="m7 9 8 8M12 7l1-3M16 10l4-1M16 5l2-2M20 14l1 1M8 4l-1-1"/><circle cx="21" cy="4" r=".5" fill="currentColor"/></svg>`,rename:`<svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M12 20h9"/><path d="M16.5 3.5a2.1 2.1 0 0 1 3 3L7 19l-4 1 1-4Z"/></svg>`,eye:`<svg viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M2 12s3.5-7 10-7 10 7 10 7-3.5 7-10 7S2 12 2 12Z"/><circle cx="12" cy="12" r="3"/></svg>`,gear:`<svg viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="12" cy="12" r="3"/><path d="M19.4 15a1.7 1.7 0 0 0 .3 1.8l.1.1a2 2 0 1 1-2.8 2.8l-.1-.1a1.7 1.7 0 0 0-1.8-.3 1.7 1.7 0 0 0-1 1.5V21a2 2 0 1 1-4 0v-.1a1.7 1.7 0 0 0-1.1-1.5 1.7 1.7 0 0 0-1.8.3l-.1.1a2 2 0 1 1-2.8-2.8l.1-.1a1.7 1.7 0 0 0 .3-1.8 1.7 1.7 0 0 0-1.5-1H3a2 2 0 1 1 0-4h.1a1.7 1.7 0 0 0 1.5-1.1 1.7 1.7 0 0 0-.3-1.8l-.1-.1a2 2 0 1 1 2.8-2.8l.1.1a1.7 1.7 0 0 0 1.8.3H9a1.7 1.7 0 0 0 1-1.5V3a2 2 0 1 1 4 0v.1a1.7 1.7 0 0 0 1 1.5 1.7 1.7 0 0 0 1.8-.3l.1-.1a2 2 0 1 1 2.8 2.8l-.1.1a1.7 1.7 0 0 0-.3 1.8V9a1.7 1.7 0 0 0 1.5 1H21a2 2 0 1 1 0 4h-.1a1.7 1.7 0 0 0-1.5 1Z"/></svg>`,live:`<svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="12" cy="12" r="2.5"/><path d="M8.5 15.5a5 5 0 0 1 0-7"/><path d="M15.5 8.5a5 5 0 0 1 0 7"/><path d="M5.6 18.4a9 9 0 0 1 0-12.8"/><path d="M18.4 5.6a9 9 0 0 1 0 12.8"/></svg>`,link:`<svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M10 13a5 5 0 0 0 7.5.5l3-3a5 5 0 0 0-7-7l-1.7 1.7"/><path d="M14 11a5 5 0 0 0-7.5-.5l-3 3a5 5 0 0 0 7 7l1.7-1.7"/></svg>`,copy:`<svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="9" y="9" width="12" height="12" rx="2"/><path d="M5 15V5a2 2 0 0 1 2-2h10"/></svg>`,restart:`<svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M21 12a9 9 0 1 1-3-6.7"/><path d="M21 3v6h-6"/></svg>`,remove:`<svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" aria-hidden="true"><path d="M18 6 6 18"/><path d="m6 6 12 12"/></svg>`,check:`<svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m5 12 5 5L20 7"/></svg>`};function Ae(e,t){e.innerHTML=ke[t]}function je(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 Me(e){return e.artist?`${e.artist} — ${e.title}`:e.title}function Ne(e){let t=e.split(`/`).pop()??e,n=t.lastIndexOf(`.`);return n>0?t.slice(0,n):t}var Pe=new Set([`mp4`,`webm`,`mkv`,`mov`,`m4v`,`ogv`,`avi`,`ts`,`m2ts`,`mts`,`m2t`,`trp`,`tp`]);function O(e,t=``){if(t.startsWith(`video/`))return!0;if(t.startsWith(`audio/`))return!1;let n=e.lastIndexOf(`.`);return n>0&&Pe.has(e.slice(n+1).toLowerCase())}function Fe(){let e=document.getElementById(`sr-status`);if(!e)return;let t=[`note`,`account-note`,`remote-state`,`transcript-audio-note`,`notify-note`,`notify-phone-note`,`persona-note`],n=new Map,r,i=``;for(let a of t){let t=document.getElementById(a);t&&(n.set(a,t.textContent?.trim()??``),new MutationObserver(()=>{let o=t.textContent?.trim()??``;n.get(a)!==o&&(n.set(a,o),o&&!t.closest(`[hidden], [data-closed], [data-collapsed]`)&&(i=o,clearTimeout(r),r=setTimeout(()=>{e.textContent!==i&&(e.textContent=i)},200)))}).observe(t,{childList:!0,characterData:!0,subtree:!0}))}}var Ie=new WeakMap;function Le(e,t=!0){let n=e.contains(document.activeElement);Ie.delete(e),t&&e.replaceChildren(),n&&(e.tabIndex=-1,e.focus({preventScroll:!0}))}function k(e,...t){if(document.activeElement===e||!e.contains(document.activeElement)){Ie.delete(e),e.replaceChildren(...t);return}let n=Ie.has(e);if(Ie.set(e,t),n)return;let r=()=>{let t=Ie.get(e);t&&(document.activeElement!==e&&e.contains(document.activeElement)?e.addEventListener(`focusout`,i,{once:!0}):(Ie.delete(e),e.replaceChildren(...t)))},i=()=>{setTimeout(r,0)};e.addEventListener(`focusout`,i,{once:!0})}var Re=new WeakMap,ze=new WeakSet;function Be(e,t){let n=new Map([...e.children].map(e=>[e.dataset.liveKey,e])),r=new Set(t.map(e=>e.dataset.liveKey)),i=!1;for(let r of t){let t=n.get(r.dataset.liveKey);t?t!==r&&!t.isEqualNode(r)&&(t.contains(document.activeElement)||t.querySelector(`details[open]`)?i=!0:t.replaceWith(r)):e.append(r)}for(let[e,t]of n)r.has(e)||(t.contains(document.activeElement)?i=!0:t.remove());if(i?Re.set(e,t):Re.delete(e),ze.has(e))return;ze.add(e);let a=()=>{let t=Re.get(e);t&&Be(e,t)};e.addEventListener(`focusout`,()=>{setTimeout(a,0)}),e.addEventListener(`toggle`,a,!0)}function Ve(e){if(!/\.(?:mp4|m4v|mkv|webm|mov|avi|mp3|m4a|flac|ogg|opus|wav|aac)$/i.test(e))return e;let t=(e.split(/[\\/]/).pop()??e).replace(/\.[^.]+$/,``);return t.replace(/^0\d+[_ .-]+(?:\d+[_ .-]+)?/,``).replace(/_+/g,` `).trim()||t}function He(e){if(/^(?:[\\/]|[A-Za-z]:)/.test(e))return[];let t=e.split(/[\\/]/).filter(Boolean);return t.some(e=>e===`..`)?[]:t.filter(e=>e!==`.`).map(e=>e.replace(/_+/g,` `))}function Ue(e,t,n=`Live`){let r=e[t];if(!r){let e=Ve(n||`Live`);return{title:e,context:``,position:``,fullTitle:e}}let i=r.artist?`${r.artist} — ${Ve(r.title)}`:Ve(r.title),a=He(r.folder??``),o=He(r.group??``).join(` › `),s=[...o?[o]:[],...a],c=s.filter((e,t)=>t===0||e!==s[t-1]).join(` › `)||r.album,l=e.map((e,t)=>({one:e,at:t})).filter(({one:e})=>(e.group??``)===(r.group??``)&&(e.folder??``)===(r.folder??``)&&(s.length>0||e.album===r.album));return{title:i,context:c,position:`Playlist · ${l.findIndex(({at:e})=>e===t)+1} of ${l.length}`,fullTitle:c?`${c} › ${i}`:i}}function We(e,t=160){let n=e.replace(/[-]/g,` `).trim();if(n.length<=t)return n;let r=n.split(/\s›\s|[\\/]/).map(e=>e.replace(/_+/g,` `).trim()).filter(Boolean),i=Ve(r.pop()??``);if(r.length===0)return Ge(i,t);let a=r.shift(),o=e=>[a,...e,i].join(` › `),s=[];for(let e=r.length-1;e>=0&&!(o([r[e],...s]).length>t);--e)s.unshift(r[e]);let c=o(s);if(c.length<=t)return c;let l=t-i.length-3;return l>=12?`${Ge(a,l)} › ${i}`:Ge(i,t)}function Ge(e,t){if(e.length<=t)return e;let n=e.slice(0,t-1),r=e[t-1]===` `?n.length:n.lastIndexOf(` `);return`${(r>t/2?n.slice(0,r):n).trimEnd()}…`}var A=new Set([`mp3`,`flac`,`ogg`,`oga`,`opus`,`m4a`,`aac`,`wav`,`wma`,`aiff`,`aif`,`alac`,`mp4`,`webm`,`mkv`,`mov`,`m4v`,`ogv`,`ts`,`m2ts`,`mts`,`m2t`,`trp`,`tp`]),j=new Set([`ts`,`m2ts`,`mts`,`m2t`,`trp`,`tp`]);function Ke(e){let t=e.lastIndexOf(`.`);return t>0&&j.has(e.slice(t+1).toLowerCase())}function qe(e,t=``){if(t.startsWith(`audio/`)||t.startsWith(`video/`))return!0;let n=e.lastIndexOf(`.`);return n>0&&A.has(e.slice(n+1).toLowerCase())}function Je(e,t){return e.localeCompare(t,void 0,{numeric:!0,sensitivity:`base`})}function Ye(e){return e.filter(e=>qe(e.name,e.type)).sort((e,t)=>Je(M(e),M(t))).map(e=>({title:Ne(e.name),artist:``,album:Xe(M(e)),duration:0,url:URL.createObjectURL(e),video:O(e.name,e.type),objectUrl:!0,...Ke(e.name)?{kind:`mpegts`}:{}}))}function M(e){return e.webkitRelativePath||e.name}function Xe(e){let t=e.split(`/`);return t.length>1?t[t.length-2]:``}function Ze(e){for(let t of e)t.objectUrl&&URL.revokeObjectURL(t.url)}var Qe=2048;function $e(e){if(e.startsWith(`blob:`)||e.startsWith(`data:`))return!0;try{let t=globalThis.location?.origin;return t?new URL(e,t).origin===t:!1}catch{return!1}}function et(e,t){return e||t===`hls`||t===`mpegts`}var tt=class{elements;handlers;attach;playBlocked=!1;attached=null;source=``;context=null;analyser=null;output=null;translated=!1;wired=new WeakSet;active;jingle=null;ads=null;adOptions=null;adRoot=null;frequencies=new Uint8Array;analysable=!0;constructor(e,t,r=n){this.elements=e,this.handlers=t,this.attach=r,this.active=e.audio;for(let t of[e.audio,e.video]){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.attached&&this.attached.engine!==`native`||this.handlers.onError(nt(t))});let e=e=>()=>{t===this.active&&this.handlers.onBusy?.(e)};for(let n of[`loadstart`,`waiting`,`stalled`,`seeking`])t.addEventListener(n,e(!0));for(let n of[`playing`,`canplay`,`pause`,`ended`,`error`,`emptied`,`seeked`,`abort`])t.addEventListener(n,e(!1))}}get playing(){return!this.active.paused&&!this.active.ended}get jinglePlaying(){return!!this.jingle&&!this.jingle.paused&&!this.jingle.ended}async playJingle(e){this.jingle!==e&&this.stopJingle(),this.jingle=e,this.ensureGraph(e);try{if(await e.play(),this.context?.state===`suspended`)throw new DOMException(`Audio needs an interaction`,`NotAllowedError`)}catch(t){throw e.pause(),e.currentTime=0,t}}stopJingle(){this.jingle?.pause(),this.jingle=null}get needsInteraction(){return this.playBlocked}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}enableAds(e,t){this.adRoot=t?e:null,this.adOptions=t,this.rebindAds()}get adPlaying(){return this.ads?.playing??!1}async playAdNow(){await this.ads?.play()}rebindAds(){this.ads?.destroy(),this.ads=null,this.adOptions&&this.adRoot&&(this.ads=r(this.adRoot,this.active,this.adOptions))}ensureGraph(e){let t=globalThis.AudioContext??globalThis.webkitAudioContext;if(t){if(!this.context)try{this.context=new t({sampleRate:48e3})}catch{this.context=new t}if(this.analyser||(this.analyser=this.context.createAnalyser(),this.analyser.fftSize=Qe,this.analyser.smoothingTimeConstant=.6,this.output=this.context.createGain(),this.output.gain.value=+!this.translated,this.analyser.connect(this.output),this.output.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()}}audioInput(){if(!this.analysable)throw Error(`This source blocks audio access, so its audio cannot be translated here.`);if(this.ensureGraph(this.active),!this.context||!this.analyser)throw Error(`This browser cannot capture player audio.`);return{context:this.context,node:this.analyser}}translatedAudio(e){this.translated=e,this.output&&(this.output.gain.value=+!e)}get mediaKey(){return this.active.currentSrc||this.active.src}get loaded(){return!!(this.active.currentSrc||this.active.src)}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,n){this.stopJingle(),this.playBlocked=!1,this.source=e.objectUrl?``:e.url;let r=e.kind??(e.objectUrl?e.video?`mp4`:`audio`:t({src:e.url})),i=et(e.video,r)?this.elements.video:this.elements.audio,a=e.objectUrl||$e(e.url)||(this.handlers.readable?.(e.url)??!1);i.crossOrigin=a?`anonymous`:null,i!==this.active&&(this.active.pause(),this.active.removeAttribute(`src`),this.active.load(),this.active=i,this.rebindAds()),this.attached?.destroy(),this.attached=null;try{this.attached=await this.attach(this.active,{src:e.url,kind:r,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.onBusy?.(!0)}})}catch(e){this.handlers.onError(e instanceof Error?e.message:`that would not play`);return}let o=this.active.currentSrc||this.active.src||e.url;this.analysable=a||o.startsWith(`blob:`)||$e(o),n&&await this.play()}async play(){this.stopJingle(),this.analysable&&this.ensureGraph(this.active),this.playBlocked=!1;try{await this.active.play()}catch(e){if(e instanceof Error&&e.name===`NotAllowedError`){this.playBlocked=!0,this.handlers.onBusy?.(!1),this.handlers.onState(!1);return}if(e instanceof Error&&e.name===`AbortError`&&this.attached?.engine!==`native`)return;this.handlers.onError(e instanceof Error?e.message:`playback was refused`)}}pause(){this.stopJingle(),this.playBlocked=!1,this.active.pause()}async resumeAfterInteraction(){this.playBlocked?await this.play():this.playing&&this.context?.state===`suspended`&&await this.context.resume()}stop(){this.stopJingle(),this.playBlocked=!1,this.active.pause(),this.active.currentTime=0,this.source=``,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 nt(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`}}var rt=.14,it=.02;function at(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 ot(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 st(e,t,n=rt){return t.map((t,r)=>{let i=e[r]??0;return t>=i?t:Math.max(t,i-n)})}function ct(e,t,n=it){return t.map((t,r)=>Math.max(t,(e[r]??0)-n))}function lt(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)})}function ut(e,t){return{name:String(e?.name??e?.displayName??e?.abbreviation??``),score:typeof e?.score==`number`?e.score:typeof t==`number`?t:null,logo:typeof e?.logoUrl==`string`&&/^https?:\/\//.test(e.logoUrl)?e.logoUrl:``}}function dt(e){let t=String(e.data.state??e.tags?.find(e=>e.startsWith(`state:`))?.slice(6)??``);return t===`in`||t===`post`?t:`pre`}function ft(e,t={}){if(!e)return``;let n=new Date(e);if(Number.isNaN(n.getTime()))return``;let r=t.now??new Date,i=t.timeZone?{timeZone:t.timeZone}:{},a=n.toLocaleDateString(t.locale??_.language,i)===r.toLocaleDateString(t.locale??_.language,i);return n.toLocaleString(t.locale??_.language,{...i,...a?{}:{weekday:`short`},hour:`numeric`,minute:`2-digit`})}function pt(e,t={}){let n=e.data,r=ut(n.away,n.awayScore),i=ut(n.home,n.homeScore),a=dt(e),o=typeof n.statusDetail==`string`?n.statusDetail.trim():``,s;if(a===`in`)s=o?`LIVE · ${o}`:`LIVE`;else if(a===`post`)s=`FINAL`;else{let n=ft(e.published_at,t);s=n?`Kicks off ${n}`:o||`Upcoming`}let c=[],l=n.league,u=String(l?.abbreviation??l?.name??``);u&&c.push(u),typeof n.broadcast==`string`&&n.broadcast.trim()&&c.push(n.broadcast.trim());let d=a!==`pre`,f=e=>d&&e.score!==null?` ${e.score}`:``;return{away:r,home:i,state:a,status:s,chips:c,text:`${r.name}${f(r)} – ${i.name}${f(i)}`}}var mt=`nixamp.tv`,ht=/\bAFT\w*\b.*\bSilk\b|\bSilk\b.*\bAFT\w*\b|Android ?TV|Google ?TV|SMART-?TV|Tizen|Web0S|WebOS|BRAVIA|CrKey|Roku|Xbox|PlayStation|HbbTV|NetCast|VIDAA|Viera|AppleTV/i;function gt(e,t=``,n=1,r=null){let i=new URLSearchParams(t).get(`tv`);return i===null?r!==null&&r!==``?_t(r):/\bSilk\b/.test(e)&&n===0?!0:ht.test(e):_t(i)}function _t(e){return e!==`0`&&e!==`no`&&e!==`off`&&e!==`false`}function vt(e){return e?12:100}function yt(e,t,n){let r=Math.max(1,Math.ceil(e/n)),i=Math.min(Math.max(0,t),r-1),a=i*n;return{page:i,from:a,to:Math.min(e,a+n),pages:r}}var bt=/\.(mp3|m4a|aac|ogg|oga|opus|flac|wav)(\?.*)?$/i,xt=/\.(mp4|m4v|webm|mov|mkv)(\?.*)?$/i,St=/\.m3u8(\?.*)?$/i,N=/\.(m3u|pls)(\?.*)?$/i;function Ct(e){try{let t=new URL(e);return xt.test(t.pathname+t.search)}catch{return!1}}function wt(e){try{let t=new URL(e),n=t.pathname.split(`/`).filter(Boolean).map(e=>{try{return decodeURIComponent(e)}catch{return e}}),r=(n.pop()??``).replace(/\.(m3u|pls)$/i,``);return(/^(playlist|index|list|all|episodes|feed)?$/i.test(r)?n.pop()??``:r).replace(/[-_]+/g,` `).trim()||t.hostname}catch{return`Playlist`}}function Tt(e,t){let n=(/^#PLAYLIST:\s*(.+)$/im.exec(e)?.[1]?.replace(/[\u0000-\u001F]/g,` `).trim()??``)||wt(t),r=[],i=(e,n)=>{if(r.length>=1e3)return;let i;try{i=new URL(e.trim(),t)}catch{return}if(i.protocol!==`https:`&&i.protocol!==`http:`)return;let a=i.pathname+i.search;if(!bt.test(a)&&!xt.test(a))return;let o=decodeURIComponent(i.pathname.split(`/`).filter(Boolean).pop()??i.hostname);r.push({url:i.toString(),title:n||o})},a=!1;try{a=/\.pls$/i.test(new URL(t).pathname)}catch{a=!1}if(a){let t=new Map,a=new Map;for(let n of e.split(/\r?\n/)){let e=/^(File|Title)(\d+)\s*=\s*(.*)$/i.exec(n.trim());e&&(/^file$/i.test(e[1]??``)?t:a).set(e[2]??``,e[3]??``)}for(let[e,n]of[...t.entries()].sort((e,t)=>Number(e[0])-Number(t[0])))i(n,(a.get(e)??``).trim());return{title:n,entries:r}}let o=``;for(let t of e.split(/\r?\n/)){let e=t.trim();if(e!==``){if(e.startsWith(`#`)){let t=/^#EXTINF:\s*-?[\d.]+\s*(?:,(.*))?$/i.exec(e);t&&(o=(t[1]??``).trim())}else i(e,o),o=``}}return{title:n,entries:r}}function Et(e){let t=e.hostname.replace(/^www\.|^m\.|^music\./,``),n=e=>e&&/^[A-Za-z0-9_-]{11}$/.test(e)?e:``;if(t===`youtu.be`)return n(e.pathname.slice(1).split(`/`)[0]??null);if(t!==`youtube.com`&&t!==`youtube-nocookie.com`)return``;if(e.pathname===`/watch`)return n(e.searchParams.get(`v`));let r=/^\/(?:shorts|live|embed|v)\/([^/?]+)/.exec(e.pathname);return r?n(r[1]??null):``}function Dt(e,t=!1){let n;try{n=new URL(e.trim())}catch{return null}if(n.protocol!==`https:`&&n.protocol!==`http:`)return null;let r=Et(n);if(r){let e=n.searchParams.get(`t`);return{kind:`embed`,site:`youtube`,src:`https://www.youtube-nocookie.com/embed/${r}?autoplay=1&playsinline=1&rel=0${e&&/^\d+$/.test(e)?`&start=${e}`:``}`,label:`YouTube · ${r}`}}let i=n.hostname.replace(/^www\.|^player\./,``),a=i===`vimeo.com`?/^\/(?:video\/)?(\d+)/.exec(n.pathname)?.[1]:void 0;if(a)return{kind:`embed`,site:`vimeo`,src:`https://player.vimeo.com/video/${a}?autoplay=1&playsinline=1`,label:`Vimeo · ${a}`};if(i===`soundcloud.com`&&n.pathname.split(`/`).filter(Boolean).length>=2)return{kind:`embed`,site:`soundcloud`,src:`https://w.soundcloud.com/player/?url=${encodeURIComponent(n.toString())}&auto_play=true&visual=false`,label:`SoundCloud · ${n.pathname.split(`/`).filter(Boolean).slice(0,2).join(` / `)}`};let o=n.pathname+n.search,s=decodeURIComponent(n.pathname.split(`/`).filter(Boolean).pop()??n.hostname);return N.test(o)?{kind:`list`,url:n.toString(),label:wt(n.toString())}:bt.test(o)?{kind:`direct`,url:n.toString(),video:!1,label:s}:xt.test(o)||St.test(o)&&t?{kind:`direct`,url:n.toString(),video:!0,label:s}:null}var Ot=`nixamp.panels`;function kt(){return{order:[],placement:{},collapsed:[],closed:[]}}var P=/^[a-z][a-z0-9-]{0,63}$/,At=/^[a-z][a-z0-9-]{0,63}:[ab]?$/;function jt(e){if(!Array.isArray(e))return[];let t=new Set,n=[];for(let r of e)typeof r==`string`&&P.test(r)&&!t.has(r)&&(t.add(r),n.push(r));return n}function Mt(e){if(!e)return kt();let t;try{t=JSON.parse(e)}catch{return kt()}if(!t||typeof t!=`object`||Array.isArray(t))return kt();let n=t,r={};if(n.placement&&typeof n.placement==`object`)for(let[e,t]of Object.entries(n.placement))P.test(e)&&typeof t==`string`&&At.test(t)&&(r[e]=t);let i=e=>{let t=jt(e),n=t.includes(`parties-panel`)?t.filter(e=>e!==`onair-panel`):t;return[...new Set(n.map(e=>e===`onair-panel`?`parties-panel`:e))]};return!r[`parties-panel`]&&r[`onair-panel`]&&(r[`parties-panel`]=r[`onair-panel`]),delete r[`onair-panel`],{order:i(n.order),placement:r,collapsed:i(n.collapsed),closed:i(n.closed)}}function Nt(e){return JSON.stringify(e)}function Pt(e,t){let n=new Set(e),r=t.filter(e=>n.has(e)),i=new Set(r);return e.forEach((t,n)=>{if(i.has(t))return;let a=0;for(let t=n-1;t>=0;t--){let n=r.indexOf(e[t]);if(n>=0){a=n+1;break}}r.splice(a,0,t),i.add(t)}),r}function Ft(e,t,n){let r=e.filter(e=>e!==t);return n?[...r,t]:r}function It(e,t=16e3){let n=new Uint8Array(44+e.length*2),r=new DataView(n.buffer),i=(e,t)=>{for(let r=0;r<t.length;r++)n[e+r]=t.charCodeAt(r)};i(0,`RIFF`),r.setUint32(4,36+e.length*2,!0),i(8,`WAVE`),i(12,`fmt `),r.setUint32(16,16,!0),r.setUint16(20,1,!0),r.setUint16(22,1,!0),r.setUint32(24,t,!0),r.setUint32(28,t*2,!0),r.setUint16(32,2,!0),r.setUint16(34,16,!0),i(36,`data`),r.setUint32(40,e.length*2,!0);for(let t=0;t<e.length;t++){let n=Math.max(-1,Math.min(1,e[t]));r.setInt16(44+t*2,n<0?n*32768:n*32767,!0)}return n}function Lt(e){let t=e?.status;return typeof t==`number`?[408,502,503,504].includes(t):e instanceof TypeError||e instanceof Error&&[`AbortError`,`TimeoutError`].includes(e.name)}function F(e,t){return Object.assign(Error(e),{status:t})}var Rt=class{random;previous=[];sequence=0;speakers=new Map;constructor(e=Math.random){this.random=e}reset(){this.previous=[],this.sequence=0,this.speakers.clear()}reconcile(e,t,n){let r=new Map,i=new Set,a=[],o=new Map;for(let n of e)for(let e of this.previous){let r=Math.min(t+n.end*1e3,e.end)-Math.max(t+n.start*1e3,e.start);if(r>120){let t=`${n.speaker}|${e.speaker}`;o.set(t,(o.get(t)??0)+r)}}for(let[e,t]of o){let[n,r]=e.split(`|`);a.push({local:n,global:r,overlap:t})}for(let e of a.sort((e,t)=>t.overlap-e.overlap)){let t=this.speakers.get(e.global);t&&!r.has(e.local)&&!i.has(e.global)&&(r.set(e.local,t),i.add(e.global))}for(let t of e){let e=r.get(t.speaker);if(!e){let i=new Set([...this.speakers.values()].map(e=>e.voice)),a=n.filter(e=>!i.has(e.id)),o=a.length?a:n,s=o[Math.floor(this.random()*o.length)];e={id:`speaker-${++this.sequence}`,profile:t.profile,voice:s?.id??`auto`},this.speakers.set(e.id,e),r.set(t.speaker,e)}}this.previous=e.map(e=>({start:t+e.start*1e3,end:t+e.end*1e3,speaker:r.get(e.speaker).id}));let s=new Set(this.previous.map(e=>e.speaker));for(let e of this.speakers.keys())this.speakers.size>64&&!s.has(e)&&this.speakers.delete(e);return r}},zt=class{options;tracker=new Rt;generation=0;pending=null;committedUntil=null;running=null;controller=null;translating=null;translationController=null;recognitionFailures=0;translationFailures=0;translations=[];constructor(e){this.options=e}reset(){this.generation++,this.controller?.abort(),this.translationController?.abort(),this.pending=null,this.running=null,this.translating=null,this.recognitionFailures=this.translationFailures=0,this.translations=[],this.committedUntil=null,this.tracker.reset()}push(e){this.committedUntil??=e.freshAt,this.pending=e,this.running===null&&this.run(this.generation)}async json(e,t,n){let r=await(this.options.fetcher??fetch)(e,{...t,signal:n}),i=await r.json();if(!r.ok)throw F(i.error||`Audio translation is unavailable.`,r.status);return i}async run(e){this.running=e;try{for(;this.pending&&e===this.generation;){let t=this.pending;this.pending=null;try{if(Date.now()-t.until>12e3)continue;let n=new AbortController;this.controller=n;let r=AbortSignal.any([n.signal,AbortSignal.timeout(12e3)]),i=this.options.speakers(),a=this.options.language(),o=this.options.sourceLanguage?.()??``,s=new Uint8Array(It(i?t.samples:t.samples.slice(-8e4))),c=this.options.hear?await this.options.hear(s,{speakers:i,language:o,signal:r}):await this.json(Bt(i?this.options.paths?.speakers??`/api/v1/speech/speakers`:this.options.paths?.transcribe??`/api/v1/speech/transcribe?live=1`,o),{method:`POST`,headers:{"content-type":`audio/wav`},body:s},r);if(e!==this.generation)return;this.recognitionFailures=0;let l=c.language,u=[];if(i){let e=this.tracker.reconcile(c.turns??[],t.at,this.options.voices()),n=this.committedUntil??t.freshAt,r=c.turns??[];for(let[i,a]of r.entries()){let o=e.get(a.speaker),s=a.words.filter(e=>t.at+(e.start+e.end)*500>=n&&(t.at+e.end*1e3<=t.until-100||/[.!?。!?]$/.test(e.text))),c=[],d=()=>{c.length&&(u.push({channel:this.options.channel(),at:t.at+c[0].start*1e3,until:t.at+c.at(-1).end*1e3,text:c.map(e=>e.text).join(` `).trim(),language:l,speaker:o.id,voiceProfile:a.profile}),c=[])},f=(this.options.phrase?.gapMs??450)/1e3,p=this.options.phrase?.pauseMs??350,m=this.options.phrase?.maxMs??3e3;for(let e of s)c.length&&e.start-c.at(-1).end>=f&&d(),c.push(e),(/[.!?。!?]$/.test(e.text)||c.map(e=>e.text).join(` `).length>=400)&&d();c.length&&(i<r.length-1||t.until-(t.at+c.at(-1).end*1e3)>=p||t.until-(t.at+c[0].start*1e3)>=m)&&d()}}else c.text&&(u=[{channel:this.options.channel(),at:t.freshAt,until:t.until,text:c.text,language:l}]);if(!u.length)continue;this.committedUntil=Math.max(this.committedUntil??t.freshAt,...u.map(e=>e.until)),this.translations=this.translations.filter(e=>Date.now()-e.until<=12e3).slice(-11),this.translations.push({lines:u,language:l,target:a,until:t.until}),this.translating===null&&this.translate(this.generation)}catch(t){if(e!==this.generation)return;if(!Lt(t)||++this.recognitionFailures>=3)throw t;this.options.status(`Speech recognition interrupted · listening for the next phrase…`)}}}catch(t){if(e===this.generation){let e=t instanceof Error?t.message:`Live translation stopped.`;this.reset(),this.options.failed(e),this.options.status(e)}}finally{this.running===e&&(this.running=null)}}async translate(e){this.translating=e;try{for(;this.translations.length&&e===this.generation;){let t=this.translations.shift();try{let{lines:n}=t,{language:r,target:i,until:a}=t;if(Date.now()-a>12e3)continue;let o=new AbortController;if(this.translationController=o,i&&r!==i){if(!r)throw F(`The audio language could not be detected. Waiting for clearer speech.`,502);let e=AbortSignal.any([o.signal,AbortSignal.timeout(12e3)]),t=n.map(e=>e.text),a=this.options.translate?await this.options.translate(t,r,i,e):await this.json(this.options.paths?.translate??`/api/v1/translate?live=1`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({texts:t,from:r,to:i})},e);if(a.texts.length!==n.length||a.texts.some(e=>!e.trim()))throw F(`Translation omitted a phrase. Waiting for the next phrase.`,502);n=n.map((e,t)=>({...e,original:e.text,sourceLanguage:r,language:i,text:a.texts[t]}))}if(e!==this.generation)return;if(Date.now()-a>12e3)continue;this.translationFailures=0,this.options.lines(n.flatMap(e=>Vt(e))),this.options.status(i?`${r} → ${i} · live translation`:`Original audio language: ${r||`detecting…`}`)}catch(t){if(e!==this.generation)return;if(!Lt(t)||++this.translationFailures>=3)throw t;this.options.status(`Translation interrupted · catching up with live speech…`)}}}catch(t){if(e===this.generation){let e=t instanceof Error?t.message:`Live translation stopped.`;this.reset(),this.options.failed(e),this.options.status(e)}}finally{this.translating===e&&(this.translating=null)}}};function Bt(e,t){return/^[a-z]{2,3}$/.test(t)?`${e}${e.includes(`?`)?`&`:`?`}language=${t}`:e}function Vt(e){let t=e.text.trim();if(!t)return[];let n=[],r=t;for(;r.length>600;){let e=r.lastIndexOf(` `,600),t=e>300?e:600;n.push(r.slice(0,t)),r=r.slice(t).trimStart()}r&&n.push(r);let i=0;return n.map(n=>{let r=e.at+(e.until-e.at)*i/t.length;return i+=n.length+1,{...e,text:n,at:r,until:Math.min(e.until,e.at+(e.until-e.at)*i/t.length)}})}var Ht=16e3,Ut=3e4;function Wt(e){return[`audio/webm;codecs=opus`,`audio/ogg;codecs=opus`,`audio/webm`,`audio/mp4`,`audio/aac`].find(t=>e(t))??``}function Gt(e,t){return`● ${Math.max(0,Math.floor((t-e)/1e3))}s`}var Kt=`nixamp.captions`,qt=`nixamp.captions.native-v2.language`,Jt=[{code:``,label:`Original (auto-detect)`},...le];function Yt(e){try{let t=(e(`nixamp.captions.native-v2.language`)??``).trim().toLowerCase();return Jt.some(e=>e.code===t)?t:``}catch{return``}}function Xt(e){return e.original!==void 0&&e.language?`[${e.language}] `:``}function Zt(e,t){return(t?Math.max(e,6):Math.max(0,e))*1e3+1500}function Qt(e,t,n){let r=[],i=[];for(let a of e)(a.at<=t-n?r:i).push(a);return r.sort((e,t)=>e.at-t.at),{ready:r,still:i}}function $t(e,t,n,r=1500){let i=t-n;for(let t=e.length-1;t>=0;t--){let n=e[t];if(n.at<=i&&i<=n.until+r)return n;if(n.until+r<i)break}return null}function en(e){try{return e(Kt)!==`off`}catch{return!0}}function tn(e){let t=new Date(e);return Number.isNaN(t.getTime())?``:t.toLocaleTimeString(_.language,{hour:`2-digit`,minute:`2-digit`,second:`2-digit`})}var nn=`live-translate-audio-tap`,rn=`// The render thread copies small mono blocks. All networking stays off it.
|
|
2
2
|
class LiveTranslateAudioTap extends AudioWorkletProcessor {
|
|
3
3
|
constructor() { super(); this.block = new Float32Array(2048); this.at = 0; }
|
|
4
4
|
process(inputs) {
|
|
@@ -30,4 +30,4 @@ registerProcessor("live-translate-audio-tap", LiveTranslateAudioTap);
|
|
|
30
30
|
<label for="${V(c)}">${V(o[r]??s.label)}${l?``:` <span class="${V(a)}__optional">(optional)</span>`}</label>
|
|
31
31
|
<input ${d.join(` `)}>${u?`\n <p class="${V(a)}__error" id="${V(c)}-error" role="alert">${V(u)}</p>`:``}
|
|
32
32
|
</div>`});return`<fieldset class="${V(a)}">\n${l}${u.join(`
|
|
33
|
-
`)}\n</fieldset>`}`${JSON.stringify([...An])}`;function zn(e,t){if(e.dataset.longStringScroller===`true`)return;e.dataset.longStringScroller=`true`,e.classList.add(`long-string-scroller`),t.classList.add(`long-string-scroller-content`),t.title=t.textContent??``;let n=0,r=0,i=0,a=!1,o=null,s=()=>{n=0;let c=matchMedia(`(prefers-reduced-motion: reduce)`).matches?r:i+(r-i)*.22;i=Math.abs(r-c)<.5?r:c,t.style.setProperty(`--path-shift`,`${i}px`),Math.abs(r-i)>=.5?n=requestAnimationFrame(s):a&&(a=!1,delete t.dataset.pan,t.style.removeProperty(`--path-shift`),o=setTimeout(()=>{o=null,e.style.removeProperty(`min-height`)},280))},c=()=>{n||=requestAnimationFrame(s)};e.addEventListener(`pointerenter`,n=>{n.pointerType===`mouse`&&matchMedia(`(hover: hover) and (pointer: fine)`).matches&&(o!==null&&(clearTimeout(o),o=null),e.style.minHeight=`${e.getBoundingClientRect().height}px`,a=!1,t.dataset.pan=`true`)}),e.addEventListener(`pointermove`,n=>{if(t.dataset.pan!==`true`)return;let i=getComputedStyle(e),a=parseFloat(i.paddingLeft)+parseFloat(i.paddingRight),o=Math.max(0,t.scrollWidth-(e.clientWidth-a));if(o<=0)return;let s=e.getBoundingClientRect(),l=Math.max(0,Math.min(1,(n.clientX-s.left)/Math.max(1,s.width)));if(l<=.02)r=0;else if(l>=.98)r=-o;else{let e=l*l*(3-2*l);r=-o*e}c()}),e.addEventListener(`pointerleave`,()=>{r=0,a=!0,c()})}var Bn=`nixamp.remote`,Vn=`nixamp.defaultServer`,Hn=`nixamp.volume`,Un=`nixamp.listenHere`,Wn=1e4,Gn=!1,Kn=[`first_name`,`last_name`,`company_domain`,`job_title`,`linkedin_url`];function qn(e){let t=e.querySelector(`[data-pfs-openprofile-import]`);if(!t||t.dataset.pfsBound)return;let n=t.querySelector(`[data-pfs-openprofile-url]`),r=t.querySelector(`[data-pfs-openprofile-button]`),i=t.querySelector(`[data-pfs-openprofile-status]`);n&&r&&i&&(t.dataset.pfsBound=`1`,n.addEventListener(`input`,()=>{r.disabled=!n.value.trim()}),r.addEventListener(`click`,async()=>{r.disabled=!0,r.textContent=`Fetching…`,i.textContent=``,i.setAttribute(`role`,`status`);try{let e=new URL(n.value.trim());if(e.protocol!==`https:`)throw Error(`Use an HTTPS OpenProfile URL.`);let r=new URL(t.dataset.endpoint||`/api/v1/me/profile/fields`,location.href);r.searchParams.set(`openprofile`,e.href);let a=await fetch(r,{credentials:`same-origin`,cache:`no-store`}),o=await a.json().catch(()=>({}));if(!a.ok)throw Error(o.error||`Could not fetch that OpenProfile.md.`);let s=t.closest(`form`),c=0;for(let[e,t]of Object.entries(o.profile||{})){if(typeof t!=`string`||!t.trim())continue;let n=s?.elements.namedItem(e);n instanceof HTMLInputElement&&(n.value=t,n.dispatchEvent(new Event(`input`,{bubbles:!0})),n.dispatchEvent(new Event(`change`,{bubbles:!0})),c++)}if(!c)throw Error(`No contact details were found in that OpenProfile.md.`);i.textContent=`Fetched. Review or edit the fields before saving.`}catch(e){i.textContent=e instanceof Error?e.message:`Could not fetch that OpenProfile.md.`,i.setAttribute(`role`,`alert`)}finally{r.textContent=`Fetch and prefill`,r.disabled=!n.value.trim()}}))}function Jn(e){let t={};for(let n of Kn){let r=e.elements.namedItem(n);r instanceof HTMLInputElement&&(t[n]=r.value.trim())}return t}function H(e){let t=document.getElementById(e);if(!t)throw Error(`nixamp: #${e} is missing from the shell`);return t}function Yn(){let e=new URLSearchParams(location.search).get(`embed`)===`1`,t=``;function r(e,n){let r=new URL(e instanceof Request?e.url:String(e),location.href);if(!t||r.origin!==location.origin||!r.pathname.startsWith(`/api/v1/`))return globalThis.fetch(e,n);let i=new Headers(n?.headers??(e instanceof Request?e.headers:void 0));return i.set(`authorization`,`Bearer ${t}`),globalThis.fetch(e,{...n,headers:i})}document.body.classList.toggle(`classroom-embed`,e);let oe=null;try{oe=localStorage.getItem(mt)}catch{}let se=gt(navigator.userAgent,location.search,navigator.maxTouchPoints,oe);if(document.body.classList.toggle(`tv`,se),new URLSearchParams(location.search).has(`tv`))try{localStorage.setItem(mt,se?`1`:`0`)}catch{}let ce=document.getElementById(`tv-toggle`);ce&&(C(ce,()=>se?`TV mode: on`:v(`TV mode`)),ce.title=se?`Back to the ordinary layout: lists with their own scrollbars, smaller type.`:`For a television: bigger type, lists a page at a time, and nothing to scroll but the page.`,ce.addEventListener(`click`,()=>{try{localStorage.setItem(mt,se?`0`:`1`)}catch{}let e=new URL(location.href);e.searchParams.delete(`tv`),location.replace(e.toString())}));let le=vt(se),h={status:H(`status`),source:H(`source`),install:H(`install`),video:H(`video`),audio:H(`audio`),title:H(`title-line`),album:H(`album-line`),meta:H(`meta-line`),metaBlurb:H(`meta-blurb`),liveLine:H(`live-line`),downloadNow:H(`download-now`),wayInHere:H(`way-in-here`),embed:H(`embed`),embedFrame:H(`embed-frame`),linkForm:H(`link-form`),linkUrl:H(`link-url`),linkServer:H(`link-server`),linkGoLive:H(`link-go-live`),goLiveNow:H(`go-live-now`),elapsed:H(`elapsed`),total:H(`total`),seek:H(`seek`),fullscreen:H(`fullscreen`),copyNow:H(`copy-now`),copyNixamp:H(`copy-nixamp`),schoolLive:H(`school-live`),streamingLive:H(`streaming-live`),streamingPublish:H(`streaming-publish`),canvas:H(`spectrum`),glyphs:H(`glyphs`),levels:H(`levels`),playlist:H(`playlist`),livePlaylist:H(`live-playlist`),livePlaylistPanel:H(`live-playlist-panel`),playlistPager:H(`playlist-pager`),crumbs:H(`crumbs`),filter:H(`filter`),playlistTitle:H(`playlist-panel`),note:H(`note`),linkNote:H(`link-note`),logList:H(`log-list`),files:H(`files`),folder:H(`folder`),remoteUrl:H(`remote-url`),remoteServer:H(`remote-server`),remoteForm:H(`remote-form`),remoteState:H(`remote-state`),disconnect:H(`disconnect`),browse:H(`browse`),panelsToggle:H(`panels-toggle`),panelsPanel:H(`panels-panel`),panelsList:H(`panels-list`),panelsSave:H(`panels-save`),panelsReset:H(`panels-reset`),accountForm:H(`account-form`),accountEmail:H(`account-email`),accountPassword:H(`account-password`),accountSubmit:H(`account-submit`),accountToggle:H(`account-toggle`),accountForgot:H(`account-forgot`),accountProviders:H(`account-providers`),accountPanel:H(`account-panel`),accountElsewhere:H(`account-elsewhere`),adnet:H(`adnet`),welcome:H(`welcome`),welcomeCreate:H(`welcome-create`),welcomeBrowse:H(`welcome-browse`),welcomeHide:H(`welcome-hide`),accountSignOut:H(`account-signout`),accountNote:H(`account-note`),personaForm:H(`persona-form`),personaHandle:H(`persona-handle`),personaVoice:H(`persona-voice`),personaProfile:H(`persona-profile`),personaNote:H(`persona-note`),accountProfile:H(`account-profile`),contactForm:H(`contact-form`),contactFields:H(`contact-fields`),contactNote:H(`contact-note`),adminPanel:H(`admin-panel`),adminNote:H(`admin-note`),adminSaid:H(`admin-said`),adminConnections:H(`admin-connections`),publishPanel:H(`publish-panel`),publishNote:H(`publish-note`),publishList:H(`publish-list`),adminRestream:H(`admin-restream`),adminReplace:H(`admin-replace`),adminSource:H(`admin-source`),adminName:H(`admin-name`),adminAdd:H(`admin-add`),homeNote:H(`home-note`),loadHome:H(`load-home`),directory:H(`directory`),recentNote:H(`recent-note`),recentList:H(`recent-list`),followingNote:H(`following-note`),followingList:H(`following-list`),serversPanel:H(`servers-panel`),serversNote:H(`servers-note`),serversList:H(`servers-list`),favoritesPanel:H(`favorites-panel`),favoritesNote:H(`favorites-note`),favoritesList:H(`favorites-list`),favHere:H(`fav-here`),partyRoom:H(`party-room`),partyTitle:H(`party-title`),partyMeta:H(`party-meta`),partyRoomNote:H(`party-note`),partyWatch:H(`party-watch`),partyCopy:H(`party-copy`),partyEnd:H(`party-end`),partyChat:H(`party-chat`),partyChatForm:H(`party-chat-form`),partyChatInput:H(`party-chat-input`),partyChatSend:H(`party-chat-send`),partyChatNote:H(`party-chat-note`),partiesPanel:H(`parties-panel`),partiesNote:H(`parties-note`),partiesList:H(`parties-list`),partyForm:H(`party-form`),partyCode:H(`party-code`),partyJoin:H(`party-join`),connectionsNote:H(`connections-note`),connectionsList:H(`connections-list`),catalogsPanel:H(`catalogs-panel`),catalogsNote:H(`catalogs-note`),catalogsForm:H(`catalogs-form`),catalogSource:H(`catalog-source`),catalogName:H(`catalog-name`),catalogsList:H(`catalogs-list`),catalogsCrumbs:H(`catalogs-crumbs`),catalogsFilter:H(`catalogs-filter`),catalogsEntries:H(`catalogs-entries`),notifyPanel:H(`notify-panel`),notifyNote:H(`notify-note`),notifyWeb:H(`notify-web`),notifyEmail:H(`notify-email`),notifySms:H(`notify-sms`),notifyPhone:H(`notify-phone`),notifyPhoneForm:H(`notify-phone-form`),notifyPhoneNote:H(`notify-phone-note`),directoryNote:H(`directory-note`),directoryList:H(`directory-list`),sharePanel:H(`share-panel`),trollboxPanel:H(`trollbox-panel`),trollboxNote:H(`trollbox-note`),trollboxList:H(`trollbox-list`),trollboxForm:H(`trollbox-form`),trollboxInput:H(`trollbox-input`),trollboxMic:H(`trollbox-mic`),trollboxEdit:H(`trollbox-edit`),trollboxEditLabel:H(`trollbox-edit-label`),transcriptPanel:H(`transcript-panel`),transcriptNote:H(`transcript-note`),transcriptOn:H(`transcript-on`),transcriptLanguage:H(`transcript-language`),transcriptAudio:H(`transcript-audio`),transcriptVoiceSettings:H(`transcript-voice-settings`),transcriptBackground:H(`transcript-background`),transcriptBackgroundLevel:H(`transcript-background-level`),transcriptBackgroundValue:H(`transcript-background-value`),transcriptAudioNote:H(`transcript-audio-note`),transcriptSpeakers:H(`transcript-speakers`),transcriptList:H(`transcript-list`),subtitle:H(`subtitle`),shareNote:H(`share-note`),shareLink:H(`share-link`),shareCopy:H(`share-copy`),sharePhone:H(`share-phone`),shareSend:H(`share-send`),liveControls:H(`live-controls`),goLive:H(`go-live`),stopLive:H(`stop-live`),shareTo:H(`share-to`),listenOnly:H(`listen-only`),listenHere:H(`listen-here`),volume:H(`volume`),volumeToggle:H(`volume-toggle`),prev:H(`prev`),playPause:H(`play-pause`),transport:H(`transport`),stop:H(`stop`),next:H(`next`),shareNow:H(`share-now`),refreshPlayer:H(`refresh-player`),appVersion:H(`app-version`)};h.appVersion.textContent=`nixamp 0.80.1`,h.accountProfile.innerHTML=Rn({fields:[...Kn],idPrefix:`account-`}),h.contactFields.innerHTML=Rn({fields:[...Kn],idPrefix:`contact-`,importOpenProfile:!0,importEndpoint:`/api/v1/me/profile/fields`}),qn(h.contactFields);let g=(e,t)=>{Ae(e,t)};g(h.copyNixamp,`link`);let ue=document.createElement(`a`);if(ue.className=`button`,ue.href=`#account-panel`,ue.hidden=!0,C(ue,()=>v(`Sign in`)),h.trollboxNote.after(ue),e){let e=document.createElement(`div`);e.className=`classroom-caption-controls`,e.append(h.transcriptOn.closest(`label`),h.transcriptLanguage.closest(`label`)),h.transcriptPanel.prepend(e),h.transcriptPanel.classList.remove(`panel`,`col-b`),h.transcriptPanel.hidden=!1,document.querySelector(`.classroom-player`).append(h.transcriptPanel),document.querySelector(`#app`).append(h.trollboxPanel);let t=document.createElement(`dialog`);t.className=`classroom-sign-in`,w(t,`aria-label`,()=>v(`Sign in`));let n=document.createElement(`button`);n.type=`button`,n.className=`button`,C(n,()=>v(`Close`)),n.addEventListener(`click`,()=>t.close()),h.accountPanel.classList.remove(`panel`,`col-a`),t.append(n,h.accountPanel),document.body.append(t),ue.addEventListener(`click`,e=>{e.preventDefault(),t.showModal()}),t.addEventListener(`close`,()=>{(ue.hidden?h.trollboxList:ue).focus({preventScroll:!0})})}let de=document.querySelector(`meta[name="nixamp-shell-title"]`)?.content||document.title||`nixamp`,y=`local`,b=``,fe=[],pe=``,me=!0,he=``;function ge(e){try{return new URL(e).origin}catch{return e}}let _e=!1,ve=globalThis.location?.search??``,x=``,be=0,xe=new Map,Se=e=>xe.get(K(e))??null;function S(e,t){let n=n=>{_e=n,x=``,h.remoteUrl.value=n?e.view:e.admin??e.view,t?.(),h.remoteForm.requestSubmit()},r=document.createElement(`button`);r.type=`button`,r.className=`icon way-in`,g(r,`eye`),r.title=`Viewer: browse and watch. Changes nothing on the server.`,r.setAttribute(`aria-label`,`View ${e.name}`),r.addEventListener(`click`,()=>n(!0));let i=document.createElement(`button`);return i.type=`button`,i.className=`icon way-in`,g(i,`gear`),i.disabled=e.admin===null,i.title=e.admin?`Admin: drive this server. What plays, what is live, what is on it.`:Y?`Admin: you do not administer this server.`:`Admin: sign in as this server's owner to administer it.`,i.setAttribute(`aria-label`,`Administer ${e.name}`),i.addEventListener(`click`,()=>n(!1)),[r,i]}let we=``,T=[],Te=0,E=ae(),Ee=`idle`,De=``,D=`Pick files, or connect to a nixamp running somewhere else.`,Oe=!1,ke=-1,Ne=null,Pe=0,O=null;function Fe(e){return e?/^https?:\/\//i.test(e)?e:L.url(e):``}let Ie=0,Re=0,ze=!1,He=()=>!I.needsInteraction&&(Re>0||ze);async function Ge(e){Re+=1,U();try{return await e()}finally{--Re,U()}}let A=null,j=null,Ke=``,qe=null,Je=``,M=null,Xe=null,Qe=0;function $e(){h.embed.hidden||(h.embedFrame.src=`about:blank`),h.embed.hidden=!0}let et=null,nt=``,rt=null;function it(e,t,n=null,i=!1){let a=`${t}|${e}`;if(nt=a,rt&&clearTimeout(rt),rt=null,!i){if(et?.key===a)return;et=null}if(y!==`remote`||e.trim()===``)return;let o=new URLSearchParams({name:e,kind:t});n&&o.set(`year`,String(n)),r(L.url(`/api/enrich?${o}`)).then(e=>e.ok?e.json():{match:null}).then(r=>{if(nt!==a)return;et={key:a,match:r.match??null},U();let i=et.match;i?.kind===`fixture`&&dt(i)!==`post`&&(rt=setTimeout(()=>{rt=null,!(nt!==a||I.source===``&&!O)&&it(e,t,n,!0)},6e4))}).catch(()=>void 0)}let ut=!1,ft=``,ht=``,_t=null,bt=``,xt=``,St=``,N=Array(24).fill(0),wt=Array(24).fill(0),Et=[],P=()=>y===`remote`&&!h.listenHere.checked,At=()=>y===`remote`&&!h.adminPanel.hidden,jt=!1,Lt=()=>At()||y===`remote`&&jt;function F(){try{if(localStorage.getItem(`nixamp.hls`)===`1`)return!0}catch{}return typeof MediaSource<`u`?!1:h.video.canPlayType(`application/vnd.apple.mpegurl`)!==``}function Rt(){if(y!==`remote`||M)return null;if(A?.catalog&&A.entry)return{kind:`entry`,catalog:A.catalog,entry:A.entry};if(O)return{kind:`channel`,id:O.id,name:O.name};let e=E.tracks[z()];return e&&(I.source!==``||P())?{kind:`track`,index:z(),name:bn(e)}:null}async function Bt(e,t){t.disabled=!0;let n=e.kind===`entry`?e.entry.title:e.name;D=`Putting ${n} on the air…`,U();try{let i=``,a=``,o=!0;{let t=e.kind===`folder`?`/api/folders/live`:e.kind===`track`?`/api/tracks/${e.index}/live`:e.kind===`entry`?`/api/catalogs/${encodeURIComponent(e.catalog.id)}/entries/${encodeURIComponent(e.entry.id)}/live`:`/api/channels/${encodeURIComponent(e.id)}/keep`,s=await r(L.url(t),{method:`POST`,...e.kind===`folder`?{headers:{"content-type":`application/json`},body:JSON.stringify({indices:e.indices,name:e.name})}:{}}),c=await s.json().catch(()=>({}));if(!s.ok){D=s.status===404&&e.kind===`folder`?`This server needs an update before folders can go live.`:c.error??`${n} would not go on the air.`,U();return}a=e.kind===`channel`?e.id:c.channel??``,o=c.video!==!1,i=`channel:${a}`}if(At()&&(ut?await r(L.url(`/api/live/start`),{method:`POST`}).catch(()=>void 0):await gs(!0)),await Ko(),Zo(),a!==``&&O?.id!==a){let t=e.kind===`entry`?{kind:`channel`,catalog:e.catalog,entry:{id:e.entry.id,title:e.entry.title,group:e.entry.group??``,live:e.entry.live??!0,...e.entry.logo?{logo:e.entry.logo}:{}}}:void 0;await ns({id:a,name:n,video:o},!0,t)}let s=us(i),c=ft?` Call ${ht||`the line`} and key ${ft} to talk about it.`:``;s===``?D=`${n} is on the air and you are watching it.${c}`:(await ls(s,t,`✓`),D=`${n} is on the air and you are watching it. Link copied.${c}`),U()}catch{D=`could not reach the server`,U()}finally{t.disabled=!1}}function Vt(e,t=`Join party`){g(e,/join/i.test(t)?`party`:`live`);let n=document.createTextNode(``);C(n,()=>` ${v(t)}`),e.append(n),w(e,`title`,()=>v(/join/i.test(t)?`Join live`:t))}Vt(h.partyJoin);function nn(e,t){let n=document.createElement(`button`);return n.type=`button`,n.className=`row-copy row-live`,g(n,`live`),n.title=`Go live with ${t}: on the air for everyone, listed, link copied`,n.setAttribute(`aria-label`,`Go live with ${t}`),n.addEventListener(`click`,t=>{t.stopPropagation(),Bt(e(),n)}),n}let rn=0,an=0,on=0,sn=null;function cn(e){let t=performance.now(),n=!I.adPlaying&&I.playing;n&&on>0&&t-on<2e3&&(an+=(t-on)/1e3),on=n?t:0,rn>0&&(e<=0||I.showingVideo)&&an>=rn&&(an=0,I.playAdNow())}function ln(){return new Promise(e=>{let t=()=>{sn=null,clearTimeout(n),e()},n=setTimeout(t,9e4);sn=t,I.playAdNow().then(()=>{I.adPlaying||t()},t)})}function dn(){rs()||br()||An()||y===`remote`&&ke<0&&!P()||Pn(1)}let I=new tt({audio:h.audio,video:h.video},{readable:e=>L.owns(e),onTime:(e,t)=>{let n=T[Te];y===`local`&&n&&t>0&&n.duration!==t&&(n.duration=t),cn(t),U()},onEnded:()=>{rn>0&&an>=rn&&I.duration>0?(an=0,ln().then(dn)):dn()},onState:()=>U(),onBusy:e=>{ze!==e&&(ze=e,U())},onError:e=>{if(!rs()&&!(Qe!==0&&Date.now()-Qe<2e3)){if(Xe&&e===`this browser cannot play that format`){let e=Xe.url;if(Xe=null,Qe=Date.now(),Lt()){D=`That site will not let a page play it directly; going live with it on ${b||`the server`} instead.`,U(),h.linkUrl.value=e,Tr();return}D=`That site will not let a page play it directly. Pick a server beside the link and press Go live: the server carries it.`,U()}else D=e,U(),es()}}}),pn=h.video.closest(`section`)??h.video.parentElement;pn&&(async()=>{let e=!1;try{e=(await r(`${location.hostname===`nixamp.com`?``:`https://nixamp.com`}/api/v1/me/pass`,{credentials:`include`,cache:`no-store`,signal:AbortSignal.timeout(3e3)})).ok}catch{}let t=await Ce(e?{paid:!0}:{},ve);if(rn=t?.everySeconds??0,I.enableAds(pn,t&&{...t,everySeconds:31536e3,onBreakEnd:e=>{t.onBreakEnd?.(e),sn?.()}}),ye(ve)){let e=()=>{pn.scrollIntoView({block:`center`}),I.playAdNow()};addEventListener(`pointerdown`,e,{once:!0}),addEventListener(`keydown`,e,{once:!0})}})();let mn=()=>P()&&!I.jinglePlaying,L=new ie({onSnapshot:e=>{let t=e.tracks!==void 0||E.index!==e.index;if(E=f(E,e),x.startsWith(`track:`)&&E.tracks.length>0){let e=Number(x.slice(6));if(x=``,Number.isInteger(e)&&e>=0&&e<E.tracks.length){let t=be;Mn(e).then(()=>{t>0&&(I.seek(t),setTimeout(()=>I.seek(t),600))})}}mn()&&(N=e.bars.length>0?e.bars:N,wt=ct(wt,N)),U(),t&&j&&Qo(j)},onStatus:(e,t)=>{Ee=e,De=t??``,U()}}),R=()=>y===`remote`?E.tracks.length:T.length,z=()=>y===`remote`?P()||ke<0?E.index:Math.min(ke,Math.max(0,E.tracks.length-1)):Te,vn=()=>{let e=j?.server.nowPlaying||`Live`;return qe&&qe.tracks===E.tracks&&qe.index===E.index&&qe.fallback===e||(qe={tracks:E.tracks,index:E.index,fallback:e,value:Ue(E.tracks,E.index,e)}),qe.value},B=()=>y===`remote`&&!O&&A?.kind===`live`,yn=()=>B()?vn().fullTitle:Sn(),bn=e=>{let t=Me(e);return e.folder?`${e.folder} / ${t}`:t},Sn=()=>{if(O){let e=O.id,t=j?.channels.find(t=>t.id===e);return t?.playlist?.[t.entry??0]||O.name}if(M)return M.label;if(B())return vn().title;let e=y===`remote`?E.tracks[z()]:T[z()];return e?bn(e):v(`Nothing loaded.`)},Cn=()=>{if(O)return`live on this server`;if(M)return`playing here, in this browser`;if(B()){let{context:e,position:t}=vn();return[e,t,`live on ${b||`this server`}`].filter(Boolean).join(` · `)}return(y===`remote`?E.tracks[z()]:T[z()])?.album||`—`},wn=()=>{if(!O&&!M&&!B()){let e=y===`remote`?E.tracks[z()]:T[z()];if(e?.artist)return e.artist}return b||`nixamp`};function Tn(){if(y!==`remote`||O===null&&A?.kind!==`live`){h.liveLine.hidden=!0,h.liveLine.replaceChildren(),delete h.liveLine.dataset.drawn;return}let e=b||`this server`,t=O?O.name:vn().fullTitle,n=[O?`Live on ${e}: `:`Live from ${e}, now playing: `,_s(t)],r=O?j?.channels.find(e=>e.id===O?.id)?.code??``:ut?ft:``;if(r){let e=ht?document.createElement(`a`):_s(`the line`);ht&&(e.textContent=ht,e.setAttribute(`href`,`tel:${ht.replace(/[^+\d]/g,``)}`)),n.push(`. To talk about it, call `,e,` and key `,_s(r),`.`)}let i=n.map(e=>typeof e==`string`?e:e.textContent).join(``);h.liveLine.dataset.drawn!==i&&(h.liveLine.dataset.drawn=i,h.liveLine.hidden=!1,h.liveLine.replaceChildren(...n.map(e=>typeof e==`string`?document.createTextNode(e):e)))}let En=()=>P()?E.tracks[z()]?.duration??0:I.duration,Dn=()=>P()?E.position:I.position,On=()=>P()?E.playing:I.playing;async function kn(e){if(y===`remote`){if(P()){await L.send({type:`play`,index:e});return}await Mn(e);return}let t=T[e];t&&(Te=e,O=null,A={kind:`file`},await Ge(()=>I.load(t,!0)),hr(t.video),gr(),U())}function An(){return!Ne||Ne.length<2?!1:(Pe=(Pe+1)%Ne.length,kn(Ne[Pe]),!0)}function jn(e){e.length!==0&&(Ne=[...e],Pe=0,kn(Ne[0]))}async function Mn(e){let t=E.tracks[e];t&&(ke=e,O=null,A={kind:`file`},it(t.title,`auto`),await Ge(()=>I.load({title:bn(t),artist:t.artist,album:t.album,duration:t.duration,url:L.media(e,0),video:t.video===!0,objectUrl:!1},!0)),hr(t.video===!0),gr())}async function Nn(){I.needsInteraction?(await I.play(),U()):P()?await L.send({type:`toggle`}):R()!==0&&(I.playing?I.pause():I.position>0?await I.play():await kn(z()),U())}async function Pn(e){Ne=null;let t=R();t!==0&&(P()?await L.send({type:e>0?`next`:`prev`}):await kn((z()+e+t)%t))}async function Fn(){Ne=null,$e(),M=null,Xe=null,P()?await L.send({type:`stop`}):(O=null,A=null,I.stop(),N=Array(24).fill(0),wt=[...N],U())}let In=(e,t)=>`L${`▮`.repeat(Math.round(e*6)).padEnd(6,`·`)} R${`▮`.repeat(Math.round(t*6)).padEnd(6,`·`)}`,Ln=e=>`▁▂▃▄▅▆▇█`[Math.max(0,Math.min(7,Math.round(e*7)))],V=``;function Yn(){let e=[],t=``,n=null,r=O?j?.channels.find(e=>e.id===O?.id):void 0;O&&r?.ended&&Je!==O.id&&(Je=O.id,li(`${O.name} has ended. What is playing is its outro; the room stays open for an hour, then the channel closes.`));let i=I.source===``&&!O&&!(P()&&E.tracks[z()]);if(!i){O&&r?.ended?e.push(`ENDED`):O?e.push(A?.entry?.live===!1?`ON DEMAND · LIVE CHANNEL`:`LIVE`):A?.kind===`vod`?e.push(`ON DEMAND`):A?.kind===`live`?e.push(`LIVE`):y===`remote`&&P()?e.push(`ON THE SERVER`):e.push(`FILE`),!h.video.hidden&&h.video.videoWidth>0?e.push(`${h.video.videoWidth}×${h.video.videoHeight}`):h.video.hidden?e.push(`audio`):e.push(`video`),r?(e.push(r.via===`pull`?`${r.listeners} watching`:`${r.listeners} listening · over ${r.via}`),r.startedAt>0&&e.push(`on air ${je(Math.max(0,(Date.now()-r.startedAt)/1e3))}`),r.redials&&e.push(`redialled ${r.redials}×`),At()&&r.error&&e.push(r.error)):y===`remote`&&!O?(E.tracks[z()]&&R()>0&&e.push(`${B()?`library track`:`track`} ${z()+1} of ${R()}`),P()&&j&&e.push(`${j.server.playing?`playing`:`stopped`} on ${b||`the server`}`)):y===`local`&&R()>0&&e.push(`track ${z()+1} of ${R()}`),A?.catalog!==void 0&&(A.kind===`channel`?O!==null:A.kind===`vod`&&I.source!==``)&&A?.catalog&&(e.push(A.entry?.group?`${A.catalog.name} › ${A.entry.group}`:A.catalog.name),t=A.entry?.logo??``),t===``&&O&&(t=Fe(r?.art??O.art));let i=et?.key===nt?et.match:null;if(i?.kind===`fixture`)n=pt(i),e.unshift(n.status,...n.chips);else if(i){i.image&&(t=i.image);let n=i.data;if(i.kind===`title`){i.year&&e.push(String(i.year));let t=typeof n.rating==`number`?n.rating:null;t&&e.push(`★ ${t.toFixed(1)}`);let r=Array.isArray(n.genres)?n.genres.slice(0,2).map(String):[];r.length&&e.push(r.join(` · `));let a=typeof n.runtimeMin==`number`?n.runtimeMin:0;a&&e.push(`${a} min`)}else if(i.kind===`channel`){let t=typeof n.country==`string`?n.country:``,r=Array.isArray(n.categories)?n.categories.slice(0,2).map(String):[],i=typeof n.network==`string`?n.network:``;t&&e.push(t),r.length&&e.push(r.join(` · `)),i&&e.push(i)}}if(O&&A?.link){let t=``;try{t=new URL(A.link.url).hostname.replace(/^www\./,``)}catch{}e.push(A.link.extractor&&A.link.extractor!==`direct`&&A.link.extractor!==`generic`?`${A.link.extractor} · ${t}`:t||`link`)}ut&&ft&&P()&&!O&&A?.kind!==`live`&&e.push(ht?`☎ ${ht} · key ${ft}`:`☎ code ${ft}`)}let a=et?.key===nt?et.match:null,o=!i&&!n&&a?.summary?a.summary:``,s=e.map(e=>/^on air \d/.test(e)?`on air`:e),c=`${t}|${n?`${n.away.logo}|${n.home.logo}|${n.text}`:``}|${s.join(`|`)}|${o}`;if(c===V){let t=h.meta.querySelector(`.meta-chip-clock`),n=e.find(e=>/^on air \d/.test(e));t&&n&&(t.textContent=n);return}V=c,h.meta.hidden=e.length===0,h.metaBlurb.textContent=o,h.metaBlurb.hidden=o===``;let l=[];if(n){let e=document.createElement(`div`);e.className=`meta-score`;let t=(e,t)=>{let r=[],i=document.createElement(`span`);if(i.className=`meta-team`,i.textContent=e.name,r.push(i),n?.state!==`pre`&&e.score!==null){let t=document.createElement(`b`);t.className=`meta-points`,t.textContent=String(e.score),r.push(t)}if(e.logo!==``){let n=document.createElement(`img`);n.className=`meta-team-logo`,n.alt=``,n.src=e.logo,n.addEventListener(`error`,()=>{n.hidden=!0}),t?r.unshift(n):r.push(n)}return r},r=document.createElement(`span`);r.className=`meta-dash`,r.textContent=`–`,e.replaceChildren(...t(n.away,!0),r,...t(n.home,!1)),l.push(e)}if(t!==``&&/^(https?:\/\/|\/api\/)/.test(t)){let e=document.createElement(`img`);e.className=a?.kind===`title`&&t===a.image?`meta-logo meta-poster`:`meta-logo`,e.alt=``,e.src=t,e.addEventListener(`error`,()=>{e.hidden=!0}),l.push(e)}for(let t of e){let e=document.createElement(`span`);e.className=/^on air \d/.test(t)?`meta-chip meta-chip-clock`:n?.state===`in`&&t===n.status?`meta-chip chip-live`:`meta-chip`,e.textContent=t,l.push(e)}h.meta.replaceChildren(...l)}function U(){let e=R(),t=On(),n=He();C(h.status,()=>v(n?`LOADING`:t?`▶ PLAYING`:`■ STOPPED`)),h.status.dataset.playing=n?`loading`:String(t),C(h.title,()=>Sn()),h.title.classList.toggle(`with-context`,B()),h.album.classList.toggle(`with-context`,B()),(B()||O)&&gr(),Tn(),Yn(),h.goLiveNow.hidden=!Lt()||O!==null||B()||Rt()===null;let r=t?`${yn()} · ${de}`:de;document.title!==r&&(document.title=r),h.copyNow.hidden=I.source===``,h.copyNixamp.hidden=ba()===``,h.schoolLive.hidden=xa()===``||!fo||Y===``,h.streamingLive.hidden=Ca()===``&&wa()===null||L.session===``,h.shareNow.hidden=ya()===``,Zi(),da(),h.downloadNow.hidden=!(O&&A?.link?.download),Sr(),h.album.textContent=Cn();let i=Dn(),a=En();h.elapsed.textContent=je(i),h.total.textContent=a>0?je(a):`--:--`,Oe||(h.seek.value=String(a>0?Math.round(i/a*1e3):0),h.seek.disabled=a<=0||P()),h.playPause.textContent=t?`❚❚`:`▶`,w(h.playPause,`aria-label`,()=>v(t?`Pause`:`Play`)),w(h.seek,`aria-valuetext`,()=>`${je(I.position)} ${_.language===`en`?`of`:`/`} ${je(I.duration)}`),w(h.volume,`aria-valuetext`,()=>_.number(Number(h.volume.value)/100,{style:`percent`})),w(h.playlistTitle,`data-title`,()=>y===`remote`?`Files on ${b||`this server`} (${e.toLocaleString(_.language)})`:`${v(`Playlist`)} (${_.number(e)})`),C(h.source,()=>y===`remote`?`connected · ${b||L.address.replace(/^https?:\/\//,``)||`—`}`:T.length>0?`local · ${T.length} files`:v(`no source`)),mr(),C(h.remoteState,()=>y===`remote`?`${Ee}${De?` — ${De}`:``}`:v(`not connected`)),h.remoteState.dataset.status=y===`remote`?Ee:`idle`,h.disconnect.hidden=y!==`remote`;let o=I.needsInteraction?`Press Play to start playback. Your browser needs a click first.`:y===`remote`&&E.note!==``?E.note:D;h.note.textContent=o,h.note.hidden=o===``,h.linkNote.textContent=o,h.linkNote.hidden=o===``,li(o),cr(),h.glyphs.textContent=N.map(Ln).join(``);let[s,c]=mn()?E.levels:I.levels();h.levels.textContent=In(s,c)}let Xn=``,W=``,Zn=0;function Qn(e){Le(h.playlist),W=e,Zn=0,Xn=``,cr()}function $n(e,t,n,r,i){if(h.playlistPager.hidden=n<=1,n<=1){h.playlistPager.replaceChildren();return}let a=(e,t,r)=>{let i=document.createElement(`button`);return i.type=`button`,i.className=`ghost`,i.textContent=e,i.title=r,i.disabled=t<0||t>=n,i.addEventListener(`click`,()=>{Le(h.playlist),Zn=t,Xn=``,cr()}),i},o=document.createElement(`span`);o.className=`pager-where`,C(o,()=>`${r+1}–${i} of ${e.toLocaleString(_.language)}`),h.playlistPager.replaceChildren(a(`‹ Previous`,t-1,`The page before this one`),o,a(`Next ›`,t+1,`The page after this one`))}function er(e){if(h.crumbs.hidden=!e,!e)return;let t=W===``?[]:W.split(`/`),n=(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`,()=>Qn(t)),r},r=[n(`All files`,``,t.length===0)],i=``;t.forEach((e,a)=>{i=i===``?e:`${i}/${e}`;let o=document.createElement(`span`);o.textContent=`/`,r.push(o,n(e,i,a===t.length-1))}),h.crumbs.replaceChildren(...r)}function tr(e,t,n){let r=document.createElement(`li`);r.className=`folder`;let i=document.createElement(`span`);i.className=`name`,i.textContent=`${e}/`;let a=document.createElement(`span`);a.className=`count`,a.textContent=`${t} file${t===1?``:`s`}`,r.append(i,a);let o=document.createElement(`button`);if(o.type=`button`,o.className=`row-main`,o.setAttribute(`aria-label`,`Open folder ${e}, ${t} files`),o.append(i,a),r.replaceChildren(o),o.addEventListener(`click`,t=>{t.stopPropagation(),Qn(W===``?e:`${W}/${e}`)}),n.length>0){let i=document.createElement(`button`);i.type=`button`,i.className=`row-copy`,g(i,`play`),i.title=`Play all ${t} files in ${e}`,i.setAttribute(`aria-label`,`Play folder ${e}`),i.addEventListener(`click`,e=>{e.stopPropagation(),jn(n)}),r.append(i)}return y===`remote`&&n.length>0&&Lt()&&r.append(nn(()=>({kind:`folder`,indices:n,name:`${e}/`}),`${e}/`)),r}let nr=null,rr=``,ir=``,ar=[],or=(e,t)=>{t.title=t.textContent??``,zn(e,t)};function sr(e,t){let n=document.createElement(`span`);n.className=`name row-file`,n.textContent=e;let r=document.createElement(`span`);r.className=`row-path`,r.textContent=t;let i=document.createElement(`span`);i.className=`row-label`;let a=document.createElement(`span`);a.className=`row-value`,a.append(n);let o=document.createElement(`span`);return o.className=`row-value`,o.append(r),i.append(a),or(a,n),or(o,r),{label:i,pathView:o}}function cr(){let e=(O?j?.channels.find(e=>e.id===O?.id):void 0)?.playlist,t=!!(O&&e?.length);h.livePlaylistPanel.hidden===t&&(h.livePlaylistPanel.hidden=!t);let n=t?O.id:``,r=t?e:[];if(ir!==n||ar.length!==r.length||ar.some((e,t)=>e!==r[t])){ir=n,ar=r;let e=r.map((e,t)=>{let n=document.createElement(`li`);n.className=`row file-row live-file-row`,n.dataset.index=String(t);let r=document.createElement(`span`);r.className=`n`,r.textContent=String(t+1);let{label:i,pathView:a}=sr(e.slice(e.lastIndexOf(`/`)+1),e),o=document.createElement(`span`);return o.className=`row-main`,o.append(i,r),n.append(o,a),n});k(h.livePlaylist,...e)}let i=y===`remote`?E.tracks:T,a=`${y}:${O?.id??``}:${W}:${h.filter.value}:${Zn}:${Lt()}:${h.adminPanel.hidden}`;if(Xn&&nr===i&&rr===a){lr();return}nr=i,rr=a;let o=y===`remote`?E.tracks.map(e=>({name:Me(e),seconds:e.duration,group:e.group??``,folder:e.folder??``,remote:e.remote===!0})):T.map(e=>({name:Me(e),seconds:e.duration,group:``,folder:``,remote:!1})),s=h.filter.value.trim().toLowerCase(),c=o.map((e,t)=>({...e,index:t})).filter(e=>!e.remote).filter(e=>s===``||`${e.folder}/${e.name}`.toLowerCase().includes(s)),l=e=>s!==``||W===``||e===W||e.startsWith(`${W}/`),u=e=>e===W,d=e=>{let t=W===``?e:e.slice(W.length+1),n=t.indexOf(`/`);return n===-1?t:t.slice(0,n)},f=new Map;for(let e of c){if(!l(e.folder)||u(e.folder))continue;let t=d(e.folder);t!==``&&f.set(t,(f.get(t)??0)+1)}let p=c.filter(e=>u(e.folder)&&l(e.folder)),m=[...f].sort((e,t)=>e[0].localeCompare(t[0],void 0,{numeric:!0})),ee=yt(m.length+p.length,Zn,le);Zn=ee.page;let te=m.slice(ee.from,ee.to),ne=p.slice(Math.max(0,ee.from-m.length),Math.max(0,ee.to-m.length)),re=`${y}:${W}:${s}:${ee.page}/${le}:${m.join(`,`)}:${p.map(e=>`${e.index}@${e.name}@${e.seconds}@${e.group}`).join(`|`)}`;if(re!==Xn){Xn=re,er(s===``&&(m.length>0||W!==``)),$n(m.length+p.length,ee.page,ee.pages,ee.from,ee.to);let e=[];for(let[t,n]of te){let r=W===``?t:`${W}/${t}`,i=c.filter(e=>e.folder===r||e.folder.startsWith(`${r}/`)).map(e=>e.index);e.push(tr(t,n,i))}let t=``,n=p.some(e=>e.group!==``);for(let r of ne){r.group!==t&&(n||r.group!==``)&&(t=r.group,e.push(ur(r.group)));let i=document.createElement(`li`);i.className=`row`,i.dataset.index=String(r.index);let a=document.createElement(`span`);a.className=`n`,a.textContent=String(r.index+1).padStart(2,` `);let o=r.folder?`${r.folder} / ${r.name}`:r.name,{label:s,pathView:c}=sr(r.name,r.folder?`${r.folder}/${r.name}`:r.name),l=document.createElement(`span`);l.className=`time`,l.textContent=r.seconds>0?je(r.seconds):`--:--`;let u=document.createElement(`button`);u.type=`button`,u.className=`row-main`,u.setAttribute(`aria-label`,`Play ${o}${r.seconds>0?`, ${je(r.seconds)}`:``}`),u.append(s,a,l),i.append(u);let d=document.createElement(`span`);d.className=`row-play-glyph`,g(d,`play`),i.append(d),y===`remote`&&Lt()&&O===null&&!B()&&i.append(nn(()=>({kind:`track`,index:r.index,name:o}),o)),i.classList.add(`file-row`),i.append(c),e.push(i)}k(h.playlist,...e)}lr()}function lr(){let e=O?j?.channels.find(e=>e.id===O?.id):void 0;if(e?.playlist&&e.playlist.length>0){let t=e.entry??0;for(let e of Array.from(h.livePlaylist.children)){let n=e,r=Number(n.dataset.index),i=Number.isInteger(r)&&r===t;n.classList.toggle(`selected`,i),n.classList.toggle(`playing`,i),n.classList.toggle(`live-file-current`,i),i?n.setAttribute(`aria-current`,`true`):n.removeAttribute(`aria-current`)}for(let n of Array.from(h.playlist.children)){let r=n,i=Number(r.dataset.index),a=E.tracks[i],o=a?`${a.folder?`${a.folder}/`:``}${Me(a)}`:``,s=!!o&&o===e.playlist[t];r.classList.toggle(`selected`,s),r.classList.toggle(`playing`,!1),s?r.setAttribute(`aria-current`,`true`):r.removeAttribute(`aria-current`)}return}for(let e of Array.from(h.livePlaylist.children)){let t=e;t.classList.remove(`selected`,`playing`,`live-file-current`),t.removeAttribute(`aria-current`)}let t=z(),n=On();for(let e of Array.from(h.playlist.children)){let r=e,i=Number(r.dataset.index),a=Number.isInteger(i)&&i===t;r.classList.toggle(`selected`,a),r.classList.toggle(`playing`,a&&n),a?r.setAttribute(`aria-current`,`true`):r.removeAttribute(`aria-current`)}}function ur(e){let t=document.createElement(`li`);t.className=`group`;let n=document.createElement(`span`);if(n.className=`group-name`,n.textContent=e===``?`This server's library`:e,t.append(n),e!==``&&!h.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`,r=>{r.stopPropagation(),cs(t,n,()=>dr(e),()=>cr())}),t.append(n)}return t}async function dr(e){try{let t=await r(L.url(`/api/source/remove`),{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({group:e})}),n=await t.json();return G(t.ok?`Removed ${n.removed??0} tracks from ${e}.`:n.error??`that did not work`),t.ok}catch{return G(`could not reach the server`),!1}}function fr(){let e=h.canvas,t=Math.min(2,globalThis.devicePixelRatio||1),n=Math.round(e.clientWidth*t),r=Math.round(e.clientHeight*t);n>0&&r>0&&(e.width!==n||e.height!==r)&&(e.width=n,e.height=r);let i=e.getContext(`2d`);if(mn())wt=ct(wt,N);else{let e=I.read();e.length>0&&(Et.length!==25&&(Et=at(24,e.length)),N=st(N,ot(e,Et)),wt=ct(wt,N))}if(i){let t=getComputedStyle(document.documentElement);lt(i,{width:e.width,height:e.height},N,wt,{bar:t.getPropertyValue(`--green`).trim()||`#4af689`,peak:t.getPropertyValue(`--green-dim`).trim()||`#227a4a`,background:`transparent`})}if(On()||I.jinglePlaying){h.glyphs.textContent=N.map(Ln).join(``);let[e,t]=mn()?E.levels:I.levels();h.levels.textContent=In(e,t)}if(On()){h.elapsed.textContent=je(Dn());let e=En();!Oe&&e>0&&(h.seek.value=String(Math.round(Dn()/e*1e3)))}requestAnimationFrame(fr)}let pr=``;function mr(){if(y!==`remote`){h.wayInHere.hidden=!0,pr=``;return}let e=At()&&!_e,t=we||L.address,n=e?null:Se(L.address),r=`${t}|${n??``}|${e?`admin`:`view`}`;if(r===pr)return;pr=r;let[i,a]=S({name:b||`this server`,view:t,admin:n});i.hidden=!e,a.hidden=e,h.wayInHere.replaceChildren(i,a),h.wayInHere.hidden=!1}function hr(e){h.video.hidden=!e,h.fullscreen.hidden=!e,$e(),M=null,Xe=null}function gr(){if(!(`mediaSession`in navigator)||typeof MediaMetadata>`u`)return;let e=O?Fe(j?.channels.find(e=>e.id===O?.id)?.art??O.art):``,t=JSON.stringify([Sn(),Cn(),wn(),e]);t!==Ke&&(Ke=t,l({title:Sn(),album:Cn(),artist:wn(),art:e}),navigator.mediaSession.setActionHandler(`play`,()=>void Nn()),navigator.mediaSession.setActionHandler(`pause`,()=>void Nn()),navigator.mediaSession.setActionHandler(`nexttrack`,()=>void Pn(1)),navigator.mediaSession.setActionHandler(`previoustrack`,()=>void Pn(-1)))}document.addEventListener(`click`,()=>{I.resumeAfterInteraction().catch(()=>{})}),h.filter.addEventListener(`input`,()=>{Zn=0,Xn=``,cr()}),h.playlist.addEventListener(`keydown`,e=>{if(e.key!==`Enter`&&e.key!==` `)return;let t=e.target?.closest(`li.row, li.folder`);t&&t===e.target&&(e.preventDefault(),t.click())}),h.playlist.addEventListener(`click`,e=>{let t=e.target.closest(`li`),n=Number(t?.dataset.index);Number.isInteger(n)&&(Ne=null,kn(n))}),h.fullscreen.addEventListener(`click`,()=>{let e=h.video;document.fullscreenElement?document.exitFullscreen().catch(()=>{}):typeof e.requestFullscreen==`function`?e.requestFullscreen().catch(()=>{e.webkitEnterFullscreen?.()}):e.webkitEnterFullscreen?.()}),h.prev.addEventListener(`click`,()=>void Pn(-1)),h.next.addEventListener(`click`,()=>void Pn(1)),h.stop.addEventListener(`click`,()=>void Fn()),h.playPause.addEventListener(`click`,()=>void Nn());async function _r(e){let t=Dt(e,F());if(t)O=null,I.stop(),t.kind===`embed`?(A={kind:`link`,link:{url:e,extractor:t.site,download:!1,live:!1,video:!0}},hr(!1),h.embedFrame.src=t.src,h.embed.hidden=!1,M={url:e,label:t.label,kind:`embed`},D=`Playing ${t.label} here, in this browser.`,U()):t.kind===`list`?await vr(e,t.label):(A={kind:`link`,link:{url:e,extractor:`direct`,download:!1,live:!1,video:t.video}},await Ge(()=>I.load({title:t.label,artist:``,album:``,duration:0,url:t.url,video:t.video,objectUrl:!1},!0)),hr(t.video),M={url:e,label:t.label,kind:`direct`},D=`Playing ${t.label} here, in this browser.`,U());else{if(!Lt()){D=y===`remote`?`That link would need this server to fetch it, which is going live with it: sign in to nixamp.com, or use the server's control link. YouTube, Vimeo, SoundCloud and links straight to a file play here.`:`That link would need a server to fetch it: pick one to go live on, or connect to one. YouTube, Vimeo, SoundCloud and links straight to a file play here.`,U();return}await xr(e)}}async function vr(e,t){D=`Reading ${t}…`,U();let n=``;try{let t=await r(e,{mode:`cors`});if(!t.ok)throw Error(`HTTP ${t.status}`);n=await t.text()}catch(e){D=`That playlist could not be read here (${e.message}). Go live with it instead: the server reads it.`,U();return}let i=Tt(n,e);i.entries.length===0?(D=`Nothing in that playlist is a file this browser plays. Go live with it instead: the server reads it.`,U()):(Xe={url:e,title:i.title||t,entries:i.entries,at:0},await yr())}async function yr(){let e=Xe,t=e?.entries[e.at];if(!e||!t)return;let n=Ct(t.url);A={kind:`link`,link:{url:e.url,extractor:`playlist`,download:!1,live:!1,video:n}},await Ge(()=>I.load({title:t.title,artist:e.title,album:``,duration:0,url:t.url,video:n,objectUrl:!1},!0)),Xe!==null&&(hr(n),M={url:e.url,label:e.title,kind:`direct`},Xe=e,D=`Playing ${e.title} here: ${e.at+1} of ${e.entries.length}, ${t.title}.`,U())}function br(){let e=Xe;return!e||e.entries.length===0?!1:(e.at=(e.at+1)%e.entries.length,yr(),!0)}async function xr(e){y===`remote`?(D=`Asking ${b||`the server`} to fetch ${e}…`,U(),await Ge(async()=>{let t,n={};try{t=await r(L.url(`/api/links/play`),{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({url:e,live:!0})}),n=await t.json().catch(()=>({}))}catch{D=`could not reach the server`;return}if(!t.ok||!n.channel)D=n.error??`that link would not play.`;else{try{await r(L.url(`/api/channels/${encodeURIComponent(n.channel)}/keep`),{method:`POST`})}catch{}await ns({id:n.channel,name:n.name||e,video:n.video!==!1,art:n.art},!0,{kind:`channel`,link:{url:e,extractor:n.extractor??``,download:n.download===!0,live:n.live===!0,video:n.video!==!1}}),(n.entries??0)>1&&(D=`${n.name||e} is on the air: ${n.entries} entries, played in turn.`)}}),U()):(D=`Pick a server to go live on, or connect to one, to put a link on the air.`,U())}h.linkForm.addEventListener(`submit`,e=>{e.preventDefault();let t=h.linkUrl.value.trim();t!==``&&_r(t)});function Sr(){let e=y===`remote`?L.address:``,t=fe.filter(t=>ge(t.url)!==ge(e)),n=JSON.stringify({here:e,name:b,carries:me,others:t});if(n===pe||document.activeElement===h.linkServer)return;pe=n;let r=[];if(e!==``&&me){let t=document.createElement(`option`);t.value=``,t.textContent=`on ${b||e}`,r.push(t)}else{let e=document.createElement(`option`);e.value=``,e.textContent=`go live on…`,r.push(e)}for(let e of t){let t=document.createElement(`option`);t.value=e.url,t.textContent=e.name,r.push(t)}h.linkServer.replaceChildren(...r),h.linkServer.value=e!==``&&!me&&t[0]?t[0].url:``,h.linkServer.hidden=t.length===0}function Cr(){let e=y===`remote`?ge(L.address):``,t=[],n=document.createElement(`option`);if(n.value=``,n.textContent=`Select a server…`,t.push(n),e!==``&&!fe.some(t=>ge(t.url)===e)){let n=document.createElement(`option`);n.value=L.address,n.textContent=b||e,t.push(n)}for(let e of fe){let n=document.createElement(`option`);n.value=e.url,n.textContent=e.name,t.push(n)}h.remoteServer.replaceChildren(...t);let r=fe.find(t=>ge(t.url)===e);h.remoteServer.value=r?.url??``}async function wr(){try{let e=await r(`/api/directory`);if(!e.ok)return;fe=((await e.json()).streams??[]).map(e=>({name:e.name,url:e.url})),Sr(),Cr()}catch{}}async function Tr(){let e=h.linkUrl.value.trim()||M?.url||``;if(e===``){D=`Paste a link first: a file, an .m3u playlist, an IPTV feed, a YouTube page.`,U();return}let t=h.linkServer.value;if(t!==``&&(y!==`remote`||ge(t)!==ge(L.address))){let n=fe.find(e=>e.url===t)?.name??t;he=e,D=`Connecting to ${n} to go live with it…`,U(),Er(t)}else y===`remote`?me?Lt()?await xr(e):(D=`Sign in to nixamp.com to go live here, or use the server's control link.`,U()):(D=`${b||`This server`} has no ffmpeg, so it cannot carry a link.`+(fe.length>0?` Pick a server to go live on, beside the link.`:``),U()):(D=fe.length>0?`Pick a server to go live on, beside the link.`:`Connect to a server first: Browse the directory, or paste a server's link in the Server panel.`,U())}function Er(e){let t=h.linkUrl.value.trim();_e=!0,x=``,h.remoteUrl.value=e,h.remoteForm.requestSubmit(),h.linkUrl.value=t}h.linkGoLive.addEventListener(`click`,()=>{Tr()}),h.linkServer.addEventListener(`change`,()=>{let e=h.linkServer.value;e!==``&&Er(e)}),h.downloadNow.addEventListener(`click`,()=>{let e=A?.link;if(!e||y!==`remote`)return;let t=e.video?``:`&audio=1`;globalThis.open(L.url(`/api/links/download?url=${encodeURIComponent(e.url)}${t}`),`_blank`),D=`Fetching it through the server; your browser will save it when it arrives.`,U()}),h.goLiveNow.addEventListener(`click`,()=>{let e=Rt();e&&Bt(e,h.goLiveNow)}),h.seek.addEventListener(`input`,()=>{Oe=!0}),h.seek.addEventListener(`change`,()=>{let e=En();e>0&&I.seek(Number(h.seek.value)/1e3*e),Oe=!1}),h.volume.addEventListener(`input`,()=>{let e=Number(h.volume.value)/100;I.volume=e,h.volumeToggle.setAttribute(`aria-pressed`,e===0?`true`:`false`),h.volumeToggle.textContent=e===0?`🔇`:`🔊`,w(h.volumeToggle,`aria-label`,()=>v(e===0?`Unmute`:`Mute`));try{localStorage.setItem(Hn,String(e))}catch{}}),h.volumeToggle.addEventListener(`click`,()=>{let e=Number(h.volume.value)===0,t=100;try{let e=Number(localStorage.getItem(Hn));Number.isFinite(e)&&e>0&&(t=Math.round(e*100))}catch{}h.volume.value=e?String(t):`0`,h.volume.dispatchEvent(new Event(`input`))}),h.refreshPlayer.addEventListener(`click`,()=>window.location.reload());let Dr=e=>{e.addEventListener(`change`,()=>{let t=Ye(Array.from(e.files??[]));t.length===0?(D=`Nothing playable in that selection.`,U()):(Ze(T),T=t,Te=0,y=`local`,L.close(),Xo(!1),D=``,kn(0))})};Dr(h.files),Dr(h.folder),h.remoteForm.addEventListener(`submit`,e=>{e.preventDefault();let t=h.remoteUrl.value,{base:n,key:r}=m(t);n===``?(D=`That is not an address.`,U()):(async()=>{Ee=`connecting`,U();let e=ne(n);if(e){Ee=`error`,De=e,D=e,he=``,y=`local`,U();return}if(await te(n,void 0,r)===null){Ee=`error`;let e=u(n);De=e?`needs the server's name`:`not answering`,D=e||`Nothing answered at ${n}. If that is your machine, it is off or nixamp is not running on it; otherwise check the address.`,he=``,y=`local`,U();return}let i=await re(n,r);if(i)Ee=`error`,De=i,D=i,he=``,y=`local`,U();else{y=`remote`,D=``;try{localStorage.setItem(Bn,t.trim())}catch{}L.connect(t),Xo(!0),Ga(),Br(),Ko(),U()}})()}),h.remoteServer.addEventListener(`change`,()=>{let e=h.remoteServer.value;e!==``&&(_e=!1,x=``,h.remoteUrl.value=e,h.remoteForm.requestSubmit())});let Or=``,kr=null,Ar=async(e=!1)=>{h.directory.hidden=!1,e||(h.directoryNote.textContent=`Looking for live streams…`,k(h.directoryList)),kr||=setInterval(()=>{!h.directory.hidden&&document.visibilityState===`visible`&&Ar(!0)},Wn);let t;try{let n=await r(`/api/directory`);if(!n.ok)throw Error(String(n.status));let i=await n.json();t=i.streams??[],fe=t.map(e=>({name:e.name,url:e.url})),Sr();let a=JSON.stringify({streams:t.map(({...e})=>{let{updatedAt:t,startedAt:n,...r}=e;return r}),recent:i.recent??[],me:Y});if(e&&a===Or)return;Or=a,Ur(i.recent??[])}catch{e||(h.directoryNote.textContent=`The directory is not answering. Type an address instead.`);return}if(k(h.directoryList),t.length===0)h.directoryNote.textContent=`Nobody is streaming right now.`;else{h.directoryNote.textContent=`${t.length} ${t.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 e of t){let t=document.createElement(`li`),n=document.createElement(`span`);n.className=`server-label`;let i=document.createElement(`span`);i.className=`name`,i.textContent=e.name;let a=document.createElement(`span`);a.className=`detail`;let o=[`${e.tracks.toLocaleString(_.language)} files to browse`];e.playing!==!1&&e.nowPlaying?o.push(`playing ${e.nowPlaying}`):o.push(`player idle`),e.code&&o.push(e.callers?`☎ ${e.code} · ${e.callers} on the phone`:`☎ ${e.code}`),a.textContent=o.join(` · `),a.title=a.textContent,n.append(i,a);let s=e.admin??Se(e.url),c=(t,n=``)=>{_e=t,x=n,h.remoteUrl.value=t?e.url:s??e.url,h.directory.hidden=!0,document.body.classList.remove(`route-directory`),h.remoteForm.requestSubmit()},l=document.createElement(`ul`);l.className=`server-lives`;for(let t of e.channels??[]){let n=document.createElement(`li`),r=document.createElement(`span`);r.className=`detail live`;let i=e.channelCodes?.[t]??``,a=e.channelCallers?.[t]??0;r.textContent=`● ${t}`+(i?` · ☎ ${i}${a?` · ${a} on the phone`:``}`:``);let o=e.lineup?.find(e=>e.name===t);if(o?.art&&/^https?:\/\//i.test(o.art)){let e=document.createElement(`img`);e.className=`live-art`,e.alt=``,e.loading=`lazy`,e.src=o.art,e.addEventListener(`error`,()=>{e.hidden=!0}),n.append(e)}o?.about&&(r.title=o.about);let u=document.createElement(`button`);u.type=`button`,u.className=`icon`,g(u,`party`),u.setAttribute(`aria-label`,`Join ${t} live on ${e.name}`),u.title=`Join live: ${t} on ${e.name}`,u.addEventListener(`click`,()=>c(!0,`channel:${t}`));let d=document.createElement(`button`);d.type=`button`,d.className=`icon`,g(d,`link`),d.setAttribute(`aria-label`,`Copy live room link for ${t}`),d.title=`Copy a nixamp link to this live room`;let f=`${globalThis.location.origin}/?url=${encodeURIComponent(e.url)}&play=${encodeURIComponent(`channel:${o?.id??t}`)}`;d.addEventListener(`click`,e=>{e.stopPropagation(),ls(f,d,`✓`)});let p=document.createElement(`button`);p.type=`button`,p.className=`icon`,g(p,`copy`),p.setAttribute(`aria-label`,`Copy raw stream URL for ${t}`),p.title=`Copy the raw stream URL for VLC or another player`;let m=e.url;try{let n=new URL(e.url);n.pathname=`/api/channels/${encodeURIComponent(o?.id??t)}`,m=n.toString()}catch{}if(p.addEventListener(`click`,e=>{e.stopPropagation(),ls(m,p,`✓`)}),n.append(r,u,d,p),o?.startedBy&&Y&&o.startedBy===Y&&s){let e=document.createElement(`button`);e.type=`button`,e.className=`icon`,g(e,`gear`),e.setAttribute(`aria-label`,`Administer ${t}`),e.title=`Administer ${t}`,e.addEventListener(`click`,e=>{e.stopPropagation(),c(!1,`channel:${o?.id??t}`)}),n.append(e)}l.append(n)}let[u,d]=S({name:e.name,view:e.url,admin:s},()=>{h.directory.hidden=!0,document.body.classList.remove(`route-directory`)});if(t.append(n,u,d),Y&&t.append(si(e.url,e.name)),e.ownerId&&Y&&e.ownerId!==Y&&t.append(ao(e.ownerId,e.name)),l.childElementCount>0&&t.append(l),e.ownerId&&Y&&e.ownerId===Y){let n=document.createElement(`button`);n.type=`button`,n.className=`ghost`,n.textContent=`Take off the list`,n.addEventListener(`click`,t=>{t.stopPropagation(),n.disabled=!0,(async()=>{try{let t=await r(`/api/directory?id=${encodeURIComponent(e.id)}`,{method:`DELETE`}),n=await t.json().catch(()=>({}));h.directoryNote.textContent=t.ok?`${e.name} is off the list.`:n.error??`that did not work`}catch{h.directoryNote.textContent=`could not reach the directory`}finally{await Ar()}})()}),t.append(n)}h.directoryList.append(t)}}};if(document.addEventListener(`visibilitychange`,()=>{document.visibilityState===`visible`&&!h.directory.hidden&&Ar(!0)}),location.pathname.replace(/\/+$/,``)===`/directory`){document.body.classList.add(`route-directory`);let e=document.getElementById(`directory-back`);e&&(e.hidden=!1),Ar()}let jr=/^\/live\/([^/]+)\/?$/.exec(location.pathname);if(jr){document.body.classList.add(`route-party`),h.partyRoom.hidden=!1;let e=decodeURIComponent(jr[1]??``),t=null,n=0,i=``,a=new Set,o=e=>{let t=Math.max(0,Math.floor(e)),n=String(t%60).padStart(2,`0`),r=Math.floor(t/60)%60,i=Math.floor(t/3600);return i>0?`${i}:${String(r).padStart(2,`0`)}:${n}`:`${r}:${n}`},s=(e,t=!1)=>{let n=t?h.partyChatNote:h.partyRoomNote;n.hidden=e===``,n.textContent=e},c=()=>{if(!t)return;let e=t.party.playing?(Date.now()-n)/1e3:0,r=t.party.positionNow+e,i=[t.event.status===`live`?t.party.playing?`▶ ${o(r)}`:`❚❚ ${o(r)}`:`ended`,t.party.mediaTitle,`code ${t.party.partyCode}`,t.host?`yours`:``].filter(Boolean);h.partyMeta.textContent=i.join(` · `)},l=()=>{if(!t)return;document.title=`${t.event.title} — nixamp`,h.partyTitle.textContent=t.event.title||t.party.partyCode;let e=t.links.partyUrl||t.party.partyUrl;h.partyWatch.href=e||`#`,h.partyWatch.hidden=e===``;let n=t.party.origin;try{n=new URL(e).hostname}catch{}h.partyWatch.title=`The film plays on ${n} (opens in a new tab)`,h.partyEnd.hidden=!t.host||t.event.status!==`live`;let r=t.event.chatEnabled!==!1&&t.event.status===`live`;h.partyChatForm.hidden=!r,h.partyChatInput.disabled=!r||Y===``,h.partyChatSend.disabled=!r||Y===``,s(r?Y===``?`Sign in to say something; everybody can read.`:``:t.event.status===`live`?`Chat is off for this party.`:`This party has ended.`,!0),c()},u=async()=>{try{let i=await r(`/api/v1/watch-parties/${encodeURIComponent(e)}`,{cache:`no-store`});if(!i.ok){s(i.status===404?`No party here. It may have ended, or the link is not one.`:`Could not open this party. Try again in a moment.`);return}t=await i.json(),n=Date.now(),s(``),l()}catch{s(`Could not open this party. Try again in a moment.`)}},d=async()=>{if(t&&t.event.chatEnabled!==!1)try{let e=new URL(`/api/v1/events/${encodeURIComponent(t.event.id)}/chat`,location.origin);i&&e.searchParams.set(`after`,i);let n=await r(e.toString(),{cache:`no-store`});if(!n.ok)return;let o=((await n.json()).messages??[]).filter(e=>!a.has(e.id));if(!o.length){if(!h.partyChat.childElementCount){let e=document.createElement(`li`);e.className=`hint`,e.textContent=`No messages yet. Say hi!`,h.partyChat.replaceChildren(e)}return}h.partyChat.querySelector(`.hint`)&&h.partyChat.replaceChildren();let s=h.partyChat.scrollHeight-h.partyChat.scrollTop-h.partyChat.clientHeight<60;for(let e of o){a.add(e.id),i=e.createdAt;let t=document.createElement(`li`),n=document.createElement(`b`);n.textContent=e.authorName,t.append(n,document.createTextNode(e.body)),h.partyChat.append(t)}for(;h.partyChat.childElementCount>200;)h.partyChat.firstElementChild?.remove();s&&(h.partyChat.scrollTop=h.partyChat.scrollHeight)}catch{}};h.partyChatForm.addEventListener(`submit`,e=>{e.preventDefault();let n=h.partyChatInput.value.trim();t&&n!==``&&(h.partyChatSend.disabled=!0,(async()=>{try{let e=await r(`/api/v1/events/${encodeURIComponent(t.event.id)}/chat`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({body:n})}),i=await e.json().catch(()=>({}));if(!e.ok){s(i.error??`That did not send.`,!0);return}h.partyChatInput.value=``,s(``,!0),await d()}catch{s(`That did not send.`,!0)}finally{h.partyChatSend.disabled=Y===``}})())}),h.partyCopy.addEventListener(`click`,()=>{navigator.clipboard?.writeText(t?.links.nixampUrl||location.href).then(()=>{h.partyCopy.textContent=`Copied`,setTimeout(()=>{h.partyCopy.textContent=`Copy room link`},2e3)},()=>s(`Could not copy that.`))}),h.partyEnd.addEventListener(`click`,()=>{t&&t.host&&(async()=>{(await r(`/api/v1/watch-parties/${encodeURIComponent(t.party.partyCode)}/end`,{method:`POST`})).ok?await u():s(`Could not end it.`)})()}),(async()=>{await u(),await d()})(),setInterval(c,1e3),setInterval(()=>void u(),1e4),setInterval(()=>void d(),4e3),document.addEventListener(`nixamp:account`,()=>l())}let Mr=null,Nr=e=>e===`cgnat`?`mobile or tailscale`:e===`private`?`your network`:e===`local`?`this machine`:e===`public`?`the internet`:e,Pr=e=>e===`events`?`watching the panel`:e===`page`?`opened the page`:e===`media`?`playing a track`:e===`stream`?`listening live`:e,Fr=``,Ir=``,Lr=e=>{let t=e.map(e=>`${e.address}|${e.kind}|${e.track}|${Math.round(e.bytes/4096)}|${e.endedAt}`).join(`~`);if(t===Fr)return;Fr=t,h.adminConnections.replaceChildren();let n=document.createElement(`tr`);for(let e of[`Where`,`Network`,`Kind`,`Client`,`Track`,`Sent`]){let t=document.createElement(`th`);t.textContent=e,n.append(t)}h.adminConnections.append(n);for(let t of e.slice(0,40)){let e=document.createElement(`tr`);t.endedAt!==null&&(e.className=`ended`);let n=[[t.address,``],[Nr(t.network),`network-${t.network}`],[Pr(t.kind),``],[t.agent,``],[t.track||`—`,``],[`${Math.round(t.bytes/1024)} KiB`,``]];for(let[t,r]of n){let n=document.createElement(`td`);n.textContent=t,r&&(n.className=r),e.append(n)}h.adminConnections.append(e)}};function G(e){h.adminSaid.textContent=e,h.adminSaid.hidden=e===``}let Rr=async()=>{try{let e=await r(L.url(`/api/connections`));if(!e.ok)return;let t=await e.json(),n=(t.connections??[]).filter(e=>e.endedAt===null&&e.kind!==`media`&&e.kind!==`stream`).length,i=t.active??0;h.adminNote.textContent=n===0?`${i} listening now.`:`${i} listening now, and ${n} with the page open.`,Lr(t.connections??[]),zr(t.publish??[],(t.channels??[]).map(e=>e.id)),hs(t.home??``,t.root??``),Zo()}catch{h.adminNote.textContent=`lost touch with the server`}};function zr(e,t){h.publishPanel.hidden=e.length===0;let n=`${e.map(e=>`${e.id}=${e.url}`).join(`~`)}::${t.join(`,`)}`;if(n===Ir)return;if(Ir=n,e.length===0){k(h.publishList);return}let r=e.length-t.length;h.publishNote.textContent=`Point OBS, Larix or ffmpeg at one of these. One publisher per URL — ${e.length} at once, ${r} free right now.`,k(h.publishList,...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`,C(o,()=>v(`Copy`)),o.addEventListener(`click`,()=>{a.select(),navigator.clipboard?.writeText(e.url).catch(()=>{})}),r.append(i,a,o),r}))}let Br=async()=>{if(y!==`remote`){h.adminPanel.hidden=!0,h.publishPanel.hidden=!0,Mr&&clearInterval(Mr),Mr=null;return}let e=!1,t=null,n=!1,i=!1;try{let a=await r(L.url(`/api/admin`));if(a.ok){let r=await a.json();e=r.allowed===!0,t=r.as??null,n=r.claimed===!0,i=r.member===!0}}catch{e=!1}let a=e||i;_e&&(e=!1),jt=a&&!e;let o=h.partiesList.dataset.adminMode!==String(e);if(h.adminPanel.hidden=!e,o&&(h.partiesList.dataset.adminMode=String(e),h.partiesList.querySelectorAll(`details[open]`).forEach(e=>e.removeAttribute(`open`)),Zr()),Go(e),he!==``){let e=he;he=``,Lt()?xr(e):(D=`Sign in to nixamp.com to go live here.`,U())}Mr&&clearInterval(Mr),Mr=null,Zo(),Ga(),Ko(),h.listenOnly.hidden=e,e?(h.adminNote.textContent=t===`owner`?`You own this server.`:`You hold this server's control link.`,Rr(),Mr=setInterval(()=>void Rr(),2e3)):h.listenOnly.textContent=n?`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.`};function Vr(e,t,n){let i=(t||e).toLowerCase().replace(/[^a-z0-9_-]+/g,`-`).replace(/^-+|-+$/g,``).slice(0,40)||`s${Math.random().toString(16).slice(2,8)}`;G(`Starting ${t||e}…`),(async()=>{try{let a=await r(L.url(`/api/channels/${encodeURIComponent(i)}/pull`),{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({...n===void 0?{source:e}:{at:n},...t?{name:t}:{}})}),o=await a.json();if(!a.ok){G(o.error??`that did not work`);return}G(`${o.channel?.name||t||e} is on the air.`),h.adminSource.value=``,h.adminName.value=``,Ko(),Zo()}catch{G(`could not reach the server`)}})()}h.adminRestream.addEventListener(`submit`,e=>{e.preventDefault();let t=h.adminSource.value.trim();t&&Vr(t,h.adminName.value.trim())}),h.adminAdd.addEventListener(`click`,()=>{let e=h.adminSource.value.trim();if(!e)return;G(`Reading ${e}…`);let t=h.adminReplace.checked,n=h.adminName.value.trim();(async()=>{try{let i=await r(L.url(`/api/source`),{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({source:e,...n?{name:n}:{},...t?{replace:!0}:{}})}),a=await i.json();G(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&&(h.adminSource.value=``,h.adminName.value=``,Ko(),Zo())}catch{G(`could not reach the server`)}})()});let Hr=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`},Ur=e=>{let t=[],n=Y?e.filter(e=>e.ownerId&&e.ownerId!==Y):[];if(h.recentNote.hidden=n.length===0,n.length===0)k(h.recentList);else{for(let e of n){let n=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 ${Hr(e.endedAt)}`:`ended ${Hr(e.endedAt)}`,r.append(i,a),n.append(r,ao(e.ownerId,e.name)),t.push(n)}k(h.recentList,...t)}},Wr=e=>{let t=Math.max(0,Math.floor(e)),n=String(t%60).padStart(2,`0`),r=Math.floor(t/60)%60,i=Math.floor(t/3600);return i>0?`${i}:${String(r).padStart(2,`0`)}:${n}`:`${r}:${n}`};function Gr(e){let t=document.createElement(`li`),n=document.createElement(`span`);n.className=`server-label`;let r=document.createElement(`span`);r.className=`name`,r.textContent=e.event.title||e.party.partyCode;let i=document.createElement(`span`);i.className=e.party.playing?`detail live`:`detail`,i.textContent=[e.party.playing?`▶ ${Wr(e.party.positionNow)}`:`❚❚ ${Wr(e.party.positionNow)}`,e.party.mediaTitle,e.party.origin,e.host?`yours`:``].filter(Boolean).join(` · `),n.append(r,i);let a=document.createElement(`a`);a.className=`button`,a.href=e.links.partyUrl||e.links.nixampUrl,a.rel=`noopener`,a.target=`_blank`,Vt(a),a.title=`Join live on the site hosting this party (opens in a new tab)`;let o=document.createElement(`a`);o.className=`ghost`,o.href=e.links.nixampUrl,o.textContent=`Open room`,t.className=`party-row`,n.className=`party-name`,n.title=i.textContent,i.hidden=!0;let s=document.createElement(`details`);s.className=`party-actions`;let c=document.createElement(`summary`);return c.textContent=`⋯`,w(c,`aria-label`,()=>`${v(`Show more`)}: ${e.event.title}`),s.append(c,o),t.append(n,a,s),t}let Kr=[],qr=[],Jr=!1,Yr=null,Xr=``;function Zr(){let e=new Map,t=(t,n,r)=>{if(!r.length)return;let i=e.get(t);if(i){let e=new Set(i.rows.map(e=>e.dataset.liveKey));i.rows.push(...r.filter(t=>!e.has(t.dataset.liveKey)))}else e.set(t,{name:n,rows:r})},n=y===`remote`&&j?ge(L.address):``;for(let e of Kr){let r=ge(e.url);if(!r||r===n)continue;let i=[],a=(t,n)=>{let a=document.createElement(`li`);a.dataset.liveKey=`${r}:${t}`,a.className=`party-row`;let o=document.createElement(`span`);o.className=`party-name`,o.textContent=n,o.title=n;let s=document.createElement(`button`);s.type=`button`,Vt(s),w(s,`aria-label`,()=>`${v(`Join party`)}: ${n} · ${e.name}`),s.addEventListener(`click`,()=>{_e=!0,x=t,h.remoteUrl.value=e.url,h.remoteForm.requestSubmit()}),a.append(o,s),i.push(a)};e.playing!==!1&&e.nowPlaying&&a(`live`,Ve(e.nowPlaying));for(let t of e.channels??[]){let n=e.lineup?.find(e=>e.name===t);a(`channel:${n?.id??t}`,t)}t(r,e.name,i)}n&&j&&t(n,j.server.name||b||n,$o(j));for(let e of qr){let n=e.party.origin;try{n=new URL(e.links.partyUrl||e.party.partyUrl).origin}catch{}let r=e.party.origin;try{r=new URL(n).hostname}catch{}let i=Gr(e);i.dataset.liveKey=`party:${e.event.id}`,t(n,r,[i])}let r=new Map([...h.partiesList.children].map(e=>[e.dataset.liveKey,e])),i=[];for(let[t,n]of e){let e=r.get(t);if(!e){e=document.createElement(`li`),e.dataset.liveKey=t,e.className=`party-server`;let n=document.createElement(`h3`),r=document.createElement(`ul`);r.className=`party-rows`,e.append(n,r)}let a=e.querySelector(`h3`);a.textContent!==n.name&&(a.textContent=n.name),Be(e.querySelector(`ul`),n.rows),i.push(e)}Be(h.partiesList,i),h.partiesNote.hidden=e.size>0,e.size||C(h.partiesNote,()=>v(Jr?`No parties live right now.`:`Loading…`))}let Qr=5e3,$r=new Set,ei=(e,t)=>{t?$r.add(e):$r.delete(e),$r.size?h.partiesPanel.dataset.loading=`true`:delete h.partiesPanel.dataset.loading};async function ti(){if(e||(Xr!==Y&&(Yr?.abort(),Yr=null,qr=[],Xr=Y,Zr()),Yr))return;let t=new AbortController;Yr=t;let n=!Jr;n&&ei(t,!0);let i=Y,a=setTimeout(()=>t.abort(),8e3),o=async e=>{let n=await r(e,{signal:t.signal,cache:`no-store`});return{ok:n.ok,status:n.status,body:n.ok?await n.json():null}};try{let[e,n]=await Promise.allSettled([o(`/api/directory`),i?o(`/api/v1/watch-parties`):Promise.resolve(null)]);if(Yr!==t||i!==Y||t.signal.aborted)return;e.status===`fulfilled`&&e.value.ok&&(Kr=e.value.body.streams??[],Jr=!0,h.directory.dataset.available=String(Kr.length>0),Uo()),n.status===`fulfilled`&&n.value&&(n.value.ok?(qr=n.value.body.parties??[],Jr=!0):[401,403].includes(n.value.status)&&(qr=[])),Zr(),!Jr&&!j&&C(h.partiesNote,()=>v(`Could not refresh parties.`))}finally{clearTimeout(a),n&&ei(t,!1),Yr===t&&(Yr=null)}}h.partyForm.addEventListener(`submit`,e=>{e.preventDefault();let t=h.partyCode.value.trim();t!==``&&(async()=>{try{let e=await r(`/api/v1/watch-parties/${encodeURIComponent(t)}`),n=await e.json().catch(()=>({}));if(!e.ok){D=n.error??`No party found with that invite code.`,U();return}h.partyCode.value=``,window.location.href=n.links.nixampUrl}catch{D=`Could not look up that party. Try again.`,U()}})()});async function ni(){if(!Y)h.connectionsNote.hidden=!0,h.connectionsList.hidden=!0;else try{let e=await r(`/api/v1/oauth/connections`);if(!e.ok){h.connectionsNote.hidden=!0,h.connectionsList.hidden=!0;return}let t=(await e.json()).connections??[];h.connectionsNote.hidden=t.length===0,h.connectionsList.hidden=t.length===0,k(h.connectionsList,...t.map(e=>{let t=document.createElement(`li`),n=document.createElement(`span`);n.className=`server-label`;let i=document.createElement(`span`);i.className=`name`,i.textContent=e.clientName;let a=document.createElement(`span`);a.className=`detail`,a.textContent=e.scope.split(` `).filter(Boolean).join(`, `),n.append(i,a);let o=document.createElement(`button`);return o.type=`button`,o.className=`ghost`,C(o,()=>v(`Disconnect`)),o.addEventListener(`click`,()=>{(async()=>{try{await r(`/api/v1/oauth/connections/${encodeURIComponent(e.clientId)}`,{method:`DELETE`})}catch{}await ni()})()}),t.append(n,o),t}))}catch{h.connectionsNote.hidden=!0,h.connectionsList.hidden=!0}}let ri=new Set,K=e=>{try{return new URL(e).origin}catch{return e}},ii=e=>[...ri].some(t=>K(t)===K(e));async function ai(){if(!Y)ri=new Set,h.favoritesPanel.hidden=!0,ci();else{try{let e=await r(`/api/v1/favorites`);if(!e.ok){h.favoritesPanel.hidden=!0;return}let t=(await e.json()).favorites??[];ri=new Set(t.map(e=>e.url)),h.favoritesPanel.hidden=t.length===0,h.favoritesNote.textContent=`Servers you hearted. Connect to one, or let it go.`,k(h.favoritesList,...t.map(e=>{let t=document.createElement(`li`),n=document.createElement(`span`);n.className=`server-label`;let r=document.createElement(`span`);r.className=`name`,r.textContent=e.name||e.url.replace(/^https?:\/\//,``);let i=document.createElement(`span`);return i.className=e.live?`detail live`:`detail`,i.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`,n.append(r,i),t.append(n,...S({name:e.name||e.url,view:e.url,admin:Se(e.url)}),si(e.url,e.name)),t}))}catch{h.favoritesPanel.hidden=!0}ci()}}async function oi(e,t,n){try{if(!(n?await r(`/api/v1/favorites`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify({url:e,name:t})}):await r(`/api/v1/favorites?url=${encodeURIComponent(e)}`,{method:`DELETE`})).ok){D=n?`Could not save that favourite.`:`Could not remove that favourite.`,U();return}}catch{D=`could not reach nixamp.com`,U();return}if(n)ri.add(e);else for(let t of[...ri])K(t)===K(e)&&ri.delete(t);await ai()}function si(e,t){let n=document.createElement(`button`);n.type=`button`,n.className=`heart`;let r=()=>{let t=ii(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=[...ri].find(t=>K(t)===K(e))??e;oi(ii(e)?i:e,t,!ii(e)).then(r)}),n}function ci(){let e=y===`remote`?L.shareLink:``;if(h.favHere.hidden=!(Y&&e),h.favHere.hidden)return;let t=ii(e);h.favHere.textContent=t?`♥`:`♡`,h.favHere.dataset.on=t?`yes`:`no`,h.favHere.title=t?`Remove this server from your favourites`:`Add this server to your favourites`,h.favHere.setAttribute(`aria-label`,h.favHere.title)}g(h.copyNow,`copy`),h.copyNow.addEventListener(`click`,()=>{ls(I.source,h.copyNow,`✓`)});function li(e){if(e===``||e===St)return;St=e;let t=document.createElement(`li`),n=document.createElement(`time`),r=new Date;n.dateTime=r.toISOString(),C(n,()=>r.toLocaleTimeString(_.language,{hour:`2-digit`,minute:`2-digit`,second:`2-digit`}));let i=document.createElement(`span`);for(i.textContent=e,t.append(n,i),h.logList.prepend(t);h.logList.children.length>100;)h.logList.lastElementChild?.remove()}let ui=3e3,q=/(^|\.)nixamp\.com$/.test(globalThis.location.hostname)?``:`https://nixamp.com`,di=``,fi=``,pi=null,mi=!1,hi=new Set,gi=``,_i=null,vi=!1,yi=en(e=>localStorage.getItem(e)),J=Yt(e=>localStorage.getItem(e)),bi=new Set,xi=new Set,Si=null,Ci=``,wi=``,Y=``,Ti=(()=>{try{let e=sessionStorage.getItem(`nixamp.translationSession`);if(e&&/^listener-[a-f0-9-]{36}$/.test(e))return e;let t=`listener-${crypto.randomUUID()}`;return sessionStorage.setItem(`nixamp.translationSession`,t),t}catch{return`listener-${crypto.randomUUID()}`}})(),Ei=null,X=!1,Di=``,Oi=!1,ki=!1,Ai=``,ji=0,Mi=!1,Ni=!1;try{h.transcriptBackground.checked=localStorage.getItem(`nixamp.backgroundSound`)!==`off`}catch{}let Pi=new hn(()=>{Ni=!0,Mi&&(h.transcriptAudioNote.textContent=`Translated audio · background sound unavailable on this device`)},{process:!1}),Fi=()=>{let e=Number(h.transcriptBackgroundLevel.value);Pi.setLevel(e/100),h.transcriptBackgroundValue.value=`${e}%`,w(h.transcriptBackgroundLevel,`aria-valuetext`,()=>_.number(e/100,{style:`percent`})),h.transcriptBackgroundLevel.disabled=!h.transcriptBackground.checked};try{let e=localStorage.getItem(`nixamp.backgroundLevel`);e!==null&&Number.isFinite(Number(e))&&(h.transcriptBackgroundLevel.value=e)}catch{}Fi(),h.transcriptBackgroundLevel.addEventListener(`input`,()=>{Fi();try{localStorage.setItem(`nixamp.backgroundLevel`,h.transcriptBackgroundLevel.value)}catch{}});let Ii=new _n({account:()=>q===``?Y:``,changed:()=>ga()});H(`translation-buy-tools`).append(Ii.button()),Ii.refresh();let Li=new gn({reconnecting:()=>Z.reset(),line:(e,t)=>{Gi=0,Ki.push(e),ma(),Z.push(e,t,0)},status:e=>{h.transcriptAudioNote.textContent=e},failed:e=>{Di=e,wi=e,X=!1,h.transcriptAudio.checked=!1,Z.disable(),Bi(),h.transcriptAudioNote.textContent=`${e} Original audio restored.`,Ii.refresh()}}),Z=new un({fetcher:((e,t)=>String(e).startsWith(`nixamp-shared:`)?Promise.resolve(Li.audio(String(e))):r(e,t)),playing:()=>I.playing,volume:()=>I.volume,active:e=>{Mi=e,I.translatedAudio(e),Pi.active(e&&I.playing&&h.transcriptBackground.checked)},status:e=>{h.transcriptAudioNote.textContent=e+(Ni&&Mi?` · background unavailable`:``)},failed:()=>{wi=h.transcriptAudioNote.textContent||`Translated audio stopped.`,X=!1,h.transcriptAudio.checked=!1,Bi()},authorization:async(e,t)=>{if(t.channel.startsWith(`dub-`))return new Headers;if(!Y||q!==``)throw Error(`Sign in on nixamp.com to enable translated audio.`);if(!Ei||Ei.channel!==t.channel||Ei.expires<Date.now()+2e4||Ei.remaining<t.text.length){let n=await r(`/api/v1/speech/grant`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({channel:t.channel}),signal:e}),i=await n.json();if(!n.ok||!i.token||!i.expires)throw Error(i.error||`Sign in to enable translated audio.`);Ei={channel:t.channel,token:i.token,expires:i.expires,remaining:2e3}}return Ei.remaining-=t.text.length,{authorization:`Bearer ${Ei.token}`}}}),Ri=new zt({fetcher:(e,t)=>{let n=new Headers(t?.headers);return String(e).includes(`/speech/speakers`)&&n.set(`x-nixamp-translation-session`,Ti),r(e,{...t,headers:n})},language:()=>J,speakers:()=>h.transcriptAudio.checked,voices:()=>Si?.voices??[],channel:()=>Ti,status:e=>{!Oi&&!X&&(Di=e),h.transcriptNote.textContent=e},failed:()=>{X=!1,h.transcriptAudio.checked=!1,Z.disable(),Bi()},lines:e=>{Gi=0,Ki.push(...e),ma(),Hi(),h.transcriptAudio.checked&&Z.pushBatch(e.map(e=>({line:e,lag:0,url:`/api/v1/speech/synthesize`,init:{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({text:e.text,language:J,channel:Ti,speaker:e.speaker,voice:Ri.tracker.speakers.get(e.speaker??``)?.voice??`auto`})}})))}}),zi=new fn(e=>{Oi&&I.playing&&Ri.push(e)});function Bi(){ji++,Oi=!1,ki=!1,Ai=``,zi.stop(),Ri.reset(),Li.stop(),Pi.stop(),Z.reset(),k(h.transcriptSpeakers)}async function Vi(){if((Oi||ki)&&Ai===I.mediaKey)return;Bi();let e=ji;ki=!0,Ai=I.mediaKey;try{if(!Y||q!==``)throw Error(`Sign in on nixamp.com to transcribe or translate this audio.`);let t=I.audioInput();if(Ni=!1,h.transcriptAudio.checked&&h.transcriptBackground.checked&&Pi.start(t.context,t.node).then(t=>{t&&e===ji&&Pi.active(Mi&&I.playing&&h.transcriptBackground.checked)}),h.transcriptAudio.checked&&y===`remote`&&O)await Li.start(va(),J),Ii.refresh();else{if(h.transcriptAudio.checked&&await Ii.startSession(Ti),e!==ji)return;await zi.start(t.context,t.node,h.transcriptAudio.checked?2:5)}if(e!==ji)return;Oi=!0,X=!0,Gi=0,Ji??=setInterval(ma,250),h.transcriptNote.textContent=h.transcriptAudio.checked?`Listening for speech and speaker changes…`:`Listening in the original audio language…`}catch(t){if(e!==ji)return;X=!1,h.transcriptAudio.checked=!1,Z.disable(),Bi(),Di=t instanceof Error?t.message:`This audio could not be captured.`,h.transcriptNote.textContent=Di}finally{e===ji&&(ki=!1)}}function Hi(){let e=[...Ri.tracker.speakers.values()].slice(-32),t=new Set(e.map(e=>e.id));for(let t of e){if(h.transcriptSpeakers.querySelector(`[data-speaker="${t.id}"]`))continue;let e=document.createElement(`label`);e.className=`transcript-switch`,e.dataset.speaker=t.id;let n=document.createElement(`span`),r=t.id.split(`-`)[1];C(n,()=>`${v(`Speaker`)} ${r} `),e.append(n);let i=document.createElement(`select`);i.className=`transcript-language`,w(i,`aria-label`,()=>`${v(`Speaker voices`)}: ${r}`);for(let e of Si?.voices??[])i.append(new Option(e.name,e.id));i.value=t.voice,i.addEventListener(`change`,()=>{t.voice=i.value,Z.reset()}),e.append(i),h.transcriptSpeakers.append(e)}h.transcriptVoiceSettings.hidden=!h.transcriptAudio.checked;for(let e of h.transcriptSpeakers.querySelectorAll(`[data-speaker]`))!t.has(e.dataset.speaker??``)&&!e.contains(document.activeElement)&&e.remove()}for(let e of[h.audio,h.video]){for(let t of[`pause`,`ended`,`seeking`,`emptied`])e.addEventListener(t,()=>{e===(I.showingVideo?h.video:h.audio)&&Bi()});for(let t of[`playing`,`seeked`])e.addEventListener(t,()=>{e===(I.showingVideo?h.video:h.audio)&&X&&yi&&I.playing&&Vi()});e.addEventListener(`volumechange`,()=>{Z.setVolume()})}let Ui=``,Wi=null,Gi=Zt(6,!1),Ki=[],qi=[],Ji=null;function Yi(){if(y!==`remote`)return null;let{base:e}=m(ds());if(e===``)return null;let t=``;try{t=new URL(e).origin}catch{return null}let n=O?O.id:A?.kind===`live`?`live`:``;return n===``?null:{server:t,channel:n}}function Xi(e,t=``){let n=new URLSearchParams({server:e.server,channel:e.channel});return t&&n.set(`after`,t),`${q}/api/v1/trollbox?${n.toString()}`}function Zi(){let e=Yi(),t=e?`${e.server}|${e.channel}`:``;t!==di&&(di=t,fi=``,hi.clear(),h.trollboxList.replaceChildren(),pi&&clearTimeout(pi),pi=null,h.trollboxPanel.hidden=e===null,h.trollboxForm.hidden=!0,ra(!1),e&&(C(h.trollboxNote,()=>`The room for ${Sn()||e.channel}. Loading…`),$i()))}function Qi(e){let t=document.createElement(`li`);t.dataset.id=e.id;let n=document.createElement(`time`);n.className=`when`,n.dateTime=e.createdAt;let r=new Date(e.createdAt);C(n,()=>Number.isNaN(r.getTime())?``:r.toLocaleTimeString(_.language,{hour:`2-digit`,minute:`2-digit`}));let i=document.createElement(`span`);i.className=`who`,i.textContent=e.handle;let a=document.createElement(`span`);return a.className=`line`,a.textContent=e.body,a.dir=`auto`,a.translate=!1,t.append(n,i,a),t}async function $i(){let e=Yi(),t=e?`${e.server}|${e.channel}`:``;if(e&&t===di&&!mi){mi=!0;try{let n=await r(Xi(e,fi)),i=await n.json().catch(()=>({}));if(t!==di)return;if(!n.ok){h.trollboxNote.textContent=i.error??`The trollbox is not answering.`;return}let a=(i.messages??[]).filter(e=>!hi.has(e.id));for(let e of a)hi.add(e.id),h.trollboxList.append(Qi(e)),fi=e.createdAt;for(;h.trollboxList.children.length>200;)h.trollboxList.firstElementChild?.remove();let o=i.you??``,s=gi!==o;gi=o,ue.hidden=o!==``,q!==``&&(ue.href=`${q}/?url=${encodeURIComponent(ds())}&play=${encodeURIComponent(`channel:${e.channel}`)}#account-panel`),s&&(Ei=null,ga()),h.trollboxForm.hidden=o===``,h.trollboxEditLabel.hidden=o===``||!ea,o===``&&ra(!1),C(h.trollboxNote,()=>o===``?q===``?`The room for ${Sn()||e.channel}. Sign in to say something.`:`The room for ${Sn()||e.channel}. To say something, open this stream on nixamp.com and sign in.`:`You are ${o} in the room for ${Sn()||e.channel}.`)}catch{t===di&&(h.trollboxNote.textContent=`The trollbox is not answering.`)}finally{mi=!1,t===di&&(pi=setTimeout(()=>{document.visibilityState===`visible`?$i():pi=setTimeout(()=>void $i(),ui)},ui))}}}h.trollboxForm.addEventListener(`submit`,e=>{e.preventDefault();let t=Yi(),n=h.trollboxInput.value.trim();t&&n!==``&&(h.trollboxInput.disabled=!0,(async()=>{try{let e=await r(`${q}/api/v1/trollbox`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({server:t.server,channel:t.channel,body:n})}),i=await e.json().catch(()=>({}));if(!e.ok||!i.message){h.trollboxNote.textContent=i.error??`that did not send`;return}h.trollboxInput.value=``,hi.has(i.message.id)||(hi.add(i.message.id),h.trollboxList.append(Qi(i.message)),fi=i.message.createdAt)}catch{h.trollboxNote.textContent=`The trollbox is not answering.`}finally{h.trollboxInput.disabled=!1}})())});let ea=typeof MediaRecorder<`u`&&typeof navigator.mediaDevices?.getUserMedia==`function`,ta=ea?Wt(e=>MediaRecorder.isTypeSupported(e)):``;h.trollboxMic.hidden=!ea;function na(e){h.trollboxNote.textContent=e,li(e)}function ra(e){let t=_i;if(!t)return;_i=null,clearTimeout(t.stop),clearInterval(t.tick),h.trollboxMic.setAttribute(`aria-pressed`,`false`),h.trollboxMic.textContent=`🎤`;let n=new Promise(e=>{t.recorder.addEventListener(`stop`,()=>e(),{once:!0})});t.recorder.state!==`inactive`&&t.recorder.stop();for(let e of t.stream.getTracks())e.stop();e&&n.then(()=>aa(new Blob(t.chunks,{type:t.recorder.mimeType||ta||`audio/webm`}),t.startedAt))}async function ia(){if(_i||vi||gi===``||!Yi())return;let e;try{e=await navigator.mediaDevices.getUserMedia({audio:{channelCount:1,echoCancellation:!0,noiseSuppression:!0,autoGainControl:!0}})}catch(e){na(e.name===`NotAllowedError`?`The microphone was refused. Allow it for nixamp.com and tap again.`:`No microphone could be opened here.`);return}let t;try{t=new MediaRecorder(e,ta?{mimeType:ta}:{})}catch{for(let t of e.getTracks())t.stop();na(`This browser cannot record the microphone.`);return}let n=[];t.addEventListener(`dataavailable`,e=>{e.data.size>0&&n.push(e.data)});let r=Date.now();_i={recorder:t,stream:e,chunks:n,startedAt:r,stop:setTimeout(()=>ra(!0),Ut),tick:setInterval(()=>{h.trollboxMic.textContent=Gt(r,Date.now())},500)},t.start(250),h.trollboxMic.setAttribute(`aria-pressed`,`true`),h.trollboxMic.textContent=Gt(r,r),na(`Listening. Tap the mic again when you have said it (${Math.round(Ut/1e3)} s at most).`)}async function aa(e,t){let n=Yi();if(n&&gi!==``){if(Date.now()-t<400||e.size===0)na(`That was too short to hear. Tap, say it, then tap again.`);else{vi=!0,h.trollboxMic.disabled=!0,h.trollboxMic.textContent=`…`,na(`Hearing you…`);try{let t=new AudioContext,i;try{i=await t.decodeAudioData(await e.arrayBuffer())}finally{t.close()}let a=new OfflineAudioContext(1,Math.max(1,Math.ceil(i.duration*Ht)),Ht),o=a.createBufferSource();o.buffer=i,o.connect(a.destination),o.start();let s=It((await a.startRendering()).getChannelData(0),Ht),c=h.trollboxEdit.checked,l=new URLSearchParams(c?{}:{server:n.server,channel:n.channel}),u=navigator.language.slice(0,2).toLowerCase();/^[a-z]{2}$/.test(u)&&l.set(`language`,u);let d=await r(`${q}/api/v1/speech/transcribe?${l.toString()}`,{method:`POST`,headers:{"content-type":`audio/wav`},body:new Blob([s.buffer],{type:`audio/wav`})}),f=await d.json().catch(()=>({}));if(!d.ok){na(f.error??`nixamp.com could not hear that.`);return}let p=(f.text??``).trim();if(p===``){na(`Heard nothing. Try again, closer to the mic.`);return}if(c||!f.message){let e=h.trollboxInput.value.trimEnd();h.trollboxInput.value=(e===``?p:`${e} ${p}`).slice(0,500),na(`Heard: “${p}”. Send it, or fix it first.`);return}Yi()&&!hi.has(f.message.id)&&(hi.add(f.message.id),h.trollboxList.append(Qi(f.message)),fi=f.message.createdAt),na(`Said: “${f.message.body}”`)}catch{na(`That recording could not be read here.`)}finally{vi=!1,h.trollboxMic.disabled=!1,h.trollboxMic.textContent=`🎤`}}}}h.trollboxMic.addEventListener(`click`,()=>{_i?ra(!0):ia()});try{h.trollboxEdit.checked=localStorage.getItem(`nixamp.dictate.edit`)===`on`}catch{}h.trollboxEdit.addEventListener(`change`,()=>{try{localStorage.setItem(`nixamp.dictate.edit`,h.trollboxEdit.checked?`on`:`off`)}catch{}na(h.trollboxEdit.checked?`A line you say will wait in the box for Send.`:`A line you say goes straight to the room.`)});async function oa(){try{let e=await r(`${q}/api/v1/me/profile/fields`),t=await e.json().catch(()=>({}));if(!e.ok){h.contactNote.textContent=t.error??`Could not read your details.`;return}for(let e of Kn){let n=h.contactForm.elements.namedItem(e);n instanceof HTMLInputElement&&(n.value=t.profile?.[e]??``)}h.contactNote.textContent=`Your name and work details. Only you see these.`}catch{h.contactNote.textContent=`Could not reach nixamp.com for your details.`}}h.contactForm.addEventListener(`submit`,e=>{e.preventDefault(),h.contactNote.textContent=`Saving…`,(async()=>{try{let e=await r(`${q}/api/v1/me/profile/fields`,{method:`PATCH`,headers:{"content-type":`application/json`},body:JSON.stringify(Jn(h.contactForm))}),t=await e.json().catch(()=>({}));h.contactNote.textContent=e.ok?`Saved.`:Object.values(t.errors??{})[0]??t.error??`that did not save`}catch{h.contactNote.textContent=`Could not reach nixamp.com.`}})()});async function sa(){try{let e=await r(`${q}/api/v1/me/handle`),t=await e.json().catch(()=>({}));if(!e.ok){h.personaNote.textContent=t.error??`Could not read your profile.`;return}h.personaHandle.value=t.chosen?t.handle??``:``,w(h.personaHandle,`placeholder`,()=>t.handle||v(`handle`)),h.personaVoice.value=t.voice===`female`||t.voice===`male`?t.voice:``,h.personaProfile.value=t.profile??``;let n=t.spoken?` (${t.spoken.replace(/^Telnyx\.KokoroTTS\./,`Kokoro `).replace(/^ElevenLabs\./,`ElevenLabs `)})`:``;h.personaNote.textContent=t.chosen?`You are ${t.handle} in every room. On the phone your lines are read ${ca(t.voice??``)}${n}.`:`Rooms call you ${t.handle} until you pick a handle. On the phone your lines are read ${ca(t.voice??``)}${n}.`}catch{h.personaNote.textContent=`Could not reach nixamp.com for your profile.`}}function ca(e){return e===`female`?`in a woman's voice`:e===`male`?`in a man's voice`:e.includes(`.`)?`in the voice ${e}`:`in whichever voice your profile says, or one picked for you`}h.personaForm.addEventListener(`submit`,e=>{e.preventDefault();let t=h.personaHandle.value.trim(),n={voice:h.personaVoice.value,profile:h.personaProfile.value.trim()};t!==``&&(n.handle=t),h.personaNote.textContent=`Saving…`,(async()=>{try{let e=await r(`${q}/api/v1/me/handle`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify(n)}),t=await e.json().catch(()=>({}));if(!e.ok){h.personaNote.textContent=t.error??`that did not save`;return}await sa()}catch{h.personaNote.textContent=`Could not reach nixamp.com.`}})()}),document.addEventListener(`visibilitychange`,()=>{document.visibilityState!==`visible`&&_i&&ra(!0)});function la(){return y===`remote`&&O?{id:O.id,name:O.name,hls:O.video&&F()}:I.loaded||M?{id:Ti,name:Sn()||`This audio`,hls:!1}:null}function ua(){Bi(),Ei=null,bi.clear(),xi.clear(),Wi?.close(),Wi=null,Ji&&clearInterval(Ji),Ji=null,Ki=[],qi=[],h.transcriptList.replaceChildren(),h.subtitle.hidden=!0,h.subtitle.textContent=``}function da(){let e=la(),t=`${e?.id??``}|${I.mediaKey}|${yi}|${J}|${h.transcriptAudio.checked}|${X}|${Y}`;if(t!==Ui){if(Ui=t,ua(),h.transcriptPanel.hidden=!1,h.transcriptOn.checked=yi&&(!!O||X||h.transcriptAudio.checked),h.transcriptLanguage.options.length===0)for(let e of Jt){let t=new Option(e.label,e.code);e.code&&(t.lang=e.code),C(t,()=>e.code?e.label:v(`Original (auto-detect)`)),h.transcriptLanguage.append(t)}h.transcriptLanguage.value=J,ga(),_a(),e?yi?Di?h.transcriptNote.textContent=Di:(h.transcriptNote.textContent=`Asking for ${e.name}'s captions…`,h.transcriptAudio.checked||X?I.playing?Vi():h.transcriptNote.textContent=`Press Play to start listening.`:y===`remote`&&O?fa(e,t):h.transcriptNote.textContent=`Turn on captions to transcribe this audio.`):h.transcriptNote.textContent=`Captions are off.`:h.transcriptNote.textContent=`Play something to see its captions.`}}async function fa(e,t){let n=6,i=J?`?language=${encodeURIComponent(J)}`:``;try{let a=await r(L.url(`/api/channels/${encodeURIComponent(e.id)}/transcript${i}`)),o=await a.json().catch(()=>({}));if(t!==Ui)return;if(!a.ok){h.transcriptNote.textContent=o.error??`This server is not captioning.`;return}if(o.recognitionRevision!==`native-v2`){Y&&q===``?(X=!0,da()):h.transcriptNote.textContent=`This broadcaster needs an update for native captions. Sign in to transcribe the audio on this device.`;return}n=o.backlog??n}catch{t===Ui&&(h.transcriptNote.textContent=`The server did not answer about captions.`);return}Gi=Zt(n,e.hls);let a=new EventSource(L.url(`/api/channels/${encodeURIComponent(e.id)}/captions${i}`));Wi=a;let o=(e,t=!1)=>{for(let n of e){if(!n||typeof n.text!=`string`||!Number.isFinite(n.at)||!Number.isFinite(n.until))continue;let e=`${n.at}|${n.language}`;bi.has(e)||(bi.add(e),bi.size>600&&bi.delete(bi.values().next().value),Ki.push(n),t&&h.transcriptAudio.checked&&xi.add(n))}};a.addEventListener(`hello`,r=>{if(t!==Ui)return;let i=JSON.parse(r.data);Gi=Zt(i.backlog??n,e.hls),o(i.lines??[]);let a=Jt.find(e=>e.code===i.language)?.label??i.language,s=Jt.find(e=>e.code===J)?.label??J;if(h.transcriptNote.textContent=i.error?`Captions unavailable: ${i.error}`:J?`${a||`Detected audio`} → ${s}`:`Original audio · ${a||`detecting language…`}`,!i.error&&i.hash&&/^[0-9a-f]{64}$/.test(i.hash)){let e=document.createElement(`a`);e.href=`${q||``}/hash/${i.hash}`,e.textContent=`Its page`,e.target=`_blank`,e.rel=`noopener`,h.transcriptNote.append(` `,e,`.`)}}),a.addEventListener(`line`,n=>{if(t!==Ui)return;let r=JSON.parse(n.data);o([r],!0);let i=r.sourceLanguage??(r.original===void 0?r.language:``),a=Jt.find(e=>e.code===i)?.label??i,s=Jt.find(e=>e.code===J)?.label??J;h.transcriptNote.textContent=J?`${e.name} · ${a||`Detected audio`} → ${s}`:`${e.name} · Original audio language: ${a||`detecting…`}`}),a.addEventListener(`error`,()=>{t===Ui&&a.readyState===EventSource.CLOSED&&(h.transcriptNote.textContent=`Captions stopped; the server went away.`)}),Ji=setInterval(ma,250)}function pa(e){let t=document.createElement(`li`),n=document.createElement(`time`);n.className=`when`,n.dateTime=new Date(e.at).toISOString(),C(n,()=>tn(e.at));let r=document.createElement(`span`);r.className=`line`,r.textContent=e.text,r.dir=`auto`,r.translate=!1,(e.language||e.sourceLanguage)&&(r.lang=e.language||e.sourceLanguage);let i=Xt(e);if(i){let a=document.createElement(`span`);a.className=`lang`,a.textContent=i.trim(),e.original&&(r.title=e.original),t.append(n,a,r)}else t.append(n,r);return t}function ma(){let e=Date.now(),{ready:t,still:n}=Qt(Ki,e,Gi);Ki=n;for(let e of t)if(qi.push(e),h.transcriptList.append(pa(e)),xi.delete(e)&&h.transcriptAudio.checked&&J){let t=new URLSearchParams({at:String(e.at),language:J,voice:`auto`});Z.push(e,L.url(`/api/channels/${encodeURIComponent(e.channel)}/voice?${t}`),Gi)}for(;qi.length>200;)qi.shift();for(;h.transcriptList.children.length>200;)h.transcriptList.firstElementChild?.remove();let r=$t(qi,e,Gi),i=h.transcriptList.children,a=r?qi.indexOf(r):-1;for(let e=0;e<i.length;e++)i[e]?.classList.toggle(`now`,e===a);let o=I.playing&&r!==null&&!h.video.hidden&&h.video.offsetHeight>0;h.subtitle.hidden=!o,o&&r&&(h.subtitle.textContent!==r.text&&(h.subtitle.textContent=r.text),h.subtitle.style.top=`${h.video.offsetTop+h.video.offsetHeight-h.subtitle.offsetHeight-10}px`)}h.transcriptOn.addEventListener(`change`,()=>{yi=h.transcriptOn.checked,X=yi&&(!O||h.transcriptAudio.checked),yi||(h.transcriptAudio.checked=!1,Z.disable());try{localStorage.setItem(Kt,yi?`on`:`off`)}catch{}da()}),h.transcriptLanguage.addEventListener(`change`,()=>{Di=``,wi=``,J=Yt(()=>h.transcriptLanguage.value),!J&&h.transcriptAudio.checked&&(h.transcriptAudio.checked=!1,X=!1,Z.disable());try{J?localStorage.setItem(qt,J):localStorage.removeItem(qt)}catch{}da()});function ha(){if(J)return J;let e=navigator.language.split(`-`)[0]||`en`;return Jt.some(t=>t.code===e)&&Si?.languages.includes(e)?e:`en`}function ga(){let e=Y!==``&&q===``,t=e&&Ii.loaded()&&!!la()&&!!Si?.languages.includes(ha());h.transcriptAudio.disabled=!t,h.transcriptVoiceSettings.contains(document.activeElement)||(h.transcriptVoiceSettings.hidden=!h.transcriptAudio.checked),t?h.transcriptAudio.checked||C(h.transcriptAudioNote,()=>wi||v(`Original audio.`)):(h.transcriptAudio.checked=!1,Z.disable(),h.transcriptAudioNote.textContent=e?la()?Ii.loaded()?wi||(Si?`Audio translation is unavailable for this language.`:`Loading voices…`):Ii.loadingMessage():`Play something to translate its audio.`:`Sign in to translate audio.`)}async function _a(){if(!Y||q!==``)return;let e=`/api/v1/speech/voices`;if(Ci!==e){Ci=e,Si=null,wi=``,ga();try{let t=await r(e,{signal:AbortSignal.timeout(1e4)}),n=await t.json();if(Ci!==e)return;if(!t.ok)throw Error(n.error||`Translated audio is unavailable on this server.`);if(!Array.isArray(n.voices)||!Array.isArray(n.languages))throw Error(`This server needs an update for translated audio.`);Si=n}catch(t){if(Ci!==e)return;wi=t instanceof Error?t.message:`Translated audio is unavailable.`}ga()}}h.transcriptBackground.addEventListener(`change`,()=>{Fi();try{localStorage.setItem(`nixamp.backgroundSound`,h.transcriptBackground.checked?`on`:`off`)}catch{}if(Pi.stop(),Ni=!1,h.transcriptBackground.checked&&h.transcriptAudio.checked&&I.playing){let e=ji,t=I.audioInput();Pi.start(t.context,t.node).then(t=>{t&&e===ji&&Pi.active(Mi&&I.playing&&h.transcriptBackground.checked)})}}),h.transcriptAudio.addEventListener(`change`,()=>{if(Di=``,wi=``,xi.clear(),h.transcriptAudio.checked&&!Ii.ready())h.transcriptAudio.checked=!1,Ii.open(h.transcriptAudio);else{if(h.transcriptAudio.checked){J=ha();try{localStorage.setItem(qt,J)}catch{}yi=!0,X=!0,Z.enable()}else X=!1,Z.disable();da()}});function va(){if(M)return M.url;if(y!==`remote`)return``;let{base:e,key:t}=m(ds());if(e===``)return``;if(O)return ee(e,`/api/channels/${encodeURIComponent(O.id)}`,t);if(A?.kind===`live`)return ee(e,`/api/live`,t);if(I.source===``)return``;try{let n=new URL(I.source);return n.origin===new URL(e).origin?(t?n.searchParams.set(`k`,t):n.searchParams.delete(`k`),n.toString()):``}catch{return``}}function ya(){let e=va();return e===``?``:`https://nixamp.com/?play=${encodeURIComponent(e)}`}function ba(){return y===`remote`?O?us(`channel:${O.id}`):A?.kind===`live`||B()?us(`live`):``:``}h.shareNow.addEventListener(`click`,()=>{let e=ya();if(e===``)return;let t=navigator;typeof t.share==`function`?t.share({title:`${yn()} on nixamp`,url:e}).catch(()=>void 0):ls(e,h.shareNow,`Copied`)}),h.copyNixamp.addEventListener(`click`,()=>{let e=ba();e!==``&&ls(e,h.copyNixamp,`✓`)});function xa(){let e=ba();if(e!==``)return e;let t=wa();return t===null?``:us(`track:${t}`)}async function Sa(){let e=xa();if(e===``||h.schoolLive.disabled)return;let t=h.schoolLive.textContent;h.schoolLive.disabled=!0,h.schoolLive.textContent=`Opening a classroom…`;let n={"content-type":`application/json`};try{let t=await r(`/api/v1/events`,{method:`POST`,headers:n,body:JSON.stringify({kind:`class`,title:We(yn())||`Live class`,broadcastUrl:e,visibility:`public`})}),i=await t.json().catch(()=>({}));if(!t.ok||!i.event)throw Error(i.error??`the class could not be made`);let a=i.event,o=await r(`/api/v1/events/${encodeURIComponent(a.id)}/start`,{method:`POST`,headers:n,body:JSON.stringify({version:a.version})}),s=`https://backtoschool.help/live/${encodeURIComponent(a.slug)}`;D=o.ok?`Your class is live on backtoschool.help: ${s}`:`The class is made but not started yet. Open it to start: ${s}`,U(),globalThis.open(s,`_blank`,`noopener`)}catch(e){D=`Could not open a classroom: ${e.message}`,U()}finally{h.schoolLive.disabled=!1,h.schoolLive.textContent=t}}h.schoolLive.addEventListener(`click`,()=>{Sa()});function Ca(){if(y!==`remote`)return``;let e=/^(https:\/\/[^/]+)\/view\/([A-Za-z0-9_-]+)\/?$/.exec(ds());return e?O?`${e[1]}/api/channels/${encodeURIComponent(O.id)}?k=${e[2]}`:A?.kind===`live`||B()?`${e[1]}/api/live?k=${e[2]}`:``:``}function wa(){if(y!==`remote`||O||A?.kind===`live`||B()||!/^https:\/\/[^/]+\/view\/[A-Za-z0-9_-]+\/?$/.test(ds()))return null;let e=z();return E.tracks?.[e]?e:null}async function Ta(e){let t=/^(https:\/\/[^/]+)\/view\/([A-Za-z0-9_-]+)\/?$/.exec(ds());if(!t)throw Error(`this server has no view link to share`);let n=await r(`${t[1]}/api/media/${e}/item?k=${t[2]}`,{cache:`no-store`}),i=await n.json().catch(()=>({}));if(n.status===404&&i.error===`no such track`)throw Error("this server needs nixamp 0.48 or newer; run `nixamp update` on it");if(!n.ok||!i.id)throw Error(i.error??`that file is not in the server's library`);return`${t[1]}/api/v1/library/items/${i.id}/play?k=${t[2]}`}let Ea=H(`streaming-publish-note`),Da=H(`streaming-publish-title-input`),Oa=H(`streaming-publish-basis`),ka=H(`streaming-publish-agree`),Aa=H(`streaming-publish-go`);h.streamingLive.addEventListener(`click`,()=>{(Ca()!==``||wa()!==null)&&(Da.value=yn(),Ea.textContent=``,h.streamingPublish.showModal())}),H(`streaming-publish-close`).addEventListener(`click`,()=>h.streamingPublish.close()),H(`streaming-publish-form`).addEventListener(`submit`,e=>{e.preventDefault(),ja()});async function ja(){let e=Ca(),t=e===``?wa():null;if(!(e===``&&t===null||Aa.disabled)){if(!ka.checked)Ea.textContent=`Tick the box to confirm you may broadcast it.`;else{Aa.disabled=!0,Ea.textContent=`Publishing…`;try{let n=e||await Ta(t),i=await r(`https://live.streaming.pit.world/api/v1/guide/${e?`rooms`:`vods`}`,{method:`POST`,headers:{"content-type":`application/json`,authorization:`Bearer ${L.session}`},body:JSON.stringify({play:n,basis:Oa.value,title:Da.value.trim(),agree:!0})}),a=await i.json().catch(()=>({}));if(!i.ok||!a.page)throw Error(a.error??`it could not be published`);h.streamingPublish.close(),D=e?`Live on live.streaming: ${a.page}`:`On demand on live.streaming: ${a.page}`,navigator.clipboard?.writeText(a.page).catch(()=>void 0),U(),globalThis.open(a.page,`_blank`,`noopener`)}catch(e){Ea.textContent=`Could not publish: ${e.message}`}finally{Aa.disabled=!1}}}}h.favHere.addEventListener(`click`,()=>{let e=ds()||L.shareLink;if(!e)return;let t=[...ri].find(t=>K(t)===K(e))??e;oi(ii(e)?t:e,b||L.address,!ii(e)).then(ci)});let Ma=se?le:200,Na=[],Q=null,Pa=null,Fa=``,Ia=[],La=0,Ra=null,za=0,Ba=null,Va=null,Ha=new Map;function Ua(e,t){za++,Ba?.abort(),Ra&&clearTimeout(Ra),Ra=null,Le(h.catalogsList),Le(h.catalogsEntries),Q=e,Pa=t,Fa=``,h.catalogsFilter.value=``,Ia=[],La=0,h.catalogsEntries.setAttribute(`aria-busy`,`false`),qa(),e&&t!==null&&Qa(0)}function Wa(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`}function Ga(){let e=L.url(`/api/catalogs`);if(Va?.url===e)return Va.promise;let t=Ka(e).finally(()=>{Va?.promise===t&&(Va=null)});return Va={url:e,promise:t},t}async function Ka(e){if(y!==`remote`){h.catalogsPanel.hidden=!0;return}let t;try{t=await r(e)}catch{e===L.url(`/api/catalogs`)&&(h.catalogsPanel.hidden=!0);return}y===`remote`&&e===L.url(`/api/catalogs`)&&(t.ok?(Na=(await t.json().catch(()=>({}))).catalogs??[],Q&&=Na.find(e=>e.id===Q?.id)??null,Q||(Pa=null),h.catalogsPanel.hidden=!1,qa()):h.catalogsPanel.hidden=!0)}function qa(){let e=!h.adminPanel.hidden;h.catalogsForm.hidden=!e;let t=Na.reduce((e,t)=>e+t.live,0),n=Na.reduce((e,t)=>e+t.vod,0);h.catalogsNote.textContent=Na.length===0?e?`No catalogs yet. Add an m3u list of channels or films.`:`No catalogs yet.`:`${Na.length} ${Na.length===1?`catalog`:`catalogs`} · ${t} live ${t===1?`channel`:`channels`} · ${n} on demand`,Ja();let r=Q!==null&&Pa!==null;h.catalogsList.hidden=r,h.catalogsFilter.hidden=!r,h.catalogsEntries.hidden=!r,r?$a():Q?Xa(Q):k(h.catalogsList,...Na.map(t=>Ya(t,e)))}function Ja(){let e=Q!==null;if(h.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},n=()=>{let e=document.createElement(`span`);return e.textContent=`/`,e},r=[t(`All catalogs`,()=>Ua(null,null),!1),n(),t(Q?.name??``,()=>Ua(Q,null),Pa===null)];Pa!==null&&r.push(n(),t(Pa===``?`All groups`:Pa,()=>void 0,!0)),h.catalogsCrumbs.replaceChildren(...r)}function Ya(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`,C(a,()=>[`${e.entries.toLocaleString(_.language)} ${e.entries===1?`entry`:`entries`}`,`${e.live.toLocaleString(_.language)} live`,`${e.vod.toLocaleString(_.language)} on demand`,`refreshed ${Wa(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.setAttribute(`aria-label`,`Browse ${e.name}`),o.addEventListener(`click`,()=>{Ua(e,null)}),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`,()=>{to(e)});let r=document.createElement(`button`);r.type=`button`,r.className=`ghost`,C(r,()=>v(`Remove`)),r.title=`Take this catalog off the server`,r.addEventListener(`click`,()=>{confirm(`Remove ${e.name} from this server?`)&&cs(n,r,()=>no(e),()=>void Ga())}),n.append(t,r)}return n}async function Xa(e){let t=L.url(`/api/catalogs/${encodeURIComponent(e.id)}/groups`),n=`${t}:${e.refreshedAt}:${e.entries}`,i;h.catalogsList.setAttribute(`aria-busy`,`true`);try{let e=Ha.get(n);e||(Ha.size>=20&&Ha.delete(Ha.keys().next().value),e=r(t).then(async e=>{if(!e.ok)throw Error(String(e.status));return(await e.json()).groups??[]}),Ha.set(n,e)),i=await e}catch{if(Ha.delete(n),Q?.id!==e.id||Pa!==null||t!==L.url(`/api/catalogs/${encodeURIComponent(e.id)}/groups`))return;h.catalogsList.setAttribute(`aria-busy`,`false`),D=`Could not read the groups in ${e.name}.`,U();return}if(Q?.id!==e.id||Pa!==null||t!==L.url(`/api/catalogs/${encodeURIComponent(e.id)}/groups`))return;h.catalogsList.setAttribute(`aria-busy`,`false`);let a=[Za(`All groups`,``,e.entries,e.live,e.vod),...i.map(e=>Za(e.name||`(no group)`,e.name,e.count,e.live,e.vod))];k(h.catalogsList,...a)}function Za(e,t,n,r,i){let a=document.createElement(`li`),o=document.createElement(`span`);o.className=`server-label`;let s=document.createElement(`span`);s.className=`name`,s.textContent=e;let c=document.createElement(`span`);c.className=`detail`,C(c,()=>`${n.toLocaleString(_.language)} · ${r.toLocaleString(_.language)} live · ${i.toLocaleString(_.language)} on demand`),o.append(s,c);let l=document.createElement(`button`);return l.type=`button`,l.className=`button`,l.textContent=`Open`,l.setAttribute(`aria-label`,`Open ${e}`),l.addEventListener(`click`,()=>{Ua(Q,t)}),a.append(o,l),a}async function Qa(e){let t=Q,n=Pa;if(!t||n===null)return;let i=++za;Ba?.abort();let a=new AbortController;Ba=a;let o=L.url(`/api/catalogs`);h.catalogsEntries.setAttribute(`aria-busy`,`true`);let s=new URLSearchParams({group:n,q:Fa,offset:String(e),limit:String(Ma)}),c;try{let e=await r(L.url(`/api/catalogs/${encodeURIComponent(t.id)}/entries?${s}`),{signal:a.signal});if(!e.ok)throw Error(String(e.status));c=await e.json()}catch{if(a.signal.aborted||i!==za)return;h.catalogsEntries.setAttribute(`aria-busy`,`false`),D=`Could not read ${t.name}.`,$a(),U();return}i===za&&Q?.id===t.id&&Pa===n&&o===L.url(`/api/catalogs`)&&(h.catalogsEntries.setAttribute(`aria-busy`,`false`),La=c.total??0,Ia=e===0?c.entries??[]:[...Ia,...c.entries??[]],$a())}function $a(){let e=Q;if(!e)return;let t=Ia.map(t=>{let n=document.createElement(`li`);n.className=`row`;let r=document.createElement(`span`);r.className=`name`,r.textContent=t.title;let i=document.createElement(`span`);i.className=t.live?`catalog-tag catalog-live`:`catalog-tag`,i.textContent=t.live?`LIVE`:t.duration>0?je(t.duration):`VOD`;let a=document.createElement(`button`);if(a.type=`button`,a.className=`row-main`,a.setAttribute(`aria-label`,`Play ${t.title}`),a.append(r,i),n.append(a),a.addEventListener(`click`,()=>{eo(e,t,n)}),!t.live){let r=document.createElement(`button`);r.type=`button`,r.className=`row-copy`,g(r,`copy`),r.title=`Copy this entry's URL`,r.setAttribute(`aria-label`,`Copy the URL of ${t.title}`),r.addEventListener(`click`,n=>{n.stopPropagation();let i=`/api/catalogs/${encodeURIComponent(e.id)}/entries/${encodeURIComponent(t.id)}/stream`;ls(L.url(i),r,`✓`)}),n.append(r)}return Lt()&&n.append(nn(()=>({kind:`entry`,catalog:{id:e.id,name:e.name},entry:t}),t.title)),n});if(Ia.length===0){let e=document.createElement(`li`);e.className=`group`;let n=document.createElement(`span`);n.className=`group-name`,n.textContent=Fa?`Nothing called "${Fa}" here.`:`Nothing in this group.`,e.append(n),t.push(e)}else if(Ia.length<La){let e=document.createElement(`li`);e.className=`group`;let n=document.createElement(`button`);n.type=`button`,n.className=`ghost`,C(n,()=>`Show more (${Ia.length.toLocaleString(_.language)} of ${La.toLocaleString(_.language)})`),n.addEventListener(`click`,e=>{e.stopPropagation(),Le(h.catalogsEntries,!1),n.disabled=!0,Qa(Ia.length)}),e.append(n),t.push(e)}k(h.catalogsEntries,...t)}async function eo(e,t,n){n?.classList.add(`loading`),D=`Starting ${t.title}…`;let i={catalog:{id:e.id,name:e.name},entry:t};try{await Ge(async()=>{let n,a={};try{n=await r(L.url(`/api/catalogs/${encodeURIComponent(e.id)}/entries/${encodeURIComponent(t.id)}/play`),{method:`POST`}),a=await n.json().catch(()=>({}))}catch{D=`could not reach the server`;return}if(!n.ok){D=a.error??`${t.title} would not play.`;return}let o=a.name||t.title;a.kind===`live`&&a.channel?await ns({id:a.channel,name:o,video:!0},!0,{kind:`channel`,...i}):a.kind===`vod`&&a.url?(O=null,ke=-1,A={kind:`vod`,...i},it(o,`title`),await I.load({title:o,artist:``,album:``,duration:0,url:L.url(a.url),video:!0,objectUrl:!1},!0),hr(!0),D=`Playing ${o}.`):D=`${t.title} would not play.`})}finally{n?.classList.remove(`loading`),U()}}async function to(e){G(`Reading ${e.name} again…`);try{let t=await r(L.url(`/api/catalogs/${encodeURIComponent(e.id)}/refresh`),{method:`POST`}),n=await t.json().catch(()=>({}));G(t.ok?`${n.catalog?.name??e.name}: ${(n.catalog?.entries??0).toLocaleString(_.language)} entries.`:n.error??`that did not work`)}catch{G(`could not reach the server`)}Ga()}async function no(e){try{let t=await r(L.url(`/api/catalogs/${encodeURIComponent(e.id)}`),{method:`DELETE`});if(G(t.ok?`${e.name} is off the server.`:`that did not work`),!t.ok)return!1}catch{return G(`could not reach the server`),!1}return Q?.id===e.id&&(Q=null,Pa=null),!0}h.catalogsForm.addEventListener(`submit`,e=>{e.preventDefault();let t=h.catalogSource.value.trim(),n=h.catalogName.value.trim();t&&(async()=>{G(`Reading ${n||t}…`);try{let e=await r(L.url(`/api/catalogs`),{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({source:t,name:n})}),i=await e.json().catch(()=>({}));if(!e.ok){G(i.error??`that did not work`);return}G(`${i.catalog?.name??n??t}: ${(i.catalog?.entries??0).toLocaleString(_.language)} entries.`),h.catalogSource.value=``,h.catalogName.value=``}catch{G(`could not reach the server`)}Ga()})()}),h.catalogsFilter.addEventListener(`input`,()=>{za++,Ba?.abort(),Ra&&clearTimeout(Ra),Ra=setTimeout(()=>{Ra=null,Fa=h.catalogsFilter.value.trim(),Qa(0)},250)});let ro=async()=>{k(h.serversList);try{let e=await r(`/api/v1/servers`);if(!e.ok){h.serversPanel.hidden=!0;return}let t=(await e.json()).servers??[];xe=new Map(t.map(e=>[K(e.url),e.key?`${e.url}/admin/${e.key}`:e.url])),h.serversPanel.hidden=!1,h.serversNote.textContent=t.length===0?"No servers yet. `nixamp server add --here` remembers the one you are running.":`The machines on your account. Arriving signed in, this page connects to your default one, or the first that answers; a link you arrive with goes live there.`;for(let e of t){let t=document.createElement(`li`),n=document.createElement(`span`);n.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,n.append(i,a);let o=e.key?`${e.url}/admin/${e.key}`:e.url,[s,c]=S({name:e.name,view:o,admin:o});te(e.url).then(n=>{n===null?(a.textContent=`${e.url} · not answering`,t.classList.add(`offline`),s.disabled=!0,c.disabled=!0,s.title=c.title=`That machine is not answering. Start nixamp on it.`):a.textContent=`${e.url} · ${n}`});let l=xo()===K(e.url),u=document.createElement(`button`);u.type=`button`,u.className=`ghost`,u.textContent=l?`✓ Default`:`Make default`,u.title=l?`The server this page connects to when you arrive signed in. Press to go back to the first that answers.`:`Connect to this server whenever you arrive signed in`,u.addEventListener(`click`,()=>{So(l?``:K(e.url)),ro()});let d=document.createElement(`button`);d.type=`button`,d.className=`ghost`,d.textContent=`Forget`,d.addEventListener(`click`,()=>{(async()=>{d.disabled=!0;try{await r(`/api/v1/servers/${encodeURIComponent(e.id)}`,{method:`DELETE`}),await ro()}catch{d.disabled=!1}})()}),t.append(n,s,c,u,d),h.serversList.append(t)}}catch{h.serversPanel.hidden=!0}},io=async()=>{k(h.followingList);try{let e=await r(`/api/v1/follows`);if(!e.ok){h.followingNote.hidden=!0;return}let t=(await e.json()).following??[];h.followingNote.hidden=t.length===0;for(let e of t){let t=document.createElement(`li`),n=document.createElement(`span`);n.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`,n.append(i,a);let o=document.createElement(`button`);o.type=`button`,o.className=`ghost follow`,C(o,()=>v(`Unfollow`)),o.addEventListener(`click`,()=>{(async()=>{o.disabled=!0;try{await r(`/api/v1/follows/${encodeURIComponent(e.id)}`,{method:`DELETE`}),t.remove(),h.followingList.children.length===0&&(h.followingNote.hidden=!0)}finally{o.disabled=!1}})()}),t.append(n,o),h.followingList.append(t)}}catch{h.followingNote.hidden=!0}},ao=(e,t)=>{let n=document.createElement(`button`);n.type=`button`,n.className=`ghost follow`,C(n,()=>v(`Follow`)),n.setAttribute(`aria-label`,`Follow ${t}`);let i=e=>{C(n,()=>e?`Following`:v(`Follow`)),n.dataset.following=e?`yes`:`no`};return(async()=>{try{let t=await r(`/api/v1/follows/${encodeURIComponent(e)}`);t.ok&&i((await t.json()).following===!0)}catch{}})(),n.addEventListener(`click`,()=>{(async()=>{let t=n.dataset.following===`yes`;n.disabled=!0;try{(await r(`/api/v1/follows/${encodeURIComponent(e)}`,{method:t?`DELETE`:`PUT`,headers:{"content-type":`application/json`},body:t?void 0:`{}`})).ok&&(i(!t),io())}catch{}finally{n.disabled=!1}})()}),n},oo=async()=>{let e=s();if(!e.supported)return h.notifyNote.textContent=e.message,!1;try{return await a({vapidKeyUrl:`/api/v1/notify/key`,serviceWorkerUrl:`/sw.js`,saveUrl:`/api/v1/notify/subscribe`}),h.notifyNote.textContent=`This device will be told.`,!0}catch(e){return h.notifyNote.textContent=e instanceof c&&e.reason!==`save-failed`?e.message:`Could not set this device up.`,!1}},so=async()=>{try{await i({removeUrl:`/api/v1/notify/subscribe`})}catch{}},co=async e=>{try{let t=await r(`/api/v1/notify/prefs`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify(e)}),n=await t.json();h.notifyPhoneNote.textContent=t.ok?``:n.error??`that did not save`,t.ok&&typeof n.phone==`string`&&(h.notifyPhone.value=n.phone)}catch{h.notifyPhoneNote.textContent=`could not reach nixamp.com`}},lo=async()=>{try{let e=await r(`/api/v1/notify/prefs`);if(!e.ok)return;let t=await e.json();h.notifyEmail.checked=t.wantsEmail!==!1,h.notifySms.checked=t.wantsSms===!0,h.notifyPhone.value=t.phone??``;let n=s(),i=n.supported&&n.permission===`granted`?await o()!==null:!1;h.notifyWeb.checked=t.wantsWeb!==!1&&i,h.notifyNote.textContent=i?`Get told when someone you follow goes live.`:n.message??`Turn on “On this device” to be told here.`}catch{}};h.notifyWeb.addEventListener(`change`,()=>{(async()=>{if(h.notifyWeb.checked){let e=await oo();h.notifyWeb.checked=e,await co({wantsWeb:e})}else await so(),await co({wantsWeb:!1}),h.notifyNote.textContent=`Turn on “On this device” to be told here.`})()}),h.notifyEmail.addEventListener(`change`,()=>{co({wantsEmail:h.notifyEmail.checked})}),h.notifySms.addEventListener(`change`,()=>{(async()=>{h.notifySms.checked&&!h.notifyPhone.value.trim()?(h.notifyPhoneNote.textContent=`Add a phone number first.`,h.notifySms.checked=!1):await co({wantsSms:h.notifySms.checked})})()}),h.notifyPhoneForm.addEventListener(`submit`,e=>{e.preventDefault(),co({phone:h.notifyPhone.value.trim()})});let uo=!1,fo=!1,po=`nixamp.welcome`,mo=()=>{let e=!1;try{e=localStorage.getItem(po)===`hidden`}catch{}h.welcome.hidden=!fo||Y!==``||e},ho=!1,go=()=>{if(ho||!fo||location.pathname.replace(/\/+$/,``)===``)return;ho=!0,h.adnet.dataset.adNetwork=`SSXBxU06ZRXMrzpJ`,h.adnet.dataset.slot=`514646f2-8299-40c1-9d9e-37d60d2d5892`,h.adnet.dataset.format=`text_link`,h.adnet.setAttribute(`data-cp-ad`,``),h.adnet.hidden=!1;let e=()=>window.crawlproofAds;if(!document.querySelector(`script[src="https://crawlproof.com/ad.js"]`)){let e=document.createElement(`script`);e.src=`https://crawlproof.com/ad.js`,e.async=!0,document.head.append(e)}let t=0,n=()=>{let r=e();r?.scan?r.scan():++t<=25&&setTimeout(n,200)};n()},_o=t=>{document.dispatchEvent(new CustomEvent(`nixamp:account`,{detail:{email:t}}));let n=t!==null;Ii.refresh(),Ci=``,Ei=null,n||(X=!1,h.transcriptAudio.checked=!1,Z.disable(),Bi()),da(),h.notifyPanel.hidden=!n,n?(lo(),io(),ro()):(h.serversPanel.hidden=!0,h.followingNote.hidden=!0,k(h.followingList),h.recentNote.hidden=!0,h.recentList.replaceChildren()),h.accountForm.hidden=n,h.accountProviders.hidden=n||h.accountProviders.childElementCount===0,h.accountSignOut.hidden=!n,h.personaForm.hidden=!n,h.personaNote.hidden=!n,n&&sa(),h.accountProfile.hidden=n||!uo;let r=h.accountProfile.querySelector(`fieldset`);r&&(r.disabled=n||!uo),h.contactForm.hidden=!n,h.contactNote.hidden=!n,n&&oa(),h.accountNote.textContent=n?`Signed in as ${t}.`:uo?`Create an account on nixamp.com.`:`Listening needs no account. Sign in to keep favourites, follow people, and publish.`,C(h.accountSubmit,()=>v(uo?`Create account`:`Sign in`)),C(h.accountToggle,()=>uo?`I have one`:v(`Create one`)),h.accountPassword.autocomplete=uo?`new-password`:`current-password`,h.accountForgot.hidden=uo,e&&(h.accountForgot.target=`_blank`,h.accountForgot.rel=`noopener`),mo()},vo=async()=>{let e=[];fo=!1;try{let t=await r(`/api/v1/auth/providers`);t.ok&&(fo=!0,e=(await t.json()).providers??[])}catch{}h.accountProviders.replaceChildren(),h.accountProviders.hidden=e.length===0,h.accountPanel.hidden=!fo,h.accountElsewhere.hidden=fo,mo(),go();for(let t of e){let e=document.createElement(`a`);e.className=`button`,e.href=`/api/v1/${encodeURIComponent(t.id)}/oauth/start?redirect=${encodeURIComponent(location.pathname+location.search)}`,e.textContent=`Continue with ${t.name}`,h.accountProviders.append(e)}},yo=async()=>{try{let e=await r(`/api/v1/auth/me`),t=await e.json();Y=e.ok?t.account?.id??``:``,_o(e.ok?t.account?.email??`you`:null)}catch{Y=``,_o(null)}if(L.session=``,Y!==``){try{let e=await r(`/api/v1/auth/token`),t=await e.json().catch(()=>({}));L.session=e.ok&&typeof t.token==`string`?t.token:``}catch{L.session=``}y===`remote`&&Br()}ai(),ti(),ni(),Co();let e=await bo();if(xt!==``){let t=xt;xt=``,e?x=`golive:${t}`:_r(t)}};async function bo(){if(Y===``||y===`remote`||bt!==``)return!1;let e=[];try{let t=await r(`/api/v1/servers`);if(!t.ok)return!1;e=(await t.json()).servers??[]}catch{return!1}if(e.length===0)return!1;let t=xo(),n=[...e].sort((e,n)=>Number(K(n.url)===t)-Number(K(e.url)===t));for(let e of n)if(await te(e.url,void 0,e.key)!==null)return y!==`remote`&&(_e=!1,x=``,h.remoteUrl.value=e.key?`${e.url}/admin/${e.key}`:e.url,D=`Connecting to ${e.name}, your server…`,U(),h.remoteForm.requestSubmit(),!0);return!1}function xo(){try{return localStorage.getItem(Vn)??``}catch{return``}}function So(e){try{e===``?localStorage.removeItem(Vn):localStorage.setItem(Vn,e)}catch{}}function Co(){if(bt===``)return;let e=bt;bt=``,h.remoteUrl.value=e,h.remoteForm.requestSubmit()}h.accountToggle.addEventListener(`click`,()=>{uo=!uo,_o(null)}),h.welcomeCreate.addEventListener(`click`,()=>{uo=!0,_o(null),h.accountPanel.scrollIntoView({behavior:`smooth`,block:`center`}),h.accountEmail.focus({preventScroll:!0})}),h.welcomeBrowse.addEventListener(`click`,()=>{h.directory.hidden?h.browse.click():h.directory.scrollIntoView({behavior:`smooth`,block:`nearest`})}),h.welcomeHide.addEventListener(`click`,()=>{try{localStorage.setItem(po,`hidden`)}catch{}h.welcome.hidden=!0}),h.accountForm.addEventListener(`submit`,n=>{n.preventDefault();let i=h.accountEmail.value.trim(),a=h.accountPassword.value;(async()=>{h.accountSubmit.disabled=!0;try{let n=await r(`/api/v1/auth/${uo?`signup`:`login`}`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({email:i,password:a,...uo?Jn(h.accountForm):{}})}),o=await n.json();if(!n.ok){h.accountNote.textContent=o.error??`that did not work`;return}e&&(t=o.token??``),Y=o.account?.id??``,h.accountPassword.value=``,_o(o.account?.email??i),Br(),Co();let s=new URLSearchParams(location.search).get(`redirect`)??``;s.startsWith(`/`)&&!s.startsWith(`//`)&&!s.startsWith(`/\\`)&&location.assign(s)}catch{h.accountNote.textContent=`could not reach nixamp.com`}finally{h.accountSubmit.disabled=!1}})()}),h.accountSignOut.addEventListener(`click`,()=>{(async()=>{try{await r(`/api/v1/auth/logout`,{method:`POST`})}catch{}t=``,Y=``,_o(null),ti(),L.close(),ke=-1,y=`local`,Ee=`idle`,De=``,h.remoteUrl.value=``,h.sharePanel.hidden=!0,h.publishPanel.hidden=!0,h.adminPanel.hidden=!0,h.catalogsPanel.hidden=!0,h.listenOnly.hidden=!0,Xo(!1);try{localStorage.removeItem(Bn)}catch{}D=`Signed out, and disconnected from the server.`,Br(),U()})()});try{let e=new URL(globalThis.location.href).searchParams,t=e.get(`url`)??``;t!==``&&(bt=t,x=e.get(`play`)??``,be=Math.max(0,Number(e.get(`t`)??`0`)||0),h.remoteUrl.value=t,D=`Opening the stream you were sent…`,globalThis.history?.replaceState(null,``,globalThis.location.pathname));let n=e.get(`link`)??``;n!==``&&(h.linkUrl.value=n,t!==``&&x===``?x=`link:${n}`:t===``&&(xt=n));let r=e.get(`play`)??``;if(t===``&&/^https?:\/\//i.test(r)){let t=d(r);t?(bt=t.view,x=t.what,be=Math.max(0,Number(e.get(`t`)??`0`)||0),h.remoteUrl.value=t.view,D=`Opening the stream you were sent…`):(h.linkUrl.value=r,xt=r),globalThis.history?.replaceState(null,``,globalThis.location.pathname)}}catch{}let wo=[`zone-top`,`zone-main`],To=e=>e instanceof HTMLElement&&e.matches(`section.panel`)&&e.id!==``,Eo=e=>e.parentElement&&wo.includes(e.parentElement.id)?e.parentElement:null,Do=e=>e.classList.contains(`col-a`)?`a`:e.classList.contains(`col-b`)?`b`:``,Oo=()=>[...document.querySelectorAll(`section.panel`)].filter(e=>To(e)&&Eo(e)!==null),ko=e=>e.dataset.title??e.id,Ao=new Map,jo=Oo().map((e,t)=>(Ao.set(e.id,{zone:Eo(e)?.id??``,col:Do(e),index:t}),e.id)),$=kt();try{$=Mt(localStorage.getItem(Ot))}catch{}let Mo=()=>$.order.length>0||Object.keys($.placement).length>0;function No(){$.order=Oo().map(e=>e.id);try{localStorage.setItem(Ot,Nt($))}catch{}}function Po(e,t,n){e.classList.remove(`col-a`,`col-b`),t.classList.contains(`split`)&&n!==``&&e.classList.add(`col-${n}`),t!==e.parentElement&&t.append(e)}function Fo(){if(e)return;for(let e of Oo()){let t=$.placement[e.id];if(!t)continue;let[n=``,r=``]=t.split(`:`),i=document.getElementById(n);i&&wo.includes(i.id)&&Po(e,i,r===`a`||r===`b`?r:``)}let t=Pt(Oo().map(e=>e.id),$.order);for(let e of wo){let n=document.getElementById(e);if(!n)continue;let r=[...n.children].filter(To),i=r.map(e=>{let t=document.createComment(`panel`);return e.before(t),t});r.sort((e,n)=>t.indexOf(e.id)-t.indexOf(n.id)),r.forEach((e,t)=>i[t]?.replaceWith(e))}for(let e of Oo())e.toggleAttribute(`data-collapsed`,$.collapsed.includes(e.id)),e.toggleAttribute(`data-closed`,$.closed.includes(e.id))}function Io(e,t){e.toggleAttribute(`data-collapsed`,t),e===h.panelsPanel&&h.panelsToggle.setAttribute(`aria-expanded`,String(!t&&!e.hidden&&!e.hasAttribute(`data-closed`))),e.querySelector(`.panel-tools [aria-expanded]`)?.setAttribute(`aria-expanded`,String(!t)),$.collapsed=Ft($.collapsed,e.id,t),No(),Uo()}function Lo(e,t){let n=e.contains(document.activeElement);e.toggleAttribute(`data-closed`,t),!t&&e.dataset.available===`true`&&(e.hidden=!1),e===h.panelsPanel&&t&&(e.hidePopover?.(),e.hidden=!0),e===h.panelsPanel&&h.panelsToggle.setAttribute(`aria-expanded`,String(!t&&!e.hidden&&!e.hasAttribute(`data-collapsed`))),e===h.partiesPanel&&!t&&ti(),t&&n&&h.panelsToggle.focus({preventScroll:!0}),$.closed=Ft($.closed,e.id,t),No(),Uo()}function Ro(e,t,n){let r=Eo(t);r&&e!==t&&(Po(e,r,Do(t)),n?t.after(e):t.before(e),$.placement[e.id]=`${r.id}:${Do(t)}`,No(),Uo())}let zo=null,Bo=()=>{for(let e of Oo())e.classList.remove(`drop-before`,`drop-after`)},Vo=(e,t,n)=>{let r=document.createElement(`button`);return r.type=`button`,r.className=`icon-btn`,r.textContent=e,r.title=t,r.setAttribute(`aria-label`,t),r.addEventListener(`click`,e=>{e.stopPropagation(),n()}),r};function Ho(){for(let e of Oo()){let t=ko(e);e.setAttribute(`aria-label`,t);let n=e.querySelector(`:scope > .panel-heading`);n||(n=document.createElement(`h2`),n.className=`panel-heading`,e.prepend(n));let r=n.querySelector(`.panel-heading-text`);if(!r){r=document.createElement(`span`),r.className=`panel-heading-text`;let e=document.createElement(`span`);e.className=`panel-loading-spinner`,e.setAttribute(`aria-hidden`,`true`),n.replaceChildren(r,e)}if(r.textContent!==t&&(r.textContent=t),e.querySelector(`:scope > .panel-tools`))continue;let i=document.createElement(`span`);i.className=`panel-tools`;let a=Vo(`≡`,`Move ${ko(e)}: Alt plus Up or Down, or drag`,()=>void 0);a.addEventListener(`keydown`,t=>{if(!t.altKey||![`ArrowUp`,`ArrowDown`].includes(t.key))return;t.preventDefault(),t.stopPropagation();let n=Oo().filter(t=>Eo(t)===Eo(e)&&Do(t)===Do(e)),r=n[n.indexOf(e)+(t.key===`ArrowUp`?-1:1)];r&&(Ro(e,r,t.key===`ArrowDown`),a.focus({preventScroll:!0}))}),a.classList.add(`grip`),a.draggable=!0,a.addEventListener(`dragstart`,t=>{zo=e,e.classList.add(`dragging`),t.dataTransfer?.setData(`text/plain`,e.id),t.dataTransfer&&(t.dataTransfer.effectAllowed=`move`)}),a.addEventListener(`dragend`,()=>{zo=null,e.classList.remove(`dragging`),Bo()});let o=Vo(`▁`,`Shade ${ko(e)} to its title`,()=>Io(e,!e.hasAttribute(`data-collapsed`)));o.setAttribute(`aria-expanded`,String(!e.hasAttribute(`data-collapsed`)));let s=Vo(`✕`,`Hide ${ko(e)}; the Panels list turns it back on`,()=>Lo(e,!0));e.id===`transcript-panel`&&i.append(Ii.button()),i.append(a,o,s),e.prepend(i),e.addEventListener(`dragover`,t=>{if(!zo||zo===e)return;t.preventDefault();let n=e.getBoundingClientRect(),r=t.clientY>n.top+n.height/2;Bo(),e.classList.add(r?`drop-after`:`drop-before`)}),e.addEventListener(`dragleave`,()=>e.classList.remove(`drop-before`,`drop-after`)),e.addEventListener(`drop`,t=>{if(!zo||zo===e)return;t.preventDefault();let n=e.classList.contains(`drop-after`);Bo(),Ro(zo,e,n)})}}function Uo(){if(h.panelsPanel.hidden||h.panelsList.contains(document.activeElement))return;let e=Oo().filter(e=>e!==h.panelsPanel).map(e=>{let t=document.createElement(`li`),n=e.hasAttribute(`data-closed`);t.classList.toggle(`off`,n);let r=document.createElement(`label`),i=document.createElement(`input`);i.type=`checkbox`,i.checked=!n,w(i,`aria-label`,()=>`${ko(e)} on`),i.addEventListener(`change`,()=>Lo(e,!i.checked));let a=document.createElement(`span`);a.className=`name`,C(a,()=>ko(e)),r.append(i,a);let o=document.createElement(`span`);return o.className=`detail`,o.textContent=n?`off`:e.hasAttribute(`data-collapsed`)?`shaded`:e.hidden&&e.dataset.available!==`true`?`nothing to show right now`:``,t.append(r,o),t});h.panelsList.replaceChildren(...e)}function Wo(){$=kt();for(let e of jo){let t=document.getElementById(e),n=Ao.get(e),r=n?document.getElementById(n.zone):null;t&&n&&r&&(Po(t,r,n.col),t.removeAttribute(`data-collapsed`),t.removeAttribute(`data-closed`))}$.order=[...jo],Fo(),$=kt();try{localStorage.removeItem(Ot)}catch{}Uo()}function Go(e){if(!e||Mo())return;let t=Eo(h.adminPanel);if(!t)return;let n=[...t.children].filter(To).find(e=>Do(e)===Do(h.adminPanel));n&&n!==h.adminPanel&&n.before(h.adminPanel),h.adminPanel.removeAttribute(`data-collapsed`),h.adminPanel.removeAttribute(`data-closed`)}h.panelsToggle.addEventListener(`click`,e=>{e.preventDefault();let t=h.panelsPanel.hidden||h.panelsPanel.hasAttribute(`data-closed`)||h.panelsPanel.hasAttribute(`data-collapsed`);h.panelsPanel.hidden=!t,h.panelsToggle.setAttribute(`aria-expanded`,String(t)),t?(h.panelsPanel.hasAttribute(`data-closed`)&&Lo(h.panelsPanel,!1),h.panelsPanel.hasAttribute(`data-collapsed`)&&Io(h.panelsPanel,!1),Uo(),h.panelsPanel.showPopover?.(),h.panelsList.querySelector(`input`)?.focus({preventScroll:!0})):h.panelsPanel.hidePopover?.()}),h.panelsPanel.addEventListener(`toggle`,()=>{let e=h.panelsPanel.matches(`:popover-open`);h.panelsToggle.setAttribute(`aria-expanded`,String(e&&!h.panelsPanel.hasAttribute(`data-collapsed`))),e||(h.panelsPanel.hidden=!0)}),h.panelsPanel.addEventListener(`keydown`,e=>{e.key===`Escape`&&typeof h.panelsPanel.hidePopover!=`function`&&(h.panelsPanel.hidden=!0,h.panelsToggle.setAttribute(`aria-expanded`,`false`),h.panelsToggle.focus({preventScroll:!0}))}),h.panelsReset.addEventListener(`click`,Wo),h.panelsSave.addEventListener(`click`,()=>{No();let e=h.panelsSave.textContent??`Save setup`;h.panelsSave.textContent=`Saved`,window.setTimeout(()=>{h.panelsSave.textContent=e},1200)}),new MutationObserver(()=>{Ho(),Uo()}).observe(document.body,{attributes:!0,attributeFilter:[`data-title`,`hidden`],subtree:!0}),Ho(),Fo(),vo(),yo(),Br(),wr(),h.browse.addEventListener(`click`,()=>{h.directory.hidden?(Ar(),h.directory.scrollIntoView({behavior:`smooth`,block:`nearest`})):h.directory.hidden=!0}),h.disconnect.addEventListener(`click`,()=>{L.close(),h.listenOnly.hidden=!0,ke=-1,h.sharePanel.hidden=!0,h.publishPanel.hidden=!0,h.adminPanel.hidden=!0,h.catalogsPanel.hidden=!0,w(h.catalogsPanel,`data-title`,()=>v(`Catalogs on this server`)),b=``,we=``,ci(),Xo(!1),y=`local`,Ee=`idle`,De=``,U()});async function Ko(){if(y!==`remote`||L.shareLink===``){h.sharePanel.hidden=!0;return}h.sharePanel.hidden=!1;let e=ds(),t=globalThis.location.origin;h.shareLink.value=e===``?``:e.startsWith(`https://`)?`${t}/?url=${encodeURIComponent(e)}`:e,h.shareNote.textContent=`Anyone with this link can watch. They sign in once, then it opens.`,h.sharePhone.hidden=!0,h.shareSend.hidden=!0,h.liveControls.hidden=!0;let n=``;try{let e=await r(`/api/directory`);e.ok&&(n=(await e.json()).callIn??``)}catch{}ht=n,Tn();let i=null;try{let n=await r(L.url(`/api/live/state`));n.ok&&(i=await n.json()),i?.url&&(e=i.url,we=i.url,h.shareLink.value=e.startsWith(`https://`)?`${t}/?url=${encodeURIComponent(e)}`:e)}catch{}i&&(ut=i.live,ft=i.live?i.code:``,ht=n,h.liveControls.hidden=h.adminPanel.hidden||!i.possible,h.goLive.hidden=i.live,h.stopLive.hidden=!i.live,h.sharePhone.hidden=!1,i.live?n?(h.sharePhone.replaceChildren(document.createTextNode(`To talk about it, call `),_s(n),document.createTextNode(` and key `),_s(i.code),document.createTextNode(`. That is a room with everyone else watching — not the stream itself.`)),h.shareSend.hidden=!1):(h.sharePhone.textContent=`Listed. The code for the phone line is ${i.code}.`,h.shareSend.hidden=!1):h.sharePhone.textContent=i.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.`)}let qo=null,Jo=null,Yo=0,Xo=e=>{qo&&clearInterval(qo),qo=null,Yo+=1,Jo?.abort(),Jo=null,j=null,Zr(),e&&(Zo(),qo=setInterval(()=>{document.visibilityState===`visible`&&Zo()},Qr))};async function Zo(){if(y!==`remote`||Jo)return;let e=new AbortController;Jo=e;let t=j===null;t&&ei(e,!0);let n=Yo,i=L.url(`/api/streams`),a=setTimeout(()=>e.abort(),8e3);try{let t=await r(i,{signal:e.signal,cache:`no-store`});if(!t.ok)return;let a=await t.json();if(e.signal.aborted||n!==Yo||y!==`remote`||i!==L.url(`/api/streams`))return;me=a.server.carries!==!1,a.server.name&&a.server.name!==b&&(b=a.server.name,h.catalogsPanel.setAttribute(`data-title`,`Catalogs on ${b}`),ci()),j=a,fs(a),U(),Qo(a)}catch{}finally{clearTimeout(a),t&&ei(e,!1),Jo===e&&(Jo=null)}}function Qo(e){Zr(),O&&cr()}function $o(e){let t=vn(),n=e.restreams??[],r=[],i=e.server.playing,a=!h.adminPanel.hidden;i&&r.push(ps({key:`live`,title:Ve(e.server.nowPlaying)||e.server.name,detail:[i?`playing ${t.fullTitle}`:e.server.nowPlaying?`stopped on ${Ve(e.server.nowPlaying)}`:`nothing loaded`,i&&t.position?t.position:`${e.server.tracks} track${e.server.tracks===1?``:`s`}`,e.server.code?`☎ ${e.server.code}`:`not listed`].join(` · `),playLabel:`Join party`,onPlay:()=>{i&&ts(e.server.nowPlaying)},link:e.server.live?e.server.url:``,...i?{page:us(`live`)}:{},direct:i?L.url(`/api/live`):``}));for(let e of n)r.push(ps({key:`restream:${e.at}`,title:e.name,detail:e.tracks===1?`re-streamed from the web`:`re-streamed from the web · ${e.tracks} tracks`,onPlay:()=>{kn(e.at)},link:``,direct:L.media(e.at,0,!0)}));for(let t of e.channels){let e=t.kind!==`audio`,n=L.url(`/api/channels/${encodeURIComponent(t.id)}`),i=[t.via===`pull`?`on the air · ${t.listeners} watching`:`live over ${t.via} · ${t.listeners} listening`];t.code&&i.push(`☎ ${t.code}`),t.redials&&i.push(`redialled ${t.redials}×`),a&&t.error&&i.push(t.error),r.push(ps({key:`channel:${t.id}`,title:t.name,detail:i.join(` · `),onPlay:()=>{ns({id:t.id,name:t.name,video:e,art:t.art,playlist:t.playlist})},link:n,page:us(`channel:${t.id}`),direct:n,onRestart:(a||jt&&Y!==``&&t.startedBy===Y)&&t.via===`pull`?()=>{as(t.id,t.name)}:void 0,onStop:a||jt&&Y!==``&&t.startedBy===Y?()=>ss(t.id,t.name):void 0,onRename:a||jt&&Y!==``&&t.startedBy===Y?()=>{os(t.id,t.name)}:void 0}))}return r}async function es(){if(y===`remote`)try{if((await r(L.media(z(),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===``&&h.accountPanel.scrollIntoView({behavior:`smooth`,block:`center`}),U()}catch{}}async function ts(e){ke=-1,O=null,A={kind:`live`},it(e,`auto`),await Ge(()=>I.load({title:e||`Live`,artist:``,album:``,duration:0,url:L.url(`/api/live`),video:!0,objectUrl:!1},!0)),hr(!0),D=`Watching what this server is playing. Everyone here sees the same thing.`,U()}async function ns(e,t=!0,n){let r=j?.channels.find(t=>t.id===e.id);!e.playlist&&r?.playlist&&(e={...e,playlist:r.playlist}),ke=-1,O=e,t&&(Ie=0),t&&(A=n??{kind:`channel`}),t&&it(e.name,A?.link||xn(e.name)?`auto`:`channel`);let i=e.video&&F(),a=e.video&&((e.playlist?.length??0)>1||e.id.startsWith(`folder-`));await Ge(()=>I.load({title:e.name,artist:``,album:``,duration:0,url:L.url(i||a?`/api/channels/${encodeURIComponent(e.id)}/hls/index.m3u8`:`/api/channels/${encodeURIComponent(e.id)}`),video:e.video,objectUrl:!1},!0)),hr(e.video),O===e&&(D=`Watching ${e.name}, live on this server.`),U()}function rs(){let e=O;return e?_t?!0:Ie>=5?(D=`${e.name} stopped, and did not come back.`,O=null,A=null,U(),!0):(Ie+=1,D=`${e.name} started over; rejoining…`,U(),_t=setTimeout(()=>{_t=null,O===e&&ns(e,!1)},2e3),!0):!1}function is(e){h.partiesNote.hidden=!1,h.partiesNote.textContent=e,G(e)}async function as(e,t){is(`Restarting ${t}…`);try{let n=await r(L.url(`/api/channels/${encodeURIComponent(e)}/restart`),{method:`POST`}),i=await n.json().catch(()=>({}));is(n.ok?`${t} is dialling its source again.`:i.error??`that did not work`)}catch{is(`could not reach the server`)}Zo()}async function os(e,t){let n=globalThis.prompt(`Call ${t}…`,t);if(n===null)return;let i=n.trim();if(i!==``&&i!==t){is(`Renaming ${t}…`);try{let n=await r(L.url(`/api/channels/${encodeURIComponent(e)}`),{method:`PATCH`,headers:{"content-type":`application/json`},body:JSON.stringify({name:i})}),a=await n.json().catch(()=>({}));is(n.ok?`${t} is now ${i}.`:a.error??`that did not work`)}catch{is(`could not reach the server`)}O?.id===e&&(O={...O,name:i}),Zo(),U()}}async function ss(e,t){is(`Taking ${t} off the air…`);try{let n=await r(L.url(`/api/channels/${encodeURIComponent(e)}`),{method:`DELETE`}),i=await n.json().catch(()=>({}));if(is(n.ok?`${t} is off the air.`:i.error??`that did not work`),!n.ok)return!1}catch{return is(`could not reach the server`),!1}return O?.id===e&&(O=null,I.stop()),!0}function cs(e,t,n,r){if(e.classList.contains(`removing`))return;t.disabled=!0,t.setAttribute(`aria-busy`,`true`);let i=document.createElement(`span`);i.className=`delete-spinner`,i.setAttribute(`role`,`status`),i.setAttribute(`aria-label`,`Removing`),i.textContent=``,t.after(i),n().then(n=>{n?(e.classList.add(`removing`),window.setTimeout(()=>{e.remove(),r?.()},260)):(i.remove(),t.disabled=!1,t.removeAttribute(`aria-busy`))}).catch(()=>{i.remove(),t.disabled=!1,t.removeAttribute(`aria-busy`)})}async function ls(e,t,n=`Copied`){if(!e)return;let r=t.innerHTML;try{await navigator.clipboard.writeText(e)}catch{D=e,U();return}n===`✓`||n===`✓`?g(t,`check`):C(t,()=>v(n)),setTimeout(()=>{t.innerHTML=r},1200)}function us(e,t=0){let n=ds();if(n===``)return``;let r=globalThis.location.origin,i=t>1?`&t=${Math.floor(t)}`:``;return`${r}/?url=${encodeURIComponent(n)}&play=${encodeURIComponent(e)}${i}`}function ds(){if(we!==``)return we;let e=y===`remote`?L.shareLink:``;return/\/admin\//.test(e)?``:e}function fs(e){if(x===``)return;let t=x;if(t===`live`){x=``,e.server.playing?ts(e.server.nowPlaying):(D=`Nothing is playing on this server right now.`,U());return}if(t.startsWith(`link:`)){x=``,_r(t.slice(5));return}if(t.startsWith(`golive:`)){x=``,h.linkUrl.value=t.slice(7),Br().then(()=>Tr());return}if(t.startsWith(`track:`)){x=``;let e=Number(t.slice(6));Number.isInteger(e)&&e>=0&&kn(e);return}let n=t.startsWith(`channel:`)?t.slice(8):``,r=e.channels.find(e=>e.id===n)??e.channels.find(e=>e.name===n);r&&(x=``,ns({id:r.id,name:r.name,video:r.kind!==`audio`,art:r.art}))}function ps(e){let t=document.createElement(`li`);t.className=`party-row`,t.dataset.liveKey=`${ge(L.address)}:${e.key}`;let 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(`span`);a.className=`onair-actions`;let o=document.createElement(`button`);o.type=`button`,o.className=`button`,Vt(o,e.playLabel??`Join party`),o.hidden=e.key.startsWith(`channel:`)&&O?.id===e.key.slice(8),o.addEventListener(`click`,e.onPlay),a.append(o);let s=(e,t,n)=>{let r=document.createElement(`button`);return r.type=`button`,r.className=`icon`,g(r,e),r.title=t,r.setAttribute(`aria-label`,t),r.addEventListener(`click`,()=>n(r)),r};(e.link||e.page)&&a.append(s(`link`,`Copy a link that opens this in the player`,t=>{let n=globalThis.location.origin;ls(e.page??(e.link.startsWith(`https://`)?`${n}/?url=${encodeURIComponent(e.link)}`:e.link),t,`✓`)})),e.direct&&a.append(s(`copy`,`Copy the stream's own URL, for VLC or mpv`,t=>{ls(e.direct??``,t,`✓`)})),e.onRestart&&a.append(s(`restart`,`Restart: dial the source again`,()=>e.onRestart?.())),e.onRename&&a.append(s(`rename`,`Rename: call it something better in the directory`,()=>e.onRename?.())),e.onStop&&a.append(s(`remove`,`Remove: take it off the air`,n=>{cs(t,n,e.onStop,()=>void Zo())})),n.className=`party-name`,n.title=`${e.title} · ${e.detail}`,i.hidden=!0,w(o,`aria-label`,()=>`${v(e.playLabel??`Join party`)}: ${e.title}`);let c=document.createElement(`details`);c.className=`party-actions`;let l=document.createElement(`summary`);return l.textContent=`⋯`,w(l,`aria-label`,()=>`${v(`Show more`)}: ${e.title}`),a.removeChild(o),c.append(l,a),t.append(n,o),a.childElementCount&&t.append(c),t}let ms=``;function hs(e,t){ms=e;let n=e!==``&&t===e;h.loadHome.hidden=e===``,h.homeNote.hidden=e===``,e!==``&&(h.homeNote.textContent=n?`This server's own files: ${e}`:`This server's own files are ${e}, and are not in the playlist.`,h.loadHome.disabled=!1)}h.loadHome.addEventListener(`click`,()=>{ms!==``&&(h.loadHome.disabled=!0,G(`Reading this server's files…`),(async()=>{try{let e=await r(L.url(`/api/source`),{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({source:ms})}),t=await e.json();G(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{G(`could not reach the server`)}finally{h.loadHome.disabled=!1}})())});let gs=async e=>{h.goLive.disabled=!0,h.stopLive.disabled=!0,h.shareNote.textContent=e?`Going live…`:`Taking it off the list…`;try{let t=await r(L.url(e?`/api/live/start`:`/api/live/stop`),{method:`POST`}),n=await t.json();h.shareNote.textContent=t.ok?e?`Live. Anyone can call and key ${n.code??``} to talk about it.`:`Taken off the list. The link still works for anybody who has it.`:n.error??`that did not work`}catch{h.shareNote.textContent=`could not reach the server`}finally{h.goLive.disabled=!1,h.stopLive.disabled=!1,await Ko()}};h.goLive.addEventListener(`click`,()=>void gs(!0)),h.stopLive.addEventListener(`click`,()=>void gs(!1));function _s(e){let t=document.createElement(`b`);return t.textContent=e,t}h.shareCopy.addEventListener(`click`,()=>{h.shareLink.select(),navigator.clipboard?.writeText(h.shareLink.value).then(()=>{h.shareNote.textContent=`Copied. Send it to anybody.`},()=>{h.shareNote.textContent=`Copy it from the box above.`})}),h.shareSend.addEventListener(`submit`,e=>{e.preventDefault();let t=h.shareTo.value.trim();t!==``&&(async()=>{h.shareNote.textContent=`Sending…`;try{let e=await r(`/api/v1/invite`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({to:t,stream:ds()})}),n=await e.json();h.shareNote.textContent=e.ok?`Sent to ${n.sent??t}.`:n.error??`that did not send`,e.ok&&(h.shareTo.value=``)}catch{h.shareNote.textContent=`could not send that`}})()}),h.listenHere.addEventListener(`change`,()=>{try{localStorage.setItem(Un,h.listenHere.checked?`1`:`0`)}catch{}y===`remote`&&(async()=>{h.listenHere.checked?(await L.send({type:`stop`}),await Mn(E.index)):(I.stop(),ke=-1),U()})()}),document.addEventListener(`keydown`,e=>{let t=e.target;if(!(e.defaultPrevented||e.altKey||e.ctrlKey||e.metaKey||e.shiftKey)&&!t?.closest(`input, textarea, select, button, a, [contenteditable], [role=button]`)&&t===h.transport)switch(e.key){case` `:e.preventDefault(),Nn();return;case`s`:Fn();return;case`n`:case`ArrowRight`:Pn(1);return;case`p`:case`ArrowLeft`:Pn(-1);return;case`ArrowDown`:e.preventDefault(),kn(Math.min(R()-1,z()+1));return;case`ArrowUp`:e.preventDefault(),kn(Math.max(0,z()-1));return}});let vs=null;globalThis.addEventListener(`beforeinstallprompt`,e=>{e.preventDefault(),vs=e,h.install.hidden=!1}),h.install.addEventListener(`click`,()=>{vs?.prompt(),vs=null,h.install.hidden=!0});try{let e=localStorage.getItem(Hn);e!==null&&(h.volume.value=String(Math.round(Number(e)*100)),I.volume=Number(e));let t=localStorage.getItem(Bn);t&&(h.remoteUrl.value=t),localStorage.getItem(Un)===`0`&&(h.listenHere.checked=!1)}catch{}(async()=>{if(h.remoteUrl.value!==``)return;let e=globalThis.location.origin;if(await te(e)===null)return;let t=await p(e);t&&t.trackCount!==0&&(h.remoteUrl.value=e,y=`remote`,D=``,L.connect(e),Xo(!0),Ga(),U())})(),ti();let ys=()=>{document.visibilityState===`visible`&&!h.partiesPanel.hasAttribute(`data-closed`)&&ti()},bs=setInterval(ys,Qr);document.addEventListener(`visibilitychange`,()=>{document.visibilityState===`visible`&&(ti(),Zo())}),globalThis.addEventListener(`pagehide`,()=>{clearInterval(bs),qo&&clearInterval(qo),Yr?.abort(),Jo?.abort(),Yr=null,Jo=null,Yo+=1}),globalThis.addEventListener(`pageshow`,e=>{e.persisted&&(clearInterval(bs),bs=setInterval(ys,Qr),ys(),y===`remote`&&Xo(!0))}),(()=>{if(Gn||bt!==``)return;let e=()=>I.source!==``||I.playing||He()||O!==null,t=async()=>{try{let e=await(await r(`/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``},i=new Audio;i.volume=.7;let a=()=>{Gn=!0},o=()=>{document.removeEventListener(`pointerdown`,o),document.removeEventListener(`keydown`,o),a(),setTimeout(()=>{e()||I.playJingle(i).catch(()=>{})},150)};t().then(async t=>{if(!(t===``||e()))return await n(i,{src:t,kind:`audio`}),I.playJingle(i).then(a,()=>{document.addEventListener(`pointerdown`,o,{once:!0}),document.addEventListener(`keydown`,o,{once:!0})})})})(),U(),requestAnimationFrame(fr)}Yn(),Oe(),Fe(),`serviceWorker`in navigator&&globalThis.addEventListener(`load`,()=>{navigator.serviceWorker.register(`/sw.js`).catch(()=>{})});export{oe as t};
|
|
33
|
+
`)}\n</fieldset>`}`${JSON.stringify([...An])}`;function zn(e,t){if(e.dataset.longStringScroller===`true`)return;e.dataset.longStringScroller=`true`,e.classList.add(`long-string-scroller`),t.classList.add(`long-string-scroller-content`),t.title=t.textContent??``;let n=0,r=0,i=0,a=!1,o=null,s=()=>{n=0;let c=matchMedia(`(prefers-reduced-motion: reduce)`).matches?r:i+(r-i)*.22;i=Math.abs(r-c)<.5?r:c,t.style.setProperty(`--path-shift`,`${i}px`),Math.abs(r-i)>=.5?n=requestAnimationFrame(s):a&&(a=!1,delete t.dataset.pan,t.style.removeProperty(`--path-shift`),o=setTimeout(()=>{o=null,e.style.removeProperty(`min-height`)},280))},c=()=>{n||=requestAnimationFrame(s)};e.addEventListener(`pointerenter`,n=>{n.pointerType===`mouse`&&matchMedia(`(hover: hover) and (pointer: fine)`).matches&&(o!==null&&(clearTimeout(o),o=null),e.style.minHeight=`${e.getBoundingClientRect().height}px`,a=!1,t.dataset.pan=`true`)}),e.addEventListener(`pointermove`,n=>{if(t.dataset.pan!==`true`)return;let i=getComputedStyle(e),a=parseFloat(i.paddingLeft)+parseFloat(i.paddingRight),o=Math.max(0,t.scrollWidth-(e.clientWidth-a));if(o<=0)return;let s=e.getBoundingClientRect(),l=Math.max(0,Math.min(1,(n.clientX-s.left)/Math.max(1,s.width)));if(l<=.02)r=0;else if(l>=.98)r=-o;else{let e=l*l*(3-2*l);r=-o*e}c()}),e.addEventListener(`pointerleave`,()=>{r=0,a=!0,c()})}var Bn=`nixamp.remote`,Vn=`nixamp.defaultServer`,Hn=`nixamp.volume`,Un=`nixamp.listenHere`,Wn=1e4,Gn=!1,Kn=[`first_name`,`last_name`,`company_domain`,`job_title`,`linkedin_url`];function qn(e){let t=e.querySelector(`[data-pfs-openprofile-import]`);if(!t||t.dataset.pfsBound)return;let n=t.querySelector(`[data-pfs-openprofile-url]`),r=t.querySelector(`[data-pfs-openprofile-button]`),i=t.querySelector(`[data-pfs-openprofile-status]`);n&&r&&i&&(t.dataset.pfsBound=`1`,n.addEventListener(`input`,()=>{r.disabled=!n.value.trim()}),r.addEventListener(`click`,async()=>{r.disabled=!0,r.textContent=`Fetching…`,i.textContent=``,i.setAttribute(`role`,`status`);try{let e=new URL(n.value.trim());if(e.protocol!==`https:`)throw Error(`Use an HTTPS OpenProfile URL.`);let r=new URL(t.dataset.endpoint||`/api/v1/me/profile/fields`,location.href);r.searchParams.set(`openprofile`,e.href);let a=await fetch(r,{credentials:`same-origin`,cache:`no-store`}),o=await a.json().catch(()=>({}));if(!a.ok)throw Error(o.error||`Could not fetch that OpenProfile.md.`);let s=t.closest(`form`),c=0;for(let[e,t]of Object.entries(o.profile||{})){if(typeof t!=`string`||!t.trim())continue;let n=s?.elements.namedItem(e);n instanceof HTMLInputElement&&(n.value=t,n.dispatchEvent(new Event(`input`,{bubbles:!0})),n.dispatchEvent(new Event(`change`,{bubbles:!0})),c++)}if(!c)throw Error(`No contact details were found in that OpenProfile.md.`);i.textContent=`Fetched. Review or edit the fields before saving.`}catch(e){i.textContent=e instanceof Error?e.message:`Could not fetch that OpenProfile.md.`,i.setAttribute(`role`,`alert`)}finally{r.textContent=`Fetch and prefill`,r.disabled=!n.value.trim()}}))}function Jn(e){let t={};for(let n of Kn){let r=e.elements.namedItem(n);r instanceof HTMLInputElement&&(t[n]=r.value.trim())}return t}function H(e){let t=document.getElementById(e);if(!t)throw Error(`nixamp: #${e} is missing from the shell`);return t}function Yn(){let e=new URLSearchParams(location.search).get(`embed`)===`1`,t=``;function r(e,n){let r=new URL(e instanceof Request?e.url:String(e),location.href);if(!t||r.origin!==location.origin||!r.pathname.startsWith(`/api/v1/`))return globalThis.fetch(e,n);let i=new Headers(n?.headers??(e instanceof Request?e.headers:void 0));return i.set(`authorization`,`Bearer ${t}`),globalThis.fetch(e,{...n,headers:i})}document.body.classList.toggle(`classroom-embed`,e);let oe=null;try{oe=localStorage.getItem(mt)}catch{}let se=gt(navigator.userAgent,location.search,navigator.maxTouchPoints,oe);if(document.body.classList.toggle(`tv`,se),new URLSearchParams(location.search).has(`tv`))try{localStorage.setItem(mt,se?`1`:`0`)}catch{}let ce=document.getElementById(`tv-toggle`);ce&&(C(ce,()=>se?`TV mode: on`:v(`TV mode`)),ce.title=se?`Back to the ordinary layout: lists with their own scrollbars, smaller type.`:`For a television: bigger type, lists a page at a time, and nothing to scroll but the page.`,ce.addEventListener(`click`,()=>{try{localStorage.setItem(mt,se?`0`:`1`)}catch{}let e=new URL(location.href);e.searchParams.delete(`tv`),location.replace(e.toString())}));let le=vt(se),h={status:H(`status`),source:H(`source`),install:H(`install`),video:H(`video`),audio:H(`audio`),title:H(`title-line`),album:H(`album-line`),meta:H(`meta-line`),metaBlurb:H(`meta-blurb`),liveLine:H(`live-line`),downloadNow:H(`download-now`),wayInHere:H(`way-in-here`),embed:H(`embed`),embedFrame:H(`embed-frame`),linkForm:H(`link-form`),linkUrl:H(`link-url`),linkServer:H(`link-server`),linkGoLive:H(`link-go-live`),goLiveNow:H(`go-live-now`),elapsed:H(`elapsed`),total:H(`total`),seek:H(`seek`),fullscreen:H(`fullscreen`),copyNow:H(`copy-now`),copyNixamp:H(`copy-nixamp`),schoolLive:H(`school-live`),streamingLive:H(`streaming-live`),streamingPublish:H(`streaming-publish`),canvas:H(`spectrum`),glyphs:H(`glyphs`),levels:H(`levels`),playlist:H(`playlist`),livePlaylist:H(`live-playlist`),livePlaylistPanel:H(`live-playlist-panel`),playlistPager:H(`playlist-pager`),crumbs:H(`crumbs`),filter:H(`filter`),playlistTitle:H(`playlist-panel`),note:H(`note`),linkNote:H(`link-note`),logList:H(`log-list`),files:H(`files`),folder:H(`folder`),remoteUrl:H(`remote-url`),remoteServer:H(`remote-server`),remoteForm:H(`remote-form`),remoteState:H(`remote-state`),disconnect:H(`disconnect`),browse:H(`browse`),panelsToggle:H(`panels-toggle`),panelsPanel:H(`panels-panel`),panelsList:H(`panels-list`),panelsSave:H(`panels-save`),panelsReset:H(`panels-reset`),accountForm:H(`account-form`),accountEmail:H(`account-email`),accountPassword:H(`account-password`),accountSubmit:H(`account-submit`),accountToggle:H(`account-toggle`),accountForgot:H(`account-forgot`),accountProviders:H(`account-providers`),accountPanel:H(`account-panel`),accountElsewhere:H(`account-elsewhere`),adnet:H(`adnet`),welcome:H(`welcome`),welcomeCreate:H(`welcome-create`),welcomeBrowse:H(`welcome-browse`),welcomeHide:H(`welcome-hide`),accountSignOut:H(`account-signout`),accountNote:H(`account-note`),personaForm:H(`persona-form`),personaHandle:H(`persona-handle`),personaVoice:H(`persona-voice`),personaProfile:H(`persona-profile`),personaNote:H(`persona-note`),accountProfile:H(`account-profile`),contactForm:H(`contact-form`),contactFields:H(`contact-fields`),contactNote:H(`contact-note`),adminPanel:H(`admin-panel`),adminNote:H(`admin-note`),adminSaid:H(`admin-said`),adminConnections:H(`admin-connections`),publishPanel:H(`publish-panel`),publishNote:H(`publish-note`),publishList:H(`publish-list`),adminRestream:H(`admin-restream`),adminReplace:H(`admin-replace`),adminSource:H(`admin-source`),adminName:H(`admin-name`),adminAdd:H(`admin-add`),homeNote:H(`home-note`),loadHome:H(`load-home`),directory:H(`directory`),recentNote:H(`recent-note`),recentList:H(`recent-list`),followingNote:H(`following-note`),followingList:H(`following-list`),serversPanel:H(`servers-panel`),serversNote:H(`servers-note`),serversList:H(`servers-list`),favoritesPanel:H(`favorites-panel`),favoritesNote:H(`favorites-note`),favoritesList:H(`favorites-list`),favHere:H(`fav-here`),partyRoom:H(`party-room`),partyTitle:H(`party-title`),partyMeta:H(`party-meta`),partyRoomNote:H(`party-note`),partyWatch:H(`party-watch`),partyCopy:H(`party-copy`),partyEnd:H(`party-end`),partyChat:H(`party-chat`),partyChatForm:H(`party-chat-form`),partyChatInput:H(`party-chat-input`),partyChatSend:H(`party-chat-send`),partyChatNote:H(`party-chat-note`),partiesPanel:H(`parties-panel`),partiesNote:H(`parties-note`),partiesList:H(`parties-list`),partyForm:H(`party-form`),partyCode:H(`party-code`),partyJoin:H(`party-join`),connectionsNote:H(`connections-note`),connectionsList:H(`connections-list`),catalogsPanel:H(`catalogs-panel`),catalogsNote:H(`catalogs-note`),catalogsForm:H(`catalogs-form`),catalogSource:H(`catalog-source`),catalogName:H(`catalog-name`),catalogsList:H(`catalogs-list`),catalogsCrumbs:H(`catalogs-crumbs`),catalogsFilter:H(`catalogs-filter`),catalogsEntries:H(`catalogs-entries`),notifyPanel:H(`notify-panel`),notifyNote:H(`notify-note`),notifyWeb:H(`notify-web`),notifyEmail:H(`notify-email`),notifySms:H(`notify-sms`),notifyPhone:H(`notify-phone`),notifyPhoneForm:H(`notify-phone-form`),notifyPhoneNote:H(`notify-phone-note`),directoryNote:H(`directory-note`),directoryList:H(`directory-list`),sharePanel:H(`share-panel`),trollboxPanel:H(`trollbox-panel`),trollboxNote:H(`trollbox-note`),trollboxList:H(`trollbox-list`),trollboxForm:H(`trollbox-form`),trollboxInput:H(`trollbox-input`),trollboxMic:H(`trollbox-mic`),trollboxEdit:H(`trollbox-edit`),trollboxEditLabel:H(`trollbox-edit-label`),transcriptPanel:H(`transcript-panel`),transcriptNote:H(`transcript-note`),transcriptOn:H(`transcript-on`),transcriptLanguage:H(`transcript-language`),transcriptAudio:H(`transcript-audio`),transcriptVoiceSettings:H(`transcript-voice-settings`),transcriptBackground:H(`transcript-background`),transcriptBackgroundLevel:H(`transcript-background-level`),transcriptBackgroundValue:H(`transcript-background-value`),transcriptAudioNote:H(`transcript-audio-note`),transcriptSpeakers:H(`transcript-speakers`),transcriptList:H(`transcript-list`),subtitle:H(`subtitle`),shareNote:H(`share-note`),shareLink:H(`share-link`),shareCopy:H(`share-copy`),sharePhone:H(`share-phone`),shareSend:H(`share-send`),liveControls:H(`live-controls`),goLive:H(`go-live`),stopLive:H(`stop-live`),shareTo:H(`share-to`),listenOnly:H(`listen-only`),listenHere:H(`listen-here`),volume:H(`volume`),volumeToggle:H(`volume-toggle`),prev:H(`prev`),playPause:H(`play-pause`),transport:H(`transport`),stop:H(`stop`),next:H(`next`),shareNow:H(`share-now`),refreshPlayer:H(`refresh-player`),appVersion:H(`app-version`)};h.appVersion.textContent=`nixamp 0.80.2`,h.accountProfile.innerHTML=Rn({fields:[...Kn],idPrefix:`account-`}),h.contactFields.innerHTML=Rn({fields:[...Kn],idPrefix:`contact-`,importOpenProfile:!0,importEndpoint:`/api/v1/me/profile/fields`}),qn(h.contactFields);let g=(e,t)=>{Ae(e,t)};g(h.copyNixamp,`link`);let ue=document.createElement(`a`);if(ue.className=`button`,ue.href=`#account-panel`,ue.hidden=!0,C(ue,()=>v(`Sign in`)),h.trollboxNote.after(ue),e){let e=document.createElement(`div`);e.className=`classroom-caption-controls`,e.append(h.transcriptOn.closest(`label`),h.transcriptLanguage.closest(`label`)),h.transcriptPanel.prepend(e),h.transcriptPanel.classList.remove(`panel`,`col-b`),h.transcriptPanel.hidden=!1,document.querySelector(`.classroom-player`).append(h.transcriptPanel),document.querySelector(`#app`).append(h.trollboxPanel);let t=document.createElement(`dialog`);t.className=`classroom-sign-in`,w(t,`aria-label`,()=>v(`Sign in`));let n=document.createElement(`button`);n.type=`button`,n.className=`button`,C(n,()=>v(`Close`)),n.addEventListener(`click`,()=>t.close()),h.accountPanel.classList.remove(`panel`,`col-a`),t.append(n,h.accountPanel),document.body.append(t),ue.addEventListener(`click`,e=>{e.preventDefault(),t.showModal()}),t.addEventListener(`close`,()=>{(ue.hidden?h.trollboxList:ue).focus({preventScroll:!0})})}let de=document.querySelector(`meta[name="nixamp-shell-title"]`)?.content||document.title||`nixamp`,y=`local`,b=``,fe=[],pe=``,me=!0,he=``;function ge(e){try{return new URL(e).origin}catch{return e}}let _e=!1,ve=globalThis.location?.search??``,x=``,be=0,xe=new Map,Se=e=>xe.get(K(e))??null;function S(e,t){let n=n=>{_e=n,x=``,h.remoteUrl.value=n?e.view:e.admin??e.view,t?.(),h.remoteForm.requestSubmit()},r=document.createElement(`button`);r.type=`button`,r.className=`icon way-in`,g(r,`eye`),r.title=`Viewer: browse and watch. Changes nothing on the server.`,r.setAttribute(`aria-label`,`View ${e.name}`),r.addEventListener(`click`,()=>n(!0));let i=document.createElement(`button`);return i.type=`button`,i.className=`icon way-in`,g(i,`gear`),i.disabled=e.admin===null,i.title=e.admin?`Admin: drive this server. What plays, what is live, what is on it.`:Y?`Admin: you do not administer this server.`:`Admin: sign in as this server's owner to administer it.`,i.setAttribute(`aria-label`,`Administer ${e.name}`),i.addEventListener(`click`,()=>n(!1)),[r,i]}let we=``,T=[],Te=0,E=ae(),Ee=`idle`,De=``,D=`Pick files, or connect to a nixamp running somewhere else.`,Oe=!1,ke=-1,Ne=null,Pe=0,O=null;function Fe(e){return e?/^https?:\/\//i.test(e)?e:L.url(e):``}let Ie=0,Re=0,ze=!1,He=()=>!I.needsInteraction&&(Re>0||ze);async function Ge(e){Re+=1,U();try{return await e()}finally{--Re,U()}}let A=null,j=null,Ke=``,qe=null,Je=``,M=null,Xe=null,Qe=0;function $e(){h.embed.hidden||(h.embedFrame.src=`about:blank`),h.embed.hidden=!0}let et=null,nt=``,rt=null;function it(e,t,n=null,i=!1){let a=`${t}|${e}`;if(nt=a,rt&&clearTimeout(rt),rt=null,!i){if(et?.key===a)return;et=null}if(y!==`remote`||e.trim()===``)return;let o=new URLSearchParams({name:e,kind:t});n&&o.set(`year`,String(n)),r(L.url(`/api/enrich?${o}`)).then(e=>e.ok?e.json():{match:null}).then(r=>{if(nt!==a)return;et={key:a,match:r.match??null},U();let i=et.match;i?.kind===`fixture`&&dt(i)!==`post`&&(rt=setTimeout(()=>{rt=null,!(nt!==a||I.source===``&&!O)&&it(e,t,n,!0)},6e4))}).catch(()=>void 0)}let ut=!1,ft=``,ht=``,_t=null,bt=``,xt=``,St=``,N=Array(24).fill(0),wt=Array(24).fill(0),Et=[],P=()=>y===`remote`&&!h.listenHere.checked,At=()=>y===`remote`&&!h.adminPanel.hidden,jt=!1,Lt=()=>At()||y===`remote`&&jt;function F(){try{if(localStorage.getItem(`nixamp.hls`)===`1`)return!0}catch{}return typeof MediaSource<`u`?!1:h.video.canPlayType(`application/vnd.apple.mpegurl`)!==``}function Rt(){if(y!==`remote`||M)return null;if(A?.catalog&&A.entry)return{kind:`entry`,catalog:A.catalog,entry:A.entry};if(O)return{kind:`channel`,id:O.id,name:O.name};let e=E.tracks[z()];return e&&(I.source!==``||P())?{kind:`track`,index:z(),name:bn(e)}:null}async function Bt(e,t){t.disabled=!0;let n=e.kind===`entry`?e.entry.title:e.name;D=`Putting ${n} on the air…`,U();try{let i=``,a=``,o=!0;{let t=e.kind===`folder`?`/api/folders/live`:e.kind===`track`?`/api/tracks/${e.index}/live`:e.kind===`entry`?`/api/catalogs/${encodeURIComponent(e.catalog.id)}/entries/${encodeURIComponent(e.entry.id)}/live`:`/api/channels/${encodeURIComponent(e.id)}/keep`,s=await r(L.url(t),{method:`POST`,...e.kind===`folder`?{headers:{"content-type":`application/json`},body:JSON.stringify({indices:e.indices,name:e.name})}:{}}),c=await s.json().catch(()=>({}));if(!s.ok){D=s.status===404&&e.kind===`folder`?`This server needs an update before folders can go live.`:c.error??`${n} would not go on the air.`,U();return}a=e.kind===`channel`?e.id:c.channel??``,o=c.video!==!1,i=`channel:${a}`}if(At()&&(ut?await r(L.url(`/api/live/start`),{method:`POST`}).catch(()=>void 0):await gs(!0)),await Ko(),Zo(),a!==``&&O?.id!==a){let t=e.kind===`entry`?{kind:`channel`,catalog:e.catalog,entry:{id:e.entry.id,title:e.entry.title,group:e.entry.group??``,live:e.entry.live??!0,...e.entry.logo?{logo:e.entry.logo}:{}}}:void 0;await ns({id:a,name:n,video:o},!0,t)}let s=us(i),c=ft?` Call ${ht||`the line`} and key ${ft} to talk about it.`:``;s===``?D=`${n} is on the air and you are watching it.${c}`:(await ls(s,t,`✓`),D=`${n} is on the air and you are watching it. Link copied.${c}`),U()}catch{D=`could not reach the server`,U()}finally{t.disabled=!1}}function Vt(e,t=`Join party`){g(e,/join/i.test(t)?`party`:`live`);let n=document.createTextNode(``);C(n,()=>` ${v(t)}`),e.append(n),w(e,`title`,()=>v(/join/i.test(t)?`Join live`:t))}Vt(h.partyJoin);function nn(e,t){let n=document.createElement(`button`);return n.type=`button`,n.className=`row-copy row-live`,g(n,`live`),n.title=`Go live with ${t}: on the air for everyone, listed, link copied`,n.setAttribute(`aria-label`,`Go live with ${t}`),n.addEventListener(`click`,t=>{t.stopPropagation(),Bt(e(),n)}),n}let rn=0,an=0,on=0,sn=null;function cn(e){let t=performance.now(),n=!I.adPlaying&&I.playing;n&&on>0&&t-on<2e3&&(an+=(t-on)/1e3),on=n?t:0,rn>0&&(e<=0||I.showingVideo)&&an>=rn&&(an=0,I.playAdNow())}function ln(){return new Promise(e=>{let t=()=>{sn=null,clearTimeout(n),e()},n=setTimeout(t,9e4);sn=t,I.playAdNow().then(()=>{I.adPlaying||t()},t)})}function dn(){rs()||br()||An()||y===`remote`&&ke<0&&!P()||Pn(1)}let I=new tt({audio:h.audio,video:h.video},{readable:e=>L.owns(e),onTime:(e,t)=>{let n=T[Te];y===`local`&&n&&t>0&&n.duration!==t&&(n.duration=t),cn(t),U()},onEnded:()=>{rn>0&&an>=rn&&I.duration>0?(an=0,ln().then(dn)):dn()},onState:()=>U(),onBusy:e=>{ze!==e&&(ze=e,U())},onError:e=>{if(!rs()&&!(Qe!==0&&Date.now()-Qe<2e3)){if(Xe&&e===`this browser cannot play that format`){let e=Xe.url;if(Xe=null,Qe=Date.now(),Lt()){D=`That site will not let a page play it directly; going live with it on ${b||`the server`} instead.`,U(),h.linkUrl.value=e,Tr();return}D=`That site will not let a page play it directly. Pick a server beside the link and press Go live: the server carries it.`,U()}else D=e,U(),es()}}}),pn=h.video.closest(`section`)??h.video.parentElement;pn&&(async()=>{let e=!1;try{e=(await r(`${location.hostname===`nixamp.com`?``:`https://nixamp.com`}/api/v1/me/pass`,{credentials:`include`,cache:`no-store`,signal:AbortSignal.timeout(3e3)})).ok}catch{}let t=await Ce(e?{paid:!0}:{},ve);if(rn=t?.everySeconds??0,I.enableAds(pn,t&&{...t,everySeconds:31536e3,onBreakEnd:e=>{t.onBreakEnd?.(e),sn?.()}}),ye(ve)){let e=()=>{pn.scrollIntoView({block:`center`}),I.playAdNow()};addEventListener(`pointerdown`,e,{once:!0}),addEventListener(`keydown`,e,{once:!0})}})();let mn=()=>P()&&!I.jinglePlaying,L=new ie({onSnapshot:e=>{let t=e.tracks!==void 0||E.index!==e.index;if(E=f(E,e),x.startsWith(`track:`)&&E.tracks.length>0){let e=Number(x.slice(6));if(x=``,Number.isInteger(e)&&e>=0&&e<E.tracks.length){let t=be;Mn(e).then(()=>{t>0&&(I.seek(t),setTimeout(()=>I.seek(t),600))})}}mn()&&(N=e.bars.length>0?e.bars:N,wt=ct(wt,N)),U(),t&&j&&Qo(j)},onStatus:(e,t)=>{Ee=e,De=t??``,U()}}),R=()=>y===`remote`?E.tracks.length:T.length,z=()=>y===`remote`?P()||ke<0?E.index:Math.min(ke,Math.max(0,E.tracks.length-1)):Te,vn=()=>{let e=j?.server.nowPlaying||`Live`;return qe&&qe.tracks===E.tracks&&qe.index===E.index&&qe.fallback===e||(qe={tracks:E.tracks,index:E.index,fallback:e,value:Ue(E.tracks,E.index,e)}),qe.value},B=()=>y===`remote`&&!O&&A?.kind===`live`,yn=()=>B()?vn().fullTitle:Sn(),bn=e=>{let t=Me(e);return e.folder?`${e.folder} / ${t}`:t},Sn=()=>{if(O){let e=O.id,t=j?.channels.find(t=>t.id===e);return t?.playlist?.[t.entry??0]||O.name}if(M)return M.label;if(B())return vn().title;let e=y===`remote`?E.tracks[z()]:T[z()];return e?bn(e):v(`Nothing loaded.`)},Cn=()=>{if(O)return`live on this server`;if(M)return`playing here, in this browser`;if(B()){let{context:e,position:t}=vn();return[e,t,`live on ${b||`this server`}`].filter(Boolean).join(` · `)}return(y===`remote`?E.tracks[z()]:T[z()])?.album||`—`},wn=()=>{if(!O&&!M&&!B()){let e=y===`remote`?E.tracks[z()]:T[z()];if(e?.artist)return e.artist}return b||`nixamp`};function Tn(){if(y!==`remote`||O===null&&A?.kind!==`live`){h.liveLine.hidden=!0,h.liveLine.replaceChildren(),delete h.liveLine.dataset.drawn;return}let e=b||`this server`,t=O?O.name:vn().fullTitle,n=[O?`Live on ${e}: `:`Live from ${e}, now playing: `,_s(t)],r=O?j?.channels.find(e=>e.id===O?.id)?.code??``:ut?ft:``;if(r){let e=ht?document.createElement(`a`):_s(`the line`);ht&&(e.textContent=ht,e.setAttribute(`href`,`tel:${ht.replace(/[^+\d]/g,``)}`)),n.push(`. To talk about it, call `,e,` and key `,_s(r),`.`)}let i=n.map(e=>typeof e==`string`?e:e.textContent).join(``);h.liveLine.dataset.drawn!==i&&(h.liveLine.dataset.drawn=i,h.liveLine.hidden=!1,h.liveLine.replaceChildren(...n.map(e=>typeof e==`string`?document.createTextNode(e):e)))}let En=()=>P()?E.tracks[z()]?.duration??0:I.duration,Dn=()=>P()?E.position:I.position,On=()=>P()?E.playing:I.playing;async function kn(e){if(y===`remote`){if(P()){await L.send({type:`play`,index:e});return}await Mn(e);return}let t=T[e];t&&(Te=e,O=null,A={kind:`file`},await Ge(()=>I.load(t,!0)),hr(t.video),gr(),U())}function An(){return!Ne||Ne.length<2?!1:(Pe=(Pe+1)%Ne.length,kn(Ne[Pe]),!0)}function jn(e){e.length!==0&&(Ne=[...e],Pe=0,kn(Ne[0]))}async function Mn(e){let t=E.tracks[e];t&&(ke=e,O=null,A={kind:`file`},it(t.title,`auto`),await Ge(()=>I.load({title:bn(t),artist:t.artist,album:t.album,duration:t.duration,url:L.media(e,0),video:t.video===!0,objectUrl:!1},!0)),hr(t.video===!0),gr())}async function Nn(){I.needsInteraction?(await I.play(),U()):P()?await L.send({type:`toggle`}):R()!==0&&(I.playing?I.pause():I.position>0?await I.play():await kn(z()),U())}async function Pn(e){Ne=null;let t=R();t!==0&&(P()?await L.send({type:e>0?`next`:`prev`}):await kn((z()+e+t)%t))}async function Fn(){Ne=null,$e(),M=null,Xe=null,P()?await L.send({type:`stop`}):(O=null,A=null,I.stop(),N=Array(24).fill(0),wt=[...N],U())}let In=(e,t)=>`L${`▮`.repeat(Math.round(e*6)).padEnd(6,`·`)} R${`▮`.repeat(Math.round(t*6)).padEnd(6,`·`)}`,Ln=e=>`▁▂▃▄▅▆▇█`[Math.max(0,Math.min(7,Math.round(e*7)))],V=``;function Yn(){let e=[],t=``,n=null,r=O?j?.channels.find(e=>e.id===O?.id):void 0;O&&r?.ended&&Je!==O.id&&(Je=O.id,li(`${O.name} has ended. What is playing is its outro; the room stays open for an hour, then the channel closes.`));let i=I.source===``&&!O&&!(P()&&E.tracks[z()]);if(!i){O&&r?.ended?e.push(`ENDED`):O?e.push(A?.entry?.live===!1?`ON DEMAND · LIVE CHANNEL`:`LIVE`):A?.kind===`vod`?e.push(`ON DEMAND`):A?.kind===`live`?e.push(`LIVE`):y===`remote`&&P()?e.push(`ON THE SERVER`):e.push(`FILE`),!h.video.hidden&&h.video.videoWidth>0?e.push(`${h.video.videoWidth}×${h.video.videoHeight}`):h.video.hidden?e.push(`audio`):e.push(`video`),r?(e.push(r.via===`pull`?`${r.listeners} watching`:`${r.listeners} listening · over ${r.via}`),r.startedAt>0&&e.push(`on air ${je(Math.max(0,(Date.now()-r.startedAt)/1e3))}`),r.redials&&e.push(`redialled ${r.redials}×`),At()&&r.error&&e.push(r.error)):y===`remote`&&!O?(E.tracks[z()]&&R()>0&&e.push(`${B()?`library track`:`track`} ${z()+1} of ${R()}`),P()&&j&&e.push(`${j.server.playing?`playing`:`stopped`} on ${b||`the server`}`)):y===`local`&&R()>0&&e.push(`track ${z()+1} of ${R()}`),A?.catalog!==void 0&&(A.kind===`channel`?O!==null:A.kind===`vod`&&I.source!==``)&&A?.catalog&&(e.push(A.entry?.group?`${A.catalog.name} › ${A.entry.group}`:A.catalog.name),t=A.entry?.logo??``),t===``&&O&&(t=Fe(r?.art??O.art));let i=et?.key===nt?et.match:null;if(i?.kind===`fixture`)n=pt(i),e.unshift(n.status,...n.chips);else if(i){i.image&&(t=i.image);let n=i.data;if(i.kind===`title`){i.year&&e.push(String(i.year));let t=typeof n.rating==`number`?n.rating:null;t&&e.push(`★ ${t.toFixed(1)}`);let r=Array.isArray(n.genres)?n.genres.slice(0,2).map(String):[];r.length&&e.push(r.join(` · `));let a=typeof n.runtimeMin==`number`?n.runtimeMin:0;a&&e.push(`${a} min`)}else if(i.kind===`channel`){let t=typeof n.country==`string`?n.country:``,r=Array.isArray(n.categories)?n.categories.slice(0,2).map(String):[],i=typeof n.network==`string`?n.network:``;t&&e.push(t),r.length&&e.push(r.join(` · `)),i&&e.push(i)}}if(O&&A?.link){let t=``;try{t=new URL(A.link.url).hostname.replace(/^www\./,``)}catch{}e.push(A.link.extractor&&A.link.extractor!==`direct`&&A.link.extractor!==`generic`?`${A.link.extractor} · ${t}`:t||`link`)}ut&&ft&&P()&&!O&&A?.kind!==`live`&&e.push(ht?`☎ ${ht} · key ${ft}`:`☎ code ${ft}`)}let a=et?.key===nt?et.match:null,o=!i&&!n&&a?.summary?a.summary:``,s=e.map(e=>/^on air \d/.test(e)?`on air`:e),c=`${t}|${n?`${n.away.logo}|${n.home.logo}|${n.text}`:``}|${s.join(`|`)}|${o}`;if(c===V){let t=h.meta.querySelector(`.meta-chip-clock`),n=e.find(e=>/^on air \d/.test(e));t&&n&&(t.textContent=n);return}V=c,h.meta.hidden=e.length===0,h.metaBlurb.textContent=o,h.metaBlurb.hidden=o===``;let l=[];if(n){let e=document.createElement(`div`);e.className=`meta-score`;let t=(e,t)=>{let r=[],i=document.createElement(`span`);if(i.className=`meta-team`,i.textContent=e.name,r.push(i),n?.state!==`pre`&&e.score!==null){let t=document.createElement(`b`);t.className=`meta-points`,t.textContent=String(e.score),r.push(t)}if(e.logo!==``){let n=document.createElement(`img`);n.className=`meta-team-logo`,n.alt=``,n.src=e.logo,n.addEventListener(`error`,()=>{n.hidden=!0}),t?r.unshift(n):r.push(n)}return r},r=document.createElement(`span`);r.className=`meta-dash`,r.textContent=`–`,e.replaceChildren(...t(n.away,!0),r,...t(n.home,!1)),l.push(e)}if(t!==``&&/^(https?:\/\/|\/api\/)/.test(t)){let e=document.createElement(`img`);e.className=a?.kind===`title`&&t===a.image?`meta-logo meta-poster`:`meta-logo`,e.alt=``,e.src=t,e.addEventListener(`error`,()=>{e.hidden=!0}),l.push(e)}for(let t of e){let e=document.createElement(`span`);e.className=/^on air \d/.test(t)?`meta-chip meta-chip-clock`:n?.state===`in`&&t===n.status?`meta-chip chip-live`:`meta-chip`,e.textContent=t,l.push(e)}h.meta.replaceChildren(...l)}function U(){let e=R(),t=On(),n=He();C(h.status,()=>v(n?`LOADING`:t?`▶ PLAYING`:`■ STOPPED`)),h.status.dataset.playing=n?`loading`:String(t),C(h.title,()=>Sn()),h.title.classList.toggle(`with-context`,B()),h.album.classList.toggle(`with-context`,B()),(B()||O)&&gr(),Tn(),Yn(),h.goLiveNow.hidden=!Lt()||O!==null||B()||Rt()===null;let r=t?`${yn()} · ${de}`:de;document.title!==r&&(document.title=r),h.copyNow.hidden=I.source===``,h.copyNixamp.hidden=ba()===``,h.schoolLive.hidden=xa()===``||!fo||Y===``,h.streamingLive.hidden=Ca()===``&&wa()===null||L.session===``,h.shareNow.hidden=ya()===``,Zi(),da(),h.downloadNow.hidden=!(O&&A?.link?.download),Sr(),h.album.textContent=Cn();let i=Dn(),a=En();h.elapsed.textContent=je(i),h.total.textContent=a>0?je(a):`--:--`,Oe||(h.seek.value=String(a>0?Math.round(i/a*1e3):0),h.seek.disabled=a<=0||P()),h.playPause.textContent=t?`❚❚`:`▶`,w(h.playPause,`aria-label`,()=>v(t?`Pause`:`Play`)),w(h.seek,`aria-valuetext`,()=>`${je(I.position)} ${_.language===`en`?`of`:`/`} ${je(I.duration)}`),w(h.volume,`aria-valuetext`,()=>_.number(Number(h.volume.value)/100,{style:`percent`})),w(h.playlistTitle,`data-title`,()=>y===`remote`?`Files on ${b||`this server`} (${e.toLocaleString(_.language)})`:`${v(`Playlist`)} (${_.number(e)})`),C(h.source,()=>y===`remote`?`connected · ${b||L.address.replace(/^https?:\/\//,``)||`—`}`:T.length>0?`local · ${T.length} files`:v(`no source`)),mr(),C(h.remoteState,()=>y===`remote`?`${Ee}${De?` — ${De}`:``}`:v(`not connected`)),h.remoteState.dataset.status=y===`remote`?Ee:`idle`,h.disconnect.hidden=y!==`remote`;let o=I.needsInteraction?`Press Play to start playback. Your browser needs a click first.`:y===`remote`&&E.note!==``?E.note:D;h.note.textContent=o,h.note.hidden=o===``,h.linkNote.textContent=o,h.linkNote.hidden=o===``,li(o),cr(),h.glyphs.textContent=N.map(Ln).join(``);let[s,c]=mn()?E.levels:I.levels();h.levels.textContent=In(s,c)}let Xn=``,W=``,Zn=0;function Qn(e){Le(h.playlist),W=e,Zn=0,Xn=``,cr()}function $n(e,t,n,r,i){if(h.playlistPager.hidden=n<=1,n<=1){h.playlistPager.replaceChildren();return}let a=(e,t,r)=>{let i=document.createElement(`button`);return i.type=`button`,i.className=`ghost`,i.textContent=e,i.title=r,i.disabled=t<0||t>=n,i.addEventListener(`click`,()=>{Le(h.playlist),Zn=t,Xn=``,cr()}),i},o=document.createElement(`span`);o.className=`pager-where`,C(o,()=>`${r+1}–${i} of ${e.toLocaleString(_.language)}`),h.playlistPager.replaceChildren(a(`‹ Previous`,t-1,`The page before this one`),o,a(`Next ›`,t+1,`The page after this one`))}function er(e){if(h.crumbs.hidden=!e,!e)return;let t=W===``?[]:W.split(`/`),n=(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`,()=>Qn(t)),r},r=[n(`All files`,``,t.length===0)],i=``;t.forEach((e,a)=>{i=i===``?e:`${i}/${e}`;let o=document.createElement(`span`);o.textContent=`/`,r.push(o,n(e,i,a===t.length-1))}),h.crumbs.replaceChildren(...r)}function tr(e,t,n){let r=document.createElement(`li`);r.className=`folder`;let i=document.createElement(`span`);i.className=`name`,i.textContent=`${e}/`;let a=document.createElement(`span`);a.className=`count`,a.textContent=`${t} file${t===1?``:`s`}`,r.append(i,a);let o=document.createElement(`button`);if(o.type=`button`,o.className=`row-main`,o.setAttribute(`aria-label`,`Open folder ${e}, ${t} files`),o.append(i,a),r.replaceChildren(o),o.addEventListener(`click`,t=>{t.stopPropagation(),Qn(W===``?e:`${W}/${e}`)}),n.length>0){let i=document.createElement(`button`);i.type=`button`,i.className=`row-copy`,g(i,`play`),i.title=`Play all ${t} files in ${e}`,i.setAttribute(`aria-label`,`Play folder ${e}`),i.addEventListener(`click`,e=>{e.stopPropagation(),jn(n)}),r.append(i)}return y===`remote`&&n.length>0&&Lt()&&r.append(nn(()=>({kind:`folder`,indices:n,name:`${e}/`}),`${e}/`)),r}let nr=null,rr=``,ir=``,ar=[],or=(e,t)=>{t.title=t.textContent??``,zn(e,t)};function sr(e,t){let n=document.createElement(`span`);n.className=`name row-file`,n.textContent=e;let r=document.createElement(`span`);r.className=`row-path`,r.textContent=t;let i=document.createElement(`span`);i.className=`row-label`;let a=document.createElement(`span`);a.className=`row-value`,a.append(n);let o=document.createElement(`span`);return o.className=`row-value`,o.append(r),i.append(a),or(a,n),or(o,r),{label:i,pathView:o}}function cr(){let e=(O?j?.channels.find(e=>e.id===O?.id):void 0)?.playlist,t=!!(O&&e?.length);h.livePlaylistPanel.hidden===t&&(h.livePlaylistPanel.hidden=!t);let n=t?O.id:``,r=t?e:[];if(ir!==n||ar.length!==r.length||ar.some((e,t)=>e!==r[t])){ir=n,ar=r;let e=r.map((e,t)=>{let n=document.createElement(`li`);n.className=`row file-row live-file-row`,n.dataset.index=String(t);let r=document.createElement(`span`);r.className=`n`,r.textContent=String(t+1);let{label:i,pathView:a}=sr(e.slice(e.lastIndexOf(`/`)+1),e),o=document.createElement(`span`);return o.className=`row-main`,o.append(i,r),n.append(o,a),n});k(h.livePlaylist,...e)}let i=y===`remote`?E.tracks:T,a=`${y}:${O?.id??``}:${W}:${h.filter.value}:${Zn}:${Lt()}:${h.adminPanel.hidden}`;if(Xn&&nr===i&&rr===a){lr();return}nr=i,rr=a;let o=y===`remote`?E.tracks.map(e=>({name:Me(e),seconds:e.duration,group:e.group??``,folder:e.folder??``,remote:e.remote===!0})):T.map(e=>({name:Me(e),seconds:e.duration,group:``,folder:``,remote:!1})),s=h.filter.value.trim().toLowerCase(),c=o.map((e,t)=>({...e,index:t})).filter(e=>!e.remote).filter(e=>s===``||`${e.folder}/${e.name}`.toLowerCase().includes(s)),l=e=>s!==``||W===``||e===W||e.startsWith(`${W}/`),u=e=>e===W,d=e=>{let t=W===``?e:e.slice(W.length+1),n=t.indexOf(`/`);return n===-1?t:t.slice(0,n)},f=new Map;for(let e of c){if(!l(e.folder)||u(e.folder))continue;let t=d(e.folder);t!==``&&f.set(t,(f.get(t)??0)+1)}let p=c.filter(e=>u(e.folder)&&l(e.folder)),m=[...f].sort((e,t)=>e[0].localeCompare(t[0],void 0,{numeric:!0})),ee=yt(m.length+p.length,Zn,le);Zn=ee.page;let te=m.slice(ee.from,ee.to),ne=p.slice(Math.max(0,ee.from-m.length),Math.max(0,ee.to-m.length)),re=`${y}:${W}:${s}:${ee.page}/${le}:${m.join(`,`)}:${p.map(e=>`${e.index}@${e.name}@${e.seconds}@${e.group}`).join(`|`)}`;if(re!==Xn){Xn=re,er(s===``&&(m.length>0||W!==``)),$n(m.length+p.length,ee.page,ee.pages,ee.from,ee.to);let e=[];for(let[t,n]of te){let r=W===``?t:`${W}/${t}`,i=c.filter(e=>e.folder===r||e.folder.startsWith(`${r}/`)).map(e=>e.index);e.push(tr(t,n,i))}let t=``,n=p.some(e=>e.group!==``);for(let r of ne){r.group!==t&&(n||r.group!==``)&&(t=r.group,e.push(ur(r.group)));let i=document.createElement(`li`);i.className=`row`,i.dataset.index=String(r.index);let a=document.createElement(`span`);a.className=`n`,a.textContent=String(r.index+1).padStart(2,` `);let o=r.folder?`${r.folder} / ${r.name}`:r.name,{label:s,pathView:c}=sr(r.name,r.folder?`${r.folder}/${r.name}`:r.name),l=document.createElement(`span`);l.className=`time`,l.textContent=r.seconds>0?je(r.seconds):`--:--`;let u=document.createElement(`button`);u.type=`button`,u.className=`row-main`,u.setAttribute(`aria-label`,`Play ${o}${r.seconds>0?`, ${je(r.seconds)}`:``}`),u.append(s,a,l),i.append(u);let d=document.createElement(`span`);d.className=`row-play-glyph`,g(d,`play`),i.append(d),y===`remote`&&Lt()&&O===null&&!B()&&i.append(nn(()=>({kind:`track`,index:r.index,name:o}),o)),i.classList.add(`file-row`),i.append(c),e.push(i)}k(h.playlist,...e)}lr()}function lr(){let e=O?j?.channels.find(e=>e.id===O?.id):void 0;if(e?.playlist&&e.playlist.length>0){let t=e.entry??0;for(let e of Array.from(h.livePlaylist.children)){let n=e,r=Number(n.dataset.index),i=Number.isInteger(r)&&r===t;n.classList.toggle(`selected`,i),n.classList.toggle(`playing`,i),n.classList.toggle(`live-file-current`,i),i?n.setAttribute(`aria-current`,`true`):n.removeAttribute(`aria-current`)}for(let n of Array.from(h.playlist.children)){let r=n,i=Number(r.dataset.index),a=E.tracks[i],o=a?`${a.folder?`${a.folder}/`:``}${Me(a)}`:``,s=!!o&&o===e.playlist[t];r.classList.toggle(`selected`,s),r.classList.toggle(`playing`,!1),s?r.setAttribute(`aria-current`,`true`):r.removeAttribute(`aria-current`)}return}for(let e of Array.from(h.livePlaylist.children)){let t=e;t.classList.remove(`selected`,`playing`,`live-file-current`),t.removeAttribute(`aria-current`)}let t=z(),n=On();for(let e of Array.from(h.playlist.children)){let r=e,i=Number(r.dataset.index),a=Number.isInteger(i)&&i===t;r.classList.toggle(`selected`,a),r.classList.toggle(`playing`,a&&n),a?r.setAttribute(`aria-current`,`true`):r.removeAttribute(`aria-current`)}}function ur(e){let t=document.createElement(`li`);t.className=`group`;let n=document.createElement(`span`);if(n.className=`group-name`,n.textContent=e===``?`This server's library`:e,t.append(n),e!==``&&!h.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`,r=>{r.stopPropagation(),cs(t,n,()=>dr(e),()=>cr())}),t.append(n)}return t}async function dr(e){try{let t=await r(L.url(`/api/source/remove`),{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({group:e})}),n=await t.json();return G(t.ok?`Removed ${n.removed??0} tracks from ${e}.`:n.error??`that did not work`),t.ok}catch{return G(`could not reach the server`),!1}}function fr(){let e=h.canvas,t=Math.min(2,globalThis.devicePixelRatio||1),n=Math.round(e.clientWidth*t),r=Math.round(e.clientHeight*t);n>0&&r>0&&(e.width!==n||e.height!==r)&&(e.width=n,e.height=r);let i=e.getContext(`2d`);if(mn())wt=ct(wt,N);else{let e=I.read();e.length>0&&(Et.length!==25&&(Et=at(24,e.length)),N=st(N,ot(e,Et)),wt=ct(wt,N))}if(i){let t=getComputedStyle(document.documentElement);lt(i,{width:e.width,height:e.height},N,wt,{bar:t.getPropertyValue(`--green`).trim()||`#4af689`,peak:t.getPropertyValue(`--green-dim`).trim()||`#227a4a`,background:`transparent`})}if(On()||I.jinglePlaying){h.glyphs.textContent=N.map(Ln).join(``);let[e,t]=mn()?E.levels:I.levels();h.levels.textContent=In(e,t)}if(On()){h.elapsed.textContent=je(Dn());let e=En();!Oe&&e>0&&(h.seek.value=String(Math.round(Dn()/e*1e3)))}requestAnimationFrame(fr)}let pr=``;function mr(){if(y!==`remote`){h.wayInHere.hidden=!0,pr=``;return}let e=At()&&!_e,t=we||L.address,n=e?null:Se(L.address),r=`${t}|${n??``}|${e?`admin`:`view`}`;if(r===pr)return;pr=r;let[i,a]=S({name:b||`this server`,view:t,admin:n});i.hidden=!e,a.hidden=e,h.wayInHere.replaceChildren(i,a),h.wayInHere.hidden=!1}function hr(e){h.video.hidden=!e,h.fullscreen.hidden=!e,$e(),M=null,Xe=null}function gr(){if(!(`mediaSession`in navigator)||typeof MediaMetadata>`u`)return;let e=O?Fe(j?.channels.find(e=>e.id===O?.id)?.art??O.art):``,t=JSON.stringify([Sn(),Cn(),wn(),e]);t!==Ke&&(Ke=t,l({title:Sn(),album:Cn(),artist:wn(),art:e}),navigator.mediaSession.setActionHandler(`play`,()=>void Nn()),navigator.mediaSession.setActionHandler(`pause`,()=>void Nn()),navigator.mediaSession.setActionHandler(`nexttrack`,()=>void Pn(1)),navigator.mediaSession.setActionHandler(`previoustrack`,()=>void Pn(-1)))}document.addEventListener(`click`,()=>{I.resumeAfterInteraction().catch(()=>{})}),h.filter.addEventListener(`input`,()=>{Zn=0,Xn=``,cr()}),h.playlist.addEventListener(`keydown`,e=>{if(e.key!==`Enter`&&e.key!==` `)return;let t=e.target?.closest(`li.row, li.folder`);t&&t===e.target&&(e.preventDefault(),t.click())}),h.playlist.addEventListener(`click`,e=>{let t=e.target.closest(`li`),n=Number(t?.dataset.index);Number.isInteger(n)&&(Ne=null,kn(n))}),h.fullscreen.addEventListener(`click`,()=>{let e=h.video;document.fullscreenElement?document.exitFullscreen().catch(()=>{}):typeof e.requestFullscreen==`function`?e.requestFullscreen().catch(()=>{e.webkitEnterFullscreen?.()}):e.webkitEnterFullscreen?.()}),h.prev.addEventListener(`click`,()=>void Pn(-1)),h.next.addEventListener(`click`,()=>void Pn(1)),h.stop.addEventListener(`click`,()=>void Fn()),h.playPause.addEventListener(`click`,()=>void Nn());async function _r(e){let t=Dt(e,F());if(t)O=null,I.stop(),t.kind===`embed`?(A={kind:`link`,link:{url:e,extractor:t.site,download:!1,live:!1,video:!0}},hr(!1),h.embedFrame.src=t.src,h.embed.hidden=!1,M={url:e,label:t.label,kind:`embed`},D=`Playing ${t.label} here, in this browser.`,U()):t.kind===`list`?await vr(e,t.label):(A={kind:`link`,link:{url:e,extractor:`direct`,download:!1,live:!1,video:t.video}},await Ge(()=>I.load({title:t.label,artist:``,album:``,duration:0,url:t.url,video:t.video,objectUrl:!1},!0)),hr(t.video),M={url:e,label:t.label,kind:`direct`},D=`Playing ${t.label} here, in this browser.`,U());else{if(!Lt()){D=y===`remote`?`That link would need this server to fetch it, which is going live with it: sign in to nixamp.com, or use the server's control link. YouTube, Vimeo, SoundCloud and links straight to a file play here.`:`That link would need a server to fetch it: pick one to go live on, or connect to one. YouTube, Vimeo, SoundCloud and links straight to a file play here.`,U();return}await xr(e)}}async function vr(e,t){D=`Reading ${t}…`,U();let n=``;try{let t=await r(e,{mode:`cors`});if(!t.ok)throw Error(`HTTP ${t.status}`);n=await t.text()}catch(e){D=`That playlist could not be read here (${e.message}). Go live with it instead: the server reads it.`,U();return}let i=Tt(n,e);i.entries.length===0?(D=`Nothing in that playlist is a file this browser plays. Go live with it instead: the server reads it.`,U()):(Xe={url:e,title:i.title||t,entries:i.entries,at:0},await yr())}async function yr(){let e=Xe,t=e?.entries[e.at];if(!e||!t)return;let n=Ct(t.url);A={kind:`link`,link:{url:e.url,extractor:`playlist`,download:!1,live:!1,video:n}},await Ge(()=>I.load({title:t.title,artist:e.title,album:``,duration:0,url:t.url,video:n,objectUrl:!1},!0)),Xe!==null&&(hr(n),M={url:e.url,label:e.title,kind:`direct`},Xe=e,D=`Playing ${e.title} here: ${e.at+1} of ${e.entries.length}, ${t.title}.`,U())}function br(){let e=Xe;return!e||e.entries.length===0?!1:(e.at=(e.at+1)%e.entries.length,yr(),!0)}async function xr(e){y===`remote`?(D=`Asking ${b||`the server`} to fetch ${e}…`,U(),await Ge(async()=>{let t,n={};try{t=await r(L.url(`/api/links/play`),{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({url:e,live:!0})}),n=await t.json().catch(()=>({}))}catch{D=`could not reach the server`;return}if(!t.ok||!n.channel)D=n.error??`that link would not play.`;else{try{await r(L.url(`/api/channels/${encodeURIComponent(n.channel)}/keep`),{method:`POST`})}catch{}await ns({id:n.channel,name:n.name||e,video:n.video!==!1,art:n.art},!0,{kind:`channel`,link:{url:e,extractor:n.extractor??``,download:n.download===!0,live:n.live===!0,video:n.video!==!1}}),(n.entries??0)>1&&(D=`${n.name||e} is on the air: ${n.entries} entries, played in turn.`)}}),U()):(D=`Pick a server to go live on, or connect to one, to put a link on the air.`,U())}h.linkForm.addEventListener(`submit`,e=>{e.preventDefault();let t=h.linkUrl.value.trim();t!==``&&_r(t)});function Sr(){let e=y===`remote`?L.address:``,t=fe.filter(t=>ge(t.url)!==ge(e)),n=JSON.stringify({here:e,name:b,carries:me,others:t});if(n===pe||document.activeElement===h.linkServer)return;pe=n;let r=[];if(e!==``&&me){let t=document.createElement(`option`);t.value=``,t.textContent=`on ${b||e}`,r.push(t)}else{let e=document.createElement(`option`);e.value=``,e.textContent=`go live on…`,r.push(e)}for(let e of t){let t=document.createElement(`option`);t.value=e.url,t.textContent=e.name,r.push(t)}h.linkServer.replaceChildren(...r),h.linkServer.value=e!==``&&!me&&t[0]?t[0].url:``,h.linkServer.hidden=t.length===0}function Cr(){let e=y===`remote`?ge(L.address):``,t=[],n=document.createElement(`option`);if(n.value=``,n.textContent=`Select a server…`,t.push(n),e!==``&&!fe.some(t=>ge(t.url)===e)){let n=document.createElement(`option`);n.value=L.address,n.textContent=b||e,t.push(n)}for(let e of fe){let n=document.createElement(`option`);n.value=e.url,n.textContent=e.name,t.push(n)}h.remoteServer.replaceChildren(...t);let r=fe.find(t=>ge(t.url)===e);h.remoteServer.value=r?.url??``}async function wr(){try{let e=await r(`/api/directory`);if(!e.ok)return;fe=((await e.json()).streams??[]).map(e=>({name:e.name,url:e.url})),Sr(),Cr()}catch{}}async function Tr(){let e=h.linkUrl.value.trim()||M?.url||``;if(e===``){D=`Paste a link first: a file, an .m3u playlist, an IPTV feed, a YouTube page.`,U();return}let t=h.linkServer.value;if(t!==``&&(y!==`remote`||ge(t)!==ge(L.address))){let n=fe.find(e=>e.url===t)?.name??t;he=e,D=`Connecting to ${n} to go live with it…`,U(),Er(t)}else y===`remote`?me?Lt()?await xr(e):(D=`Sign in to nixamp.com to go live here, or use the server's control link.`,U()):(D=`${b||`This server`} has no ffmpeg, so it cannot carry a link.`+(fe.length>0?` Pick a server to go live on, beside the link.`:``),U()):(D=fe.length>0?`Pick a server to go live on, beside the link.`:`Connect to a server first: Browse the directory, or paste a server's link in the Server panel.`,U())}function Er(e){let t=h.linkUrl.value.trim();_e=!0,x=``,h.remoteUrl.value=e,h.remoteForm.requestSubmit(),h.linkUrl.value=t}h.linkGoLive.addEventListener(`click`,()=>{Tr()}),h.linkServer.addEventListener(`change`,()=>{let e=h.linkServer.value;e!==``&&Er(e)}),h.downloadNow.addEventListener(`click`,()=>{let e=A?.link;if(!e||y!==`remote`)return;let t=e.video?``:`&audio=1`;globalThis.open(L.url(`/api/links/download?url=${encodeURIComponent(e.url)}${t}`),`_blank`),D=`Fetching it through the server; your browser will save it when it arrives.`,U()}),h.goLiveNow.addEventListener(`click`,()=>{let e=Rt();e&&Bt(e,h.goLiveNow)}),h.seek.addEventListener(`input`,()=>{Oe=!0}),h.seek.addEventListener(`change`,()=>{let e=En();e>0&&I.seek(Number(h.seek.value)/1e3*e),Oe=!1}),h.volume.addEventListener(`input`,()=>{let e=Number(h.volume.value)/100;I.volume=e,h.volumeToggle.setAttribute(`aria-pressed`,e===0?`true`:`false`),h.volumeToggle.textContent=e===0?`🔇`:`🔊`,w(h.volumeToggle,`aria-label`,()=>v(e===0?`Unmute`:`Mute`));try{localStorage.setItem(Hn,String(e))}catch{}}),h.volumeToggle.addEventListener(`click`,()=>{let e=Number(h.volume.value)===0,t=100;try{let e=Number(localStorage.getItem(Hn));Number.isFinite(e)&&e>0&&(t=Math.round(e*100))}catch{}h.volume.value=e?String(t):`0`,h.volume.dispatchEvent(new Event(`input`))}),h.refreshPlayer.addEventListener(`click`,()=>window.location.reload());let Dr=e=>{e.addEventListener(`change`,()=>{let t=Ye(Array.from(e.files??[]));t.length===0?(D=`Nothing playable in that selection.`,U()):(Ze(T),T=t,Te=0,y=`local`,L.close(),Xo(!1),D=``,kn(0))})};Dr(h.files),Dr(h.folder),h.remoteForm.addEventListener(`submit`,e=>{e.preventDefault();let t=h.remoteUrl.value,{base:n,key:r}=m(t);n===``?(D=`That is not an address.`,U()):(async()=>{Ee=`connecting`,U();let e=ne(n);if(e){Ee=`error`,De=e,D=e,he=``,y=`local`,U();return}if(await te(n,void 0,r)===null){Ee=`error`;let e=u(n);De=e?`needs the server's name`:`not answering`,D=e||`Nothing answered at ${n}. If that is your machine, it is off or nixamp is not running on it; otherwise check the address.`,he=``,y=`local`,U();return}let i=await re(n,r);if(i)Ee=`error`,De=i,D=i,he=``,y=`local`,U();else{y=`remote`,D=``;try{localStorage.setItem(Bn,t.trim())}catch{}L.connect(t),Xo(!0),Ga(),Br(),Ko(),U()}})()}),h.remoteServer.addEventListener(`change`,()=>{let e=h.remoteServer.value;e!==``&&(_e=!1,x=``,h.remoteUrl.value=e,h.remoteForm.requestSubmit())});let Or=``,kr=null,Ar=async(e=!1)=>{h.directory.hidden=!1,e||(h.directoryNote.textContent=`Looking for live streams…`,k(h.directoryList)),kr||=setInterval(()=>{!h.directory.hidden&&document.visibilityState===`visible`&&Ar(!0)},Wn);let t;try{let n=await r(`/api/directory`);if(!n.ok)throw Error(String(n.status));let i=await n.json();t=i.streams??[],fe=t.map(e=>({name:e.name,url:e.url})),Sr();let a=JSON.stringify({streams:t.map(({...e})=>{let{updatedAt:t,startedAt:n,...r}=e;return r}),recent:i.recent??[],me:Y});if(e&&a===Or)return;Or=a,Ur(i.recent??[])}catch{e||(h.directoryNote.textContent=`The directory is not answering. Type an address instead.`);return}if(k(h.directoryList),t.length===0)h.directoryNote.textContent=`Nobody is streaming right now.`;else{h.directoryNote.textContent=`${t.length} ${t.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 e of t){let t=document.createElement(`li`),n=document.createElement(`span`);n.className=`server-label`;let i=document.createElement(`span`);i.className=`name`,i.textContent=e.name;let a=document.createElement(`span`);a.className=`detail`;let o=[`${e.tracks.toLocaleString(_.language)} files to browse`];e.playing!==!1&&e.nowPlaying?o.push(`playing ${e.nowPlaying}`):o.push(`player idle`),e.code&&o.push(e.callers?`☎ ${e.code} · ${e.callers} on the phone`:`☎ ${e.code}`),a.textContent=o.join(` · `),a.title=a.textContent,n.append(i,a);let s=e.admin??Se(e.url),c=(t,n=``)=>{_e=t,x=n,h.remoteUrl.value=t?e.url:s??e.url,h.directory.hidden=!0,document.body.classList.remove(`route-directory`),h.remoteForm.requestSubmit()},l=document.createElement(`ul`);l.className=`server-lives`;for(let t of e.channels??[]){let n=document.createElement(`li`),r=document.createElement(`span`);r.className=`detail live`;let i=e.channelCodes?.[t]??``,a=e.channelCallers?.[t]??0;r.textContent=`● ${t}`+(i?` · ☎ ${i}${a?` · ${a} on the phone`:``}`:``);let o=e.lineup?.find(e=>e.name===t);if(o?.art&&/^https?:\/\//i.test(o.art)){let e=document.createElement(`img`);e.className=`live-art`,e.alt=``,e.loading=`lazy`,e.src=o.art,e.addEventListener(`error`,()=>{e.hidden=!0}),n.append(e)}o?.about&&(r.title=o.about);let u=document.createElement(`button`);u.type=`button`,u.className=`icon`,g(u,`party`),u.setAttribute(`aria-label`,`Join ${t} live on ${e.name}`),u.title=`Join live: ${t} on ${e.name}`,u.addEventListener(`click`,()=>c(!0,`channel:${t}`));let d=document.createElement(`button`);d.type=`button`,d.className=`icon`,g(d,`link`),d.setAttribute(`aria-label`,`Copy live room link for ${t}`),d.title=`Copy a nixamp link to this live room`;let f=`${globalThis.location.origin}/?url=${encodeURIComponent(e.url)}&play=${encodeURIComponent(`channel:${o?.id??t}`)}`;d.addEventListener(`click`,e=>{e.stopPropagation(),ls(f,d,`✓`)});let p=document.createElement(`button`);p.type=`button`,p.className=`icon`,g(p,`copy`),p.setAttribute(`aria-label`,`Copy raw stream URL for ${t}`),p.title=`Copy the raw stream URL for VLC or another player`;let m=e.url;try{let n=new URL(e.url);n.pathname=`/api/channels/${encodeURIComponent(o?.id??t)}`,m=n.toString()}catch{}if(p.addEventListener(`click`,e=>{e.stopPropagation(),ls(m,p,`✓`)}),n.append(r,u,d,p),o?.startedBy&&Y&&o.startedBy===Y&&s){let e=document.createElement(`button`);e.type=`button`,e.className=`icon`,g(e,`gear`),e.setAttribute(`aria-label`,`Administer ${t}`),e.title=`Administer ${t}`,e.addEventListener(`click`,e=>{e.stopPropagation(),c(!1,`channel:${o?.id??t}`)}),n.append(e)}l.append(n)}let[u,d]=S({name:e.name,view:e.url,admin:s},()=>{h.directory.hidden=!0,document.body.classList.remove(`route-directory`)});if(t.append(n,u,d),Y&&t.append(si(e.url,e.name)),e.ownerId&&Y&&e.ownerId!==Y&&t.append(ao(e.ownerId,e.name)),l.childElementCount>0&&t.append(l),e.ownerId&&Y&&e.ownerId===Y){let n=document.createElement(`button`);n.type=`button`,n.className=`ghost`,n.textContent=`Take off the list`,n.addEventListener(`click`,t=>{t.stopPropagation(),n.disabled=!0,(async()=>{try{let t=await r(`/api/directory?id=${encodeURIComponent(e.id)}`,{method:`DELETE`}),n=await t.json().catch(()=>({}));h.directoryNote.textContent=t.ok?`${e.name} is off the list.`:n.error??`that did not work`}catch{h.directoryNote.textContent=`could not reach the directory`}finally{await Ar()}})()}),t.append(n)}h.directoryList.append(t)}}};if(document.addEventListener(`visibilitychange`,()=>{document.visibilityState===`visible`&&!h.directory.hidden&&Ar(!0)}),location.pathname.replace(/\/+$/,``)===`/directory`){document.body.classList.add(`route-directory`);let e=document.getElementById(`directory-back`);e&&(e.hidden=!1),Ar()}let jr=/^\/live\/([^/]+)\/?$/.exec(location.pathname);if(jr){document.body.classList.add(`route-party`),h.partyRoom.hidden=!1;let e=decodeURIComponent(jr[1]??``),t=null,n=0,i=``,a=new Set,o=e=>{let t=Math.max(0,Math.floor(e)),n=String(t%60).padStart(2,`0`),r=Math.floor(t/60)%60,i=Math.floor(t/3600);return i>0?`${i}:${String(r).padStart(2,`0`)}:${n}`:`${r}:${n}`},s=(e,t=!1)=>{let n=t?h.partyChatNote:h.partyRoomNote;n.hidden=e===``,n.textContent=e},c=()=>{if(!t)return;let e=t.party.playing?(Date.now()-n)/1e3:0,r=t.party.positionNow+e,i=[t.event.status===`live`?t.party.playing?`▶ ${o(r)}`:`❚❚ ${o(r)}`:`ended`,t.party.mediaTitle,`code ${t.party.partyCode}`,t.host?`yours`:``].filter(Boolean);h.partyMeta.textContent=i.join(` · `)},l=()=>{if(!t)return;document.title=`${t.event.title} — nixamp`,h.partyTitle.textContent=t.event.title||t.party.partyCode;let e=t.links.partyUrl||t.party.partyUrl;h.partyWatch.href=e||`#`,h.partyWatch.hidden=e===``;let n=t.party.origin;try{n=new URL(e).hostname}catch{}h.partyWatch.title=`The film plays on ${n} (opens in a new tab)`,h.partyEnd.hidden=!t.host||t.event.status!==`live`;let r=t.event.chatEnabled!==!1&&t.event.status===`live`;h.partyChatForm.hidden=!r,h.partyChatInput.disabled=!r||Y===``,h.partyChatSend.disabled=!r||Y===``,s(r?Y===``?`Sign in to say something; everybody can read.`:``:t.event.status===`live`?`Chat is off for this party.`:`This party has ended.`,!0),c()},u=async()=>{try{let i=await r(`/api/v1/watch-parties/${encodeURIComponent(e)}`,{cache:`no-store`});if(!i.ok){s(i.status===404?`No party here. It may have ended, or the link is not one.`:`Could not open this party. Try again in a moment.`);return}t=await i.json(),n=Date.now(),s(``),l()}catch{s(`Could not open this party. Try again in a moment.`)}},d=async()=>{if(t&&t.event.chatEnabled!==!1)try{let e=new URL(`/api/v1/events/${encodeURIComponent(t.event.id)}/chat`,location.origin);i&&e.searchParams.set(`after`,i);let n=await r(e.toString(),{cache:`no-store`});if(!n.ok)return;let o=((await n.json()).messages??[]).filter(e=>!a.has(e.id));if(!o.length){if(!h.partyChat.childElementCount){let e=document.createElement(`li`);e.className=`hint`,e.textContent=`No messages yet. Say hi!`,h.partyChat.replaceChildren(e)}return}h.partyChat.querySelector(`.hint`)&&h.partyChat.replaceChildren();let s=h.partyChat.scrollHeight-h.partyChat.scrollTop-h.partyChat.clientHeight<60;for(let e of o){a.add(e.id),i=e.createdAt;let t=document.createElement(`li`),n=document.createElement(`b`);n.textContent=e.authorName,t.append(n,document.createTextNode(e.body)),h.partyChat.append(t)}for(;h.partyChat.childElementCount>200;)h.partyChat.firstElementChild?.remove();s&&(h.partyChat.scrollTop=h.partyChat.scrollHeight)}catch{}};h.partyChatForm.addEventListener(`submit`,e=>{e.preventDefault();let n=h.partyChatInput.value.trim();t&&n!==``&&(h.partyChatSend.disabled=!0,(async()=>{try{let e=await r(`/api/v1/events/${encodeURIComponent(t.event.id)}/chat`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({body:n})}),i=await e.json().catch(()=>({}));if(!e.ok){s(i.error??`That did not send.`,!0);return}h.partyChatInput.value=``,s(``,!0),await d()}catch{s(`That did not send.`,!0)}finally{h.partyChatSend.disabled=Y===``}})())}),h.partyCopy.addEventListener(`click`,()=>{navigator.clipboard?.writeText(t?.links.nixampUrl||location.href).then(()=>{h.partyCopy.textContent=`Copied`,setTimeout(()=>{h.partyCopy.textContent=`Copy room link`},2e3)},()=>s(`Could not copy that.`))}),h.partyEnd.addEventListener(`click`,()=>{t&&t.host&&(async()=>{(await r(`/api/v1/watch-parties/${encodeURIComponent(t.party.partyCode)}/end`,{method:`POST`})).ok?await u():s(`Could not end it.`)})()}),(async()=>{await u(),await d()})(),setInterval(c,1e3),setInterval(()=>void u(),1e4),setInterval(()=>void d(),4e3),document.addEventListener(`nixamp:account`,()=>l())}let Mr=null,Nr=e=>e===`cgnat`?`mobile or tailscale`:e===`private`?`your network`:e===`local`?`this machine`:e===`public`?`the internet`:e,Pr=e=>e===`events`?`watching the panel`:e===`page`?`opened the page`:e===`media`?`playing a track`:e===`stream`?`listening live`:e,Fr=``,Ir=``,Lr=e=>{let t=e.map(e=>`${e.address}|${e.kind}|${e.track}|${Math.round(e.bytes/4096)}|${e.endedAt}`).join(`~`);if(t===Fr)return;Fr=t,h.adminConnections.replaceChildren();let n=document.createElement(`tr`);for(let e of[`Where`,`Network`,`Kind`,`Client`,`Track`,`Sent`]){let t=document.createElement(`th`);t.textContent=e,n.append(t)}h.adminConnections.append(n);for(let t of e.slice(0,40)){let e=document.createElement(`tr`);t.endedAt!==null&&(e.className=`ended`);let n=[[t.address,``],[Nr(t.network),`network-${t.network}`],[Pr(t.kind),``],[t.agent,``],[t.track||`—`,``],[`${Math.round(t.bytes/1024)} KiB`,``]];for(let[t,r]of n){let n=document.createElement(`td`);n.textContent=t,r&&(n.className=r),e.append(n)}h.adminConnections.append(e)}};function G(e){h.adminSaid.textContent=e,h.adminSaid.hidden=e===``}let Rr=async()=>{try{let e=await r(L.url(`/api/connections`));if(!e.ok)return;let t=await e.json(),n=(t.connections??[]).filter(e=>e.endedAt===null&&e.kind!==`media`&&e.kind!==`stream`).length,i=t.active??0;h.adminNote.textContent=n===0?`${i} listening now.`:`${i} listening now, and ${n} with the page open.`,Lr(t.connections??[]),zr(t.publish??[],(t.channels??[]).map(e=>e.id)),hs(t.home??``,t.root??``),Zo()}catch{h.adminNote.textContent=`lost touch with the server`}};function zr(e,t){h.publishPanel.hidden=e.length===0;let n=`${e.map(e=>`${e.id}=${e.url}`).join(`~`)}::${t.join(`,`)}`;if(n===Ir)return;if(Ir=n,e.length===0){k(h.publishList);return}let r=e.length-t.length;h.publishNote.textContent=`Point OBS, Larix or ffmpeg at one of these. One publisher per URL — ${e.length} at once, ${r} free right now.`,k(h.publishList,...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`,C(o,()=>v(`Copy`)),o.addEventListener(`click`,()=>{a.select(),navigator.clipboard?.writeText(e.url).catch(()=>{})}),r.append(i,a,o),r}))}let Br=async()=>{if(y!==`remote`){h.adminPanel.hidden=!0,h.publishPanel.hidden=!0,Mr&&clearInterval(Mr),Mr=null;return}let e=!1,t=null,n=!1,i=!1;try{let a=await r(L.url(`/api/admin`));if(a.ok){let r=await a.json();e=r.allowed===!0,t=r.as??null,n=r.claimed===!0,i=r.member===!0}}catch{e=!1}let a=e||i;_e&&(e=!1),jt=a&&!e;let o=h.partiesList.dataset.adminMode!==String(e);if(h.adminPanel.hidden=!e,o&&(h.partiesList.dataset.adminMode=String(e),h.partiesList.querySelectorAll(`details[open]`).forEach(e=>e.removeAttribute(`open`)),Zr()),Go(e),he!==``){let e=he;he=``,Lt()?xr(e):(D=`Sign in to nixamp.com to go live here.`,U())}Mr&&clearInterval(Mr),Mr=null,Zo(),Ga(),Ko(),h.listenOnly.hidden=e,e?(h.adminNote.textContent=t===`owner`?`You own this server.`:`You hold this server's control link.`,Rr(),Mr=setInterval(()=>void Rr(),2e3)):h.listenOnly.textContent=n?`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.`};function Vr(e,t,n){let i=(t||e).toLowerCase().replace(/[^a-z0-9_-]+/g,`-`).replace(/^-+|-+$/g,``).slice(0,40)||`s${Math.random().toString(16).slice(2,8)}`;G(`Starting ${t||e}…`),(async()=>{try{let a=await r(L.url(`/api/channels/${encodeURIComponent(i)}/pull`),{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({...n===void 0?{source:e}:{at:n},...t?{name:t}:{}})}),o=await a.json();if(!a.ok){G(o.error??`that did not work`);return}G(`${o.channel?.name||t||e} is on the air.`),h.adminSource.value=``,h.adminName.value=``,Ko(),Zo()}catch{G(`could not reach the server`)}})()}h.adminRestream.addEventListener(`submit`,e=>{e.preventDefault();let t=h.adminSource.value.trim();t&&Vr(t,h.adminName.value.trim())}),h.adminAdd.addEventListener(`click`,()=>{let e=h.adminSource.value.trim();if(!e)return;G(`Reading ${e}…`);let t=h.adminReplace.checked,n=h.adminName.value.trim();(async()=>{try{let i=await r(L.url(`/api/source`),{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({source:e,...n?{name:n}:{},...t?{replace:!0}:{}})}),a=await i.json();G(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&&(h.adminSource.value=``,h.adminName.value=``,Ko(),Zo())}catch{G(`could not reach the server`)}})()});let Hr=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`},Ur=e=>{let t=[],n=Y?e.filter(e=>e.ownerId&&e.ownerId!==Y):[];if(h.recentNote.hidden=n.length===0,n.length===0)k(h.recentList);else{for(let e of n){let n=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 ${Hr(e.endedAt)}`:`ended ${Hr(e.endedAt)}`,r.append(i,a),n.append(r,ao(e.ownerId,e.name)),t.push(n)}k(h.recentList,...t)}},Wr=e=>{let t=Math.max(0,Math.floor(e)),n=String(t%60).padStart(2,`0`),r=Math.floor(t/60)%60,i=Math.floor(t/3600);return i>0?`${i}:${String(r).padStart(2,`0`)}:${n}`:`${r}:${n}`};function Gr(e){let t=document.createElement(`li`),n=document.createElement(`span`);n.className=`server-label`;let r=document.createElement(`span`);r.className=`name`,r.textContent=e.event.title||e.party.partyCode;let i=document.createElement(`span`);i.className=e.party.playing?`detail live`:`detail`,i.textContent=[e.party.playing?`▶ ${Wr(e.party.positionNow)}`:`❚❚ ${Wr(e.party.positionNow)}`,e.party.mediaTitle,e.party.origin,e.host?`yours`:``].filter(Boolean).join(` · `),n.append(r,i);let a=document.createElement(`a`);a.className=`button`,a.href=e.links.partyUrl||e.links.nixampUrl,a.rel=`noopener`,a.target=`_blank`,Vt(a),a.title=`Join live on the site hosting this party (opens in a new tab)`;let o=document.createElement(`a`);o.className=`ghost`,o.href=e.links.nixampUrl,o.textContent=`Open room`,t.className=`party-row`,n.className=`party-name`,n.title=i.textContent,i.hidden=!0;let s=document.createElement(`details`);s.className=`party-actions`;let c=document.createElement(`summary`);return c.textContent=`⋯`,w(c,`aria-label`,()=>`${v(`Show more`)}: ${e.event.title}`),s.append(c,o),t.append(n,a,s),t}let Kr=[],qr=[],Jr=!1,Yr=null,Xr=``;function Zr(){let e=new Map,t=(t,n,r)=>{if(!r.length)return;let i=e.get(t);if(i){let e=new Set(i.rows.map(e=>e.dataset.liveKey));i.rows.push(...r.filter(t=>!e.has(t.dataset.liveKey)))}else e.set(t,{name:n,rows:r})},n=y===`remote`&&j?ge(L.address):``;for(let e of Kr){let r=ge(e.url);if(!r||r===n)continue;let i=[],a=(t,n)=>{let a=document.createElement(`li`);a.dataset.liveKey=`${r}:${t}`,a.className=`party-row`;let o=document.createElement(`span`);o.className=`party-name`,o.textContent=n,o.title=n;let s=document.createElement(`button`);s.type=`button`,Vt(s),w(s,`aria-label`,()=>`${v(`Join party`)}: ${n} · ${e.name}`),s.addEventListener(`click`,()=>{_e=!0,x=t,h.remoteUrl.value=e.url,h.remoteForm.requestSubmit()}),a.append(o,s),i.push(a)};e.playing!==!1&&e.nowPlaying&&a(`live`,Ve(e.nowPlaying));for(let t of e.channels??[]){let n=e.lineup?.find(e=>e.name===t);a(`channel:${n?.id??t}`,t)}t(r,e.name,i)}n&&j&&t(n,j.server.name||b||n,$o(j));for(let e of qr){let n=e.party.origin;try{n=new URL(e.links.partyUrl||e.party.partyUrl).origin}catch{}let r=e.party.origin;try{r=new URL(n).hostname}catch{}let i=Gr(e);i.dataset.liveKey=`party:${e.event.id}`,t(n,r,[i])}let r=new Map([...h.partiesList.children].map(e=>[e.dataset.liveKey,e])),i=[];for(let[t,n]of e){let e=r.get(t);if(!e){e=document.createElement(`li`),e.dataset.liveKey=t,e.className=`party-server`;let n=document.createElement(`h3`),r=document.createElement(`ul`);r.className=`party-rows`,e.append(n,r)}let a=e.querySelector(`h3`);a.textContent!==n.name&&(a.textContent=n.name),Be(e.querySelector(`ul`),n.rows),i.push(e)}Be(h.partiesList,i),h.partiesNote.hidden=e.size>0,e.size||C(h.partiesNote,()=>v(Jr?`No parties live right now.`:`Loading…`))}let Qr=5e3,$r=new Set,ei=(e,t)=>{t?$r.add(e):$r.delete(e),$r.size?h.partiesPanel.dataset.loading=`true`:delete h.partiesPanel.dataset.loading};async function ti(){if(e||(Xr!==Y&&(Yr?.abort(),Yr=null,qr=[],Xr=Y,Zr()),Yr))return;let t=new AbortController;Yr=t;let n=!Jr;n&&ei(t,!0);let i=Y,a=setTimeout(()=>t.abort(),8e3),o=async e=>{let n=await r(e,{signal:t.signal,cache:`no-store`});return{ok:n.ok,status:n.status,body:n.ok?await n.json():null}};try{let[e,n]=await Promise.allSettled([o(`/api/directory`),i?o(`/api/v1/watch-parties`):Promise.resolve(null)]);if(Yr!==t||i!==Y||t.signal.aborted)return;e.status===`fulfilled`&&e.value.ok&&(Kr=e.value.body.streams??[],Jr=!0,h.directory.dataset.available=String(Kr.length>0),Uo()),n.status===`fulfilled`&&n.value&&(n.value.ok?(qr=n.value.body.parties??[],Jr=!0):[401,403].includes(n.value.status)&&(qr=[])),Zr(),!Jr&&!j&&C(h.partiesNote,()=>v(`Could not refresh parties.`))}finally{clearTimeout(a),n&&ei(t,!1),Yr===t&&(Yr=null)}}h.partyForm.addEventListener(`submit`,e=>{e.preventDefault();let t=h.partyCode.value.trim();t!==``&&(async()=>{try{let e=await r(`/api/v1/watch-parties/${encodeURIComponent(t)}`),n=await e.json().catch(()=>({}));if(!e.ok){D=n.error??`No party found with that invite code.`,U();return}h.partyCode.value=``,window.location.href=n.links.nixampUrl}catch{D=`Could not look up that party. Try again.`,U()}})()});async function ni(){if(!Y)h.connectionsNote.hidden=!0,h.connectionsList.hidden=!0;else try{let e=await r(`/api/v1/oauth/connections`);if(!e.ok){h.connectionsNote.hidden=!0,h.connectionsList.hidden=!0;return}let t=(await e.json()).connections??[];h.connectionsNote.hidden=t.length===0,h.connectionsList.hidden=t.length===0,k(h.connectionsList,...t.map(e=>{let t=document.createElement(`li`),n=document.createElement(`span`);n.className=`server-label`;let i=document.createElement(`span`);i.className=`name`,i.textContent=e.clientName;let a=document.createElement(`span`);a.className=`detail`,a.textContent=e.scope.split(` `).filter(Boolean).join(`, `),n.append(i,a);let o=document.createElement(`button`);return o.type=`button`,o.className=`ghost`,C(o,()=>v(`Disconnect`)),o.addEventListener(`click`,()=>{(async()=>{try{await r(`/api/v1/oauth/connections/${encodeURIComponent(e.clientId)}`,{method:`DELETE`})}catch{}await ni()})()}),t.append(n,o),t}))}catch{h.connectionsNote.hidden=!0,h.connectionsList.hidden=!0}}let ri=new Set,K=e=>{try{return new URL(e).origin}catch{return e}},ii=e=>[...ri].some(t=>K(t)===K(e));async function ai(){if(!Y)ri=new Set,h.favoritesPanel.hidden=!0,ci();else{try{let e=await r(`/api/v1/favorites`);if(!e.ok){h.favoritesPanel.hidden=!0;return}let t=(await e.json()).favorites??[];ri=new Set(t.map(e=>e.url)),h.favoritesPanel.hidden=t.length===0,h.favoritesNote.textContent=`Servers you hearted. Connect to one, or let it go.`,k(h.favoritesList,...t.map(e=>{let t=document.createElement(`li`),n=document.createElement(`span`);n.className=`server-label`;let r=document.createElement(`span`);r.className=`name`,r.textContent=e.name||e.url.replace(/^https?:\/\//,``);let i=document.createElement(`span`);return i.className=e.live?`detail live`:`detail`,i.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`,n.append(r,i),t.append(n,...S({name:e.name||e.url,view:e.url,admin:Se(e.url)}),si(e.url,e.name)),t}))}catch{h.favoritesPanel.hidden=!0}ci()}}async function oi(e,t,n){try{if(!(n?await r(`/api/v1/favorites`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify({url:e,name:t})}):await r(`/api/v1/favorites?url=${encodeURIComponent(e)}`,{method:`DELETE`})).ok){D=n?`Could not save that favourite.`:`Could not remove that favourite.`,U();return}}catch{D=`could not reach nixamp.com`,U();return}if(n)ri.add(e);else for(let t of[...ri])K(t)===K(e)&&ri.delete(t);await ai()}function si(e,t){let n=document.createElement(`button`);n.type=`button`,n.className=`heart`;let r=()=>{let t=ii(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=[...ri].find(t=>K(t)===K(e))??e;oi(ii(e)?i:e,t,!ii(e)).then(r)}),n}function ci(){let e=y===`remote`?L.shareLink:``;if(h.favHere.hidden=!(Y&&e),h.favHere.hidden)return;let t=ii(e);h.favHere.textContent=t?`♥`:`♡`,h.favHere.dataset.on=t?`yes`:`no`,h.favHere.title=t?`Remove this server from your favourites`:`Add this server to your favourites`,h.favHere.setAttribute(`aria-label`,h.favHere.title)}g(h.copyNow,`copy`),h.copyNow.addEventListener(`click`,()=>{ls(I.source,h.copyNow,`✓`)});function li(e){if(e===``||e===St)return;St=e;let t=document.createElement(`li`),n=document.createElement(`time`),r=new Date;n.dateTime=r.toISOString(),C(n,()=>r.toLocaleTimeString(_.language,{hour:`2-digit`,minute:`2-digit`,second:`2-digit`}));let i=document.createElement(`span`);for(i.textContent=e,t.append(n,i),h.logList.prepend(t);h.logList.children.length>100;)h.logList.lastElementChild?.remove()}let ui=3e3,q=/(^|\.)nixamp\.com$/.test(globalThis.location.hostname)?``:`https://nixamp.com`,di=``,fi=``,pi=null,mi=!1,hi=new Set,gi=``,_i=null,vi=!1,yi=en(e=>localStorage.getItem(e)),J=Yt(e=>localStorage.getItem(e)),bi=new Set,xi=new Set,Si=null,Ci=``,wi=``,Y=``,Ti=(()=>{try{let e=sessionStorage.getItem(`nixamp.translationSession`);if(e&&/^listener-[a-f0-9-]{36}$/.test(e))return e;let t=`listener-${crypto.randomUUID()}`;return sessionStorage.setItem(`nixamp.translationSession`,t),t}catch{return`listener-${crypto.randomUUID()}`}})(),Ei=null,X=!1,Di=``,Oi=!1,ki=!1,Ai=``,ji=0,Mi=!1,Ni=!1;try{h.transcriptBackground.checked=localStorage.getItem(`nixamp.backgroundSound`)!==`off`}catch{}let Pi=new hn(()=>{Ni=!0,Mi&&(h.transcriptAudioNote.textContent=`Translated audio · background sound unavailable on this device`)},{process:!1}),Fi=()=>{let e=Number(h.transcriptBackgroundLevel.value);Pi.setLevel(e/100),h.transcriptBackgroundValue.value=`${e}%`,w(h.transcriptBackgroundLevel,`aria-valuetext`,()=>_.number(e/100,{style:`percent`})),h.transcriptBackgroundLevel.disabled=!h.transcriptBackground.checked};try{let e=localStorage.getItem(`nixamp.backgroundLevel`);e!==null&&Number.isFinite(Number(e))&&(h.transcriptBackgroundLevel.value=e)}catch{}Fi(),h.transcriptBackgroundLevel.addEventListener(`input`,()=>{Fi();try{localStorage.setItem(`nixamp.backgroundLevel`,h.transcriptBackgroundLevel.value)}catch{}});let Ii=new _n({account:()=>q===``?Y:``,changed:()=>ga()});H(`translation-buy-tools`).append(Ii.button()),Ii.refresh();let Li=new gn({reconnecting:()=>Z.reset(),line:(e,t)=>{Gi=0,Ki.push(e),ma(),Z.push(e,t,0)},status:e=>{h.transcriptAudioNote.textContent=e},failed:e=>{Di=e,wi=e,X=!1,h.transcriptAudio.checked=!1,Z.disable(),Bi(),h.transcriptAudioNote.textContent=`${e} Original audio restored.`,Ii.refresh()}}),Z=new un({fetcher:((e,t)=>String(e).startsWith(`nixamp-shared:`)?Promise.resolve(Li.audio(String(e))):r(e,t)),playing:()=>I.playing,volume:()=>I.volume,active:e=>{Mi=e,I.translatedAudio(e),Pi.active(e&&I.playing&&h.transcriptBackground.checked)},status:e=>{h.transcriptAudioNote.textContent=e+(Ni&&Mi?` · background unavailable`:``)},failed:()=>{wi=h.transcriptAudioNote.textContent||`Translated audio stopped.`,X=!1,h.transcriptAudio.checked=!1,Bi()},authorization:async(e,t)=>{if(t.channel.startsWith(`dub-`))return new Headers;if(!Y||q!==``)throw Error(`Sign in on nixamp.com to enable translated audio.`);if(!Ei||Ei.channel!==t.channel||Ei.expires<Date.now()+2e4||Ei.remaining<t.text.length){let n=await r(`/api/v1/speech/grant`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({channel:t.channel}),signal:e}),i=await n.json();if(!n.ok||!i.token||!i.expires)throw Error(i.error||`Sign in to enable translated audio.`);Ei={channel:t.channel,token:i.token,expires:i.expires,remaining:2e3}}return Ei.remaining-=t.text.length,{authorization:`Bearer ${Ei.token}`}}}),Ri=new zt({fetcher:(e,t)=>{let n=new Headers(t?.headers);return String(e).includes(`/speech/speakers`)&&n.set(`x-nixamp-translation-session`,Ti),r(e,{...t,headers:n})},language:()=>J,speakers:()=>h.transcriptAudio.checked,voices:()=>Si?.voices??[],channel:()=>Ti,status:e=>{!Oi&&!X&&(Di=e),h.transcriptNote.textContent=e},failed:()=>{X=!1,h.transcriptAudio.checked=!1,Z.disable(),Bi()},lines:e=>{Gi=0,Ki.push(...e),ma(),Hi(),h.transcriptAudio.checked&&Z.pushBatch(e.map(e=>({line:e,lag:0,url:`/api/v1/speech/synthesize`,init:{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({text:e.text,language:J,channel:Ti,speaker:e.speaker,voice:Ri.tracker.speakers.get(e.speaker??``)?.voice??`auto`})}})))}}),zi=new fn(e=>{Oi&&I.playing&&Ri.push(e)});function Bi(){ji++,Oi=!1,ki=!1,Ai=``,zi.stop(),Ri.reset(),Li.stop(),Pi.stop(),Z.reset(),k(h.transcriptSpeakers)}async function Vi(){if((Oi||ki)&&Ai===I.mediaKey)return;Bi();let e=ji;ki=!0,Ai=I.mediaKey;try{if(!Y||q!==``)throw Error(`Sign in on nixamp.com to transcribe or translate this audio.`);let t=I.audioInput();if(Ni=!1,h.transcriptAudio.checked&&h.transcriptBackground.checked&&Pi.start(t.context,t.node).then(t=>{t&&e===ji&&Pi.active(Mi&&I.playing&&h.transcriptBackground.checked)}),h.transcriptAudio.checked&&y===`remote`&&O)await Li.start(va(),J),Ii.refresh();else{if(h.transcriptAudio.checked&&await Ii.startSession(Ti),e!==ji)return;await zi.start(t.context,t.node,h.transcriptAudio.checked?2:5)}if(e!==ji)return;Oi=!0,X=!0,Gi=0,Ji??=setInterval(ma,250),h.transcriptNote.textContent=h.transcriptAudio.checked?`Listening for speech and speaker changes…`:`Listening in the original audio language…`}catch(t){if(e!==ji)return;X=!1,h.transcriptAudio.checked=!1,Z.disable(),Bi(),Di=t instanceof Error?t.message:`This audio could not be captured.`,h.transcriptNote.textContent=Di}finally{e===ji&&(ki=!1)}}function Hi(){let e=[...Ri.tracker.speakers.values()].slice(-32),t=new Set(e.map(e=>e.id));for(let t of e){if(h.transcriptSpeakers.querySelector(`[data-speaker="${t.id}"]`))continue;let e=document.createElement(`label`);e.className=`transcript-switch`,e.dataset.speaker=t.id;let n=document.createElement(`span`),r=t.id.split(`-`)[1];C(n,()=>`${v(`Speaker`)} ${r} `),e.append(n);let i=document.createElement(`select`);i.className=`transcript-language`,w(i,`aria-label`,()=>`${v(`Speaker voices`)}: ${r}`);for(let e of Si?.voices??[])i.append(new Option(e.name,e.id));i.value=t.voice,i.addEventListener(`change`,()=>{t.voice=i.value,Z.reset()}),e.append(i),h.transcriptSpeakers.append(e)}h.transcriptVoiceSettings.hidden=!h.transcriptAudio.checked;for(let e of h.transcriptSpeakers.querySelectorAll(`[data-speaker]`))!t.has(e.dataset.speaker??``)&&!e.contains(document.activeElement)&&e.remove()}for(let e of[h.audio,h.video]){for(let t of[`pause`,`ended`,`seeking`,`emptied`])e.addEventListener(t,()=>{e===(I.showingVideo?h.video:h.audio)&&Bi()});for(let t of[`playing`,`seeked`])e.addEventListener(t,()=>{e===(I.showingVideo?h.video:h.audio)&&X&&yi&&I.playing&&Vi()});e.addEventListener(`volumechange`,()=>{Z.setVolume()})}let Ui=``,Wi=null,Gi=Zt(6,!1),Ki=[],qi=[],Ji=null;function Yi(){if(y!==`remote`)return null;let{base:e}=m(ds());if(e===``)return null;let t=``;try{t=new URL(e).origin}catch{return null}let n=O?O.id:A?.kind===`live`?`live`:``;return n===``?null:{server:t,channel:n}}function Xi(e,t=``){let n=new URLSearchParams({server:e.server,channel:e.channel});return t&&n.set(`after`,t),`${q}/api/v1/trollbox?${n.toString()}`}function Zi(){let e=Yi(),t=e?`${e.server}|${e.channel}`:``;t!==di&&(di=t,fi=``,hi.clear(),h.trollboxList.replaceChildren(),pi&&clearTimeout(pi),pi=null,h.trollboxPanel.hidden=e===null,h.trollboxForm.hidden=!0,ra(!1),e&&(C(h.trollboxNote,()=>`The room for ${Sn()||e.channel}. Loading…`),$i()))}function Qi(e){let t=document.createElement(`li`);t.dataset.id=e.id;let n=document.createElement(`time`);n.className=`when`,n.dateTime=e.createdAt;let r=new Date(e.createdAt);C(n,()=>Number.isNaN(r.getTime())?``:r.toLocaleTimeString(_.language,{hour:`2-digit`,minute:`2-digit`}));let i=document.createElement(`span`);i.className=`who`,i.textContent=e.handle;let a=document.createElement(`span`);return a.className=`line`,a.textContent=e.body,a.dir=`auto`,a.translate=!1,t.append(n,i,a),t}async function $i(){let e=Yi(),t=e?`${e.server}|${e.channel}`:``;if(e&&t===di&&!mi){mi=!0;try{let n=await r(Xi(e,fi)),i=await n.json().catch(()=>({}));if(t!==di)return;if(!n.ok){h.trollboxNote.textContent=i.error??`The trollbox is not answering.`;return}let a=(i.messages??[]).filter(e=>!hi.has(e.id));for(let e of a)hi.add(e.id),h.trollboxList.append(Qi(e)),fi=e.createdAt;for(;h.trollboxList.children.length>200;)h.trollboxList.firstElementChild?.remove();let o=i.you??``,s=gi!==o;gi=o,ue.hidden=o!==``,q!==``&&(ue.href=`${q}/?url=${encodeURIComponent(ds())}&play=${encodeURIComponent(`channel:${e.channel}`)}#account-panel`),s&&(Ei=null,ga()),h.trollboxForm.hidden=o===``,h.trollboxEditLabel.hidden=o===``||!ea,o===``&&ra(!1),C(h.trollboxNote,()=>o===``?q===``?`The room for ${Sn()||e.channel}. Sign in to say something.`:`The room for ${Sn()||e.channel}. To say something, open this stream on nixamp.com and sign in.`:`You are ${o} in the room for ${Sn()||e.channel}.`)}catch{t===di&&(h.trollboxNote.textContent=`The trollbox is not answering.`)}finally{mi=!1,t===di&&(pi=setTimeout(()=>{document.visibilityState===`visible`?$i():pi=setTimeout(()=>void $i(),ui)},ui))}}}h.trollboxForm.addEventListener(`submit`,e=>{e.preventDefault();let t=Yi(),n=h.trollboxInput.value.trim();t&&n!==``&&(h.trollboxInput.disabled=!0,(async()=>{try{let e=await r(`${q}/api/v1/trollbox`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({server:t.server,channel:t.channel,body:n})}),i=await e.json().catch(()=>({}));if(!e.ok||!i.message){h.trollboxNote.textContent=i.error??`that did not send`;return}h.trollboxInput.value=``,hi.has(i.message.id)||(hi.add(i.message.id),h.trollboxList.append(Qi(i.message)),fi=i.message.createdAt)}catch{h.trollboxNote.textContent=`The trollbox is not answering.`}finally{h.trollboxInput.disabled=!1}})())});let ea=typeof MediaRecorder<`u`&&typeof navigator.mediaDevices?.getUserMedia==`function`,ta=ea?Wt(e=>MediaRecorder.isTypeSupported(e)):``;h.trollboxMic.hidden=!ea;function na(e){h.trollboxNote.textContent=e,li(e)}function ra(e){let t=_i;if(!t)return;_i=null,clearTimeout(t.stop),clearInterval(t.tick),h.trollboxMic.setAttribute(`aria-pressed`,`false`),h.trollboxMic.textContent=`🎤`;let n=new Promise(e=>{t.recorder.addEventListener(`stop`,()=>e(),{once:!0})});t.recorder.state!==`inactive`&&t.recorder.stop();for(let e of t.stream.getTracks())e.stop();e&&n.then(()=>aa(new Blob(t.chunks,{type:t.recorder.mimeType||ta||`audio/webm`}),t.startedAt))}async function ia(){if(_i||vi||gi===``||!Yi())return;let e;try{e=await navigator.mediaDevices.getUserMedia({audio:{channelCount:1,echoCancellation:!0,noiseSuppression:!0,autoGainControl:!0}})}catch(e){na(e.name===`NotAllowedError`?`The microphone was refused. Allow it for nixamp.com and tap again.`:`No microphone could be opened here.`);return}let t;try{t=new MediaRecorder(e,ta?{mimeType:ta}:{})}catch{for(let t of e.getTracks())t.stop();na(`This browser cannot record the microphone.`);return}let n=[];t.addEventListener(`dataavailable`,e=>{e.data.size>0&&n.push(e.data)});let r=Date.now();_i={recorder:t,stream:e,chunks:n,startedAt:r,stop:setTimeout(()=>ra(!0),Ut),tick:setInterval(()=>{h.trollboxMic.textContent=Gt(r,Date.now())},500)},t.start(250),h.trollboxMic.setAttribute(`aria-pressed`,`true`),h.trollboxMic.textContent=Gt(r,r),na(`Listening. Tap the mic again when you have said it (${Math.round(Ut/1e3)} s at most).`)}async function aa(e,t){let n=Yi();if(n&&gi!==``){if(Date.now()-t<400||e.size===0)na(`That was too short to hear. Tap, say it, then tap again.`);else{vi=!0,h.trollboxMic.disabled=!0,h.trollboxMic.textContent=`…`,na(`Hearing you…`);try{let t=new AudioContext,i;try{i=await t.decodeAudioData(await e.arrayBuffer())}finally{t.close()}let a=new OfflineAudioContext(1,Math.max(1,Math.ceil(i.duration*Ht)),Ht),o=a.createBufferSource();o.buffer=i,o.connect(a.destination),o.start();let s=It((await a.startRendering()).getChannelData(0),Ht),c=h.trollboxEdit.checked,l=new URLSearchParams(c?{}:{server:n.server,channel:n.channel}),u=navigator.language.slice(0,2).toLowerCase();/^[a-z]{2}$/.test(u)&&l.set(`language`,u);let d=await r(`${q}/api/v1/speech/transcribe?${l.toString()}`,{method:`POST`,headers:{"content-type":`audio/wav`},body:new Blob([s.buffer],{type:`audio/wav`})}),f=await d.json().catch(()=>({}));if(!d.ok){na(f.error??`nixamp.com could not hear that.`);return}let p=(f.text??``).trim();if(p===``){na(`Heard nothing. Try again, closer to the mic.`);return}if(c||!f.message){let e=h.trollboxInput.value.trimEnd();h.trollboxInput.value=(e===``?p:`${e} ${p}`).slice(0,500),na(`Heard: “${p}”. Send it, or fix it first.`);return}Yi()&&!hi.has(f.message.id)&&(hi.add(f.message.id),h.trollboxList.append(Qi(f.message)),fi=f.message.createdAt),na(`Said: “${f.message.body}”`)}catch{na(`That recording could not be read here.`)}finally{vi=!1,h.trollboxMic.disabled=!1,h.trollboxMic.textContent=`🎤`}}}}h.trollboxMic.addEventListener(`click`,()=>{_i?ra(!0):ia()});try{h.trollboxEdit.checked=localStorage.getItem(`nixamp.dictate.edit`)===`on`}catch{}h.trollboxEdit.addEventListener(`change`,()=>{try{localStorage.setItem(`nixamp.dictate.edit`,h.trollboxEdit.checked?`on`:`off`)}catch{}na(h.trollboxEdit.checked?`A line you say will wait in the box for Send.`:`A line you say goes straight to the room.`)});async function oa(){try{let e=await r(`${q}/api/v1/me/profile/fields`),t=await e.json().catch(()=>({}));if(!e.ok){h.contactNote.textContent=t.error??`Could not read your details.`;return}for(let e of Kn){let n=h.contactForm.elements.namedItem(e);n instanceof HTMLInputElement&&(n.value=t.profile?.[e]??``)}h.contactNote.textContent=`Your name and work details. Only you see these.`}catch{h.contactNote.textContent=`Could not reach nixamp.com for your details.`}}h.contactForm.addEventListener(`submit`,e=>{e.preventDefault(),h.contactNote.textContent=`Saving…`,(async()=>{try{let e=await r(`${q}/api/v1/me/profile/fields`,{method:`PATCH`,headers:{"content-type":`application/json`},body:JSON.stringify(Jn(h.contactForm))}),t=await e.json().catch(()=>({}));h.contactNote.textContent=e.ok?`Saved.`:Object.values(t.errors??{})[0]??t.error??`that did not save`}catch{h.contactNote.textContent=`Could not reach nixamp.com.`}})()});async function sa(){try{let e=await r(`${q}/api/v1/me/handle`),t=await e.json().catch(()=>({}));if(!e.ok){h.personaNote.textContent=t.error??`Could not read your profile.`;return}h.personaHandle.value=t.chosen?t.handle??``:``,w(h.personaHandle,`placeholder`,()=>t.handle||v(`handle`)),h.personaVoice.value=t.voice===`female`||t.voice===`male`?t.voice:``,h.personaProfile.value=t.profile??``;let n=t.spoken?` (${t.spoken.replace(/^Telnyx\.KokoroTTS\./,`Kokoro `).replace(/^ElevenLabs\./,`ElevenLabs `)})`:``;h.personaNote.textContent=t.chosen?`You are ${t.handle} in every room. On the phone your lines are read ${ca(t.voice??``)}${n}.`:`Rooms call you ${t.handle} until you pick a handle. On the phone your lines are read ${ca(t.voice??``)}${n}.`}catch{h.personaNote.textContent=`Could not reach nixamp.com for your profile.`}}function ca(e){return e===`female`?`in a woman's voice`:e===`male`?`in a man's voice`:e.includes(`.`)?`in the voice ${e}`:`in whichever voice your profile says, or one picked for you`}h.personaForm.addEventListener(`submit`,e=>{e.preventDefault();let t=h.personaHandle.value.trim(),n={voice:h.personaVoice.value,profile:h.personaProfile.value.trim()};t!==``&&(n.handle=t),h.personaNote.textContent=`Saving…`,(async()=>{try{let e=await r(`${q}/api/v1/me/handle`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify(n)}),t=await e.json().catch(()=>({}));if(!e.ok){h.personaNote.textContent=t.error??`that did not save`;return}await sa()}catch{h.personaNote.textContent=`Could not reach nixamp.com.`}})()}),document.addEventListener(`visibilitychange`,()=>{document.visibilityState!==`visible`&&_i&&ra(!0)});function la(){return y===`remote`&&O?{id:O.id,name:O.name,hls:O.video&&F()}:I.loaded||M?{id:Ti,name:Sn()||`This audio`,hls:!1}:null}function ua(){Bi(),Ei=null,bi.clear(),xi.clear(),Wi?.close(),Wi=null,Ji&&clearInterval(Ji),Ji=null,Ki=[],qi=[],h.transcriptList.replaceChildren(),h.subtitle.hidden=!0,h.subtitle.textContent=``}function da(){let e=la(),t=`${e?.id??``}|${I.mediaKey}|${yi}|${J}|${h.transcriptAudio.checked}|${X}|${Y}`;if(t!==Ui){if(Ui=t,ua(),h.transcriptPanel.hidden=!1,h.transcriptOn.checked=yi&&(!!O||X||h.transcriptAudio.checked),h.transcriptLanguage.options.length===0)for(let e of Jt){let t=new Option(e.label,e.code);e.code&&(t.lang=e.code),C(t,()=>e.code?e.label:v(`Original (auto-detect)`)),h.transcriptLanguage.append(t)}h.transcriptLanguage.value=J,ga(),_a(),e?yi?Di?h.transcriptNote.textContent=Di:(h.transcriptNote.textContent=`Asking for ${e.name}'s captions…`,h.transcriptAudio.checked||X?I.playing?Vi():h.transcriptNote.textContent=`Press Play to start listening.`:y===`remote`&&O?fa(e,t):h.transcriptNote.textContent=`Turn on captions to transcribe this audio.`):h.transcriptNote.textContent=`Captions are off.`:h.transcriptNote.textContent=`Play something to see its captions.`}}async function fa(e,t){let n=6,i=J?`?language=${encodeURIComponent(J)}`:``;try{let a=await r(L.url(`/api/channels/${encodeURIComponent(e.id)}/transcript${i}`)),o=await a.json().catch(()=>({}));if(t!==Ui)return;if(!a.ok){h.transcriptNote.textContent=o.error??`This server is not captioning.`;return}if(o.recognitionRevision!==`native-v2`){Y&&q===``?(X=!0,da()):h.transcriptNote.textContent=`This broadcaster needs an update for native captions. Sign in to transcribe the audio on this device.`;return}n=o.backlog??n}catch{t===Ui&&(h.transcriptNote.textContent=`The server did not answer about captions.`);return}Gi=Zt(n,e.hls);let a=new EventSource(L.url(`/api/channels/${encodeURIComponent(e.id)}/captions${i}`));Wi=a;let o=(e,t=!1)=>{for(let n of e){if(!n||typeof n.text!=`string`||!Number.isFinite(n.at)||!Number.isFinite(n.until))continue;let e=`${n.at}|${n.language}`;bi.has(e)||(bi.add(e),bi.size>600&&bi.delete(bi.values().next().value),Ki.push(n),t&&h.transcriptAudio.checked&&xi.add(n))}};a.addEventListener(`hello`,r=>{if(t!==Ui)return;let i=JSON.parse(r.data);Gi=Zt(i.backlog??n,e.hls),o(i.lines??[]);let a=Jt.find(e=>e.code===i.language)?.label??i.language,s=Jt.find(e=>e.code===J)?.label??J;if(h.transcriptNote.textContent=i.error?`Captions unavailable: ${i.error}`:J?`${a||`Detected audio`} → ${s}`:`Original audio · ${a||`detecting language…`}`,!i.error&&i.hash&&/^[0-9a-f]{64}$/.test(i.hash)){let e=document.createElement(`a`);e.href=`${q||``}/hash/${i.hash}`,e.textContent=`Its page`,e.target=`_blank`,e.rel=`noopener`,h.transcriptNote.append(` `,e,`.`)}}),a.addEventListener(`line`,n=>{if(t!==Ui)return;let r=JSON.parse(n.data);o([r],!0);let i=r.sourceLanguage??(r.original===void 0?r.language:``),a=Jt.find(e=>e.code===i)?.label??i,s=Jt.find(e=>e.code===J)?.label??J;h.transcriptNote.textContent=J?`${e.name} · ${a||`Detected audio`} → ${s}`:`${e.name} · Original audio language: ${a||`detecting…`}`}),a.addEventListener(`error`,()=>{t===Ui&&a.readyState===EventSource.CLOSED&&(h.transcriptNote.textContent=`Captions stopped; the server went away.`)}),Ji=setInterval(ma,250)}function pa(e){let t=document.createElement(`li`),n=document.createElement(`time`);n.className=`when`,n.dateTime=new Date(e.at).toISOString(),C(n,()=>tn(e.at));let r=document.createElement(`span`);r.className=`line`,r.textContent=e.text,r.dir=`auto`,r.translate=!1,(e.language||e.sourceLanguage)&&(r.lang=e.language||e.sourceLanguage);let i=Xt(e);if(i){let a=document.createElement(`span`);a.className=`lang`,a.textContent=i.trim(),e.original&&(r.title=e.original),t.append(n,a,r)}else t.append(n,r);return t}function ma(){let e=Date.now(),{ready:t,still:n}=Qt(Ki,e,Gi);Ki=n;for(let e of t)if(qi.push(e),h.transcriptList.append(pa(e)),xi.delete(e)&&h.transcriptAudio.checked&&J){let t=new URLSearchParams({at:String(e.at),language:J,voice:`auto`});Z.push(e,L.url(`/api/channels/${encodeURIComponent(e.channel)}/voice?${t}`),Gi)}for(;qi.length>200;)qi.shift();for(;h.transcriptList.children.length>200;)h.transcriptList.firstElementChild?.remove();let r=$t(qi,e,Gi),i=h.transcriptList.children,a=r?qi.indexOf(r):-1;for(let e=0;e<i.length;e++)i[e]?.classList.toggle(`now`,e===a);let o=I.playing&&r!==null&&!h.video.hidden&&h.video.offsetHeight>0;h.subtitle.hidden=!o,o&&r&&(h.subtitle.textContent!==r.text&&(h.subtitle.textContent=r.text),h.subtitle.style.top=`${h.video.offsetTop+h.video.offsetHeight-h.subtitle.offsetHeight-10}px`)}h.transcriptOn.addEventListener(`change`,()=>{yi=h.transcriptOn.checked,X=yi&&(!O||h.transcriptAudio.checked),yi||(h.transcriptAudio.checked=!1,Z.disable());try{localStorage.setItem(Kt,yi?`on`:`off`)}catch{}da()}),h.transcriptLanguage.addEventListener(`change`,()=>{Di=``,wi=``,J=Yt(()=>h.transcriptLanguage.value),!J&&h.transcriptAudio.checked&&(h.transcriptAudio.checked=!1,X=!1,Z.disable());try{J?localStorage.setItem(qt,J):localStorage.removeItem(qt)}catch{}da()});function ha(){if(J)return J;let e=navigator.language.split(`-`)[0]||`en`;return Jt.some(t=>t.code===e)&&Si?.languages.includes(e)?e:`en`}function ga(){let e=Y!==``&&q===``,t=e&&Ii.loaded()&&!!la()&&!!Si?.languages.includes(ha());h.transcriptAudio.disabled=!t,h.transcriptVoiceSettings.contains(document.activeElement)||(h.transcriptVoiceSettings.hidden=!h.transcriptAudio.checked),t?h.transcriptAudio.checked||C(h.transcriptAudioNote,()=>wi||v(`Original audio.`)):(h.transcriptAudio.checked=!1,Z.disable(),h.transcriptAudioNote.textContent=e?la()?Ii.loaded()?wi||(Si?`Audio translation is unavailable for this language.`:`Loading voices…`):Ii.loadingMessage():`Play something to translate its audio.`:`Sign in to translate audio.`)}async function _a(){if(!Y||q!==``)return;let e=`/api/v1/speech/voices`;if(Ci!==e){Ci=e,Si=null,wi=``,ga();try{let t=await r(e,{signal:AbortSignal.timeout(1e4)}),n=await t.json();if(Ci!==e)return;if(!t.ok)throw Error(n.error||`Translated audio is unavailable on this server.`);if(!Array.isArray(n.voices)||!Array.isArray(n.languages))throw Error(`This server needs an update for translated audio.`);Si=n}catch(t){if(Ci!==e)return;wi=t instanceof Error?t.message:`Translated audio is unavailable.`}ga()}}h.transcriptBackground.addEventListener(`change`,()=>{Fi();try{localStorage.setItem(`nixamp.backgroundSound`,h.transcriptBackground.checked?`on`:`off`)}catch{}if(Pi.stop(),Ni=!1,h.transcriptBackground.checked&&h.transcriptAudio.checked&&I.playing){let e=ji,t=I.audioInput();Pi.start(t.context,t.node).then(t=>{t&&e===ji&&Pi.active(Mi&&I.playing&&h.transcriptBackground.checked)})}}),h.transcriptAudio.addEventListener(`change`,()=>{if(Di=``,wi=``,xi.clear(),h.transcriptAudio.checked&&!Ii.ready())h.transcriptAudio.checked=!1,Ii.open(h.transcriptAudio);else{if(h.transcriptAudio.checked){J=ha();try{localStorage.setItem(qt,J)}catch{}yi=!0,X=!0,Z.enable()}else X=!1,Z.disable();da()}});function va(){if(M)return M.url;if(y!==`remote`)return``;let{base:e,key:t}=m(ds());if(e===``)return``;if(O)return ee(e,`/api/channels/${encodeURIComponent(O.id)}`,t);if(A?.kind===`live`)return ee(e,`/api/live`,t);if(I.source===``)return``;try{let n=new URL(I.source);return n.origin===new URL(e).origin?(t?n.searchParams.set(`k`,t):n.searchParams.delete(`k`),n.toString()):``}catch{return``}}function ya(){let e=va();return e===``?``:`https://nixamp.com/?play=${encodeURIComponent(e)}`}function ba(){return y===`remote`?O?us(`channel:${O.id}`):A?.kind===`live`||B()?us(`live`):``:``}h.shareNow.addEventListener(`click`,()=>{let e=ya();if(e===``)return;let t=navigator;typeof t.share==`function`?t.share({title:`${yn()} on nixamp`,url:e}).catch(()=>void 0):ls(e,h.shareNow,`Copied`)}),h.copyNixamp.addEventListener(`click`,()=>{let e=ba();e!==``&&ls(e,h.copyNixamp,`✓`)});function xa(){let e=ba();if(e!==``)return e;let t=wa();return t===null?``:us(`track:${t}`)}async function Sa(){let e=xa();if(e===``||h.schoolLive.disabled)return;let t=h.schoolLive.textContent;h.schoolLive.disabled=!0,h.schoolLive.textContent=`Opening a classroom…`;let n={"content-type":`application/json`};try{let t=await r(`/api/v1/events`,{method:`POST`,headers:n,body:JSON.stringify({kind:`class`,title:We(yn())||`Live class`,broadcastUrl:e,visibility:`public`})}),i=await t.json().catch(()=>({}));if(!t.ok||!i.event)throw Error(i.error??`the class could not be made`);let a=i.event,o=await r(`/api/v1/events/${encodeURIComponent(a.id)}/start`,{method:`POST`,headers:n,body:JSON.stringify({version:a.version})}),s=`https://backtoschool.help/live/${encodeURIComponent(a.slug)}`;D=o.ok?`Your class is live on backtoschool.help: ${s}`:`The class is made but not started yet. Open it to start: ${s}`,U(),globalThis.open(s,`_blank`,`noopener`)}catch(e){D=`Could not open a classroom: ${e.message}`,U()}finally{h.schoolLive.disabled=!1,h.schoolLive.textContent=t}}h.schoolLive.addEventListener(`click`,()=>{Sa()});function Ca(){if(y!==`remote`)return``;let e=/^(https:\/\/[^/]+)\/view\/([A-Za-z0-9_-]+)\/?$/.exec(ds());return e?O?`${e[1]}/api/channels/${encodeURIComponent(O.id)}?k=${e[2]}`:A?.kind===`live`||B()?`${e[1]}/api/live?k=${e[2]}`:``:``}function wa(){if(y!==`remote`||O||A?.kind===`live`||B()||!/^https:\/\/[^/]+\/view\/[A-Za-z0-9_-]+\/?$/.test(ds()))return null;let e=z();return E.tracks?.[e]?e:null}async function Ta(e){let t=/^(https:\/\/[^/]+)\/view\/([A-Za-z0-9_-]+)\/?$/.exec(ds());if(!t)throw Error(`this server has no view link to share`);let n=await r(`${t[1]}/api/media/${e}/item?k=${t[2]}`,{cache:`no-store`}),i=await n.json().catch(()=>({}));if(n.status===404&&i.error===`no such track`)throw Error("this server needs nixamp 0.48 or newer; run `nixamp update` on it");if(!n.ok||!i.id)throw Error(i.error??`that file is not in the server's library`);return`${t[1]}/api/v1/library/items/${i.id}/play?k=${t[2]}`}let Ea=H(`streaming-publish-note`),Da=H(`streaming-publish-title-input`),Oa=H(`streaming-publish-basis`),ka=H(`streaming-publish-agree`),Aa=H(`streaming-publish-go`);h.streamingLive.addEventListener(`click`,()=>{(Ca()!==``||wa()!==null)&&(Da.value=yn(),Ea.textContent=``,h.streamingPublish.showModal())}),H(`streaming-publish-close`).addEventListener(`click`,()=>h.streamingPublish.close()),H(`streaming-publish-form`).addEventListener(`submit`,e=>{e.preventDefault(),ja()});async function ja(){let e=Ca(),t=e===``?wa():null;if(!(e===``&&t===null||Aa.disabled)){if(!ka.checked)Ea.textContent=`Tick the box to confirm you may broadcast it.`;else{Aa.disabled=!0,Ea.textContent=`Publishing…`;try{let n=e||await Ta(t),i=await r(`https://live.streaming.pit.world/api/v1/guide/${e?`rooms`:`vods`}`,{method:`POST`,headers:{"content-type":`application/json`,authorization:`Bearer ${L.session}`},body:JSON.stringify({play:n,basis:Oa.value,title:Da.value.trim(),agree:!0})}),a=await i.json().catch(()=>({}));if(!i.ok||!a.page)throw Error(a.error??`it could not be published`);h.streamingPublish.close(),D=e?`Live on live.streaming: ${a.page}`:`On demand on live.streaming: ${a.page}`,navigator.clipboard?.writeText(a.page).catch(()=>void 0),U(),globalThis.open(a.page,`_blank`,`noopener`)}catch(e){Ea.textContent=`Could not publish: ${e.message}`}finally{Aa.disabled=!1}}}}h.favHere.addEventListener(`click`,()=>{let e=ds()||L.shareLink;if(!e)return;let t=[...ri].find(t=>K(t)===K(e))??e;oi(ii(e)?t:e,b||L.address,!ii(e)).then(ci)});let Ma=se?le:200,Na=[],Q=null,Pa=null,Fa=``,Ia=[],La=0,Ra=null,za=0,Ba=null,Va=null,Ha=new Map;function Ua(e,t){za++,Ba?.abort(),Ra&&clearTimeout(Ra),Ra=null,Le(h.catalogsList),Le(h.catalogsEntries),Q=e,Pa=t,Fa=``,h.catalogsFilter.value=``,Ia=[],La=0,h.catalogsEntries.setAttribute(`aria-busy`,`false`),qa(),e&&t!==null&&Qa(0)}function Wa(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`}function Ga(){let e=L.url(`/api/catalogs`);if(Va?.url===e)return Va.promise;let t=Ka(e).finally(()=>{Va?.promise===t&&(Va=null)});return Va={url:e,promise:t},t}async function Ka(e){if(y!==`remote`){h.catalogsPanel.hidden=!0;return}let t;try{t=await r(e)}catch{e===L.url(`/api/catalogs`)&&(h.catalogsPanel.hidden=!0);return}y===`remote`&&e===L.url(`/api/catalogs`)&&(t.ok?(Na=(await t.json().catch(()=>({}))).catalogs??[],Q&&=Na.find(e=>e.id===Q?.id)??null,Q||(Pa=null),h.catalogsPanel.hidden=!1,qa()):h.catalogsPanel.hidden=!0)}function qa(){let e=!h.adminPanel.hidden;h.catalogsForm.hidden=!e;let t=Na.reduce((e,t)=>e+t.live,0),n=Na.reduce((e,t)=>e+t.vod,0);h.catalogsNote.textContent=Na.length===0?e?`No catalogs yet. Add an m3u list of channels or films.`:`No catalogs yet.`:`${Na.length} ${Na.length===1?`catalog`:`catalogs`} · ${t} live ${t===1?`channel`:`channels`} · ${n} on demand`,Ja();let r=Q!==null&&Pa!==null;h.catalogsList.hidden=r,h.catalogsFilter.hidden=!r,h.catalogsEntries.hidden=!r,r?$a():Q?Xa(Q):k(h.catalogsList,...Na.map(t=>Ya(t,e)))}function Ja(){let e=Q!==null;if(h.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},n=()=>{let e=document.createElement(`span`);return e.textContent=`/`,e},r=[t(`All catalogs`,()=>Ua(null,null),!1),n(),t(Q?.name??``,()=>Ua(Q,null),Pa===null)];Pa!==null&&r.push(n(),t(Pa===``?`All groups`:Pa,()=>void 0,!0)),h.catalogsCrumbs.replaceChildren(...r)}function Ya(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`,C(a,()=>[`${e.entries.toLocaleString(_.language)} ${e.entries===1?`entry`:`entries`}`,`${e.live.toLocaleString(_.language)} live`,`${e.vod.toLocaleString(_.language)} on demand`,`refreshed ${Wa(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.setAttribute(`aria-label`,`Browse ${e.name}`),o.addEventListener(`click`,()=>{Ua(e,null)}),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`,()=>{to(e)});let r=document.createElement(`button`);r.type=`button`,r.className=`ghost`,C(r,()=>v(`Remove`)),r.title=`Take this catalog off the server`,r.addEventListener(`click`,()=>{confirm(`Remove ${e.name} from this server?`)&&cs(n,r,()=>no(e),()=>void Ga())}),n.append(t,r)}return n}async function Xa(e){let t=L.url(`/api/catalogs/${encodeURIComponent(e.id)}/groups`),n=`${t}:${e.refreshedAt}:${e.entries}`,i;h.catalogsList.setAttribute(`aria-busy`,`true`);try{let e=Ha.get(n);e||(Ha.size>=20&&Ha.delete(Ha.keys().next().value),e=r(t).then(async e=>{if(!e.ok)throw Error(String(e.status));return(await e.json()).groups??[]}),Ha.set(n,e)),i=await e}catch{if(Ha.delete(n),Q?.id!==e.id||Pa!==null||t!==L.url(`/api/catalogs/${encodeURIComponent(e.id)}/groups`))return;h.catalogsList.setAttribute(`aria-busy`,`false`),D=`Could not read the groups in ${e.name}.`,U();return}if(Q?.id!==e.id||Pa!==null||t!==L.url(`/api/catalogs/${encodeURIComponent(e.id)}/groups`))return;h.catalogsList.setAttribute(`aria-busy`,`false`);let a=[Za(`All groups`,``,e.entries,e.live,e.vod),...i.map(e=>Za(e.name||`(no group)`,e.name,e.count,e.live,e.vod))];k(h.catalogsList,...a)}function Za(e,t,n,r,i){let a=document.createElement(`li`),o=document.createElement(`span`);o.className=`server-label`;let s=document.createElement(`span`);s.className=`name`,s.textContent=e;let c=document.createElement(`span`);c.className=`detail`,C(c,()=>`${n.toLocaleString(_.language)} · ${r.toLocaleString(_.language)} live · ${i.toLocaleString(_.language)} on demand`),o.append(s,c);let l=document.createElement(`button`);return l.type=`button`,l.className=`button`,l.textContent=`Open`,l.setAttribute(`aria-label`,`Open ${e}`),l.addEventListener(`click`,()=>{Ua(Q,t)}),a.append(o,l),a}async function Qa(e){let t=Q,n=Pa;if(!t||n===null)return;let i=++za;Ba?.abort();let a=new AbortController;Ba=a;let o=L.url(`/api/catalogs`);h.catalogsEntries.setAttribute(`aria-busy`,`true`);let s=new URLSearchParams({group:n,q:Fa,offset:String(e),limit:String(Ma)}),c;try{let e=await r(L.url(`/api/catalogs/${encodeURIComponent(t.id)}/entries?${s}`),{signal:a.signal});if(!e.ok)throw Error(String(e.status));c=await e.json()}catch{if(a.signal.aborted||i!==za)return;h.catalogsEntries.setAttribute(`aria-busy`,`false`),D=`Could not read ${t.name}.`,$a(),U();return}i===za&&Q?.id===t.id&&Pa===n&&o===L.url(`/api/catalogs`)&&(h.catalogsEntries.setAttribute(`aria-busy`,`false`),La=c.total??0,Ia=e===0?c.entries??[]:[...Ia,...c.entries??[]],$a())}function $a(){let e=Q;if(!e)return;let t=Ia.map(t=>{let n=document.createElement(`li`);n.className=`row`;let r=document.createElement(`span`);r.className=`name`,r.textContent=t.title;let i=document.createElement(`span`);i.className=t.live?`catalog-tag catalog-live`:`catalog-tag`,i.textContent=t.live?`LIVE`:t.duration>0?je(t.duration):`VOD`;let a=document.createElement(`button`);if(a.type=`button`,a.className=`row-main`,a.setAttribute(`aria-label`,`Play ${t.title}`),a.append(r,i),n.append(a),a.addEventListener(`click`,()=>{eo(e,t,n)}),!t.live){let r=document.createElement(`button`);r.type=`button`,r.className=`row-copy`,g(r,`copy`),r.title=`Copy this entry's URL`,r.setAttribute(`aria-label`,`Copy the URL of ${t.title}`),r.addEventListener(`click`,n=>{n.stopPropagation();let i=`/api/catalogs/${encodeURIComponent(e.id)}/entries/${encodeURIComponent(t.id)}/stream`;ls(L.url(i),r,`✓`)}),n.append(r)}return Lt()&&n.append(nn(()=>({kind:`entry`,catalog:{id:e.id,name:e.name},entry:t}),t.title)),n});if(Ia.length===0){let e=document.createElement(`li`);e.className=`group`;let n=document.createElement(`span`);n.className=`group-name`,n.textContent=Fa?`Nothing called "${Fa}" here.`:`Nothing in this group.`,e.append(n),t.push(e)}else if(Ia.length<La){let e=document.createElement(`li`);e.className=`group`;let n=document.createElement(`button`);n.type=`button`,n.className=`ghost`,C(n,()=>`Show more (${Ia.length.toLocaleString(_.language)} of ${La.toLocaleString(_.language)})`),n.addEventListener(`click`,e=>{e.stopPropagation(),Le(h.catalogsEntries,!1),n.disabled=!0,Qa(Ia.length)}),e.append(n),t.push(e)}k(h.catalogsEntries,...t)}async function eo(e,t,n){n?.classList.add(`loading`),D=`Starting ${t.title}…`;let i={catalog:{id:e.id,name:e.name},entry:t};try{await Ge(async()=>{let n,a={};try{n=await r(L.url(`/api/catalogs/${encodeURIComponent(e.id)}/entries/${encodeURIComponent(t.id)}/play`),{method:`POST`}),a=await n.json().catch(()=>({}))}catch{D=`could not reach the server`;return}if(!n.ok){D=a.error??`${t.title} would not play.`;return}let o=a.name||t.title;a.kind===`live`&&a.channel?await ns({id:a.channel,name:o,video:!0},!0,{kind:`channel`,...i}):a.kind===`vod`&&a.url?(O=null,ke=-1,A={kind:`vod`,...i},it(o,`title`),await I.load({title:o,artist:``,album:``,duration:0,url:L.url(a.url),video:!0,objectUrl:!1},!0),hr(!0),D=`Playing ${o}.`):D=`${t.title} would not play.`})}finally{n?.classList.remove(`loading`),U()}}async function to(e){G(`Reading ${e.name} again…`);try{let t=await r(L.url(`/api/catalogs/${encodeURIComponent(e.id)}/refresh`),{method:`POST`}),n=await t.json().catch(()=>({}));G(t.ok?`${n.catalog?.name??e.name}: ${(n.catalog?.entries??0).toLocaleString(_.language)} entries.`:n.error??`that did not work`)}catch{G(`could not reach the server`)}Ga()}async function no(e){try{let t=await r(L.url(`/api/catalogs/${encodeURIComponent(e.id)}`),{method:`DELETE`});if(G(t.ok?`${e.name} is off the server.`:`that did not work`),!t.ok)return!1}catch{return G(`could not reach the server`),!1}return Q?.id===e.id&&(Q=null,Pa=null),!0}h.catalogsForm.addEventListener(`submit`,e=>{e.preventDefault();let t=h.catalogSource.value.trim(),n=h.catalogName.value.trim();t&&(async()=>{G(`Reading ${n||t}…`);try{let e=await r(L.url(`/api/catalogs`),{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({source:t,name:n})}),i=await e.json().catch(()=>({}));if(!e.ok){G(i.error??`that did not work`);return}G(`${i.catalog?.name??n??t}: ${(i.catalog?.entries??0).toLocaleString(_.language)} entries.`),h.catalogSource.value=``,h.catalogName.value=``}catch{G(`could not reach the server`)}Ga()})()}),h.catalogsFilter.addEventListener(`input`,()=>{za++,Ba?.abort(),Ra&&clearTimeout(Ra),Ra=setTimeout(()=>{Ra=null,Fa=h.catalogsFilter.value.trim(),Qa(0)},250)});let ro=async()=>{k(h.serversList);try{let e=await r(`/api/v1/servers`);if(!e.ok){h.serversPanel.hidden=!0;return}let t=(await e.json()).servers??[];xe=new Map(t.map(e=>[K(e.url),e.key?`${e.url}/admin/${e.key}`:e.url])),h.serversPanel.hidden=!1,h.serversNote.textContent=t.length===0?"No servers yet. `nixamp server add --here` remembers the one you are running.":`The machines on your account. Arriving signed in, this page connects to your default one, or the first that answers; a link you arrive with goes live there.`;for(let e of t){let t=document.createElement(`li`),n=document.createElement(`span`);n.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,n.append(i,a);let o=e.key?`${e.url}/admin/${e.key}`:e.url,[s,c]=S({name:e.name,view:o,admin:o});te(e.url).then(n=>{n===null?(a.textContent=`${e.url} · not answering`,t.classList.add(`offline`),s.disabled=!0,c.disabled=!0,s.title=c.title=`That machine is not answering. Start nixamp on it.`):a.textContent=`${e.url} · ${n}`});let l=xo()===K(e.url),u=document.createElement(`button`);u.type=`button`,u.className=`ghost`,u.textContent=l?`✓ Default`:`Make default`,u.title=l?`The server this page connects to when you arrive signed in. Press to go back to the first that answers.`:`Connect to this server whenever you arrive signed in`,u.addEventListener(`click`,()=>{So(l?``:K(e.url)),ro()});let d=document.createElement(`button`);d.type=`button`,d.className=`ghost`,d.textContent=`Forget`,d.addEventListener(`click`,()=>{(async()=>{d.disabled=!0;try{await r(`/api/v1/servers/${encodeURIComponent(e.id)}`,{method:`DELETE`}),await ro()}catch{d.disabled=!1}})()}),t.append(n,s,c,u,d),h.serversList.append(t)}}catch{h.serversPanel.hidden=!0}},io=async()=>{k(h.followingList);try{let e=await r(`/api/v1/follows`);if(!e.ok){h.followingNote.hidden=!0;return}let t=(await e.json()).following??[];h.followingNote.hidden=t.length===0;for(let e of t){let t=document.createElement(`li`),n=document.createElement(`span`);n.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`,n.append(i,a);let o=document.createElement(`button`);o.type=`button`,o.className=`ghost follow`,C(o,()=>v(`Unfollow`)),o.addEventListener(`click`,()=>{(async()=>{o.disabled=!0;try{await r(`/api/v1/follows/${encodeURIComponent(e.id)}`,{method:`DELETE`}),t.remove(),h.followingList.children.length===0&&(h.followingNote.hidden=!0)}finally{o.disabled=!1}})()}),t.append(n,o),h.followingList.append(t)}}catch{h.followingNote.hidden=!0}},ao=(e,t)=>{let n=document.createElement(`button`);n.type=`button`,n.className=`ghost follow`,C(n,()=>v(`Follow`)),n.setAttribute(`aria-label`,`Follow ${t}`);let i=e=>{C(n,()=>e?`Following`:v(`Follow`)),n.dataset.following=e?`yes`:`no`};return(async()=>{try{let t=await r(`/api/v1/follows/${encodeURIComponent(e)}`);t.ok&&i((await t.json()).following===!0)}catch{}})(),n.addEventListener(`click`,()=>{(async()=>{let t=n.dataset.following===`yes`;n.disabled=!0;try{(await r(`/api/v1/follows/${encodeURIComponent(e)}`,{method:t?`DELETE`:`PUT`,headers:{"content-type":`application/json`},body:t?void 0:`{}`})).ok&&(i(!t),io())}catch{}finally{n.disabled=!1}})()}),n},oo=async()=>{let e=s();if(!e.supported)return h.notifyNote.textContent=e.message,!1;try{return await a({vapidKeyUrl:`/api/v1/notify/key`,serviceWorkerUrl:`/sw.js`,saveUrl:`/api/v1/notify/subscribe`}),h.notifyNote.textContent=`This device will be told.`,!0}catch(e){return h.notifyNote.textContent=e instanceof c&&e.reason!==`save-failed`?e.message:`Could not set this device up.`,!1}},so=async()=>{try{await i({removeUrl:`/api/v1/notify/subscribe`})}catch{}},co=async e=>{try{let t=await r(`/api/v1/notify/prefs`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify(e)}),n=await t.json();h.notifyPhoneNote.textContent=t.ok?``:n.error??`that did not save`,t.ok&&typeof n.phone==`string`&&(h.notifyPhone.value=n.phone)}catch{h.notifyPhoneNote.textContent=`could not reach nixamp.com`}},lo=async()=>{try{let e=await r(`/api/v1/notify/prefs`);if(!e.ok)return;let t=await e.json();h.notifyEmail.checked=t.wantsEmail!==!1,h.notifySms.checked=t.wantsSms===!0,h.notifyPhone.value=t.phone??``;let n=s(),i=n.supported&&n.permission===`granted`?await o()!==null:!1;h.notifyWeb.checked=t.wantsWeb!==!1&&i,h.notifyNote.textContent=i?`Get told when someone you follow goes live.`:n.message??`Turn on “On this device” to be told here.`}catch{}};h.notifyWeb.addEventListener(`change`,()=>{(async()=>{if(h.notifyWeb.checked){let e=await oo();h.notifyWeb.checked=e,await co({wantsWeb:e})}else await so(),await co({wantsWeb:!1}),h.notifyNote.textContent=`Turn on “On this device” to be told here.`})()}),h.notifyEmail.addEventListener(`change`,()=>{co({wantsEmail:h.notifyEmail.checked})}),h.notifySms.addEventListener(`change`,()=>{(async()=>{h.notifySms.checked&&!h.notifyPhone.value.trim()?(h.notifyPhoneNote.textContent=`Add a phone number first.`,h.notifySms.checked=!1):await co({wantsSms:h.notifySms.checked})})()}),h.notifyPhoneForm.addEventListener(`submit`,e=>{e.preventDefault(),co({phone:h.notifyPhone.value.trim()})});let uo=!1,fo=!1,po=`nixamp.welcome`,mo=()=>{let e=!1;try{e=localStorage.getItem(po)===`hidden`}catch{}h.welcome.hidden=!fo||Y!==``||e},ho=!1,go=()=>{if(ho||!fo||location.pathname.replace(/\/+$/,``)===``)return;ho=!0,h.adnet.dataset.adNetwork=`SSXBxU06ZRXMrzpJ`,h.adnet.dataset.slot=`514646f2-8299-40c1-9d9e-37d60d2d5892`,h.adnet.dataset.format=`text_link`,h.adnet.setAttribute(`data-cp-ad`,``),h.adnet.hidden=!1;let e=()=>window.crawlproofAds;if(!document.querySelector(`script[src="https://crawlproof.com/ad.js"]`)){let e=document.createElement(`script`);e.src=`https://crawlproof.com/ad.js`,e.async=!0,document.head.append(e)}let t=0,n=()=>{let r=e();r?.scan?r.scan():++t<=25&&setTimeout(n,200)};n()},_o=t=>{document.dispatchEvent(new CustomEvent(`nixamp:account`,{detail:{email:t}}));let n=t!==null;Ii.refresh(),Ci=``,Ei=null,n||(X=!1,h.transcriptAudio.checked=!1,Z.disable(),Bi()),da(),h.notifyPanel.hidden=!n,n?(lo(),io(),ro()):(h.serversPanel.hidden=!0,h.followingNote.hidden=!0,k(h.followingList),h.recentNote.hidden=!0,h.recentList.replaceChildren()),h.accountForm.hidden=n,h.accountProviders.hidden=n||h.accountProviders.childElementCount===0,h.accountSignOut.hidden=!n,h.personaForm.hidden=!n,h.personaNote.hidden=!n,n&&sa(),h.accountProfile.hidden=n||!uo;let r=h.accountProfile.querySelector(`fieldset`);r&&(r.disabled=n||!uo),h.contactForm.hidden=!n,h.contactNote.hidden=!n,n&&oa(),h.accountNote.textContent=n?`Signed in as ${t}.`:uo?`Create an account on nixamp.com.`:`Listening needs no account. Sign in to keep favourites, follow people, and publish.`,C(h.accountSubmit,()=>v(uo?`Create account`:`Sign in`)),C(h.accountToggle,()=>uo?`I have one`:v(`Create one`)),h.accountPassword.autocomplete=uo?`new-password`:`current-password`,h.accountForgot.hidden=uo,e&&(h.accountForgot.target=`_blank`,h.accountForgot.rel=`noopener`),mo()},vo=async()=>{let e=[];fo=!1;try{let t=await r(`/api/v1/auth/providers`);t.ok&&(fo=!0,e=(await t.json()).providers??[])}catch{}h.accountProviders.replaceChildren(),h.accountProviders.hidden=e.length===0,h.accountPanel.hidden=!fo,h.accountElsewhere.hidden=fo,mo(),go();for(let t of e){let e=document.createElement(`a`);e.className=`button`,e.href=`/api/v1/${encodeURIComponent(t.id)}/oauth/start?redirect=${encodeURIComponent(location.pathname+location.search)}`,e.textContent=`Continue with ${t.name}`,h.accountProviders.append(e)}},yo=async()=>{try{let e=await r(`/api/v1/auth/me`),t=await e.json();Y=e.ok?t.account?.id??``:``,_o(e.ok?t.account?.email??`you`:null)}catch{Y=``,_o(null)}if(L.session=``,Y!==``){try{let e=await r(`/api/v1/auth/token`),t=await e.json().catch(()=>({}));L.session=e.ok&&typeof t.token==`string`?t.token:``}catch{L.session=``}y===`remote`&&Br()}ai(),ti(),ni(),Co();let e=await bo();if(xt!==``){let t=xt;xt=``,e?x=`golive:${t}`:_r(t)}};async function bo(){if(Y===``||y===`remote`||bt!==``)return!1;let e=[];try{let t=await r(`/api/v1/servers`);if(!t.ok)return!1;e=(await t.json()).servers??[]}catch{return!1}if(e.length===0)return!1;let t=xo(),n=[...e].sort((e,n)=>Number(K(n.url)===t)-Number(K(e.url)===t));for(let e of n)if(await te(e.url,void 0,e.key)!==null)return y!==`remote`&&(_e=!1,x=``,h.remoteUrl.value=e.key?`${e.url}/admin/${e.key}`:e.url,D=`Connecting to ${e.name}, your server…`,U(),h.remoteForm.requestSubmit(),!0);return!1}function xo(){try{return localStorage.getItem(Vn)??``}catch{return``}}function So(e){try{e===``?localStorage.removeItem(Vn):localStorage.setItem(Vn,e)}catch{}}function Co(){if(bt===``)return;let e=bt;bt=``,h.remoteUrl.value=e,h.remoteForm.requestSubmit()}h.accountToggle.addEventListener(`click`,()=>{uo=!uo,_o(null)}),h.welcomeCreate.addEventListener(`click`,()=>{uo=!0,_o(null),h.accountPanel.scrollIntoView({behavior:`smooth`,block:`center`}),h.accountEmail.focus({preventScroll:!0})}),h.welcomeBrowse.addEventListener(`click`,()=>{h.directory.hidden?h.browse.click():h.directory.scrollIntoView({behavior:`smooth`,block:`nearest`})}),h.welcomeHide.addEventListener(`click`,()=>{try{localStorage.setItem(po,`hidden`)}catch{}h.welcome.hidden=!0}),h.accountForm.addEventListener(`submit`,n=>{n.preventDefault();let i=h.accountEmail.value.trim(),a=h.accountPassword.value;(async()=>{h.accountSubmit.disabled=!0;try{let n=await r(`/api/v1/auth/${uo?`signup`:`login`}`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({email:i,password:a,...uo?Jn(h.accountForm):{}})}),o=await n.json();if(!n.ok){h.accountNote.textContent=o.error??`that did not work`;return}e&&(t=o.token??``),Y=o.account?.id??``,h.accountPassword.value=``,_o(o.account?.email??i),Br(),Co();let s=new URLSearchParams(location.search).get(`redirect`)??``;s.startsWith(`/`)&&!s.startsWith(`//`)&&!s.startsWith(`/\\`)&&location.assign(s)}catch{h.accountNote.textContent=`could not reach nixamp.com`}finally{h.accountSubmit.disabled=!1}})()}),h.accountSignOut.addEventListener(`click`,()=>{(async()=>{try{await r(`/api/v1/auth/logout`,{method:`POST`})}catch{}t=``,Y=``,_o(null),ti(),L.close(),ke=-1,y=`local`,Ee=`idle`,De=``,h.remoteUrl.value=``,h.sharePanel.hidden=!0,h.publishPanel.hidden=!0,h.adminPanel.hidden=!0,h.catalogsPanel.hidden=!0,h.listenOnly.hidden=!0,Xo(!1);try{localStorage.removeItem(Bn)}catch{}D=`Signed out, and disconnected from the server.`,Br(),U()})()});try{let e=new URL(globalThis.location.href).searchParams,t=e.get(`url`)??``;t!==``&&(bt=t,x=e.get(`play`)??``,be=Math.max(0,Number(e.get(`t`)??`0`)||0),h.remoteUrl.value=t,D=`Opening the stream you were sent…`,globalThis.history?.replaceState(null,``,globalThis.location.pathname));let n=e.get(`link`)??``;n!==``&&(h.linkUrl.value=n,t!==``&&x===``?x=`link:${n}`:t===``&&(xt=n));let r=e.get(`play`)??``;if(t===``&&/^https?:\/\//i.test(r)){let t=d(r);t?(bt=t.view,x=t.what,be=Math.max(0,Number(e.get(`t`)??`0`)||0),h.remoteUrl.value=t.view,D=`Opening the stream you were sent…`):(h.linkUrl.value=r,xt=r),globalThis.history?.replaceState(null,``,globalThis.location.pathname)}}catch{}let wo=[`zone-top`,`zone-main`],To=e=>e instanceof HTMLElement&&e.matches(`section.panel`)&&e.id!==``,Eo=e=>e.parentElement&&wo.includes(e.parentElement.id)?e.parentElement:null,Do=e=>e.classList.contains(`col-a`)?`a`:e.classList.contains(`col-b`)?`b`:``,Oo=()=>[...document.querySelectorAll(`section.panel`)].filter(e=>To(e)&&Eo(e)!==null),ko=e=>e.dataset.title??e.id,Ao=new Map,jo=Oo().map((e,t)=>(Ao.set(e.id,{zone:Eo(e)?.id??``,col:Do(e),index:t}),e.id)),$=kt();try{$=Mt(localStorage.getItem(Ot))}catch{}let Mo=()=>$.order.length>0||Object.keys($.placement).length>0;function No(){$.order=Oo().map(e=>e.id);try{localStorage.setItem(Ot,Nt($))}catch{}}function Po(e,t,n){e.classList.remove(`col-a`,`col-b`),t.classList.contains(`split`)&&n!==``&&e.classList.add(`col-${n}`),t!==e.parentElement&&t.append(e)}function Fo(){if(e)return;for(let e of Oo()){let t=$.placement[e.id];if(!t)continue;let[n=``,r=``]=t.split(`:`),i=document.getElementById(n);i&&wo.includes(i.id)&&Po(e,i,r===`a`||r===`b`?r:``)}let t=Pt(Oo().map(e=>e.id),$.order);for(let e of wo){let n=document.getElementById(e);if(!n)continue;let r=[...n.children].filter(To),i=r.map(e=>{let t=document.createComment(`panel`);return e.before(t),t});r.sort((e,n)=>t.indexOf(e.id)-t.indexOf(n.id)),r.forEach((e,t)=>i[t]?.replaceWith(e))}for(let e of Oo())e.toggleAttribute(`data-collapsed`,$.collapsed.includes(e.id)),e.toggleAttribute(`data-closed`,$.closed.includes(e.id))}function Io(e,t){e.toggleAttribute(`data-collapsed`,t),e===h.panelsPanel&&h.panelsToggle.setAttribute(`aria-expanded`,String(!t&&!e.hidden&&!e.hasAttribute(`data-closed`))),e.querySelector(`.panel-tools [aria-expanded]`)?.setAttribute(`aria-expanded`,String(!t)),$.collapsed=Ft($.collapsed,e.id,t),No(),Uo()}function Lo(e,t){let n=e.contains(document.activeElement);e.toggleAttribute(`data-closed`,t),!t&&e.dataset.available===`true`&&(e.hidden=!1),e===h.panelsPanel&&t&&(e.hidePopover?.(),e.hidden=!0),e===h.panelsPanel&&h.panelsToggle.setAttribute(`aria-expanded`,String(!t&&!e.hidden&&!e.hasAttribute(`data-collapsed`))),e===h.partiesPanel&&!t&&ti(),t&&n&&h.panelsToggle.focus({preventScroll:!0}),$.closed=Ft($.closed,e.id,t),No(),Uo()}function Ro(e,t,n){let r=Eo(t);r&&e!==t&&(Po(e,r,Do(t)),n?t.after(e):t.before(e),$.placement[e.id]=`${r.id}:${Do(t)}`,No(),Uo())}let zo=null,Bo=()=>{for(let e of Oo())e.classList.remove(`drop-before`,`drop-after`)},Vo=(e,t,n)=>{let r=document.createElement(`button`);return r.type=`button`,r.className=`icon-btn`,r.textContent=e,r.title=t,r.setAttribute(`aria-label`,t),r.addEventListener(`click`,e=>{e.stopPropagation(),n()}),r};function Ho(){for(let e of Oo()){let t=ko(e);e.setAttribute(`aria-label`,t);let n=e.querySelector(`:scope > .panel-heading`);n||(n=document.createElement(`h2`),n.className=`panel-heading`,e.prepend(n));let r=n.querySelector(`.panel-heading-text`);if(!r){r=document.createElement(`span`),r.className=`panel-heading-text`;let e=document.createElement(`span`);e.className=`panel-loading-spinner`,e.setAttribute(`aria-hidden`,`true`),n.replaceChildren(r,e)}if(r.textContent!==t&&(r.textContent=t),e.querySelector(`:scope > .panel-tools`))continue;let i=document.createElement(`span`);i.className=`panel-tools`;let a=Vo(`≡`,`Move ${ko(e)}: Alt plus Up or Down, or drag`,()=>void 0);a.addEventListener(`keydown`,t=>{if(!t.altKey||![`ArrowUp`,`ArrowDown`].includes(t.key))return;t.preventDefault(),t.stopPropagation();let n=Oo().filter(t=>Eo(t)===Eo(e)&&Do(t)===Do(e)),r=n[n.indexOf(e)+(t.key===`ArrowUp`?-1:1)];r&&(Ro(e,r,t.key===`ArrowDown`),a.focus({preventScroll:!0}))}),a.classList.add(`grip`),a.draggable=!0,a.addEventListener(`dragstart`,t=>{zo=e,e.classList.add(`dragging`),t.dataTransfer?.setData(`text/plain`,e.id),t.dataTransfer&&(t.dataTransfer.effectAllowed=`move`)}),a.addEventListener(`dragend`,()=>{zo=null,e.classList.remove(`dragging`),Bo()});let o=Vo(`▁`,`Shade ${ko(e)} to its title`,()=>Io(e,!e.hasAttribute(`data-collapsed`)));o.setAttribute(`aria-expanded`,String(!e.hasAttribute(`data-collapsed`)));let s=Vo(`✕`,`Hide ${ko(e)}; the Panels list turns it back on`,()=>Lo(e,!0));e.id===`transcript-panel`&&i.append(Ii.button()),i.append(a,o,s),e.prepend(i),e.addEventListener(`dragover`,t=>{if(!zo||zo===e)return;t.preventDefault();let n=e.getBoundingClientRect(),r=t.clientY>n.top+n.height/2;Bo(),e.classList.add(r?`drop-after`:`drop-before`)}),e.addEventListener(`dragleave`,()=>e.classList.remove(`drop-before`,`drop-after`)),e.addEventListener(`drop`,t=>{if(!zo||zo===e)return;t.preventDefault();let n=e.classList.contains(`drop-after`);Bo(),Ro(zo,e,n)})}}function Uo(){if(h.panelsPanel.hidden||h.panelsList.contains(document.activeElement))return;let e=Oo().filter(e=>e!==h.panelsPanel).map(e=>{let t=document.createElement(`li`),n=e.hasAttribute(`data-closed`);t.classList.toggle(`off`,n);let r=document.createElement(`label`),i=document.createElement(`input`);i.type=`checkbox`,i.checked=!n,w(i,`aria-label`,()=>`${ko(e)} on`),i.addEventListener(`change`,()=>Lo(e,!i.checked));let a=document.createElement(`span`);a.className=`name`,C(a,()=>ko(e)),r.append(i,a);let o=document.createElement(`span`);return o.className=`detail`,o.textContent=n?`off`:e.hasAttribute(`data-collapsed`)?`shaded`:e.hidden&&e.dataset.available!==`true`?`nothing to show right now`:``,t.append(r,o),t});h.panelsList.replaceChildren(...e)}function Wo(){$=kt();for(let e of jo){let t=document.getElementById(e),n=Ao.get(e),r=n?document.getElementById(n.zone):null;t&&n&&r&&(Po(t,r,n.col),t.removeAttribute(`data-collapsed`),t.removeAttribute(`data-closed`))}$.order=[...jo],Fo(),$=kt();try{localStorage.removeItem(Ot)}catch{}Uo()}function Go(e){if(!e||Mo())return;let t=Eo(h.adminPanel);if(!t)return;let n=[...t.children].filter(To).find(e=>Do(e)===Do(h.adminPanel));n&&n!==h.adminPanel&&n.before(h.adminPanel),h.adminPanel.removeAttribute(`data-collapsed`),h.adminPanel.removeAttribute(`data-closed`)}h.panelsToggle.addEventListener(`click`,e=>{e.preventDefault();let t=h.panelsPanel.hidden||h.panelsPanel.hasAttribute(`data-closed`)||h.panelsPanel.hasAttribute(`data-collapsed`);h.panelsPanel.hidden=!t,h.panelsToggle.setAttribute(`aria-expanded`,String(t)),t?(h.panelsPanel.hasAttribute(`data-closed`)&&Lo(h.panelsPanel,!1),h.panelsPanel.hasAttribute(`data-collapsed`)&&Io(h.panelsPanel,!1),Uo(),h.panelsPanel.showPopover?.(),h.panelsList.querySelector(`input`)?.focus({preventScroll:!0})):h.panelsPanel.hidePopover?.()}),h.panelsPanel.addEventListener(`toggle`,()=>{let e=h.panelsPanel.matches(`:popover-open`);h.panelsToggle.setAttribute(`aria-expanded`,String(e&&!h.panelsPanel.hasAttribute(`data-collapsed`))),e||(h.panelsPanel.hidden=!0)}),h.panelsPanel.addEventListener(`keydown`,e=>{e.key===`Escape`&&typeof h.panelsPanel.hidePopover!=`function`&&(h.panelsPanel.hidden=!0,h.panelsToggle.setAttribute(`aria-expanded`,`false`),h.panelsToggle.focus({preventScroll:!0}))}),h.panelsReset.addEventListener(`click`,Wo),h.panelsSave.addEventListener(`click`,()=>{No();let e=h.panelsSave.textContent??`Save setup`;h.panelsSave.textContent=`Saved`,window.setTimeout(()=>{h.panelsSave.textContent=e},1200)}),new MutationObserver(()=>{Ho(),Uo()}).observe(document.body,{attributes:!0,attributeFilter:[`data-title`,`hidden`],subtree:!0}),Ho(),Fo(),vo(),yo(),Br(),wr(),h.browse.addEventListener(`click`,()=>{h.directory.hidden?(Ar(),h.directory.scrollIntoView({behavior:`smooth`,block:`nearest`})):h.directory.hidden=!0}),h.disconnect.addEventListener(`click`,()=>{L.close(),h.listenOnly.hidden=!0,ke=-1,h.sharePanel.hidden=!0,h.publishPanel.hidden=!0,h.adminPanel.hidden=!0,h.catalogsPanel.hidden=!0,w(h.catalogsPanel,`data-title`,()=>v(`Catalogs on this server`)),b=``,we=``,ci(),Xo(!1),y=`local`,Ee=`idle`,De=``,U()});async function Ko(){if(y!==`remote`||L.shareLink===``){h.sharePanel.hidden=!0;return}h.sharePanel.hidden=!1;let e=ds(),t=globalThis.location.origin;h.shareLink.value=e===``?``:e.startsWith(`https://`)?`${t}/?url=${encodeURIComponent(e)}`:e,h.shareNote.textContent=`Anyone with this link can watch. They sign in once, then it opens.`,h.sharePhone.hidden=!0,h.shareSend.hidden=!0,h.liveControls.hidden=!0;let n=``;try{let e=await r(`/api/directory`);e.ok&&(n=(await e.json()).callIn??``)}catch{}ht=n,Tn();let i=null;try{let n=await r(L.url(`/api/live/state`));n.ok&&(i=await n.json()),i?.url&&(e=i.url,we=i.url,h.shareLink.value=e.startsWith(`https://`)?`${t}/?url=${encodeURIComponent(e)}`:e)}catch{}i&&(ut=i.live,ft=i.live?i.code:``,ht=n,h.liveControls.hidden=h.adminPanel.hidden||!i.possible,h.goLive.hidden=i.live,h.stopLive.hidden=!i.live,h.sharePhone.hidden=!1,i.live?n?(h.sharePhone.replaceChildren(document.createTextNode(`To talk about it, call `),_s(n),document.createTextNode(` and key `),_s(i.code),document.createTextNode(`. That is a room with everyone else watching — not the stream itself.`)),h.shareSend.hidden=!1):(h.sharePhone.textContent=`Listed. The code for the phone line is ${i.code}.`,h.shareSend.hidden=!1):h.sharePhone.textContent=i.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.`)}let qo=null,Jo=null,Yo=0,Xo=e=>{qo&&clearInterval(qo),qo=null,Yo+=1,Jo?.abort(),Jo=null,j=null,Zr(),e&&(Zo(),qo=setInterval(()=>{document.visibilityState===`visible`&&Zo()},Qr))};async function Zo(){if(y!==`remote`||Jo)return;let e=new AbortController;Jo=e;let t=j===null;t&&ei(e,!0);let n=Yo,i=L.url(`/api/streams`),a=setTimeout(()=>e.abort(),8e3);try{let t=await r(i,{signal:e.signal,cache:`no-store`});if(!t.ok)return;let a=await t.json();if(e.signal.aborted||n!==Yo||y!==`remote`||i!==L.url(`/api/streams`))return;me=a.server.carries!==!1,a.server.name&&a.server.name!==b&&(b=a.server.name,h.catalogsPanel.setAttribute(`data-title`,`Catalogs on ${b}`),ci()),j=a,fs(a),U(),Qo(a)}catch{}finally{clearTimeout(a),t&&ei(e,!1),Jo===e&&(Jo=null)}}function Qo(e){Zr(),O&&cr()}function $o(e){let t=vn(),n=e.restreams??[],r=[],i=e.server.playing,a=!h.adminPanel.hidden;i&&r.push(ps({key:`live`,title:Ve(e.server.nowPlaying)||e.server.name,detail:[i?`playing ${t.fullTitle}`:e.server.nowPlaying?`stopped on ${Ve(e.server.nowPlaying)}`:`nothing loaded`,i&&t.position?t.position:`${e.server.tracks} track${e.server.tracks===1?``:`s`}`,e.server.code?`☎ ${e.server.code}`:`not listed`].join(` · `),playLabel:`Join party`,onPlay:()=>{i&&ts(e.server.nowPlaying)},link:e.server.live?e.server.url:``,...i?{page:us(`live`)}:{},direct:i?L.url(`/api/live`):``}));for(let e of n)r.push(ps({key:`restream:${e.at}`,title:e.name,detail:e.tracks===1?`re-streamed from the web`:`re-streamed from the web · ${e.tracks} tracks`,onPlay:()=>{kn(e.at)},link:``,direct:L.media(e.at,0,!0)}));for(let t of e.channels){let e=t.kind!==`audio`,n=L.url(`/api/channels/${encodeURIComponent(t.id)}`),i=[t.via===`pull`?`on the air · ${t.listeners} watching`:`live over ${t.via} · ${t.listeners} listening`];t.code&&i.push(`☎ ${t.code}`),t.redials&&i.push(`redialled ${t.redials}×`),a&&t.error&&i.push(t.error),r.push(ps({key:`channel:${t.id}`,title:t.name,detail:i.join(` · `),onPlay:()=>{ns({id:t.id,name:t.name,video:e,art:t.art,playlist:t.playlist})},link:n,page:us(`channel:${t.id}`),direct:n,onRestart:(a||jt&&Y!==``&&t.startedBy===Y)&&t.via===`pull`?()=>{as(t.id,t.name)}:void 0,onStop:a||jt&&Y!==``&&t.startedBy===Y?()=>ss(t.id,t.name):void 0,onRename:a||jt&&Y!==``&&t.startedBy===Y?()=>{os(t.id,t.name)}:void 0}))}return r}async function es(){if(y===`remote`)try{if((await r(L.media(z(),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===``&&h.accountPanel.scrollIntoView({behavior:`smooth`,block:`center`}),U()}catch{}}async function ts(e){ke=-1,O=null,A={kind:`live`},it(e,`auto`),await Ge(()=>I.load({title:e||`Live`,artist:``,album:``,duration:0,url:L.url(`/api/live`),video:!0,objectUrl:!1},!0)),hr(!0),D=`Watching what this server is playing. Everyone here sees the same thing.`,U()}async function ns(e,t=!0,n){let r=j?.channels.find(t=>t.id===e.id);!e.playlist&&r?.playlist&&(e={...e,playlist:r.playlist}),ke=-1,O=e,t&&(Ie=0),t&&(A=n??{kind:`channel`}),t&&it(e.name,A?.link||xn(e.name)?`auto`:`channel`);let i=e.video&&F(),a=e.video&&((e.playlist?.length??0)>1||e.id.startsWith(`folder-`));await Ge(()=>I.load({title:e.name,artist:``,album:``,duration:0,url:L.url(i||a?`/api/channels/${encodeURIComponent(e.id)}/hls/index.m3u8`:`/api/channels/${encodeURIComponent(e.id)}`),video:e.video,objectUrl:!1},!0)),hr(e.video),O===e&&(D=`Watching ${e.name}, live on this server.`),U()}function rs(){let e=O;return e?_t?!0:Ie>=5?(D=`${e.name} stopped, and did not come back.`,O=null,A=null,U(),!0):(Ie+=1,D=`${e.name} started over; rejoining…`,U(),_t=setTimeout(()=>{_t=null,O===e&&ns(e,!1)},2e3),!0):!1}function is(e){h.partiesNote.hidden=!1,h.partiesNote.textContent=e,G(e)}async function as(e,t){is(`Restarting ${t}…`);try{let n=await r(L.url(`/api/channels/${encodeURIComponent(e)}/restart`),{method:`POST`}),i=await n.json().catch(()=>({}));is(n.ok?`${t} is dialling its source again.`:i.error??`that did not work`)}catch{is(`could not reach the server`)}Zo()}async function os(e,t){let n=globalThis.prompt(`Call ${t}…`,t);if(n===null)return;let i=n.trim();if(i!==``&&i!==t){is(`Renaming ${t}…`);try{let n=await r(L.url(`/api/channels/${encodeURIComponent(e)}`),{method:`PATCH`,headers:{"content-type":`application/json`},body:JSON.stringify({name:i})}),a=await n.json().catch(()=>({}));is(n.ok?`${t} is now ${i}.`:a.error??`that did not work`)}catch{is(`could not reach the server`)}O?.id===e&&(O={...O,name:i}),Zo(),U()}}async function ss(e,t){is(`Taking ${t} off the air…`);try{let n=await r(L.url(`/api/channels/${encodeURIComponent(e)}`),{method:`DELETE`}),i=await n.json().catch(()=>({}));if(is(n.ok?`${t} is off the air.`:i.error??`that did not work`),!n.ok)return!1}catch{return is(`could not reach the server`),!1}return O?.id===e&&(O=null,I.stop()),!0}function cs(e,t,n,r){if(e.classList.contains(`removing`))return;t.disabled=!0,t.setAttribute(`aria-busy`,`true`);let i=document.createElement(`span`);i.className=`delete-spinner`,i.setAttribute(`role`,`status`),i.setAttribute(`aria-label`,`Removing`),i.textContent=``,t.after(i),n().then(n=>{n?(e.classList.add(`removing`),window.setTimeout(()=>{e.remove(),r?.()},260)):(i.remove(),t.disabled=!1,t.removeAttribute(`aria-busy`))}).catch(()=>{i.remove(),t.disabled=!1,t.removeAttribute(`aria-busy`)})}async function ls(e,t,n=`Copied`){if(!e)return;let r=t.innerHTML;try{await navigator.clipboard.writeText(e)}catch{D=e,U();return}n===`✓`||n===`✓`?g(t,`check`):C(t,()=>v(n)),setTimeout(()=>{t.innerHTML=r},1200)}function us(e,t=0){let n=ds();if(n===``)return``;let r=globalThis.location.origin,i=t>1?`&t=${Math.floor(t)}`:``;return`${r}/?url=${encodeURIComponent(n)}&play=${encodeURIComponent(e)}${i}`}function ds(){if(we!==``)return we;let e=y===`remote`?L.shareLink:``;return/\/admin\//.test(e)?``:e}function fs(e){if(x===``)return;let t=x;if(t===`live`){x=``,e.server.playing?ts(e.server.nowPlaying):(D=`Nothing is playing on this server right now.`,U());return}if(t.startsWith(`link:`)){x=``,_r(t.slice(5));return}if(t.startsWith(`golive:`)){x=``,h.linkUrl.value=t.slice(7),Br().then(()=>Tr());return}if(t.startsWith(`track:`)){x=``;let e=Number(t.slice(6));Number.isInteger(e)&&e>=0&&kn(e);return}let n=t.startsWith(`channel:`)?t.slice(8):``,r=e.channels.find(e=>e.id===n)??e.channels.find(e=>e.name===n);r&&(x=``,ns({id:r.id,name:r.name,video:r.kind!==`audio`,art:r.art}))}function ps(e){let t=document.createElement(`li`);t.className=`party-row`,t.dataset.liveKey=`${ge(L.address)}:${e.key}`;let 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(`span`);a.className=`onair-actions`;let o=document.createElement(`button`);o.type=`button`,o.className=`button`,Vt(o,e.playLabel??`Join party`),o.hidden=e.key.startsWith(`channel:`)&&O?.id===e.key.slice(8),o.addEventListener(`click`,e.onPlay),a.append(o);let s=(e,t,n)=>{let r=document.createElement(`button`);return r.type=`button`,r.className=`icon`,g(r,e),r.title=t,r.setAttribute(`aria-label`,t),r.addEventListener(`click`,()=>n(r)),r};(e.link||e.page)&&a.append(s(`link`,`Copy a link that opens this in the player`,t=>{let n=globalThis.location.origin;ls(e.page??(e.link.startsWith(`https://`)?`${n}/?url=${encodeURIComponent(e.link)}`:e.link),t,`✓`)})),e.direct&&a.append(s(`copy`,`Copy the stream's own URL, for VLC or mpv`,t=>{ls(e.direct??``,t,`✓`)})),e.onRestart&&a.append(s(`restart`,`Restart: dial the source again`,()=>e.onRestart?.())),e.onRename&&a.append(s(`rename`,`Rename: call it something better in the directory`,()=>e.onRename?.())),e.onStop&&a.append(s(`remove`,`Remove: take it off the air`,n=>{cs(t,n,e.onStop,()=>void Zo())})),n.className=`party-name`,n.title=`${e.title} · ${e.detail}`,i.hidden=!0,w(o,`aria-label`,()=>`${v(e.playLabel??`Join party`)}: ${e.title}`);let c=document.createElement(`details`);c.className=`party-actions`;let l=document.createElement(`summary`);return l.textContent=`⋯`,w(l,`aria-label`,()=>`${v(`Show more`)}: ${e.title}`),a.removeChild(o),c.append(l,a),t.append(n,o),a.childElementCount&&t.append(c),t}let ms=``;function hs(e,t){ms=e;let n=e!==``&&t===e;h.loadHome.hidden=e===``,h.homeNote.hidden=e===``,e!==``&&(h.homeNote.textContent=n?`This server's own files: ${e}`:`This server's own files are ${e}, and are not in the playlist.`,h.loadHome.disabled=!1)}h.loadHome.addEventListener(`click`,()=>{ms!==``&&(h.loadHome.disabled=!0,G(`Reading this server's files…`),(async()=>{try{let e=await r(L.url(`/api/source`),{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({source:ms})}),t=await e.json();G(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{G(`could not reach the server`)}finally{h.loadHome.disabled=!1}})())});let gs=async e=>{h.goLive.disabled=!0,h.stopLive.disabled=!0,h.shareNote.textContent=e?`Going live…`:`Taking it off the list…`;try{let t=await r(L.url(e?`/api/live/start`:`/api/live/stop`),{method:`POST`}),n=await t.json();h.shareNote.textContent=t.ok?e?`Live. Anyone can call and key ${n.code??``} to talk about it.`:`Taken off the list. The link still works for anybody who has it.`:n.error??`that did not work`}catch{h.shareNote.textContent=`could not reach the server`}finally{h.goLive.disabled=!1,h.stopLive.disabled=!1,await Ko()}};h.goLive.addEventListener(`click`,()=>void gs(!0)),h.stopLive.addEventListener(`click`,()=>void gs(!1));function _s(e){let t=document.createElement(`b`);return t.textContent=e,t}h.shareCopy.addEventListener(`click`,()=>{h.shareLink.select(),navigator.clipboard?.writeText(h.shareLink.value).then(()=>{h.shareNote.textContent=`Copied. Send it to anybody.`},()=>{h.shareNote.textContent=`Copy it from the box above.`})}),h.shareSend.addEventListener(`submit`,e=>{e.preventDefault();let t=h.shareTo.value.trim();t!==``&&(async()=>{h.shareNote.textContent=`Sending…`;try{let e=await r(`/api/v1/invite`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({to:t,stream:ds()})}),n=await e.json();h.shareNote.textContent=e.ok?`Sent to ${n.sent??t}.`:n.error??`that did not send`,e.ok&&(h.shareTo.value=``)}catch{h.shareNote.textContent=`could not send that`}})()}),h.listenHere.addEventListener(`change`,()=>{try{localStorage.setItem(Un,h.listenHere.checked?`1`:`0`)}catch{}y===`remote`&&(async()=>{h.listenHere.checked?(await L.send({type:`stop`}),await Mn(E.index)):(I.stop(),ke=-1),U()})()}),document.addEventListener(`keydown`,e=>{let t=e.target;if(!(e.defaultPrevented||e.altKey||e.ctrlKey||e.metaKey||e.shiftKey)&&!t?.closest(`input, textarea, select, button, a, [contenteditable], [role=button]`)&&t===h.transport)switch(e.key){case` `:e.preventDefault(),Nn();return;case`s`:Fn();return;case`n`:case`ArrowRight`:Pn(1);return;case`p`:case`ArrowLeft`:Pn(-1);return;case`ArrowDown`:e.preventDefault(),kn(Math.min(R()-1,z()+1));return;case`ArrowUp`:e.preventDefault(),kn(Math.max(0,z()-1));return}});let vs=null;globalThis.addEventListener(`beforeinstallprompt`,e=>{e.preventDefault(),vs=e,h.install.hidden=!1}),h.install.addEventListener(`click`,()=>{vs?.prompt(),vs=null,h.install.hidden=!0});try{let e=localStorage.getItem(Hn);e!==null&&(h.volume.value=String(Math.round(Number(e)*100)),I.volume=Number(e));let t=localStorage.getItem(Bn);t&&(h.remoteUrl.value=t),localStorage.getItem(Un)===`0`&&(h.listenHere.checked=!1)}catch{}(async()=>{if(h.remoteUrl.value!==``)return;let e=globalThis.location.origin;if(await te(e)===null)return;let t=await p(e);t&&t.trackCount!==0&&(h.remoteUrl.value=e,y=`remote`,D=``,L.connect(e),Xo(!0),Ga(),U())})(),ti();let ys=()=>{document.visibilityState===`visible`&&!h.partiesPanel.hasAttribute(`data-closed`)&&ti()},bs=setInterval(ys,Qr);document.addEventListener(`visibilitychange`,()=>{document.visibilityState===`visible`&&(ti(),Zo())}),globalThis.addEventListener(`pagehide`,()=>{clearInterval(bs),qo&&clearInterval(qo),Yr?.abort(),Jo?.abort(),Yr=null,Jo=null,Yo+=1}),globalThis.addEventListener(`pageshow`,e=>{e.persisted&&(clearInterval(bs),bs=setInterval(ys,Qr),ys(),y===`remote`&&Xo(!0))}),(()=>{if(Gn||bt!==``)return;let e=()=>I.source!==``||I.playing||He()||O!==null,t=async()=>{try{let e=await(await r(`/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``},i=new Audio;i.volume=.7;let a=()=>{Gn=!0},o=()=>{document.removeEventListener(`pointerdown`,o),document.removeEventListener(`keydown`,o),a(),setTimeout(()=>{e()||I.playJingle(i).catch(()=>{})},150)};t().then(async t=>{if(!(t===``||e()))return await n(i,{src:t,kind:`audio`}),I.playJingle(i).then(a,()=>{document.addEventListener(`pointerdown`,o,{once:!0}),document.addEventListener(`keydown`,o,{once:!0})})})})(),U(),requestAnimationFrame(fr)}Yn(),Oe(),Fe(),`serviceWorker`in navigator&&globalThis.addEventListener(`load`,()=>{navigator.serviceWorker.register(`/sw.js`).catch(()=>{})});export{oe as t};
|