// @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPL-3.0-or-later
export{};const s=document.getElementById("message-input"),b=s.form,h=document.getElementById("message-section"),c=document.getElementById("openmoji-attribution"),f=c==null?void 0:c.getAttribute("openmoji-version"),i=document.getElementById("connection-state"),l=document.getElementById("current-user");let r=100,u=0,m="";const T=t=>new Date(t+16510752e5).toLocaleString(),j=()=>c==null?void 0:c.getAttribute("type"),y=t=>{const e=document.createElement("div"),n=j();if(n==="img"){for(const o of t.author)e.append(d(o));e.innerHTML+=": ";for(const o of t.content)e.append(d(o))}else e.innerText="".concat(t.author.join(""),": ").concat(t.content.join("")),n&&e.classList.add("openmoji");e.setAttribute("tooltip",T(t.timestamp)),h.append(e)},I=t=>{l.innerHTML="";const e=j();if(e==="img"){for(const n of t)l.append(d(n));return}e&&l.classList.add("openmoji"),l.innerText=t.join("")},d=t=>{const e=[...t],n=(e.length==2&&e[1]==="️"?[e[0]]:e).map(k=>k.codePointAt(0).toString(16).padStart(4,"0")).join("-").toUpperCase(),o=document.createElement("img"),p="/static/openmoji/svg/".concat(n,".svg");return o.src=f?"".concat(p,"?v=").concat(f):p,o.classList.add("emoji"),o.alt=t,o},v=()=>{m&&!s.value&&(s.value=m,m="")},a=t=>{let e;if(i.onclick=()=>{},t==="connecting")e="Versuche mit WebSocket zu verbinden";else if(t==="connected")e="Mit WebSocket verbunden!";else if(t==="disconnected")e="Verbindung getrennt. Drücke hier um erneut zu versuchen.",i.onclick=()=>{u=0,r=500,i.onclick=()=>{},g()};else{console.error("invalid state",t);return}i.setAttribute("state",t),i.setAttribute("tooltip",e)},S=t=>{const e=JSON.parse(t.data);switch(e.type){case"messages":{h.innerText="";for(const n of e.messages)y(n);break}case"message":{y(e.message);break}case"init":{I(e.current_user),console.log("Connected as",e.current_user.join("")),a("connected"),r=100,u=0;break}case"users":{console.debug("Received users data",e.users);break}case"ratelimit":{v(),alert("Retry after ".concat(e.retry_after," seconds."));break}case"error":{v(),alert(e.error);break}default:console.error("Invalid type ".concat(e.type))}},g=()=>{a("connecting");const t=new WebSocket((window.location.protocol==="https:"?"wss:":"ws:")+"//".concat(window.location.host,"/websocket/emoji-chat")),e=setInterval(()=>{t.send("")},1e4);t.onclose=n=>{if(b.onsubmit=()=>{},n.wasClean){console.debug("Connection closed cleanly, code=".concat(n.code," reason=").concat(n.reason)),a("disconnected");return}if(console.debug("Connection closed, reconnecting in ".concat(r,"ms")),a("connecting"),clearInterval(e),u>20){a("disconnected");return}setTimeout(()=>{r=Math.max(500,Math.floor(Math.min(15e3,1.5*r-200))),u++,g()},r)},t.onopen=n=>{console.debug("Opened WebSocket",n)},t.onmessage=S,b.onsubmit=n=>{s.value!==""&&(m=s.value,t.send(JSON.stringify({type:"message",message:s.value})),s.value=""),n.preventDefault()}};g();// @license-end
//# sourceMappingURL=chat.js.map
