import{e as i}from"/static/js/utils/utils.js?v=c676bb123f83b0ed";import{Fragment as S,jsx as s,jsxs as I}from"/static/js/utils/utils.js?v=c676bb123f83b0ed";// @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPL-3.0-or-later
var o=i("message-input"),y=o.form,h=i("message-section"),c=i("openmoji-attribution"),v=c==null?void 0:c.getAttribute("openmoji-version"),a=100,m=0,d="",E=e=>new Date(e+16510752e5).toLocaleString(),g=()=>c==null?void 0:c.getAttribute("type"),C=({emoji:e})=>{let t=[...e],n=(t.length==2&&t[1]==="️"?[t[0]]:t).map(k=>k.codePointAt(0).toString(16).padStart(4,"0")).join("-").toUpperCase(),u="/static/openmoji/svg/".concat(n,".svg");return s("img",{src:v?"".concat(u,"?v=").concat(v):u,alt:e,className:"emoji"})},l=({emoji:e})=>(g(),g()==="img"?s(C,{emoji:e}):g()?s("span",{className:"openmoji",children:[e]}):e),j=({msg:e})=>I("div",{tooltip:E(e.timestamp),children:[s(S,{children:e.author.map(t=>s(l,{emoji:t}))}),": ",s(S,{children:e.content.map(t=>s(l,{emoji:t}))})]}),b=e=>{h.append(s(j,{msg:e}))},M=e=>{let t="current-user";i(t).replaceWith(s("div",{className:g()?"openmoji":"",id:t,children:e.map(n=>s(l,{emoji:n}))}))},f=()=>{d&&!o.value&&(o.value=d,d="")},$={connecting:"Versuche mit WebSocket zu verbinden",connected:"Mit WebSocket verbunden!",disconnected:"Verbindung getrennt. Drücke hier um erneut zu versuchen."},r=e=>{let t="connection-state",n=e=="disconnected"?(()=>{m=0,a=500,i(t).removeEventListener("click",n),p()}):void 0;i(t).replaceWith(s("div",{tooltip:$[e],"tooltip-position":"right",onclick:n,"data-state":e,id:t}))},w=e=>{let t=JSON.parse(e.data);switch(t.type){case"messages":{h.innerText="";for(let n of t.messages)b(n);break}case"message":{b(t.message);break}case"init":{M(t.current_user),t.current_user.join(""),r("connected"),a=100,m=0;break}case"users":{t.users;break}case"ratelimit":{f(),alert("Retry after ".concat(t.retry_after," seconds."));break}case"error":{f(),alert(t.error);break}default:console.error("Invalid type ".concat(t.type))}},p=()=>{r("connecting");let e=new WebSocket((location.protocol==="https:"?"wss:":"ws:")+"//".concat(location.host,"/websocket/emoji-chat")),t=setInterval(()=>{e.readyState==e.OPEN&&e.send("")},1e4);e.addEventListener("close",n=>{if(clearInterval(t),n.wasClean){"Connection closed cleanly, code=".concat(n.code," reason=").concat(n.reason),r("disconnected");return}if("Connection closed, reconnecting in ".concat(a,"ms  (").concat(m,")"),r("connecting"),m>10){r("disconnected");return}setTimeout(()=>{a=Math.max(500,Math.floor(Math.min(15e3,1.5*a-200))),m++,p()},a)}),e.addEventListener("open",n=>{r("connected")}),e.addEventListener("error",n=>{console.error({msg:"got error from websocket",event:n})}),e.addEventListener("message",n=>{w(n)}),y.addEventListener("submit",n=>{o.value!==""&&(d=o.value,e.send(JSON.stringify({type:"message",message:o.value})),o.value=""),n.preventDefault()})};p();
// @license-end
//# sourceMappingURL=chat.js.map
