act-soloop-js-bridge
Version:
H5与即录soloop App交互工具库
8 lines • 14.5 kB
JavaScript
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports["js-bridge"]=e():t["js-bridge"]=e()}(this,(function(){return(n={},t.m=e=[function(t,e,n){
/*!
* @oppo/lib-heytap-jsapi.js v1.0.1
* (c) 2018-2019 liutianwen@oppo.com
* native通信方法.
*/
t.exports=function(){"use strict";function t(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}function e(){}function n(t){return"function"==typeof t}function r(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:6;return Math.random().toString().slice(-t)}return new(function(){function o(){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,o),this.clientCallMap={},this.apiCallMap={},this.broadMap={},window.heytapCall=this._clientCallHandler.bind(this)}return function(e,n,r){n&&t(e.prototype,n),r&&t(e,r)}(o,[{key:"invoke",value:function(){var t=this,o=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},i=r(),a=o.name;if(!a)throw new Error("The name field is required");if(1===a.split(/\./).length){if(!o.module)throw new Error("The module field is required when there is no module information in the name field");a="".concat(o.module,".").concat(a)}if(o.fail&&n(o.fail)||(o.fail=e),o.success&&n(o.success)||(o.success=e),!o.complete||!n(o.complete))return new Promise((function(e,n){t.apiCallMap[i]=function(t){e(t)},!!window.HeytapNativeApi&&HeytapNativeApi.invoke(a,JSON.stringify(o.data),i)?o.success():n("unsupported method")}));this.apiCallMap[i]=o.complete;var c=!!window.HeytapNativeApi&&HeytapNativeApi.invoke(a,JSON.stringify(o.data),i);c?o.success():o.fail("unsupported method")}},{key:"callback",value:function(t,e){this.apiCallMap[t]&&this.apiCallMap[t](e),delete this.apiCallMap[t]}},{key:"_clientCallHandler",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(t&&this.clientCallMap[t]){var n=this.clientCallMap[t];n.forEach((function(t){t(e)}))}}},{key:"registeAction",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:e;if(!t)throw new Error("注册事件回调的动作名不能为空");if(!r||!n(r))throw new Error("注册事件回调的函数不能为空");var o=this.clientCallMap[t];o?this.clientCallMap[t].push(r):this.clientCallMap[t]=[r]}},{key:"registerBroadcast",value:function(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:e;t&&(this.broadMap[t]=n,window.HeytapNativeApi&&HeytapNativeApi.registerBroadcastReceiver(t,t))}},{key:"removeBroadcast",value:function(t){var e=this;t&&("string"==typeof t&&(t=[t]),t instanceof Array&&t.forEach((function(t){window.HeytapNativeApi&&HeytapNativeApi.removeBroadcastReceiver(t),delete e.broadMap[t]})))}},{key:"broadcastReceiver",value:function(t,e){var n=this.broadMap[t];n&&n(JSON.parse(e))}},{key:"doBroadcast",value:function(t,e){t&&this.broadMap[t]&&window.HeytapNativeApi&&window.HeytapNativeApi.broadcast(t,JSON.stringify(e))}},{key:"version",get:function(){return"1.0.0"}}]),o}())}()},function(t,e,n){t.exports=n(5)},function(t,e){function n(t,e,n,r,o,i,a){try{var c=t[i](a),u=c.value}catch(t){return void n(t)}c.done?e(u):Promise.resolve(u).then(r,o)}t.exports=function(t){return function(){var e=this,r=arguments;return new Promise((function(o,i){var a=t.apply(e,r);function c(t){n(a,o,i,c,u,"next",t)}function u(t){n(a,o,i,c,u,"throw",t)}c(void 0)}))}}},function(t,e){t.exports=function(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}},function(t,e,n){"use strict";n.r(e);var r=n(3),o=n.n(r),i=n(1),a=n.n(i),c=n(2),u=n.n(c),f=n(0),s=n.n(f);function l(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),n.push.apply(n,r)}return n}function p(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?l(Object(n),!0).forEach((function(e){o()(t,e,n[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):l(Object(n)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))}))}return t}function h(){return s.a.invoke({name:"common.app_info",data:{}}).then((function(t){return t.data})).catch((function(t){return Promise.reject(t)}))}function d(){return s.a.invoke({name:"account.open_id",data:{}}).then((function(t){return t.data?t.data.open_id:Promise.reject("无法获取到open_id")})).catch((function(t){return Promise.reject(t)}))}function v(){return(v=u()(a.a.mark((function t(){var e,n,r=arguments;return a.a.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return e=0<r.length&&void 0!==r[0]?r[0]:"com.coloros.videoeditor",n=!1,t.next=4,h().catch((function(){return{}}));case 4:return t.sent.package_name===e&&(n=!0),t.abrupt("return",n);case 7:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function y(){return s.a.invoke({name:"common.device_info",data:{}}).then((function(t){return t.data})).catch((function(t){return Promise.reject(t)}))}function m(){return(m=u()(a.a.mark((function t(){var e,n;return a.a.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,y().catch((function(){return!1}));case 2:return e=t.sent,t.next=5,d().catch((function(){return!1}));case 5:if(n=t.sent,e&&!1!==n)return t.abrupt("return",p({},e,{openId:n}));t.next=10;break;case 10:return t.abrupt("return",Promise.reject("获取设备信息失败"));case 11:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function g(){return s.a.invoke({name:"account.user_info",data:{}}).then((function(t){return 0===t.code&&t.data?t.data:Promise.reject(t.data)})).catch((function(t){return Promise.reject(t)}))}function w(){return(w=u()(a.a.mark((function t(){var e;return a.a.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,g().catch((function(){return{}}));case 2:return e=t.sent,t.abrupt("return",!!e.isLogin);case 4:case"end":return t.stop()}}),t)})))).apply(this,arguments)}window.HeytapJsApi=s.a,e.default={isInApp:function(){return v.apply(this,arguments)},getDeviceInfo:y,getAppInfo:h,getUserInfo:g,getOpenId:d,getAllDeviceInfo:function(){return m.apply(this,arguments)},isLogin:function(){return w.apply(this,arguments)},doLogin:function(){return s.a.invoke({name:"account.login",data:{}}).then((function(t){return 0===t.code&&t.data?t.data:Promise.reject(t.data)})).catch((function(t){return Promise.reject(t)}))},openAppWebPage:function(t){var e=t||window.location.href,n=function(t,e){var n=e||window.location.search||"";if(n=n.replace(/\?/g,"&")){var r=new RegExp("(^|&)title=([^&]*)(&|$)","i"),o=n.match(r);return null!=o?decodeURI(o[2]):null}return null}(0,e);window.location.href="oaps://soloop/web?u=".concat(encodeURIComponent(e),"&t=").concat(n)},openAppVideoEditor:function(){window.location.href="hap://soloop/materialpicker"},openAppMall:function(){s.a.invoke({name:"mall.point_mall",data:{}})},toast:function(t){var e=1<arguments.length&&void 0!==arguments[1]?arguments[1]:2e3;s.a.invoke({name:"common.toast",data:{message:t,duration:e}})}}},function(t,e,n){var r=function(t){"use strict";var e,n=Object.prototype,r=n.hasOwnProperty,o="function"==typeof Symbol?Symbol:{},i=o.iterator||"@@iterator",a=o.asyncIterator||"@@asyncIterator",c=o.toStringTag||"@@toStringTag";function u(t,e,n,r){var o,i,a,c,u=e&&e.prototype instanceof v?e:v,y=Object.create(u.prototype),m=new L(r||[]);return y._invoke=(o=t,i=n,a=m,c=s,function(t,e){if(c===p)throw new Error("Generator is already running");if(c===h){if("throw"===t)throw e;return M()}for(a.method=t,a.arg=e;;){var n=a.delegate;if(n){var r=k(n,a);if(r){if(r===d)continue;return r}}if("next"===a.method)a.sent=a._sent=a.arg;else if("throw"===a.method){if(c===s)throw c=h,a.arg;a.dispatchException(a.arg)}else"return"===a.method&&a.abrupt("return",a.arg);c=p;var u=f(o,i,a);if("normal"===u.type){if(c=a.done?h:l,u.arg===d)continue;return{value:u.arg,done:a.done}}"throw"===u.type&&(c=h,a.method="throw",a.arg=u.arg)}}),y}function f(t,e,n){try{return{type:"normal",arg:t.call(e,n)}}catch(t){return{type:"throw",arg:t}}}t.wrap=u;var s="suspendedStart",l="suspendedYield",p="executing",h="completed",d={};function v(){}function y(){}function m(){}var g={};g[i]=function(){return this};var w=Object.getPrototypeOf,b=w&&w(w(_([])));b&&b!==n&&r.call(b,i)&&(g=b);var x=m.prototype=v.prototype=Object.create(g);function j(t){["next","throw","return"].forEach((function(e){t[e]=function(t){return this._invoke(e,t)}}))}function O(t){var e;this._invoke=function(n,o){function i(){return new Promise((function(e,i){!function e(n,o,i,a){var c=f(t[n],t,o);if("throw"!==c.type){var u=c.arg,s=u.value;return s&&"object"==typeof s&&r.call(s,"__await")?Promise.resolve(s.__await).then((function(t){e("next",t,i,a)}),(function(t){e("throw",t,i,a)})):Promise.resolve(s).then((function(t){u.value=t,i(u)}),(function(t){return e("throw",t,i,a)}))}a(c.arg)}(n,o,e,i)}))}return e=e?e.then(i,i):i()}}function k(t,n){var r=t.iterator[n.method];if(r===e){if(n.delegate=null,"throw"===n.method){if(t.iterator.return&&(n.method="return",n.arg=e,k(t,n),"throw"===n.method))return d;n.method="throw",n.arg=new TypeError("The iterator does not provide a 'throw' method")}return d}var o=f(r,t.iterator,n.arg);if("throw"===o.type)return n.method="throw",n.arg=o.arg,n.delegate=null,d;var i=o.arg;return i?i.done?(n[t.resultName]=i.value,n.next=t.nextLoc,"return"!==n.method&&(n.method="next",n.arg=e),n.delegate=null,d):i:(n.method="throw",n.arg=new TypeError("iterator result is not an object"),n.delegate=null,d)}function P(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function E(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function L(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(P,this),this.reset(!0)}function _(t){if(t){var n=t[i];if(n)return n.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var o=-1,a=function n(){for(;++o<t.length;)if(r.call(t,o))return n.value=t[o],n.done=!1,n;return n.value=e,n.done=!0,n};return a.next=a}}return{next:M}}function M(){return{value:e,done:!0}}return y.prototype=x.constructor=m,m.constructor=y,m[c]=y.displayName="GeneratorFunction",t.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===y||"GeneratorFunction"===(e.displayName||e.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,m):(t.__proto__=m,c in t||(t[c]="GeneratorFunction")),t.prototype=Object.create(x),t},t.awrap=function(t){return{__await:t}},j(O.prototype),O.prototype[a]=function(){return this},t.AsyncIterator=O,t.async=function(e,n,r,o){var i=new O(u(e,n,r,o));return t.isGeneratorFunction(n)?i:i.next().then((function(t){return t.done?t.value:i.next()}))},j(x),x[c]="Generator",x[i]=function(){return this},x.toString=function(){return"[object Generator]"},t.keys=function(t){var e=[];for(var n in t)e.push(n);return e.reverse(),function n(){for(;e.length;){var r=e.pop();if(r in t)return n.value=r,n.done=!1,n}return n.done=!0,n}},t.values=_,L.prototype={constructor:L,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=e,this.done=!1,this.delegate=null,this.method="next",this.arg=e,this.tryEntries.forEach(E),!t)for(var n in this)"t"===n.charAt(0)&&r.call(this,n)&&!isNaN(+n.slice(1))&&(this[n]=e)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var n=this;function o(r,o){return c.type="throw",c.arg=t,n.next=r,o&&(n.method="next",n.arg=e),!!o}for(var i=this.tryEntries.length-1;0<=i;--i){var a=this.tryEntries[i],c=a.completion;if("root"===a.tryLoc)return o("end");if(a.tryLoc<=this.prev){var u=r.call(a,"catchLoc"),f=r.call(a,"finallyLoc");if(u&&f){if(this.prev<a.catchLoc)return o(a.catchLoc,!0);if(this.prev<a.finallyLoc)return o(a.finallyLoc)}else if(u){if(this.prev<a.catchLoc)return o(a.catchLoc,!0)}else{if(!f)throw new Error("try statement without catch or finally");if(this.prev<a.finallyLoc)return o(a.finallyLoc)}}}},abrupt:function(t,e){for(var n=this.tryEntries.length-1;0<=n;--n){var o=this.tryEntries[n];if(o.tryLoc<=this.prev&&r.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var i=o;break}}i&&("break"===t||"continue"===t)&&i.tryLoc<=e&&e<=i.finallyLoc&&(i=null);var a=i?i.completion:{};return a.type=t,a.arg=e,i?(this.method="next",this.next=i.finallyLoc,d):this.complete(a)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),d},finish:function(t){for(var e=this.tryEntries.length-1;0<=e;--e){var n=this.tryEntries[e];if(n.finallyLoc===t)return this.complete(n.completion,n.afterLoc),E(n),d}},catch:function(t){for(var e=this.tryEntries.length-1;0<=e;--e){var n=this.tryEntries[e];if(n.tryLoc===t){var r=n.completion;if("throw"===r.type){var o=r.arg;E(n)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,n,r){return this.delegate={iterator:_(t),resultName:n,nextLoc:r},"next"===this.method&&(this.arg=e),d}},t}(t.exports);try{regeneratorRuntime=r}catch(t){Function("r","regeneratorRuntime = r")(r)}}],t.c=n,t.d=function(e,n,r){t.o(e,n)||Object.defineProperty(e,n,{enumerable:!0,get:r})},t.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},t.t=function(e,n){if(1&n&&(e=t(e)),8&n)return e;if(4&n&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(t.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&n&&"string"!=typeof e)for(var o in e)t.d(r,o,function(t){return e[t]}.bind(null,o));return r},t.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(n,"a",n),n},t.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},t.p="",t(t.s=4)).default;function t(r){if(n[r])return n[r].exports;var o=n[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,t),o.l=!0,o.exports}var e,n}));
//# sourceMappingURL=index.js.map