1 line
92 KiB
JavaScript
1 line
92 KiB
JavaScript
!function(e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).Tinode=e()}((function(){var e={};function t(e,t,s){return function(e,t){if(e!==t)throw new TypeError("Private static access of wrong provenance")}(e,t),s}Object.defineProperty(e,"__esModule",{value:!0}),e.default=void 0;class s{constructor(e){e&&(this.given="number"==typeof e.given?e.given:s.decode(e.given),this.want="number"==typeof e.want?e.want:s.decode(e.want),this.mode=e.mode?"number"==typeof e.mode?e.mode:s.decode(e.mode):this.given&this.want)}static decode(e){if(!e)return null;if("number"==typeof e)return e&s._BITMASK;if("N"===e||"n"===e)return s._NONE;const t={J:s._JOIN,R:s._READ,W:s._WRITE,P:s._PRES,A:s._APPROVE,S:s._SHARE,D:s._DELETE,O:s._OWNER};let i=s._NONE;for(let s=0;s<e.length;s++){const n=t[e.charAt(s).toUpperCase()];n&&(i|=n)}return i}static encode(e){if(null===e||e===s._INVALID)return null;if(e===s._NONE)return"N";const t=["J","R","W","P","A","S","D","O"];let i="";for(let s=0;s<t.length;s++)0!=(e&1<<s)&&(i+=t[s]);return i}static update(e,t){if(!t||"string"!=typeof t)return e;let i=t.charAt(0);if("+"==i||"-"==i){let n=e;const r=t.split(/([-+])/);for(let t=1;t<r.length-1;t+=2){i=r[t];const a=s.decode(r[t+1]);if(a==s._INVALID)return e;null!=a&&("+"===i?n|=a:"-"===i&&(n&=~a))}e=n}else{const i=s.decode(t);i!=s._INVALID&&(e=i)}return e}static diff(e,t){return e=s.decode(e),t=s.decode(t),e==s._INVALID||t==s._INVALID?s._INVALID:e&~t}toString(){return'{"mode": "'+s.encode(this.mode)+'", "given": "'+s.encode(this.given)+'", "want": "'+s.encode(this.want)+'"}'}jsonHelper(){return{mode:s.encode(this.mode),given:s.encode(this.given),want:s.encode(this.want)}}setMode(e){return this.mode=s.decode(e),this}updateMode(e){return this.mode=s.update(this.mode,e),this}getMode(){return s.encode(this.mode)}setGiven(e){return this.given=s.decode(e),this}updateGiven(e){return this.given=s.update(this.given,e),this}getGiven(){return s.encode(this.given)}setWant(e){return this.want=s.decode(e),this}updateWant(e){return this.want=s.update(this.want,e),this}getWant(){return s.encode(this.want)}getMissing(){return s.encode(this.want&~this.given)}getExcessive(){return s.encode(this.given&~this.want)}updateAll(e){return e&&(this.updateGiven(e.given),this.updateWant(e.want),this.mode=this.given&this.want),this}isOwner(e){return t(s,s,i).call(s,this,e,s._OWNER)}isPresencer(e){return t(s,s,i).call(s,this,e,s._PRES)}isMuted(e){return!this.isPresencer(e)}isJoiner(e){return t(s,s,i).call(s,this,e,s._JOIN)}isReader(e){return t(s,s,i).call(s,this,e,s._READ)}isWriter(e){return t(s,s,i).call(s,this,e,s._WRITE)}isApprover(e){return t(s,s,i).call(s,this,e,s._APPROVE)}isAdmin(e){return this.isOwner(e)||this.isApprover(e)}isSharer(e){return this.isAdmin(e)||t(s,s,i).call(s,this,e,s._SHARE)}isDeleter(e){return t(s,s,i).call(s,this,e,s._DELETE)}}function i(e,t,s){if(["given","want","mode"].includes(t=t||"mode"))return 0!=(e[t]&s);throw new Error(`Invalid AccessMode component '${t}'`)}e.default=s,s._NONE=0,s._JOIN=1,s._READ=2,s._WRITE=4,s._PRES=8,s._APPROVE=16,s._SHARE=32,s._DELETE=64,s._OWNER=128,s._BITMASK=s._JOIN|s._READ|s._WRITE|s._PRES|s._APPROVE|s._SHARE|s._DELETE|s._OWNER,s._INVALID=1048576;var n={};Object.defineProperty(n,"__esModule",{value:!0}),n.VERSION=n.USER_NEW=n.TOPIC_SYS=n.TOPIC_P2P=n.TOPIC_NEW_CHAN=n.TOPIC_NEW=n.TOPIC_ME=n.TOPIC_GRP=n.TOPIC_FND=n.TOPIC_CHAN=n.RECV_TIMEOUT=n.PROTOCOL_VERSION=n.MESSAGE_STATUS_TO_ME=n.MESSAGE_STATUS_SENT=n.MESSAGE_STATUS_SENDING=n.MESSAGE_STATUS_RECEIVED=n.MESSAGE_STATUS_READ=n.MESSAGE_STATUS_QUEUED=n.MESSAGE_STATUS_NONE=n.MESSAGE_STATUS_FAILED=n.LOCAL_SEQID=n.LIBRARY=n.EXPIRE_PROMISES_TIMEOUT=n.EXPIRE_PROMISES_PERIOD=n.DEL_CHAR=n.DEFAULT_MESSAGES_PAGE=void 0,n.PROTOCOL_VERSION="0",n.VERSION="0.21.0-beta1",n.LIBRARY="tinodejs/0.21.0-beta1",n.TOPIC_NEW="new",n.TOPIC_NEW_CHAN="nch",n.TOPIC_ME="me",n.TOPIC_FND="fnd",n.TOPIC_SYS="sys",n.TOPIC_CHAN="chn",n.TOPIC_GRP="grp",n.TOPIC_P2P="p2p",n.USER_NEW="new",n.LOCAL_SEQID=268435455,n.MESSAGE_STATUS_NONE=0,n.MESSAGE_STATUS_QUEUED=1,n.MESSAGE_STATUS_SENDING=2,n.MESSAGE_STATUS_FAILED=3,n.MESSAGE_STATUS_SENT=4,n.MESSAGE_STATUS_RECEIVED=5,n.MESSAGE_STATUS_READ=6,n.MESSAGE_STATUS_TO_ME=7,n.EXPIRE_PROMISES_TIMEOUT=5e3,n.EXPIRE_PROMISES_PERIOD=1e3,n.RECV_TIMEOUT=100,n.DEFAULT_MESSAGES_PAGE=24,n.DEL_CHAR="␡";var r={};Object.defineProperty(r,"__esModule",{value:!0}),r.isUrlRelative=function(e){return e&&!/^\s*([a-z][a-z0-9+.-]*:|\/\/)/im.test(e)},r.jsonParseHelper=function(e,t){if("string"==typeof t&&t.length>=20&&t.length<=24&&["ts","touched","updated","created","when","deleted","expires"].includes(e)){const e=new Date(t);if(!isNaN(e))return e}else if("acs"===e&&"object"==typeof t)return new o.default(t);return t},r.mergeObj=h,r.mergeToCache=function(e,t,s,i){return e[t]=h(e[t],s,i),e[t]},r.normalizeArray=function(e){let t=[];if(Array.isArray(e)){for(let s=0,i=e.length;s<i;s++){let i=e[s];i&&(i=i.trim().toLowerCase(),i.length>1&&t.push(i))}t.sort().filter((function(e,t,s){return!t||e!=s[t-1]}))}return 0==t.length&&t.push(n.DEL_CHAR),t},r.rfc3339DateString=function(e){if(!c(e))return;const t=function(e,t){return"0".repeat((t=t||2)-(""+e).length)+e},s=e.getUTCMilliseconds();return e.getUTCFullYear()+"-"+t(e.getUTCMonth()+1)+"-"+t(e.getUTCDate())+"T"+t(e.getUTCHours())+":"+t(e.getUTCMinutes())+":"+t(e.getUTCSeconds())+(s?"."+t(s,3):"")+"Z"},r.simplify=function e(t){return Object.keys(t).forEach((s=>{"_"==s[0]?delete t[s]:t[s]?Array.isArray(t[s])&&0==t[s].length?delete t[s]:t[s]?t[s]instanceof Date?c(t[s])||delete t[s]:"object"==typeof t[s]&&(e(t[s]),0==Object.getOwnPropertyNames(t[s]).length&&delete t[s]):delete t[s]:delete t[s]})),t};var a,o=(a=e)&&a.__esModule?a:{default:a};function c(e){return e instanceof Date&&!isNaN(e)&&0!=e.getTime()}function h(e,t,s){if("object"!=typeof t){if(void 0===t)return e;if(t===n.DEL_CHAR)return;return t}if(null===t)return t;if(t instanceof Date&&!isNaN(t))return!e||!(e instanceof Date)||isNaN(e)||e<t?t:e;if(t instanceof o.default)return new o.default(t);if(t instanceof Array)return t;e&&e!==n.DEL_CHAR||(e=t.constructor());for(let i in t)if(t.hasOwnProperty(i)&&(!s||!s[i])&&"_noForwarding"!=i)try{e[i]=h(e[i],t[i])}catch(e){}return e}var l={};function d(e,t){f(e,t),t.add(e)}function u(e,t,s){return(t=function(e){var t=function(e,t){if("object"!=typeof e||null===e)return e;var s=e[Symbol.toPrimitive];if(void 0!==s){var i=s.call(e,"string");if("object"!=typeof i)return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==typeof t?t:String(t)}(t))in e?Object.defineProperty(e,t,{value:s,enumerable:!0,configurable:!0,writable:!0}):e[t]=s,e}function p(e,t,s){f(e,t),t.set(e,s)}function f(e,t){if(t.has(e))throw new TypeError("Cannot initialize the same private elements twice on an object")}function g(e,t,s){return b(e,_(e,t,"set"),s),s}function m(e,t){return T(e,_(e,t,"get"))}function _(e,t,s){if(!t.has(e))throw new TypeError("attempted to "+s+" private field on non-instance");return t.get(e)}function b(e,t,s){if(t.set)t.set.call(e,s);else{if(!t.writable)throw new TypeError("attempted to set read only private field");t.value=s}}function v(e,t,s){return S(e,t),w(s,"get"),T(e,s)}function w(e,t){if(void 0===e)throw new TypeError("attempted to "+t+" private static field before its declaration")}function S(e,t){if(e!==t)throw new TypeError("Private static access of wrong provenance")}function T(e,t){return t.get?t.get.call(e):t.value}function E(e,t,s){if(!t.has(e))throw new TypeError("attempted to get private field on non-instance");return s}let y,M;function P(e,t,s,i){let n=null;return["http","https","ws","wss"].includes(t)&&(n=`${t}://${e}`,"/"!==n.charAt(n.length-1)&&(n+="/"),n+="v"+s+"/channels",["http","https"].includes(t)&&(n+="/lp"),n+="?apikey="+i),n}Object.defineProperty(l,"__esModule",{value:!0}),l.default=void 0;var A=new WeakMap,R=new WeakMap,x=new WeakMap,O=new WeakMap,C=new WeakSet,D=new WeakSet,I=new WeakSet,N=new WeakSet,k=new WeakSet;class U{constructor(e,t,s){if(d(this,k),d(this,N),d(this,I),d(this,D),d(this,C),p(this,A,{writable:!0,value:null}),p(this,R,{writable:!0,value:0}),p(this,x,{writable:!0,value:!1}),p(this,O,{writable:!0,value:null}),u(this,"host",void 0),u(this,"secure",void 0),u(this,"apiKey",void 0),u(this,"version",void 0),u(this,"autoreconnect",void 0),u(this,"initialized",void 0),u(this,"onMessage",void 0),u(this,"onDisconnect",void 0),u(this,"onOpen",void 0),u(this,"onAutoreconnectIteration",void 0),this.host=e.host,this.secure=e.secure,this.apiKey=e.apiKey,this.version=t,this.autoreconnect=s,"lp"===e.transport?(E(this,N,W).call(this),this.initialized="lp"):"ws"===e.transport&&(E(this,k,G).call(this),this.initialized="ws"),!this.initialized)throw v(U,U,V).call(U,"Unknown or invalid network transport. Running under Node? Call 'Tinode.setNetworkProviders()'."),new Error("Unknown or invalid network transport. Running under Node? Call 'Tinode.setNetworkProviders()'.")}static setNetworkProviders(e,t){y=e,M=t}static set logger(e){var t,s,i;s=V,i=e,S(t=U,U),w(s,"set"),b(t,s,i)}connect(e,t){return Promise.reject(null)}reconnect(e){}disconnect(){}sendText(e){}isConnected(){return!1}transport(){return this.initialized}probe(){this.sendText("1")}backoffReset(){E(this,I,L).call(this)}}function j(){clearTimeout(m(this,A));const e=Math.pow(2,m(this,R))*(1+.3*Math.random())*2e3;g(this,R,m(this,R)>=10?m(this,R):m(this,R)+1),this.onAutoreconnectIteration&&this.onAutoreconnectIteration(e),g(this,A,setTimeout((t=>{if(v(U,U,V).call(U,`Reconnecting, iter=${m(this,R)}, timeout=${e}`),m(this,x))this.onAutoreconnectIteration&&this.onAutoreconnectIteration(-1);else{const e=this.connect();this.onAutoreconnectIteration?this.onAutoreconnectIteration(0,e):e.catch((e=>{}))}}),e))}function q(){clearTimeout(m(this,A)),g(this,A,null)}function L(){g(this,R,0)}function W(){let e=null,t=null,s=null,i=(t,s,n)=>{let a=new M,o=!1;return a.onreadystatechange=c=>{if(4==a.readyState)if(201==a.status){let n=JSON.parse(a.responseText,r.jsonParseHelper);e=t+"&sid="+n.ctrl.params.sid,a=i(e),a.send(null),this.onOpen&&this.onOpen(),s&&(o=!0,s()),this.autoreconnect&&E(this,D,q).call(this)}else if(a.status<400)this.onMessage&&this.onMessage(a.responseText),a=i(e),a.send(null);else{if(n&&!o&&(o=!0,n(a.responseText)),this.onMessage&&a.responseText&&this.onMessage(a.responseText),this.onDisconnect){const e=a.status||(m(this,x)?418:503),t=a.responseText||(m(this,x)?"Disconnected by client":"Connection failed");this.onDisconnect(new Error(t+" ("+e+")"),e)}a=null,!m(this,x)&&this.autoreconnect&&E(this,C,j).call(this)}},a.open("POST",t,!0),a};this.connect=(e,s)=>{if(g(this,x,!1),t){if(!s)return Promise.resolve();t.onreadystatechange=void 0,t.abort(),t=null}return e&&(this.host=e),new Promise(((e,s)=>{const n=P(this.host,this.secure?"https":"http",this.version,this.apiKey);v(U,U,V).call(U,"LP connecting to:",n),t=i(n,e,s),t.send(null)})).catch((e=>{v(U,U,V).call(U,"LP connection failed:",e)}))},this.reconnect=e=>{E(this,D,q).call(this),this.connect(null,e)},this.disconnect=i=>{g(this,x,!0),E(this,D,q).call(this),s&&(s.onreadystatechange=void 0,s.abort(),s=null),t&&(t.onreadystatechange=void 0,t.abort(),t=null),this.onDisconnect&&this.onDisconnect(new Error("Disconnected by client (418)"),418),e=null},this.sendText=t=>{if(s=(e=>{const t=new M;return t.onreadystatechange=e=>{if(4==t.readyState&&t.status>=400)throw new Error("LP sender failed, "+t.status)},t.open("POST",e,!0),t})(e),!s||1!=s.readyState)throw new Error("Long poller failed to connect");s.send(t)},this.isConnected=e=>t&&!0}function G(){this.connect=(e,t)=>{if(g(this,x,!1),m(this,O)){if(!t&&m(this,O).readyState==m(this,O).OPEN)return Promise.resolve();m(this,O).close(),g(this,O,null)}return e&&(this.host=e),new Promise(((e,t)=>{const s=P(this.host,this.secure?"wss":"ws",this.version,this.apiKey);v(U,U,V).call(U,"WS connecting to: ",s);const i=new y(s);i.onerror=e=>{t(e)},i.onopen=t=>{this.autoreconnect&&E(this,D,q).call(this),this.onOpen&&this.onOpen(),e()},i.onclose=e=>{if(g(this,O,null),this.onDisconnect){const e=m(this,x)?418:503;this.onDisconnect(new Error(m(this,x)?"Disconnected by client":"Connection failed ("+e+")"),e)}!m(this,x)&&this.autoreconnect&&E(this,C,j).call(this)},i.onmessage=e=>{this.onMessage&&this.onMessage(e.data)},g(this,O,i)}))},this.reconnect=e=>{E(this,D,q).call(this),this.connect(null,e)},this.disconnect=e=>{g(this,x,!0),E(this,D,q).call(this),m(this,O)&&(m(this,O).close(),g(this,O,null))},this.sendText=e=>{if(!m(this,O)||m(this,O).readyState!=m(this,O).OPEN)throw new Error("Websocket is not connected");m(this,O).send(e)},this.isConnected=e=>m(this,O)&&m(this,O).readyState==m(this,O).OPEN}l.default=U;var V={writable:!0,value:e=>{}};U.NETWORK_ERROR=503,U.NETWORK_ERROR_TEXT="Connection failed",U.NETWORK_USER=418,U.NETWORK_USER_TEXT="Disconnected by client";var F={};function H(e,t,s){return(t=function(e){var t=function(e,t){if("object"!=typeof e||null===e)return e;var s=e[Symbol.toPrimitive];if(void 0!==s){var i=s.call(e,"string");if("object"!=typeof i)return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==typeof t?t:String(t)}(t))in e?Object.defineProperty(e,t,{value:s,enumerable:!0,configurable:!0,writable:!0}):e[t]=s,e}function z(e,t,s){B(e,t),t.set(e,s)}function B(e,t){if(t.has(e))throw new TypeError("Cannot initialize the same private elements twice on an object")}function Q(e,t,s){return $(e,t),function(e,t){if(void 0===e)throw new TypeError("attempted to get private static field before its declaration")}(s),Y(e,s)}function K(e,t,s){if(!t.has(e))throw new TypeError("attempted to get private field on non-instance");return s}function X(e,t,s){return $(e,t),s}function $(e,t){if(e!==t)throw new TypeError("Private static access of wrong provenance")}function J(e,t){return Y(e,ee(e,t,"get"))}function Y(e,t){return t.get?t.get.call(e):t.value}function Z(e,t,s){return function(e,t,s){if(t.set)t.set.call(e,s);else{if(!t.writable)throw new TypeError("attempted to set read only private field");t.value=s}}(e,ee(e,t,"set"),s),s}function ee(e,t,s){if(!t.has(e))throw new TypeError("attempted to "+s+" private field on non-instance");return t.get(e)}let te;Object.defineProperty(F,"__esModule",{value:!0}),F.default=void 0;var se=new WeakMap,ie=new WeakMap,ne=new WeakSet;class re{constructor(e,t){var s;B(this,s=ne),s.add(this),z(this,se,{writable:!0,value:e=>{}}),z(this,ie,{writable:!0,value:e=>{}}),H(this,"db",null),H(this,"disabled",!1),Z(this,se,e||J(this,se)),Z(this,ie,t||J(this,ie))}initDatabase(){return new Promise(((e,t)=>{const s=te.open("tinode-web",1);s.onsuccess=t=>{this.db=t.target.result,this.disabled=!1,e(this.db)},s.onerror=e=>{J(this,ie).call(this,"PCache","failed to initialize",e),t(e.target.error),J(this,se).call(this,e.target.error)},s.onupgradeneeded=e=>{this.db=e.target.result,this.db.onerror=e=>{J(this,ie).call(this,"PCache","failed to create storage",e),J(this,se).call(this,e.target.error)},this.db.createObjectStore("topic",{keyPath:"name"}),this.db.createObjectStore("user",{keyPath:"uid"}),this.db.createObjectStore("subscription",{keyPath:["topic","uid"]}),this.db.createObjectStore("message",{keyPath:["topic","seq"]})}}))}deleteDatabase(){return this.db&&(this.db.close(),this.db=null),new Promise(((e,t)=>{const s=te.deleteDatabase("tinode-web");s.onblocked=e=>{this.db&&this.db.close();const s=new Error("blocked");J(this,ie).call(this,"PCache","deleteDatabase",s),t(s)},s.onsuccess=t=>{this.db=null,this.disabled=!0,e(!0)},s.onerror=e=>{J(this,ie).call(this,"PCache","deleteDatabase",e.target.error),t(e.target.error)}}))}isReady(){return!!this.db}updTopic(e){return this.isReady()?new Promise(((t,s)=>{const i=this.db.transaction(["topic"],"readwrite");i.oncomplete=e=>{t(e.target.result)},i.onerror=e=>{J(this,ie).call(this,"PCache","updTopic",e.target.error),s(e.target.error)};const n=i.objectStore("topic").get(e.name);n.onsuccess=t=>{i.objectStore("topic").put(X(re,re,ce).call(re,n.result,e)),i.commit()}})):this.disabled?Promise.resolve():Promise.reject(new Error("not initialized"))}markTopicAsDeleted(e){return this.isReady()?new Promise(((t,s)=>{const i=this.db.transaction(["topic"],"readwrite");i.oncomplete=e=>{t(e.target.result)},i.onerror=e=>{J(this,ie).call(this,"PCache","markTopicAsDeleted",e.target.error),s(e.target.error)},i.objectStore("topic").get(e).onsuccess=e=>{const t=e.target.result;t._deleted=!0,i.objectStore("topic").put(t),i.commit()}})):this.disabled?Promise.resolve():Promise.reject(new Error("not initialized"))}remTopic(e){return this.isReady()?new Promise(((t,s)=>{const i=this.db.transaction(["topic","subscription","message"],"readwrite");i.oncomplete=e=>{t(e.target.result)},i.onerror=e=>{J(this,ie).call(this,"PCache","remTopic",e.target.error),s(e.target.error)},i.objectStore("topic").delete(IDBKeyRange.only(e)),i.objectStore("subscription").delete(IDBKeyRange.bound([e,"-"],[e,"~"])),i.objectStore("message").delete(IDBKeyRange.bound([e,0],[e,Number.MAX_SAFE_INTEGER])),i.commit()})):this.disabled?Promise.resolve():Promise.reject(new Error("not initialized"))}mapTopics(e,t){return K(this,ne,ae).call(this,"topic",e,t)}deserializeTopic(e,t){X(re,re,oe).call(re,e,t)}updUser(e,t){if(!(arguments.length<2||void 0===t))return this.isReady()?new Promise(((s,i)=>{const n=this.db.transaction(["user"],"readwrite");n.oncomplete=e=>{s(e.target.result)},n.onerror=e=>{J(this,ie).call(this,"PCache","updUser",e.target.error),i(e.target.error)},n.objectStore("user").put({uid:e,public:t}),n.commit()})):this.disabled?Promise.resolve():Promise.reject(new Error("not initialized"))}remUser(e){return this.isReady()?new Promise(((t,s)=>{const i=this.db.transaction(["user"],"readwrite");i.oncomplete=e=>{t(e.target.result)},i.onerror=e=>{J(this,ie).call(this,"PCache","remUser",e.target.error),s(e.target.error)},i.objectStore("user").delete(IDBKeyRange.only(e)),i.commit()})):this.disabled?Promise.resolve():Promise.reject(new Error("not initialized"))}mapUsers(e,t){return K(this,ne,ae).call(this,"user",e,t)}getUser(e){return this.isReady()?new Promise(((t,s)=>{const i=this.db.transaction(["user"]);i.oncomplete=e=>{const s=e.target.result;t({user:s.uid,public:s.public})},i.onerror=e=>{J(this,ie).call(this,"PCache","getUser",e.target.error),s(e.target.error)},i.objectStore("user").get(e)})):this.disabled?Promise.resolve():Promise.reject(new Error("not initialized"))}updSubscription(e,t,s){return this.isReady()?new Promise(((i,n)=>{const r=this.db.transaction(["subscription"],"readwrite");r.oncomplete=e=>{i(e.target.result)},r.onerror=e=>{J(this,ie).call(this,"PCache","updSubscription",e.target.error),n(e.target.error)},r.objectStore("subscription").get([e,t]).onsuccess=i=>{r.objectStore("subscription").put(X(re,re,he).call(re,i.target.result,e,t,s)),r.commit()}})):this.disabled?Promise.resolve():Promise.reject(new Error("not initialized"))}mapSubscriptions(e,t,s){return this.isReady()?new Promise(((i,n)=>{const r=this.db.transaction(["subscription"]);r.onerror=e=>{J(this,ie).call(this,"PCache","mapSubscriptions",e.target.error),n(e.target.error)},r.objectStore("subscription").getAll(IDBKeyRange.bound([e,"-"],[e,"~"])).onsuccess=e=>{t&&e.target.result.forEach((e=>{t.call(s,e)})),i(e.target.result)}})):this.disabled?Promise.resolve([]):Promise.reject(new Error("not initialized"))}addMessage(e){return this.isReady()?new Promise(((t,s)=>{const i=this.db.transaction(["message"],"readwrite");i.onsuccess=e=>{t(e.target.result)},i.onerror=e=>{J(this,ie).call(this,"PCache","addMessage",e.target.error),s(e.target.error)},i.objectStore("message").add(X(re,re,le).call(re,null,e)),i.commit()})):this.disabled?Promise.resolve():Promise.reject(new Error("not initialized"))}updMessageStatus(e,t,s){return this.isReady()?new Promise(((i,n)=>{const r=this.db.transaction(["message"],"readwrite");r.onsuccess=e=>{i(e.target.result)},r.onerror=e=>{J(this,ie).call(this,"PCache","updMessageStatus",e.target.error),n(e.target.error)};const a=r.objectStore("message").get(IDBKeyRange.only([e,t]));a.onsuccess=i=>{const n=a.result||i.target.result;n&&n._status!=s?(r.objectStore("message").put(X(re,re,le).call(re,n,{topic:e,seq:t,_status:s})),r.commit()):r.commit()}})):this.disabled?Promise.resolve():Promise.reject(new Error("not initialized"))}remMessages(e,t,s){return this.isReady()?new Promise(((i,n)=>{t||s||(t=0,s=Number.MAX_SAFE_INTEGER);const r=s>0?IDBKeyRange.bound([e,t],[e,s],!1,!0):IDBKeyRange.only([e,t]),a=this.db.transaction(["message"],"readwrite");a.onsuccess=e=>{i(e.target.result)},a.onerror=e=>{J(this,ie).call(this,"PCache","remMessages",e.target.error),n(e.target.error)},a.objectStore("message").delete(r),a.commit()})):this.disabled?Promise.resolve():Promise.reject(new Error("not initialized"))}readMessages(e,t,s,i){return this.isReady()?new Promise(((n,r)=>{const a=(t=t||{}).since>0?t.since:0,o=t.before>0?t.before:Number.MAX_SAFE_INTEGER,c=0|t.limit,h=[],l=IDBKeyRange.bound([e,a],[e,o],!1,!0),d=this.db.transaction(["message"]);d.onerror=e=>{J(this,ie).call(this,"PCache","readMessages",e.target.error),r(e.target.error)},d.objectStore("message").openCursor(l,"prev").onsuccess=e=>{const t=e.target.result;t?(s&&s.call(i,t.value),h.push(t.value),c<=0||h.length<c?t.continue():n(h)):n(h)}})):this.disabled?Promise.resolve([]):Promise.reject(new Error("not initialized"))}static setDatabaseProvider(e){te=e}}function ae(e,t,s){return this.db?new Promise(((i,n)=>{const r=this.db.transaction([e]);r.onerror=t=>{J(this,ie).call(this,"PCache","mapObjects",e,t.target.error),n(t.target.error)},r.objectStore(e).getAll().onsuccess=e=>{t&&e.target.result.forEach((e=>{t.call(s,e)})),i(e.target.result)}})):disabled?Promise.resolve([]):Promise.reject(new Error("not initialized"))}function oe(e,t){Q(re,re,de).forEach((s=>{t.hasOwnProperty(s)&&(e[s]=t[s])})),Array.isArray(t.tags)&&(e._tags=t.tags),t.acs&&e.setAccessMode(t.acs),e.seq|=0,e.read|=0,e.unread=Math.max(0,e.seq-e.read)}function ce(e,t){const s=e||{name:t.name};return Q(re,re,de).forEach((e=>{t.hasOwnProperty(e)&&(s[e]=t[e])})),Array.isArray(t._tags)&&(s.tags=t._tags),t.acs&&(s.acs=t.getAccessMode().jsonHelper()),s}function he(e,t,s,i){const n=e||{topic:t,uid:s};return["updated","mode","read","recv","clear","lastSeen","userAgent"].forEach((e=>{i.hasOwnProperty(e)&&(n[e]=i[e])})),n}function le(e,t){const s=e||{};return["topic","seq","ts","_status","from","head","content"].forEach((e=>{t.hasOwnProperty(e)&&(s[e]=t[e])})),s}F.default=re;var de={writable:!0,value:["created","updated","deleted","read","recv","seq","clear","defacs","creds","public","trusted","private","touched","_deleted"]},ue={exports:{}};const pe=["act","height","duration","incoming","mime","name","premime","preref","preview","ref","size","state","url","val","width"],fe=[{name:"ST",start:/(?:^|[\W_])(\*)[^\s*]/,end:/[^\s*](\*)(?=$|[\W_])/},{name:"EM",start:/(?:^|\W)(_)[^\s_]/,end:/[^\s_](_)(?=$|\W)/},{name:"DL",start:/(?:^|[\W_])(~)[^\s~]/,end:/[^\s~](~)(?=$|[\W_])/},{name:"CO",start:/(?:^|\W)(`)[^`]/,end:/[^`](`)(?=$|\W)/}],ge=["QQ"],me=[{name:"LN",dataName:"url",pack:function(e){return/^[a-z]+:\/\//i.test(e)||(e="http://"+e),{url:e}},re:/(?:(?:https?|ftp):\/\/|www\.|ftp\.)[-A-Z0-9+&@#\/%=~_|$?!:,.]*[A-Z0-9+&@#\/%=~_|$]/gi},{name:"MN",dataName:"val",pack:function(e){return{val:e.slice(1)}},re:/\B@([\p{L}\p{N}][._\p{L}\p{N}]*[\p{L}\p{N}])/gu},{name:"HT",dataName:"val",pack:function(e){return{val:e.slice(1)}},re:/\B#([\p{L}\p{N}][._\p{L}\p{N}]*[\p{L}\p{N}])/gu}],_e={AU:{html_tag:"audio",md_tag:void 0,isVoid:!1},BN:{html_tag:"button",md_tag:void 0,isVoid:!1},BR:{html_tag:"br",md_tag:"\n",isVoid:!0},CO:{html_tag:"tt",md_tag:"`",isVoid:!1},DL:{html_tag:"del",md_tag:"~",isVoid:!1},EM:{html_tag:"i",md_tag:"_",isVoid:!1},EX:{html_tag:"",md_tag:void 0,isVoid:!0},FM:{html_tag:"div",md_tag:void 0,isVoid:!1},HD:{html_tag:"",md_tag:void 0,isVoid:!1},HL:{html_tag:"span",md_tag:void 0,isVoid:!1},HT:{html_tag:"a",md_tag:void 0,isVoid:!1},IM:{html_tag:"img",md_tag:void 0,isVoid:!1},LN:{html_tag:"a",md_tag:void 0,isVoid:!1},MN:{html_tag:"a",md_tag:void 0,isVoid:!1},RW:{html_tag:"div",md_tag:void 0,isVoid:!1},QQ:{html_tag:"div",md_tag:void 0,isVoid:!1},ST:{html_tag:"b",md_tag:"*",isVoid:!1},VC:{html_tag:"div",md_tag:void 0,isVoid:!1},VD:{html_tag:"video",md_tag:void 0,isVoid:!1}};function be(e,t,s){if(!e)return null;try{const s=atob(e),i=s.length,n=new ArrayBuffer(i),r=new Uint8Array(n);for(let e=0;e<i;e++)r[e]=s.charCodeAt(e);return URL.createObjectURL(new Blob([n],{type:t}))}catch(e){s&&s("Drafty: failed to convert object.",e.message)}return null}function ve(e,t){return e?"data:"+(t=t||"image/jpeg")+";base64,"+e:null}const we={ST:{open:e=>"<b>",close:e=>"</b>"},EM:{open:e=>"<i>",close:e=>"</i>"},DL:{open:e=>"<del>",close:e=>"</del>"},CO:{open:e=>"<tt>",close:e=>"</tt>"},BR:{open:e=>"<br/>",close:e=>""},HD:{open:e=>"",close:e=>""},HL:{open:e=>'<span style="color:teal">',close:e=>"</span>"},LN:{open:e=>'<a href="'+e.url+'">',close:e=>"</a>",props:e=>e?{href:e.url,target:"_blank"}:null},MN:{open:e=>'<a href="#'+e.val+'">',close:e=>"</a>",props:e=>e?{id:e.val}:null},HT:{open:e=>'<a href="#'+e.val+'">',close:e=>"</a>",props:e=>e?{id:e.val}:null},BN:{open:e=>"<button>",close:e=>"</button>",props:e=>e?{"data-act":e.act,"data-val":e.val,"data-name":e.name,"data-ref":e.ref}:null},AU:{open:e=>'<audio controls src="'+(e.ref||be(e.val,e.mime,Se.logger))+'">',close:e=>"</audio>",props:e=>e?{src:e.ref||be(e.val,e.mime,Se.logger),"data-preload":e.ref?"metadata":"auto","data-duration":e.duration,"data-name":e.name,"data-size":e.val?.75*e.val.length|0:0|e.size,"data-mime":e.mime}:null},IM:{open:e=>{const t=ve(e._tempPreview,e.mime),s=be(e.val,e.mime,Se.logger),i=e.ref||s;return(e.name?'<a href="'+i+'" download="'+e.name+'">':"")+'<img src="'+(t||s)+'"'+(e.width?' width="'+e.width+'"':"")+(e.height?' height="'+e.height+'"':"")+' border="0" />'},close:e=>e.name?"</a>":"",props:e=>e?{src:ve(e._tempPreview,e.mime)||e.ref||be(e.val,e.mime,Se.logger),title:e.name,alt:e.name,"data-width":e.width,"data-height":e.height,"data-name":e.name,"data-size":e.val?.75*e.val.length|0:0|e.size,"data-mime":e.mime}:null},FM:{open:e=>"<div>",close:e=>"</div>"},RW:{open:e=>"<div>",close:e=>"</div>"},QQ:{open:e=>"<div>",close:e=>"</div>",props:e=>e?{}:null},VC:{open:e=>"<div>",close:e=>"</div>",props:e=>e?{"data-duration":e.duration,"data-state":e.state}:{}},VD:{open:e=>{const t=ve(e._tempPreview,e.mime),s=e.ref||be(e.preview,e.premime||"image/json",Se.logger);return'<img src="'+(t||s)+'"'+(e.width?' width="'+e.width+'"':"")+(e.height?' height="'+e.height+'"':"")+' border="0" />'},close:e=>"",props:e=>e?{src:e.preref||be(e.preview,e.premime||"image/json",Se.logger),"data-src":e.ref||ve(e.val,e.mime),"data-width":e.width,"data-height":e.height,"data-preload":e.ref?"metadata":"auto","data-preview":be(e.preview,e.premime||"image/json",Se.logger),"data-duration":0|e.duration,"data-name":e.name,"data-size":e.val?.75*e.val.length|0:0|e.size,"data-mime":e.mime}:null}},Se=function(){this.txt="",this.fmt=[],this.ent=[]};function Te(e){if(!e)return null;e="string"==typeof e?{txt:e}:e;let{txt:t,fmt:s,ent:i}=e;if(t=t||"",Array.isArray(i)||(i=[]),!Array.isArray(s)||0==s.length){if(0==i.length)return{text:t};s=[{at:0,len:0,key:0}]}const n=[],r=[];s.forEach((e=>{if(!e||"object"!=typeof e)return;if(!["undefined","number"].includes(typeof e.at))return;if(!["undefined","number"].includes(typeof e.len))return;let s=0|e.at,a=0|e.len;if(a<0)return;let o=e.key||0;i.length>0&&("number"!=typeof o||o<0||o>=i.length)||(s<=-1?r.push({start:-1,end:0,key:o}):s+a>t.length||(e.tp?n.push({type:e.tp,start:s,end:s+a}):i.length>0&&"object"==typeof i[o]&&n.push({start:s,end:s+a,key:o})))})),n.sort(((e,t)=>{let s=e.start-t.start;return 0!=s?s:(s=t.end-e.end,0!=s?s:ge.indexOf(t.type)-ge.indexOf(e.type))})),r.length>0&&n.push(...r),n.forEach((e=>{i.length>0&&!e.type&&i[e.key]&&"object"==typeof i[e.key]&&(e.type=i[e.key].tp,e.data=i[e.key].data),e.type||(e.type="HD")}));let a=function e(t,s,i,n,r){if(!r||0==r.length)return i<n&&Ee(t,{text:s.substring(i,n)}),t;for(let n=0;n<r.length;n++){const a=r[n];if(a.start<0&&"EX"==a.type){Ee(t,{type:a.type,data:a.data,key:a.key,att:!0});continue}i<a.start&&(Ee(t,{text:s.substring(i,a.start)}),i=a.start);const o=[];for(;n<r.length-1;){const e=r[n+1];if(e.start<0)break;if(!(e.start<a.end))break;if(e.end<=a.end){const t=_e[e.tp]||{};(e.start<e.end||t.isVoid)&&o.push(e)}n++}Ee(t,e({type:a.type,data:a.data,key:a.key},s,i,a.end,o)),i=a.end}return i<n&&Ee(t,{text:s.substring(i,n)}),t}({},t,0,t.length,n);return a=Me(a,(function(e){if(Array.isArray(e.children)&&1==e.children.length){const t=e.children[0];if(e.type)t.type||t.children||(e.text=t.text,delete e.children);else{const s=e.parent;(e=t).parent=s}}return e})),a}function Ee(e,t){return t?(e.children||(e.children=[]),e.text&&(e.children.push({text:e.text,parent:e}),delete e.text),t.parent=e,e.children.push(t),e):e}function ye(e,t,s){if(!t)return e;e.txt=e.txt||"";const i=e.txt.length;if(t.text?e.txt+=t.text:Array.isArray(t.children)&&t.children.forEach((t=>{ye(e,t,s)})),t.type){const n=e.txt.length-i;if(e.fmt=e.fmt||[],Object.keys(t.data||{}).length>0){e.ent=e.ent||[];const r=void 0===s[t.key]?e.ent.length:s[t.key];s[t.key]=r,e.ent[r]={tp:t.type,data:t.data},t.att?e.fmt.push({at:-1,len:0,key:r}):e.fmt.push({at:i,len:n,key:r})}else e.fmt.push({tp:t.type,at:i,len:n})}return e}function Me(e,t,s){if(!e)return null;let i=t.call(s,e);if(!i||!i.children)return i;const n=[];for(let e in i.children){let r=i.children[e];r&&(r=Me(r,t,s),r&&n.push(r))}return 0==n.length?i.children=null:i.children=n,i}function Pe(e,t,s,i,n){if(!e)return null;i&&e.type&&i.push(e.type);let r=[];for(let s in e.children){const a=Pe(e.children[s],t,s,i,n);a&&r.push(a)}return 0==r.length&&(r=e.text?[e.text]:null),i&&e.type&&i.pop(),t.call(n,e.type,e.data,r,s,i)}function Ae(e,t,s){return e?(s&&(t-=s.length),Me(e,(function(e){if(t<=-1)return null;if(e.att)return e;if(0==t)e.text=s,t=-1;else if(e.text){const i=e.text.length;i>t?(e.text=e.text.substring(0,t)+s,t=-1):t-=i}return e}))):null}function Re(e,t){return Me(e,(e=>{const s=Oe(e.data,!0,t?t(e):null);return s?e.data=s:delete e.data,e}))}function xe(e,t){if(!e)return null;if(e.att)e.text=" ",delete e.att,delete e.children;else if(e.children){const s=[],i=[];for(let n in e.children){const r=e.children[n];if(r.att){if(s.length==t)continue;if("application/json"==r.data.mime)continue;delete r.att,delete r.children,r.text=" ",s.push(r)}else i.push(r)}e.children=i.concat(s)}return e}function Oe(e,t,s){if(e&&Object.entries(e).length>0){s=s||[];const i={};if(pe.forEach((n=>{if(e[n]){if(t&&!s.includes(n)&&("string"==typeof e[n]||Array.isArray(e[n]))&&e[n].length>64)return;if("object"==typeof e[n])return;i[n]=e[n]}})),0!=Object.entries(i).length)return i}return null}Se.init=function(e){if(void 0===e)e="";else if("string"!=typeof e)return null;return{txt:e}},Se.parse=function(e){if("string"!=typeof e)return null;const t=e.split(/\r?\n/),s=[],i={},n=[];t.forEach((e=>{let t,r,a=[];if(fe.forEach((t=>{a=a.concat(function(e,t,s,i){const n=[];let r=0,a=e.slice(0);for(;a.length>0;){const o=t.exec(a);if(null==o)break;let c=o.index+o[0].lastIndexOf(o[1]);a=a.slice(c+1),c+=r,r=c+1;const h=s?s.exec(a):null;if(null==h)break;let l=h.index+h[0].indexOf(h[1]);a=a.slice(l+1),l+=r,r=l+1,n.push({txt:e.slice(c+1,l),children:[],at:c,end:l,tp:i})}return n}(e,t.start,t.end,t.name))})),0==a.length)r={txt:e};else{a.sort(((e,t)=>{const s=e.at-t.at;return 0!=s?s:t.end-e.end})),a=function e(t){if(0==t.length)return[];const s=[t[0]];let i=t[0];for(let e=1;e<t.length;e++)t[e].at>i.end?(s.push(t[e]),i=t[e]):t[e].end<=i.end&&i.children.push(t[e]);for(let t in s)s[t].children=e(s[t].children);return s}(a);const t=function e(t,s){let i="",n=[];for(let r in t){const a=t[r];if(!a.txt){const t=e(a.children,i.length+s);a.txt=t.txt,n=n.concat(t.fmt)}a.tp&&n.push({at:i.length+s,len:a.txt.length,tp:a.tp}),i+=a.txt}return{txt:i,fmt:n}}(function e(t,s,i,n){const r=[];if(0==n.length)return[];for(let i in n){const a=n[i];a.at>s&&r.push({txt:t.slice(s,a.at)});const o={tp:a.tp},c=e(t,a.at+1,a.end,a.children);c.length>0?o.children=c:o.txt=a.txt,r.push(o),s=a.end+1}return s<i&&r.push({txt:t.slice(s,i)}),r}(e,0,e.length,a),0);r={txt:t.txt,fmt:t.fmt}}if(t=function(e){let t,s=[];if(me.forEach((i=>{for(;null!==(t=i.re.exec(e));)s.push({offset:t.index,len:t[0].length,unique:t[0],data:i.pack(t[0]),type:i.name})})),0==s.length)return s;s.sort(((e,t)=>e.offset-t.offset));let i=-1;return s=s.filter((e=>{const t=e.offset>i;return i=e.offset+e.len,t})),s}(r.txt),t.length>0){const e=[];for(let n in t){const r=t[n];let a=i[r.unique];a||(a=s.length,i[r.unique]=a,s.push({tp:r.type,data:r.data})),e.push({at:r.offset,len:r.len,key:a})}r.ent=e}n.push(r)}));const r={txt:""};if(n.length>0){r.txt=n[0].txt,r.fmt=(n[0].fmt||[]).concat(n[0].ent||[]);for(let e=1;e<n.length;e++){const t=n[e],s=r.txt.length+1;r.fmt.push({tp:"BR",len:1,at:s-1}),r.txt+=" "+t.txt,t.fmt&&(r.fmt=r.fmt.concat(t.fmt.map((e=>(e.at+=s,e))))),t.ent&&(r.fmt=r.fmt.concat(t.ent.map((e=>(e.at+=s,e)))))}0==r.fmt.length&&delete r.fmt,s.length>0&&(r.ent=s)}return r},Se.append=function(e,t){if(!e)return t;if(!t)return e;e.txt=e.txt||"";const s=e.txt.length;return"string"==typeof t?e.txt+=t:t.txt&&(e.txt+=t.txt),Array.isArray(t.fmt)&&(e.fmt=e.fmt||[],Array.isArray(t.ent)&&(e.ent=e.ent||[]),t.fmt.forEach((i=>{const n={at:(0|i.at)+s,len:0|i.len};-1==i.at&&(n.at=-1,n.len=0),i.tp?n.tp=i.tp:(n.key=e.ent.length,e.ent.push(t.ent[i.key||0])),e.fmt.push(n)}))),e},Se.insertImage=function(e,t,s){(e=e||{txt:" "}).ent=e.ent||[],e.fmt=e.fmt||[],e.fmt.push({at:0|t,len:1,key:e.ent.length});const i={tp:"IM",data:{mime:s.mime,ref:s.refurl,val:s.bits||s.preview,width:s.width,height:s.height,name:s.filename,size:0|s.size}};return s.urlPromise&&(i.data._tempPreview=s._tempPreview,i.data._processing=!0,s.urlPromise.then((e=>{i.data.ref=e,i.data._tempPreview=void 0,i.data._processing=void 0}),(e=>{i.data._processing=void 0}))),e.ent.push(i),e},Se.insertVideo=function(e,t,s){(e=e||{txt:" "}).ent=e.ent||[],e.fmt=e.fmt||[],e.fmt.push({at:0|t,len:1,key:e.ent.length});const i={tp:"VD",data:{mime:s.mime,ref:s.refurl,val:s.bits,preref:s.preref,preview:s.preview,width:s.width,height:s.height,duration:0|s.duration,name:s.filename,size:0|s.size}};return s.urlPromise&&(i.data._tempPreview=s._tempPreview,i.data._processing=!0,s.urlPromise.then((e=>{i.data.ref=e[0],i.data.preref=e[1],i.data._tempPreview=void 0,i.data._processing=void 0}),(e=>{i.data._processing=void 0}))),e.ent.push(i),e},Se.insertAudio=function(e,t,s){(e=e||{txt:" "}).ent=e.ent||[],e.fmt=e.fmt||[],e.fmt.push({at:0|t,len:1,key:e.ent.length});const i={tp:"AU",data:{mime:s.mime,val:s.bits,duration:0|s.duration,preview:s.preview,name:s.filename,size:0|s.size,ref:s.refurl}};return s.urlPromise&&(i.data._processing=!0,s.urlPromise.then((e=>{i.data.ref=e,i.data._processing=void 0}),(e=>{i.data._processing=void 0}))),e.ent.push(i),e},Se.videoCall=function(){return{txt:" ",fmt:[{at:0,len:1,key:0}],ent:[{tp:"VC"}]}},Se.updateVideoCall=function(e,t){const s=((e||{}).fmt||[])[0];if(!s)return e;let i;if("VC"==s.tp)delete s.tp,s.key=0,i={tp:"VC"},e.ent=[i];else if(i=(e.ent||[])[0|s.key],!i||"VC"!=i.tp)return e;return i.data=i.data||{},Object.assign(i.data,t),e},Se.quote=function(e,t,s){const i=Se.append(Se.appendLineBreak(Se.mention(e,t)),s);return i.fmt.push({at:0,len:i.txt.length,tp:"QQ"}),i},Se.mention=function(e,t){return{txt:e||"",fmt:[{at:0,len:(e||"").length,key:0}],ent:[{tp:"MN",data:{val:t}}]}},Se.appendLink=function(e,t){(e=e||{txt:""}).ent=e.ent||[],e.fmt=e.fmt||[],e.fmt.push({at:e.txt.length,len:t.txt.length,key:e.ent.length}),e.txt+=t.txt;const s={tp:"LN",data:{url:t.url}};return e.ent.push(s),e},Se.appendImage=function(e,t){return(e=e||{txt:""}).txt+=" ",Se.insertImage(e,e.txt.length-1,t)},Se.appendAudio=function(e,t){return(e=e||{txt:""}).txt+=" ",Se.insertAudio(e,e.txt.length-1,t)},Se.attachFile=function(e,t){(e=e||{txt:""}).ent=e.ent||[],e.fmt=e.fmt||[],e.fmt.push({at:-1,len:0,key:e.ent.length});const s={tp:"EX",data:{mime:t.mime,val:t.data,name:t.filename,ref:t.refurl,size:0|t.size}};return t.urlPromise&&(s.data._processing=!0,t.urlPromise.then((e=>{s.data.ref=e,s.data._processing=void 0}),(e=>{s.data._processing=void 0}))),e.ent.push(s),e},Se.wrapInto=function(e,t,s,i){return"string"==typeof e&&(e={txt:e}),e.fmt=e.fmt||[],e.fmt.push({at:s||0,len:i||e.txt.length,tp:t}),e},Se.wrapAsForm=function(e,t,s){return Se.wrapInto(e,"FM",t,s)},Se.insertButton=function(e,t,s,i,n,r,a){return"string"==typeof e&&(e={txt:e}),!e||!e.txt||e.txt.length<t+s||s<=0||-1==["url","pub"].indexOf(n)?null:"url"!=n||a?(a=""+a,e.ent=e.ent||[],e.fmt=e.fmt||[],e.fmt.push({at:0|t,len:s,key:e.ent.length}),e.ent.push({tp:"BN",data:{act:n,val:r,ref:a,name:i}}),e):null},Se.appendButton=function(e,t,s,i,n,r){const a=(e=e||{txt:""}).txt.length;return e.txt+=t,Se.insertButton(e,a,t.length,s,i,n,r)},Se.attachJSON=function(e,t){return(e=e||{txt:""}).ent=e.ent||[],e.fmt=e.fmt||[],e.fmt.push({at:-1,len:0,key:e.ent.length}),e.ent.push({tp:"EX",data:{mime:"application/json",val:t}}),e},Se.appendLineBreak=function(e){return(e=e||{txt:""}).fmt=e.fmt||[],e.fmt.push({at:e.txt.length,len:1,tp:"BR"}),e.txt+=" ",e},Se.UNSAFE_toHTML=function(e){return Pe(Te(e),(function(e,t,s){const i=we[e];let n=s?s.join(""):"";return i&&(n=i.open(t)+n+i.close(t)),n}),0)},Se.format=function(e,t,s){return Pe(Te(e),t,0,[],s)},Se.shorten=function(e,t,s){let i=Te(e);return i=Ae(i,t,"…"),i&&s&&(i=Re(i)),ye({},i,[])},Se.forwardedContent=function(e){let t=Te(e);return t=Me(t,(function(e){return"MN"!=e.type||e.parent&&e.parent.type?e:null})),t=function e(t){if("BR"==t.type)t=null;else if(t.text)t.type||(t.text=t.text.trimStart(),t.text||(t=null));else if(!t.type&&t.children&&t.children.length>0){const s=e(t.children[0]);s?t.children[0]=s:(t.children.shift(),t.type||0!=t.children.length||(t=null))}return t}(t),ye({},t,[])},Se.replyContent=function(e,t){let s=Te(e);return s?(s=Me(s,(function(e){return"QQ"==e.type?null:("MN"==e.type?e.parent&&e.parent.type||!(e.text||"").startsWith("➦")||(e.text="➦",delete e.children,delete e.data):"BR"==e.type&&(e.text=" ",delete e.type,delete e.children),e)})),s=xe(s,3),s=Ae(s,t,"…"),s=Re(s,(e=>{switch(e.type){case"IM":return["val"];case"VD":return["preview"]}return null})),ye({},s,[])):e},Se.preview=function(e,t,s){let i=Te(e);return i=xe(i,3),i=Me(i,(function(e){return"MN"==e.type?e.parent&&e.parent.type||!(e.text||"").startsWith("➦")||(e.text="➦",delete e.children):"QQ"==e.type?(e.text=" ",delete e.children):"BR"==e.type&&(e.text=" ",delete e.children,delete e.type),e})),i=Ae(i,t,"…"),i=s?Re(i,(e=>"IM"==e.type?["val"]:null)):Re(i),ye({},i,[])},Se.toPlainText=function(e){return"string"==typeof e?e:e.txt},Se.isPlainText=function(e){return"string"==typeof e||!(e.fmt||e.ent)},Se.toMarkdown=function(e){return Pe(Te(e),(function(e,t,s){const i=_e[e];let n=s?s.join(""):"";return i&&(i.isVoid?n=i.md_tag||"":i.md_tag&&(n=i.md_tag+n+i.md_tag)),n}),0)},Se.isValid=function(e){if(!e)return!1;const{txt:t,fmt:s,ent:i}=e;if(!t&&""!==t&&!s&&!i)return!1;const n=typeof t;return!("string"!=n&&"undefined"!=n&&null!==t||void 0!==s&&!Array.isArray(s)&&null!==s||void 0!==i&&!Array.isArray(i)&&null!==i)},Se.hasAttachments=function(e){if(!Array.isArray(e.fmt))return!1;for(let t in e.fmt){const s=e.fmt[t];if(s&&s.at<0){const t=e.ent[0|s.key];return t&&"EX"==t.tp&&t.data}}return!1},Se.attachments=function(e,t,s){if(!Array.isArray(e.fmt))return;let i=0;for(let n in e.ent){let r=e.fmt[n];if(r&&r.at<0){const n=e.ent[0|r.key];if(n&&"EX"==n.tp&&n.data&&t.call(s,n.data,i++,"EX"))break}}},Se.hasEntities=function(e){return e.ent&&e.ent.length>0},Se.entities=function(e,t,s){if(e.ent&&e.ent.length>0)for(let i in e.ent)if(e.ent[i]&&t.call(s,e.ent[i].data,i,e.ent[i].tp))break},Se.styles=function(e,t,s){if(e.fmt&&e.fmt.length>0)for(let i in e.fmt){const n=e.fmt[i];if(n&&t.call(s,n.tp,n.at,n.len,n.key,i))break}},Se.sanitizeEntities=function(e){if(e&&e.ent&&e.ent.length>0)for(let t in e.ent){const s=e.ent[t];if(s&&s.data){const i=Oe(s.data);i?e.ent[t].data=i:delete e.ent[t].data}}return e},Se.getDownloadUrl=function(e){let t=null;return"application/json"!=e.mime&&e.val?t=be(e.val,e.mime,Se.logger):"string"==typeof e.ref&&(t=e.ref),t},Se.isProcessing=function(e){return!!e._processing},Se.getPreviewUrl=function(e){return e.val?be(e.val,e.mime,Se.logger):null},Se.getEntitySize=function(e){return e.size?e.size:e.val?.75*e.val.length|0:0},Se.getEntityMimeType=function(e){return e.mime||"text/plain"},Se.tagName=function(e){return _e[e]&&_e[e].html_tag},Se.attrValue=function(e,t){if(t&&we[e])return we[e].props(t)},Se.getContentType=function(){return"text/x-drafty"},ue.exports=Se,ue=ue.exports;var Ce={};let De;Object.defineProperty(Ce,"__esModule",{value:!0}),Ce.default=void 0,Ce.default=class{constructor(e,t){this._tinode=e,this._version=t,this._apiKey=e._apiKey,this._authToken=e.getAuthToken(),this._reqId=e.getNextUniqueId(),this.xhr=new De,this.toResolve=null,this.toReject=null,this.onProgress=null,this.onSuccess=null,this.onFailure=null}uploadWithBaseUrl(e,t,s,i,n,a){const o=this;let c=`/v${this._version}/file/u/`;if(e){let t=e;if(t.endsWith("/")&&(t=t.slice(0,-1)),!t.startsWith("http://")&&!t.startsWith("https://"))throw new Error(`Invalid base URL '${e}'`);c=t+c}this.xhr.open("POST",c,!0),this.xhr.setRequestHeader("X-Tinode-APIKey",this._apiKey),this._authToken&&this.xhr.setRequestHeader("X-Tinode-Auth","Token "+this._authToken.token);const h=new Promise(((e,t)=>{this.toResolve=e,this.toReject=t}));this.onProgress=i,this.onSuccess=n,this.onFailure=a,this.xhr.upload.onprogress=e=>{e.lengthComputable&&o.onProgress&&o.onProgress(e.loaded/e.total)},this.xhr.onload=function(){let e;try{e=JSON.parse(this.response,r.jsonParseHelper)}catch(t){o._tinode.logger("ERROR: Invalid server response in LargeFileHelper",this.response),e={ctrl:{code:this.status,text:this.statusText}}}this.status>=200&&this.status<300?(o.toResolve&&o.toResolve(e.ctrl.params.url),o.onSuccess&&o.onSuccess(e.ctrl)):this.status>=400?(o.toReject&&o.toReject(new Error(`${e.ctrl.text} (${e.ctrl.code})`)),o.onFailure&&o.onFailure(e.ctrl)):o._tinode.logger("ERROR: Unexpected server response status",this.status,this.response)},this.xhr.onerror=function(e){o.toReject&&o.toReject(new Error("failed")),o.onFailure&&o.onFailure(null)},this.xhr.onabort=function(e){o.toReject&&o.toReject(new Error("upload cancelled by user")),o.onFailure&&o.onFailure(null)};try{const e=new FormData;e.append("file",t),e.set("id",this._reqId),s&&e.set("topic",s),this.xhr.send(e)}catch(e){this.toReject&&this.toReject(e),this.onFailure&&this.onFailure(null)}return h}upload(e,t,s,i,n){const r=(this._tinode._secure?"https://":"http://")+this._tinode._host;return this.uploadWithBaseUrl(r,e,t,s,i,n)}download(e,t,s,i,n){if(!(0,r.isUrlRelative)(e))return void(n&&n(`The URL '${e}' must be relative, not absolute`));if(!this._authToken)return void(n&&n("Must authenticate first"));const a=this;this.xhr.open("GET",e,!0),this.xhr.setRequestHeader("X-Tinode-APIKey",this._apiKey),this.xhr.setRequestHeader("X-Tinode-Auth","Token "+this._authToken.token),this.xhr.responseType="blob",this.onProgress=i,this.xhr.onprogress=function(e){a.onProgress&&a.onProgress(e.loaded)};const o=new Promise(((e,t)=>{this.toResolve=e,this.toReject=t}));this.xhr.onload=function(){if(200==this.status){const e=document.createElement("a");e.href=window.URL.createObjectURL(new Blob([this.response],{type:s})),e.style.display="none",e.setAttribute("download",t),document.body.appendChild(e),e.click(),document.body.removeChild(e),window.URL.revokeObjectURL(e.href),a.toResolve&&a.toResolve()}else if(this.status>=400&&a.toReject){const e=new FileReader;e.onload=function(){try{const e=JSON.parse(this.result,r.jsonParseHelper);a.toReject(new Error(`${e.ctrl.text} (${e.ctrl.code})`))}catch(e){a._tinode.logger("ERROR: Invalid server response in LargeFileHelper",this.result),a.toReject(e)}},e.readAsText(this.response)}},this.xhr.onerror=function(e){a.toReject&&a.toReject(new Error("failed"))},this.xhr.onabort=function(){a.toReject&&a.toReject(null)};try{this.xhr.send()}catch(e){this.toReject&&this.toReject(e)}return o}cancel(){this.xhr&&this.xhr.readyState<4&&this.xhr.abort()}getId(){return this._reqId}static setNetworkProvider(e){De=e}};var Ie={};function Ne(e,t){!function(e,t){if(t.has(e))throw new TypeError("Cannot initialize the same private elements twice on an object")}(e,t),t.add(e)}function ke(e,t,s){if(!t.has(e))throw new TypeError("attempted to get private field on non-instance");return s}Object.defineProperty(Ie,"__esModule",{value:!0}),Ie.default=void 0;var Ue=new WeakSet,je=new WeakSet;function qe(){return this.topic.updated}function Le(){return this.topic.isP2PType()?ke(this,Ue,qe).call(this):this.topic._lastSubsUpdate}Ie.default=class{constructor(e){Ne(this,je),Ne(this,Ue),this.topic=e,this.what={}}withData(e,t,s){return this.what.data={since:e,before:t,limit:s},this}withLaterData(e){return this.withData(this.topic._maxSeq>0?this.topic._maxSeq+1:void 0,void 0,e)}withEarlierData(e){return this.withData(void 0,this.topic._minSeq>0?this.topic._minSeq:void 0,e)}withDesc(e){return this.what.desc={ims:e},this}withLaterDesc(){return this.withDesc(ke(this,Ue,qe).call(this))}withSub(e,t,s){const i={ims:e,limit:t};return"me"==this.topic.getType()?i.topic=s:i.user=s,this.what.sub=i,this}withOneSub(e,t){return this.withSub(e,void 0,t)}withLaterOneSub(e){return this.withOneSub(this.topic._lastSubsUpdate,e)}withLaterSub(e){return this.withSub(ke(this,je,Le).call(this),e)}withTags(){return this.what.tags=!0,this}withCred(){return"me"==this.topic.getType()?this.what.cred=!0:this.topic._tinode.logger("ERROR: Invalid topic type for MetaGetBuilder:withCreds",this.topic.getType()),this}withDel(e,t){return(e||t)&&(this.what.del={since:e,limit:t}),this}withLaterDel(e){return this.withDel(this.topic._maxSeq>0?this.topic._maxDel+1:void 0,e)}extract(e){return this.what[e]}build(){const e=[];let t={};return["data","sub","desc","tags","cred","del"].forEach((s=>{this.what.hasOwnProperty(s)&&(e.push(s),Object.getOwnPropertyNames(this.what[s]).length>0&&(t[s]=this.what[s]))})),e.length>0?t.what=e.join(" "):t=void 0,t}};var We={};function Ge(e,t){Fe(e,t),t.add(e)}function Ve(e,t,s){Fe(e,t),t.set(e,s)}function Fe(e,t){if(t.has(e))throw new TypeError("Cannot initialize the same private elements twice on an object")}function He(e,t,s){if(!t.has(e))throw new TypeError("attempted to get private field on non-instance");return s}function ze(e,t){return function(e,t){return t.get?t.get.call(e):t.value}(e,Qe(e,t,"get"))}function Be(e,t,s){return function(e,t,s){if(t.set)t.set.call(e,s);else{if(!t.writable)throw new TypeError("attempted to set read only private field");t.value=s}}(e,Qe(e,t,"set"),s),s}function Qe(e,t,s){if(!t.has(e))throw new TypeError("attempted to "+s+" private field on non-instance");return t.get(e)}Object.defineProperty(We,"__esModule",{value:!0}),We.default=void 0;var Ke=new WeakMap,Xe=new WeakMap,$e=new WeakSet,Je=new WeakSet;function Ye(e,t,s){let i=0,n=t.length-1,r=0,a=0,o=!1;for(;i<=n;)if(r=(i+n)/2|0,a=ze(this,Ke).call(this,t[r],e),a<0)i=r+1;else{if(!(a>0)){o=!0;break}n=r-1}return o?{idx:r,exact:!0}:s?{idx:-1}:{idx:a<0?r+1:r}}function Ze(e,t){const s=He(this,$e,Ye).call(this,e,t,!1),i=s.exact&&ze(this,Xe)?1:0;return t.splice(s.idx,i,e),t}We.default=class{constructor(e,t){Ge(this,Je),Ge(this,$e),Ve(this,Ke,{writable:!0,value:void 0}),Ve(this,Xe,{writable:!0,value:!1}),function(e,t,s){(t=function(e){var t=function(e,t){if("object"!=typeof e||null===e)return e;var s=e[Symbol.toPrimitive];if(void 0!==s){var i=s.call(e,"string");if("object"!=typeof i)return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==typeof t?t:String(t)}(t))in e?Object.defineProperty(e,t,{value:s,enumerable:!0,configurable:!0,writable:!0}):e[t]=s}(this,"buffer",[]),Be(this,Ke,e||((e,t)=>e===t?0:e<t?-1:1)),Be(this,Xe,t)}getAt(e){return this.buffer[e]}getLast(e){return e|=0,this.buffer.length>e?this.buffer[this.buffer.length-1-e]:void 0}put(){let e;e=1==arguments.length&&Array.isArray(arguments[0])?arguments[0]:arguments;for(let t in e)He(this,Je,Ze).call(this,e[t],this.buffer)}delAt(e){e|=0;let t=this.buffer.splice(e,1);if(t&&t.length>0)return t[0]}delRange(e,t){return this.buffer.splice(e,t-e)}length(){return this.buffer.length}reset(){this.buffer=[]}forEach(e,t,s,i){t|=0,s=s||this.buffer.length;for(let n=t;n<s;n++)e.call(i,this.buffer[n],n>t?this.buffer[n-1]:void 0,n<s-1?this.buffer[n+1]:void 0,n)}find(e,t){const{idx:s}=He(this,$e,Ye).call(this,e,this.buffer,!t);return s}filter(e,t){let s=0;for(let i=0;i<this.buffer.length;i++)e.call(t,this.buffer[i],i)&&(this.buffer[s]=this.buffer[i],s++);this.buffer.splice(s)}};var et={};Object.defineProperty(et,"__esModule",{value:!0}),et.TopicMe=et.TopicFnd=et.Topic=void 0;var tt=at(e),st=at(We),it=function(e,t){if(e&&e.__esModule)return e;if(null===e||"object"!=typeof e&&"function"!=typeof e)return{default:e};var s=function(e){if("function"!=typeof WeakMap)return null;var t=new WeakMap;new WeakMap;return t}();if(s&&s.has(e))return s.get(e);var i={},n=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var r in e)if("default"!==r&&Object.prototype.hasOwnProperty.call(e,r)){var a=n?Object.getOwnPropertyDescriptor(e,r):null;a&&(a.get||a.set)?Object.defineProperty(i,r,a):i[r]=e[r]}return i.default=e,s&&s.set(e,i),i}(n),nt=at(ue),rt=at(Ie);function at(e){return e&&e.__esModule?e:{default:e}}function ot(e,t,s){return(t=function(e){var t=function(e,t){if("object"!=typeof e||null===e)return e;var s=e[Symbol.toPrimitive];if(void 0!==s){var i=s.call(e,"string");if("object"!=typeof i)return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==typeof t?t:String(t)}(t))in e?Object.defineProperty(e,t,{value:s,enumerable:!0,configurable:!0,writable:!0}):e[t]=s,e}class ct{constructor(e,t){this._tinode=null,this.name=e,this.created=null,this.updated=null,this.touched=new Date(0),this.acs=new tt.default(null),this.private=null,this.public=null,this.trusted=null,this._users={},this._queuedSeqId=it.LOCAL_SEQID,this._maxSeq=0,this._minSeq=0,this._noEarlierMsgs=!1,this._maxDel=0,this._recvNotificationTimer=null,this._tags=[],this._credentials=[],this._messageVersions={},this._messages=new st.default(((e,t)=>e.seq-t.seq),!0),this._attached=!1,this._lastSubsUpdate=new Date(0),this._new=!0,this._deleted=!1,this._delayedLeaveTimer=null,t&&(this.onData=t.onData,this.onMeta=t.onMeta,this.onPres=t.onPres,this.onInfo=t.onInfo,this.onMetaDesc=t.onMetaDesc,this.onMetaSub=t.onMetaSub,this.onSubsUpdated=t.onSubsUpdated,this.onTagsUpdated=t.onTagsUpdated,this.onCredsUpdated=t.onCredsUpdated,this.onDeleteTopic=t.onDeleteTopic,this.onAllMessagesReceived=t.onAllMessagesReceived)}static topicType(e){return{me:it.TOPIC_ME,fnd:it.TOPIC_FND,grp:it.TOPIC_GRP,new:it.TOPIC_GRP,nch:it.TOPIC_GRP,chn:it.TOPIC_GRP,usr:it.TOPIC_P2P,sys:it.TOPIC_SYS}["string"==typeof e?e.substring(0,3):"xxx"]}static isMeTopicName(e){return ct.topicType(e)==it.TOPIC_ME}static isGroupTopicName(e){return ct.topicType(e)==it.TOPIC_GRP}static isP2PTopicName(e){return ct.topicType(e)==it.TOPIC_P2P}static isCommTopicName(e){return ct.isP2PTopicName(e)||ct.isGroupTopicName(e)}static isNewGroupTopicName(e){return"string"==typeof e&&(e.substring(0,3)==it.TOPIC_NEW||e.substring(0,3)==it.TOPIC_NEW_CHAN)}static isChannelTopicName(e){return"string"==typeof e&&(e.substring(0,3)==it.TOPIC_CHAN||e.substring(0,3)==it.TOPIC_NEW_CHAN)}isSubscribed(){return this._attached}subscribe(e,t){return clearTimeout(this._delayedLeaveTimer),this._delayedLeaveTimer=null,this._attached?Promise.resolve(this):this._deleted?Promise.reject(new Error("Conversation deleted")):this._tinode.subscribe(this.name||it.TOPIC_NEW,e,t).then((e=>{if(e.code>=300)return e;if(this._attached=!0,this._deleted=!1,this.acs=e.params&&e.params.acs?e.params.acs:this.acs,this._new){if(delete this._new,this.name!=e.topic&&(this._cacheDelSelf(),this.name=e.topic),this._cachePutSelf(),this.created=e.ts,this.updated=e.ts,this.name!=it.TOPIC_ME&&this.name!=it.TOPIC_FND){const e=this._tinode.getMeTopic();e.onMetaSub&&e.onMetaSub(this),e.onSubsUpdated&&e.onSubsUpdated([this.name],1)}t&&t.desc&&(t.desc._noForwarding=!0,this._processMetaDesc(t.desc))}return e}))}createMessage(e,t){return this._tinode.createMessage(this.name,e,t)}publish(e,t){return this.publishMessage(this.createMessage(e,t))}publishMessage(e){if(!this._attached)return Promise.reject(new Error("Cannot publish on inactive topic"));if(this._sending)return Promise.reject(new Error("The message is already being sent"));e._sending=!0,e._failed=!1;let t=null;return nt.default.hasEntities(e.content)&&(t=[],nt.default.entities(e.content,(e=>{e&&e.ref&&t.push(e.ref)})),0==t.length&&(t=null)),this._tinode.publishMessage(e,t).then((t=>(e._sending=!1,e.ts=t.ts,this.swapMessageId(e,t.params.seq),this._maybeUpdateMessageVersionsCache(e),this._routeData(e),t))).catch((t=>{this._tinode.logger("WARNING: Message rejected by the server",t),e._sending=!1,e._failed=!0,this.onData&&this.onData()}))}publishDraft(e,t){const s=e.seq||this._getQueuedSeqId();return e._noForwarding||(e._noForwarding=!0,e.seq=s,e.ts=new Date,e.from=this._tinode.getCurrentUserID(),e.noecho=!0,this._messages.put(e),this._tinode._db.addMessage(e),this.onData&&this.onData(e)),(t||Promise.resolve()).then((t=>e._cancelled?{code:300,text:"cancelled"}:this.publishMessage(e))).catch((t=>{throw this._tinode.logger("WARNING: Message draft rejected",t),e._sending=!1,e._failed=!0,this.onData&&this.onData(),t}))}leave(e){return this._attached||e?this._tinode.leave(this.name,e).then((t=>(this._resetSub(),e&&this._gone(),t))):Promise.reject(new Error("Cannot leave inactive topic"))}leaveDelayed(e,t){clearTimeout(this._delayedLeaveTimer),this._delayedLeaveTimer=setTimeout((t=>{this._delayedLeaveTimer=null,this.leave(e)}),t)}getMeta(e){return this._tinode.getMeta(this.name,e)}getMessagesPage(e,t){let s=t?this.startMetaQuery().withLaterData(e):this.startMetaQuery().withEarlierData(e);return this._loadMessages(this._tinode._db,s.extract("data")).then((i=>{if(i==e)return Promise.resolve({topic:this.name,code:200,params:{count:i}});e-=i,s=t?this.startMetaQuery().withLaterData(e):this.startMetaQuery().withEarlierData(e);let n=this.getMeta(s.build());return t||(n=n.then((e=>{e&&e.params&&!e.params.count&&(this._noEarlierMsgs=!0)}))),n}))}setMeta(e){return e.tags&&(e.tags=(0,r.normalizeArray)(e.tags)),this._tinode.setMeta(this.name,e).then((t=>(t&&t.code>=300||(e.sub&&(e.sub.topic=this.name,t.params&&t.params.acs&&(e.sub.acs=t.params.acs,e.sub.updated=t.ts),e.sub.user||(e.sub.user=this._tinode.getCurrentUserID(),e.desc||(e.desc={})),e.sub._noForwarding=!0,this._processMetaSub([e.sub])),e.desc&&(t.params&&t.params.acs&&(e.desc.acs=t.params.acs,e.desc.updated=t.ts),this._processMetaDesc(e.desc)),e.tags&&this._processMetaTags(e.tags),e.cred&&this._processMetaCreds([e.cred],!0)),t)))}updateMode(e,t){const s=e?this.subscriber(e):null,i=s?s.acs.updateGiven(t).getGiven():this.getAccessMode().updateWant(t).getWant();return this.setMeta({sub:{user:e,mode:i}})}invite(e,t){return this.setMeta({sub:{user:e,mode:t}})}archive(e){return this.private&&!this.private.arch==!e?Promise.resolve(e):this.setMeta({desc:{private:{arch:!!e||it.DEL_CHAR}}})}delMessages(e,t){if(!this._attached)return Promise.reject(new Error("Cannot delete messages in inactive topic"));e.sort(((e,t)=>e.low<t.low||e.low==t.low&&(!t.hi||e.hi>=t.hi)));let s,i=e.reduce(((e,t)=>(t.low<it.LOCAL_SEQID&&(!t.hi||t.hi<it.LOCAL_SEQID?e.push(t):e.push({low:t.low,hi:this._maxSeq+1})),e)),[]);return s=i.length>0?this._tinode.delMessages(this.name,i,t):Promise.resolve({params:{del:0}}),s.then((t=>(t.params.del>this._maxDel&&(this._maxDel=t.params.del),e.forEach((e=>{e.hi?this.flushMessageRange(e.low,e.hi):this.flushMessage(e.low)})),this.onData&&this.onData(),t)))}delMessagesAll(e){return!this._maxSeq||this._maxSeq<=0?Promise.resolve():this.delMessages([{low:1,hi:this._maxSeq+1,_all:!0}],e)}delMessagesList(e,t){e.sort(((e,t)=>e-t));let s=e.reduce(((e,t)=>{if(0==e.length)e.push({low:t});else{let s=e[e.length-1];!s.hi&&t!=s.low+1||t>s.hi?e.push({low:t}):s.hi=s.hi?Math.max(s.hi,t+1):t+1}return e}),[]);return this.delMessages(s,t)}delMessagesEdits(e,t){const s=[e];return this.messageVersions(e,(e=>s.push(e.seq))),this.delMessagesList(s,t)}delTopic(e){return this._deleted?(this._gone(),Promise.resolve(null)):this._tinode.delTopic(this.name,e).then((e=>(this._deleted=!0,this._resetSub(),this._gone(),e)))}delSubscription(e){return this._attached?this._tinode.delSubscription(this.name,e).then((t=>(delete this._users[e],this.onSubsUpdated&&this.onSubsUpdated(Object.keys(this._users)),t))):Promise.reject(new Error("Cannot delete subscription in inactive topic"))}note(e,t){if(!this._attached)return;const s=this._users[this._tinode.getCurrentUserID()];let i=!1;s?(!s[e]||s[e]<t)&&(s[e]=t,i=!0):i=(0|this[e])<t,i&&(this._tinode.note(this.name,e,t),this._updateReadRecv(e,t),null!=this.acs&&!this.acs.isMuted())&&this._tinode.getMeTopic()._refreshContact(e,this)}noteRecv(e){this.note("recv",e)}noteRead(e){(e=e||this._maxSeq)>0&&this.note("read",e)}noteKeyPress(){this._attached?this._tinode.noteKeyPress(this.name):this._tinode.logger("INFO: Cannot send notification in inactive topic")}noteRecording(e){this._attached?this._tinode.noteKeyPress(this.name,e?"kpa":"kpv"):this._tinode.logger("INFO: Cannot send notification in inactive topic")}videoCall(e,t,s){if(this._attached||["ringing","hang-up"].includes(e))return this._tinode.videoCall(this.name,t,e,s)}_updateReadRecv(e,t,s){let i,n=!1;switch(t|=0,this.seq=0|this.seq,this.read=0|this.read,this.recv=0|this.recv,e){case"recv":i=this.recv,this.recv=Math.max(this.recv,t),n=i!=this.recv;break;case"read":i=this.read,this.read=Math.max(this.read,t),n=i!=this.read;break;case"msg":i=this.seq,this.seq=Math.max(this.seq,t),(!this.touched||this.touched<s)&&(this.touched=s),n=i!=this.seq}return this.recv<this.read&&(this.recv=this.read,n=!0),this.seq<this.recv&&(this.seq=this.recv,(!this.touched||this.touched<s)&&(this.touched=s),n=!0),this.unread=this.seq-this.read,n}userDesc(e){const t=this._cacheGetUser(e);if(t)return t}p2pPeerDesc(){if(this.isP2PType())return this._users[this.name]}subscribers(e,t){const s=e||this.onMetaSub;if(s)for(let e in this._users)s.call(t,this._users[e],e,this._users)}tags(){return this._tags.slice(0)}subscriber(e){return this._users[e]}messageVersions(e,t,s){if(!t)return;const i=this._messageVersions[e];i&&i.forEach(t,void 0,void 0,s)}messages(e,t,s,i){const n=e||this.onData;if(n){const e="number"==typeof t?this._messages.find({seq:t},!0):void 0,r="number"==typeof s?this._messages.find({seq:s},!0):void 0;if(-1!=e&&-1!=r){let t=[];this._messages.forEach(((e,s,i,n)=>{if(this._isReplacementMsg(e))return;const r=this.latestMsgVersion(e.seq)||e;r._origTs||(r._origTs=r.ts,r.ts=e.ts),t.push({data:r,idx:n})}),e,r,{}),t.forEach(((e,s)=>{n.call(i,e.data,s>0?t[s-1].data:void 0,s<t.length-1?t[s+1].data:void 0,e.idx)}))}}}findMessage(e){const t=this._messages.find({seq:e});if(t>=0)return this._messages.getAt(t)}latestMessage(){return this._messages.getLast()}latestMsgVersion(e){const t=this._messageVersions[e];return t?t.getLast():null}maxMsgSeq(){return this._maxSeq}maxClearId(){return this._maxDel}messageCount(){return this._messages.length()}queuedMessages(e,t){if(!e)throw new Error("Callback must be provided");this.messages(e,it.LOCAL_SEQID,void 0,t)}msgReceiptCount(e,t){let s=0;if(t>0){const i=this._tinode.getCurrentUserID();for(let n in this._users){const r=this._users[n];r.user!==i&&r[e]>=t&&s++}}return s}msgReadCount(e){return this.msgReceiptCount("read",e)}msgRecvCount(e){return this.msgReceiptCount("recv",e)}msgHasMoreMessages(e){return e?this.seq>this._maxSeq:this._minSeq>1&&!this._noEarlierMsgs}isNewMessage(e){return this._maxSeq<=e}flushMessage(e){const t=this._messages.find({seq:e});if(delete this._messageVersions[e],t>=0)return this._tinode._db.remMessages(this.name,e),this._messages.delAt(t)}flushMessageRange(e,t){this._tinode._db.remMessages(this.name,e,t);for(let s=e;s<t;s++)delete this._messageVersions[s];const s=this._messages.find({seq:e},!0);return s>=0?this._messages.delRange(s,this._messages.find({seq:t},!0)):[]}swapMessageId(e,t){const s=this._messages.find(e),i=this._messages.length();0<=s&&s<i&&(this._messages.delAt(s),this._tinode._db.remMessages(this.name,e.seq),e.seq=t,this._messages.put(e),this._tinode._db.addMessage(e))}cancelSend(e){const t=this._messages.find({seq:e});if(t>=0){const s=this._messages.getAt(t),i=this.msgStatus(s);if(i==it.MESSAGE_STATUS_QUEUED||i==it.MESSAGE_STATUS_FAILED)return this._tinode._db.remMessages(this.name,e),s._cancelled=!0,this._messages.delAt(t),this.onData&&this.onData(),!0}return!1}getType(){return ct.topicType(this.name)}getAccessMode(){return this.acs}setAccessMode(e){return this.acs=new tt.default(e)}getDefaultAccess(){return this.defacs}startMetaQuery(){return new rt.default(this)}isArchived(){return this.private&&!!this.private.arch}isMeType(){return ct.isMeTopicName(this.name)}isChannelType(){return ct.isChannelTopicName(this.name)}isGroupType(){return ct.isGroupTopicName(this.name)}isP2PType(){return ct.isP2PTopicName(this.name)}isCommType(){return ct.isCommTopicName(this.name)}msgStatus(e,t){let s=it.MESSAGE_STATUS_NONE;return this._tinode.isMe(e.from)?e._sending?s=it.MESSAGE_STATUS_SENDING:e._failed||e._cancelled?s=it.MESSAGE_STATUS_FAILED:e.seq>=it.LOCAL_SEQID?s=it.MESSAGE_STATUS_QUEUED:this.msgReadCount(e.seq)>0?s=it.MESSAGE_STATUS_READ:this.msgRecvCount(e.seq)>0?s=it.MESSAGE_STATUS_RECEIVED:e.seq>0&&(s=it.MESSAGE_STATUS_SENT):s=it.MESSAGE_STATUS_TO_ME,t&&e._status!=s&&(e._status=s,this._tinode._db.updMessageStatus(this.name,e.seq,s)),s}_isReplacementMsg(e){return e.head&&e.head.replace}_maybeUpdateMessageVersionsCache(e){if(!this._isReplacementMsg(e))return;const t=parseInt(e.head.replace.split(":")[1]);if(t>e.seq)return!1;const s=this._messageVersions[t]||new st.default(((e,t)=>e.seq-t.seq),!0);s.put(e),this._messageVersions[t]=s}_routeData(e){e.content&&(!this.touched||this.touched<e.ts)&&(this.touched=e.ts,this._tinode._db.updTopic(this)),e.seq>this._maxSeq&&(this._maxSeq=e.seq,this.msgStatus(e,!0),clearTimeout(this._recvNotificationTimer),this._recvNotificationTimer=setTimeout((e=>{this._recvNotificationTimer=null,this.noteRecv(this._maxSeq)}),it.RECV_TIMEOUT)),(e.seq<this._minSeq||0==this._minSeq)&&(this._minSeq=e.seq);const t=!this.isChannelType()&&!e.from||this._tinode.isMe(e.from);e.head&&e.head.webrtc&&e.head.mime==nt.default.getContentType()&&e.content&&(e.content=nt.default.updateVideoCall(e.content,{state:e.head.webrtc,duration:e.head["webrtc-duration"],incoming:!t})),e._noForwarding||(this._messages.put(e),this._tinode._db.addMessage(e),this._maybeUpdateMessageVersionsCache(e)),this.onData&&this.onData(e);const s=t?"read":"msg";this._updateReadRecv(s,e.seq,e.ts),this._tinode.getMeTopic()._refreshContact(s,this)}_routeMeta(e){e.desc&&this._processMetaDesc(e.desc),e.sub&&e.sub.length>0&&this._processMetaSub(e.sub),e.del&&this._processDelMessages(e.del.clear,e.del.delseq),e.tags&&this._processMetaTags(e.tags),e.cred&&this._processMetaCreds(e.cred),this.onMeta&&this.onMeta(e)}_routePres(e){let t,s;switch(e.what){case"del":this._processDelMessages(e.clear,e.delseq);break;case"on":case"off":t=this._users[e.src],t?t.online="on"==e.what:this._tinode.logger("WARNING: Presence update for an unknown user",this.name,e.src);break;case"term":this._resetSub();break;case"upd":e.src&&!this._tinode.isTopicCached(e.src)&&this.getMeta(this.startMetaQuery().withLaterOneSub(e.src).build());break;case"acs":if(s=e.src||this._tinode.getCurrentUserID(),t=this._users[s],t)t.acs.updateAll(e.dacs),this._processMetaSub([{user:s,updated:new Date,acs:t.acs}]);else{const i=(new tt.default).updateAll(e.dacs);i&&i.mode!=tt.default._NONE&&(t=this._cacheGetUser(s),t?t.acs=i:(t={user:s,acs:i},this.getMeta(this.startMetaQuery().withOneSub(void 0,s).build())),t.updated=new Date,this._processMetaSub([t]))}break;default:this._tinode.logger("INFO: Ignored presence update",e.what)}this.onPres&&this.onPres(e)}_routeInfo(e){switch(e.what){case"recv":case"read":const t=this._users[e.from];t&&(t[e.what]=e.seq,t.recv<t.read&&(t.recv=t.read));const s=this.latestMessage();s&&this.msgStatus(s,!0),this._tinode.isMe(e.from)&&this._updateReadRecv(e.what,e.seq),this._tinode.getMeTopic()._refreshContact(e.what,this);break;case"kp":case"call":break;default:this._tinode.logger("INFO: Ignored info update",e.what)}this.onInfo&&this.onInfo(e)}_processMetaDesc(e){if(this.isP2PType()&&(delete e.defacs,this._tinode._db.updUser(this.name,e.public)),(0,r.mergeObj)(this,e),this._tinode._db.updTopic(this),this.name!==it.TOPIC_ME&&!e._noForwarding){const e=this._tinode.getMeTopic();e.onMetaSub&&e.onMetaSub(this),e.onSubsUpdated&&e.onSubsUpdated([this.name],1)}this.onMetaDesc&&this.onMetaDesc(this)}_processMetaSub(e){for(let t in e){const s=e[t];s.online=!!s.online,this._lastSubsUpdate=new Date(Math.max(this._lastSubsUpdate,s.updated));let i=null;s.deleted?(delete this._users[s.user],i=s):(this._tinode.isMe(s.user)&&s.acs&&this._processMetaDesc({updated:s.updated,touched:s.touched,acs:s.acs}),i=this._updateCachedUser(s.user,s)),this.onMetaSub&&this.onMetaSub(i)}this.onSubsUpdated&&this.onSubsUpdated(Object.keys(this._users))}_processMetaTags(e){1==e.length&&e[0]==it.DEL_CHAR&&(e=[]),this._tags=e,this.onTagsUpdated&&this.onTagsUpdated(e)}_processMetaCreds(e){}_processDelMessages(e,t){this._maxDel=Math.max(e,this._maxDel),this.clear=Math.max(e,this.clear);const s=this;let i=0;Array.isArray(t)&&t.forEach((function(e){if(e.hi)for(let t=e.low;t<e.hi;t++)i++,s.flushMessage(t);else i++,s.flushMessage(e.low)})),i>0&&this.onData&&this.onData()}_allMessagesReceived(e){this.onAllMessagesReceived&&this.onAllMessagesReceived(e)}_resetSub(){this._attached=!1}_gone(){this._messages.reset(),this._tinode._db.remMessages(this.name),this._users={},this.acs=new tt.default(null),this.private=null,this.public=null,this.trusted=null,this._maxSeq=0,this._minSeq=0,this._attached=!1;const e=this._tinode.getMeTopic();e&&e._routePres({_noForwarding:!0,what:"gone",topic:it.TOPIC_ME,src:this.name}),this.onDeleteTopic&&this.onDeleteTopic()}_updateCachedUser(e,t){let s=this._cacheGetUser(e);return s=(0,r.mergeObj)(s||{},t),this._cachePutUser(e,s),(0,r.mergeToCache)(this._users,e,s)}_getQueuedSeqId(){return this._queuedSeqId++}_loadMessages(e,t){const{since:s,before:i,limit:n}=t||{};return e.readMessages(this.name,{since:s,before:i,limit:n||it.DEFAULT_MESSAGES_PAGE}).then((e=>(e.forEach((e=>{e.seq>this._maxSeq&&(this._maxSeq=e.seq),(e.seq<this._minSeq||0==this._minSeq)&&(this._minSeq=e.seq),this._messages.put(e),this._maybeUpdateMessageVersionsCache(e)})),e.length)))}_updateReceived(e,t){this.touched=new Date,this.seq=0|e,t&&!this._tinode.isMe(t)||(this.read=this.read?Math.max(this.read,this.seq):this.seq,this.recv=this.recv?Math.max(this.read,this.recv):this.read),this.unread=this.seq-(0|this.read),this._tinode._db.updTopic(this)}}et.Topic=ct,et.TopicMe=class extends ct{constructor(e){super(it.TOPIC_ME,e),ot(this,"onContactUpdate",void 0),e&&(this.onContactUpdate=e.onContactUpdate)}_processMetaDesc(e){const t=e.acs&&!e.acs.isPresencer()&&this.acs&&this.acs.isPresencer();(0,r.mergeObj)(this,e),this._tinode._db.updTopic(this),this._updateCachedUser(this._tinode._myUID,e),t&&this._tinode.mapTopics((e=>{e.online&&(e.online=!1,e.seen=Object.assign(e.seen||{},{when:new Date}),this._refreshContact("off",e))})),this.onMetaDesc&&this.onMetaDesc(this)}_processMetaSub(e){let t=0;if(e.forEach((e=>{const s=e.topic;if(s==it.TOPIC_FND||s==it.TOPIC_ME)return;e.online=!!e.online;let i=null;if(e.deleted)i=e,this._tinode.cacheRemTopic(s),this._tinode._db.remTopic(s);else{void 0!==e.seq&&(e.seq=0|e.seq,e.recv=0|e.recv,e.read=0|e.read,e.unread=e.seq-e.read);const t=this._tinode.getTopic(s);t._new&&delete t._new,i=(0,r.mergeObj)(t,e),this._tinode._db.updTopic(i),ct.isP2PTopicName(s)&&(this._cachePutUser(s,i),this._tinode._db.updUser(s,i.public)),!e._noForwarding&&t&&(e._noForwarding=!0,t._processMetaDesc(e))}t++,this.onMetaSub&&this.onMetaSub(i)})),this.onSubsUpdated&&t>0){const s=[];e.forEach((e=>{s.push(e.topic)})),this.onSubsUpdated(s,t)}}_processMetaCreds(e,t){1==e.length&&e[0]==it.DEL_CHAR&&(e=[]),t?e.forEach((e=>{if(e.val){let t=this._credentials.findIndex((t=>t.meth==e.meth&&t.val==e.val));t<0?(e.done||(t=this._credentials.findIndex((t=>t.meth==e.meth&&!t.done)),t>=0&&this._credentials.splice(t,1)),this._credentials.push(e)):this._credentials[t].done=e.done}else if(e.resp){const t=this._credentials.findIndex((t=>t.meth==e.meth&&!t.done));t>=0&&(this._credentials[t].done=!0)}})):this._credentials=e,this.onCredsUpdated&&this.onCredsUpdated(this._credentials)}_routePres(e){if("term"==e.what)return void this._resetSub();if("upd"==e.what&&e.src==it.TOPIC_ME)return void this.getMeta(this.startMetaQuery().withDesc().build());const t=this._tinode.cacheGetTopic(e.src);if(t){switch(e.what){case"on":t.online=!0;break;case"off":t.online&&(t.online=!1,t.seen=Object.assign(t.seen||{},{when:new Date}));break;case"msg":t._updateReceived(e.seq,e.act);break;case"upd":this.getMeta(this.startMetaQuery().withLaterOneSub(e.src).build());break;case"acs":t.acs?t.acs.updateAll(e.dacs):t.acs=(new tt.default).updateAll(e.dacs),t.touched=new Date;break;case"ua":t.seen={when:new Date,ua:e.ua};break;case"recv":e.seq=0|e.seq,t.recv=t.recv?Math.max(t.recv,e.seq):e.seq;break;case"read":e.seq=0|e.seq,t.read=t.read?Math.max(t.read,e.seq):e.seq,t.recv=t.recv?Math.max(t.read,t.recv):t.recv,t.unread=t.seq-t.read;break;case"gone":t._deleted?this._tinode._db.remTopic(e.src):(t._deleted=!0,t._attached=!1,this._tinode._db.markTopicAsDeleted(e.src));break;case"del":break;default:this._tinode.logger("INFO: Unsupported presence update in 'me'",e.what)}this._refreshContact(e.what,t)}else if("acs"==e.what){const t=new tt.default(e.dacs);if(!t||t.mode==tt.default._INVALID)return void this._tinode.logger("ERROR: Invalid access mode update",e.src,e.dacs);if(t.mode==tt.default._NONE)return void this._tinode.logger("WARNING: Removing non-existent subscription",e.src,e.dacs);{this.getMeta(this.startMetaQuery().withOneSub(void 0,e.src).build());const s=this._tinode.getTopic(e.src);s.topic=e.src,s.online=!1,s.acs=t,this._tinode._db.updTopic(s)}}else"tags"==e.what&&this.getMeta(this.startMetaQuery().withTags().build());this.onPres&&this.onPres(e)}_refreshContact(e,t){this.onContactUpdate&&this.onContactUpdate(e,t)}publish(){return Promise.reject(new Error("Publishing to 'me' is not supported"))}delCredential(e,t){return this._attached?this._tinode.delCredential(e,t).then((s=>{const i=this._credentials.findIndex((s=>s.meth==e&&s.val==t));return i>-1&&this._credentials.splice(i,1),this.onCredsUpdated&&this.onCredsUpdated(this._credentials),s})):Promise.reject(new Error("Cannot delete credential in inactive 'me' topic"))}contacts(e,t,s){this._tinode.mapTopics(((i,n)=>{!i.isCommType()||t&&!t(i)||e.call(s,i,n)}))}getContact(e){return this._tinode.cacheGetTopic(e)}getAccessMode(e){if(e){const t=this._tinode.cacheGetTopic(e);return t?t.acs:null}return this.acs}isArchived(e){const t=this._tinode.cacheGetTopic(e);return t&&t.private&&!!t.private.arch}getCredentials(){return this._credentials}};class ht extends ct{constructor(e){super(it.TOPIC_FND,e),ot(this,"_contacts",{})}_processMetaSub(e){let t=Object.getOwnPropertyNames(this._contacts).length;this._contacts={};for(let s in e){let i=e[s];const n=i.topic?i.topic:i.user;i=(0,r.mergeToCache)(this._contacts,n,i),t++,this.onMetaSub&&this.onMetaSub(i)}t>0&&this.onSubsUpdated&&this.onSubsUpdated(Object.keys(this._contacts))}publish(){return Promise.reject(new Error("Publishing to 'fnd' is not supported"))}setMeta(e){return Object.getPrototypeOf(ht.prototype).setMeta.call(this,e).then((e=>{Object.keys(this._contacts).length>0&&(this._contacts={},this.onSubsUpdated&&this.onSubsUpdated([]))}))}contacts(e,t){const s=e||this.onMetaSub;if(s)for(let e in this._contacts)s.call(t,this._contacts[e],e,this._contacts)}}et.TopicFnd=ht;var lt={};return function(t){(function(){"use strict";Object.defineProperty(lt,"__esModule",{value:!0}),Object.defineProperty(lt,"AccessMode",{enumerable:!0,get:function(){return s.default}}),Object.defineProperty(lt,"Drafty",{enumerable:!0,get:function(){return c.default}}),lt.Tinode=void 0;var s=u(e),i=function(e,t){if(e&&e.__esModule)return e;if(null===e||"object"!=typeof e&&"function"!=typeof e)return{default:e};var s=function(e){if("function"!=typeof WeakMap)return null;var t=new WeakMap;new WeakMap;return t}();if(s&&s.has(e))return s.get(e);var i={},n=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var r in e)if("default"!==r&&Object.prototype.hasOwnProperty.call(e,r)){var a=n?Object.getOwnPropertyDescriptor(e,r):null;a&&(a.get||a.set)?Object.defineProperty(i,r,a):i[r]=e[r]}return i.default=e,s&&s.set(e,i),i}(n),a=u(l),o=u(F),c=u(ue),h=u(Ce),d=u(Ie);function u(e){return e&&e.__esModule?e:{default:e}}function p(e,t){!function(e,t){if(t.has(e))throw new TypeError("Cannot initialize the same private elements twice on an object")}(e,t),t.add(e)}function f(e,t,s){return(t=function(e){var t=function(e,t){if("object"!=typeof e||null===e)return e;var s=e[Symbol.toPrimitive];if(void 0!==s){var i=s.call(e,"string");if("object"!=typeof i)return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==typeof t?t:String(t)}(t))in e?Object.defineProperty(e,t,{value:s,enumerable:!0,configurable:!0,writable:!0}):e[t]=s,e}function g(e,t,s){if(!t.has(e))throw new TypeError("attempted to get private field on non-instance");return s}let m,_,b;function v(e){return btoa(encodeURIComponent(e).replace(/%([0-9A-F]{2})/g,(function(e,t){return String.fromCharCode("0x"+t)})))}function w(e,t){return"string"==typeof t&&t.length>128?"<"+t.length+", bytes: "+t.substring(0,12)+"..."+t.substring(t.length-12)+">":function(e,t){if(t instanceof Date)t=(0,r.rfc3339DateString)(t);else if(t instanceof s.default)t=t.jsonHelper();else if(null==t||!1===t||Array.isArray(t)&&0==t.length||"object"==typeof t&&0==Object.keys(t).length)return;return t}(0,t)}"undefined"!=typeof WebSocket&&(m=WebSocket),"undefined"!=typeof XMLHttpRequest&&(_=XMLHttpRequest),"undefined"!=typeof indexedDB&&(b=indexedDB),function(){const e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";"undefined"==typeof btoa&&(t.btoa=function(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",s=t,i="";for(let t,n=0,r=0,a=e;s.charAt(0|r)||(a="=",r%1);i+=a.charAt(63&n>>8-r%1*8)){if(t=s.charCodeAt(r+=3/4),t>255)throw new Error("'btoa' failed: The string to be encoded contains characters outside of the Latin1 range.");n=n<<8|t}return i}),"undefined"==typeof atob&&(t.atob=function(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",s=t.replace(/=+$/,""),i="";if(s.length%4==1)throw new Error("'atob' failed: The string to be decoded is not correctly encoded.");for(let t,n=0,r=0,a=0;t=s.charAt(a++);~t&&(r=n%4?64*r+t:t,n++%4)?i+=String.fromCharCode(255&r>>(-2*n&6)):0)t=e.indexOf(t);return i}),"undefined"==typeof window&&(t.window={WebSocket:m,XMLHttpRequest:_,indexedDB:b,URL:{createObjectURL:function(){throw new Error("Unable to use URL.createObjectURL in a non-browser application")}}}),a.default.setNetworkProviders(m,_),h.default.setNetworkProvider(_),o.default.setDatabaseProvider(b)}();var S=new WeakSet,T=new WeakSet,E=new WeakSet,y=new WeakSet,M=new WeakSet,P=new WeakSet,A=new WeakSet,R=new WeakSet,x=new WeakSet,O=new WeakSet,C=new WeakSet,D=new WeakSet,I=new WeakSet,N=new WeakSet;class k{constructor(e,t){if(p(this,N),p(this,I),p(this,D),p(this,C),p(this,O),p(this,x),p(this,R),p(this,A),p(this,P),p(this,M),p(this,y),p(this,E),p(this,T),p(this,S),f(this,"_host",void 0),f(this,"_secure",void 0),f(this,"_appName",void 0),f(this,"_apiKey",void 0),f(this,"_browser",""),f(this,"_platform",void 0),f(this,"_hwos","undefined"),f(this,"_humanLanguage","xx"),f(this,"_loggingEnabled",!1),f(this,"_trimLongStrings",!1),f(this,"_myUID",null),f(this,"_authenticated",!1),f(this,"_login",null),f(this,"_authToken",null),f(this,"_inPacketCount",0),f(this,"_messageId",Math.floor(65535*Math.random()+65535)),f(this,"_serverInfo",null),f(this,"_deviceToken",null),f(this,"_pendingPromises",{}),f(this,"_expirePromises",null),f(this,"_connection",null),f(this,"_persist",!1),f(this,"_db",null),f(this,"_cache",{}),f(this,"onWebsocketOpen",void 0),f(this,"onConnect",void 0),f(this,"onDisconnect",void 0),f(this,"onLogin",void 0),f(this,"onCtrlMessage",void 0),f(this,"onDataMessage",void 0),f(this,"onPresMessage",void 0),f(this,"onMessage",void 0),f(this,"onRawMessage",void 0),f(this,"onNetworkProbe",void 0),f(this,"onAutoreconnectIteration",void 0),this._host=e.host,this._secure=e.secure,this._appName=e.appName||"Undefined",this._apiKey=e.apiKey,this._platform=e.platform||"web","undefined"!=typeof navigator&&(this._browser=function(e,t){e=e||"";let s,i="";/reactnative/i.test(t)&&(i="ReactNative; ");let n=(e=e.replace(" (KHTML, like Gecko)","")).match(/(AppleWebKit\/[.\d]+)/i);if(n){const t=["edg","chrome","safari","mobile","version"];let i,r=e.substr(n.index+n[0].length).split(" "),a=[];for(let e=0;e<r.length;e++){let s=/([\w.]+)[\/]([\.\d]+)/.exec(r[e]);s&&(a.push([s[1],s[2],t.findIndex((e=>s[1].toLowerCase().startsWith(e)))]),"Version"==s[1]&&(i=s[2]))}a.sort(((e,t)=>e[2]-t[2])),a.length>0?(a[0][0].toLowerCase().startsWith("edg")?a[0][0]="Edge":"OPR"==a[0][0]?a[0][0]="Opera":"Safari"==a[0][0]&&i&&(a[0][1]=i),s=a[0][0]+"/"+a[0][1]):s=n[1]}else/firefox/i.test(e)?(n=/Firefox\/([.\d]+)/g.exec(e),s=n?"Firefox/"+n[1]:"Firefox/?"):(n=/([\w.]+)\/([.\d]+)/.exec(e),n?s=n[1]+"/"+n[2]:(n=e.split(" "),s=n[0]));if(n=s.split("/"),n.length>1){const e=n[1].split("."),t=e[1]?"."+e[1].substr(0,2):"";s=`${n[0]}/${e[0]}${t}`}return i+s}(navigator.userAgent,navigator.product),this._hwos=navigator.platform,this._humanLanguage=navigator.language||"en-US"),a.default.logger=this.logger,c.default.logger=this.logger,"lp"!=e.transport&&"ws"!=e.transport&&(e.transport=function(){if("object"==typeof window){if(window.WebSocket)return"ws";if(window.XMLHttpRequest)return"lp"}return null}()),this._connection=new a.default(e,i.PROTOCOL_VERSION,!0),this._connection.onMessage=e=>{g(this,y,L).call(this,e)},this._connection.onOpen=e=>g(this,M,W).call(this),this._connection.onDisconnect=(e,t)=>g(this,P,G).call(this,e,t),this._connection.onAutoreconnectIteration=(e,t)=>{this.onAutoreconnectIteration&&this.onAutoreconnectIteration(e,t)},this._persist=e.persist,this._db=new o.default((e=>{this.logger("DB",e)}),this.logger),this._persist){const e=[];this._db.initDatabase().then((t=>this._db.mapTopics((t=>{let s=g(this,O,B).call(this,"topic",t.name);s||(s=t.name==i.TOPIC_ME?new et.TopicMe:t.name==i.TOPIC_FND?new et.TopicFnd:new et.Topic(t.name),this._db.deserializeTopic(s,t),g(this,I,X).call(this,s),s._cachePutSelf(),delete s._new,e.push(s._loadMessages(this._db)))})))).then((e=>this._db.mapUsers((e=>{g(this,x,z).call(this,"user",e.uid,(0,r.mergeObj)({},e.public))})))).then((t=>Promise.all(e))).then((e=>{t&&t(),this.logger("Persistent cache initialized.")})).catch((e=>{t&&t(e),this.logger("Failed to initialize persistent cache:",e)}))}else this._db.deleteDatabase().then((e=>{t&&t()}))}logger(e){if(this._loggingEnabled){const n=new Date,r=("0"+n.getUTCHours()).slice(-2)+":"+("0"+n.getUTCMinutes()).slice(-2)+":"+("0"+n.getUTCSeconds()).slice(-2)+"."+("00"+n.getUTCMilliseconds()).slice(-3);for(var t=arguments.length,s=new Array(t>1?t-1:0),i=1;i<t;i++)s[i-1]=arguments[i];console.log("["+r+"]",e,s.join(" "))}}static credential(e,t,s,i){return"object"==typeof e&&({val:t,params:s,resp:i,meth:e}=e),e&&(t||i)?[{meth:e,val:t,resp:i,params:s}]:null}static topicType(e){return et.Topic.topicType(e)}static isMeTopicName(e){return et.Topic.isMeTopicName(e)}static isGroupTopicName(e){return et.Topic.isGroupTopicName(e)}static isP2PTopicName(e){return et.Topic.isP2PTopicName(e)}static isCommTopicName(e){return et.Topic.isCommTopicName(e)}static isNewGroupTopicName(e){return et.Topic.isNewGroupTopicName(e)}static isChannelTopicName(e){return et.Topic.isChannelTopicName(e)}static getVersion(){return i.VERSION}static setNetworkProviders(e,t){m=e,_=t,a.default.setNetworkProviders(m,_),h.default.setNetworkProvider(_)}static setDatabaseProvider(e){b=e,o.default.setDatabaseProvider(b)}static getLibrary(){return i.LIBRARY}static isNullValue(e){return e===i.DEL_CHAR}getNextUniqueId(){return 0!=this._messageId?""+this._messageId++:void 0}connect(e){return this._connection.connect(e)}reconnect(e){this._connection.reconnect(e)}disconnect(){this._connection.disconnect()}clearStorage(){return this._db.isReady()?this._db.deleteDatabase():Promise.resolve()}initStorage(){return this._db.isReady()?Promise.resolve():this._db.initDatabase()}networkProbe(){this._connection.probe()}isConnected(){return this._connection.isConnected()}isAuthenticated(){return this._authenticated}authorizeURL(e){if("string"!=typeof e)return e;if((0,r.isUrlRelative)(e)){const t="scheme://host/",s=new URL(e,t);this._apiKey&&s.searchParams.append("apikey",this._apiKey),this._authToken&&this._authToken.token&&(s.searchParams.append("auth","token"),s.searchParams.append("secret",this._authToken.token)),e=s.toString().substring(t.length-1)}return e}account(e,t,s,i,n){const a=g(this,R,H).call(this,"acc");return a.acc.user=e,a.acc.scheme=t,a.acc.secret=s,a.acc.login=i,n&&(a.acc.desc.defacs=n.defacs,a.acc.desc.public=n.public,a.acc.desc.private=n.private,a.acc.desc.trusted=n.trusted,a.acc.tags=n.tags,a.acc.cred=n.cred,a.acc.token=n.token,Array.isArray(n.attachments)&&n.attachments.length>0&&(a.extra={attachments:n.attachments.filter((e=>(0,r.isUrlRelative)(e)))})),g(this,E,q).call(this,a,a.acc.id)}createAccount(e,t,s,n){let r=this.account(i.USER_NEW,e,t,s,n);return s&&(r=r.then((e=>g(this,N,$).call(this,e)))),r}createAccountBasic(e,t,s){return e=e||"",t=t||"",this.createAccount("basic",v(e+":"+t),!0,s)}updateAccountBasic(e,t,s,i){return t=t||"",s=s||"",this.account(e,"basic",v(t+":"+s),!1,i)}hello(){const e=g(this,R,H).call(this,"hi");return g(this,E,q).call(this,e,e.hi.id).then((e=>(this._connection.backoffReset(),e.params&&(this._serverInfo=e.params),this.onConnect&&this.onConnect(),e))).catch((e=>{this._connection.reconnect(!0),this.onDisconnect&&this.onDisconnect(e)}))}setDeviceToken(e){let t=!1;return(e=e||null)!=this._deviceToken&&(this._deviceToken=e,this.isConnected()&&this.isAuthenticated()&&(g(this,E,q).call(this,{hi:{dev:e||k.DEL_CHAR}}),t=!0)),t}login(e,t,s){const i=g(this,R,H).call(this,"login");return i.login.scheme=e,i.login.secret=t,i.login.cred=s,g(this,E,q).call(this,i,i.login.id).then((e=>g(this,N,$).call(this,e)))}loginBasic(e,t,s){return this.login("basic",v(e+":"+t),s).then((t=>(this._login=e,t)))}loginToken(e,t){return this.login("token",e,t)}requestResetAuthSecret(e,t,s){return this.login("reset",v(e+":"+t+":"+s))}getAuthToken(){return this._authToken&&this._authToken.expires.getTime()>Date.now()?this._authToken:(this._authToken=null,null)}setAuthToken(e){this._authToken=e}subscribe(e,t,s){const n=g(this,R,H).call(this,"sub",e);if(e||(e=i.TOPIC_NEW),n.sub.get=t,s){if(s.sub&&(n.sub.set.sub=s.sub),s.desc){const t=s.desc;k.isNewGroupTopicName(e)?n.sub.set.desc=t:k.isP2PTopicName(e)&&t.defacs&&(n.sub.set.desc={defacs:t.defacs})}Array.isArray(s.attachments)&&s.attachments.length>0&&(n.extra={attachments:s.attachments.filter((e=>(0,r.isUrlRelative)(e)))}),s.tags&&(n.sub.set.tags=s.tags)}return g(this,E,q).call(this,n,n.sub.id)}leave(e,t){const s=g(this,R,H).call(this,"leave",e);return s.leave.unsub=t,g(this,E,q).call(this,s,s.leave.id)}createMessage(e,t,s){const i=g(this,R,H).call(this,"pub",e);let n="string"==typeof t?c.default.parse(t):t;return n&&!c.default.isPlainText(n)&&(i.pub.head={mime:c.default.getContentType()},t=n),i.pub.noecho=s,i.pub.content=t,i.pub}publish(e,t,s){return this.publishMessage(this.createMessage(e,t,s))}publishMessage(e,t){(e=Object.assign({},e)).seq=void 0,e.from=void 0,e.ts=void 0;const s={pub:e};return t&&(s.extra={attachments:t.filter((e=>(0,r.isUrlRelative)(e)))}),g(this,E,q).call(this,s,e.id)}oobNotification(e){switch(this.logger("oob: "+(this._trimLongStrings?JSON.stringify(e,w):e)),e.what){case"msg":if(!e.seq||e.seq<1||!e.topic)break;if(!this.isConnected())break;const t=g(this,O,B).call(this,"topic",e.topic);if(!t)break;if(t.isSubscribed())break;t.maxMsgSeq()<e.seq&&(t.isChannelType()&&t._updateReceived(e.seq,"fake-uid"),e.xfrom&&!g(this,O,B).call(this,"user",e.xfrom)&&this.getMeta(e.xfrom,(new d.default).withDesc().build()).catch((e=>{this.logger("Failed to get the name of a new sender",e)})),t.subscribe(null).then((e=>t.getMeta(new d.default(t).withLaterData(24).withLaterDel(24).build()))).then((e=>{t.leaveDelayed(!1,1e3)})).catch((e=>{this.logger("On push data fetch failed",e)})).finally((e=>{this.getMeTopic()._refreshContact("msg",t)})));break;case"read":this.getMeTopic()._routePres({what:"read",seq:e.seq});break;case"sub":if(!this.isMe(e.xfrom))break;let i={given:e.modeGiven,want:e.modeWant},n=new s.default(i),r=n.mode&&n.mode!=s.default._NONE?{what:"acs",src:e.topic,dacs:i}:{what:"gone",src:e.topic};this.getMeTopic()._routePres(r);break;default:this.logger("Unknown push type ignored",e.what)}}getMeta(e,t){const s=g(this,R,H).call(this,"get",e);return s.get=(0,r.mergeObj)(s.get,t),g(this,E,q).call(this,s,s.get.id)}setMeta(e,t){const s=g(this,R,H).call(this,"set",e),i=[];return t&&(["desc","sub","tags","cred","ephemeral"].forEach((function(e){t.hasOwnProperty(e)&&(i.push(e),s.set[e]=t[e])})),Array.isArray(t.attachments)&&t.attachments.length>0&&(s.extra={attachments:t.attachments.filter((e=>(0,r.isUrlRelative)(e)))})),0==i.length?Promise.reject(new Error("Invalid {set} parameters")):g(this,E,q).call(this,s,s.set.id)}delMessages(e,t,s){const i=g(this,R,H).call(this,"del",e);return i.del.what="msg",i.del.delseq=t,i.del.hard=s,g(this,E,q).call(this,i,i.del.id)}delTopic(e,t){const s=g(this,R,H).call(this,"del",e);return s.del.what="topic",s.del.hard=t,g(this,E,q).call(this,s,s.del.id)}delSubscription(e,t){const s=g(this,R,H).call(this,"del",e);return s.del.what="sub",s.del.user=t,g(this,E,q).call(this,s,s.del.id)}delCredential(e,t){const s=g(this,R,H).call(this,"del",i.TOPIC_ME);return s.del.what="cred",s.del.cred={meth:e,val:t},g(this,E,q).call(this,s,s.del.id)}delCurrentUser(e){const t=g(this,R,H).call(this,"del",null);return t.del.what="user",t.del.hard=e,g(this,E,q).call(this,t,t.del.id).then((e=>{this._myUID=null}))}note(e,t,s){if(s<=0||s>=i.LOCAL_SEQID)throw new Error("Invalid message id "+s);const n=g(this,R,H).call(this,"note",e);n.note.what=t,n.note.seq=s,g(this,E,q).call(this,n)}noteKeyPress(e,t){const s=g(this,R,H).call(this,"note",e);s.note.what=t||"kp",g(this,E,q).call(this,s)}videoCall(e,t,s,i){const n=g(this,R,H).call(this,"note",e);n.note.seq=t,n.note.what="call",n.note.event=s,n.note.payload=i,g(this,E,q).call(this,n,n.note.id)}getTopic(e){let t=g(this,O,B).call(this,"topic",e);return!t&&e&&(t=e==i.TOPIC_ME?new et.TopicMe:e==i.TOPIC_FND?new et.TopicFnd:new et.Topic(e),g(this,I,X).call(this,t),t._cachePutSelf()),t}cacheGetTopic(e){return g(this,O,B).call(this,"topic",e)}cacheRemTopic(e){g(this,C,Q).call(this,"topic",e)}mapTopics(e,t){g(this,D,K).call(this,"topic",e,t)}isTopicCached(e){return!!g(this,O,B).call(this,"topic",e)}newGroupTopicName(e){return(e?i.TOPIC_NEW_CHAN:i.TOPIC_NEW)+this.getNextUniqueId()}getMeTopic(){return this.getTopic(i.TOPIC_ME)}getFndTopic(){return this.getTopic(i.TOPIC_FND)}getLargeFileHelper(){return new h.default(this,i.PROTOCOL_VERSION)}getCurrentUserID(){return this._myUID}isMe(e){return this._myUID===e}getCurrentLogin(){return this._login}getServerInfo(){return this._serverInfo}report(e,t){return this.publish(i.TOPIC_SYS,c.default.attachJSON(null,{action:e,target:t}))}getServerParam(e,t){return this._serverInfo&&this._serverInfo[e]||t}enableLogging(e,t){this._loggingEnabled=e,this._trimLongStrings=e&&t}setHumanLanguage(e){e&&(this._humanLanguage=e)}isTopicOnline(e){const t=g(this,O,B).call(this,"topic",e);return t&&t.online}getTopicAccessMode(e){const t=g(this,O,B).call(this,"topic",e);return t?t.acs:null}wantAkn(e){this._messageId=e?Math.floor(16777215*Math.random()+16777215):0}}function U(e){let t=null;return e&&(t=new Promise(((t,s)=>{this._pendingPromises[e]={resolve:t,reject:s,ts:new Date}}))),t}function j(e,t,s,i){const n=this._pendingPromises[e];n&&(delete this._pendingPromises[e],t>=200&&t<400?n.resolve&&n.resolve(s):n.reject&&n.reject(new Error(`${i} (${t})`)))}function q(e,t){let s;t&&(s=g(this,S,U).call(this,t)),e=(0,r.simplify)(e);let i=JSON.stringify(e);this.logger("out: "+(this._trimLongStrings?JSON.stringify(e,w):i));try{this._connection.sendText(i)}catch(e){if(!t)throw e;g(this,T,j).call(this,t,a.default.NETWORK_ERROR,null,e.message)}return s}function L(e){if(!e)return;if(this._inPacketCount++,this.onRawMessage&&this.onRawMessage(e),"0"===e)return void(this.onNetworkProbe&&this.onNetworkProbe());let t=JSON.parse(e,r.jsonParseHelper);t?(this.logger("in: "+(this._trimLongStrings?JSON.stringify(t,w):e)),this.onMessage&&this.onMessage(t),t.ctrl?(this.onCtrlMessage&&this.onCtrlMessage(t.ctrl),t.ctrl.id&&g(this,T,j).call(this,t.ctrl.id,t.ctrl.code,t.ctrl,t.ctrl.text),setTimeout((e=>{if(205==t.ctrl.code&&"evicted"==t.ctrl.text){const e=g(this,O,B).call(this,"topic",t.ctrl.topic);e&&(e._resetSub(),t.ctrl.params&&t.ctrl.params.unsub&&e._gone())}else if(t.ctrl.code<300&&t.ctrl.params)if("data"==t.ctrl.params.what){const e=g(this,O,B).call(this,"topic",t.ctrl.topic);e&&e._allMessagesReceived(t.ctrl.params.count)}else if("sub"==t.ctrl.params.what){const e=g(this,O,B).call(this,"topic",t.ctrl.topic);e&&e._processMetaSub([])}}),0)):setTimeout((e=>{if(t.meta){const e=g(this,O,B).call(this,"topic",t.meta.topic);e&&e._routeMeta(t.meta),t.meta.id&&g(this,T,j).call(this,t.meta.id,200,t.meta,"META"),this.onMetaMessage&&this.onMetaMessage(t.meta)}else if(t.data){const e=g(this,O,B).call(this,"topic",t.data.topic);e&&e._routeData(t.data),this.onDataMessage&&this.onDataMessage(t.data)}else if(t.pres){const e=g(this,O,B).call(this,"topic",t.pres.topic);e&&e._routePres(t.pres),this.onPresMessage&&this.onPresMessage(t.pres)}else if(t.info){const e=g(this,O,B).call(this,"topic",t.info.topic);e&&e._routeInfo(t.info),this.onInfoMessage&&this.onInfoMessage(t.info)}else this.logger("ERROR: Unknown packet received.")}),0)):(this.logger("in: "+e),this.logger("ERROR: failed to parse data"))}function W(){this._expirePromises||(this._expirePromises=setInterval((e=>{const t=new Error("Timeout (504)"),s=new Date((new Date).getTime()-i.EXPIRE_PROMISES_TIMEOUT);for(let e in this._pendingPromises){let i=this._pendingPromises[e];i&&i.ts<s&&(this.logger("Promise expired",e),delete this._pendingPromises[e],i.reject&&i.reject(t))}}),i.EXPIRE_PROMISES_PERIOD)),this.hello()}function G(e,t){this._inPacketCount=0,this._serverInfo=null,this._authenticated=!1,this._expirePromises&&(clearInterval(this._expirePromises),this._expirePromises=null),g(this,D,K).call(this,"topic",((e,t)=>{e._resetSub()}));for(let t in this._pendingPromises){const s=this._pendingPromises[t];s&&s.reject&&s.reject(e)}this._pendingPromises={},this.onDisconnect&&this.onDisconnect(e)}function V(){return this._appName+" ("+(this._browser?this._browser+"; ":"")+this._hwos+"); "+i.LIBRARY}function H(e,t){switch(e){case"hi":return{hi:{id:this.getNextUniqueId(),ver:i.VERSION,ua:g(this,A,V).call(this),dev:this._deviceToken,lang:this._humanLanguage,platf:this._platform}};case"acc":return{acc:{id:this.getNextUniqueId(),user:null,scheme:null,secret:null,login:!1,tags:null,desc:{},cred:{}}};case"login":return{login:{id:this.getNextUniqueId(),scheme:null,secret:null}};case"sub":return{sub:{id:this.getNextUniqueId(),topic:t,set:{},get:{}}};case"leave":return{leave:{id:this.getNextUniqueId(),topic:t,unsub:!1}};case"pub":return{pub:{id:this.getNextUniqueId(),topic:t,noecho:!1,head:null,content:{}}};case"get":return{get:{id:this.getNextUniqueId(),topic:t,what:null,desc:{},sub:{},data:{}}};case"set":return{set:{id:this.getNextUniqueId(),topic:t,desc:{},sub:{},tags:[],ephemeral:{}}};case"del":return{del:{id:this.getNextUniqueId(),topic:t,what:null,delseq:null,user:null,hard:!1}};case"note":return{note:{topic:t,what:null,seq:void 0}};default:throw new Error("Unknown packet type requested: "+e)}}function z(e,t,s){this._cache[e+":"+t]=s}function B(e,t){return this._cache[e+":"+t]}function Q(e,t){delete this._cache[e+":"+t]}function K(e,t,s){const i=e?e+":":void 0;for(let e in this._cache)if((!i||0==e.indexOf(i))&&t.call(s,this._cache[e],e))break}function X(e){e._tinode=this,e._cacheGetUser=e=>{const t=g(this,O,B).call(this,"user",e);if(t)return{user:e,public:(0,r.mergeObj)({},t)}},e._cachePutUser=(e,t)=>{g(this,x,z).call(this,"user",e,(0,r.mergeObj)({},t.public))},e._cacheDelUser=e=>{g(this,C,Q).call(this,"user",e)},e._cachePutSelf=t=>{g(this,x,z).call(this,"topic",e.name,e)},e._cacheDelSelf=t=>{g(this,C,Q).call(this,"topic",e.name)}}function $(e){return e.params&&e.params.user?(this._myUID=e.params.user,this._authenticated=e&&e.code>=200&&e.code<300,e.params&&e.params.token&&e.params.expires?this._authToken={token:e.params.token,expires:e.params.expires}:this._authToken=null,this.onLogin&&this.onLogin(e.code,e.text),e):e}lt.Tinode=k,k.MESSAGE_STATUS_NONE=i.MESSAGE_STATUS_NONE,k.MESSAGE_STATUS_QUEUED=i.MESSAGE_STATUS_QUEUED,k.MESSAGE_STATUS_SENDING=i.MESSAGE_STATUS_SENDING,k.MESSAGE_STATUS_FAILED=i.MESSAGE_STATUS_FAILED,k.MESSAGE_STATUS_SENT=i.MESSAGE_STATUS_SENT,k.MESSAGE_STATUS_RECEIVED=i.MESSAGE_STATUS_RECEIVED,k.MESSAGE_STATUS_READ=i.MESSAGE_STATUS_READ,k.MESSAGE_STATUS_TO_ME=i.MESSAGE_STATUS_TO_ME,k.DEL_CHAR=i.DEL_CHAR,k.MAX_MESSAGE_SIZE="maxMessageSize",k.MAX_SUBSCRIBER_COUNT="maxSubscriberCount",k.MAX_TAG_COUNT="maxTagCount",k.MAX_FILE_UPLOAD_SIZE="maxFileUploadSize"}).call(this)}.call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{}),lt})); |