zmp-sdk
Version:
Zalo Mini App SDK
2 lines (1 loc) • 2.2 kB
JavaScript
import t from'./../external/@swc/helpers/src/_class_call_check.mjs.js';import e from'./../external/@swc/helpers/src/_get.mjs.js';import n from'./../external/@swc/helpers/src/_get_prototype_of.mjs.js';import o from'./../external/@swc/helpers/src/_inherits.mjs.js';import r from'./../external/@swc/helpers/src/_create_super.mjs.js';import a from'./../external/eventemitter3/index.js';import s from"../utils/debug.js";import{stringToData as c}from"../utils/common.js";import{APP_ID as i}from"../constants.js";import{Events as m}from"../types/enum.js";var l="ACTION_CALLBACK";var p=function(a){o(i,a);var c=r(i);function i(){var e;return t(this,i),(e=c.apply(this,arguments)).debug=s("zmp:event-emitter"),e}var p=i.prototype;return p.h5ConfirmHandleEvent=function(t,e,n){ZaloJavaScriptInterface.jsH5EventCallback(t,e,n||"")},p.on=function(t,o,r){var a=this;if(t===l||t===m.PaymentCallback)return e(n(i.prototype),"on",this).call(this,t,o,r);this.debug("register ".concat(String(t),": ").concat(r));return e(n(i.prototype),"on",this).call(this,t,(function(e,n){a.h5ConfirmHandleEvent(e,t,r),o(n)}),r)},p.once=function(t,o,r){var a=this;if(t===l)return e(n(i.prototype),"once",this).call(this,t,o,r);this.debug("register once ".concat(String(t),": ").concat(r));return e(n(i.prototype),"once",this).call(this,t,(function(e,n){a.h5ConfirmHandleEvent(e,t,r),o(n)}),r)},i.getInstance=function(){return i.instance||(i.instance=new i),i.instance},i}(a);function u(t){p.getInstance().on(l,t)}function f(t){p.getInstance().emit(l,t)}window.onNativeMessage=function(t,e){return function(n){f({serialId:t,actionName:e,result:n})}},window.zaloJSV2={zalo_h5_event_handler:function(t,e,n){var o=s("zmp:zalo_h5_event_handler");o("eventId: ".concat(t,", eventName: ").concat(e,", eventData: ").concat(n));var r=c(n);o("stringToData",r);var a=function(t,e){try{if(t===m.OpenApp){var n=e.url,o=new URL(n),r=o.pathname.split("/zapps/".concat(i))[1];return{path:"".concat(r||"/").concat(o.search)}}return e}catch(t){return e}}(e,r);p.getInstance().emit(e,t,a)}},window.zaloNative2JS={nativeCall:function(t,e,n){p.getInstance().emit(m.PaymentCallback,t,e,n)}};export{p as MPEEmitter,f as fireActionMessage,u as onActionMessage};