varAntunnel;!function(s){lete;!function(s){s[s.OK=0]="OK",s[s.SUBSCRIBE=2]="SUBSCRIBE",s[s.UNSUBSCRIBE=3]="UNSUBSCRIBE",s[s.ERROR=1]="ERROR",s[s.DATA=6]="DATA",s[s.CTRL=7]="CTRL",s[s.CLOSE=5]="CLOSE",s[s.PING=8]="PING"}(e=s.AntunnelMSGType||(s.AntunnelMSGType={}))}(Antunnel||(Antunnel={})),function(s){lete,t;!function(s){s[s.SUBSCRIBE=10]="SUBSCRIBE",s[s.UNSUBSCRIBE=11]="UNSUBSCRIBE",s[s.QUERY_USER=12]="QUERY_USER",s[s.QUERY_GROUP=13]="QUERY_GROUP"}(e=s.BroadcastCTRLType||(s.BroadcastCTRLType={})),function(s){s[s.INIT=0]="INIT",s[s.SUBSCRIBED=1]="SUBSCRIBED",s[s.UNSUBSCRIBED=2]="UNSUBSCRIBED"}(t=s.BroadcastGroupState||(s.BroadcastGroupState={}));classn{constructor(s){this.groupname=s,this.users=newSet,this.onmessage=void0,this.onready=void0,this.onuseradd=void0,this.onuserdel=void0,this.onclose=void0,this.user=OS.setting.user.name,this.mgr=void0,this.state=t.INIT}close(){this.mgr&&this.id&&this.mgr.unsubscribe(this.id)}refresh(){this.mgr&&this.id&&this.mgr.query(this.id)}send(s){this.mgr.send(this.id,s)}}s.BroadcastGroup=n,s.BroadcastManager=class{constructor(s){this.sub=void0,this.channel=s,this.tunnel=void0,this.groups={},this.pendings={},this.ongroupadd=void0,this.ongroupdel=void0}connect(i){this.sub=news.Subscriber(this.channel),this.sub.onopen=()=>{OS.announcer.osinfo(__("Subscriber {0}: Connected to the {1} channel",this.sub.id,this.channel)),i(!0)},this.sub.onerror=s=>{lete=s;s.data&&(e=newTextDecoder("utf-8").decode(s.data)),OS.announcer.oserror(__("Subscriber {0}: Error from the {1} channel: {2}",this.sub.id,this.channel,e),void0)},this.sub.onmessage=e=>{if(e.data){lett=s.Msg.int_from(e.data.slice(0,4),0,4),n=this.groups[t];if(!n)return;n.onmessage&&n.onmessage(e.data.slice(4))}},this.sub.onctrl=i=>{letr={user:void0,group:void0,type:i.data[0],id:void0};switch(r.type){casee.SUBSCRIBE:casee.UNSUBSCRIBE:leto=i.data[1]+2;if(r.user=newTextDecoder("utf-8").decode(i.data.slice(2,o)),r.id=s.Msg.int_from(i.data,o,4),o+=4,r.group=newTextDecoder("utf-8").decode(i.data.slice(o)),r.type===e.SUBSCRIBE){lets=this.pendings[r.group];s&&s.user===r.user&&(s.id=r.id,this.pendings[r.group]=void0,deletethis.pendings[r.group],this.groups[r.id]=s,s.state=t.SUBSCRIBED,this.ongroupadd&&this.ongroupadd(s),s.onready()),s=this.groups[r.id],s||(s=newn(r.group),s.id=r.id,s.state=t.SUBSCRIBED,s.mgr=this,this.groups[r.id]=s,this.ongroupadd&&this.ongroupadd(s),s.onready&&s.onready()),s.users.has(r.user)||(s.users.add(r.user),s.onuseradd&&s.onuseradd(r.user))}else{lets=this.groups[r.id];if(!s)return;s.user===r.user?(OS.announcer.osinfo(__("Subcriber {0}: leave group {1}",this.sub.id,r.group)),this.groups[r.id]=void0,deletethis.groups[r.id],s.state=t.UNSUBSCRIBED,s.onclose&&s.onclose(),this.ongroupdel&&this.ongroupdel(s)):(s.users.delete(r.user),s.onuserdel&&s.onuserdel(r.user))}break;casee.QUERY_USER:r.id=s.Msg.int_from(i.data,1,4),r.user=newTextDecoder("utf-8").decode(i.data.slice(5));letu=this.groups[r.id];if(!u)return;u.users.has(r.user)||(u.users.add(r.user),u.onuseradd&&u.onuseradd(r.user));break;casee.QUERY_GROUP:if(r.id=s.Msg.int_from(i.data,1,4),r.group=newTextDecoder("utf-8").decode(i.data.slice(5)),this.groups[r.id])return;this.groups[r.id]=newn(r.group),this.groups[r.id].id=r.id,this.groups[r.id].state=t.SUBSCRIBED,this.groups[r.id].mgr=this,this.ongroupadd&&this.ongroupadd(this.groups[r.id]),this.groups[r.id].onready&&this.groups[r.id].onready()}},this.sub.onclose=()=>{OS.announcer.osinfo(__("Subscriber {0}: Connection to {1} closed",this.sub.id,this.channel)),this.sub=void0},this.tunnel.subscribe(this.sub)}setup(){returnnewPromise(async(e,t)=>{try{if(!s)thrownewError(__("Library not fould: %s","Antunnel").__());if(s.tunnel)this.tunnel=s.tunnel;else{awaitOS.GUI.pushService("Antunnel/AntunnelService");lete=OS.setting.system.tunnel_uri;if(!e)thrownewError(__("Unable to connect to: %s","Antunnel").__());awaits.init(e),this.tunnel=s.tunnel}this.sub?e(!0):this.connect(e)}catch(e){s.tunnel&&s.tunnel.close(),t(__e(e))}})}unsubscribe(t){letn=newUint8Array(5);n[0]=e.UNSUBSCRIBE,n.set(s.Msg