@hehanlin/open-agent-bridge 0.6.3 → 0.6.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/node_modules/@byted/frontier-web-sdk/README.md +11 -0
- package/node_modules/@byted/frontier-web-sdk/lib/fws.esm.js +2438 -0
- package/node_modules/@byted/frontier-web-sdk/lib/fws.js +2535 -0
- package/node_modules/@byted/frontier-web-sdk/lib/fws.umd.js +2699 -0
- package/node_modules/@byted/frontier-web-sdk/lib/fws.umd.min.js +1 -0
- package/node_modules/@byted/frontier-web-sdk/lib/types/db/index.d.ts +5 -0
- package/node_modules/@byted/frontier-web-sdk/lib/types/db/qos-idb.d.ts +22 -0
- package/node_modules/@byted/frontier-web-sdk/lib/types/db/qos-localstorage.d.ts +20 -0
- package/node_modules/@byted/frontier-web-sdk/lib/types/db/qos-ministorage.d.ts +20 -0
- package/node_modules/@byted/frontier-web-sdk/lib/types/fws.d.ts +225 -0
- package/node_modules/@byted/frontier-web-sdk/lib/types/idl/bppb2.d.ts +27 -0
- package/node_modules/@byted/frontier-web-sdk/lib/types/idl/protobuf.d.ts +8 -0
- package/node_modules/@byted/frontier-web-sdk/lib/types/manager/cursor-manager.d.ts +25 -0
- package/node_modules/@byted/frontier-web-sdk/lib/types/manager/endpoint-manager.d.ts +15 -0
- package/node_modules/@byted/frontier-web-sdk/lib/types/manager/qos-manager.d.ts +17 -0
- package/node_modules/@byted/frontier-web-sdk/lib/types/manager/tnc-manager.d.ts +0 -0
- package/node_modules/@byted/frontier-web-sdk/lib/types/process/message/ack-process.d.ts +3 -0
- package/node_modules/@byted/frontier-web-sdk/lib/types/process/message/cursor-helper.d.ts +3 -0
- package/node_modules/@byted/frontier-web-sdk/lib/types/process/message/cursor-process.d.ts +3 -0
- package/node_modules/@byted/frontier-web-sdk/lib/types/process/message/decode-process.d.ts +2 -0
- package/node_modules/@byted/frontier-web-sdk/lib/types/process/message/dispatch-message-process.d.ts +3 -0
- package/node_modules/@byted/frontier-web-sdk/lib/types/process/message/finish-message-process.d.ts +3 -0
- package/node_modules/@byted/frontier-web-sdk/lib/types/process/message/index.d.ts +7 -0
- package/node_modules/@byted/frontier-web-sdk/lib/types/process/message/qos-helper.d.ts +12 -0
- package/node_modules/@byted/frontier-web-sdk/lib/types/process/message/qos-process.d.ts +3 -0
- package/node_modules/@byted/frontier-web-sdk/lib/types/process/open/finish-open-process.d.ts +2 -0
- package/node_modules/@byted/frontier-web-sdk/lib/types/process/open/index.d.ts +3 -0
- package/node_modules/@byted/frontier-web-sdk/lib/types/process/open/open-process.d.ts +2 -0
- package/node_modules/@byted/frontier-web-sdk/lib/types/process/open/open-success-process.d.ts +2 -0
- package/node_modules/@byted/frontier-web-sdk/lib/types/process/process-trigger.d.ts +3 -0
- package/node_modules/@byted/frontier-web-sdk/lib/types/utils/arraybuffer-trans.d.ts +2 -0
- package/node_modules/@byted/frontier-web-sdk/lib/types/utils/buffer.d.ts +115 -0
- package/node_modules/@byted/frontier-web-sdk/lib/types/utils/check-payload-type.d.ts +1 -0
- package/node_modules/@byted/frontier-web-sdk/lib/types/utils/cursor-serialize.d.ts +14 -0
- package/node_modules/@byted/frontier-web-sdk/lib/types/utils/env-params-gen.d.ts +5 -0
- package/node_modules/@byted/frontier-web-sdk/lib/types/utils/env.d.ts +5 -0
- package/node_modules/@byted/frontier-web-sdk/lib/types/utils/event-emitter.d.ts +39 -0
- package/node_modules/@byted/frontier-web-sdk/lib/types/utils/event.d.ts +88 -0
- package/node_modules/@byted/frontier-web-sdk/lib/types/utils/get-socket-error.d.ts +1 -0
- package/node_modules/@byted/frontier-web-sdk/lib/types/utils/header-key.d.ts +2 -0
- package/node_modules/@byted/frontier-web-sdk/lib/types/utils/log-id.d.ts +6 -0
- package/node_modules/@byted/frontier-web-sdk/lib/types/utils/long.d.ts +25 -0
- package/node_modules/@byted/frontier-web-sdk/lib/types/utils/pkg-loss-counter.d.ts +8 -0
- package/node_modules/@byted/frontier-web-sdk/lib/types/utils/pool.d.ts +29 -0
- package/node_modules/@byted/frontier-web-sdk/lib/types/utils/utf8.d.ts +24 -0
- package/node_modules/@byted/frontier-web-sdk/lib/types/utils/websocket.d.ts +2 -0
- package/node_modules/@byted/frontier-web-sdk/lib/types/websocket/mini-websocket.d.ts +20 -0
- package/node_modules/@byted/frontier-web-sdk/package.json +52 -0
- package/node_modules/idb/CHANGELOG.md +87 -0
- package/node_modules/idb/LICENSE +6 -0
- package/node_modules/idb/README.md +497 -0
- package/node_modules/idb/build/async-iterators.cjs +57 -0
- package/node_modules/idb/build/async-iterators.d.ts +1 -0
- package/node_modules/idb/build/async-iterators.js +55 -0
- package/node_modules/idb/build/database-extras.d.ts +1 -0
- package/node_modules/idb/build/entry.d.ts +615 -0
- package/node_modules/idb/build/index.cjs +94 -0
- package/node_modules/idb/build/index.d.ts +2 -0
- package/node_modules/idb/build/index.js +88 -0
- package/node_modules/idb/build/umd-with-async-ittr.js +1 -0
- package/node_modules/idb/build/umd.js +1 -0
- package/node_modules/idb/build/util.d.ts +3 -0
- package/node_modules/idb/build/wrap-idb-value.cjs +191 -0
- package/node_modules/idb/build/wrap-idb-value.d.ts +34 -0
- package/node_modules/idb/build/wrap-idb-value.js +185 -0
- package/node_modules/idb/package.json +59 -0
- package/node_modules/idb/with-async-ittr.cjs +2 -0
- package/node_modules/idb/with-async-ittr.d.ts +1 -0
- package/node_modules/idb/with-async-ittr.js +2 -0
- package/package.json +4 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.fws=t():e.fws=t()}(globalThis,()=>(()=>{"use strict";var e={"../../node_modules/.pnpm/idb@7.0.2/node_modules/idb/build/index.js":function(e,t,s){let i,n,r;s.r(t),s.d(t,{deleteDB:()=>g,wrap:()=>u,openDB:()=>f,unwrap:()=>_});let o=new WeakMap,a=new WeakMap,h=new WeakMap,c=new WeakMap,l=new WeakMap,d={get(e,t,s){if(e instanceof IDBTransaction){if("done"===t)return a.get(e);if("objectStoreNames"===t)return e.objectStoreNames||h.get(e);if("store"===t)return s.objectStoreNames[1]?void 0:s.objectStore(s.objectStoreNames[0])}return u(e[t])},set:(e,t,s)=>(e[t]=s,!0),has:(e,t)=>e instanceof IDBTransaction&&("done"===t||"store"===t)||t in e};function u(e){if(e instanceof IDBRequest){let t;return(t=new Promise((t,s)=>{let i=()=>{e.removeEventListener("success",n),e.removeEventListener("error",r)},n=()=>{t(u(e.result)),i()},r=()=>{s(e.error),i()};e.addEventListener("success",n),e.addEventListener("error",r)})).then(t=>{t instanceof IDBCursor&&o.set(t,e)}).catch(()=>{}),l.set(t,e),t}if(c.has(e))return c.get(e);let t=function(e){if("function"==typeof e)return e!==IDBDatabase.prototype.transaction||"objectStoreNames"in IDBTransaction.prototype?(n||(n=[IDBCursor.prototype.advance,IDBCursor.prototype.continue,IDBCursor.prototype.continuePrimaryKey])).includes(e)?function(...t){return e.apply(_(this),t),u(o.get(this))}:function(...t){return u(e.apply(_(this),t))}:function(t,...s){let i=e.call(_(this),t,...s);return h.set(i,t.sort?t.sort():[t]),u(i)};return e instanceof IDBTransaction&&function(e){if(a.has(e))return;let t=new Promise((t,s)=>{let i=()=>{e.removeEventListener("complete",n),e.removeEventListener("error",r),e.removeEventListener("abort",r)},n=()=>{t(),i()},r=()=>{s(e.error||new DOMException("AbortError","AbortError")),i()};e.addEventListener("complete",n),e.addEventListener("error",r),e.addEventListener("abort",r)});a.set(e,t)}(e),(i||(i=[IDBDatabase,IDBObjectStore,IDBIndex,IDBCursor,IDBTransaction])).some(t=>e instanceof t)?new Proxy(e,d):e}(e);return t!==e&&(c.set(e,t),l.set(t,e)),t}let _=e=>l.get(e);function f(e,t,{blocked:s,upgrade:i,blocking:n,terminated:r}={}){let o=indexedDB.open(e,t),a=u(o);return i&&o.addEventListener("upgradeneeded",e=>{i(u(o.result),e.oldVersion,e.newVersion,u(o.transaction))}),s&&o.addEventListener("blocked",()=>s()),a.then(e=>{r&&e.addEventListener("close",()=>r()),n&&e.addEventListener("versionchange",()=>n())}).catch(()=>{}),a}function g(e,{blocked:t}={}){let s=indexedDB.deleteDatabase(e);return t&&s.addEventListener("blocked",()=>t()),u(s).then(()=>void 0)}let p=["get","getKey","getAll","getAllKeys","count"],m=["put","add","delete","clear"],y=new Map;function w(e,t){if(!(e instanceof IDBDatabase&&!(t in e)&&"string"==typeof t))return;if(y.get(t))return y.get(t);let s=t.replace(/FromIndex$/,""),i=t!==s,n=m.includes(s);if(!(s in(i?IDBIndex:IDBObjectStore).prototype)||!(n||p.includes(s)))return;let r=async function(e,...t){let r=this.transaction(e,n?"readwrite":"readonly"),o=r.store;return i&&(o=o.index(t.shift())),(await Promise.all([o[s](...t),n&&r.done]))[0]};return y.set(t,r),r}d={...r=d,get:(e,t,s)=>w(e,t)||r.get(e,t,s),has:(e,t)=>!!w(e,t)||r.has(e,t)}}},t={};function s(i){var n=t[i];if(void 0!==n)return n.exports;var r=t[i]={exports:{}};return e[i](r,r.exports,s),r.exports}s.d=(e,t)=>{for(var i in t)s.o(t,i)&&!s.o(e,i)&&Object.defineProperty(e,i,{enumerable:!0,get:t[i]})},s.g=(()=>{if("object"==typeof globalThis)return globalThis;try{return this||Function("return this")()}catch(e){if("object"==typeof window)return window}})(),s.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),s.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var i={};return(()=>{let e,t,n;s.r(i),s.d(i,{FWS:()=>eP,CustomErrorEvent:()=>j,createCloseEvent:()=>J,ReconnectEvent:()=>W,createErrorEvent:()=>G,decodedFrame:()=>T,createOpenEvent:()=>X,CustomCloseEvent:()=>$,createReconnectEvent:()=>K,FrontierMessageEvent:()=>Q,encodeFrame:()=>k,createMessageEvent:()=>H,OpenEvent:()=>U,ErrorCode:()=>P,Event:()=>q,MessageEvent:()=>F});let r="";function o(){return 1e4*Date.now()+Math.floor(1e4*Math.random())}function a(e){return("000"+parseInt(e,2).toString(16)).slice(-4)}function h(e){var t;let s,i,n=u();return function(e,t){var s,i,n;let r,o=e.SeqID;void 0!==o&&(b(t,8),S(t,o));let a=e.LogID;void 0!==a&&(b(t,16),S(t,a));let h=e.service;void 0!==h&&(b(t,24),S(t,l(h)));let c=e.method;void 0!==c&&(b(t,32),S(t,l(c)));let _=e.headers;if(void 0!==_)for(let e of _){b(t,42);let i=u();!function(e,t){let s=e.key;void 0!==s&&(b(t,10),y(t,s));let i=e.value;void 0!==i&&(b(t,18),y(t,i))}(e,i),b(t,i.limit),function(e,t){let s=g(e,t.limit),i=e.bytes,n=t.bytes;for(let e=0,r=t.limit;e<r;e++)i[e+s]=n[e]}(t,i),s=i,d.push(s)}let f=e.payloadEncoding;void 0!==f&&(b(t,50),y(t,f));let p=e.payloadType;void 0!==p&&(b(t,58),y(t,p));let m=e.payload;void 0!==m&&(b(t,66),b(t,m.length),r=g(i=t,(n=m).length),i.bytes.set(n,r));let w=e.LogIDNew;void 0!==w&&(b(t,74),y(t,w));let v=e.serverTiming;void 0!==v&&(b(t,82),y(t,v));let E=e.msgID;void 0!==E&&(b(t,90),y(t,E));let C=e.frameType;void 0!==C&&(b(t,96),S(t,l(C)))}(e,n),s=(t=n).bytes,i=t.limit,s.length===i?s:s.subarray(0,i)}function c(e,t){switch(t){case 0:for(;128&w(e););break;case 2:_(e,E(e));break;case 5:_(e,4);break;case 1:_(e,8);break;default:throw Error("Unimplemented type: "+t)}}function l(e){return{low:e|=0,high:e>>31,unsigned:e>=0}}let d=[];function u(){let e=d.pop();return e?(e.offset=e.limit=0,e):{bytes:new Uint8Array(64),offset:0,limit:0}}function _(e,t){if(e.offset+t>e.limit)throw Error("Skip past limit");e.offset+=t}function f(e){return e.offset>=e.limit}function g(e,t){let s=e.bytes,i=e.offset,n=e.limit,r=i+t;if(r>s.length){let t=new Uint8Array(2*r);t.set(s),e.bytes=t}return e.offset=r,r>n&&(e.limit=r),i}function p(e,t){let s=e.offset;if(s+t>e.limit)throw Error("Read past limit");return e.offset+=t,s}function m(e,t){let s=p(e,t),i=String.fromCharCode,n=e.bytes,r="";for(let e=0;e<t;e++){let o,a,h,c,l=n[e+s];(128&l)==0?r+=i(l):(224&l)==192?e+1>=t||(192&(o=n[e+s+1]))!=128||(c=(31&l)<<6|63&o)<128?r+="�":(r+=i(c),e++):(240&l)==224?e+2>=t||(((o=n[e+s+1])|(a=n[e+s+2])<<8)&49344)!=32896||(c=(15&l)<<12|(63&o)<<6|63&a)<2048||c>=55296&&c<=57343?r+="�":(r+=i(c),e+=2):(248&l)==240?e+3>=t?r+="�":(o=n[e+s+1],((o|(a=n[e+s+2])<<8|(h=n[e+s+3])<<16)&0xc0c0c0)!=8421504||(c=(7&l)<<18|(63&o)<<12|(63&a)<<6|63&h)<65536||c>1114111?r+="�":(c-=65536,r+=i((c>>10)+55296,(1023&c)+56320),e+=3)):r+="�"}return r}function y(e,t){let s=t.length,i=0;for(let e=0;e<s;e++){let n=t.charCodeAt(e);n>=55296&&n<=56319&&e+1<s&&(n=(n<<10)+t.charCodeAt(++e)-0x35fdc00),i+=n<128?1:n<2048?2:n<65536?3:4}b(e,i);let n=g(e,i),r=e.bytes;for(let e=0;e<s;e++){let i=t.charCodeAt(e);i>=55296&&i<=56319&&e+1<s&&(i=(i<<10)+t.charCodeAt(++e)-0x35fdc00),i<128?r[n++]=i:(i<2048?r[n++]=i>>6&31|192:(i<65536?r[n++]=i>>12&15|224:(r[n++]=i>>18&7|240,r[n++]=i>>12&63|128),r[n++]=i>>6&63|128),r[n++]=63&i|128)}}function w(e){return e.bytes[p(e,1)]}function v(e,t){let s=g(e,1);e.bytes[s]=t}function E(e){let t,s=0,i=0;do t=w(e),s<32&&(i|=(127&t)<<s),s+=7;while(128&t);return i}function b(e,t){for(t>>>=0;t>=128;)v(e,127&t|128),t>>>=7;v(e,t)}function C(e,t){let s,i=0,n=0,r=0;return i=127&(s=w(e)),128&s&&(i|=(127&(s=w(e)))<<7,128&s&&(i|=(127&(s=w(e)))<<14,128&s&&(i|=(127&(s=w(e)))<<21,128&s&&(n=127&(s=w(e)),128&s&&(n|=(127&(s=w(e)))<<7,128&s&&(n|=(127&(s=w(e)))<<14,128&s&&(n|=(127&(s=w(e)))<<21,128&s&&(r=127&(s=w(e)),128&s&&(r|=(127&(s=w(e)))<<7))))))))),{low:i|n<<28,high:n>>>4|r<<24,unsigned:t}}function S(e,t){let s=t.low>>>0,i=(t.low>>>28|t.high<<4)>>>0,n=t.high>>>24,r=0===n?0===i?s<16384?s<128?1:2:s<2097152?3:4:i<16384?i<128?5:6:i<2097152?7:8:n<128?9:10,o=g(e,r),a=e.bytes;switch(r){case 10:a[o+9]=n>>>7&1;case 9:a[o+8]=9!==r?128|n:127&n;case 8:a[o+7]=8!==r?i>>>21|128:i>>>21&127;case 7:a[o+6]=7!==r?i>>>14|128:i>>>14&127;case 6:a[o+5]=6!==r?i>>>7|128:i>>>7&127;case 5:a[o+4]=5!==r?128|i:127&i;case 4:a[o+3]=4!==r?s>>>21|128:s>>>21&127;case 3:a[o+2]=3!==r?s>>>14|128:s>>>14&127;case 2:a[o+1]=2!==r?s>>>7|128:s>>>7&127;case 1:a[o]=1!==r?128|s:127&s}}function T(e){var t;return function(e){let t={};e:for(;!f(e);){let s=E(e);switch(s>>>3){case 0:break e;case 1:t.SeqID=C(e,!0);break;case 2:t.LogID=C(e,!0);break;case 3:t.service=E(e);break;case 4:t.method=E(e);break;case 5:{let s=function(e){let t=E(e),s=e.limit;return e.limit=e.offset+t,s}(e);(t.headers||(t.headers=[])).push(function(e){let t={};e:for(;!f(e);){let s=E(e);switch(s>>>3){case 0:break e;case 1:t.key=m(e,E(e));break;case 2:t.value=m(e,E(e));break;default:c(e,7&s)}}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=s;break}case 6:t.payloadEncoding=m(e,E(e));break;case 7:t.payloadType=m(e,E(e));break;case 8:t.payload=function(e,t){let s=p(e,t);return e.bytes.subarray(s,s+t)}(e,E(e));break;case 9:t.LogIDNew=m(e,E(e));break;case 10:t.serverTiming=m(e,E(e));break;case 11:t.msgID=m(e,E(e));break;case 12:t.frameType=E(e);break;default:c(e,7&s)}}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}({bytes:t=e,offset:0,limit:t.length})}function k(e){return h(e)}let I=String.prototype.charCodeAt;class B{constructor(e,t,s){this.isLong=!0,this.low=0|e,this.high=0|t,this.unsigned=!!s}static isLong(e){return e&&!0===e.isLong}static fromBits(e,t,s){return new B(e,t,s)}static fromBytes(e,t,s){return s?B.fromBytesLE(e,t):B.fromBytesBE(e,t)}static fromBytesLE(e,t){return new B(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 B(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?D:new B((I.call(e,0)|I.call(e,1)<<8|I.call(e,2)<<16|I.call(e,3)<<24)>>>0,(I.call(e,4)|I.call(e,5)<<8|I.call(e,6)<<16|I.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?L:D;if(t){if(e>=0xffffffffffffffff)return O}else{if(e<=-0x8000000000000000)return N;if(e+1>=0x8000000000000000)return x}return B.fromBits(e%0x100000000|0,e/0x100000000|0,t)}toNumber(){return this.unsigned?(this.high>>>0)*0x100000000+(this.low>>>0):0x100000000*this.high+(this.low>>>0)}isZero(){return 0===this.high&&0===this.low}add(e){B.isLong(e)||(e=B.fromNumber(e));let t=this.high>>>16,s=65535&this.high,i=this.low>>>16,n=65535&this.low,r=e.high>>>16,o=65535&e.high,a=e.low>>>16,h=65535&e.low,c=0,l=0,d,u;return d=0+((u=0+(n+h))>>>16),u&=65535,d+=i+a,l+=d>>>16,d&=65535,l+=s+o,c+=l>>>16,l&=65535,c+=t+r,c&=65535,B.fromBits(d<<16|u,c<<16|l,this.unsigned)}equals(e){return B.isLong(e)||(e=B.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?B.fromBits(0,0,this.unsigned):-1===this.low?B.fromBits(0,this.high+1,this.unsigned):B.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 D=new B(0,0,!1),L=new B(0,0,!0),x=B.fromBits(-1,0x7fffffff,!1),O=B.fromBits(-1,-1,!0),N=B.fromBits(0,-0x80000000,!1);var M,R,A,P=((M={})[M.NATIVE_ERROR=5001]="NATIVE_ERROR",M[M.CONNECTING_ERROR=5002]="CONNECTING_ERROR",M[M.MAX_RETRIES_ERROR=5003]="MAX_RETRIES_ERROR",M[M.MESSAGE_ERROR=5004]="MESSAGE_ERROR",M[M.OPEN_ERROR=5005]="OPEN_ERROR",M);class q{constructor(e){this.type=e,this.target=null}}class W extends q{constructor(e,t){super(e),this.message=t&&t.message||null}}class j extends q{constructor(e,t){super(e),this.error=t&&t.error||null,this.colno=t&&t.colno||0,this.filename=t&&t.filename||"",this.lineno=t&&t.lineno||0,this.message=t&&t.message||"",this.code=t&&t.code||5001}}class $ extends q{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 F extends q{constructor(e,t){super(e),this.data=t&&t.data||null}}class Q extends F{constructor(e,t){super(e),this.data=t&&t.data||null,this.message=t&&t.message||null}}class U extends q{constructor(e,t){super(e),this.data=t&&t.data||null}}function G(e,{message:t,code:s,error:i}){return new j(e,{message:t,code:s,error:i})}function J(e,{code:t,reason:s,wasClean:i,willReconnect:n}){return new $(e,{code:t,reason:s,wasClean:i,willReconnect:n})}function H(e,{data:t,message:s}){return new Q(e,{data:t,message:s})}function X(e,{data:t}){return new U(e,{data:t})}function K(e,{message:t}){return new W(e,{message:t})}class V{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}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,Z="undefined"!=typeof globalThis&&("Object"===globalThis.constructor.name||"DedicatedWorkerGlobalScope"===globalThis.constructor.name)&&"undefined"!=typeof tt,Y=("undefined"!=typeof globalThis&&"Object"===globalThis.constructor.name||"undefined"==typeof globalThis||"undefined"!=typeof globalThis&&!!globalThis.WeixinJSBridge)&&"undefined"!=typeof wx,ee="undefined"!=typeof globalThis&&("DedicatedWorkerGlobalScope"===globalThis.constructor.name||"SharedWorkerGlobalScope"===globalThis.constructor.name||"ServiceWorkerGlobalScope"===globalThis.constructor.name)&&"undefined"!=typeof self,et="undefined"!=typeof globalThis&&"Object"===globalThis.constructor.name&&void 0!==s.g&&"Object"===s.g.constructor.name&&"undefined"!=typeof process&&!!process.version;class es{constructor(){this._listeners={}}emit(e,...t){let s=this._listeners[e];if(s)s.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 s=this._listeners[e];if(s)for(let e=0;e<s.length;)s[e].fn===t?s.splice(e,1):++e}return this}on(e,t,s){return(this._listeners[e]||(this._listeners[e]=[])).push({fn:t,ctx:s||this}),this}}class ei extends es{_formatErrorMessage(e){return e.errMsg||e.errNo?`message: ${e.errMsg||""} code: ${e.errNo||""}`.trim():JSON.stringify(e)}constructor(e,t,s){super(),this._socket=null,Y&&wx.connectSocket&&(this._socket=wx.connectSocket({url:e,protocols:t,header:s,fail:this._createSocketFailHandler.bind(this),success:this._createSocketSuccessHandler.bind(this)})),Z&&tt.connectSocket&&(this._socket=tt.connectSocket({url:e,protocols:t,header:s,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:this._formatErrorMessage(e)});this.emit("error",t);let s=J("close",{reason:this._formatErrorMessage(e)});this.emit("close",s)})}_addWsListeners(){this._socket.onOpen(e=>{this.emit("open",X("open",{...e,data:e.errMsg||""}))}),this._socket.onClose(e=>{this.emit("close",J("close",{...e}))}),this._socket.onMessage(e=>{this.emit("message",H("message",{...e}))}),this._socket.onError(e=>{this.emit("error",G("error",{...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:this._formatErrorMessage(e)}))}})}else this._socket&&this._socket.send({data:e,fail:e=>{this.emit("error",G("error",{message:this._formatErrorMessage(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 en(e,t,s){let i=-1;async function n(r){return r<=i?Promise.reject(Error("next() called multiple times in process")):(i=r,r===s.length)?Promise.resolve():s[r].bind(e)(t,n.bind(null,r+1))}n(0)}function er(e){let t=0,s=0;for(let i=0;i<e.length;++i)(s=e.charCodeAt(i))<128?t+=1:s<2048?t+=2:(64512&s)==55296&&(64512&e.charCodeAt(i+1))==56320?(++i,t+=4):t+=3;return t}function eo(e,t,s){if(s-t<1)return"";let i="";for(let n=t;n<s;){let t=e[n++];if(t<=127)i+=String.fromCharCode(t);else if(t>=192&&t<224)i+=String.fromCharCode((31&t)<<6|63&e[n++]);else if(t>=224&&t<240)i+=String.fromCharCode((15&t)<<12|(63&e[n++])<<6|63&e[n++]);else if(t>=240){let s=((7&t)<<18|(63&e[n++])<<12|(63&e[n++])<<6|63&e[n++])-65536;i+=String.fromCharCode(55296+(s>>10)),i+=String.fromCharCode(56320+(1023&s))}}return i}function ea(e,t,s){let i,n,r=s;for(let r=0;r<e.length;++r)(i=e.charCodeAt(r))<128?t[s++]=i:(i<2048?t[s++]=i>>6|192:((64512&i)==55296&&(64512&(n=e.charCodeAt(r+1)))==56320?(i=65536+((1023&i)<<10)+(1023&n),++r,t[s++]=i>>18|240,t[s++]=i>>12&63|128):t[s++]=i>>12|224,t[s++]=i>>6&63|128),t[s++]=63&i|128);return s-r}async function eh(e){if("string"==typeof e){let t=new Uint8Array(er(e));return ea(e,t,0),t}return e instanceof ArrayBuffer?new Uint8Array(e):new Uint8Array(e.buffer,e.byteOffset,e.byteLength)}class ec{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}}async function el(e){return new Promise(t=>{if(!z)return t("unknown reason");try{let s=document.createElement("script");window.frontierJSONP=e=>{document.body.removeChild(s),window.frontierJSONP=void 0,t(e&&e.msg||"unknown reason")},s.type="text/javascript",s.src=e.replace(/^ws/,"http")+"&jscallback=frontierJSONP";try{document.body.appendChild(s)}catch{document.body.removeChild(s)}}catch{window.frontierJSONP=void 0,t("unknown reason")}})}function ed(e,t,s){return!!e?.find(e=>e.key===t&&e.value===s)}function eu(e,t){return e?.find(e=>e.key===t)?.value}let e_=null;async function ef(){return e_||(e_=Promise.resolve().then(s.bind(s,"../../node_modules/.pnpm/idb@7.0.2/node_modules/idb/build/index.js"))),e_}class eg extends es{constructor(e,t){super(),this._dbName=e,this._keyPath=t,this._qosDB=void 0,this._initPromise=null}async openDB(){await this._init()}async _init(){if(!this._qosDB){if(this._initPromise)return this._initPromise;try{let e=this._dbName,t=this._keyPath;this._initPromise=(async()=>{let{openDB:s}=await ef();this._qosDB=await s(`frontier_${e}`,1,{upgrade(s){s.createObjectStore(e,{keyPath:t})}})})(),await this._initPromise}catch(e){console.log(e)}finally{this._initPromise=null}}}async get(e){try{return await this._init(),this._qosDB?.get(this._dbName,e)}catch(e){console.log(e)}}async set(e,t){return await this._init(),this._qosDB?.put(this._dbName,e)}async del(e){try{return await this._init(),this._qosDB?.delete(this._dbName,e)}catch(e){console.log(e)}}async clear(){try{return await this._init(),this._qosDB?.clear(this._dbName)}catch(e){console.log(e)}}async keys(){return await this._init(),this._qosDB?.getAllKeys(this._dbName)}async getAll(){return await this._init(),this._qosDB?.getAll(this._dbName)}async closeDB(){try{this._qosDB?.close(),this._qosDB=void 0}catch(e){console.log(e)}}get isReady(){try{return!!this._qosDB}catch(e){return console.log(e),!1}}}class ep{constructor(e,t){this._DBName=e,this._pathKey=t,this._qosDB=localStorage}async openDB(){}get _prefix(){return`frontier_${this._DBName}`}async get(e){return JSON.parse(this._qosDB.getItem(this._prefix)||"{}")[e]}async set(e,t){let s=JSON.parse(this._qosDB.getItem(this._prefix)||"{}");return s[t||e[this._pathKey]]=e,this._qosDB.setItem(this._prefix,JSON.stringify(s)),t||e[this._pathKey]}async del(e){let t=JSON.parse(this._qosDB.getItem(this._prefix)||"{}");return t[e]=void 0,this._qosDB.setItem(this._prefix,JSON.stringify(t))}async clear(){return this._qosDB.clear()}async keys(){return Object.keys(JSON.parse(this._qosDB.getItem(this._prefix)||"{}"))}async getAll(){return Object.values(JSON.parse(this._qosDB.getItem(this._prefix)||"{}"))}closeDB(){return Promise.resolve()}get isReady(){return!!this._qosDB}}class em{constructor(e,t){this._DBName=e,this._pathKey=t,this._qosDB=Z?tt:Y?wx:null}async openDB(){}get _prefix(){return`frontier_${this._DBName}`}async get(e){return JSON.parse(this._qosDB.getStorageSync(this._prefix)||"{}")[e]}async set(e,t){let s=JSON.parse(this._qosDB.getStorageSync(this._prefix)||"{}");return s[t||e[this._pathKey]]=e,this._qosDB.setStorageSync(this._prefix,JSON.stringify(s)),t||e[this._pathKey]}async del(e){let t=JSON.parse(this._qosDB.getStorageSync(this._prefix)||"{}");return t[e]=void 0,this._qosDB.setStorageSync(this._prefix,JSON.stringify(t))}async clear(){return this._qosDB.clearStorageSync()}async keys(){return Object.keys(JSON.parse(this._qosDB.getStorageInfoSync(this._prefix)||"{}"))}async getAll(){return Object.values(JSON.parse(this._qosDB.getStorageInfoSync(this._prefix)||"{}"))}closeDB(){return Promise.resolve()}get isReady(){return!!this._qosDB}}function ey(e,t){if(Z||Z)return new em(e,t);if((z||ee)&&"undefined"!=typeof indexedDB)return new eg(e,t);if((z||ee)&&"undefined"!=typeof localStorage)return new ep(e,t);throw Error("init QoSDB failed")}class ew{constructor(){this._intervalTimeoutId=null,this._interval=36e5,this._qosDB=ey("qos","message_id")}async _intervalFlush(){clearInterval(this._intervalTimeoutId),this._intervalTimeoutId=setInterval(()=>{this.flushExpired()},this._interval)}async openDB(){await this._qosDB.openDB().then(()=>{this._intervalFlush()})}async flushExpired(){(await this._qosDB?.getAll()||[]).filter(({timestamp:e})=>e<Date.now()).forEach(e=>{this._qosDB?.del(e.message_id)})}async del(e){return this._qosDB?.del(e)}async set(e,t){return this._qosDB?.set({message_id:e,timestamp:t})}async get(e){return this._qosDB?.get(e)}async closeDB(){clearInterval(this._intervalTimeoutId),await this._qosDB?.closeDB()}get isReady(){return this._qosDB?.isReady}}function ev(e){let t=!!this._options.enableQoS;if(!t)return{enabled:t,isQoSMessage:!1,isQoSAck:!1,isAckCleanupMessage:!1,ackMsgIds:[]};let s=ed(e.message.headers,"x_frontier_qos","2"),i=s&&ed(e.message.headers,"x_frontier_qos_ack","1"),n=s&&ed(e.message.headers,"x_frontier_is_ack","1"),r=n&&eu(e.message.headers,"x_frontier_ack_msgid")?.split(",").filter(Boolean)||[];return{enabled:t,isQoSMessage:s,isQoSAck:i,isAckCleanupMessage:n,ackMsgIds:r}}async function eE(){return this._QoSManager||(this._QoSManager=new ew),this._QoSManager.isReady||await this._QoSManager.openDB(),this._QoSManager}async function eb(e,t){let{enableAutoAck:s}=this._options,i=ed(e.message.headers,"need_ack","1"),n=ed(e.message.headers,"is_ack","1"),r=ev.call(this,e);if(s&&i){let{SeqID:t,LogID:s,service:i,LogIDNew:n,method:r}=e.message;this._sendAck({SeqID:t,LogID:s,LogIDNew:n,service:i,method:r,headers:[{key:"is_ack",value:"1"},{key:"ack_id",value:n||""},{key:"ack_code",value:"0"}]})}n&&!r.isQoSAck&&this._dispatchAckMessageEvent(e),t()}async function eC(e,t){this._debug("received",e.message),t()}async function eS(e,t){let s=T(await eh(e.data));try{if(s.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=s.payloadEncoding?s.payloadEncoding.replace(/\s/g,"").toLowerCase():"",i=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():""},n=s.payloadType?s.payloadType.replace(/\s/g,"").toLowerCase():"",r=i.force?i.type:n||i.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))?s.textPayload=eo(s.payload,0,s.payload.byteLength):s.textPayload=""}else s.textPayload=""}catch(e){s.textPayload="",console.log(e)}e.message=s,t()}function eT(e,t){return e.readUInt8?{value:e.readUInt8(t),offset:t+1}:{value:255&e[t],offset:t+1}}function ek(e,t,s){return t.writeUint8?t.writeUint8(e,s):t[s]=255&e,s+1}let eI="undefined"!=typeof Buffer?Buffer.allocUnsafe:(R=function(e){return new Uint8Array(e)},A=Uint8Array.prototype.subarray,e=4096,t=null,n=8192,function(s){if(s<1||s>e)return R(s);n+s>8192&&(t=R(8192),n=0);let i=A.call(t,n,n+=s);return 7&n&&(n=(7|n)+1),i});function eB(e,t,s){let[i,n]=function(e){let t=0,s={};for(let i=0;i<e.length;i++)s[e[i].cursor_name]=er(e[i].cursor_name),t+=14+s[e[i].cursor_name];return[t,s]}(e),r=eI(i),o=0;return e.forEach(e=>{var s,i,a,h,c;let l,d;console.log("cursor.service",e,e.service),console.log("header",o=ek(0,r,o)),console.log("service",o=function(e,t,s){if(s>0xffffffff)throw Error("integer too large");let i=3;for(;i>=0;)ek(255&s,e,t+i),s>>>=8,i--;return t+4}(r,o,e.service||0)),console.log("service-name",o=ek(n[e.cursor_name],r,o)),console.log("name",(a=e.cursor_name,h=r,c=o,o=a?a.length<40?ea(a,h,c)+c:h.utf8Write?h.utf8Write(a,c)+c:h.write?h.write(a,c)+c:ea(a,h,c)+c:c)),s=B.fromNumber(e.cursor||t),i=o,l=s.low,d=s.high,r[i]=d>>>24,r[i+1]=d>>>16&255,r[i+2]=d>>>8&255,r[i+3]=255&d,r[i+4]=l>>>24,r[i+5]=l>>>16&255,r[i+6]=l>>>8&255,r[i+7]=255&l,console.log("curvalue",o=i+=8)}),{frameType:32,headers:[{key:"cursor_file_name",value:s}],payload:r}}class eD{constructor(e,t,s){this._cursorNameSpace=e,this._cursorFileName=t,this._messageStrategy=s,this._qosDB=ey(this._cursorNameSpace,"cursor_name")}async openDB(){await this._qosDB.openDB()}async getCursors(){if(!this._qosDB.isReady)return;let e=this._messageStrategy,t=await this._qosDB.getAll();switch(console.log("allCursorValues",t),e){case"ALL":return t&&t.length?eB(t,0,this._cursorFileName):void 0;case"INSTANT":return;case"CONTINUE":return t&&t.length?eB(t,0,this._cursorFileName):{frameType:32,headers:[{key:"cursor_file_name",value:"FILE_NOT_EXIST"}],payload:void 0}}}async set(e,t,s){return console.log("setdb",e,t,s),this._qosDB.set({cursor_name:e,cursor:t,service:s})}async setCursors(e){let t=function(e){let t=0,s=[];for(;t<e.byteLength;){var i,n;let{offset:r}=eT(e,t),o={cursor_name:"",cursor:0,service:0},{value:a,offset:h}=function(e,t){let s=0,i=t,n=t+4;for(;i<n;){let{value:t,offset:n}=eT(e,i);i=n,s=(s<<8>>>0)+t}return{value:s,offset:n}}(e,t=r);o.service=a;let{value:c,offset:l}=eT(e,t=h);o.cursor_name=eo(e,t=l,t+c);let{value:d,offset:u}={value:new B((i=e)[(n=t+=c)+4]<<24|i[n+5]<<16|i[n+6]<<8|i[n+7],i[n+0]<<24|i[n+1]<<16|i[n+2]<<8|i[n+3],!0),offset:(n+=8)+8};o.cursor=d.toNumber(),t=u,s.push(o)}return s}(e);for(let e of t)console.log("setcursor",t),await this._qosDB.set(e)}async get(e){return(await this._qosDB.get(e))?.cursor}async closeDB(){await this._qosDB.closeDB()}updateCursorFileName(e){this._cursorFileName=e}get isReady(){return this._qosDB.isReady}}async function eL(e){if(!this._options.enableQoS)return null;let{aID:t,fpID:s,messageStrategy:i}=this._options,n=e||"__x_msg_qos__";try{return this._cursorManager?e&&this._cursorManager.updateCursorFileName(e):this._cursorManager=new eD(`${s}_${t}_${n}`,n,i),this._cursorManager.isReady||await this._cursorManager.openDB(),this._cursorManager}catch{return null}}async function ex(e,t){let s=ed(e.message.headers,"code","-1"),i=ed(e.message.headers,"is_ack","1"),n=eu(e.message.headers,"x_frontier_msgid"),r=Number(eu(e.message.headers,"x_frontier_ttl"))||0,o=ev.call(this,e),a=ed(e.message.headers,"x-msg-qos","2"),h=eu(e.message.headers,"x-msg-cursor_name"),c=Number(eu(e.message.headers,"x-msg-cursor_value"));if(o.isQoSAck)return t();let l=o.isQoSMessage?await eE.call(this):null;if(e.message.service>0&&i&&!s||e.message.service>0){if(n&&o.isQoSMessage&&l)return await l.get(n)||(this._dispatchMessageEvent(e),await l.set(n,Date.now()+r)),t();if(a){let s=await eL.call(this);if(!s)return this._dispatchMessageEvent(e),t();let i=await s.get(h)??-1;if(i<c)this._dispatchMessageEvent(e),s.set(h,c,e.message.service);else throw Error(`recevied message cursor ${c} larger than local cursor ${i}`);return t()}return this._dispatchMessageEvent(e),t()}}async function eO(e,t){let s=ev.call(this,e);if(!s.isQoSMessage)return t();let i=await eE.call(this);if(s.isAckCleanupMessage&&s.ackMsgIds.length)for(let e of s.ackMsgIds)await i.del(e);t()}async function eN(e,t){let s=16===e.message.frameType,i=32===e.message.frameType;if(!s&&!i)return t();let n=eu(e.message.headers,"cursor_file_name");if(!n)return t();let r=await eL.call(this,n);if(!r)return t();if(s){let e=await r.getCursors(),t=h({frameType:e?.frameType,SeqID:B.fromNumber(this._seqId++),LogID:B.fromNumber(this._options.logIDGenerator()),service:9e3,method:5,headers:e?.headers,payload:e?.payload});this._ws&&this._ws.readyState&&this._ws.send(t)}if(i){let t=e.message.payload;t&&r.setCursors(t)}}let eM=async function(e,t){this._isInit=!1,clearTimeout(this._connectionTimeoutId),t()},eR=async function(e,t){if(!this._ws||this._ws.readyState!==this.OPEN)return t();let{pingInterval:s}=this._options;this._endpointManager?.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 i=this._endpointManager?.getCurrentEndpoint();this._debug(`open ${i} success`),t()},eA=async function(e,t){let s=this._endpointManager?.getCurrentEndpoint();this._debug(`open ${s}`),t()};class eP extends es{constructor(e){super(),this._miniNavigatorOnline=!0,this._isBrowser=z,this._isNode=et,this._isMiniTT=Z,this._isMiniWX=Y,this._isWorker=ee,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=e=>{try{en(this,e,[eM,eR,eA])}catch(t){let e=G("error",{message:t.message,code:P.OPEN_ERROR,error:t});this._dispatchErrorEvent(e)}},this._onMessage=async e=>{let{pingInterval:t,pingFrequency:s}=this._options;if(("hi"===e.data&&"always"===s||"auto"===s)&&(this._clearPingTimer(),this.emit("ping_once_success","success"),this._pingPongTimeoutId=setTimeout(this._ping.bind(this),t)),"hi"!==e.data)try{en(this,e,[eS,eb,eO,eN,ex,eC])}catch(t){let e=G("error",{message:t.message,code:P.MESSAGE_ERROR,error:t});this._dispatchErrorEvent(e)}},this._onError=e=>{let t=this._endpointManager?.checkReachMaxTries(),s=this._endpointManager?.getCurrentEndpoint();if(t&&!e.message){let t=`connect ${s} fail, max retries reached`;this._dispatchErrorEvent(G("error",{message:t,code:P.MAX_RETRIES_ERROR,error:e}));return}this._ws&&this._ws.readyState===this.OPEN&&this._disconnect(),this._dispatchErrorEvent(G("error",{message:e.message,code:P.NATIVE_ERROR,error:e}))},this._onClose=async e=>{this._clearTimer(),this._clearPingTimer(),this._removeWsListeners(),this._ws=null,this._connectLock=!1;let t=this._endpointManager?.checkReachMaxTries();if(!t&&this._navigatorOnline()&&!this._readyClosed){let t=this._endpointManager?.getCurrentEndpoint(),s=this._options.reconnectInterceptor(e.code,e.reason);this._dispatchCloseEvent(J("close",{code:1006,reason:e.reason||`connecting failed, unknown reason, hostname: ${t}`,willReconnect:s})),s&&this._connect();return}if(1e3!==e.code&&this._readyClosed){this._dispatchCloseEvent(J("close",{code:1e3,reason:"bye"})),this._endpointManager?.resetEndpointConfig(),this._pingLossCounter?.resetCounter();return}if(1e3!==e.code&&t){let t=this._endpointManager?.getCurrentEndpoint(),s=e.reason;s||(s=await el(this._url)),s=`connecting failed, ${s}, hostname: ${t}, max retries reached`,this._dispatchCloseEvent(J("close",{code:e.code,reason:s}));let i=`connect ${t} fail, max retries reached`;this._dispatchErrorEvent(G("error",{message:i,code:P.MAX_RETRIES_ERROR})),this._endpointManager?.resetEndpointConfig(),this._pingLossCounter?.resetCounter();return}if(1e3!==e.code&&!e.reason){let t=this._endpointManager?.getCurrentEndpoint();this._dispatchCloseEvent(J("close",{code:e.code,reason:`connecting failed, unknown reason, hostname: ${t}`})),this._endpointManager?.resetEndpointConfig(),this._pingLossCounter?.resetCounter();return}this._dispatchCloseEvent(e),this._endpointManager?.resetEndpointConfig(),this._pingLossCounter?.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:o,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};const{url:t,ws:s}=e,i=Array.isArray(t)?t:"string"==typeof t?[t]:[];if(!i||0===i.length)throw Error("please provide valid url");if(!(s||Y&&wx.connectSocket||Z&&tt.connectSocket||(z||ee)&&"undefined"!=typeof WebSocket&&WebSocket))throw Error("please provide ws params, WebSocket constructor is undefined");Object.assign(this._options,e),this._endpointManager=new V(i,this._options.maxRetries),this._pingLossCounter=new ec(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(){this._options.disableAutoReconnect||this._readyClosed||this._handleReconnect()}_handleOffLine(){this._destroyWebSocket();let e=K("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))}async _generateUrl(e){let t,s,i,{fpID:n,deviceID:r,bddID:o,ttwID:a,accessKey:h,aID:c,customParams:l={},enableAutoAck:d,enableQoS:u,QoSLevel:_,env:f}=this._options;this._isBrowser||this._isMiniWX||this._isMiniTT?(t=location&&"https:"==location.protocol?"wss://":"ws://",s=e.replace(/((^ws)|(^http))((?:[s]*:\/\/))/,""),i=/^wss(.*:\/\/)/.test(e)?e:`${t}${s}`):(t="wss://",s=e.replace(/(^http)((?:[s]*:\/\/))/,""),i=/(^ws)((?:[s]*:\/\/))/.test(s)?s:`${t}${s}`);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 m="function"==typeof l?await l():l,y=Object.assign({device_platform:"web",version_code:"fws_1.0.0",access_key:h,fpid:n,aid:c,[g]:p,xsack:+!!d,xaack:+!!d,xsqos:+!!u,qos_level:u?_:void 0,qos_sdk_version:2,...f?((e,t)=>{switch(e){case"boe":case"ppe":return{[`x-use-${e}`]:1,"x-tt-env":t};default:return{}}})(f.xUseEnv,f.xTTEnv):{}},m),w=Object.keys(y).reduce((e,t)=>void 0!==y[t]?`${e}${e?"&":"?"}${t}=${y[t]}`:e,"");return`${i}/ws/v2${w}`}async _connect(){if(!this._connectLock&&!this._readyClosed){this._connectLock=!0;try{var e,t;let s=this._endpointManager?.checkCurrentEndpointReachedMaxRetries(),{timeoutInterval:i}=this._options;if(s){let e=this._endpointManager?.getCurrentEndpoint(),t=this._endpointManager?.replaceBackupEndpointAndUpdateCount(),s=this._endpointManager?.getCurrentEndpointTriesCount();if(t){let i=`connect ${e} timeout, max retries reached, will use backup endpoint ${t} to retry`,n=G("error",{message:i,code:P.MAX_RETRIES_ERROR});this._debug(i),this._dispatchErrorEvent(n),this._url=await this._generateUrl(t),this._debug(`connect ${t} ${s} times`),this._removeWsListeners()}else{let t=`connect ${e} timeout, max retries reached`;this._debug(t),this._dispatchErrorEvent(G("error",{message:t,code:P.MAX_RETRIES_ERROR}));return}}else{let e=this._endpointManager?.getCurrentEndpointAndUpdateCount(),t=this._endpointManager?.getCurrentEndpointTriesCount();this._url=await this._generateUrl(e||""),this._debug(`connect ${e} ${t} times`),this._removeWsListeners()}if(this._isInit)this._isInit=!1;else{let e=K("reconnect",{message:"start"});this.onStartReconnect&&this.onStartReconnect(e)}let n=this._endpointManager?.getCurrentEndpointTriesCount()||0;n>1&&await this._wait(n-1),this._debug(`connecting url: ${this._url} protocols: ${this._protocols}`),this._ws=(e={url:this._url,protocols:[this._protocols],headers:this._options.miniProgramParams.customHttpHeader},(t=this._options.ws)?new t(e.url,e.protocol):Y||Z?new ei(e.url,e.protocol,e.headers):(z||ee)&&"undefined"!=typeof WebSocket&&WebSocket?new WebSocket(e.url,e.protocols):void 0),(this._isBrowser||this._isWorker)&&this._ws&&(this._ws.binaryType=this._binaryType),this._addWsListeners(),this._connectionTimeoutId=setTimeout(this._onTimeout.bind(this),i)}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&&console.log.apply(console,["FRONTIER>",...e])}_getIntervalValue(e){let{initReconnectInterval:t,maxReconnectInterval:s,reconnectIntervalGrowFactor:i}=this._options,n=t*Math.pow(i,e-1);return n>s?s:n}_ping(){if(this._ws&&this._ws.readyState===this.CONNECTING){this._clearPingTimer(),this._pingPongTimeoutId=setTimeout(this._ping.bind(this),this._options.pingInterval);return}this._ws&&this._ws.readyState===this.OPEN?(this._ws&&this._ws.send("hi"),this._reconnectTimeoutId=setTimeout(this._handleReconnectTimeout.bind(this),this._options.pingTimeoutInterval)):this._handleReconnect()}_handleReconnectTimeout(){this._pingLossCounter?.addCount(),this.emit("ping_once_timeout","timeout"),this._pingLossCounter?.checkReachMaxCount()?this._handleReconnect():this._ping()}_navigatorOnline(){return this._isMiniTT||this._isMiniWX?this._miniNavigatorOnline:!this._isBrowser&&!this._isWorker||!this._options.listenNetworkChanged||navigator.onLine}_handleReconnect(){this._navigatorOnline()&&!this._readyClosed&&(this._endpointManager?.resetEndpointConfig(),this._pingLossCounter?.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="",s=!1){this._ws&&this._destroyWebSocket(e,t,s)}_onTimeout(){let e=this._endpointManager?.getCurrentEndpoint();this._debug(`connect ${e} timeout`),this._disconnect(1001,"timeout, try reconnecting",!0)}_sendAck(e){let t=h(e);this._ws&&this._ws.readyState===this.OPEN&&(this._ws&&this._ws.send(t),this._debug("send_ack",e))}_removeWsListeners(){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(){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{}}_destroyWebSocket(e=1e3,t="",s=!1){if(this._clearPingTimer(),this._clearTimer(),this._removeWsListeners(),this._wsInstanceClose(1e3,t),this._connectLock=!1,s&&this._navigatorOnline()&&!this._readyClosed){if(this._endpointManager?.checkReachMaxTries()){let e=this._endpointManager?.getCurrentEndpoint();this._dispatchCloseEvent(J("close",{code:1006,reason:`connect ${e} timeout, max retries reached`,wasClean:!0}))}else{let s=this._options.reconnectInterceptor(e,t);this._dispatchCloseEvent(J("close",{code:e,reason:t,wasClean:!0,willReconnect:s})),s&&this._connect()}return}this._navigatorOnline()||this._readyClosed?this._dispatchCloseEvent(J("close",{code:e,reason:"bye"})):this._dispatchCloseEvent(J("close",{code:1006,reason:"going away, network offline"})),this._ws=null,this._endpointManager?.resetEndpointConfig(),this._pingLossCounter?.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(){return this._endpointManager?.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){(this._readyClosed=!0,this._clearTimer(),this._clearPingTimer(),this._dropGlobalEventListener(),this._QoSManager?.closeDB(),this._ws)?this._ws.readyState===this.CLOSED||this._ws.readyState===this.CLOSING?this._debug("close, ws already closed"):this._destroyWebSocket(e,t):this._debug("close, ws instance not initialized")}async send(e,t){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 s=await eh(e),i=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";return""}catch{if("string"==typeof e)return"text/plain;charset=utf-8";return""}}(e),{method:n=0,service:o=this._options.service,logID:c=this._options.logIDGenerator(),headers:l=this._options.headers,payloadEncoding:d=this._options.payloadEncoding,payloadType:u=this._options.payloadType,logIDNew:_=this._options.logIDNewConfig.enableAutoGenerateLogIDNew?function(e=""){var t;let s,i,n,o;return`02${Date.now()}`+(r||(t=e,n=/(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(t),o=/(([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(t),r=n?(s=t.split(/\./).map(e=>(Array(8).join("0")+parseInt(e,10).toString(2)).slice(-8)),(i=[])[0]=a(s[0]+s[1]),i[1]=a(s[2]+s[3]),"00000000000000000000ffff"+i[0]+i[1]):o?function(e){let t="",s=[],i=0,n=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&&(i=e.length),n+=e.length;for(let t=0;t<e.length;t++)if(4!==e[t].length){let i=o.substring(0,4-e[t].length).concat(e[t]);s.push(i)}else s.push(e[t]);r=!1}else{if(4!==t.length){let e=o.substring(0,4-t.length).concat(t);s.push(e)}else s.push(t);r&&(i+=1),n+=1,r=!1}}let h="";for(let e=0;e<8-n;e++)h=h.concat(o);for(let e=0;e<s.length;e++)t=e===i?(t=t.concat(h)).concat(s[e]):t.concat(s[e]);return t}{let s=e.split(":");for(let e=0;e<s.length;e++){let i=s[e];if(4!==s[e].length){let n=o.substring(0,4-s[e].length).concat(i);t=t.concat(n)}else t=t.concat(i)}return t}}(t):"00000000000000000000000000000000"))+Math.random().toString(16).slice(-6)}(this._options.logIDNewConfig.userIp):""}=t||{};if(!o)throw Error("please provide a valid service");let f={SeqID:B.fromNumber(this._seqId++),LogID:B.fromNumber(c),service:o,method:n,headers:l,payloadEncoding:d instanceof Object?d.encoding?d.encoding:"":d,payloadType:u instanceof Object?u.type?u.type:i:u||i,payload:s,LogIDNew:_},g=h(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:c,logIDNew:_}}async reconnect(e){let{url:t}=e||{},s=Array.isArray(t)?t:"string"==typeof t?[t]:[];e&&Object.assign(this._options,e),s&&s.length?this._endpointManager=new V(s,this._options.maxRetries):this._endpointManager?.resetEndpointConfig(),this._pingLossCounter?.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())}async connect(){this._connectLock||(this._endpointManager?.resetEndpointConfig(),this._pingLossCounter?.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 s=()=>{e("success"),this.off("ping_once_success",s),this.off("ping_once_timeout",i)},i=()=>{t("timeout"),this.off("ping_once_success",s),this.off("ping_once_timeout",i)};this.on("ping_once_success",s),this.on("ping_once_timeout",i),this._ping()})}}})(),i})());
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { EventEmitter } from '../utils/event-emitter';
|
|
2
|
+
import type { IQoSDB } from './qos';
|
|
3
|
+
export declare class QoSDB<DBSchema extends {
|
|
4
|
+
key: string;
|
|
5
|
+
value: any;
|
|
6
|
+
}> extends EventEmitter implements IQoSDB<DBSchema> {
|
|
7
|
+
private _dbName;
|
|
8
|
+
private _keyPath;
|
|
9
|
+
private _qosDB;
|
|
10
|
+
private _initPromise;
|
|
11
|
+
constructor(_dbName: string, _keyPath: string);
|
|
12
|
+
openDB(): Promise<void>;
|
|
13
|
+
protected _init(): Promise<void>;
|
|
14
|
+
get(key: string): Promise<DBSchema["value"] | undefined>;
|
|
15
|
+
set(val: DBSchema['value'], _key?: string): Promise<DBSchema["key"]>;
|
|
16
|
+
del(key: string): Promise<void>;
|
|
17
|
+
clear(): Promise<void>;
|
|
18
|
+
keys(): Promise<DBSchema["key"][]>;
|
|
19
|
+
getAll(): Promise<DBSchema["value"][]>;
|
|
20
|
+
closeDB(): Promise<void>;
|
|
21
|
+
get isReady(): boolean;
|
|
22
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { IQoSDB } from './qos';
|
|
2
|
+
export declare class QoSLocalStorage<DBSchema extends {
|
|
3
|
+
key: string;
|
|
4
|
+
value: any;
|
|
5
|
+
}> implements IQoSDB<DBSchema> {
|
|
6
|
+
private _DBName;
|
|
7
|
+
private _pathKey;
|
|
8
|
+
private _qosDB;
|
|
9
|
+
constructor(_DBName: string, _pathKey: string);
|
|
10
|
+
openDB(): Promise<void>;
|
|
11
|
+
protected get _prefix(): string;
|
|
12
|
+
get(key: string): Promise<DBSchema["value"] | undefined>;
|
|
13
|
+
set(val: DBSchema['value'], key?: string): Promise<any>;
|
|
14
|
+
del(key: string): Promise<void>;
|
|
15
|
+
clear(): Promise<void>;
|
|
16
|
+
keys(): Promise<DBSchema["key"][]>;
|
|
17
|
+
getAll(): Promise<DBSchema["value"][]>;
|
|
18
|
+
closeDB(): Promise<void>;
|
|
19
|
+
get isReady(): boolean;
|
|
20
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { IQoSDB } from './qos';
|
|
2
|
+
export declare class QoSMiniStorage<DBSchema extends {
|
|
3
|
+
key: string;
|
|
4
|
+
value: any;
|
|
5
|
+
}> implements IQoSDB<DBSchema> {
|
|
6
|
+
private _DBName;
|
|
7
|
+
private _pathKey;
|
|
8
|
+
private _qosDB;
|
|
9
|
+
constructor(_DBName: string, _pathKey: string);
|
|
10
|
+
openDB(): Promise<void>;
|
|
11
|
+
protected get _prefix(): string;
|
|
12
|
+
get(key: string): Promise<DBSchema["value"] | undefined>;
|
|
13
|
+
set(val: DBSchema['value'], key?: string): Promise<any>;
|
|
14
|
+
del(key: string): Promise<any>;
|
|
15
|
+
clear(): Promise<any>;
|
|
16
|
+
keys(): Promise<DBSchema["key"][]>;
|
|
17
|
+
getAll(): Promise<DBSchema["value"][]>;
|
|
18
|
+
closeDB(): Promise<void>;
|
|
19
|
+
get isReady(): boolean;
|
|
20
|
+
}
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
import type { FrontierMessageFrame, FrontierMessageHeader } from './idl/protobuf';
|
|
2
|
+
import type { ReconnectEvent, FrontierMessageEvent, CustomErrorEvent, CustomCloseEvent, OpenEvent } from './utils/event';
|
|
3
|
+
import { EndpointManager } from './manager/endpoint-manager';
|
|
4
|
+
import { EventEmitter } from './utils/event-emitter';
|
|
5
|
+
import { PkgLossCounter } from './utils/pkg-loss-counter';
|
|
6
|
+
import { QoSManager } from './manager/qos-manager';
|
|
7
|
+
import { CursorManager } from './manager/cursor-manager';
|
|
8
|
+
export * from './utils/event';
|
|
9
|
+
export * from './idl/protobuf';
|
|
10
|
+
export type Message = string | ArrayBuffer | ArrayBufferView;
|
|
11
|
+
export type Protocols = string | string[];
|
|
12
|
+
export interface Options {
|
|
13
|
+
/** 自定义建连域名,可传入域名数组,第一个域名为高优先级域名,后面的域名为备用域名 */
|
|
14
|
+
url: string | string[];
|
|
15
|
+
/** 自定义 WebSocket */
|
|
16
|
+
ws?: any;
|
|
17
|
+
/** 是否初始化实例后自动开启 websocket 连接 */
|
|
18
|
+
automaticOpen?: boolean;
|
|
19
|
+
/** 重连间隔 */
|
|
20
|
+
initReconnectInterval?: number;
|
|
21
|
+
/** 最大重连间隔 */
|
|
22
|
+
maxReconnectInterval?: number;
|
|
23
|
+
/** 支持重连回退算法, 回退因子,数值越大重试间隔时间越长 */
|
|
24
|
+
reconnectIntervalGrowFactor?: number;
|
|
25
|
+
/** 建连超时间隔 */
|
|
26
|
+
timeoutInterval?: number;
|
|
27
|
+
/** 最大重试次数 */
|
|
28
|
+
maxRetries?: number;
|
|
29
|
+
/** 最大消息缓存长度,该长度指的是消息条数 */
|
|
30
|
+
maxMessageQueueLength?: number;
|
|
31
|
+
/** 开启 debug 模式 */
|
|
32
|
+
debug?: boolean;
|
|
33
|
+
/** frontier 平台的服务 ID */
|
|
34
|
+
service?: number;
|
|
35
|
+
/** frontier 平台的 LogID 生成方法 */
|
|
36
|
+
logIDGenerator?: () => number;
|
|
37
|
+
/** 全局配置的消息头 */
|
|
38
|
+
headers?: FrontierMessageHeader[] | undefined;
|
|
39
|
+
/** 全局配置的发送消息的编码, 可配置 force 项,强制使用客户端配置,忽略 payload 里的配置 */
|
|
40
|
+
payloadEncoding?: string | {
|
|
41
|
+
encoding: string;
|
|
42
|
+
force: boolean;
|
|
43
|
+
};
|
|
44
|
+
/** 全局配置的发送消息的类型, 可配置 force 项,强制使用客户端配置,忽略 payload 里的配置 */
|
|
45
|
+
payloadType?: string | {
|
|
46
|
+
type: string;
|
|
47
|
+
force: boolean;
|
|
48
|
+
};
|
|
49
|
+
/** frontier 平台的产品线 ID */
|
|
50
|
+
fpID: string;
|
|
51
|
+
/** frontier 平台需要的设备 ID,请填写正整数数字*/
|
|
52
|
+
deviceID?: string | number;
|
|
53
|
+
/** frontier 平台需要的 toB ID*/
|
|
54
|
+
bddID?: string;
|
|
55
|
+
/** frontier 平台需要的 TT Web ID*/
|
|
56
|
+
ttwID?: string;
|
|
57
|
+
/** 服务端生成的 accessKey,供和 frontier 平台建立连接使用 */
|
|
58
|
+
accessKey: string;
|
|
59
|
+
/** frontier 平台的应用 ID */
|
|
60
|
+
aID: string;
|
|
61
|
+
/** 建连附加参数,例如 session 鉴权 */
|
|
62
|
+
customParams?: {
|
|
63
|
+
[key: string]: string | number;
|
|
64
|
+
} | (() => Promise<{
|
|
65
|
+
[key: string]: string | number;
|
|
66
|
+
}> | {
|
|
67
|
+
[key: string]: string | number;
|
|
68
|
+
});
|
|
69
|
+
/** web 端主动保活 ping-pong 间隔,默认为 30s */
|
|
70
|
+
pingInterval?: number;
|
|
71
|
+
/** web 端主动保活 ping-pong 超时间隔,默认配置为 5s */
|
|
72
|
+
pingTimeoutInterval?: number;
|
|
73
|
+
/** web 端主动保活 ping-pong 频率, 'always' 模式保持指定的 pingInterval 间隔发出 ping 帧;'auto' 模式会根据当前连接是否活跃自动调整 ping 的发出间隔,当接收到消息会延迟下次 ping 帧的发出 */
|
|
74
|
+
pingFrequency?: 'always' | 'auto';
|
|
75
|
+
/** web 端主动保活 ping-pong 的期望最大丢包数,当达到最大丢包数后,就判断为失活,触发重连逻辑 */
|
|
76
|
+
pingLossCount?: number;
|
|
77
|
+
/** 是否开启自动转换文本类型的 payload,默认关闭 */
|
|
78
|
+
enableTransformTextPayload?: boolean;
|
|
79
|
+
/** logIDNew 配置项 */
|
|
80
|
+
logIDNewConfig?: {
|
|
81
|
+
/** 启用自动生成 logIDNew 字段,遵循公司 logID 规范 */
|
|
82
|
+
enableAutoGenerateLogIDNew?: boolean;
|
|
83
|
+
/** 自动生成 logIDNew 需要的 ip,默认置 0 */
|
|
84
|
+
userIp?: string;
|
|
85
|
+
};
|
|
86
|
+
/** 关闭断网后,网络恢复自动重连 */
|
|
87
|
+
disableAutoReconnect?: boolean;
|
|
88
|
+
/** 小程序建连参数 */
|
|
89
|
+
miniProgramParams?: {
|
|
90
|
+
customHttpHeader?: {
|
|
91
|
+
[key: string]: string;
|
|
92
|
+
};
|
|
93
|
+
};
|
|
94
|
+
/** 是否开启自动 ack */
|
|
95
|
+
enableAutoAck?: boolean;
|
|
96
|
+
/** 重连拦截器,可自定义是否进行重连操作,返回 boolean 值,为 true 则进行重连 */
|
|
97
|
+
reconnectInterceptor?: (code: number, reason: string) => boolean;
|
|
98
|
+
/** 是否开启 QoS 能力 */
|
|
99
|
+
enableQoS?: boolean;
|
|
100
|
+
/** QoS Level, 配置 QoS 等级 */
|
|
101
|
+
QoSLevel?: 2;
|
|
102
|
+
/** 消息策略, 可选值 ALL | CONTINUE (默认) | INSTANT */
|
|
103
|
+
messageStrategy?: 'CONTINUE';
|
|
104
|
+
/** 使用多环境能力, 传入 xUseEnv: boe|ppe, xTTEnv: custom_tag */
|
|
105
|
+
env?: {
|
|
106
|
+
xUseEnv: 'boe' | 'ppe';
|
|
107
|
+
xTTEnv: string;
|
|
108
|
+
};
|
|
109
|
+
/** 监听网络变化,自动判断是否重连 */
|
|
110
|
+
listenNetworkChanged?: boolean;
|
|
111
|
+
}
|
|
112
|
+
export type ReconnectOptions = Partial<Pick<Options, 'url' | 'initReconnectInterval' | 'maxReconnectInterval' | 'reconnectIntervalGrowFactor' | 'timeoutInterval' | 'maxRetries' | 'service' | 'deviceID' | 'bddID' | 'ttwID' | 'accessKey' | 'customParams' | 'pingInterval' | 'pingTimeoutInterval' | 'pingFrequency' | 'pingLossCount' | 'miniProgramParams' | 'enableAutoAck' | 'env'>>;
|
|
113
|
+
export interface FrontierEventMap {
|
|
114
|
+
error: CustomErrorEvent;
|
|
115
|
+
message: FrontierMessageEvent;
|
|
116
|
+
open: OpenEvent;
|
|
117
|
+
close: CustomCloseEvent;
|
|
118
|
+
ack: FrontierMessageEvent;
|
|
119
|
+
}
|
|
120
|
+
export declare class FWS extends EventEmitter {
|
|
121
|
+
protected _ws?: any;
|
|
122
|
+
protected _miniNavigatorOnline: boolean;
|
|
123
|
+
protected _isBrowser: boolean;
|
|
124
|
+
protected _isNode: boolean;
|
|
125
|
+
protected _isMiniTT: boolean;
|
|
126
|
+
protected _isMiniWX: boolean;
|
|
127
|
+
protected _isWorker: boolean;
|
|
128
|
+
protected _messageQueue: (ArrayBuffer | null)[];
|
|
129
|
+
protected _endpointManager: EndpointManager | null;
|
|
130
|
+
protected _readyClosed: boolean;
|
|
131
|
+
protected _binaryType: BinaryType;
|
|
132
|
+
protected _connectLock: boolean;
|
|
133
|
+
protected _connectionTimeoutId: any;
|
|
134
|
+
protected _reconnectTimeoutId: any;
|
|
135
|
+
protected _pingPongTimeoutId: any;
|
|
136
|
+
protected _seqId: number;
|
|
137
|
+
protected _isInit: boolean;
|
|
138
|
+
protected _url: string;
|
|
139
|
+
protected _QoSManager: QoSManager | null;
|
|
140
|
+
protected _cursorManager: CursorManager | null;
|
|
141
|
+
protected _pingLossCounter: PkgLossCounter | null;
|
|
142
|
+
protected readonly _protocols: Protocols;
|
|
143
|
+
protected readonly _options: Omit<Required<Options>, 'ws' | 'deviceID' | 'bddID' | 'ttwID' | 'headers' | 'env'> & {
|
|
144
|
+
ws?: any;
|
|
145
|
+
deviceID?: string;
|
|
146
|
+
bddID?: string;
|
|
147
|
+
ttwID?: string;
|
|
148
|
+
headers?: FrontierMessageHeader[];
|
|
149
|
+
env: {
|
|
150
|
+
xUseEnv: 'boe' | 'ppe' | '';
|
|
151
|
+
xTTEnv: string;
|
|
152
|
+
};
|
|
153
|
+
};
|
|
154
|
+
readonly CLOSED = 3;
|
|
155
|
+
readonly CONNECTING = 0;
|
|
156
|
+
readonly OPEN = 1;
|
|
157
|
+
readonly CLOSING = 2;
|
|
158
|
+
constructor(options: Options);
|
|
159
|
+
protected _handleOnLine(): void;
|
|
160
|
+
protected _handleOffLine(): void;
|
|
161
|
+
protected _initGlobalEventListener(): void;
|
|
162
|
+
protected _dropGlobalEventListener(): void;
|
|
163
|
+
protected _handlePageHide(event: any): void;
|
|
164
|
+
protected _handlePageShow(event: any): void;
|
|
165
|
+
protected _generateUrl(endpoint: string): Promise<string>;
|
|
166
|
+
protected _connect(): Promise<void>;
|
|
167
|
+
protected _clearTimer(): void;
|
|
168
|
+
protected _clearPingTimer(): void;
|
|
169
|
+
protected _debug(...args: any[]): void;
|
|
170
|
+
protected _getIntervalValue(times: number): number;
|
|
171
|
+
protected _ping(): void;
|
|
172
|
+
protected _handleReconnectTimeout(): void;
|
|
173
|
+
protected _navigatorOnline(): boolean;
|
|
174
|
+
protected _handleReconnect(): void;
|
|
175
|
+
protected _onPageNetWorkChange(): void;
|
|
176
|
+
protected _wait(times: number): Promise<void>;
|
|
177
|
+
protected _disconnect(code?: number, reason?: string, needReconnect?: boolean): void;
|
|
178
|
+
protected _onTimeout(): void;
|
|
179
|
+
protected _onOpen: (openEvent: any) => void;
|
|
180
|
+
protected _sendAck(frameData: FrontierMessageFrame): void;
|
|
181
|
+
protected _onMessage: (messageEvent: any) => Promise<void>;
|
|
182
|
+
protected _onError: (errorEvent: any) => void;
|
|
183
|
+
protected _onClose: (event: any) => Promise<void>;
|
|
184
|
+
protected _removeWsListeners(): void;
|
|
185
|
+
protected _addWsListeners(): void;
|
|
186
|
+
protected _wsInstanceClose(code?: number, reason?: string): void;
|
|
187
|
+
protected _destroyWebSocket(code?: number, reason?: string, needReconnect?: boolean): void;
|
|
188
|
+
protected _dispatchOpenEvent(event: any): void;
|
|
189
|
+
protected _dispatchMessageEvent(event: any): void;
|
|
190
|
+
protected _dispatchAckMessageEvent(event: any): void;
|
|
191
|
+
protected _dispatchErrorEvent(event: any): void;
|
|
192
|
+
protected _dispatchCloseEvent(event: any): void;
|
|
193
|
+
get binaryType(): BinaryType;
|
|
194
|
+
set binaryType(value: BinaryType);
|
|
195
|
+
get retryCount(): number;
|
|
196
|
+
get bufferedAmount(): number;
|
|
197
|
+
get extensions(): string;
|
|
198
|
+
get protocol(): string;
|
|
199
|
+
get readyState(): number;
|
|
200
|
+
get url(): string;
|
|
201
|
+
onclose: ((event: CustomCloseEvent) => void) | null;
|
|
202
|
+
onerror: ((event: CustomErrorEvent) => void) | null;
|
|
203
|
+
onmessage: ((event: FrontierMessageEvent) => void) | null;
|
|
204
|
+
onopen: ((event: OpenEvent) => void) | null;
|
|
205
|
+
onStartReconnect: ((event: ReconnectEvent) => void) | null;
|
|
206
|
+
onReceiveAck: ((event: FrontierMessageEvent) => void) | null;
|
|
207
|
+
onStopImmediatelyReconnect: ((event: ReconnectEvent) => void) | null;
|
|
208
|
+
close(code?: number, reason?: string): void;
|
|
209
|
+
send(data: Message, options?: Omit<FrontierMessageFrame, 'payload' | 'SeqID' | 'LogIDNew' | 'LogID' | 'service' | 'method'> & {
|
|
210
|
+
logID?: number;
|
|
211
|
+
service?: number;
|
|
212
|
+
method?: number;
|
|
213
|
+
logIDNew?: string;
|
|
214
|
+
}): Promise<{
|
|
215
|
+
seqID: number;
|
|
216
|
+
logID: number;
|
|
217
|
+
logIDNew: string;
|
|
218
|
+
}>;
|
|
219
|
+
reconnect(options?: ReconnectOptions): Promise<void>;
|
|
220
|
+
connect(): Promise<void>;
|
|
221
|
+
addEventListener<T extends keyof FrontierEventMap>(type: T, listener: (event: any) => any): void;
|
|
222
|
+
dispatchEvent(event: any): void;
|
|
223
|
+
removeEventListener<T extends keyof FrontierEventMap>(type: T, listener: (event: any) => any): void;
|
|
224
|
+
pingOnce(): Promise<'success'>;
|
|
225
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export interface Header {
|
|
2
|
+
key: string;
|
|
3
|
+
value: string;
|
|
4
|
+
}
|
|
5
|
+
export declare function encodeHeader(message: Header): Uint8Array;
|
|
6
|
+
export declare function decodeHeader(binary: Uint8Array): Header;
|
|
7
|
+
export interface Frame {
|
|
8
|
+
SeqID: Long;
|
|
9
|
+
LogID: Long;
|
|
10
|
+
service: number;
|
|
11
|
+
method: number;
|
|
12
|
+
headers?: Header[];
|
|
13
|
+
payloadEncoding?: string;
|
|
14
|
+
payloadType?: string;
|
|
15
|
+
payload?: Uint8Array;
|
|
16
|
+
LogIDNew?: string;
|
|
17
|
+
serverTiming?: string;
|
|
18
|
+
msgID?: string;
|
|
19
|
+
frameType?: number;
|
|
20
|
+
}
|
|
21
|
+
export declare function encodeFrame(message: Frame): Uint8Array;
|
|
22
|
+
export declare function decodeFrame(binary: Uint8Array): Frame;
|
|
23
|
+
export interface Long {
|
|
24
|
+
low: number;
|
|
25
|
+
high: number;
|
|
26
|
+
unsigned: boolean;
|
|
27
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Frame, Header } from './bppb2';
|
|
2
|
+
export type FrontierMessageHeader = Header;
|
|
3
|
+
export type FrontierMessageFrame = Frame;
|
|
4
|
+
export type FrontierMessage = FrontierMessageFrame & {
|
|
5
|
+
textPayload?: string | null;
|
|
6
|
+
};
|
|
7
|
+
export declare function decodedFrame(buffer: Uint8Array): FrontierMessage;
|
|
8
|
+
export declare function encodeFrame(message: FrontierMessageFrame): Uint8Array;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { CursorFrameInfo } from '../utils/cursor-serialize';
|
|
2
|
+
export interface CursorDBSchema {
|
|
3
|
+
value: {
|
|
4
|
+
cursor_name: string;
|
|
5
|
+
cursor: number;
|
|
6
|
+
service?: number;
|
|
7
|
+
};
|
|
8
|
+
key: string;
|
|
9
|
+
}
|
|
10
|
+
export type MessageStrategy = 'ALL' | 'CONTINUE' | 'INSTANT';
|
|
11
|
+
export declare class CursorManager {
|
|
12
|
+
private _cursorNameSpace;
|
|
13
|
+
private _cursorFileName;
|
|
14
|
+
private _messageStrategy;
|
|
15
|
+
private _qosDB;
|
|
16
|
+
constructor(_cursorNameSpace: string, _cursorFileName: string, _messageStrategy: MessageStrategy);
|
|
17
|
+
openDB(): Promise<void>;
|
|
18
|
+
getCursors(): Promise<CursorFrameInfo | undefined>;
|
|
19
|
+
set(cursorName: string, cursor: number, service?: number): Promise<string>;
|
|
20
|
+
setCursors(cursorData: Uint8Array): Promise<void>;
|
|
21
|
+
get(cursorName: string): Promise<number | undefined>;
|
|
22
|
+
closeDB(): Promise<void>;
|
|
23
|
+
updateCursorFileName(cursorFileName: string): void;
|
|
24
|
+
get isReady(): boolean;
|
|
25
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export declare class EndpointManager {
|
|
2
|
+
private endpoints;
|
|
3
|
+
private maxRetries;
|
|
4
|
+
private currentIndex;
|
|
5
|
+
private currentEndpointTriesCount;
|
|
6
|
+
constructor(endpoints: string[], maxRetries: number);
|
|
7
|
+
resetEndpointConfig(): void;
|
|
8
|
+
resetTries(): void;
|
|
9
|
+
getCurrentEndpoint(): string;
|
|
10
|
+
getCurrentEndpointTriesCount(): number;
|
|
11
|
+
checkReachMaxTries(): boolean;
|
|
12
|
+
checkCurrentEndpointReachedMaxRetries(): boolean;
|
|
13
|
+
replaceBackupEndpointAndUpdateCount(): string;
|
|
14
|
+
getCurrentEndpointAndUpdateCount(): string;
|
|
15
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export declare class QoSManager {
|
|
2
|
+
private _qosDB;
|
|
3
|
+
private _intervalTimeoutId;
|
|
4
|
+
private _interval;
|
|
5
|
+
constructor();
|
|
6
|
+
protected _intervalFlush(): Promise<void>;
|
|
7
|
+
openDB(): Promise<void>;
|
|
8
|
+
flushExpired(): Promise<void>;
|
|
9
|
+
del(msgID: string): Promise<void>;
|
|
10
|
+
set(msgID: string, timestamp: number): Promise<string>;
|
|
11
|
+
get(msgID: string): Promise<{
|
|
12
|
+
message_id: string;
|
|
13
|
+
timestamp: number;
|
|
14
|
+
} | undefined>;
|
|
15
|
+
closeDB(): Promise<void>;
|
|
16
|
+
get isReady(): boolean;
|
|
17
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { FWS } from '../../fws';
|
|
2
|
+
import { QoSManager } from '../../manager/qos-manager';
|
|
3
|
+
import { FrontierMessageEvent } from '../../utils/event';
|
|
4
|
+
export interface FrontierQoSState {
|
|
5
|
+
enabled: boolean;
|
|
6
|
+
isQoSMessage: boolean;
|
|
7
|
+
isQoSAck: boolean;
|
|
8
|
+
isAckCleanupMessage: boolean;
|
|
9
|
+
ackMsgIds: string[];
|
|
10
|
+
}
|
|
11
|
+
export declare function getFrontierQoSState(this: FWS, ctx: FrontierMessageEvent): FrontierQoSState;
|
|
12
|
+
export declare function ensureQoSManager(this: FWS): Promise<QoSManager>;
|