@jolibox/native-bridge 1.3.3-beta.1 → 1.3.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/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var je=Object.defineProperty,$e=Object.defineProperties;var Ve=Object.getOwnPropertyDescriptors;var D=Object.getOwnPropertySymbols;var ce=Object.prototype.hasOwnProperty,ue=Object.prototype.propertyIsEnumerable;var ae=(e,t,r)=>t in e?je(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,v=(e,t)=>{for(var r in t||(t={}))ce.call(t,r)&&ae(e,r,t[r]);if(D)for(var r of D(t))ue.call(t,r)&&ae(e,r,t[r]);return e},le=(e,t)=>$e(e,Ve(t));var de=(e,t)=>{var r={};for(var n in e)ce.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(e!=null&&D)for(var n of D(e))t.indexOf(n)<0&&ue.call(e,n)&&(r[n]=e[n]);return r};var R=(e,t,r)=>new Promise((n,s)=>{var i=u=>{try{o(r.next(u))}catch(c){s(c)}},a=u=>{try{o(r.throw(u))}catch(c){s(c)}},o=u=>u.done?n(u.value):Promise.resolve(u.value).then(i,a);o((r=r.apply(e,t)).next())});function He(e){return!!(e!=null&&e.__nativeBuffers__)}var Ge=e=>{let t=atob(e),r=t.length,n=new Uint8Array(r);for(let s=0;s<r;s++)n[s]=t.charCodeAt(s);return n.buffer};function k(e){if(typeof e=="string")try{e=JSON.parse(e)}catch(r){return{}}if(typeof e!="object"||e===null)return{};if(!He(e))return e;let t=e.__nativeBuffers__;if(delete e.__nativeBuffers__,t)for(let r=0;r<t.length;r++){let n=t[r];if(n){let s;n.value?s=n.value:n.base64&&(s=Ge(n.base64)),typeof s!="undefined"&&s instanceof ArrayBuffer&&(e[n.key]=s)}}return e}var Ke=e=>{let t="",r=new Uint8Array(e),n=r.byteLength;for(let s=0;s<n;s++)t+=String.fromCharCode(r[s]);return btoa(t)};function ge(e={},t=!1){let r=e,n=[];for(let[s,i]of Object.entries(r))if(i!==void 0&&i instanceof ArrayBuffer&&i.byteLength!==void 0){let a=t?{value:i,key:s}:{base64:Ke(i),key:s};n.push(a),delete r[s]}return n.length>0&&(r.__nativeBuffers__=n),r}var he=Object.defineProperty;var ze=Object.getOwnPropertyDescriptor;var We=(e,t)=>{for(var r in t)he(e,r,{get:t[r],enumerable:!0})},fe=(e,t,r,n)=>{for(var s=n>1?void 0:n?ze(t,r):t,i=e.length-1,a;i>=0;i--)(a=e[i])&&(s=(n?a(t,r,s):a(s))||s);return n&&s&&he(t,r,s),s},Ye=(e,t,r)=>new Promise((n,s)=>{var i=u=>{try{o(r.next(u))}catch(c){s(c)}},a=u=>{try{o(r.throw(u))}catch(c){s(c)}},o=u=>u.done?n(u.value):Promise.resolve(u.value).then(i,a);o((r=r.apply(e,t)).next())});if(typeof window!="undefined"&&!window.AbortController){let e=function(){this.signal=new t};e.prototype.abort=function(){this.signal._aborted=!0,typeof this.signal.onabort=="function"&&this.signal.onabort(new Event("abort"));let r=new Event("abort");this.signal.dispatchEvent(r)};let t=function(){this._aborted=!1,this.aborted=!1,this.onabort=null,this._eventListeners={}};Object.defineProperty(t.prototype,"aborted",{get:function(){return this._aborted}}),t.prototype.addEventListener=function(r,n){this._eventListeners[r]||(this._eventListeners[r]=[]),this._eventListeners[r].push(n)},t.prototype.removeEventListener=function(r,n){if(!this._eventListeners[r])return;let s=this._eventListeners[r].indexOf(n);s!==-1&&this._eventListeners[r].splice(s,1)},t.prototype.dispatchEvent=function(r){if(this._eventListeners[r.type])for(let n of this._eventListeners[r.type])n.call(this,r)},window.AbortController=e,window.AbortSignal=t}function Qe(e){return new Promise(t=>{setTimeout(()=>{t()},e)})}var ve=class{constructor(){this.state="pending",this.promise=new Promise((e,t)=>{this.resolve=r=>{this.state==="pending"&&(this.state="fulfilled",e(r))},this.reject=r=>{this.state==="pending"&&(this.state="rejected",t(r))}})}};function Q(e){return typeof e=="string"}function S(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)&&!(e instanceof RegExp)&&!(e instanceof Date)}function X(e){return typeof e=="number"&&!isNaN(e)}function Xe(e){return typeof e=="undefined"}function Ze(e){return Xe(e)||e===null}function be(e){return typeof e=="function"}function ye(e){return S(e)&&be(e.then)}function _e(e){let t=e,r=null,n=function(...s){return r||(r=new t(...s)),r};return n.prototype=t.prototype,n}var et=(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))(et||{}),tt=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}},U=class extends tt{constructor(){super(...arguments),this.kind="INTERNAL_ERROR"}};var Se=class extends U{constructor(){super(...arguments),this.name="INTERNAL_INVOKE_NATIVE_ERROR"}};var Ne=class extends U{constructor(e,t,r,n){super(e),this.errNo=t,this.name="INTERNAL_APPLY_NATIVE_ERROR",this.errorType=r,this.errorCode=n}};var Ee=class extends U{constructor(){super(...arguments),this.name="INTERNAL_JSCORE_ERROR",this.priority="P0"}};var L=class extends U{constructor(){super(...arguments),this.name="INTERNAL_METRIC_REPORT_ERROR"}};function C(e){return(...t)=>{var r,n;((n=(r=globalThis.VConsole)==null?void 0:r[e])!=null?n:globalThis.console[e])(...t)}}var A={log:C("log"),warn:C("warn"),info:C("info"),error:C("error"),debug:C("debug")};Object.assign(globalThis,{logger:A});var me=Symbol.for("Jolibox.canIUseMap"),rt={};globalThis[me]||(globalThis[me]=rt);function Re(e,t,r){let n=e;for(let s of t)if(n&&typeof n=="object")n=n[s];else return r;return n===void 0?r:n}var G=Symbol.for("Jolibox.canIUseMap.native"),nt={};globalThis[G]||(globalThis[G]=nt);var q={get config(){return globalThis[G]}};var st=(e=>(e[e.Other=0]="Other",e[e.Route=1]="Route",e[e.Click=2]="Click",e[e.View=3]="View",e[e.Expose=4]="Expose",e[e.Swipe=5]="Swipe",e[e.Input=6]="Input",e[e.Select=7]="Select",e[e.SwitchOn=8]="SwitchOn",e[e.SwitchOff=9]="SwitchOff",e[e.Submit=10]="Submit",e[e.Scroll=11]="Scroll",e[e.Hide=12]="Hide",e[e.System=1e3]="System",e[e.ErrorTrace=1001]="ErrorTrace",e[e.UserDefined=1002]="UserDefined",e))(st||{}),it=(e=>(e.MiniGame="mini-game",e.MiniDrama="mini-drama",e.App="app",e.WebSDK="web-sdk",e.AppSDK="app-sdk",e))(it||{}),ot=(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))(ot||{});function at(){if(typeof window=="undefined")return{getItem:()=>null,setItem:()=>{},removeItem:()=>{},clear:()=>{},length:0,key:()=>null};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 t=Window.prototype,r=Object.getOwnPropertyDescriptor(t,"localStorage");if(r&&r.get){let n=r.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}}at();var x=typeof window=="undefined",xe=()=>!x&&!!(navigator.userAgent||"").includes("JoliboxPlatformSDK"),At={isiOS:!x&&(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:!x&&navigator.userAgent.includes("Android"),isMac:!x&&navigator.userAgent.includes("Mac"),isFacebook:!x&&navigator.userAgent.includes("FB_IAB"),isPC:!x&&!navigator.userAgent.includes("iPhone")&&!navigator.userAgent.includes("Android")};var K=class z{constructor(t){this.element=t,this.next=z.Undefined,this.prev=z.Undefined}};K.Undefined=new K(void 0);var m=K,ct=class{constructor(){this._first=m.Undefined,this._last=m.Undefined,this._size=0}get size(){return this._size}isEmpty(){return this._first===m.Undefined}clear(){let e=this._first;for(;e!==m.Undefined;){let t=e.next;e.prev=m.Undefined,e.next=m.Undefined,e=t}this._first=m.Undefined,this._last=m.Undefined,this._size=0}unshift(e){return this._insert(e,!1)}push(e){return this._insert(e,!0)}_insert(e,t){let r=new m(e);if(this._first===m.Undefined)this._first=r,this._last=r;else if(t){let s=this._last;this._last=r,r.prev=s,s.next=r}else{let s=this._first;this._first=r,r.next=s,s.prev=r}this._size+=1;let n=!1;return()=>{n||(n=!0,this._remove(r))}}shift(){if(this._first!==m.Undefined){let e=this._first.element;return this._remove(this._first),e}}pop(){if(this._last!==m.Undefined){let e=this._last.element;return this._remove(this._last),e}}_remove(e){if(e.prev!==m.Undefined&&e.next!==m.Undefined){let t=e.prev;t.next=e.next,e.next.prev=t}else e.prev===m.Undefined&&e.next===m.Undefined?(this._first=m.Undefined,this._last=m.Undefined):e.next===m.Undefined?(this._last=this._last.prev,this._last.next=m.Undefined):e.prev===m.Undefined&&(this._first=this._first.next,this._first.prev=m.Undefined);this._size-=1}*[Symbol.iterator](){let e=this._first;for(;e!==m.Undefined;)yield e.element,e=e.next}},ut=0,w=class{constructor(e){this.value=e,this.id=ut++}},O=class{constructor(e){this.options=e,this._size=0}dispose(e){var t,r;this._disposed||(this._disposed=!0,this._listeners&&(e?(this._listeners instanceof w&&(this._listeners=[this._listeners]),this._listeners=this._listeners.filter(n=>(n==null?void 0:n.value)===e)):(this._listeners=void 0,this._size=0)),(r=(t=this.options)==null?void 0:t.onDidRemoveLastListener)==null||r.call(t))}get event(){var e;return(e=this._event)!=null||(this._event=(t,r)=>{var n,s,i,a,o,u;if(this._disposed)return()=>{console.info("[Jolibox SDK] Emitter is _disposed")};r&&(t=t.bind(r));let c=new w(t);return this._listeners?this._listeners instanceof w?this._listeners=[this._listeners,c]:this._listeners.push(c):((s=(n=this.options)==null?void 0:n.onWillAddFirstListener)==null||s.call(n,this),this._listeners=c,(a=(i=this.options)==null?void 0:i.onDidFirstListener)==null||a.call(i,this)),(u=(o=this.options)==null?void 0:o.onDidAddListener)==null||u.call(o,this),this._size++,()=>{var l,d,g,p;if(!this._disposed){if(this._listeners instanceof w)this._listeners.id===c.id&&(this._listeners=void 0,this._size=0,(d=(l=this.options)==null?void 0:l.onDidRemoveLastListener)==null||d.call(l));else if(this._listeners){let f=this._listeners.indexOf(c);f>=0&&(this._listeners.splice(f,1),this._size--,this._size===0&&((p=(g=this.options)==null?void 0:g.onDidRemoveLastListener)==null||p.call(g)))}}}}),this._event}_deliver(e,t){var r;if(!e)return;let n=((r=this.options)==null?void 0:r.onListenerError)||Error.constructor;if(!n){e.value(t);return}try{e.value(t)}catch(s){n(s)}}fire(e){this._listeners&&(this._listeners instanceof w?this._deliver(this._listeners,e):this._listeners.forEach(t=>this._deliver(t,e)))}hasListeners(){return this._size>0}},B=class{constructor(){this.listeners=new Map,this.listerHandlerMap=new WeakMap,this.cachedEventQueue=new Map}on(e,t,r=!0){var n;let s=(n=this.listeners.get(e))!=null?n:new O,i=u=>t(...u.args),a=s.event(i);this.listerHandlerMap.set(t,{handler:i,dispose:a}),this.listeners.set(e,s);let o=this.cachedEventQueue.get(e);if(o&&r)for(let u of o)t(...u.args)}flushCachedEvent(e){e?this.cachedEventQueue.delete(e):this.cachedEventQueue.clear()}off(e,t){let r=this.listerHandlerMap.get(t);r&&(r.dispose(),this.listerHandlerMap.delete(t))}emit(e,...t){let r=this.listeners.get(e),n=this.cachedEventQueue.get(e);n||(n=new ct,this.cachedEventQueue.set(e,n)),n.push({args:t}),r&&r.fire({event:e,args:t})}once(e,t){let r=(...n)=>{t(...n),this.off(e,r)};this.on(e,r,!1)}},W={};We(W,{None:()=>lt,filter:()=>gt,once:()=>Ae,toPromise:()=>dt});var lt=()=>(console.log("[Jolibox SDK] None Event"),()=>{console.log("[Jolibox SDK] None Event dispose")});function dt(e){return new Promise(t=>Ae(e)(t))}function Ae(e){return(t,r=null)=>{let n=!1;return e(s=>{if(!n)return n=!0,t.call(r,s)},null)}}function gt(e,t){return(r=>{let n,s={onWillAddFirstListener(){n=r(i.fire,i)}},i=new O(s);return i.event})((r,n=null)=>e(s=>t(s)&&r.call(n,s),null))}var H=Symbol.for("Jolibox.hostEmitter"),mt=()=>{let e=new B;return globalThis[H]||(globalThis[H]={on:e.on.bind(e),off:e.off.bind(e),emit:e.emit.bind(e),once:e.once.bind(e)}),globalThis[H]},Tt=mt();function pt(e,t){let r=Math.min(e.length,t.length);for(let n=0;n<r;n++)ht(e[n],t[n])}function ht(e,t){if(Q(t)){if(typeof e!==t)throw new Error(`argument does not match constraint: typeof ${t}`)}else if(be(t)){try{if(e instanceof t)return}catch(r){}if(!Ze(e)&&e.constructor===t||t.length===1&&t.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 Y=class{constructor(){this._commands=new Map,this._onDidRegisterCommand=new O,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 r=[];for(let s of e.metadata.args)r.push(s.constraint);let n=e.handler;e.handler=function(...s){return pt(s,r),n(...s)}}let{id:t}=e;this._commands.get(t)&&console.info(`[Jolibox SDK] duplicated command is registered ${t}`),this._commands.set(t,e),this._onDidRegisterCommand.fire(t)}getCommand(e){return this._commands.get(e)}getCommands(){let e=new Map;for(let t of this._commands.keys()){let r=this.getCommand(t);r&&e.set(t,r)}return e}};Y=fe([_e],Y);var pe=class{constructor(){this._onWillExecuteCommand=new O,this.onWillExecuteCommand=this._onWillExecuteCommand.event,this._onDidExecuteCommand=new O,this.onDidExecuteCommand=this._onDidExecuteCommand.event,this.registry=new Y,this._starActivation=null}_activateStar(){return this._starActivation||(this._starActivation=Qe(3e4)),this._starActivation}executeCommand(e,...t){return Ye(this,null,function*(){return this.registry.getCommand(e)?this._tryExecuteCommand(e,t):(yield Promise.all([Promise.race([this._activateStar(),W.toPromise(W.filter(this.registry.onDidRegisterCommand,r=>r===e))])]),this._tryExecuteCommand(e,t))})}executeCommandThowErr(e,...t){if(!this.registry.getCommand(e))throw new Error(`command '${e}' not found`);let r=this.registry.getCommand(e);this._onWillExecuteCommand.fire({commandId:e,args:t});let n=this.invokeFunction(r.handler,...t);return this._onDidExecuteCommand.fire({commandId:e,args:t}),n}_tryExecuteCommand(e,t){let r=this.registry.getCommand(e);if(!r)return Promise.reject(new Error(`command '${e}' not found`));try{this._onWillExecuteCommand.fire({commandId:e,args:t});let n=this.invokeFunction(r.handler,...t);return this._onDidExecuteCommand.fire({commandId:e,args:t}),Promise.resolve(n)}catch(n){return Promise.reject(n)}}invokeFunction(e,...t){let r=!1;try{return e(...t)}finally{r=!0}}};pe=fe([_e],pe);var It=Symbol.for("Jolibox.commands");b("requestPaymentSync",{version:1e6,properties:{paymentBody:{appStoreProductId:102e4}}});b("requestProductDetailsAsync",{version:102e4});b("invokeSubscriptionPanelSync",{version:107e4,properties:{type:{game:107e4,drama:107e4}}});b("loginSync",{version:1e6,properties:{skipLogin:102e4,triggerFrom:102e4}});b("getABTest",{version:1050100,platforms:{android:1050100,ios:!1}});b("userTrackAsync",{version:1e6});b("openMiniapp",{version:1050100});b("requestCoinDetailsSync",{version:1070100});b("requestCoinDetailsAsync",{version:1070100});function b(e,t){if(q.config[e]){A.warn(`[can i use] ${e} already registered`);return}q.config[e]=v({},t)}var ft=(e,t)=>{function r(s){var d;let[i,...a]=s.split(":");if(!i)return!1;let o=q.config[i];if(!o)return!1;let u=(d=t==null?void 0:t())!=null?d:"",c=o.version;if(o.platforms&&u in o.platforms){let g=o.platforms[u];if(g===!1)return!1;typeof g=="number"&&(c=g)}if(typeof c!="number")return!1;let l=e();return typeof l!="number"||l<c?!1:a.length===0?!0:n(o,a,l)||n(o.properties,a,l)}function n(s,i,a){if(!s)return!1;let o=Re(s,i);if(!o)return!1;if(S(o)){let u=o.version;return X(u)?typeof a=="number"&&a>=u:!0}return X(o)?typeof a=="number"&&a>=o:o===!0}return{canIUseNative:r}};function P(e,t){return`[${e}]:${t}`}var Te=()=>xe();var N="custom_event_";var Ie=[],ke=[],Ce=["env","createRequestTask","login"],J="__batch_event__",we="__native_batch_event__";var vt=e=>e==="pv"?e:"default",E=class{constructor(t){this.interval=30;this.lastReportTime=0;this.cache={};let{reporter:r,interval:n=30,eventName:s,tagNameOrder:i,metricName:a,type:o}=t;this.reporter=r,this.interval=n,this.eventName=s,this.tagNameOrder=i,this.metricName=a,this.type=vt(o)}report(t){this.type==="pv"?this.addPVPoint(t):this.addPoint(t),this.tryReport(!1)}flush(){this.tryReport(!0)}tryReport(t){if(Object.keys(this.cache).length){if(t){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(t){let r=(n,s,i,a)=>{let o=s.shift();if(o){let u=a[o];n[u]||(n[u]={}),r(n[u],s,i,a)}else n[i]||(n[i]=[]),n[i].push(a[i])};r(this.cache,[...this.tagNameOrder],this.metricName,t)}addPVPoint(t){let r=(s,i,a,o)=>{let u=i.shift();if(!u&&S(o))throw new L(`report value failed to match tagNameOrder, ${JSON.stringify(n)}`);if(u){let c=[];if(S(o))c.push(...Object.keys(o));else if(Q(o)){if(i.length>0)throw new L(`report value failed to match tagNameOrder, ${JSON.stringify(n)}`);c.push(o)}else throw new L(`expected metric value to be a string, but got a(n) ${typeof o}, ${JSON.stringify(n)}`);c.forEach(l=>{s[l]||(s[l]={});let d=S(o)?o[l]:o;r(s[l],[...i],a,d)})}else s[a]?s[a]++:s[a]=1},n={point:t,metricName:this.metricName,tagNameOrder:this.tagNameOrder};r(this.cache,[...this.tagNameOrder],this.metricName,t)}processPoints(t){return{eventName:this.eventName,tagNameOrder:this.tagNameOrder,metricName:this.metricName,metricAggregateType:this.type==="pv"?"itoa":"arr",data:t}}clearPoints(){this.cache={}}},Oe=!1,Z,ee,te;function Pe(e,t){Oe||(Z=new E({eventName:"jolibox_invoke",tagNameOrder:["status","method","errNo","errMsg","isForeground"],metricName:"duration",reporter(s){e.invoke("trackAsync",JSON.stringify({event:"reportMetrics",data:s}),-1)}}),ee=new E({eventName:"jolibox_invoke_js2native",tagNameOrder:["status","method","isForeground"],metricName:"duration",reporter(s){e.invoke("trackAsync",JSON.stringify({event:"reportMetrics",data:s}),-1)}}),te=new E({eventName:"jolibox_invoke_native2js",tagNameOrder:["status","method","isForeground"],metricName:"duration",reporter(s){e.invoke("trackAsync",JSON.stringify({event:"reportMetrics",data:s}),-1)}}),t("onJoliboxEnterBackground",()=>{Z.flush(),ee.flush(),te.flush()}),Oe=!0);function r(s){var T,I;let{method:i,args:a,startTime:o,isForeground:u,errMsg:c=`${i}:fail no errMsg`,errNo:l=0,__timing:d={receiveJSInvoke:0,invokeCallback:0}}=s,{receiveJSInvoke:g,invokeCallback:p}=d,f=(I=(T=c.match(/\S:(\S+)\s?/))==null?void 0:T[1])!=null?I:"fail";Z.report({status:f,method:n(i,a),errNo:`${l}`,errMsg:c,isForeground:u,duration:Date.now()-o}),o&&g&&p&&(ee.report({status:f,method:i,isForeground:u,duration:Number((g-o).toFixed(3))}),te.report({status:f,method:i,isForeground:u,duration:Number((Date.now()-p).toFixed(3))}))}function n(s,i){return(s==="callHostMethod"||s==="callHostMethodSync")&&i!=null&&i.method?`${s}-${i.method}`:s}return r}var re=[],bt=!1,ne=Symbol.for("Jolibox.invokeResolverInstance"),yt=new Map;globalThis[ne]||(globalThis[ne]=yt);var _t={get resolveMap(){return globalThis[ne]}};function De(e,t){let r=0,n=!0,s=_t.resolveMap,i=Pe(e,t);t("onJoliboxEnterBackground",()=>{n=!1}),t("onJoliboxEnterForeground",()=>{n=!0,re.forEach(g=>R(this,[g],function*({method:c,args:l,resolve:d}){let p=yield o(c,l);d(p)})),re.length=0});let a=(c,l)=>{let d=s.get(Number(c));if(!d)return;let g=k(l);d(g),s.delete(Number(c))},o=(c,l)=>{var ie,oe;let d=Date.now(),g=`${n}`;r+=1;let p=new ve;if(s.set(r,p.resolve),!n&&ke.includes(c))return new Promise(_=>{re.push({method:c,args:l,resolve:_})});let T=le(v({},{method:c,startTime:d,args:l,isForeground:g}),{invokeType:"js-bridge"}),I=!bt&&Ie.includes(c),$=ge(l,I),V=I?$:JSON.stringify($),h;if(c.endsWith("Sync")||Ce.includes(c)?h=(ie=e.call)==null?void 0:ie.call(e,c,$,r):typeof V=="string"?h=e.invoke(c,V,r):h=(oe=e.call)==null?void 0:oe.call(e,c,V,r),h){try{typeof h=="string"&&(h=JSON.parse(h)),h=k(h)}catch(_){A.error(_)}return s.delete(r),h.errorCode&&(h.errorCode=P(c,h.errorCode)),i(v(v({},T),h)),h}return c.endsWith("Sync")&&s.delete(r),p.promise.then(_=>(_.errorCode&&(_.errorCode=P(c,_.errorCode)),i(v(v({},T),_)),_))};return{invokeNative:o,applyNative:(c,l)=>{let d=o(c,l);return ye(d)?d.then(g=>Me(c,g)):Me(c,d)},invokeHandler:a}}function Me(e,t){if(!S(t)){A.warn(`[Jolibox SDK]${e} no response value`);return}let o=t,{errMsg:r,errNo:n,errorType:s,errorCode:i}=o,a=de(o,["errMsg","errNo","errorType","errorCode"]);if(r&&r!==`${e}:ok`)throw new Ne(r,n,s,i);return a}var F=Symbol.for("Jolibox.subscribeInstance");function Ue(e){if(globalThis[F])return globalThis[F];let t=new B,r=new B,n=new E({eventName:"jolibox_publish",tagNameOrder:["type","event"],metricName:"duration",reporter(s){e.invoke("trackAsync",JSON.stringify({event:"reportMetrics",data:s}),-1)}});return t.on("onJoliboxEnterBackground",()=>{n.flush()}),globalThis[F]={onNative:t.on.bind(t),offNative:t.off.bind(t),subscribe:r.on.bind(r),unsubscribe:r.off.bind(r),subscribeHandler(s,i,a){let o=k(i),u;if(o.__extra){u=o.params;let{type:c,startTime:l}=o.__extra;n.report({type:c,event:s,duration:Date.now()-l})}else u=o;if(s===J){u.forEach(l=>{let[d,g]=l;try{r.emit(d.slice(N.length),g,a)}catch(p){}});return}if(s.startsWith(N)){r.emit(s.slice(N.length),u,a);return}t.emit(s,u,a)}},globalThis[F]}function Le(e){let t=new Map,r=new Map,n,s;return{publish:(o,u,c,l)=>{if(l){let g=c!==void 0?c==="*"?"*":[c]:void 0;e.publish(`${N}${o}`,u,g);return}n||(n=Promise.resolve().then(()=>{t.forEach((g,p)=>{try{let f=p!==void 0?p==="*"?"*":[p]:void 0;e.publish(J,g,f)}catch(f){}}),n=void 0,t.clear()}));let d=t.get(c);d||(d=[],t.set(c,d)),d.push([`${N}${o}`,u])},emitNative:(o,u,c,l)=>{if(l){let g=c!==void 0?c==="*"?"*":[c]:void 0;e.publish(o,u,g),console.log("emitNative",o,u,g);return}s||(s=Promise.resolve().then(()=>{r.forEach((g,p)=>{try{let f=p!==void 0?p==="*"?"*":[p]:void 0;e.publish(we,g,f)}catch(f){}}),s=void 0,r.clear()}));let d=r.get(c);d||(d=[],r.set(c,d)),d.push([o,u])}}}function se(e){let{subscribeHandler:t,onNative:r,offNative:n,subscribe:s,unsubscribe:i}=Ue(e),{invokeNative:a,invokeHandler:o,applyNative:u}=De(e,r),{publish:c,emitNative:l}=Le(e);return{invokeHandler:o,subscribeHandler:t,applyNative:u,invokeNative:a,onNative:r,offNative:n,emitNative:l,publish:c,subscribe:s,unsubscribe:i}}function j(e,t){return{params:e,__extra:{startTime:Date.now(),type:t}}}var M,y={trigger(){},exit(){return Promise.resolve(!1)},backPress(){return Promise.resolve(!1)},onReady(e){y.trigger=e},onDoExit(e){y.exit=e},onDoBackPress(e){y.backPress=e}},qe=e=>{let t=window.prompt("invoke",JSON.stringify({event:"envSync",paramsString:JSON.stringify({})}));if(!t)e.onError(new Se("native env failed"));else{let{data:r}=JSON.parse(t);return r!=null?r:void 0}};if(typeof window!="undefined"&&window.webkit){let e=window.webkit.messageHandlers,t=(s="")=>{y.trigger(),e.onDocumentReady.postMessage({path:s})},r=s=>R(void 0,null,function*(){let i=yield y.exit();e.doExit.postMessage({uuid:s,shouldInterrupt:i})});M={onDocumentReady:t,doExit:r,invoke(s,i,a){e.invoke.postMessage({event:s,paramsString:i,callbackId:a})},publish(s,i,a){let o=j(i,"joliboxJSCore");window.prompt("publish",JSON.stringify({event:s,paramsString:JSON.stringify(o),webviewIds:a}))},call(s,i,a){let o=window.prompt("invoke",JSON.stringify({event:s,paramsString:JSON.stringify(i),callbackId:a}));if(o)return JSON.parse(o)}};let n={onDocumentReady:t,env:qe,doExit:r};globalThis.joliboxJSCore=v({},n)}if(typeof window!="undefined"&&window.JoliAndroidSDKBridge){let s,e=window.JoliAndroidSDKBridge,t=(i="")=>{y.trigger(),e.onDocumentReady(JSON.stringify({path:i}))},r=i=>R(void 0,null,function*(){let a=yield y.exit();e.doExit(JSON.stringify({uuid:i,shouldInterrupt:a}))});M={onDocumentReady:t,invoke(i,a,o){e.invoke(JSON.stringify({event:i,paramsString:a,callbackId:o}))},doExit:r,publish(i,a,o){let u=j(a,"joliboxJSCore");e.publish(JSON.stringify({event:i,paramsString:JSON.stringify(u),webviewIds:o}))},call(i,a,o){let u=window.prompt("invoke",JSON.stringify({event:i,paramsString:JSON.stringify(a),callbackId:o}));if(u)return JSON.parse(u)},doBackPress(i){return R(this,null,function*(){let a=yield y.backPress();e.doBackPress(JSON.stringify({uuid:i,shouldInterrupt:a}))})}};let n={onDocumentReady:t,env:qe,doExit:r};globalThis.joliboxJSCore=v({},n)}var Je=M;if(!Je&&Te())throw new Ee("No joliboxJScore is found, native bridge not found.");var St=v({},Je),Fe=se(St),{invokeHandler:Be}=Fe,{applyNative:Vr,invokeNative:Hr,onNative:Nt,offNative:Gr,subscribeHandler:Et,publish:Kr,emitNative:zr,subscribe:Wr,unsubscribe:Yr}=Fe,Qr=(e,t)=>{Nt(e,(...r)=>{var n;(n=r[0])!=null&&n.errorCode&&(r[0].errorCode=P(e,r[0].errorCode)),t(...r)})};globalThis.joliboxJSBridge={callHandler:Be,invokeHandler:Be,subscribeHandler:Et};export{y as RuntimeLoader,Vr as applyNative,zr as emitNative,Hr as invokeNative,Gr as offNative,Nt as onNative,Qr as onNativeWithError,Kr as publish,ft as registerCanIUseContext,Wr as subscribe,Et as subscribeHandler,Yr as unsubscribe};
|
|
1
|
+
var je=Object.defineProperty,$e=Object.defineProperties;var Ve=Object.getOwnPropertyDescriptors;var D=Object.getOwnPropertySymbols;var ce=Object.prototype.hasOwnProperty,ue=Object.prototype.propertyIsEnumerable;var ae=(e,t,r)=>t in e?je(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,v=(e,t)=>{for(var r in t||(t={}))ce.call(t,r)&&ae(e,r,t[r]);if(D)for(var r of D(t))ue.call(t,r)&&ae(e,r,t[r]);return e},le=(e,t)=>$e(e,Ve(t));var de=(e,t)=>{var r={};for(var n in e)ce.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(e!=null&&D)for(var n of D(e))t.indexOf(n)<0&&ue.call(e,n)&&(r[n]=e[n]);return r};var R=(e,t,r)=>new Promise((n,s)=>{var i=u=>{try{o(r.next(u))}catch(c){s(c)}},a=u=>{try{o(r.throw(u))}catch(c){s(c)}},o=u=>u.done?n(u.value):Promise.resolve(u.value).then(i,a);o((r=r.apply(e,t)).next())});function He(e){return!!(e!=null&&e.__nativeBuffers__)}var Ge=e=>{let t=atob(e),r=t.length,n=new Uint8Array(r);for(let s=0;s<r;s++)n[s]=t.charCodeAt(s);return n.buffer};function I(e){if(typeof e=="string")try{e=JSON.parse(e)}catch(r){return{}}if(typeof e!="object"||e===null)return{};if(!He(e))return e;let t=e.__nativeBuffers__;if(delete e.__nativeBuffers__,t)for(let r=0;r<t.length;r++){let n=t[r];if(n){let s;n.value?s=n.value:n.base64&&(s=Ge(n.base64)),typeof s!="undefined"&&s instanceof ArrayBuffer&&(e[n.key]=s)}}return e}var Ke=e=>{let t="",r=new Uint8Array(e),n=r.byteLength;for(let s=0;s<n;s++)t+=String.fromCharCode(r[s]);return btoa(t)};function ge(e={},t=!1){let r=e,n=[];for(let[s,i]of Object.entries(r))if(i!==void 0&&i instanceof ArrayBuffer&&i.byteLength!==void 0){let a=t?{value:i,key:s}:{base64:Ke(i),key:s};n.push(a),delete r[s]}return n.length>0&&(r.__nativeBuffers__=n),r}var he=Object.defineProperty;var ze=Object.getOwnPropertyDescriptor;var We=(e,t)=>{for(var r in t)he(e,r,{get:t[r],enumerable:!0})},fe=(e,t,r,n)=>{for(var s=n>1?void 0:n?ze(t,r):t,i=e.length-1,a;i>=0;i--)(a=e[i])&&(s=(n?a(t,r,s):a(s))||s);return n&&s&&he(t,r,s),s},Ye=(e,t,r)=>new Promise((n,s)=>{var i=u=>{try{o(r.next(u))}catch(c){s(c)}},a=u=>{try{o(r.throw(u))}catch(c){s(c)}},o=u=>u.done?n(u.value):Promise.resolve(u.value).then(i,a);o((r=r.apply(e,t)).next())});if(typeof window!="undefined"&&!window.AbortController){let e=function(){this.signal=new t};e.prototype.abort=function(){this.signal._aborted=!0,typeof this.signal.onabort=="function"&&this.signal.onabort(new Event("abort"));let r=new Event("abort");this.signal.dispatchEvent(r)};let t=function(){this._aborted=!1,this.aborted=!1,this.onabort=null,this._eventListeners={}};Object.defineProperty(t.prototype,"aborted",{get:function(){return this._aborted}}),t.prototype.addEventListener=function(r,n){this._eventListeners[r]||(this._eventListeners[r]=[]),this._eventListeners[r].push(n)},t.prototype.removeEventListener=function(r,n){if(!this._eventListeners[r])return;let s=this._eventListeners[r].indexOf(n);s!==-1&&this._eventListeners[r].splice(s,1)},t.prototype.dispatchEvent=function(r){if(this._eventListeners[r.type])for(let n of this._eventListeners[r.type])n.call(this,r)},window.AbortController=e,window.AbortSignal=t}function Qe(e){return new Promise(t=>{setTimeout(()=>{t()},e)})}var ve=class{constructor(){this.state="pending",this.promise=new Promise((e,t)=>{this.resolve=r=>{this.state==="pending"&&(this.state="fulfilled",e(r))},this.reject=r=>{this.state==="pending"&&(this.state="rejected",t(r))}})}};function Q(e){return typeof e=="string"}function S(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)&&!(e instanceof RegExp)&&!(e instanceof Date)}function X(e){return typeof e=="number"&&!isNaN(e)}function Xe(e){return typeof e=="undefined"}function Ze(e){return Xe(e)||e===null}function be(e){return typeof e=="function"}function ye(e){return S(e)&&be(e.then)}function _e(e){let t=e,r=null,n=function(...s){return r||(r=new t(...s)),r};return n.prototype=t.prototype,n}var et=(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))(et||{}),tt=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}},U=class extends tt{constructor(){super(...arguments),this.kind="INTERNAL_ERROR"}};var Se=class extends U{constructor(){super(...arguments),this.name="INTERNAL_INVOKE_NATIVE_ERROR"}};var Ne=class extends U{constructor(e,t,r,n){super(e),this.errNo=t,this.name="INTERNAL_APPLY_NATIVE_ERROR",this.errorType=r,this.errorCode=n}};var Ee=class extends U{constructor(){super(...arguments),this.name="INTERNAL_JSCORE_ERROR",this.priority="P0"}};var L=class extends U{constructor(){super(...arguments),this.name="INTERNAL_METRIC_REPORT_ERROR"}};function C(e){return(...t)=>{var r,n;((n=(r=globalThis.VConsole)==null?void 0:r[e])!=null?n:globalThis.console[e])(...t)}}var x={log:C("log"),warn:C("warn"),info:C("info"),error:C("error"),debug:C("debug")};Object.assign(globalThis,{logger:x});var me=Symbol.for("Jolibox.canIUseMap"),rt={};globalThis[me]||(globalThis[me]=rt);function Re(e,t,r){let n=e;for(let s of t)if(n&&typeof n=="object")n=n[s];else return r;return n===void 0?r:n}var G=Symbol.for("Jolibox.canIUseMap.native"),nt={};globalThis[G]||(globalThis[G]=nt);var q={get config(){return globalThis[G]}};var st=(e=>(e[e.Other=0]="Other",e[e.Route=1]="Route",e[e.Click=2]="Click",e[e.View=3]="View",e[e.Expose=4]="Expose",e[e.Swipe=5]="Swipe",e[e.Input=6]="Input",e[e.Select=7]="Select",e[e.SwitchOn=8]="SwitchOn",e[e.SwitchOff=9]="SwitchOff",e[e.Submit=10]="Submit",e[e.Scroll=11]="Scroll",e[e.Hide=12]="Hide",e[e.System=1e3]="System",e[e.ErrorTrace=1001]="ErrorTrace",e[e.UserDefined=1002]="UserDefined",e))(st||{}),it=(e=>(e.MiniGame="mini-game",e.MiniDrama="mini-drama",e.App="app",e.WebSDK="web-sdk",e.AppSDK="app-sdk",e))(it||{}),ot=(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))(ot||{});function at(){if(typeof window=="undefined")return{getItem:()=>null,setItem:()=>{},removeItem:()=>{},clear:()=>{},length:0,key:()=>null};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 t=Window.prototype,r=Object.getOwnPropertyDescriptor(t,"localStorage");if(r&&r.get){let n=r.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}}at();var A=typeof window=="undefined",Ae=()=>!A&&!!(navigator.userAgent||"").includes("JoliboxPlatformSDK"),xt={isiOS:!A&&(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:!A&&navigator.userAgent.includes("Android"),isMac:!A&&navigator.userAgent.includes("Mac"),isFacebook:!A&&navigator.userAgent.includes("FB_IAB"),isPC:!A&&!navigator.userAgent.includes("iPhone")&&!navigator.userAgent.includes("Android")};var K=class z{constructor(t){this.element=t,this.next=z.Undefined,this.prev=z.Undefined}};K.Undefined=new K(void 0);var m=K,ct=class{constructor(){this._first=m.Undefined,this._last=m.Undefined,this._size=0}get size(){return this._size}isEmpty(){return this._first===m.Undefined}clear(){let e=this._first;for(;e!==m.Undefined;){let t=e.next;e.prev=m.Undefined,e.next=m.Undefined,e=t}this._first=m.Undefined,this._last=m.Undefined,this._size=0}unshift(e){return this._insert(e,!1)}push(e){return this._insert(e,!0)}_insert(e,t){let r=new m(e);if(this._first===m.Undefined)this._first=r,this._last=r;else if(t){let s=this._last;this._last=r,r.prev=s,s.next=r}else{let s=this._first;this._first=r,r.next=s,s.prev=r}this._size+=1;let n=!1;return()=>{n||(n=!0,this._remove(r))}}shift(){if(this._first!==m.Undefined){let e=this._first.element;return this._remove(this._first),e}}pop(){if(this._last!==m.Undefined){let e=this._last.element;return this._remove(this._last),e}}_remove(e){if(e.prev!==m.Undefined&&e.next!==m.Undefined){let t=e.prev;t.next=e.next,e.next.prev=t}else e.prev===m.Undefined&&e.next===m.Undefined?(this._first=m.Undefined,this._last=m.Undefined):e.next===m.Undefined?(this._last=this._last.prev,this._last.next=m.Undefined):e.prev===m.Undefined&&(this._first=this._first.next,this._first.prev=m.Undefined);this._size-=1}*[Symbol.iterator](){let e=this._first;for(;e!==m.Undefined;)yield e.element,e=e.next}},ut=0,w=class{constructor(e){this.value=e,this.id=ut++}},O=class{constructor(e){this.options=e,this._size=0}dispose(e){var t,r;this._disposed||(this._disposed=!0,this._listeners&&(e?(this._listeners instanceof w&&(this._listeners=[this._listeners]),this._listeners=this._listeners.filter(n=>(n==null?void 0:n.value)===e)):(this._listeners=void 0,this._size=0)),(r=(t=this.options)==null?void 0:t.onDidRemoveLastListener)==null||r.call(t))}get event(){var e;return(e=this._event)!=null||(this._event=(t,r)=>{var n,s,i,a,o,u;if(this._disposed)return()=>{console.info("[Jolibox SDK] Emitter is _disposed")};r&&(t=t.bind(r));let c=new w(t);return this._listeners?this._listeners instanceof w?this._listeners=[this._listeners,c]:this._listeners.push(c):((s=(n=this.options)==null?void 0:n.onWillAddFirstListener)==null||s.call(n,this),this._listeners=c,(a=(i=this.options)==null?void 0:i.onDidFirstListener)==null||a.call(i,this)),(u=(o=this.options)==null?void 0:o.onDidAddListener)==null||u.call(o,this),this._size++,()=>{var l,d,g,p;if(!this._disposed){if(this._listeners instanceof w)this._listeners.id===c.id&&(this._listeners=void 0,this._size=0,(d=(l=this.options)==null?void 0:l.onDidRemoveLastListener)==null||d.call(l));else if(this._listeners){let f=this._listeners.indexOf(c);f>=0&&(this._listeners.splice(f,1),this._size--,this._size===0&&((p=(g=this.options)==null?void 0:g.onDidRemoveLastListener)==null||p.call(g)))}}}}),this._event}_deliver(e,t){var r;if(!e)return;let n=((r=this.options)==null?void 0:r.onListenerError)||Error.constructor;if(!n){e.value(t);return}try{e.value(t)}catch(s){n(s)}}fire(e){this._listeners&&(this._listeners instanceof w?this._deliver(this._listeners,e):this._listeners.forEach(t=>this._deliver(t,e)))}hasListeners(){return this._size>0}},B=class{constructor(){this.listeners=new Map,this.listerHandlerMap=new WeakMap,this.cachedEventQueue=new Map}on(e,t,r=!0){var n;let s=(n=this.listeners.get(e))!=null?n:new O,i=u=>t(...u.args),a=s.event(i);this.listerHandlerMap.set(t,{handler:i,dispose:a}),this.listeners.set(e,s);let o=this.cachedEventQueue.get(e);if(o&&r)for(let u of o)t(...u.args)}flushCachedEvent(e){e?this.cachedEventQueue.delete(e):this.cachedEventQueue.clear()}off(e,t){let r=this.listerHandlerMap.get(t);r&&(r.dispose(),this.listerHandlerMap.delete(t))}emit(e,...t){let r=this.listeners.get(e),n=this.cachedEventQueue.get(e);n||(n=new ct,this.cachedEventQueue.set(e,n)),n.push({args:t}),r&&r.fire({event:e,args:t})}once(e,t){let r=(...n)=>{t(...n),this.off(e,r)};this.on(e,r,!1)}},W={};We(W,{None:()=>lt,filter:()=>gt,once:()=>xe,toPromise:()=>dt});var lt=()=>(console.log("[Jolibox SDK] None Event"),()=>{console.log("[Jolibox SDK] None Event dispose")});function dt(e){return new Promise(t=>xe(e)(t))}function xe(e){return(t,r=null)=>{let n=!1;return e(s=>{if(!n)return n=!0,t.call(r,s)},null)}}function gt(e,t){return(r=>{let n,s={onWillAddFirstListener(){n=r(i.fire,i)}},i=new O(s);return i.event})((r,n=null)=>e(s=>t(s)&&r.call(n,s),null))}var H=Symbol.for("Jolibox.hostEmitter"),mt=()=>{let e=new B;return globalThis[H]||(globalThis[H]={on:e.on.bind(e),off:e.off.bind(e),emit:e.emit.bind(e),once:e.once.bind(e)}),globalThis[H]},Tt=mt();function pt(e,t){let r=Math.min(e.length,t.length);for(let n=0;n<r;n++)ht(e[n],t[n])}function ht(e,t){if(Q(t)){if(typeof e!==t)throw new Error(`argument does not match constraint: typeof ${t}`)}else if(be(t)){try{if(e instanceof t)return}catch(r){}if(!Ze(e)&&e.constructor===t||t.length===1&&t.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 Y=class{constructor(){this._commands=new Map,this._onDidRegisterCommand=new O,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 r=[];for(let s of e.metadata.args)r.push(s.constraint);let n=e.handler;e.handler=function(...s){return pt(s,r),n(...s)}}let{id:t}=e;this._commands.get(t)&&console.info(`[Jolibox SDK] duplicated command is registered ${t}`),this._commands.set(t,e),this._onDidRegisterCommand.fire(t)}getCommand(e){return this._commands.get(e)}getCommands(){let e=new Map;for(let t of this._commands.keys()){let r=this.getCommand(t);r&&e.set(t,r)}return e}};Y=fe([_e],Y);var pe=class{constructor(){this._onWillExecuteCommand=new O,this.onWillExecuteCommand=this._onWillExecuteCommand.event,this._onDidExecuteCommand=new O,this.onDidExecuteCommand=this._onDidExecuteCommand.event,this.registry=new Y,this._starActivation=null}_activateStar(){return this._starActivation||(this._starActivation=Qe(3e4)),this._starActivation}executeCommand(e,...t){return Ye(this,null,function*(){return this.registry.getCommand(e)?this._tryExecuteCommand(e,t):(yield Promise.all([Promise.race([this._activateStar(),W.toPromise(W.filter(this.registry.onDidRegisterCommand,r=>r===e))])]),this._tryExecuteCommand(e,t))})}executeCommandThowErr(e,...t){if(!this.registry.getCommand(e))throw new Error(`command '${e}' not found`);let r=this.registry.getCommand(e);this._onWillExecuteCommand.fire({commandId:e,args:t});let n=this.invokeFunction(r.handler,...t);return this._onDidExecuteCommand.fire({commandId:e,args:t}),n}_tryExecuteCommand(e,t){let r=this.registry.getCommand(e);if(!r)return Promise.reject(new Error(`command '${e}' not found`));try{this._onWillExecuteCommand.fire({commandId:e,args:t});let n=this.invokeFunction(r.handler,...t);return this._onDidExecuteCommand.fire({commandId:e,args:t}),Promise.resolve(n)}catch(n){return Promise.reject(n)}}invokeFunction(e,...t){let r=!1;try{return e(...t)}finally{r=!0}}};pe=fe([_e],pe);var kt=Symbol.for("Jolibox.commands");b("requestPaymentSync",{version:1e6,properties:{paymentBody:{appStoreProductId:102e4}}});b("requestProductDetailsAsync",{version:102e4});b("invokeSubscriptionPanelSync",{version:107e4,properties:{type:{game:107e4,drama:107e4}}});b("loginSync",{version:1e6,properties:{skipLogin:102e4,triggerFrom:102e4}});b("getABTest",{version:1050100,platforms:{android:1050100,ios:!1}});b("userTrackAsync",{version:1e6});b("openMiniapp",{version:1050100});b("requestCoinDetailsSync",{version:1070100});b("requestCoinDetailsAsync",{version:1070100});b("sendServerEventAsync",{version:1070100});function b(e,t){if(q.config[e]){x.warn(`[can i use] ${e} already registered`);return}q.config[e]=v({},t)}var ft=(e,t)=>{function r(s){var d;let[i,...a]=s.split(":");if(!i)return!1;let o=q.config[i];if(!o)return!1;let u=(d=t==null?void 0:t())!=null?d:"",c=o.version;if(o.platforms&&u in o.platforms){let g=o.platforms[u];if(g===!1)return!1;typeof g=="number"&&(c=g)}if(typeof c!="number")return!1;let l=e();return typeof l!="number"||l<c?!1:a.length===0?!0:n(o,a,l)||n(o.properties,a,l)}function n(s,i,a){if(!s)return!1;let o=Re(s,i);if(!o)return!1;if(S(o)){let u=o.version;return X(u)?typeof a=="number"&&a>=u:!0}return X(o)?typeof a=="number"&&a>=o:o===!0}return{canIUseNative:r}};function P(e,t){return`[${e}]:${t}`}var Te=()=>Ae();var N="custom_event_";var ke=[],Ie=[],Ce=["env","createRequestTask","login"],J="__batch_event__",we="__native_batch_event__";var vt=e=>e==="pv"?e:"default",E=class{constructor(t){this.interval=30;this.lastReportTime=0;this.cache={};let{reporter:r,interval:n=30,eventName:s,tagNameOrder:i,metricName:a,type:o}=t;this.reporter=r,this.interval=n,this.eventName=s,this.tagNameOrder=i,this.metricName=a,this.type=vt(o)}report(t){this.type==="pv"?this.addPVPoint(t):this.addPoint(t),this.tryReport(!1)}flush(){this.tryReport(!0)}tryReport(t){if(Object.keys(this.cache).length){if(t){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(t){let r=(n,s,i,a)=>{let o=s.shift();if(o){let u=a[o];n[u]||(n[u]={}),r(n[u],s,i,a)}else n[i]||(n[i]=[]),n[i].push(a[i])};r(this.cache,[...this.tagNameOrder],this.metricName,t)}addPVPoint(t){let r=(s,i,a,o)=>{let u=i.shift();if(!u&&S(o))throw new L(`report value failed to match tagNameOrder, ${JSON.stringify(n)}`);if(u){let c=[];if(S(o))c.push(...Object.keys(o));else if(Q(o)){if(i.length>0)throw new L(`report value failed to match tagNameOrder, ${JSON.stringify(n)}`);c.push(o)}else throw new L(`expected metric value to be a string, but got a(n) ${typeof o}, ${JSON.stringify(n)}`);c.forEach(l=>{s[l]||(s[l]={});let d=S(o)?o[l]:o;r(s[l],[...i],a,d)})}else s[a]?s[a]++:s[a]=1},n={point:t,metricName:this.metricName,tagNameOrder:this.tagNameOrder};r(this.cache,[...this.tagNameOrder],this.metricName,t)}processPoints(t){return{eventName:this.eventName,tagNameOrder:this.tagNameOrder,metricName:this.metricName,metricAggregateType:this.type==="pv"?"itoa":"arr",data:t}}clearPoints(){this.cache={}}},Oe=!1,Z,ee,te;function Pe(e,t){Oe||(Z=new E({eventName:"jolibox_invoke",tagNameOrder:["status","method","errNo","errMsg","isForeground"],metricName:"duration",reporter(s){e.invoke("trackAsync",JSON.stringify({event:"reportMetrics",data:s}),-1)}}),ee=new E({eventName:"jolibox_invoke_js2native",tagNameOrder:["status","method","isForeground"],metricName:"duration",reporter(s){e.invoke("trackAsync",JSON.stringify({event:"reportMetrics",data:s}),-1)}}),te=new E({eventName:"jolibox_invoke_native2js",tagNameOrder:["status","method","isForeground"],metricName:"duration",reporter(s){e.invoke("trackAsync",JSON.stringify({event:"reportMetrics",data:s}),-1)}}),t("onJoliboxEnterBackground",()=>{Z.flush(),ee.flush(),te.flush()}),Oe=!0);function r(s){var T,k;let{method:i,args:a,startTime:o,isForeground:u,errMsg:c=`${i}:fail no errMsg`,errNo:l=0,__timing:d={receiveJSInvoke:0,invokeCallback:0}}=s,{receiveJSInvoke:g,invokeCallback:p}=d,f=(k=(T=c.match(/\S:(\S+)\s?/))==null?void 0:T[1])!=null?k:"fail";Z.report({status:f,method:n(i,a),errNo:`${l}`,errMsg:c,isForeground:u,duration:Date.now()-o}),o&&g&&p&&(ee.report({status:f,method:i,isForeground:u,duration:Number((g-o).toFixed(3))}),te.report({status:f,method:i,isForeground:u,duration:Number((Date.now()-p).toFixed(3))}))}function n(s,i){return(s==="callHostMethod"||s==="callHostMethodSync")&&i!=null&&i.method?`${s}-${i.method}`:s}return r}var re=[],bt=!1,ne=Symbol.for("Jolibox.invokeResolverInstance"),yt=new Map;globalThis[ne]||(globalThis[ne]=yt);var _t={get resolveMap(){return globalThis[ne]}};function De(e,t){let r=0,n=!0,s=_t.resolveMap,i=Pe(e,t);t("onJoliboxEnterBackground",()=>{n=!1}),t("onJoliboxEnterForeground",()=>{n=!0,re.forEach(g=>R(this,[g],function*({method:c,args:l,resolve:d}){let p=yield o(c,l);d(p)})),re.length=0});let a=(c,l)=>{let d=s.get(Number(c));if(!d)return;let g=I(l);d(g),s.delete(Number(c))},o=(c,l)=>{var ie,oe;let d=Date.now(),g=`${n}`;r+=1;let p=new ve;if(s.set(r,p.resolve),!n&&Ie.includes(c))return new Promise(_=>{re.push({method:c,args:l,resolve:_})});let T=le(v({},{method:c,startTime:d,args:l,isForeground:g}),{invokeType:"js-bridge"}),k=!bt&&ke.includes(c),$=ge(l,k),V=k?$:JSON.stringify($),h;if(c.endsWith("Sync")||Ce.includes(c)?h=(ie=e.call)==null?void 0:ie.call(e,c,$,r):typeof V=="string"?h=e.invoke(c,V,r):h=(oe=e.call)==null?void 0:oe.call(e,c,V,r),h){try{typeof h=="string"&&(h=JSON.parse(h)),h=I(h)}catch(_){x.error(_)}return s.delete(r),h.errorCode&&(h.errorCode=P(c,h.errorCode)),i(v(v({},T),h)),h}return c.endsWith("Sync")&&s.delete(r),p.promise.then(_=>(_.errorCode&&(_.errorCode=P(c,_.errorCode)),i(v(v({},T),_)),_))};return{invokeNative:o,applyNative:(c,l)=>{let d=o(c,l);return ye(d)?d.then(g=>Me(c,g)):Me(c,d)},invokeHandler:a}}function Me(e,t){if(!S(t)){x.warn(`[Jolibox SDK]${e} no response value`);return}let o=t,{errMsg:r,errNo:n,errorType:s,errorCode:i}=o,a=de(o,["errMsg","errNo","errorType","errorCode"]);if(r&&r!==`${e}:ok`)throw new Ne(r,n,s,i);return a}var F=Symbol.for("Jolibox.subscribeInstance");function Ue(e){if(globalThis[F])return globalThis[F];let t=new B,r=new B,n=new E({eventName:"jolibox_publish",tagNameOrder:["type","event"],metricName:"duration",reporter(s){e.invoke("trackAsync",JSON.stringify({event:"reportMetrics",data:s}),-1)}});return t.on("onJoliboxEnterBackground",()=>{n.flush()}),globalThis[F]={onNative:t.on.bind(t),offNative:t.off.bind(t),subscribe:r.on.bind(r),unsubscribe:r.off.bind(r),subscribeHandler(s,i,a){let o=I(i),u;if(o.__extra){u=o.params;let{type:c,startTime:l}=o.__extra;n.report({type:c,event:s,duration:Date.now()-l})}else u=o;if(s===J){u.forEach(l=>{let[d,g]=l;try{r.emit(d.slice(N.length),g,a)}catch(p){}});return}if(s.startsWith(N)){r.emit(s.slice(N.length),u,a);return}t.emit(s,u,a)}},globalThis[F]}function Le(e){let t=new Map,r=new Map,n,s;return{publish:(o,u,c,l)=>{if(l){let g=c!==void 0?c==="*"?"*":[c]:void 0;e.publish(`${N}${o}`,u,g);return}n||(n=Promise.resolve().then(()=>{t.forEach((g,p)=>{try{let f=p!==void 0?p==="*"?"*":[p]:void 0;e.publish(J,g,f)}catch(f){}}),n=void 0,t.clear()}));let d=t.get(c);d||(d=[],t.set(c,d)),d.push([`${N}${o}`,u])},emitNative:(o,u,c,l)=>{if(l){let g=c!==void 0?c==="*"?"*":[c]:void 0;e.publish(o,u,g),console.log("emitNative",o,u,g);return}s||(s=Promise.resolve().then(()=>{r.forEach((g,p)=>{try{let f=p!==void 0?p==="*"?"*":[p]:void 0;e.publish(we,g,f)}catch(f){}}),s=void 0,r.clear()}));let d=r.get(c);d||(d=[],r.set(c,d)),d.push([o,u])}}}function se(e){let{subscribeHandler:t,onNative:r,offNative:n,subscribe:s,unsubscribe:i}=Ue(e),{invokeNative:a,invokeHandler:o,applyNative:u}=De(e,r),{publish:c,emitNative:l}=Le(e);return{invokeHandler:o,subscribeHandler:t,applyNative:u,invokeNative:a,onNative:r,offNative:n,emitNative:l,publish:c,subscribe:s,unsubscribe:i}}function j(e,t){return{params:e,__extra:{startTime:Date.now(),type:t}}}var M,y={trigger(){},exit(){return Promise.resolve(!1)},backPress(){return Promise.resolve(!1)},onReady(e){y.trigger=e},onDoExit(e){y.exit=e},onDoBackPress(e){y.backPress=e}},qe=e=>{let t=window.prompt("invoke",JSON.stringify({event:"envSync",paramsString:JSON.stringify({})}));if(!t)e.onError(new Se("native env failed"));else{let{data:r}=JSON.parse(t);return r!=null?r:void 0}};if(typeof window!="undefined"&&window.webkit){let e=window.webkit.messageHandlers,t=(s="")=>{y.trigger(),e.onDocumentReady.postMessage({path:s})},r=s=>R(void 0,null,function*(){let i=yield y.exit();e.doExit.postMessage({uuid:s,shouldInterrupt:i})});M={onDocumentReady:t,doExit:r,invoke(s,i,a){e.invoke.postMessage({event:s,paramsString:i,callbackId:a})},publish(s,i,a){let o=j(i,"joliboxJSCore");window.prompt("publish",JSON.stringify({event:s,paramsString:JSON.stringify(o),webviewIds:a}))},call(s,i,a){let o=window.prompt("invoke",JSON.stringify({event:s,paramsString:JSON.stringify(i),callbackId:a}));if(o)return JSON.parse(o)}};let n={onDocumentReady:t,env:qe,doExit:r};globalThis.joliboxJSCore=v({},n)}if(typeof window!="undefined"&&window.JoliAndroidSDKBridge){let s,e=window.JoliAndroidSDKBridge,t=(i="")=>{y.trigger(),e.onDocumentReady(JSON.stringify({path:i}))},r=i=>R(void 0,null,function*(){let a=yield y.exit();e.doExit(JSON.stringify({uuid:i,shouldInterrupt:a}))});M={onDocumentReady:t,invoke(i,a,o){e.invoke(JSON.stringify({event:i,paramsString:a,callbackId:o}))},doExit:r,publish(i,a,o){let u=j(a,"joliboxJSCore");e.publish(JSON.stringify({event:i,paramsString:JSON.stringify(u),webviewIds:o}))},call(i,a,o){let u=window.prompt("invoke",JSON.stringify({event:i,paramsString:JSON.stringify(a),callbackId:o}));if(u)return JSON.parse(u)},doBackPress(i){return R(this,null,function*(){let a=yield y.backPress();e.doBackPress(JSON.stringify({uuid:i,shouldInterrupt:a}))})}};let n={onDocumentReady:t,env:qe,doExit:r};globalThis.joliboxJSCore=v({},n)}var Je=M;if(!Je&&Te())throw new Ee("No joliboxJScore is found, native bridge not found.");var St=v({},Je),Fe=se(St),{invokeHandler:Be}=Fe,{applyNative:Vr,invokeNative:Hr,onNative:Nt,offNative:Gr,subscribeHandler:Et,publish:Kr,emitNative:zr,subscribe:Wr,unsubscribe:Yr}=Fe,Qr=(e,t)=>{Nt(e,(...r)=>{var n;(n=r[0])!=null&&n.errorCode&&(r[0].errorCode=P(e,r[0].errorCode)),t(...r)})};globalThis.joliboxJSBridge={callHandler:Be,invokeHandler:Be,subscribeHandler:Et};export{y as RuntimeLoader,Vr as applyNative,zr as emitNative,Hr as invokeNative,Gr as offNative,Nt as onNative,Qr as onNativeWithError,Kr as publish,ft as registerCanIUseContext,Wr as subscribe,Et as subscribeHandler,Yr as unsubscribe};
|
|
@@ -527,6 +527,16 @@ declare global {
|
|
|
527
527
|
};
|
|
528
528
|
};
|
|
529
529
|
}>;
|
|
530
|
+
|
|
531
|
+
sendServerEventAsync: (params: {
|
|
532
|
+
payload: {
|
|
533
|
+
eventType: string;
|
|
534
|
+
[key: string]: any;
|
|
535
|
+
};
|
|
536
|
+
}) => Promise<{
|
|
537
|
+
errMsg: string;
|
|
538
|
+
errNo?: number;
|
|
539
|
+
}>;
|
|
530
540
|
}
|
|
531
541
|
|
|
532
542
|
interface NativeEventMap {
|
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.3.
|
|
4
|
+
"version": "1.3.4",
|
|
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.3.
|
|
15
|
-
"@jolibox/types": "1.3.
|
|
14
|
+
"@jolibox/common": "1.3.4",
|
|
15
|
+
"@jolibox/types": "1.3.4"
|
|
16
16
|
},
|
|
17
17
|
"devDependencies": {
|
|
18
18
|
"typescript": "5.7.3",
|
|
@@ -527,6 +527,16 @@ declare global {
|
|
|
527
527
|
};
|
|
528
528
|
};
|
|
529
529
|
}>;
|
|
530
|
+
|
|
531
|
+
sendServerEventAsync: (params: {
|
|
532
|
+
payload: {
|
|
533
|
+
eventType: string;
|
|
534
|
+
[key: string]: any;
|
|
535
|
+
};
|
|
536
|
+
}) => Promise<{
|
|
537
|
+
errMsg: string;
|
|
538
|
+
errNo?: number;
|
|
539
|
+
}>;
|
|
530
540
|
}
|
|
531
541
|
|
|
532
542
|
interface NativeEventMap {
|