1 line
6.9 KiB
JavaScript
1 line
6.9 KiB
JavaScript
import{B as e,C as t,D as n,H as r,K as i,M as a,P as o,R as s,S as c,W as l,k as u,r as d,v as f,x as p}from"./ui-CzB-gjVP.js";import{t as m}from"./message-square-1ZGuav88.js";var h=[[`path`,{d:`M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z`,key:`1oefj6`}],[`path`,{d:`M14 2v5a1 1 0 0 0 1 1h5`,key:`wfsgrz`}],[`path`,{d:`M15.033 13.44a.647.647 0 0 1 0 1.12l-4.065 2.352a.645.645 0 0 1-.968-.56v-4.704a.645.645 0 0 1 .967-.56z`,key:`1tzo1f`}]],g=e=>s(f,i(e,{iconNode:h,name:`file-play`})),_=[[`path`,{d:`M14.536 21.686a.5.5 0 0 0 .937-.024l6.5-19a.496.496 0 0 0-.635-.635l-19 6.5a.5.5 0 0 0-.024.937l7.93 3.18a2 2 0 0 1 1.112 1.11z`,key:`1ffxy3`}],[`path`,{d:`m21.854 2.147-10.94 10.939`,key:`12cjpa`}]],v=e=>s(f,i(e,{iconNode:_,name:`send`})),y=u(`<div class="pointer-events-none absolute inset-0 overflow-hidden">`),b=u(`<span class=danmaku-item>`),x=u(`<div class="flex h-full min-h-24 flex-col items-center justify-center gap-2.5 text-center"><p class="text-sm text-muted-foreground">还没有弹幕</p><p class="micro-label text-muted-foreground/50">danmaku channel idle`),S=u(`<div class="flex gap-2 border-t border-line/80 p-2.5"><input class="field field-mono h-9 flex-1 text-sm"placeholder=发条弹幕… aria-label=弹幕内容>`),C=u(`<div class="flex h-full min-h-0 flex-col"><div class="flex-1 space-y-3 overflow-y-auto p-3">`),w=u(`<div class="flex items-start gap-2.5"><span></span><div class="min-w-0 flex-1"><div class="flex flex-wrap items-baseline gap-x-2"><span class="font-mono text-xs font-medium"></span><span class="micro-label text-[9px] text-muted-foreground"></span><span class="font-mono text-[9px] text-muted-foreground/60"></span></div><p class="mt-0.5 text-sm leading-snug break-words">`),T=u(`<p class="border-t border-line/80 p-3 text-xs text-muted-foreground">登录后可在房间内发送弹幕`);function E(i){let[o,c]=l([]),u=0,d=0,f=``,p=[6,18,30,42,54,66,78];e(()=>{let e=i.messages(),t=e[e.length-1];if(!t||t.id===f)return;f=t.id;let n=p[d%p.length];d++;let r=7+Math.random()*4,a={key:++u,text:t.message,color:t.color||`#f1f5f9`,top:n,dur:r};c(e=>{let t=[...e,a];return t.length>50?t.slice(t.length-50):t})});let m=e=>c(t=>t.filter(t=>t.key!==e));return(()=>{var e=y();return t(e,s(a,{get each(){return o()},children:e=>(()=>{var i=b();return i.addEventListener(`animationend`,()=>m(e.key)),t(i,()=>e.text),r(t=>{var r=`${e.top}%`,a=e.color,o=`${e.dur}s`;return r!==t.e&&n(i,`top`,t.e=r),a!==t.t&&n(i,`color`,t.t=a),o!==t.a&&n(i,`animation-duration`,t.a=o),t},{e:void 0,t:void 0,a:void 0}),i})()})),e})()}function D(e){return Number.isFinite(e)?new Date(e).toLocaleTimeString(`zh-CN`,{hour:`2-digit`,minute:`2-digit`}):`--:--`}function O(e){return e===`admin`?`border-acid-magenta/40 bg-acid-magenta/10 text-acid-magenta`:e===`publisher`?`border-warning/40 bg-warning/10 text-warning`:`border-acid-cyan/40 bg-acid-cyan/10 text-acid-cyan`}function k(e){let[n,i]=l(``),c=()=>{let t=n().trim();t&&(e.onSend(t),i(``))};return(()=>{var l=C(),u=l.firstChild;return t(u,s(o,{get when(){return e.messages().length>0},get children(){return s(a,{get each(){return e.messages()},children:e=>(()=>{var n=w(),i=n.firstChild,a=i.nextSibling.firstChild,o=a.firstChild,s=o.nextSibling,c=s.nextSibling,l=a.nextSibling;return t(i,()=>(e.user[0]??`?`).toUpperCase()),t(o,()=>e.user),t(s,()=>String(e.role)),t(c,()=>D(e.ts)),t(l,()=>e.message),r(()=>p(i,`mt-0.5 flex size-6 shrink-0 items-center justify-center border font-mono text-[10px] font-bold ${O(String(e.role))}`)),n})()})}}),null),t(u,s(o,{get when(){return e.messages().length===0},get children(){var e=x(),n=e.firstChild;return t(e,s(m,{class:`size-5 text-muted-foreground/50`}),n),e}}),null),t(l,s(o,{get when(){return e.canChat},get fallback(){return T()},get children(){var e=S(),a=e.firstChild;return a.$$keydown=e=>{e.key===`Enter`&&c()},a.$$input=e=>i(e.currentTarget.value),t(e,s(d,{onClick:c,size:`icon`,"aria-label":`发送弹幕`,class:`shrink-0`,get children(){return s(v,{class:`size-4`})}}),null),r(()=>a.value=n()),e}}),null),l})()}c([`input`,`keydown`]);function A(e,t){let n=new EventSource(`/api/room/${encodeURIComponent(e)}/events`,{withCredentials:!0});return n.addEventListener(`room`,e=>{try{t(JSON.parse(e.data))}catch{}}),()=>n.close()}function j(e,t){let n=new EventSource(`/api/room/${encodeURIComponent(e)}/chat`,{withCredentials:!0});return n.addEventListener(`chat`,e=>{try{t(JSON.parse(e.data))}catch{}}),()=>n.close()}async function M(e,t,n){await fetch(`/api/room/${encodeURIComponent(e)}/chat`,{method:`POST`,credentials:`same-origin`,headers:{"Content-Type":`application/json`},body:JSON.stringify({message:t,color:n})})}function N(e){return{urls:e.urls,username:e.username,credential:e.credential}}async function P(e){let t=new RTCPeerConnection({iceServers:e.iceServers||[]});e.local.getTracks().forEach(n=>t.addTrack(n,e.local));let n=await t.createOffer();await t.setLocalDescription(n);let r=await(await fetch(`/rtc/v1/whip/?app=live&stream=${encodeURIComponent(e.stream)}&token=${encodeURIComponent(e.token)}`,{method:`POST`,headers:{"Content-Type":`application/sdp`},credentials:`same-origin`,body:n.sdp??``})).text();return await t.setRemoteDescription({type:`answer`,sdp:r}),t}async function F(e){let t=new RTCPeerConnection({iceServers:e.iceServers||[]});t.addTransceiver(`video`,{direction:`recvonly`}),t.addTransceiver(`audio`,{direction:`recvonly`});let n=await t.createOffer();await t.setLocalDescription(n);let r=await(await fetch(`/rtc/v1/whep/?app=live&stream=${encodeURIComponent(e.stream)}`,{method:`POST`,headers:{"Content-Type":`application/sdp`},credentials:`same-origin`,body:n.sdp??``})).text();return await t.setRemoteDescription({type:`answer`,sdp:r}),t}async function I(e){let t=new RTCPeerConnection({iceServers:e.iceServers||[]});e.local.getTracks().forEach(n=>t.addTrack(n,e.local));let n=await t.createOffer();await t.setLocalDescription(n);let r=await(await fetch(`/api/cf/sessions/${e.sessionId}/tracks/new`,{method:`POST`,headers:{"Content-Type":`application/json`},credentials:`same-origin`,body:JSON.stringify({sessionDescription:{type:`offer`,sdp:n.sdp},tracks:[{location:`local`}]})})).json();return await t.setRemoteDescription({type:r.sessionDescription.type,sdp:r.sessionDescription.sdp}),t}async function L(e){let t=new RTCPeerConnection({iceServers:e.iceServers||[]});t.addTransceiver(`video`,{direction:`recvonly`}),t.addTransceiver(`audio`,{direction:`recvonly`});let n=await t.createOffer();await t.setLocalDescription(n);let r=await(await fetch(`/api/cf/sessions/${e.viewerSessionId}/tracks/new`,{method:`POST`,headers:{"Content-Type":`application/json`},credentials:`same-origin`,body:JSON.stringify({sessionDescription:{type:`offer`,sdp:n.sdp},tracks:[{location:`remote`,sessionId:e.publisherSessionId}]})})).json();return await t.setRemoteDescription({type:r.sessionDescription.type,sdp:r.sessionDescription.sdp}),t}export{P as a,A as c,g as d,F as i,k as l,L as n,M as o,N as r,j as s,I as t,E as u}; |