UNPKG

wgappsdk

Version:

WarGaming App SDK for WebView communication

2 lines (1 loc) 5.55 kB
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).wgappsdk={})}(this,(function(e){"use strict";var t,n,o,i,r,a,l=function(){return l=Object.assign||function(e){for(var t,n=1,o=arguments.length;n<o;n++)for(var i in t=arguments[n])Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e},l.apply(this,arguments)};function u(e,t,n,o){return new(n||(n=Promise))((function(i,r){function a(e){try{u(o.next(e))}catch(e){r(e)}}function l(e){try{u(o.throw(e))}catch(e){r(e)}}function u(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,l)}u((o=o.apply(e,t||[])).next())}))}function s(e,t){var n,o,i,r,a={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return r={next:l(0),throw:l(1),return:l(2)},"function"==typeof Symbol&&(r[Symbol.iterator]=function(){return this}),r;function l(l){return function(u){return function(l){if(n)throw new TypeError("Generator is already executing.");for(;r&&(r=0,l[0]&&(a=0)),a;)try{if(n=1,o&&(i=2&l[0]?o.return:l[0]?o.throw||((i=o.return)&&i.call(o),0):o.next)&&!(i=i.call(o,l[1])).done)return i;switch(o=0,i&&(l=[2&l[0],i.value]),l[0]){case 0:case 1:i=l;break;case 4:return a.label++,{value:l[1],done:!1};case 5:a.label++,o=l[1],l=[0];continue;case 7:l=a.ops.pop(),a.trys.pop();continue;default:if(!(i=a.trys,(i=i.length>0&&i[i.length-1])||6!==l[0]&&2!==l[0])){a=0;continue}if(3===l[0]&&(!i||l[1]>i[0]&&l[1]<i[3])){a.label=l[1];break}if(6===l[0]&&a.label<i[1]){a.label=i[1],i=l;break}if(i&&a.label<i[2]){a.label=i[2],a.ops.push(l);break}i[2]&&a.ops.pop(),a.trys.pop();continue}l=t.call(e,a)}catch(e){l=[6,e],o=0}finally{n=i=0}if(5&l[0])throw l[1];return{value:l[0]?l[1]:void 0,done:!0}}([l,u])}}}function c(e){var t=window;return t.WKWebViewJavascriptBridge?e(t.WKWebViewJavascriptBridge):t.WKWVJBCallbacks?t.WKWVJBCallbacks.push(e):(t.WKWVJBCallbacks=[e],void(t.webkit&&t.webkit.messageHandlers&&t.webkit.messageHandlers.iOS_Native_InjectJavascript&&t.webkit.messageHandlers.iOS_Native_InjectJavascript.postMessage(null)))}e.NetStatus=void 0,(t=e.NetStatus||(e.NetStatus={})).NONE="NONE",t.WIFI="WIFI",t["2G"]="2G",t["3G"]="3G",t["4G"]="4G",t["5G"]="5G",e.JumpMethod=void 0,(n=e.JumpMethod||(e.JumpMethod={})).SHOWTITLE="showTitle",n.ENCODECALLURLSYNC="encodeCallUrlSync",n.OPENH5URL="openH5Url",n.OPENNEWH5URL="openNewH5Url",n.SHOWH5LOG="showH5Log",n.GETNETSTATUS="getNetStatus",n.SHOWNETERRORUI="showNetErrorUi",n.SHOWSUBTITLE="showSubTitle",n.JUMPTOUI="jumpToUi",n.JUMPTOSHARE="jumpToShare",n.JUMPTORANKFILTER="jumpToRankFilter",n.SHAREBTNISSHOW="shareBtnIsShow",n.GETCURUSERPLAT="getCurUserPlat",n.JUMPTOLOGIN="jumpToLogin",n.GETCURVERSION="getCurVersion",n.TITLEBARSTYLEMOTIFY="titleBarStyleMotify",n.JUMPIMAGEBROWSEPAGE="JumpImageBrowsePage",n.SAVEIMAGETOGALLERY="SaveImageToGallery",n.FINISHWEB="finishWeb",n.OPENINPUTVIEW="openInputView",n.OPENINPUTVIEWFORUM="openInputViewForum",n.OPENEDITORFORUM="openEditorForum",n.PUSHFORUMVOTE="pushForumVote",n.PUSHFORUMRECORD="pushForumRecord",n.GETCOMMUNITYTOKEN="getCommmunityToken",n.EDITAVATARFORUM="editAvatarForum",n.VIBRATE="vibrate",n.GETDEVICECONFIGURE="getDeviceConfigure",n.OPENSELECT="openSelect",n.OPENMODAL="openModal",n.VIDEOPLAYER="jumpToVideoPlayer",n.PUSHMESSAGE="pushMessage",n.GETAPPUSERINFO="getAppUserInfo",n.FULLDIALOG="fullDialog",n.SETREQUESTEDORIENTATION="setRequestedOrientation",n.CLIENTRECORD="clientRecord",n.SELECTALBUM="selectAlbum",n.GEOLOCATION="geolocation",e.VibrateLevel=void 0,(o=e.VibrateLevel||(e.VibrateLevel={})).LIGHT="light",o.MEDIUM="medium",o.HEAVY="heavy",e.AppNetMethod=void 0,(i=e.AppNetMethod||(e.AppNetMethod={})).GET="get",i.POST="post",e.JumpType=void 0,(r=e.JumpType||(e.JumpType={})).WEBLINK="weblink",r.CMSDETAIL="cmsdetail",r.SHIPINSIDELINK="shipinsidelink",r.WEEKLYLINK="weeklylink",r.RANKFILTERLINK="rankfilterlink",r.OPENCLIENT="openclient",r.INSIDELINK="insidelink",r.OPENBROWSER="openbrowser",r.OPENUPLOAD="openupload",e.ShareType=void 0,(a=e.ShareType||(e.ShareType={})).URL="url",a.SCREENSHOT="base64bitmap",a.NETIMG="netimg",e.callNative=function(t,n){return u(this,void 0,void 0,(function(){var o,i,r,a,u,p,E,d;return s(this,(function(s){var O,f,T,N,S;return f=navigator.userAgent,T=f.indexOf("Android")>-1||f.indexOf("Adr")>-1,N=!!f.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/),o=T?"Android":N?"IOS":(O=f).includes("OpenHarmony")||O.includes("HarmonyOS")?"HarmonyOS":"PC",i={biz:t,data:l({method:e.AppNetMethod.GET},n)},t===e.JumpMethod.ENCODECALLURLSYNC&&(r=n.url,a=n.appMethod,u=function(e){var t=new URL(e);return{baseUrl:t.origin+t.pathname,urlParam:t.search.substr(1)}}(r),p=u.baseUrl,E=u.urlParam,d=null,a==e.AppNetMethod.POST&&(d=function(e){var t={};if(e)for(var n=e.split("&"),o=0;o<n.length;o++){var i=n[o].split("=");t[i[0]]=decodeURIComponent(i[1])}return t}(E)),i.data={baseUrl:p,urlParam:E,postParam:d}),"Android"===o||"HarmonyOS"===o?[2,new Promise((function(e,t){e(window.wargame.callClientFunction(JSON.stringify(i)))}))]:"IOS"===o?[2,(S=i,new Promise((function(e,t){c((function(t){t.callHandler("callClientFunction",S,(function(t){e(t)}))}))})))]:[2,Promise.resolve("callNative function Error!")]}))}))},e.onAppMessage=function(e){return u(this,void 0,void 0,(function(){return s(this,(function(t){return c((function(e){e.registerHandler("callWebViewFunction",(function(e,t){window.callWebViewFunction(e)}))})),window.callWebViewFunction=function(t){t.biz,e(t)},[2]}))}))}}));