@jolibox/native-bridge 1.1.16-beta.3 → 1.1.16-beta.5
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/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var Me=Object.defineProperty,Ie=Object.defineProperties;var Pe=Object.getOwnPropertyDescriptors;var I=Object.getOwnPropertySymbols;var re=Object.prototype.hasOwnProperty,te=Object.prototype.propertyIsEnumerable;var ee=(e,r,t)=>r in e?Me(e,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[r]=t,h=(e,r)=>{for(var t in r||(r={}))re.call(r,t)&&ee(e,t,r[t]);if(I)for(var t of I(r))te.call(r,t)&&ee(e,t,r[t]);return e},ne=(e,r)=>Ie(e,Pe(r));var ie=(e,r)=>{var t={};for(var n in e)re.call(e,n)&&r.indexOf(n)<0&&(t[n]=e[n]);if(e!=null&&I)for(var n of I(e))r.indexOf(n)<0&&te.call(e,n)&&(t[n]=e[n]);return t};var R=(e,r,t)=>new Promise((n,i)=>{var s=l=>{try{o(t.next(l))}catch(c){i(c)}},a=l=>{try{o(t.throw(l))}catch(c){i(c)}},o=l=>l.done?n(l.value):Promise.resolve(l.value).then(s,a);o((t=t.apply(e,r)).next())});function Ce(e){return!!(e!=null&&e.__nativeBuffers__)}var De=e=>{let r=atob(e),t=r.length,n=new Uint8Array(t);for(let i=0;i<t;i++)n[i]=r.charCodeAt(i);return n.buffer};function w(e){if(typeof e=="string")try{e=JSON.parse(e)}catch(t){return{}}if(typeof e!="object"||e===null)return{};if(!Ce(e))return e;let r=e.__nativeBuffers__;if(delete e.__nativeBuffers__,r)for(let t=0;t<r.length;t++){let n=r[t];if(n){let i;n.value?i=n.value:n.base64&&(i=De(n.base64)),typeof i!="undefined"&&i instanceof ArrayBuffer&&(e[n.key]=i)}}return e}var Ue=e=>{let r="",t=new Uint8Array(e),n=t.byteLength;for(let i=0;i<n;i++)r+=String.fromCharCode(t[i]);return btoa(r)};function se(e={},r=!1){let t=e,n=[];for(let[i,s]of Object.entries(t))if(s!==void 0&&s instanceof ArrayBuffer&&s.byteLength!==void 0){let a=r?{value:s,key:i}:{base64:Ue(s),key:i};n.push(a),delete t[i]}return n.length>0&&(t.__nativeBuffers__=n),t}var ae=Object.defineProperty;var Le=Object.getOwnPropertyDescriptor;var Je=(e,r)=>{for(var t in r)ae(e,t,{get:r[t],enumerable:!0})},ce=(e,r,t,n)=>{for(var i=n>1?void 0:n?Le(r,t):r,s=e.length-1,a;s>=0;s--)(a=e[s])&&(i=(n?a(r,t,i):a(i))||i);return n&&i&&ae(r,t,i),i},Fe=(e,r,t)=>new Promise((n,i)=>{var s=l=>{try{o(t.next(l))}catch(c){i(c)}},a=l=>{try{o(t.throw(l))}catch(c){i(c)}},o=l=>l.done?n(l.value):Promise.resolve(l.value).then(s,a);o((t=t.apply(e,r)).next())});if(typeof window!="undefined"&&!window.AbortController){let e=function(){this.signal=new r};e.prototype.abort=function(){this.signal._aborted=!0,typeof this.signal.onabort=="function"&&this.signal.onabort(new Event("abort"));let t=new Event("abort");this.signal.dispatchEvent(t)};let r=function(){this._aborted=!1,this.aborted=!1,this.onabort=null,this._eventListeners={}};Object.defineProperty(r.prototype,"aborted",{get:function(){return this._aborted}}),r.prototype.addEventListener=function(t,n){this._eventListeners[t]||(this._eventListeners[t]=[]),this._eventListeners[t].push(n)},r.prototype.removeEventListener=function(t,n){if(!this._eventListeners[t])return;let i=this._eventListeners[t].indexOf(n);i!==-1&&this._eventListeners[t].splice(i,1)},r.prototype.dispatchEvent=function(t){if(this._eventListeners[t.type])for(let n of this._eventListeners[t.type])n.call(this,t)},window.AbortController=e,window.AbortSignal=r}function je(e){return new Promise(r=>{setTimeout(()=>{r()},e)})}var le=class{constructor(){this.state="pending",this.promise=new Promise((e,r)=>{this.resolve=t=>{this.state==="pending"&&(this.state="fulfilled",e(t))},this.reject=t=>{this.state==="pending"&&(this.state="rejected",r(t))}})}};function G(e){return typeof e=="string"}function y(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)&&!(e instanceof RegExp)&&!(e instanceof Date)}function Be(e){return typeof e=="undefined"}function He(e){return Be(e)||e===null}function ue(e){return typeof e=="function"}function de(e){return y(e)&&ue(e.then)}function me(e){let r=e,t=null,n=function(...i){return t||(t=new r(...i)),t};return n.prototype=r.prototype,n}var Ve=(e=>(e[e.DEVELOPER_FILE_NOT_FOUND=0]="DEVELOPER_FILE_NOT_FOUND",e[e.INTERNAL_IOS_CAN_NOT_FOUND_PKG=1]="INTERNAL_IOS_CAN_NOT_FOUND_PKG",e[e.USER_IOS_LOAD_TIMEOUT=2]="USER_IOS_LOAD_TIMEOUT",e[e.INTERNAL_IOS_PKG_LOAD_ERROR=3]="INTERNAL_IOS_PKG_LOAD_ERROR",e[e.INTERNAL_IOS_PKG_PARSE_FAIL=4]="INTERNAL_IOS_PKG_PARSE_FAIL",e[e.USER_IOS_GET_EMPTY_DATA=5]="USER_IOS_GET_EMPTY_DATA",e[e.USER_ANDROID_GET_PKG_FAIL=6]="USER_ANDROID_GET_PKG_FAIL",e[e.DEVELOPER_ANDROID_PACKAGE_FILE_UNEXPECTED_REQUIRE=7]="DEVELOPER_ANDROID_PACKAGE_FILE_UNEXPECTED_REQUIRE",e))(Ve||{}),Ke=class extends Error{constructor(e){if(typeof e=="string"){super(e),this.priority="P1";return}super(e.message),this.priority="P1",this.stack=e.stack,this.raw=e}},P=class extends Ke{constructor(){super(...arguments),this.kind="INTERNAL_ERROR"}};var ge=class extends P{constructor(){super(...arguments),this.name="INTERNAL_INVOKE_NATIVE_ERROR"}},fe=class extends P{constructor(e,r,t,n){super(e),this.errNo=r,this.name="INTERNAL_APPLY_NATIVE_ERROR",this.errorType=t,this.errorCode=n}};var pe=class extends P{constructor(){super(...arguments),this.name="INTERNAL_JSCORE_ERROR",this.priority="P0"}};var C=class extends P{constructor(){super(...arguments),this.name="INTERNAL_METRIC_REPORT_ERROR"}};function O(e){return(...r)=>{var t,n;((n=(t=globalThis.VConsole)==null?void 0:t[e])!=null?n:globalThis.console[e])(...r)}}var D={log:O("log"),warn:O("warn"),info:O("info"),error:O("error"),debug:O("debug")};Object.assign(globalThis,{logger:D});var $e=Symbol.for("Jolibox.canIUseMap"),Ge={};globalThis[$e]=Ge;var ze=(e=>(e[e.System=1e3]="System",e[e.ErrorTrace=1001]="ErrorTrace",e[e.UserDefined=1002]="UserDefined",e))(ze||{}),We=(e=>(e.MiniGame="mini-game",e.MiniDrama="mini-drama",e.App="app",e.WebSDK="web-sdk",e.AppSDK="app-sdk",e))(We||{}),Qe=(e=>(e[e.App=0]="App",e[e.H5=1]="H5",e[e.Weapp=2]="Weapp",e[e.Alipay=3]="Alipay",e[e.Gcash=4]="Gcash",e[e.Dana=5]="Dana",e[e.Umma=6]="Umma",e[e.WebSDK=1e3]="WebSDK",e[e.AppSDK=1001]="AppSDK",e[e.Other=9999]="Other",e))(Qe||{});function Ye(){try{if(window.__joliboxLocalStorage__)return window.__joliboxLocalStorage__;let e=Object.getOwnPropertyDescriptor(window,"localStorage");if(e&&e.get){let n=e.get.call(window);return window.__joliboxLocalStorage__=n,n}if(e=Object.getOwnPropertyDescriptor(Object.getPrototypeOf(window),"localStorage"),e&&e.get)return e.get.call(window);let r=Window.prototype,t=Object.getOwnPropertyDescriptor(r,"localStorage");if(t&&t.get){let n=t.get.call(window);return window.__joliboxLocalStorage__=n,n}return localStorage}catch(e){return console.warn("Failed to get original localStorage, fallback to default implementation",e),localStorage}}Ye();var mr={isiOS:navigator.userAgent.includes("iPhone")||navigator.userAgent.includes("iPod")||navigator.userAgent.includes("iPad")||navigator.userAgent.includes("iPhone OS"),iosVersion:()=>{let e=navigator.appVersion.match(/OS (\d+)_(\d+)_?(\d+)?/);return[parseInt(e[1],10),parseInt(e[2],10),parseInt(e[3]||"0",10)]},isAndroid:navigator.userAgent.includes("Android"),isMac:navigator.userAgent.includes("Mac"),isFacebook:navigator.userAgent.includes("FB_IAB"),isPC:!navigator.userAgent.includes("iPhone")&&!navigator.userAgent.includes("Android")};var H=class V{constructor(r){this.element=r,this.next=V.Undefined,this.prev=V.Undefined}};H.Undefined=new H(void 0);var d=H,qe=class{constructor(){this._first=d.Undefined,this._last=d.Undefined,this._size=0}get size(){return this._size}isEmpty(){return this._first===d.Undefined}clear(){let e=this._first;for(;e!==d.Undefined;){let r=e.next;e.prev=d.Undefined,e.next=d.Undefined,e=r}this._first=d.Undefined,this._last=d.Undefined,this._size=0}unshift(e){return this._insert(e,!1)}push(e){return this._insert(e,!0)}_insert(e,r){let t=new d(e);if(this._first===d.Undefined)this._first=t,this._last=t;else if(r){let i=this._last;this._last=t,t.prev=i,i.next=t}else{let i=this._first;this._first=t,t.next=i,i.prev=t}this._size+=1;let n=!1;return()=>{n||(n=!0,this._remove(t))}}shift(){if(this._first!==d.Undefined){let e=this._first.element;return this._remove(this._first),e}}pop(){if(this._last!==d.Undefined){let e=this._last.element;return this._remove(this._last),e}}_remove(e){if(e.prev!==d.Undefined&&e.next!==d.Undefined){let r=e.prev;r.next=e.next,e.next.prev=r}else e.prev===d.Undefined&&e.next===d.Undefined?(this._first=d.Undefined,this._last=d.Undefined):e.next===d.Undefined?(this._last=this._last.prev,this._last.next=d.Undefined):e.prev===d.Undefined&&(this._first=this._first.next,this._first.prev=d.Undefined);this._size-=1}*[Symbol.iterator](){let e=this._first;for(;e!==d.Undefined;)yield e.element,e=e.next}},Xe=0,T=class{constructor(e){this.value=e,this.id=Xe++}},k=class{constructor(e){this.options=e,this._size=0}dispose(e){var r,t;this._disposed||(this._disposed=!0,this._listeners&&(e?(this._listeners instanceof T&&(this._listeners=[this._listeners]),this._listeners=this._listeners.filter(n=>(n==null?void 0:n.value)===e)):(this._listeners=void 0,this._size=0)),(t=(r=this.options)==null?void 0:r.onDidRemoveLastListener)==null||t.call(r))}get event(){var e;return(e=this._event)!=null||(this._event=(r,t)=>{var n,i,s,a,o,l;if(this._disposed)return()=>{console.info("[Jolibox SDK] Emitter is _disposed")};t&&(r=r.bind(t));let c=new T(r);return this._listeners?this._listeners instanceof T?this._listeners=[this._listeners,c]:this._listeners.push(c):((i=(n=this.options)==null?void 0:n.onWillAddFirstListener)==null||i.call(n,this),this._listeners=c,(a=(s=this.options)==null?void 0:s.onDidFirstListener)==null||a.call(s,this)),(l=(o=this.options)==null?void 0:o.onDidAddListener)==null||l.call(o,this),this._size++,()=>{var u,m,g,p;if(!this._disposed){if(this._listeners instanceof T)this._listeners.id===c.id&&(this._listeners=void 0,this._size=0,(m=(u=this.options)==null?void 0:u.onDidRemoveLastListener)==null||m.call(u));else if(this._listeners){let _=this._listeners.indexOf(c);_>=0&&(this._listeners.splice(_,1),this._size--,this._size===0&&((p=(g=this.options)==null?void 0:g.onDidRemoveLastListener)==null||p.call(g)))}}}}),this._event}_deliver(e,r){var t;if(!e)return;let n=((t=this.options)==null?void 0:t.onListenerError)||Error.constructor;if(!n){e.value(r);return}try{e.value(r)}catch(i){n(i)}}fire(e){this._listeners&&(this._listeners instanceof T?this._deliver(this._listeners,e):this._listeners.forEach(r=>this._deliver(r,e)))}hasListeners(){return this._size>0}},U=class{constructor(){this.listeners=new Map,this.listerHandlerMap=new WeakMap,this.cachedEventQueue=new Map}on(e,r){var t;let n=(t=this.listeners.get(e))!=null?t:new k,i=o=>r(...o.args),s=n.event(i);this.listerHandlerMap.set(r,{handler:i,dispose:s}),this.listeners.set(e,n);let a=this.cachedEventQueue.get(e);if(a)for(let o of a)r(...o.args)}flushCachedEvent(e){e?this.cachedEventQueue.delete(e):this.cachedEventQueue.clear()}off(e,r){let t=this.listerHandlerMap.get(r);t&&(t.dispose(),this.listerHandlerMap.delete(r))}emit(e,...r){let t=this.listeners.get(e);if(t)t.fire({event:e,args:r});else{let n=this.cachedEventQueue.get(e);n||(n=new qe,this.cachedEventQueue.set(e,n)),n.push({args:r})}}},K={};Je(K,{None:()=>Ze,filter:()=>rr,once:()=>he,toPromise:()=>er});var Ze=()=>(console.log("[Jolibox SDK] None Event"),()=>{console.log("[Jolibox SDK] None Event dispose")});function er(e){return new Promise(r=>he(e)(r))}function he(e){return(r,t=null)=>{let n=!1;return e(i=>{if(!n)return n=!0,r.call(t,i)},null)}}function rr(e,r){return(t=>{let n,i={onWillAddFirstListener(){n=t(s.fire,s)}},s=new k(i);return s.event})((t,n=null)=>e(i=>r(i)&&t.call(n,i),null))}var B=Symbol.for("Jolibox.hostEmitter"),tr=()=>{let e=new U;return globalThis[B]||(globalThis[B]={on:e.on.bind(e),off:e.off.bind(e),emit:e.emit.bind(e)}),globalThis[B]},gr=tr();function nr(e,r){let t=Math.min(e.length,r.length);for(let n=0;n<t;n++)ir(e[n],r[n])}function ir(e,r){if(G(r)){if(typeof e!==r)throw new Error(`argument does not match constraint: typeof ${r}`)}else if(ue(r)){try{if(e instanceof r)return}catch(t){}if(!He(e)&&e.constructor===r||r.length===1&&r.call(void 0,e)===!0)return;throw new Error("[Jolibox SDK]argument does not match one of these constraints: arg instanceof constraint, arg.constructor === constraint, nor constraint(arg) === true")}}var $=class{constructor(){this._commands=new Map,this._onDidRegisterCommand=new k,this.onDidRegisterCommand=this._onDidRegisterCommand.event,console.log("[Jolibox SDK] command registry")}registerCommand(e){if(!e)throw new Error("invalid command");if(e.metadata&&Array.isArray(e.metadata.args)){let t=[];for(let i of e.metadata.args)t.push(i.constraint);let n=e.handler;e.handler=function(...i){return nr(i,t),n(...i)}}let{id:r}=e;this._commands.get(r)&&console.info(`[Jolibox SDK] duplicated command is registered ${r}`),this._commands.set(r,e),this._onDidRegisterCommand.fire(r)}getCommand(e){return this._commands.get(e)}getCommands(){let e=new Map;for(let r of this._commands.keys()){let t=this.getCommand(r);t&&e.set(r,t)}return e}};$=ce([me],$);var oe=class{constructor(){this._onWillExecuteCommand=new k,this.onWillExecuteCommand=this._onWillExecuteCommand.event,this._onDidExecuteCommand=new k,this.onDidExecuteCommand=this._onDidExecuteCommand.event,this.registry=new $,this._starActivation=null}_activateStar(){return this._starActivation||(this._starActivation=je(3e4)),this._starActivation}executeCommand(e,...r){return Fe(this,null,function*(){return this.registry.getCommand(e)?this._tryExecuteCommand(e,r):(yield Promise.all([Promise.race([this._activateStar(),K.toPromise(K.filter(this.registry.onDidRegisterCommand,t=>t===e))])]),this._tryExecuteCommand(e,r))})}executeCommandThowErr(e,...r){if(!this.registry.getCommand(e))throw new Error(`command '${e}' not found`);let t=this.registry.getCommand(e);this._onWillExecuteCommand.fire({commandId:e,args:r});let n=this.invokeFunction(t.handler,...r);return this._onDidExecuteCommand.fire({commandId:e,args:r}),n}_tryExecuteCommand(e,r){let t=this.registry.getCommand(e);if(!t)return Promise.reject(new Error(`command '${e}' not found`));try{this._onWillExecuteCommand.fire({commandId:e,args:r});let n=this.invokeFunction(t.handler,...r);return this._onDidExecuteCommand.fire({commandId:e,args:r}),Promise.resolve(n)}catch(n){return Promise.reject(n)}}invokeFunction(e,...r){let t=!1;try{return e(...r)}finally{t=!0}}};oe=ce([me],oe);var fr=Symbol.for("Jolibox.commands");function A(e,r){return`[${e}]:${r}`}var ve=()=>!!(navigator.userAgent||"").includes("JoliboxPlatformSDK");var E="custom_event_";var be=[],_e=[],ye=["env","createRequestTask","login"],L="__batch_event__";var sr=e=>e==="pv"?e:"default",N=class{constructor(r){this.interval=30;this.lastReportTime=0;this.cache={};let{reporter:t,interval:n=30,eventName:i,tagNameOrder:s,metricName:a,type:o}=r;this.reporter=t,this.interval=n,this.eventName=i,this.tagNameOrder=s,this.metricName=a,this.type=sr(o)}report(r){this.type==="pv"?this.addPVPoint(r):this.addPoint(r),this.tryReport(!1)}flush(){this.tryReport(!0)}tryReport(r){if(Object.keys(this.cache).length){if(r){this.reporter(this.processPoints(this.cache)),this.clearPoints();return}this.lastReportTime=this.lastReportTime||Date.now(),Date.now()-this.lastReportTime>=this.interval*1e3&&(this.reporter(this.processPoints(this.cache)),this.clearPoints(),this.lastReportTime=Date.now())}}addPoint(r){let t=(n,i,s,a)=>{let o=i.shift();if(o){let l=a[o];n[l]||(n[l]={}),t(n[l],i,s,a)}else n[s]||(n[s]=[]),n[s].push(a[s])};t(this.cache,[...this.tagNameOrder],this.metricName,r)}addPVPoint(r){let t=(i,s,a,o)=>{let l=s.shift();if(!l&&y(o))throw new C(`report value failed to match tagNameOrder, ${JSON.stringify(n)}`);if(l){let c=[];if(y(o))c.push(...Object.keys(o));else if(G(o)){if(s.length>0)throw new C(`report value failed to match tagNameOrder, ${JSON.stringify(n)}`);c.push(o)}else throw new C(`expected metric value to be a string, but got a(n) ${typeof o}, ${JSON.stringify(n)}`);c.forEach(u=>{i[u]||(i[u]={});let m=y(o)?o[u]:o;t(i[u],[...s],a,m)})}else i[a]?i[a]++:i[a]=1},n={point:r,metricName:this.metricName,tagNameOrder:this.tagNameOrder};t(this.cache,[...this.tagNameOrder],this.metricName,r)}processPoints(r){return{eventName:this.eventName,tagNameOrder:this.tagNameOrder,metricName:this.metricName,metricAggregateType:this.type==="pv"?"itoa":"arr",data:r}}clearPoints(){this.cache={}}},Ee=!1,z,W,Q;function Ne(e,r){Ee||(z=new N({eventName:"jolibox_invoke",tagNameOrder:["status","method","errNo","errMsg","isForeground"],metricName:"duration",reporter(i){e.invoke("trackAsync",JSON.stringify({event:"reportMetrics",data:i}),-1)}}),W=new N({eventName:"jolibox_invoke_js2native",tagNameOrder:["status","method","isForeground"],metricName:"duration",reporter(i){e.invoke("trackAsync",JSON.stringify({event:"reportMetrics",data:i}),-1)}}),Q=new N({eventName:"jolibox_invoke_native2js",tagNameOrder:["status","method","isForeground"],metricName:"duration",reporter(i){e.invoke("trackAsync",JSON.stringify({event:"reportMetrics",data:i}),-1)}}),r("onJoliboxEnterBackground",()=>{z.flush(),W.flush(),Q.flush()}),Ee=!0);function t(i){var S,x;let{method:s,args:a,startTime:o,isForeground:l,errMsg:c=`${s}:fail no errMsg`,errNo:u=0,__timing:m={receiveJSInvoke:0,invokeCallback:0}}=i,{receiveJSInvoke:g,invokeCallback:p}=m,_=(x=(S=c.match(/\S:(\S+)\s?/))==null?void 0:S[1])!=null?x:"fail";z.report({status:_,method:n(s,a),errNo:`${u}`,errMsg:c,isForeground:l,duration:Date.now()-o}),o&&g&&p&&(W.report({status:_,method:s,isForeground:l,duration:Number((g-o).toFixed(3))}),Q.report({status:_,method:s,isForeground:l,duration:Number((Date.now()-p).toFixed(3))}))}function n(i,s){return(i==="callHostMethod"||i==="callHostMethodSync")&&s!=null&&s.method?`${i}-${s.method}`:i}return t}var Y=[],or=!1;function xe(e,r){let t=0,n=!0,i=new Map,s=Ne(e,r);r("onJoliboxEnterBackground",()=>{n=!1}),r("onJoliboxEnterForeground",()=>{n=!0,Y.forEach(g=>R(this,[g],function*({method:c,args:u,resolve:m}){let p=yield o(c,u);m(p)})),Y.length=0});let a=(c,u)=>{let m=i.get(Number(c));if(!m)return;let g=w(u);m(g),i.delete(Number(c))},o=(c,u)=>{var X,Z;let m=Date.now(),g=`${n}`;t+=1;let p=new le;if(i.set(t,p.resolve),!n&&_e.includes(c))return new Promise(v=>{Y.push({method:c,args:u,resolve:v})});let S=ne(h({},{method:c,startTime:m,args:u,isForeground:g}),{invokeType:"js-bridge"}),x=!or&&be.includes(c),F=se(u,x),j=x?F:JSON.stringify(F),f;if(c.endsWith("Sync")||ye.includes(c)?f=(X=e.call)==null?void 0:X.call(e,c,F,t):typeof j=="string"?f=e.invoke(c,j,t):f=(Z=e.call)==null?void 0:Z.call(e,c,j,t),f){try{typeof f=="string"&&(f=JSON.parse(f)),f=w(f)}catch(v){D.error(v)}return i.delete(t),f.errorCode&&(f.errorCode=A(c,f.errorCode)),s(h(h({},S),f)),f}return c.endsWith("Sync")&&i.delete(t),p.promise.then(v=>(v.errorCode&&(v.errorCode=A(c,v.errorCode)),s(h(h({},S),v)),v))};return{invokeNative:o,applyNative:(c,u)=>{let m=o(c,u);return de(m)?m.then(g=>Se(c,g)):Se(c,m)},invokeHandler:a}}function Se(e,r){if(!y(r)){D.warn(`[Jolibox SDK]${e} no response value`);return}let o=r,{errMsg:t,errNo:n,errorType:i,errorCode:s}=o,a=ie(o,["errMsg","errNo","errorType","errorCode"]);if(t&&t!==`${e}:ok`)throw new fe(t,n,i,s);return a}function Re(e){let r=new U,t=new U,n=new N({eventName:"jolibox_publish",tagNameOrder:["type","event"],metricName:"duration",reporter(i){e.invoke("trackAsync",JSON.stringify({event:"reportMetrics",data:i}),-1)}});return r.on("onJoliboxEnterBackground",()=>{n.flush()}),{onNative:r.on.bind(r),offNative:r.off.bind(r),subscribe:t.on.bind(t),unsubscribe:t.off.bind(t),subscribeHandler(i,s,a){let o=w(s),l;if(o.__extra){l=o.params;let{type:c,startTime:u}=o.__extra;n.report({type:c,event:i,duration:Date.now()-u})}else l=o;if(i===L){l.forEach(u=>{let[m,g]=u;try{t.emit(m.slice(E.length),g,a)}catch(p){}});return}if(i.startsWith(E)){t.emit(i.slice(E.length),l,a);return}r.emit(i,l,a)}}}function we(e){let r=new Map,t;return(i,s,a,o)=>{if(o){let c=a?[a]:"*";e.publish(`${E}${i}`,s,c);return}t||(t=Promise.resolve().then(()=>{r.forEach((c,u)=>{try{let m=u?[u]:"*";e.publish(L,c,m)}catch(m){}}),t=void 0,r.clear()}));let l=r.get(a);l||(l=[],r.set(a,l)),l.push([`${E}${i}`,s])}}function q(e){let{subscribeHandler:r,onNative:t,offNative:n,subscribe:i,unsubscribe:s}=Re(e),{invokeNative:a,invokeHandler:o,applyNative:l}=xe(e,t),c=we(e);return{invokeHandler:o,subscribeHandler:r,applyNative:l,invokeNative:a,onNative:t,offNative:n,publish:c,subscribe:i,unsubscribe:s}}function J(e,r){return{params:e,__extra:{startTime:Date.now(),type:r}}}var M,b={trigger(){},exit(){return Promise.resolve(!1)},onReady(e){b.trigger=e},onDoExit(e){b.exit=e}},Oe=e=>{let r=window.prompt("invoke",JSON.stringify({event:"envSync",paramsString:JSON.stringify({})}));if(!r)e.onError(new ge("native env failed"));else{let{data:t}=JSON.parse(r);return t!=null?t:void 0}};if(window.webkit){let e=window.webkit.messageHandlers,r=(i="")=>{b.trigger(),e.onDocumentReady.postMessage({path:i})},t=i=>R(void 0,null,function*(){let s=yield b.exit();e.doExit.postMessage({uuid:i,shouldInterrupt:s})});M={onDocumentReady:r,doExit:t,invoke(i,s,a){e.invoke.postMessage({event:i,paramsString:s,callbackId:a})},publish(i,s,a){let o=J(s,"joliboxJSCore");window.prompt("publish",JSON.stringify({event:i,paramsString:JSON.stringify(o),webviewIds:a}))},call(i,s,a){let o=window.prompt("invoke",JSON.stringify({event:i,paramsString:JSON.stringify(s),callbackId:a}));if(o)return JSON.parse(o)}};let n={onDocumentReady:r,env:Oe,doExit:t};globalThis.joliboxJSCore=h({},n)}if(window.JoliAndroidSDKBridge){let e=window.JoliAndroidSDKBridge,r=(i="")=>{b.trigger(),e.onDocumentReady(JSON.stringify({path:i}))},t=i=>R(void 0,null,function*(){let s=yield b.exit();e.doExit(JSON.stringify({uuid:i,shouldInterrupt:s}))});M={onDocumentReady:r,invoke(i,s,a){e.invoke(JSON.stringify({event:i,paramsString:s,callbackId:a}))},doExit:t,publish(i,s,a){let o=J(s,"joliboxJSCore");e.publish({event:i,paramsString:JSON.stringify(o),webviewIds:a})},call(i,s,a){let o=window.prompt("invoke",JSON.stringify({event:i,paramsString:JSON.stringify(s),callbackId:a}));if(o)return JSON.parse(o)}};let n={onDocumentReady:r,env:Oe,doExit:t};globalThis.joliboxJSCore=h({},n)}var ke=M;if(!ke&&ve())throw new pe("No joliboxJScore is found, native bridge not found.");var ar=h({},ke),Ae=q(ar),{invokeHandler:Te}=Ae,{applyNative:bt,invokeNative:_t,onNative:cr,offNative:yt,subscribeHandler:lr,publish:Et,subscribe:Nt,unsubscribe:St}=Ae,xt=(e,r)=>{cr(e,(...t)=>{var n;(n=t[0])!=null&&n.errorCode&&(t[0].errorCode=A(e,t[0].errorCode)),r(...t)})};globalThis.joliboxJSBridge={callHandler:Te,invokeHandler:Te,subscribeHandler:lr};export{b as RuntimeLoader,bt as applyNative,_t as invokeNative,yt as offNative,cr as onNative,xt as onNativeWithError,Et as publish,Nt as subscribe,lr as subscribeHandler,St as unsubscribe};
|
|
1
|
+
var Pe=Object.defineProperty,Ce=Object.defineProperties;var De=Object.getOwnPropertyDescriptors;var M=Object.getOwnPropertySymbols;var ne=Object.prototype.hasOwnProperty,ie=Object.prototype.propertyIsEnumerable;var te=(e,r,t)=>r in e?Pe(e,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[r]=t,h=(e,r)=>{for(var t in r||(r={}))ne.call(r,t)&&te(e,t,r[t]);if(M)for(var t of M(r))ie.call(r,t)&&te(e,t,r[t]);return e},se=(e,r)=>Ce(e,De(r));var oe=(e,r)=>{var t={};for(var n in e)ne.call(e,n)&&r.indexOf(n)<0&&(t[n]=e[n]);if(e!=null&&M)for(var n of M(e))r.indexOf(n)<0&&ie.call(e,n)&&(t[n]=e[n]);return t};var x=(e,r,t)=>new Promise((n,i)=>{var s=l=>{try{o(t.next(l))}catch(c){i(c)}},a=l=>{try{o(t.throw(l))}catch(c){i(c)}},o=l=>l.done?n(l.value):Promise.resolve(l.value).then(s,a);o((t=t.apply(e,r)).next())});function Le(e){return!!(e!=null&&e.__nativeBuffers__)}var Ue=e=>{let r=atob(e),t=r.length,n=new Uint8Array(t);for(let i=0;i<t;i++)n[i]=r.charCodeAt(i);return n.buffer};function T(e){if(typeof e=="string")try{e=JSON.parse(e)}catch(t){return{}}if(typeof e!="object"||e===null)return{};if(!Le(e))return e;let r=e.__nativeBuffers__;if(delete e.__nativeBuffers__,r)for(let t=0;t<r.length;t++){let n=r[t];if(n){let i;n.value?i=n.value:n.base64&&(i=Ue(n.base64)),typeof i!="undefined"&&i instanceof ArrayBuffer&&(e[n.key]=i)}}return e}var Je=e=>{let r="",t=new Uint8Array(e),n=t.byteLength;for(let i=0;i<n;i++)r+=String.fromCharCode(t[i]);return btoa(r)};function ae(e={},r=!1){let t=e,n=[];for(let[i,s]of Object.entries(t))if(s!==void 0&&s instanceof ArrayBuffer&&s.byteLength!==void 0){let a=r?{value:s,key:i}:{base64:Je(s),key:i};n.push(a),delete t[i]}return n.length>0&&(t.__nativeBuffers__=n),t}var le=Object.defineProperty;var Be=Object.getOwnPropertyDescriptor;var Fe=(e,r)=>{for(var t in r)le(e,t,{get:r[t],enumerable:!0})},ue=(e,r,t,n)=>{for(var i=n>1?void 0:n?Be(r,t):r,s=e.length-1,a;s>=0;s--)(a=e[s])&&(i=(n?a(r,t,i):a(i))||i);return n&&i&&le(r,t,i),i},je=(e,r,t)=>new Promise((n,i)=>{var s=l=>{try{o(t.next(l))}catch(c){i(c)}},a=l=>{try{o(t.throw(l))}catch(c){i(c)}},o=l=>l.done?n(l.value):Promise.resolve(l.value).then(s,a);o((t=t.apply(e,r)).next())});if(typeof window!="undefined"&&!window.AbortController){let e=function(){this.signal=new r};e.prototype.abort=function(){this.signal._aborted=!0,typeof this.signal.onabort=="function"&&this.signal.onabort(new Event("abort"));let t=new Event("abort");this.signal.dispatchEvent(t)};let r=function(){this._aborted=!1,this.aborted=!1,this.onabort=null,this._eventListeners={}};Object.defineProperty(r.prototype,"aborted",{get:function(){return this._aborted}}),r.prototype.addEventListener=function(t,n){this._eventListeners[t]||(this._eventListeners[t]=[]),this._eventListeners[t].push(n)},r.prototype.removeEventListener=function(t,n){if(!this._eventListeners[t])return;let i=this._eventListeners[t].indexOf(n);i!==-1&&this._eventListeners[t].splice(i,1)},r.prototype.dispatchEvent=function(t){if(this._eventListeners[t.type])for(let n of this._eventListeners[t.type])n.call(this,t)},window.AbortController=e,window.AbortSignal=r}function Ve(e){return new Promise(r=>{setTimeout(()=>{r()},e)})}var de=class{constructor(){this.state="pending",this.promise=new Promise((e,r)=>{this.resolve=t=>{this.state==="pending"&&(this.state="fulfilled",e(t))},this.reject=t=>{this.state==="pending"&&(this.state="rejected",r(t))}})}};function z(e){return typeof e=="string"}function y(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)&&!(e instanceof RegExp)&&!(e instanceof Date)}function He(e){return typeof e=="undefined"}function Ke(e){return He(e)||e===null}function me(e){return typeof e=="function"}function ge(e){return y(e)&&me(e.then)}function fe(e){let r=e,t=null,n=function(...i){return t||(t=new r(...i)),t};return n.prototype=r.prototype,n}var Ge=(e=>(e[e.DEVELOPER_FILE_NOT_FOUND=0]="DEVELOPER_FILE_NOT_FOUND",e[e.INTERNAL_IOS_CAN_NOT_FOUND_PKG=1]="INTERNAL_IOS_CAN_NOT_FOUND_PKG",e[e.USER_IOS_LOAD_TIMEOUT=2]="USER_IOS_LOAD_TIMEOUT",e[e.INTERNAL_IOS_PKG_LOAD_ERROR=3]="INTERNAL_IOS_PKG_LOAD_ERROR",e[e.INTERNAL_IOS_PKG_PARSE_FAIL=4]="INTERNAL_IOS_PKG_PARSE_FAIL",e[e.USER_IOS_GET_EMPTY_DATA=5]="USER_IOS_GET_EMPTY_DATA",e[e.USER_ANDROID_GET_PKG_FAIL=6]="USER_ANDROID_GET_PKG_FAIL",e[e.DEVELOPER_ANDROID_PACKAGE_FILE_UNEXPECTED_REQUIRE=7]="DEVELOPER_ANDROID_PACKAGE_FILE_UNEXPECTED_REQUIRE",e))(Ge||{}),$e=class extends Error{constructor(e){if(typeof e=="string"){super(e),this.priority="P1";return}super(e.message),this.priority="P1",this.stack=e.stack,this.raw=e}},P=class extends $e{constructor(){super(...arguments),this.kind="INTERNAL_ERROR"}};var pe=class extends P{constructor(){super(...arguments),this.name="INTERNAL_INVOKE_NATIVE_ERROR"}},he=class extends P{constructor(e,r,t,n){super(e),this.errNo=r,this.name="INTERNAL_APPLY_NATIVE_ERROR",this.errorType=t,this.errorCode=n}};var ve=class extends P{constructor(){super(...arguments),this.name="INTERNAL_JSCORE_ERROR",this.priority="P0"}};var C=class extends P{constructor(){super(...arguments),this.name="INTERNAL_METRIC_REPORT_ERROR"}};function w(e){return(...r)=>{var t,n;((n=(t=globalThis.VConsole)==null?void 0:t[e])!=null?n:globalThis.console[e])(...r)}}var D={log:w("log"),warn:w("warn"),info:w("info"),error:w("error"),debug:w("debug")};Object.assign(globalThis,{logger:D});var ze=Symbol.for("Jolibox.canIUseMap"),We={};globalThis[ze]=We;var qe=(e=>(e[e.System=1e3]="System",e[e.ErrorTrace=1001]="ErrorTrace",e[e.UserDefined=1002]="UserDefined",e))(qe||{}),Qe=(e=>(e.MiniGame="mini-game",e.MiniDrama="mini-drama",e.App="app",e.WebSDK="web-sdk",e.AppSDK="app-sdk",e))(Qe||{}),Ye=(e=>(e[e.App=0]="App",e[e.H5=1]="H5",e[e.Weapp=2]="Weapp",e[e.Alipay=3]="Alipay",e[e.Gcash=4]="Gcash",e[e.Dana=5]="Dana",e[e.Umma=6]="Umma",e[e.WebSDK=1e3]="WebSDK",e[e.AppSDK=1001]="AppSDK",e[e.Other=9999]="Other",e))(Ye||{});function Xe(){try{if(window.__joliboxLocalStorage__)return window.__joliboxLocalStorage__;let e=Object.getOwnPropertyDescriptor(window,"localStorage");if(e&&e.get){let n=e.get.call(window);return window.__joliboxLocalStorage__=n,n}if(e=Object.getOwnPropertyDescriptor(Object.getPrototypeOf(window),"localStorage"),e&&e.get)return e.get.call(window);let r=Window.prototype,t=Object.getOwnPropertyDescriptor(r,"localStorage");if(t&&t.get){let n=t.get.call(window);return window.__joliboxLocalStorage__=n,n}return localStorage}catch(e){return console.warn("Failed to get original localStorage, fallback to default implementation",e),localStorage}}Xe();var fr={isiOS:navigator.userAgent.includes("iPhone")||navigator.userAgent.includes("iPod")||navigator.userAgent.includes("iPad")||navigator.userAgent.includes("iPhone OS"),iosVersion:()=>{let e=navigator.appVersion.match(/OS (\d+)_(\d+)_?(\d+)?/);return[parseInt(e[1],10),parseInt(e[2],10),parseInt(e[3]||"0",10)]},isAndroid:navigator.userAgent.includes("Android"),isMac:navigator.userAgent.includes("Mac"),isFacebook:navigator.userAgent.includes("FB_IAB"),isPC:!navigator.userAgent.includes("iPhone")&&!navigator.userAgent.includes("Android")};var H=class K{constructor(r){this.element=r,this.next=K.Undefined,this.prev=K.Undefined}};H.Undefined=new H(void 0);var d=H,Ze=class{constructor(){this._first=d.Undefined,this._last=d.Undefined,this._size=0}get size(){return this._size}isEmpty(){return this._first===d.Undefined}clear(){let e=this._first;for(;e!==d.Undefined;){let r=e.next;e.prev=d.Undefined,e.next=d.Undefined,e=r}this._first=d.Undefined,this._last=d.Undefined,this._size=0}unshift(e){return this._insert(e,!1)}push(e){return this._insert(e,!0)}_insert(e,r){let t=new d(e);if(this._first===d.Undefined)this._first=t,this._last=t;else if(r){let i=this._last;this._last=t,t.prev=i,i.next=t}else{let i=this._first;this._first=t,t.next=i,i.prev=t}this._size+=1;let n=!1;return()=>{n||(n=!0,this._remove(t))}}shift(){if(this._first!==d.Undefined){let e=this._first.element;return this._remove(this._first),e}}pop(){if(this._last!==d.Undefined){let e=this._last.element;return this._remove(this._last),e}}_remove(e){if(e.prev!==d.Undefined&&e.next!==d.Undefined){let r=e.prev;r.next=e.next,e.next.prev=r}else e.prev===d.Undefined&&e.next===d.Undefined?(this._first=d.Undefined,this._last=d.Undefined):e.next===d.Undefined?(this._last=this._last.prev,this._last.next=d.Undefined):e.prev===d.Undefined&&(this._first=this._first.next,this._first.prev=d.Undefined);this._size-=1}*[Symbol.iterator](){let e=this._first;for(;e!==d.Undefined;)yield e.element,e=e.next}},er=0,O=class{constructor(e){this.value=e,this.id=er++}},k=class{constructor(e){this.options=e,this._size=0}dispose(e){var r,t;this._disposed||(this._disposed=!0,this._listeners&&(e?(this._listeners instanceof O&&(this._listeners=[this._listeners]),this._listeners=this._listeners.filter(n=>(n==null?void 0:n.value)===e)):(this._listeners=void 0,this._size=0)),(t=(r=this.options)==null?void 0:r.onDidRemoveLastListener)==null||t.call(r))}get event(){var e;return(e=this._event)!=null||(this._event=(r,t)=>{var n,i,s,a,o,l;if(this._disposed)return()=>{console.info("[Jolibox SDK] Emitter is _disposed")};t&&(r=r.bind(t));let c=new O(r);return this._listeners?this._listeners instanceof O?this._listeners=[this._listeners,c]:this._listeners.push(c):((i=(n=this.options)==null?void 0:n.onWillAddFirstListener)==null||i.call(n,this),this._listeners=c,(a=(s=this.options)==null?void 0:s.onDidFirstListener)==null||a.call(s,this)),(l=(o=this.options)==null?void 0:o.onDidAddListener)==null||l.call(o,this),this._size++,()=>{var u,m,g,p;if(!this._disposed){if(this._listeners instanceof O)this._listeners.id===c.id&&(this._listeners=void 0,this._size=0,(m=(u=this.options)==null?void 0:u.onDidRemoveLastListener)==null||m.call(u));else if(this._listeners){let _=this._listeners.indexOf(c);_>=0&&(this._listeners.splice(_,1),this._size--,this._size===0&&((p=(g=this.options)==null?void 0:g.onDidRemoveLastListener)==null||p.call(g)))}}}}),this._event}_deliver(e,r){var t;if(!e)return;let n=((t=this.options)==null?void 0:t.onListenerError)||Error.constructor;if(!n){e.value(r);return}try{e.value(r)}catch(i){n(i)}}fire(e){this._listeners&&(this._listeners instanceof O?this._deliver(this._listeners,e):this._listeners.forEach(r=>this._deliver(r,e)))}hasListeners(){return this._size>0}},L=class{constructor(){this.listeners=new Map,this.listerHandlerMap=new WeakMap,this.cachedEventQueue=new Map}on(e,r){var t;let n=(t=this.listeners.get(e))!=null?t:new k,i=o=>r(...o.args),s=n.event(i);this.listerHandlerMap.set(r,{handler:i,dispose:s}),this.listeners.set(e,n);let a=this.cachedEventQueue.get(e);if(a)for(let o of a)r(...o.args)}flushCachedEvent(e){e?this.cachedEventQueue.delete(e):this.cachedEventQueue.clear()}off(e,r){let t=this.listerHandlerMap.get(r);t&&(t.dispose(),this.listerHandlerMap.delete(r))}emit(e,...r){let t=this.listeners.get(e);if(t)t.fire({event:e,args:r});else{let n=this.cachedEventQueue.get(e);n||(n=new Ze,this.cachedEventQueue.set(e,n)),n.push({args:r})}}},G={};Fe(G,{None:()=>rr,filter:()=>nr,once:()=>be,toPromise:()=>tr});var rr=()=>(console.log("[Jolibox SDK] None Event"),()=>{console.log("[Jolibox SDK] None Event dispose")});function tr(e){return new Promise(r=>be(e)(r))}function be(e){return(r,t=null)=>{let n=!1;return e(i=>{if(!n)return n=!0,r.call(t,i)},null)}}function nr(e,r){return(t=>{let n,i={onWillAddFirstListener(){n=t(s.fire,s)}},s=new k(i);return s.event})((t,n=null)=>e(i=>r(i)&&t.call(n,i),null))}var V=Symbol.for("Jolibox.hostEmitter"),ir=()=>{let e=new L;return globalThis[V]||(globalThis[V]={on:e.on.bind(e),off:e.off.bind(e),emit:e.emit.bind(e)}),globalThis[V]},pr=ir();function sr(e,r){let t=Math.min(e.length,r.length);for(let n=0;n<t;n++)or(e[n],r[n])}function or(e,r){if(z(r)){if(typeof e!==r)throw new Error(`argument does not match constraint: typeof ${r}`)}else if(me(r)){try{if(e instanceof r)return}catch(t){}if(!Ke(e)&&e.constructor===r||r.length===1&&r.call(void 0,e)===!0)return;throw new Error("[Jolibox SDK]argument does not match one of these constraints: arg instanceof constraint, arg.constructor === constraint, nor constraint(arg) === true")}}var $=class{constructor(){this._commands=new Map,this._onDidRegisterCommand=new k,this.onDidRegisterCommand=this._onDidRegisterCommand.event,console.log("[Jolibox SDK] command registry")}registerCommand(e){if(!e)throw new Error("invalid command");if(e.metadata&&Array.isArray(e.metadata.args)){let t=[];for(let i of e.metadata.args)t.push(i.constraint);let n=e.handler;e.handler=function(...i){return sr(i,t),n(...i)}}let{id:r}=e;this._commands.get(r)&&console.info(`[Jolibox SDK] duplicated command is registered ${r}`),this._commands.set(r,e),this._onDidRegisterCommand.fire(r)}getCommand(e){return this._commands.get(e)}getCommands(){let e=new Map;for(let r of this._commands.keys()){let t=this.getCommand(r);t&&e.set(r,t)}return e}};$=ue([fe],$);var ce=class{constructor(){this._onWillExecuteCommand=new k,this.onWillExecuteCommand=this._onWillExecuteCommand.event,this._onDidExecuteCommand=new k,this.onDidExecuteCommand=this._onDidExecuteCommand.event,this.registry=new $,this._starActivation=null}_activateStar(){return this._starActivation||(this._starActivation=Ve(3e4)),this._starActivation}executeCommand(e,...r){return je(this,null,function*(){return this.registry.getCommand(e)?this._tryExecuteCommand(e,r):(yield Promise.all([Promise.race([this._activateStar(),G.toPromise(G.filter(this.registry.onDidRegisterCommand,t=>t===e))])]),this._tryExecuteCommand(e,r))})}executeCommandThowErr(e,...r){if(!this.registry.getCommand(e))throw new Error(`command '${e}' not found`);let t=this.registry.getCommand(e);this._onWillExecuteCommand.fire({commandId:e,args:r});let n=this.invokeFunction(t.handler,...r);return this._onDidExecuteCommand.fire({commandId:e,args:r}),n}_tryExecuteCommand(e,r){let t=this.registry.getCommand(e);if(!t)return Promise.reject(new Error(`command '${e}' not found`));try{this._onWillExecuteCommand.fire({commandId:e,args:r});let n=this.invokeFunction(t.handler,...r);return this._onDidExecuteCommand.fire({commandId:e,args:r}),Promise.resolve(n)}catch(n){return Promise.reject(n)}}invokeFunction(e,...r){let t=!1;try{return e(...r)}finally{t=!0}}};ce=ue([fe],ce);var hr=Symbol.for("Jolibox.commands");function A(e,r){return`[${e}]:${r}`}var _e=()=>!!(navigator.userAgent||"").includes("JoliboxPlatformSDK");var E="custom_event_";var ye=[],Ee=[],Ne=["env","createRequestTask","login"],U="__batch_event__";var ar=e=>e==="pv"?e:"default",N=class{constructor(r){this.interval=30;this.lastReportTime=0;this.cache={};let{reporter:t,interval:n=30,eventName:i,tagNameOrder:s,metricName:a,type:o}=r;this.reporter=t,this.interval=n,this.eventName=i,this.tagNameOrder=s,this.metricName=a,this.type=ar(o)}report(r){this.type==="pv"?this.addPVPoint(r):this.addPoint(r),this.tryReport(!1)}flush(){this.tryReport(!0)}tryReport(r){if(Object.keys(this.cache).length){if(r){this.reporter(this.processPoints(this.cache)),this.clearPoints();return}this.lastReportTime=this.lastReportTime||Date.now(),Date.now()-this.lastReportTime>=this.interval*1e3&&(this.reporter(this.processPoints(this.cache)),this.clearPoints(),this.lastReportTime=Date.now())}}addPoint(r){let t=(n,i,s,a)=>{let o=i.shift();if(o){let l=a[o];n[l]||(n[l]={}),t(n[l],i,s,a)}else n[s]||(n[s]=[]),n[s].push(a[s])};t(this.cache,[...this.tagNameOrder],this.metricName,r)}addPVPoint(r){let t=(i,s,a,o)=>{let l=s.shift();if(!l&&y(o))throw new C(`report value failed to match tagNameOrder, ${JSON.stringify(n)}`);if(l){let c=[];if(y(o))c.push(...Object.keys(o));else if(z(o)){if(s.length>0)throw new C(`report value failed to match tagNameOrder, ${JSON.stringify(n)}`);c.push(o)}else throw new C(`expected metric value to be a string, but got a(n) ${typeof o}, ${JSON.stringify(n)}`);c.forEach(u=>{i[u]||(i[u]={});let m=y(o)?o[u]:o;t(i[u],[...s],a,m)})}else i[a]?i[a]++:i[a]=1},n={point:r,metricName:this.metricName,tagNameOrder:this.tagNameOrder};t(this.cache,[...this.tagNameOrder],this.metricName,r)}processPoints(r){return{eventName:this.eventName,tagNameOrder:this.tagNameOrder,metricName:this.metricName,metricAggregateType:this.type==="pv"?"itoa":"arr",data:r}}clearPoints(){this.cache={}}},Se=!1,W,q,Q;function Re(e,r){Se||(W=new N({eventName:"jolibox_invoke",tagNameOrder:["status","method","errNo","errMsg","isForeground"],metricName:"duration",reporter(i){e.invoke("trackAsync",JSON.stringify({event:"reportMetrics",data:i}),-1)}}),q=new N({eventName:"jolibox_invoke_js2native",tagNameOrder:["status","method","isForeground"],metricName:"duration",reporter(i){e.invoke("trackAsync",JSON.stringify({event:"reportMetrics",data:i}),-1)}}),Q=new N({eventName:"jolibox_invoke_native2js",tagNameOrder:["status","method","isForeground"],metricName:"duration",reporter(i){e.invoke("trackAsync",JSON.stringify({event:"reportMetrics",data:i}),-1)}}),r("onJoliboxEnterBackground",()=>{W.flush(),q.flush(),Q.flush()}),Se=!0);function t(i){var S,R;let{method:s,args:a,startTime:o,isForeground:l,errMsg:c=`${s}:fail no errMsg`,errNo:u=0,__timing:m={receiveJSInvoke:0,invokeCallback:0}}=i,{receiveJSInvoke:g,invokeCallback:p}=m,_=(R=(S=c.match(/\S:(\S+)\s?/))==null?void 0:S[1])!=null?R:"fail";W.report({status:_,method:n(s,a),errNo:`${u}`,errMsg:c,isForeground:l,duration:Date.now()-o}),o&&g&&p&&(q.report({status:_,method:s,isForeground:l,duration:Number((g-o).toFixed(3))}),Q.report({status:_,method:s,isForeground:l,duration:Number((Date.now()-p).toFixed(3))}))}function n(i,s){return(i==="callHostMethod"||i==="callHostMethodSync")&&s!=null&&s.method?`${i}-${s.method}`:i}return t}var Y=[],cr=!1,X=Symbol.for("Jolibox.invokeResolverInstance");function Te(e,r){let t=0,n=!0;globalThis[X]||(globalThis[X]=new Map);let i=globalThis[X],s=Re(e,r);r("onJoliboxEnterBackground",()=>{n=!1}),r("onJoliboxEnterForeground",()=>{n=!0,Y.forEach(g=>x(this,[g],function*({method:c,args:u,resolve:m}){let p=yield o(c,u);m(p)})),Y.length=0});let a=(c,u)=>{let m=i.get(Number(c));if(!m)return;let g=T(u);m(g),i.delete(Number(c))},o=(c,u)=>{var ee,re;let m=Date.now(),g=`${n}`;t+=1;let p=new de;if(i.set(t,p.resolve),!n&&Ee.includes(c))return new Promise(v=>{Y.push({method:c,args:u,resolve:v})});let S=se(h({},{method:c,startTime:m,args:u,isForeground:g}),{invokeType:"js-bridge"}),R=!cr&&ye.includes(c),F=ae(u,R),j=R?F:JSON.stringify(F),f;if(c.endsWith("Sync")||Ne.includes(c)?f=(ee=e.call)==null?void 0:ee.call(e,c,F,t):typeof j=="string"?f=e.invoke(c,j,t):f=(re=e.call)==null?void 0:re.call(e,c,j,t),f){try{typeof f=="string"&&(f=JSON.parse(f)),f=T(f)}catch(v){D.error(v)}return i.delete(t),f.errorCode&&(f.errorCode=A(c,f.errorCode)),s(h(h({},S),f)),f}return c.endsWith("Sync")&&i.delete(t),p.promise.then(v=>(v.errorCode&&(v.errorCode=A(c,v.errorCode)),s(h(h({},S),v)),v))};return{invokeNative:o,applyNative:(c,u)=>{let m=o(c,u);return ge(m)?m.then(g=>xe(c,g)):xe(c,m)},invokeHandler:a}}function xe(e,r){if(!y(r)){D.warn(`[Jolibox SDK]${e} no response value`);return}let o=r,{errMsg:t,errNo:n,errorType:i,errorCode:s}=o,a=oe(o,["errMsg","errNo","errorType","errorCode"]);if(t&&t!==`${e}:ok`)throw new he(t,n,i,s);return a}var J=Symbol.for("Jolibox.subscribeInstance");function we(e){if(globalThis[J])return globalThis[J];let r=new L,t=new L,n=new N({eventName:"jolibox_publish",tagNameOrder:["type","event"],metricName:"duration",reporter(i){e.invoke("trackAsync",JSON.stringify({event:"reportMetrics",data:i}),-1)}});return r.on("onJoliboxEnterBackground",()=>{n.flush()}),globalThis[J]={onNative:r.on.bind(r),offNative:r.off.bind(r),subscribe:t.on.bind(t),unsubscribe:t.off.bind(t),subscribeHandler(i,s,a){let o=T(s),l;if(o.__extra){l=o.params;let{type:c,startTime:u}=o.__extra;n.report({type:c,event:i,duration:Date.now()-u})}else l=o;if(i===U){l.forEach(u=>{let[m,g]=u;try{t.emit(m.slice(E.length),g,a)}catch(p){}});return}if(i.startsWith(E)){t.emit(i.slice(E.length),l,a);return}r.emit(i,l,a)}},globalThis[J]}function Oe(e){let r=new Map,t;return(i,s,a,o)=>{if(o){let c=a?[a]:"*";e.publish(`${E}${i}`,s,c);return}t||(t=Promise.resolve().then(()=>{r.forEach((c,u)=>{try{let m=u?[u]:"*";e.publish(U,c,m)}catch(m){}}),t=void 0,r.clear()}));let l=r.get(a);l||(l=[],r.set(a,l)),l.push([`${E}${i}`,s])}}function Z(e){let{subscribeHandler:r,onNative:t,offNative:n,subscribe:i,unsubscribe:s}=we(e),{invokeNative:a,invokeHandler:o,applyNative:l}=Te(e,t),c=Oe(e);return{invokeHandler:o,subscribeHandler:r,applyNative:l,invokeNative:a,onNative:t,offNative:n,publish:c,subscribe:i,unsubscribe:s}}function B(e,r){return{params:e,__extra:{startTime:Date.now(),type:r}}}var I,b={trigger(){},exit(){return Promise.resolve(!1)},onReady(e){b.trigger=e},onDoExit(e){b.exit=e}},ke=e=>{let r=window.prompt("invoke",JSON.stringify({event:"envSync",paramsString:JSON.stringify({})}));if(!r)e.onError(new pe("native env failed"));else{let{data:t}=JSON.parse(r);return t!=null?t:void 0}};if(window.webkit){let e=window.webkit.messageHandlers,r=(i="")=>{b.trigger(),e.onDocumentReady.postMessage({path:i})},t=i=>x(void 0,null,function*(){let s=yield b.exit();e.doExit.postMessage({uuid:i,shouldInterrupt:s})});I={onDocumentReady:r,doExit:t,invoke(i,s,a){e.invoke.postMessage({event:i,paramsString:s,callbackId:a})},publish(i,s,a){let o=B(s,"joliboxJSCore");window.prompt("publish",JSON.stringify({event:i,paramsString:JSON.stringify(o),webviewIds:a}))},call(i,s,a){let o=window.prompt("invoke",JSON.stringify({event:i,paramsString:JSON.stringify(s),callbackId:a}));if(o)return JSON.parse(o)}};let n={onDocumentReady:r,env:ke,doExit:t};globalThis.joliboxJSCore=h({},n)}if(window.JoliAndroidSDKBridge){let e=window.JoliAndroidSDKBridge,r=(i="")=>{b.trigger(),e.onDocumentReady(JSON.stringify({path:i}))},t=i=>x(void 0,null,function*(){let s=yield b.exit();e.doExit(JSON.stringify({uuid:i,shouldInterrupt:s}))});I={onDocumentReady:r,invoke(i,s,a){e.invoke(JSON.stringify({event:i,paramsString:s,callbackId:a}))},doExit:t,publish(i,s,a){let o=B(s,"joliboxJSCore");e.publish({event:i,paramsString:JSON.stringify(o),webviewIds:a})},call(i,s,a){let o=window.prompt("invoke",JSON.stringify({event:i,paramsString:JSON.stringify(s),callbackId:a}));if(o)return JSON.parse(o)}};let n={onDocumentReady:r,env:ke,doExit:t};globalThis.joliboxJSCore=h({},n)}var Ie=I;if(!Ie&&_e())throw new ve("No joliboxJScore is found, native bridge not found.");var lr=h({},Ie),Me=Z(lr),{invokeHandler:Ae}=Me,{applyNative:yt,invokeNative:Et,onNative:ur,offNative:Nt,subscribeHandler:dr,publish:St,subscribe:Rt,unsubscribe:xt}=Me,Tt=(e,r)=>{ur(e,(...t)=>{var n;(n=t[0])!=null&&n.errorCode&&(t[0].errorCode=A(e,t[0].errorCode)),r(...t)})};globalThis.joliboxJSBridge={callHandler:Ae,invokeHandler:Ae,subscribeHandler:dr};export{b as RuntimeLoader,yt as applyNative,Et as invokeNative,Nt as offNative,ur as onNative,Tt as onNativeWithError,St as publish,Rt as subscribe,dr as subscribeHandler,xt as unsubscribe};
|
|
@@ -249,6 +249,16 @@ declare global {
|
|
|
249
249
|
};
|
|
250
250
|
};
|
|
251
251
|
|
|
252
|
+
sendRequestBodyAsync: (params: {
|
|
253
|
+
requestId: string;
|
|
254
|
+
body: string;
|
|
255
|
+
dataType: 'json' | 'text';
|
|
256
|
+
}) => Promise<{
|
|
257
|
+
errMsg: string;
|
|
258
|
+
/** 错误码 */
|
|
259
|
+
errNo?: number;
|
|
260
|
+
}>;
|
|
261
|
+
|
|
252
262
|
updateContainerConfigSync: (params: { displayCapsuleButton: boolean; webviewId?: number }) => {
|
|
253
263
|
/** 错误消息 */
|
|
254
264
|
errMsg: string;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jolibox/native-bridge",
|
|
3
3
|
"description": "This project is Jolibox JS-SDk bridge for Native",
|
|
4
|
-
"version": "1.1.16-beta.
|
|
4
|
+
"version": "1.1.16-beta.5",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"typings": "dist/index.d.ts",
|
|
7
7
|
"license": "MIT",
|
|
@@ -11,8 +11,8 @@
|
|
|
11
11
|
],
|
|
12
12
|
"types": "./dist/index.d.ts",
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"@jolibox/common": "1.1.16-beta.
|
|
15
|
-
"@jolibox/types": "1.1.16-beta.
|
|
14
|
+
"@jolibox/common": "1.1.16-beta.5",
|
|
15
|
+
"@jolibox/types": "1.1.16-beta.5"
|
|
16
16
|
},
|
|
17
17
|
"devDependencies": {
|
|
18
18
|
"typescript": "5.7.3",
|
|
@@ -249,6 +249,16 @@ declare global {
|
|
|
249
249
|
};
|
|
250
250
|
};
|
|
251
251
|
|
|
252
|
+
sendRequestBodyAsync: (params: {
|
|
253
|
+
requestId: string;
|
|
254
|
+
body: string;
|
|
255
|
+
dataType: 'json' | 'text';
|
|
256
|
+
}) => Promise<{
|
|
257
|
+
errMsg: string;
|
|
258
|
+
/** 错误码 */
|
|
259
|
+
errNo?: number;
|
|
260
|
+
}>;
|
|
261
|
+
|
|
252
262
|
updateContainerConfigSync: (params: { displayCapsuleButton: boolean; webviewId?: number }) => {
|
|
253
263
|
/** 错误消息 */
|
|
254
264
|
errMsg: string;
|