2 lines
53 KiB
Plaintext
2 lines
53 KiB
Plaintext
/*! For license information please see NoticeEntry-frontier.74735cc6.js.LICENSE.txt */
|
||
(self.webpackChunkdouyin_web=self.webpackChunkdouyin_web||[]).push([["91465"],{747688:function(e,t,i){var n,s=i(777296),r=i(949868).Buffer;n=0,function(e){"use strict";var t;let i,n;function o(e,t,i,n){return new(i||(i=Promise))(function(s,r){function o(e){try{h(n.next(e))}catch(e){r(e)}}function a(e){try{h(n.throw(e))}catch(e){r(e)}}function h(e){var t;e.done?s(e.value):((t=e.value)instanceof i?t:new i(function(e){e(t)})).then(o,a)}h((n=n.apply(e,t||[])).next())})}let a="";function h(){return 1e4*Date.now()+Math.floor(1e4*Math.random())}function l(e){return("000"+parseInt(e,2).toString(16)).slice(-4)}function c(e){let t=f();return function(e,t){let i=e.SeqID;void 0!==i&&(S(t,8),T(t,i));let n=e.LogID;void 0!==n&&(S(t,16),T(t,n));let s=e.service;void 0!==s&&(S(t,24),T(t,u(s)));let r=e.method;void 0!==r&&(S(t,32),T(t,u(r)));let o=e.headers;if(void 0!==o)for(let e of o){S(t,42);let i=f();!function(e,t){let i=e.key;void 0!==i&&(S(t,10),w(t,i));let n=e.value;void 0!==n&&(S(t,18),w(t,n))}(e,i),S(t,i.limit),function(e,t){let i=v(e,t.limit),n=e.bytes,s=t.bytes;for(let e=0,r=t.limit;e<r;e++)n[e+i]=s[e]}(t,i),function(e){_.push(e)}(i)}let a=e.payloadEncoding;void 0!==a&&(S(t,50),w(t,a));let h=e.payloadType;void 0!==h&&(S(t,58),w(t,h));let l=e.payload;void 0!==l&&(S(t,66),S(t,l.length),function(e,t){let i=v(e,t.length);e.bytes.set(t,i)}(t,l));let c=e.LogIDNew;void 0!==c&&(S(t,74),w(t,c));let d=e.serverTiming;void 0!==d&&(S(t,82),w(t,d));let g=e.msgID;void 0!==g&&(S(t,90),w(t,g));let p=e.frameType;void 0!==p&&(S(t,96),T(t,u(p)))}(e,t),function(e){let t=e.bytes,i=e.limit;return t.length===i?t:t.subarray(0,i)}(t)}function d(e,t){switch(t){case 0:for(;128&E(e););break;case 2:g(e,C(e));break;case 5:g(e,4);break;case 1:g(e,8);break;default:throw Error("Unimplemented type: "+t)}}function u(e){return{low:e|=0,high:e>>31,unsigned:e>=0}}let _=[];function f(){let e=_.pop();return e?(e.offset=e.limit=0,e):{bytes:new Uint8Array(64),offset:0,limit:0}}function g(e,t){if(e.offset+t>e.limit)throw Error("Skip past limit");e.offset+=t}function p(e){return e.offset>=e.limit}function v(e,t){let i=e.bytes,n=e.offset,s=e.limit,r=n+t;if(r>i.length){let t=new Uint8Array(2*r);t.set(i),e.bytes=t}return e.offset=r,r>s&&(e.limit=r),n}function m(e,t){let i=e.offset;if(i+t>e.limit)throw Error("Read past limit");return e.offset+=t,i}function y(e,t){let i=m(e,t),n=String.fromCharCode,s=e.bytes,r="";for(let e=0;e<t;e++){let o,a,h,l;let c=s[e+i];(128&c)==0?r+=n(c):(224&c)==192?e+1>=t?r+="<22>":(192&(o=s[e+i+1]))!=128?r+="<22>":(l=(31&c)<<6|63&o)<128?r+="<22>":(r+=n(l),e++):(240&c)==224?e+2>=t?r+="<22>":(o=s[e+i+1],((o|(a=s[e+i+2])<<8)&49344)!=32896?r+="<22>":(l=(15&c)<<12|(63&o)<<6|63&a)<2048||l>=55296&&l<=57343?r+="<22>":(r+=n(l),e+=2)):(248&c)==240?e+3>=t?r+="<22>":(o=s[e+i+1],a=s[e+i+2],((o|a<<8|(h=s[e+i+3])<<16)&12632256)!=8421504?r+="<22>":(l=(7&c)<<18|(63&o)<<12|(63&a)<<6|63&h)<65536||l>1114111?r+="<22>":(l-=65536,r+=n((l>>10)+55296,(1023&l)+56320),e+=3)):r+="<22>"}return r}function w(e,t){let i=t.length,n=0;for(let e=0;e<i;e++){let s=t.charCodeAt(e);s>=55296&&s<=56319&&e+1<i&&(s=(s<<10)+t.charCodeAt(++e)-56613888),n+=s<128?1:s<2048?2:s<65536?3:4}S(e,n);let s=v(e,n),r=e.bytes;for(let e=0;e<i;e++){let n=t.charCodeAt(e);n>=55296&&n<=56319&&e+1<i&&(n=(n<<10)+t.charCodeAt(++e)-56613888),n<128?r[s++]=n:(n<2048?r[s++]=n>>6&31|192:(n<65536?r[s++]=n>>12&15|224:(r[s++]=n>>18&7|240,r[s++]=n>>12&63|128),r[s++]=n>>6&63|128),r[s++]=63&n|128)}}function E(e){return e.bytes[m(e,1)]}function b(e,t){let i=v(e,1);e.bytes[i]=t}function C(e){let t,i=0,n=0;do t=E(e),i<32&&(n|=(127&t)<<i),i+=7;while(128&t);return n}function S(e,t){for(t>>>=0;t>=128;)b(e,127&t|128),t>>>=7;b(e,t)}function I(e,t){let i,n=0,s=0,r=0;return n=127&(i=E(e)),128&i&&(n|=(127&(i=E(e)))<<7,128&i&&(n|=(127&(i=E(e)))<<14,128&i&&(n|=(127&(i=E(e)))<<21,128&i&&(s=127&(i=E(e)),128&i&&(s|=(127&(i=E(e)))<<7,128&i&&(s|=(127&(i=E(e)))<<14,128&i&&(s|=(127&(i=E(e)))<<21,128&i&&(r=127&(i=E(e)),128&i&&(r|=(127&(i=E(e)))<<7))))))))),{low:n|s<<28,high:s>>>4|r<<24,unsigned:t}}function T(e,t){let i=t.low>>>0,n=(t.low>>>28|t.high<<4)>>>0,s=t.high>>>24,r=0===s?0===n?i<16384?i<128?1:2:i<2097152?3:4:n<16384?n<128?5:6:n<2097152?7:8:s<128?9:10,o=v(e,r),a=e.bytes;switch(r){case 10:a[o+9]=s>>>7&1;case 9:a[o+8]=9!==r?128|s:127&s;case 8:a[o+7]=8!==r?n>>>21|128:n>>>21&127;case 7:a[o+6]=7!==r?n>>>14|128:n>>>14&127;case 6:a[o+5]=6!==r?n>>>7|128:n>>>7&127;case 5:a[o+4]=5!==r?128|n:127&n;case 4:a[o+3]=4!==r?i>>>21|128:i>>>21&127;case 3:a[o+2]=3!==r?i>>>14|128:i>>>14&127;case 2:a[o+1]=2!==r?i>>>7|128:i>>>7&127;case 1:a[o]=1!==r?128|i:127&i}}function k(e){return function(e){let t={};e:for(;!p(e);){let i=C(e);switch(i>>>3){case 0:break e;case 1:t.SeqID=I(e,!0);break;case 2:t.LogID=I(e,!0);break;case 3:t.service=C(e);break;case 4:t.method=C(e);break;case 5:{let i=function(e){let t=C(e),i=e.limit;return e.limit=e.offset+t,i}(e);(t.headers||(t.headers=[])).push(function(e){let t={};e:for(;!p(e);){let i=C(e);switch(i>>>3){case 0:break e;case 1:t.key=y(e,C(e));break;case 2:t.value=y(e,C(e));break;default:d(e,7&i)}}if(void 0===t.key)throw Error("Missing required field: key");if(void 0===t.value)throw Error("Missing required field: value");return t}(e)),e.limit=i;break}case 6:t.payloadEncoding=y(e,C(e));break;case 7:t.payloadType=y(e,C(e));break;case 8:t.payload=function(e,t){let i=m(e,t);return e.bytes.subarray(i,i+t)}(e,C(e));break;case 9:t.LogIDNew=y(e,C(e));break;case 10:t.serverTiming=y(e,C(e));break;case 11:t.msgID=y(e,C(e));break;case 12:t.frameType=C(e);break;default:d(e,7&i)}}if(void 0===t.SeqID)throw Error("Missing required field: SeqID");if(void 0===t.LogID)throw Error("Missing required field: LogID");if(void 0===t.service)throw Error("Missing required field: service");if(void 0===t.method)throw Error("Missing required field: method");return t}(function(e){return{bytes:e,offset:0,limit:e.length}}(e))}function D(e){return c(e)}let O=4294967296,B=18446744073709552e3,L=0x7fffffffffffffff,N=String.prototype.charCodeAt;class M{constructor(e,t,i){this.isLong=!0,this.low=0|e,this.high=0|t,this.unsigned=!!i}static isLong(e){return e&&!0===e.isLong}static fromBits(e,t,i){return new M(e,t,i)}static fromBytes(e,t,i){return i?M.fromBytesLE(e,t):M.fromBytesBE(e,t)}static fromBytesLE(e,t){return new M(e[0]|e[1]<<8|e[2]<<16|e[3]<<24,e[4]|e[5]<<8|e[6]<<16|e[7]<<24,t)}static fromBytesBE(e,t){return new M(e[4]<<24|e[5]<<16|e[6]<<8|e[7],e[0]<<24|e[1]<<16|e[2]<<8|e[3],t)}static fromHash(e){return"\0\0\0\0\0\0\0\0"===e?R:new M((N.call(e,0)|N.call(e,1)<<8|N.call(e,2)<<16|N.call(e,3)<<24)>>>0,(N.call(e,4)|N.call(e,5)<<8|N.call(e,6)<<16|N.call(e,7)<<24)>>>0,!0)}toHash(){return String.fromCharCode(255&this.low,this.low>>>8&255,this.low>>>16&255,this.low>>>24,255&this.high,this.high>>>8&255,this.high>>>16&255,this.high>>>24)}static fromNumber(e,t=!0){if(isNaN(e))return t?x:R;if(t){if(e>=B)return q}else{if(e<=-L)return P;if(e+1>=L)return A}return M.fromBits(e%O|0,e/O|0,t)}toNumber(){return this.unsigned?(this.high>>>0)*O+(this.low>>>0):this.high*O+(this.low>>>0)}isZero(){return 0===this.high&&0===this.low}add(e){!M.isLong(e)&&(e=M.fromNumber(e));let t=this.high>>>16,i=65535&this.high,n=this.low>>>16,s=65535&this.low,r=e.high>>>16,o=65535&e.high,a=e.low>>>16,h=65535&e.low,l=0,c=0,d,u;return d=0+((u=0+(s+h))>>>16),u&=65535,d+=n+a,c+=d>>>16,d&=65535,c+=i+o,l+=c>>>16,c&=65535,l+=t+r,l&=65535,M.fromBits(d<<16|u,l<<16|c,this.unsigned)}equals(e){return!M.isLong(e)&&(e=M.fromNumber(e)),(this.unsigned===e.unsigned||this.high>>>31!=1||e.high>>>31!=1)&&this.high===e.high&&this.low===e.low}addOne(){return -1===this.low&&-1===this.high?M.fromBits(0,0,this.unsigned):-1===this.low?M.fromBits(0,this.high+1,this.unsigned):M.fromBits(this.low+1,this.high,this.unsigned)}toBytes(e){return e?this.toBytesLE():this.toBytesBE()}toBytesLE(){let e=this.high,t=this.low;return[255&t,t>>>8&255,t>>>16&255,t>>>24,255&e,e>>>8&255,e>>>16&255,e>>>24]}toBytesBE(){let e=this.high,t=this.low;return[e>>>24,e>>>16&255,e>>>8&255,255&e,t>>>24,t>>>16&255,t>>>8&255,255&t]}}let R=new M(0,0,!1),x=new M(0,0,!0),A=M.fromBits(-1,2147483647,!1),q=M.fromBits(-1,-1,!0),P=M.fromBits(0,-2147483648,!1);e.ErrorCode=void 0,(t=e.ErrorCode||(e.ErrorCode={}))[t.NATIVE_ERROR=5001]="NATIVE_ERROR",t[t.CONNECTING_ERROR=5002]="CONNECTING_ERROR",t[t.MAX_RETRIES_ERROR=5003]="MAX_RETRIES_ERROR",t[t.MESSAGE_ERROR=5004]="MESSAGE_ERROR",t[t.OPEN_ERROR=5005]="OPEN_ERROR";class ${constructor(e){this.type=e,this.target=null}}class W extends ${constructor(e,t){super(e),this.message=t&&t.message||null}}class j extends ${constructor(t,i){super(t),this.error=i&&i.error||null,this.colno=i&&i.colno||0,this.filename=i&&i.filename||"",this.lineno=i&&i.lineno||0,this.message=i&&i.message||"",this.code=i&&i.code||e.ErrorCode.NATIVE_ERROR}}class F extends ${constructor(e,t){super(e),this.code=t&&t.code||0,this.reason=t&&t.reason||"",this.wasClean=t&&t.wasClean||!1,this.willReconnect=t&&t.willReconnect||!1}}class U extends ${constructor(e,t){super(e),this.data=t&&t.data||null}}class Q extends U{constructor(e,t){super(e),this.data=t&&t.data||null,this.message=t&&t.message||null}}class J extends ${constructor(e,t){super(e),this.data=t&&t.data||null}}function G(e,{message:t,code:i,error:n}){return new j(e,{message:t,code:i,error:n})}function H(e,{code:t,reason:i,wasClean:n,willReconnect:s}){return new F(e,{code:t,reason:i,wasClean:n,willReconnect:s})}function K(e,{data:t,message:i}){return new Q(e,{data:t,message:i})}function V(e,{data:t}){return new J(e,{data:t})}function X(e,{message:t}){return new W(e,{message:t})}class Z{constructor(e,t){this.endpoints=e,this.maxRetries=t,this.currentIndex=0,this.currentEndpointTriesCount=0}resetEndpointConfig(){this.currentIndex=0,this.currentEndpointTriesCount=0}resetTries(){this.currentEndpointTriesCount=0}getCurrentEndpoint(){return this.endpoints[this.currentIndex]}getCurrentEndpointTriesCount(){return this.currentEndpointTriesCount}checkReachMaxTries(){return!!(this.currentIndex>=this.endpoints.length)||this.currentIndex===this.endpoints.length-1&&this.currentEndpointTriesCount===this.maxRetries||!1}checkCurrentEndpointReachedMaxRetries(){return this.currentIndex==this.endpoints.length||this.currentEndpointTriesCount>this.maxRetries}replaceBackupEndpointAndUpdateCount(){return this.currentEndpointTriesCount=1,this.currentIndex++,this.endpoints[this.currentIndex]}getCurrentEndpointAndUpdateCount(){return this.currentEndpointTriesCount++,this.getCurrentEndpoint()}}let z=("undefined"!=typeof globalThis&&"Window"===globalThis.constructor.name||"undefined"!=typeof window&&"Window"===window.constructor.name)&&"undefined"!=typeof document,Y="undefined"!=typeof globalThis&&("Object"===globalThis.constructor.name||"DedicatedWorkerGlobalScope"===globalThis.constructor.name)&&"undefined"!=typeof tt,ee=("undefined"!=typeof globalThis&&"Object"===globalThis.constructor.name||"undefined"==typeof globalThis||"undefined"!=typeof globalThis&&!!globalThis.WeixinJSBridge)&&"undefined"!=typeof wx,et="undefined"!=typeof globalThis&&("DedicatedWorkerGlobalScope"===globalThis.constructor.name||"SharedWorkerGlobalScope"===globalThis.constructor.name||"ServiceWorkerGlobalScope"===globalThis.constructor.name)&&"undefined"!=typeof self,ei="undefined"!=typeof globalThis&&"Object"===globalThis.constructor.name&&"undefined"!=typeof window&&"Object"===window.constructor.name&&void 0!==s&&!!s.version;class en{constructor(){this._listeners={}}emit(e,...t){let i=this._listeners[e];if(i)i.slice().forEach(e=>e.fn.apply(e.ctx,t));else if("error"===e&&!this.onerror){let e=t.length&&t[0];if(e instanceof Error)throw e;throw Error("Unhandled error."+(e?" ("+e.message+")":"")).context=e,e}return this}off(e,t){if(void 0===e)this._listeners={};else if(void 0===t)this._listeners[e]=null;else{let i=this._listeners[e];if(i)for(let e=0;e<i.length;)i[e].fn===t?i.splice(e,1):++e}return this}on(e,t,i){return(this._listeners[e]||(this._listeners[e]=[])).push({fn:t,ctx:i||this}),this}}class es extends en{constructor(e,t,i){super(),this._socket=null,ee&&wx.connectSocket&&(this._socket=wx.connectSocket({url:e,protocols:t,header:i,fail:this._createSocketFailHandler.bind(this),success:this._createSocketSuccessHandler.bind(this)})),Y&&tt.connectSocket&&(this._socket=tt.connectSocket({url:e,protocols:t,header:i,fail:this._createSocketFailHandler.bind(this),success:this._createSocketSuccessHandler.bind(this)}))}_createSocketSuccessHandler(){Promise.resolve().then(()=>{this._addWsListeners()})}_createSocketFailHandler(e){Promise.resolve().then(()=>{let t=G("error",{message:e.errMsg||e.errNo?`message: ${e.errMsg}`||`code: ${e.errNo}`||"":JSON.stringify(e)});this.emit("error",t);let i=H("close",{reason:e.errMsg||e.errNo?`message: ${e.errMsg}`||`code: ${e.errNo}`||"":JSON.stringify(e)});this.emit("close",i)})}_addWsListeners(){this._socket.onOpen(e=>{this.emit("open",V("open",Object.assign(Object.assign({},e),{data:e.errMsg||""})))}),this._socket.onClose(e=>{this.emit("close",H("close",Object.assign({},e)))}),this._socket.onMessage(e=>{this.emit("message",K("message",Object.assign({},e)))}),this._socket.onError(e=>{this.emit("error",G("error",Object.assign(Object.assign({},e),{message:e.errMsg||""})))})}send(e){if(e instanceof Uint8Array){let t=e.buffer.slice(e.byteOffset,e.byteLength+e.byteOffset);this._socket&&this._socket.send({data:t,fail:e=>{this.emit("error",G("error",{message:e.errMsg||e.errNo?`message: ${e.errMsg}`||`code: ${e.errNo}`||"":JSON.stringify(e)}))}})}else this._socket&&this._socket.send({data:e,fail:e=>{this.emit("error",G("error",{message:e.errMsg||e.errNo?`message: ${e.errMsg}`||`code: ${e.errNo}`||"":JSON.stringify(e)}))}})}close(e,t){this._socket&&this._socket.close({code:e,reason:t})}addEventListener(e,t){this.on(e,t)}removeEventListener(e,t){this.off(e,t)}get readyState(){return this._socket.readyState}get binaryType(){return this._socket.binaryType}set binaryType(e){}get url(){return this._socket.url}get protocol(){return this._socket.protocol}get extensions(){return this._socket.extensions}get bufferedAmount(){return 0}}function er(e,t,i){let n=-1;!function s(r){return o(this,void 0,void 0,function*(){return r<=n?Promise.reject(Error("next() called multiple times in process")):(n=r,r===i.length)?Promise.resolve():i[r].bind(e)(t,s.bind(null,r+1))})}(0)}function eo(e){let t=0,i=0;for(let n=0;n<e.length;++n)(i=e.charCodeAt(n))<128?t+=1:i<2048?t+=2:(64512&i)==55296&&(64512&e.charCodeAt(n+1))==56320?(++n,t+=4):t+=3;return t}function ea(e,t,i){if(i-t<1)return"";let n="";for(let s=t;s<i;){let t=e[s++];if(t<=127)n+=String.fromCharCode(t);else if(t>=192&&t<224)n+=String.fromCharCode((31&t)<<6|63&e[s++]);else if(t>=224&&t<240)n+=String.fromCharCode((15&t)<<12|(63&e[s++])<<6|63&e[s++]);else if(t>=240){let i=((7&t)<<18|(63&e[s++])<<12|(63&e[s++])<<6|63&e[s++])-65536;n+=String.fromCharCode(55296+(i>>10))+String.fromCharCode(56320+(1023&i))}}return n}function eh(e,t,i){let n,s;let r=i;for(let r=0;r<e.length;++r)(n=e.charCodeAt(r))<128?t[i++]=n:(n<2048?t[i++]=n>>6|192:((64512&n)==55296&&(64512&(s=e.charCodeAt(r+1)))==56320?(n=65536+((1023&n)<<10)+(1023&s),++r,t[i++]=n>>18|240,t[i++]=n>>12&63|128):t[i++]=n>>12|224,t[i++]=n>>6&63|128),t[i++]=63&n|128);return i-r}function el(e){return o(this,void 0,void 0,function*(){if("string"==typeof e){let t=new Uint8Array(eo(e));return eh(e,t,0),t}if(e instanceof ArrayBuffer)return new Uint8Array(e);return new Uint8Array(e.buffer,e.byteOffset,e.byteLength)})}let ec=(e,t)=>{switch(e){case"boe":case"ppe":return{[`x-use-${e}`]:1,"x-tt-env":t};default:return{}}};class ed{constructor(e){this.maxLossCount=e,this.count=0}addCount(){this.count++}checkReachMaxCount(){return this.count>=this.maxLossCount}resetCounter(e=0){this.maxLossCount=e,this.count=0}}function eu(e,t,i){return!!(null==e?void 0:e.find(e=>e.key===t&&e.value===i))}function e_(e,t){var i;return null===(i=null==e?void 0:e.find(e=>e.key===t))||void 0===i?void 0:i.value}function ef(e,t){return o(this,void 0,void 0,function*(){let{enableAutoAck:i}=this._options,n=eu(e.message.headers,"need_ack","1"),s=eu(e.message.headers,"is_ack","1"),r=eu(e.message.headers,"x_frontier_qos_ack","1");if(i&&n){let{SeqID:t,LogID:i,service:n,LogIDNew:s,method:r}=e.message;this._sendAck({SeqID:t,LogID:i,LogIDNew:s,service:n,method:r,headers:[{key:"is_ack",value:"1"},{key:"ack_id",value:s||""},{key:"ack_code",value:"0"}]})}s&&!r&&this._dispatchAckMessageEvent(e),t()})}function eg(e,t){return o(this,void 0,void 0,function*(){this._debug("received",e.message),t()})}function ep(e,t){return o(this,void 0,void 0,function*(){let i=k((yield el(e.data)));try{if(i.payload instanceof Uint8Array){let e=this._options.payloadEncoding instanceof Object?{force:!!this._options.payloadEncoding.force,encoding:this._options.payloadEncoding.encoding?this._options.payloadEncoding.encoding.replace(/\s/g,"").toLowerCase():""}:{force:!1,encoding:this._options.payloadEncoding?this._options.payloadEncoding.replace(/\s/g,"").toLowerCase():""},t=i.payloadEncoding?i.payloadEncoding.replace(/\s/g,"").toLowerCase():"",n=this._options.payloadType instanceof Object?{force:!!this._options.payloadType.force,type:this._options.payloadType.type?this._options.payloadType.type.replace(/\s/g,"").toLowerCase():""}:{force:!1,type:this._options.payloadType?this._options.payloadType.replace(/\s/g,"").toLowerCase():""},s=i.payloadType?i.payloadType.replace(/\s/g,"").toLowerCase():"",r=n.force?n.type:s||n.type,o=e.force?e.encoding:t||e.encoding;this._options.enableTransformTextPayload&&["text/plain;charset=utf-8","application/json","application/json;charset=utf-8","string"].includes(r)&&(!o||["none_none","binary"].includes(o))?i.textPayload=ea(i.payload,0,i.payload.byteLength):i.textPayload=""}else i.textPayload=""}catch(e){i.textPayload=""}e.message=i,t()})}let ev=(e,t)=>t.some(t=>e instanceof t),em=new WeakMap,ey=new WeakMap,ew=new WeakMap,eE=new WeakMap,eb=new WeakMap,eC={get(e,t,i){if(e instanceof IDBTransaction){if("done"===t)return ey.get(e);if("objectStoreNames"===t)return e.objectStoreNames||ew.get(e);if("store"===t)return i.objectStoreNames[1]?void 0:i.objectStore(i.objectStoreNames[0])}return eS(e[t])},set:(e,t,i)=>(e[t]=i,!0),has:(e,t)=>e instanceof IDBTransaction&&("done"===t||"store"===t)||t in e};function eS(e){if(e instanceof IDBRequest)return function(e){let t=new Promise((t,i)=>{let n=()=>{e.removeEventListener("success",s),e.removeEventListener("error",r)},s=()=>{t(eS(e.result)),n()},r=()=>{i(e.error),n()};e.addEventListener("success",s),e.addEventListener("error",r)});return t.then(t=>{t instanceof IDBCursor&&em.set(t,e)}).catch(()=>{}),eb.set(t,e),t}(e);if(eE.has(e))return eE.get(e);let t=function(e){if("function"==typeof e){var t;return(t=e)!==IDBDatabase.prototype.transaction||"objectStoreNames"in IDBTransaction.prototype?(n||(n=[IDBCursor.prototype.advance,IDBCursor.prototype.continue,IDBCursor.prototype.continuePrimaryKey])).includes(t)?function(...e){return t.apply(eI(this),e),eS(em.get(this))}:function(...e){return eS(t.apply(eI(this),e))}:function(e,...i){let n=t.call(eI(this),e,...i);return ew.set(n,e.sort?e.sort():[e]),eS(n)}}return(e instanceof IDBTransaction&&!function(e){if(ey.has(e))return;let t=new Promise((t,i)=>{let n=()=>{e.removeEventListener("complete",s),e.removeEventListener("error",r),e.removeEventListener("abort",r)},s=()=>{t(),n()},r=()=>{i(e.error||new DOMException("AbortError","AbortError")),n()};e.addEventListener("complete",s),e.addEventListener("error",r),e.addEventListener("abort",r)});ey.set(e,t)}(e),ev(e,i||(i=[IDBDatabase,IDBObjectStore,IDBIndex,IDBCursor,IDBTransaction])))?new Proxy(e,eC):e}(e);return t!==e&&(eE.set(e,t),eb.set(t,e)),t}let eI=e=>eb.get(e),eT=["get","getKey","getAll","getAllKeys","count"],ek=["put","add","delete","clear"],eD=new Map;function eO(e,t){if(!(e instanceof IDBDatabase&&!(t in e)&&"string"==typeof t))return;if(eD.get(t))return eD.get(t);let i=t.replace(/FromIndex$/,""),n=t!==i,s=ek.includes(i);if(!(i in(n?IDBIndex:IDBObjectStore).prototype)||!(s||eT.includes(i)))return;let r=async function(e,...t){let r=this.transaction(e,s?"readwrite":"readonly"),o=r.store;return n&&(o=o.index(t.shift())),(await Promise.all([o[i](...t),s&&r.done]))[0]};return eD.set(t,r),r}eC=(e=>({...e,get:(t,i,n)=>eO(t,i)||e.get(t,i,n),has:(t,i)=>!!eO(t,i)||e.has(t,i)}))(eC);class eB extends en{constructor(e,t){super(),this._dbName=e,this._keyPath=t,this._qosDB=void 0,this._init()}openDB(){return o(this,void 0,void 0,function*(){yield this._init()})}_init(){return o(this,void 0,void 0,function*(){let e=this._dbName,t=this._keyPath;return new Promise(i=>{this._qosDB?i(this):((function(e,t,{blocked:i,upgrade:n,blocking:s,terminated:r}={}){let o=indexedDB.open(e,1),a=eS(o);return n&&o.addEventListener("upgradeneeded",e=>{n(eS(o.result),e.oldVersion,e.newVersion,eS(o.transaction))}),i&&o.addEventListener("blocked",()=>i()),a.then(e=>{r&&e.addEventListener("close",()=>r()),s&&e.addEventListener("versionchange",()=>s())}).catch(()=>{}),a})(`frontier_${e}`,1,{upgrade(i){i.createObjectStore(e,{keyPath:t})}}).then(e=>{this._qosDB=e,this.emit("ready")}),this.on("ready",()=>{i(this),this.off()}))})})}get(e){var t;return o(this,void 0,void 0,function*(){return null===(t=this._qosDB)||void 0===t?void 0:t.get(this._dbName,e)})}set(e,t){var i;return o(this,void 0,void 0,function*(){return null===(i=this._qosDB)||void 0===i?void 0:i.put(this._dbName,e)})}del(e){var t;return o(this,void 0,void 0,function*(){return null===(t=this._qosDB)||void 0===t?void 0:t.delete(this._dbName,e)})}clear(){var e;return o(this,void 0,void 0,function*(){return null===(e=this._qosDB)||void 0===e?void 0:e.clear(this._dbName)})}keys(){var e;return o(this,void 0,void 0,function*(){return null===(e=this._qosDB)||void 0===e?void 0:e.getAllKeys(this._dbName)})}getAll(){var e;return o(this,void 0,void 0,function*(){return null===(e=this._qosDB)||void 0===e?void 0:e.getAll(this._dbName)})}closeDB(){var e;return o(this,void 0,void 0,function*(){null===(e=this._qosDB)||void 0===e||e.close(),this._qosDB=void 0})}get isReady(){return!!this._qosDB}}class eL{constructor(e,t){this._DBName=e,this._pathKey=t,this._qosDB=localStorage}openDB(){return o(this,void 0,void 0,function*(){})}get _prefix(){return`frontier_${this._DBName}`}get(e){return o(this,void 0,void 0,function*(){return JSON.parse(this._qosDB.getItem(this._prefix)||"{}")[e]})}set(e,t){return o(this,void 0,void 0,function*(){let i=JSON.parse(this._qosDB.getItem(this._prefix)||"{}");return i[t||e[this._pathKey]]=e,this._qosDB.setItem(this._prefix,JSON.stringify(i)),t||e[this._pathKey]})}del(e){return o(this,void 0,void 0,function*(){let t=JSON.parse(this._qosDB.getItem(this._prefix)||"{}");return t[e]=void 0,this._qosDB.setItem(this._prefix,JSON.stringify(t))})}clear(){return o(this,void 0,void 0,function*(){return this._qosDB.clear()})}keys(){return o(this,void 0,void 0,function*(){return Object.keys(JSON.parse(this._qosDB.getItem(this._prefix)||"{}"))})}getAll(){return o(this,void 0,void 0,function*(){return Object.values(JSON.parse(this._qosDB.getItem(this._prefix)||"{}"))})}closeDB(){return Promise.resolve()}get isReady(){return!!this._qosDB}}class eN{constructor(e,t){this._DBName=e,this._pathKey=t,this._qosDB=Y?tt:ee?wx:null}openDB(){return o(this,void 0,void 0,function*(){})}get _prefix(){return`frontier_${this._DBName}`}get(e){return o(this,void 0,void 0,function*(){return JSON.parse(this._qosDB.getStorageSync(this._prefix)||"{}")[e]})}set(e,t){return o(this,void 0,void 0,function*(){let i=JSON.parse(this._qosDB.getStorageSync(this._prefix)||"{}");return i[t||e[this._pathKey]]=e,this._qosDB.setStorageSync(this._prefix,JSON.stringify(i)),t||e[this._pathKey]})}del(e){return o(this,void 0,void 0,function*(){let t=JSON.parse(this._qosDB.getStorageSync(this._prefix)||"{}");return t[e]=void 0,this._qosDB.setStorageSync(this._prefix,JSON.stringify(t))})}clear(){return o(this,void 0,void 0,function*(){return this._qosDB.clearStorageSync()})}keys(){return o(this,void 0,void 0,function*(){return Object.keys(JSON.parse(this._qosDB.getStorageInfoSync(this._prefix)||"{}"))})}getAll(){return o(this,void 0,void 0,function*(){return Object.values(JSON.parse(this._qosDB.getStorageInfoSync(this._prefix)||"{}"))})}closeDB(){return Promise.resolve()}get isReady(){return!!this._qosDB}}function eM(e,t){if(Y||Y)return new eN(e,t);if(z||et)return new eB(e,t);if(z||et)return new eL(e,t);throw Error("init QoSDB failed")}class eR{constructor(){this._intervalTimeoutId=null,this._interval=36e5,this._qosDB=eM("qos","message_id")}_intervalFlush(){return o(this,void 0,void 0,function*(){clearInterval(this._intervalTimeoutId),this._intervalTimeoutId=setInterval(()=>{this.flushExpired()},this._interval)})}openDB(){return o(this,void 0,void 0,function*(){yield this._qosDB.openDB().then(()=>{this._intervalFlush()})})}flushExpired(){var e;return o(this,void 0,void 0,function*(){((yield null===(e=this._qosDB)||void 0===e?void 0:e.getAll())||[]).filter(({timestamp:e})=>e<Date.now()).forEach(e=>{var t;null===(t=this._qosDB)||void 0===t||t.del(e.message_id)})})}del(e){var t;return o(this,void 0,void 0,function*(){return null===(t=this._qosDB)||void 0===t?void 0:t.del(e)})}set(e,t){var i;return o(this,void 0,void 0,function*(){return null===(i=this._qosDB)||void 0===i?void 0:i.set({message_id:e,timestamp:t})})}get(e){var t;return o(this,void 0,void 0,function*(){return null===(t=this._qosDB)||void 0===t?void 0:t.get(e)})}closeDB(){var e;return o(this,void 0,void 0,function*(){clearInterval(this._intervalTimeoutId),yield null===(e=this._qosDB)||void 0===e?void 0:e.closeDB()})}get isReady(){var e;return null===(e=this._qosDB)||void 0===e?void 0:e.isReady}}function ex(e,t){var i,n,s,r,a;return o(this,void 0,void 0,function*(){let o=eu(e.message.headers,"code","-1"),h=eu(e.message.headers,"is_ack","1"),l=e_(e.message.headers,"x_frontier_msgid"),c=Number(e_(e.message.headers,"x_frontier_ttl"))||0,d=eu(e.message.headers,"x_frontier_qos","2"),u=eu(e.message.headers,"x_frontier_qos_ack","1"),_=eu(e.message.headers,"x-msg-qos","2"),f=e_(e.message.headers,"x-msg-cursor_name"),g=Number(e_(e.message.headers,"x-msg-cursor_value"));if(d&&u||_&&!(null===(i=this._cursorManager)||void 0===i?void 0:i.isReady))return t();if(d&&!this._QoSManager&&(this._QoSManager=new eR),d&&this._QoSManager&&!this._QoSManager.isReady&&(yield this._QoSManager.openDB()),e.message.service>0&&h&&!o||e.message.service>0){if(l&&d)return!(yield null===(n=this._QoSManager)||void 0===n?void 0:n.get(l))&&(this._dispatchMessageEvent(e),yield null===(s=this._QoSManager)||void 0===s?void 0:s.set(l,Date.now()+c)),t();if(_&&(null===(r=this._cursorManager)||void 0===r?void 0:r.isReady)){let i=null!==(a=yield this._cursorManager.get(f))&&void 0!==a?a:-1;if(i<g)this._dispatchMessageEvent(e),this._cursorManager.set(f,g,e.message.service);else throw Error(`recevied message cursor ${g} larger than local cursor ${i}`);return t()}return this._dispatchMessageEvent(e),t()}})}function eA(e,t){var i,n;return o(this,void 0,void 0,function*(){let s=eu(e.message.headers,"x_frontier_qos","2"),r=eu(e.message.headers,"x_frontier_is_ack","1"),o=null===(i=e_(e.message.headers,"x_frontier_ack_msgid"))||void 0===i?void 0:i.split(",");if(!s)return t();if(!this._QoSManager&&(this._QoSManager=new eR),this._QoSManager&&!this._QoSManager.isReady&&(yield this._QoSManager.openDB()),r&&o&&o.length)for(let e of o)yield null===(n=this._QoSManager)||void 0===n?void 0:n.del(e);t()})}function eq(e,t){return e.readUInt8?{value:e.readUInt8(t),offset:t+1}:{value:255&e[t],offset:t+1}}function eP(e,t,i){return t.writeUint8?t.writeUint8(e,i):t[i]=255&e,i+1}let e$=void 0!==r?r.allocUnsafe:function(e,t,i){let n=8192,s=n>>>1,r=null,o=n;return function(i){if(i<1||i>s)return e(i);o+i>n&&(r=e(n),o=0);let a=t.call(r,o,o+=i);return 7&o&&(o=(7|o)+1),a}}(function(e){return new Uint8Array(e)},Uint8Array.prototype.subarray);function eW(e,t,i){let[n,s]=function(e){let t=0,i={};for(let n=0;n<e.length;n++)i[e[n].cursor_name]=eo(e[n].cursor_name),t+=14+i[e[n].cursor_name];return[t,i]}(e),r=e$(n),o=0;return e.forEach(e=>{o=eP(0,r,o),o=function(e,t,i){if(i>4294967295)throw Error("integer too large");let n=3;for(;n>=0;)eP(255&i,e,t+n),i>>>=8,n--;return t+4}(r,o,e.service||0),o=eP(s[e.cursor_name],r,o),o=function(e,t,i){if(!e)return i;if(e.length<40)return eh(e,t,i)+i;if(t.utf8Write)return t.utf8Write(e,i)+i;if(t.write)return t.write(e,i)+i;else return eh(e,t,i)+i}(e.cursor_name,r,o),o=function(e,t,i){let n=e.low,s=e.high;return t[i]=s>>>24,t[i+1]=s>>>16&255,t[i+2]=s>>>8&255,t[i+3]=255&s,t[i+4]=n>>>24,t[i+5]=n>>>16&255,t[i+6]=n>>>8&255,t[i+7]=255&n,i+=8}(M.fromNumber(e.cursor||t),r,o)}),{frameType:32,headers:[{key:"cursor_file_name",value:i}],payload:r}}class ej{constructor(e,t,i){this._cursorNameSpace=e,this._cursorFileName=t,this._messageStrategy=i,this._qosDB=eM(this._cursorNameSpace,"cursor_name")}openDB(){return o(this,void 0,void 0,function*(){yield this._qosDB.openDB()})}getCursors(){return o(this,void 0,void 0,function*(){if(!this._qosDB.isReady)return;let e=this._messageStrategy,t=yield this._qosDB.getAll();switch(e){case"ALL":return t&&t.length?eW(t,0,this._cursorFileName):void 0;case"INSTANT":return;case"CONTINUE":return t&&t.length?eW(t,0,this._cursorFileName):{frameType:32,headers:[{key:"cursor_file_name",value:"FILE_NOT_EXIST"}],payload:void 0}}})}set(e,t,i){return o(this,void 0,void 0,function*(){return this._qosDB.set({cursor_name:e,cursor:t,service:i})})}setCursors(e){return o(this,void 0,void 0,function*(){for(let t of function(e){let t=0,i=[];for(;t<e.byteLength;){let{offset:n}=eq(e,t),s={cursor_name:"",cursor:0,service:0},{value:r,offset:o}=function(e,t){let i=0,n=t,s=t+4;for(;n<s;){let{value:t,offset:s}=eq(e,n);n=s,i=(i<<8>>>0)+t}return{value:i,offset:s}}(e,t=n);s.service=r;let{value:a,offset:h}=eq(e,t=o);t=h,s.cursor_name=ea(e,t,t+a);let{value:l,offset:c}=function(e,t){let i=new M(e[t+4]<<24|e[t+5]<<16|e[t+6]<<8|e[t+7],e[t+0]<<24|e[t+1]<<16|e[t+2]<<8|e[t+3],!0);return{value:i,offset:(t+=8)+8}}(e,t+=a);s.cursor=l.toNumber(),t=c,i.push(s)}return i}(e))yield this._qosDB.set(t)})}get(e){var t;return o(this,void 0,void 0,function*(){return null===(t=yield this._qosDB.get(e))||void 0===t?void 0:t.cursor})}closeDB(){return o(this,void 0,void 0,function*(){yield this._qosDB.closeDB()})}get isReady(){return this._qosDB.isReady}}function eF(e,t){return o(this,void 0,void 0,function*(){let i=16===e.message.frameType,n=32===e.message.frameType;if(!i&&!n)return t();let s=e_(e.message.headers,"cursor_file_name"),{aID:r,fpID:o,messageStrategy:a}=this._options;if(!s)return t();if(!this._cursorManager&&(this._cursorManager=new ej(`${o}_${r}_${s}`,s,a)),!this._cursorManager.isReady&&(yield this._cursorManager.openDB()),i){let e=yield this._cursorManager.getCursors(),t=c({frameType:null==e?void 0:e.frameType,SeqID:M.fromNumber(this._seqId++),LogID:M.fromNumber(this._options.logIDGenerator()),service:9e3,method:5,headers:null==e?void 0:e.headers,payload:null==e?void 0:e.payload});this._ws.send(t)}if(n){let t=e.message.payload;t&&this._cursorManager.setCursors(t)}})}let eU=function(e,t){return o(this,void 0,void 0,function*(){this._isInit=!1,clearTimeout(this._connectionTimeoutId),t()})},eQ=function(e,t){var i;return o(this,void 0,void 0,function*(){let e=null===(i=this._endpointManager)||void 0===i?void 0:i.getCurrentEndpoint();this._debug(`open ${e}`),t()})},eJ=function(e,t){var i,n;return o(this,void 0,void 0,function*(){if(!this._ws||this._ws.readyState!==this.OPEN)return t();let{pingInterval:s}=this._options;null===(i=this._endpointManager)||void 0===i||i.resetEndpointConfig();for(let e=0;e<this._messageQueue.length;e++){let t=this._messageQueue[e];if(this._ws.readyState===this.OPEN&&null!==t)this._ws&&this._ws.send(t),this._messageQueue[e]=null;else break}this._messageQueue=this._messageQueue.filter(e=>!!e),this._pingPongTimeoutId=setTimeout(()=>this._ping(),s),this._dispatchOpenEvent(e),this._isBrowser&&this._ws&&(this._ws.binaryType=this._binaryType);let r=null===(n=this._endpointManager)||void 0===n?void 0:n.getCurrentEndpoint();this._debug(`open ${r} success`),t()})};e.CustomCloseEvent=F,e.CustomErrorEvent=j,e.Event=$,e.FWS=class t extends en{constructor(t){super(),this._miniNavigatorOnline=!0,this._isBrowser=z,this._isNode=ei,this._isMiniTT=Y,this._isMiniWX=ee,this._isWorker=et,this._messageQueue=[],this._endpointManager=null,this._readyClosed=!1,this._binaryType="arraybuffer",this._connectLock=!1,this._connectionTimeoutId=null,this._reconnectTimeoutId=null,this._pingPongTimeoutId=null,this._seqId=0,this._isInit=!1,this._url="",this._QoSManager=null,this._cursorManager=null,this._pingLossCounter=null,this._protocols="pbbp2",this.CLOSED=3,this.CONNECTING=0,this.OPEN=1,this.CLOSING=2,this._onOpen=t=>{try{er(this,t,[eU,eJ,eQ])}catch(i){let t=G("error",{message:i.message,code:e.ErrorCode.OPEN_ERROR,error:i});this._dispatchErrorEvent(t)}},this._onMessage=t=>o(this,void 0,void 0,function*(){let{pingInterval:i,pingFrequency:n}=this._options;if(("hi"===t.data&&"always"===n||"auto"===n)&&(this._clearPingTimer(),this.emit("ping_once_success","success"),this._pingPongTimeoutId=setTimeout(this._ping.bind(this),i)),"hi"!==t.data)try{er(this,t,[ep,ef,eA,eF,ex,eg])}catch(i){let t=G("error",{message:i.message,code:e.ErrorCode.MESSAGE_ERROR,error:i});this._dispatchErrorEvent(t)}}),this._onError=t=>{var i,n;let s=null===(i=this._endpointManager)||void 0===i?void 0:i.checkReachMaxTries(),r=null===(n=this._endpointManager)||void 0===n?void 0:n.getCurrentEndpoint();if(s&&!t.message){let i=`connect ${r} fail, max retries reached`;this._dispatchErrorEvent(G("error",{message:i,code:e.ErrorCode.MAX_RETRIES_ERROR,error:t}));return}this._ws&&this._ws.readyState===this.OPEN&&this._disconnect(),this._dispatchErrorEvent(G("error",{message:t.message,code:e.ErrorCode.NATIVE_ERROR,error:t}))},this._onClose=t=>o(this,void 0,void 0,function*(){var i,n,s,r,a,h,l,c,d,u,_,f;this._clearTimer(),this._clearPingTimer(),this._removeWsListeners(),this._ws=null,this._connectLock=!1;let g=null===(i=this._endpointManager)||void 0===i?void 0:i.checkReachMaxTries();if(!g&&this._navigatorOnline()&&!this._readyClosed){let e=null===(n=this._endpointManager)||void 0===n?void 0:n.getCurrentEndpoint(),i=this._options.reconnectInterceptor(t.code,t.reason);this._dispatchCloseEvent(H("close",{code:1006,reason:t.reason||`connecting failed, unknown reason, hostname: ${e}`,willReconnect:i})),i&&this._connect();return}if(1e3!==t.code&&this._readyClosed){this._dispatchCloseEvent(H("close",{code:1e3,reason:"bye"})),null===(s=this._endpointManager)||void 0===s||s.resetEndpointConfig(),null===(r=this._pingLossCounter)||void 0===r||r.resetCounter();return}if(1e3!==t.code&&g){let i=null===(a=this._endpointManager)||void 0===a?void 0:a.getCurrentEndpoint(),n=t.reason;!n&&(n=yield function(e){return o(this,void 0,void 0,function*(){return new Promise(t=>{if(!z)return t("unknown reason");try{let i=document.createElement("script");window.frontierJSONP=e=>{document.body.removeChild(i),window.frontierJSONP=void 0,t(e&&e.msg||"unknown reason")},i.type="text/javascript",i.src=e.replace(/^ws/,"http")+"&jscallback=frontierJSONP";try{document.body.appendChild(i)}catch(e){document.body.removeChild(i)}}catch(e){window.frontierJSONP=void 0,t("unknown reason")}})})}(this._url)),n=`connecting failed, ${n}, hostname: ${i}, max retries reached`,this._dispatchCloseEvent(H("close",{code:t.code,reason:n}));let s=`connect ${i} fail, max retries reached`;this._dispatchErrorEvent(G("error",{message:s,code:e.ErrorCode.MAX_RETRIES_ERROR})),null===(h=this._endpointManager)||void 0===h||h.resetEndpointConfig(),null===(l=this._pingLossCounter)||void 0===l||l.resetCounter();return}if(1e3!==t.code&&!t.reason){let e=null===(c=this._endpointManager)||void 0===c?void 0:c.getCurrentEndpoint();this._dispatchCloseEvent(H("close",{code:t.code,reason:`connecting failed, unknown reason, hostname: ${e}`})),null===(d=this._endpointManager)||void 0===d||d.resetEndpointConfig(),null===(u=this._pingLossCounter)||void 0===u||u.resetCounter();return}this._dispatchCloseEvent(t),null===(_=this._endpointManager)||void 0===_||_.resetEndpointConfig(),null===(f=this._pingLossCounter)||void 0===f||f.resetCounter()}),this.onclose=null,this.onerror=null,this.onmessage=null,this.onopen=null,this.onStartReconnect=null,this.onReceiveAck=null,this.onStopImmediatelyReconnect=null,this._handleOnLine=this._handleOnLine.bind(this),this._handleOffLine=this._handleOffLine.bind(this),this._handlePageHide=this._handlePageHide.bind(this),this._handlePageShow=this._handlePageShow.bind(this),this._options={url:"",automaticOpen:!0,initReconnectInterval:1e3,maxReconnectInterval:1e4,reconnectIntervalGrowFactor:2,timeoutInterval:5e3,maxRetries:5,debug:!1,maxMessageQueueLength:1/0,service:0,logIDGenerator:h,headers:void 0,payloadEncoding:"",payloadType:"",fpID:"",deviceID:"",accessKey:"",ttwID:"",bddID:"",aID:"",disableAutoReconnect:!1,customParams:{},pingInterval:15e3,pingTimeoutInterval:4e3,pingFrequency:"auto",pingLossCount:2,enableTransformTextPayload:!1,logIDNewConfig:{enableAutoGenerateLogIDNew:!1,userIp:""},miniProgramParams:{customHttpHeader:{}},enableAutoAck:!1,reconnectInterceptor:()=>!0,enableQoS:!1,QoSLevel:2,messageStrategy:"CONTINUE",env:{xTTEnv:"",xUseEnv:""},listenNetworkChanged:!0};let{url:i,ws:n}=t,s=Array.isArray(i)?i:"string"==typeof i?[i]:[];if(!s||0===s.length)throw Error("please provide valid url");if(!(n||ee&&wx.connectSocket||Y&&tt.connectSocket||(z||et)&&"undefined"!=typeof WebSocket&&WebSocket))throw Error("please provide ws params, WebSocket constructor is undefined");Object.assign(this._options,t),this._endpointManager=new Z(s,this._options.maxRetries),this._pingLossCounter=new ed(this._options.pingLossCount),this._options.automaticOpen&&(this._isInit=!0,this._connect()),this._options.listenNetworkChanged&&(this._isMiniTT||this._isMiniWX?this._onPageNetWorkChange():this._isBrowser&&this._initGlobalEventListener())}_handleOnLine(){if(!this._options.disableAutoReconnect&&!this._readyClosed)this._handleReconnect()}_handleOffLine(){this._destroyWebSocket();let e=X("reconnect",{message:"stop immediately reconnect"});this.onStopImmediatelyReconnect&&this.onStopImmediatelyReconnect(e)}_initGlobalEventListener(){this._isBrowser&&window.addEventListener("online",this._handleOnLine),this._isBrowser&&window.addEventListener("offline",this._handleOffLine),this._isBrowser&&window.addEventListener("pagehide",this._handlePageHide),this._isBrowser&&window.addEventListener("pageshow",this._handlePageShow)}_dropGlobalEventListener(){this._isBrowser&&window.removeEventListener("online",this._handleOnLine),this._isBrowser&&window.removeEventListener("offline",this._handleOffLine),this._isBrowser&&window.removeEventListener("pagehide",this._handlePageHide),this._isBrowser&&window.removeEventListener("pageshow",this._handlePageShow)}_handlePageHide(e){!e.persisted&&(this._isBrowser&&window.removeEventListener("pagehide",this._handlePageHide),this._isBrowser&&window.removeEventListener("pageshow",this._handlePageShow),this.close()),this._isBrowser&&window.removeEventListener("online",this._handleOnLine),this._isBrowser&&window.removeEventListener("offline",this._handleOffLine)}_handlePageShow(e){e.persisted&&(this._navigatorOnline()&&(!this._ws||this._ws.readyState!==this.OPEN||this._ws.readyState!==this.CONNECTING)&&this._handleOnLine(),this._isBrowser&&window.addEventListener("online",this._handleOnLine),this._isBrowser&&window.addEventListener("offline",this._handleOffLine))}_generateUrl(e){return o(this,void 0,void 0,function*(){let t,i,n;let{fpID:s,deviceID:r,bddID:o,ttwID:a,accessKey:h,aID:l,customParams:c={},enableAutoAck:d,enableQoS:u,QoSLevel:_,env:f}=this._options;this._isBrowser||this._isMiniWX||this._isMiniTT?(t=location&&"https:"==location.protocol?"wss://":"ws://",i=e.replace(/((^ws)|(^http))((?:[s]*:\/\/))/,""),n=/^wss(.*:\/\/)/.test(e)?e:`${t}${i}`):(t="wss://",i=e.replace(/(^http)((?:[s]*:\/\/))/,""),n=/(^ws)((?:[s]*:\/\/))/.test(i)?i:`${t}${i}`);let g=o?"bd_did":a?"ttwid":"device_id",p=o||a||r;if(!p||!g)throw Error("please provide bddID, deviceID or ttwID");let v="function"==typeof c?yield c():c,m=Object.assign(Object.assign({device_platform:"web",version_code:"fws_1.0.0",access_key:h,fpid:s,aid:l,[g]:p,xsack:d?1:0,xaack:d?1:0,xsqos:u?1:0,qos_level:u?_:void 0,qos_sdk_version:2},f?ec(f.xUseEnv,f.xTTEnv):{}),v),y=Object.keys(m).reduce((e,t)=>void 0!==m[t]?`${e}${e?"&":"?"}${t}=${m[t]}`:e,"");return`${n}/ws/v2${y}`})}_connect(){var t,i,n,s,r,a,h;return o(this,void 0,void 0,function*(){if(!this._connectLock&&!this._readyClosed){this._connectLock=!0;try{var o,l;let c=null===(t=this._endpointManager)||void 0===t?void 0:t.checkCurrentEndpointReachedMaxRetries(),{timeoutInterval:d}=this._options;if(c){let t=null===(i=this._endpointManager)||void 0===i?void 0:i.getCurrentEndpoint(),r=null===(n=this._endpointManager)||void 0===n?void 0:n.replaceBackupEndpointAndUpdateCount(),o=null===(s=this._endpointManager)||void 0===s?void 0:s.getCurrentEndpointTriesCount();if(r){let i=`connect ${t} timeout, max retries reached, will use backup endpoint ${r} to retry`,n=G("error",{message:i,code:e.ErrorCode.MAX_RETRIES_ERROR});this._debug(i),this._dispatchErrorEvent(n),this._url=yield this._generateUrl(r),this._debug(`connect ${r} ${o} times`),this._removeWsListeners()}else{let i=`connect ${t} timeout, max retries reached`;this._debug(i),this._dispatchErrorEvent(G("error",{message:i,code:e.ErrorCode.MAX_RETRIES_ERROR}));return}}else{let e=null===(r=this._endpointManager)||void 0===r?void 0:r.getCurrentEndpointAndUpdateCount(),t=null===(a=this._endpointManager)||void 0===a?void 0:a.getCurrentEndpointTriesCount();this._url=yield this._generateUrl(e||""),this._debug(`connect ${e} ${t} times`),this._removeWsListeners()}if(this._isInit)this._isInit=!1;else{let e=X("reconnect",{message:"start"});this.onStartReconnect&&this.onStartReconnect(e)}let u=(null===(h=this._endpointManager)||void 0===h?void 0:h.getCurrentEndpointTriesCount())||0;u>1&&(yield this._wait(u-1)),this._debug(`connecting url: ${this._url} protocols: ${this._protocols}`),this._ws=(o={url:this._url,protocols:[this._protocols],headers:this._options.miniProgramParams.customHttpHeader},(l=this._options.ws)?new l(o.url,o.protocol):ee||Y?new es(o.url,o.protocol,o.headers):(z||et)&&"undefined"!=typeof WebSocket&&WebSocket?new WebSocket(o.url,o.protocols):void 0),(this._isBrowser||this._isWorker)&&this._ws&&(this._ws.binaryType=this._binaryType),this._addWsListeners(),this._connectionTimeoutId=setTimeout(this._onTimeout.bind(this),d)}catch(e){throw this._connectLock=!1,e}}})}_clearTimer(){clearTimeout(this._connectionTimeoutId),this._connectionTimeoutId=null}_clearPingTimer(){clearTimeout(this._pingPongTimeoutId),clearTimeout(this._reconnectTimeoutId),this._pingPongTimeoutId=null,this._reconnectTimeoutId=null}_debug(...e){this._options.debug}_getIntervalValue(e){let{initReconnectInterval:t,maxReconnectInterval:i,reconnectIntervalGrowFactor:n}=this._options,s=t*Math.pow(n,e-1);return s>i?i:s}_ping(){if(this._ws&&this._ws.readyState===this.CONNECTING){this._clearPingTimer(),this._pingPongTimeoutId=setTimeout(this._ping.bind(this),this._options.pingInterval);return}if(!this._ws||this._ws.readyState!==this.OPEN){this._handleReconnect();return}this._ws&&this._ws.send("hi"),this._reconnectTimeoutId=setTimeout(this._handleReconnectTimeout.bind(this),this._options.pingTimeoutInterval)}_handleReconnectTimeout(){var e,t;null===(e=this._pingLossCounter)||void 0===e||e.addCount(),this.emit("ping_once_timeout","timeout"),(null===(t=this._pingLossCounter)||void 0===t?void 0:t.checkReachMaxCount())?this._handleReconnect():this._ping()}_navigatorOnline(){return this._isMiniTT||this._isMiniWX?this._miniNavigatorOnline:!this._isBrowser&&!this._isWorker||!this._options.listenNetworkChanged||navigator.onLine}_handleReconnect(){var e,t;if(!!this._navigatorOnline()&&!this._readyClosed)null===(e=this._endpointManager)||void 0===e||e.resetEndpointConfig(),null===(t=this._pingLossCounter)||void 0===t||t.resetCounter(),this._ws?this._disconnect(1001,"going away, try reconnecting server",!0):this._connect()}_onPageNetWorkChange(){this._isMiniTT?tt.onNetworkStatusChange(({isConnected:e})=>{this._miniNavigatorOnline=e,e?this._handleOnLine():this._handleOffLine()}):this._isMiniWX&&wx.onNetworkStatusChange(({isConnected:e})=>{this._miniNavigatorOnline=e,e?this._handleOnLine():this._handleOffLine()})}_wait(e){return new Promise(t=>{setTimeout(t,this._getIntervalValue(e))})}_disconnect(e=1e3,t="",i=!1){if(!!this._ws)this._destroyWebSocket(e,t,i)}_onTimeout(){var e;let t=null===(e=this._endpointManager)||void 0===e?void 0:e.getCurrentEndpoint();this._debug(`connect ${t} timeout`),this._disconnect(1001,"timeout, try reconnecting",!0)}_sendAck(e){let t=c(e);this._ws&&this._ws.readyState===this.OPEN&&(this._ws&&this._ws.send(t),this._debug("send_ack",e))}_removeWsListeners(){if(!!this._ws)this._ws.removeEventListener("open",this._onOpen),this._ws.removeEventListener("close",this._onClose),this._ws.removeEventListener("message",this._onMessage),this._ws.removeEventListener("error",this._onError)}_addWsListeners(){if(!!this._ws)this._ws.addEventListener("open",this._onOpen),this._ws.addEventListener("close",this._onClose),this._ws.addEventListener("message",this._onMessage),this._ws.addEventListener("error",this._onError)}_wsInstanceClose(e=1e3,t=""){try{this._ws&&this._ws.close(e,t)}catch(e){}}_destroyWebSocket(e=1e3,t="",i=!1){var n,s,r,o;if(this._clearPingTimer(),this._clearTimer(),this._removeWsListeners(),this._wsInstanceClose(1e3,t),this._connectLock=!1,i&&this._navigatorOnline()&&!this._readyClosed){if(null===(n=this._endpointManager)||void 0===n?void 0:n.checkReachMaxTries()){let e=null===(s=this._endpointManager)||void 0===s?void 0:s.getCurrentEndpoint();this._dispatchCloseEvent(H("close",{code:1006,reason:`connect ${e} timeout, max retries reached`,wasClean:!0}))}else{let i=this._options.reconnectInterceptor(e,t);this._dispatchCloseEvent(H("close",{code:e,reason:t,wasClean:!0,willReconnect:i})),i&&this._connect()}return}this._navigatorOnline()||this._readyClosed?this._dispatchCloseEvent(H("close",{code:e,reason:"bye"})):this._dispatchCloseEvent(H("close",{code:1006,reason:"going away, network offline"})),this._ws=null,null===(r=this._endpointManager)||void 0===r||r.resetEndpointConfig(),null===(o=this._pingLossCounter)||void 0===o||o.resetCounter()}_dispatchOpenEvent(e){this.emit("open",e),this.onopen&&this.onopen(e)}_dispatchMessageEvent(e){this.emit("message",e),this.onmessage&&this.onmessage(e)}_dispatchAckMessageEvent(e){this.emit("ack",e),this.onReceiveAck&&this.onReceiveAck(e)}_dispatchErrorEvent(e){this.emit("error",e),this.onerror&&this.onerror(e)}_dispatchCloseEvent(e){this.emit("close",e),this.onclose&&this.onclose(e)}get binaryType(){return this._ws?this._ws.binaryType:this._binaryType}set binaryType(e){this._binaryType=e,this._ws&&(this._ws.binaryType=e)}get retryCount(){var e;return(null===(e=this._endpointManager)||void 0===e?void 0:e.getCurrentEndpointTriesCount())||0}get bufferedAmount(){return this._messageQueue.reduce((e,t)=>e+=t&&t.byteLength||0,0)+(this._ws?this._ws.bufferedAmount:0)}get extensions(){return this._ws?this._ws.extensions:""}get protocol(){return this._ws?this._ws.protocol:""}get readyState(){return this._ws?this._ws.readyState:this._options.automaticOpen?this.CONNECTING:this.CLOSED}get url(){return this._ws?this._ws.url:this._url}close(e=1e3,t){var i;if(this._readyClosed=!0,this._clearTimer(),this._clearPingTimer(),this._dropGlobalEventListener(),null===(i=this._QoSManager)||void 0===i||i.closeDB(),!this._ws){this._debug("close, ws instance not initialized");return}if(this._ws.readyState===this.CLOSED||this._ws.readyState===this.CLOSING){this._debug("close, ws already closed");return}this._destroyWebSocket(e,t)}send(e,t){return o(this,void 0,void 0,function*(){if(null==e)throw Error("please provide a valid data, data must be a string or an arraybuffer");"number"==typeof e&&(e=JSON.stringify(e)),"string"!=typeof e&&!(e instanceof ArrayBuffer)&&!(e.buffer&&e.buffer instanceof ArrayBuffer)&&(e=JSON.stringify(e));let i=yield el(e),n=function(e){try{if("string"!=typeof e&&(e instanceof ArrayBuffer||e.buffer&&e.buffer instanceof ArrayBuffer))return"";if("string"==typeof e)return JSON.parse(e),"application/json";else return""}catch(t){if("string"==typeof e)return"text/plain;charset=utf-8";return""}}(e),{method:s=0,service:r=this._options.service,logID:o=this._options.logIDGenerator(),headers:h=this._options.headers,payloadEncoding:d=this._options.payloadEncoding,payloadType:u=this._options.payloadType,logIDNew:_=this._options.logIDNewConfig.enableAutoGenerateLogIDNew?function(e=""){let t=`${Date.now()}`,i=a||(a=function(e){let t=/(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}/.test(e),i=/(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))/.test(e);return t?function(e){let t=e.split(/\./).map(e=>{var t;return t=e,(Array(8).join("0")+parseInt(t,10).toString(2)).slice(-8)}),i=[];return i[0]=l(t[0]+t[1]),i[1]=l(t[2]+t[3]),["0000","0000","0000","0000","0000","ffff",i[0],i[1]].join("")}(e):i?function(e){let t="",i=[],n=0,s=0,r=!0,o="0000";if(e.indexOf("::")>-1){let a=e.split("::");for(let e=0;e<a.length;e++){let t=a[e];if(t.indexOf(":")>0){let e=t.split(":");r&&(n=e.length),s+=e.length;for(let t=0;t<e.length;t++)if(4!==e[t].length){let n=o.substring(0,4-e[t].length).concat(e[t]);i.push(n)}else i.push(e[t]);r=!1}else{if(4!==t.length){let e=o.substring(0,4-t.length).concat(t);i.push(e)}else i.push(t);r&&(n+=1),s+=1,r=!1}}let h="";for(let e=0;e<8-s;e++)h=h.concat(o);for(let e=0;e<i.length;e++)t=e===n?(t=t.concat(h)).concat(i[e]):t.concat(i[e]);return t}{let i=e.split(":");for(let e=0;e<i.length;e++){let n=i[e];if(4!==i[e].length){let s=o.substring(0,4-i[e].length).concat(n);t=t.concat(s)}else t=t.concat(n)}return t}}(e):"00000000000000000000000000000000"}(e));return"02"+t+i+Math.random().toString(16).slice(-6)}(this._options.logIDNewConfig.userIp):""}=t||{};if(!r)throw Error("please provide a valid service");let f={SeqID:M.fromNumber(this._seqId++),LogID:M.fromNumber(o),service:r,method:s,headers:h,payloadEncoding:d instanceof Object?d.encoding?d.encoding:"":d,payloadType:u instanceof Object?u.type?u.type:n:u||n,payload:i,LogIDNew:_},g=c(f);return this._ws&&this._ws.readyState===this.OPEN?(this._ws&&this._ws.send(g),this._debug("sent",f)):this._messageQueue.length<this._options.maxMessageQueueLength?(this._messageQueue.push(g),this._debug("enqueue",f)):(this._messageQueue.shift(),this._messageQueue.push(g)),{seqID:this._seqId,logID:o,logIDNew:_}})}reconnect(e){var t,i;return o(this,void 0,void 0,function*(){let{url:n}=e||{},s=Array.isArray(n)?n:"string"==typeof n?[n]:[];e&&Object.assign(this._options,e),s&&s.length?this._endpointManager=new Z(s,this._options.maxRetries):null===(t=this._endpointManager)||void 0===t||t.resetEndpointConfig(),null===(i=this._pingLossCounter)||void 0===i||i.resetCounter(this._options.pingLossCount),this._readyClosed=!1,this._ws&&this._ws.readyState!==this.CLOSED?this._disconnect(1e3,"manual reconnecting",!0):(this._isInit=!0,this._connect())})}connect(){var e,t;return o(this,void 0,void 0,function*(){!this._connectLock&&(null===(e=this._endpointManager)||void 0===e||e.resetEndpointConfig(),null===(t=this._pingLossCounter)||void 0===t||t.resetCounter(),this._readyClosed=!1,this._isInit=!0,this._connect())})}addEventListener(e,t){this.on(e,t)}dispatchEvent(e){let{type:t}=e;this.emit(t,e)}removeEventListener(e,t){this.off(e,t)}pingOnce(){return new Promise((e,t)=>{this._clearPingTimer(),this._pingPongTimeoutId=setTimeout(this._ping.bind(this),this._options.pingInterval);let i=()=>{e("success"),this.off("ping_once_success",i),this.off("ping_once_timeout",n)},n=()=>{t("timeout"),this.off("ping_once_success",i),this.off("ping_once_timeout",n)};this.on("ping_once_success",i),this.on("ping_once_timeout",n),this._ping()})}},e.FrontierMessageEvent=Q,e.MessageEvent=U,e.OpenEvent=J,e.ReconnectEvent=W,e.createCloseEvent=H,e.createErrorEvent=G,e.createMessageEvent=K,e.createOpenEvent=V,e.createReconnectEvent=X,e.decodedFrame=k,e.encodeFrame=D,Object.defineProperty(e,"__esModule",{value:!0})}(t)},295707:function(e,t,i){"use strict";i.r(t),i.d(t,{NOTICE_PUSH_EVENT_NAMES:function(){return u},NoticeFrontier:function(){return _}});var n=i(480333),s=i(629686);i(190932),i(808483),i(126159),i(100832),i(825666),i(943281),i(82726),i(490629);var r=i(785005),o=i.n(r),a=i(747688),h=i(263070),l=i(973140);let c={fpID:9,aID:6383,appKey:"e1bd35ec9db7b8d846de66ed140b1ad9",deviceID:"",url:"wss://frontier-im.douyin.com",devicePlatform:"douyin_pc"},d=new l.Z;var u={RECEIVE_PUSH:"NOTICE_RECEIVE_PUSH"};class _{static tryStart(e,t){h.Z.warn("[frontier]登录用户信息",t);let{uid:i=""}=t||{},{frontierInstance:n}=_;return e&&i?!n&&_.init({deviceID:i}):_&&_.destroy(),_.frontierInstance}static init(e){let t=(0,s._)({},c,e);t.accessKey=o()(`${t.fpID+t.appKey+t.deviceID}f8a69f1719916z`),h.Z.warn("[frontier]notice初始化参数",t);let i=new a.FWS(t);return _.frontierInstance=i,i.onopen=()=>h.Z.warn("[frontier]连接建立成功"),i.onmessage=e=>{try{let{data:t=[]}=e,i=(0,a.decodedFrame)(new Uint8Array(t));h.Z.warn("[frontier]decodedData",i),d.emit("NOTICE_RECEIVE_PUSH",i)}catch(e){h.Z.error("[frontier]error",e)}},i.onerror=e=>h.Z.warn("[frontier]error",e),i}static destroy(){var e;d.off(),null===(e=_.frontierInstance)||void 0===e||e.close(),_.frontierInstance=null}static listenEvents(e,t){d.on("NOTICE_RECEIVE_PUSH",i=>{let{payload:n,service:s}=i||{};if(s&&s===e)try{let e=String.fromCharCode(...n),i=JSON.parse(e);h.Z.warn("[frontier]res",i),null==t||t(i)}catch(e){h.Z.error("[frontier]error",e)}})}}(0,n._)(_,"frontierInstance",null)}}]); |