wgappsdk
Version:
WarGaming App SDK for WebView communication
2 lines (1 loc) • 5.29 kB
JavaScript
!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,r,o,i,a,u=function(){return u=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},u.apply(this,arguments)};function l(e,t,n,r){return new(n||(n=Promise))((function(o,i){function a(e){try{l(r.next(e))}catch(e){i(e)}}function u(e){try{l(r.throw(e))}catch(e){i(e)}}function l(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,u)}l((r=r.apply(e,t||[])).next())}))}function s(e,t){var n,r,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(l){return function(u){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,u[0]&&(a=0)),a;)try{if(n=1,r&&(o=2&u[0]?r.return:u[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,u[1])).done)return o;switch(r=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++,r=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],r=0}finally{n=o=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,l])}}}function p(e){return new Promise((function(t,n){!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(n){n.callHandler("callClientFunction",e,(function(e){t(e)}))}))}))}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",e.VibrateLevel=void 0,(r=e.VibrateLevel||(e.VibrateLevel={})).LIGHT="light",r.MEDIUM="medium",r.HEAVY="heavy",e.AppNetMethod=void 0,(o=e.AppNetMethod||(e.AppNetMethod={})).GET="get",o.POST="post",e.JumpType=void 0,(i=e.JumpType||(e.JumpType={})).WEBLINK="weblink",i.CMSDETAIL="cmsdetail",i.INSIDELINK="insidelink",i.WEEKLYLINK="weeklylink",i.RANKFILTERLINK="rankfilterlink",i.OPENCLIENT="openclient",e.ShareType=void 0,(a=e.ShareType||(e.ShareType={})).URL="url",a.SCREENSHOT="base64bitmap",a.NETIMG="netimg",e.callNative=function(t,n){return l(this,void 0,void 0,(function(){var r,o,i,a,l,c,E,d;return s(this,(function(s){var f,T,O,S;return T=navigator.userAgent,O=T.indexOf("Android")>-1||T.indexOf("Adr")>-1,S=!!T.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/),r=O?"Android":S?"IOS":(f=T).includes("OpenHarmony")||f.includes("HarmonyOS")?"HarmonyOS":"PC",o={biz:t,data:u({method:e.AppNetMethod.GET},n)},t===e.JumpMethod.ENCODECALLURLSYNC&&(i=n.url,a=n.appMethod,l=function(e){var t=new URL(e);return{baseUrl:t.origin+t.pathname,urlParam:t.search.substr(1)}}(i),c=l.baseUrl,E=l.urlParam,d=null,a==e.AppNetMethod.POST&&(d=function(e){var t={};if(e)for(var n=e.split("&"),r=0;r<n.length;r++){var o=n[r].split("=");t[o[0]]=decodeURIComponent(o[1])}return t}(E)),o.data={baseUrl:c,urlParam:E,postParam:d}),"Android"===r||"HarmonyOS"===r?[2,new Promise((function(e,t){e(window.wargame.callClientFunction(JSON.stringify(o)))}))]:"IOS"===r?[2,p(o)]:[2,Promise.resolve("callNative function Error!")]}))}))},e.onAppMessage=function(e){return l(this,void 0,void 0,(function(){return s(this,(function(t){return window.callWebViewFunction=function(t){t.biz,e(t)},[2]}))}))}}));