UNPKG

@yunzhijia/qing

Version:

> qingjs是为了方便前端人员在云之家环境调用native代码的工具类,兼容新版桌面端、老版桌面端、移动端、微信

2 lines 3.89 kB
/** Fri Sep 15 2023 13:31:58 GMT+0800 (中国标准时间) **/ (self.qingJsonpFunction=self.qingJsonpFunction||[]).push([[237,487],{7237:(n,e,o)=>{var t=window.qing;t.define("desktop-remote",function(n,e){if(t.isDesktop){var i=o(6860),c=function(){var o=window._CloudHubWebJSBridge;o&&o.version?t.ready(function(){!function(n,e,o){var t=e.call,i={};n.init(e,o,function(){e.call=function(o,c){i[o]?t(o,c):e.checkJsApi({jsApiList:[o],success:function(e){e.data[o]?(i[o]=!0,t(o,c)):n.call(o,c)}})}})}(i,t._bridge,e)}):i.init(t._bridge,e,function(){setTimeout(function(){n.call=i.call,n.checkJsApi=i.checkJsApi},300)})};if(window._CloudHubWebJSBridge)c();else{var u=document;u.addEventListener("QingWebJSLoaded",function n(){c(),u.removeEventListener("QingWebJSLoaded",n)})}}})},6860:(n,e,o)=>{"use strict";o.r(e),o.d(e,{call:()=>A,checkJsApi:()=>(function(n){A("checkJsApi",n)}),init:()=>(function(n){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},t=arguments.length>2?arguments[2]:void 0,c=!1;void 0!==e.saas?c=e.saas:"cloudhub"!=e.scheme&&(c=!0);c?(e.scheme=e.scheme||"cloudhub-private",e.port=e.port||"28064"):(e.scheme="cloudhub",e.port="1864");i=e,function(n,e){l?o.e(234).then(o.bind(o,8234)).then(function(o){(d=o.default).loadFlashPolicyFile("xmlsocket://127.0.0.1:".concat(n,"/")),e()},e):e()}(e.port,function(){p(e.port,5e3),t()}),k.on=n.on,k.once=n.once,k.off=n.off,k.emit=n.trigger,k.has=n.has})});var t,i,c=window.qing,u=c.utils.Events,a=new u,s=new u,d=window.WebSocket,r=void 0!==d,f=2e3,l=c.isIe()&&"https:"==location.protocol,h=!1,m=0;function p(n,e){r&&n&&(t||function n(e,o){o--,(t=new d("ws://127.0.0.1:".concat(e))).onopen=function(){h=!0},t.onerror=function(){},t.onmessage=function(n){var e=JSON.parse(n.data);e.id?g(e.id,e.data,{code:e.code,data:e.data}):g(e.cmd,e.data,{code:e.code,data:e.data})},t.onclose=function(){h=!1,g("closed"),o<0?t=null:setTimeout(function(){n(e,o)},f)}}(n,parseInt(e/(f+1e3))))}function v(n,e,o){o?s.once(n,e):a.once(n,e)}function g(n,e,o){s.emit(n,e,o),a.emit(n,e,o)}function b(n,e){var o;if(e)for(var i in e.success&&v(o=++m,e.success,!0),e)"function"==typeof e[i]&&delete e[i];t.send(JSON.stringify({cmd:n,id:o,data:e}))}function w(n,e){Array.isArray(n)?n.forEach(function(n){b(n[0],n[1])}):b(n,e)}a.on("closed",function(){s.clear()});var k={};function y(n,e){var o=function(){J.callback=null,w(n)};J.callback&&function(n,e){s.off(n,e),a.off(n,e)}("logined",J.callback),J.callback=o,v("logined",o,!0)}function J(n,e){k.has("requestLoginCode")?k.emit("requestLoginCode",function(o){o?(w("_login",{eid:e.eid,oid:e.oId||e.openId,code:o}),v("logined",function(){w(n)})):y(n)}):y(n)}var I=function(){var n,e=[];return function(o,t){/^_/.test(o)||(/^system:/.test(o)?w(o,t):(e.push([o,t]),clearTimeout(n),n=setTimeout(function(){n=null;var o=function(){var n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};w("_isLogin",{oId:n.oId||n.openId,eid:n.eid,success:function(o){o.success?w(e):J(e,n),e=[]}})};k.has("requestUserInfo")?k.emit("requestUserInfo",o):o()},150)))}}(),L=function(){var n,e=[];return function(o,t){t&&e.push(t),clearTimeout(n),n=setTimeout(function(){var t=document.createElement("iframe");t.style.position="absolute",t.style.zIndex="-1",t.style.left="-10000px",t.style.top="-1000px",t.src="".concat(i.scheme,"://start"),document.body.appendChild(t),setTimeout(function(){p(i.port,o),e.forEach(function(n){n()}),e.length=0,document.body.removeChild(t),t=null},2e3),n=null},100)}}(),T=function(){var n=0,e=[];return function(o,t){var c=i.timeout||16e3,u=c/1e3;if(e.push({name:o,data:t}),n>0)return n++,void L(c);n=u;L(c,function o(){if(--n<=0)return e.forEach(function(n){var e=n.data.error,o={success:!1,errorCode:"NOT_INSTALL"};e&&e(o,{code:200,data:o})}),void(e.length=0);h?(e.forEach(function(n){I(n.name,n.data)}),n=0,e.length=0):setTimeout(o,1e3)})}}();function A(n,e){h?I(n,e):T(n,e)}}}]);