// @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPL-3.0-or-later
var s=document.getElementById("message-input"),b=s.form,f=document.getElementById("message-section"),r=document.getElementById("openmoji-attribution"),y=r==null?void 0:r.getAttribute("openmoji-version"),i=document.getElementById("connection-state"),l=document.getElementById("current-user"),c=100,m=0,u="",T=t=>new Date(t+16510752e5).toLocaleString(),v=()=>r==null?void 0:r.getAttribute("type"),h=t=>{let e=document.createElement("div"),n=v();if(n==="img"){for(let o of t.author)e.append(d(o));e.innerHTML+=": ";for(let 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)),f.append(e)},I=t=>{l.innerHTML="";let e=v();if(e==="img"){for(let n of t)l.append(d(n));return}e&&l.classList.add("openmoji"),l.innerText=t.join("")},d=t=>{let 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=y?"".concat(p,"?v=").concat(y):p,o.classList.add("emoji"),o.alt=t,o},j=()=>{u&&!s.value&&(s.value=u,u="")},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=()=>{m=0,c=500,i.onclick=()=>{},g()};else{console.error("invalid state",t);return}i.setAttribute("state",t),i.setAttribute("tooltip",e)},S=t=>{let e=JSON.parse(t.data);switch(e.type){case"messages":{f.innerText="";for(let n of e.messages)h(n);break}case"message":{h(e.message);break}case"init":{I(e.current_user),e.current_user.join(""),a("connected"),c=100,m=0;break}case"users":{e.users;break}case"ratelimit":{j(),alert("Retry after ".concat(e.retry_after," seconds."));break}case"error":{j(),alert(e.error);break}default:console.error("Invalid type ".concat(e.type))}},g=()=>{a("connecting");let t=new WebSocket((location.protocol==="https:"?"wss:":"ws:")+"//".concat(location.host,"/websocket/emoji-chat")),e=setInterval(()=>{t.send("")},1e4);t.onclose=n=>{if(b.onsubmit=()=>{},n.wasClean){"Connection closed cleanly, code=".concat(n.code," reason=").concat(n.reason),a("disconnected");return}if("Connection closed, reconnecting in ".concat(c,"ms"),a("connecting"),clearInterval(e),m>20){a("disconnected");return}setTimeout(()=>{c=Math.max(500,Math.floor(Math.min(15e3,1.5*c-200))),m++,g()},c)},t.onopen=n=>{},t.onmessage=S,b.onsubmit=n=>{s.value!==""&&(u=s.value,t.send(JSON.stringify({type:"message",message:s.value})),s.value=""),n.preventDefault()}};g();
// @license-end
//# sourceMappingURL=chat.js.map
