UNPKG

wgappsdk

Version:

WarGaming App SDK for WebView communication

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