UNPKG

easy-qwebchannel

Version:

Easy IPC communication for QT applications

3 lines (2 loc) 15.2 kB
"use strict";function e(){e=function(){return t};var t={},n=Object.prototype,r=n.hasOwnProperty,o=Object.defineProperty||function(e,t,n){e[t]=n.value},i="function"==typeof Symbol?Symbol:{},a=i.iterator||"@@iterator",c=i.asyncIterator||"@@asyncIterator",s=i.toStringTag||"@@toStringTag";function u(e,t,n){return Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{u({},"")}catch(e){u=function(e,t,n){return e[t]=n}}function f(e,t,n,r){var i=Object.create((t&&t.prototype instanceof p?t:p).prototype),a=new S(r||[]);return o(i,"_invoke",{value:j(e,n,a)}),i}function l(e,t,n){try{return{type:"normal",arg:e.call(t,n)}}catch(e){return{type:"throw",arg:e}}}t.wrap=f;var h={};function p(){}function d(){}function v(){}var y={};u(y,a,(function(){return this}));var _=Object.getPrototypeOf,g=_&&_(_(k([])));g&&g!==n&&r.call(g,a)&&(y=g);var b=v.prototype=p.prototype=Object.create(y);function w(e){["next","throw","return"].forEach((function(t){u(e,t,(function(e){return this._invoke(t,e)}))}))}function m(e,t){var n;o(this,"_invoke",{value:function(o,i){function a(){return new t((function(n,a){!function n(o,i,a,c){var s=l(e[o],e,i);if("throw"!==s.type){var u=s.arg,f=u.value;return f&&"object"==typeof f&&r.call(f,"__await")?t.resolve(f.__await).then((function(e){n("next",e,a,c)}),(function(e){n("throw",e,a,c)})):t.resolve(f).then((function(e){u.value=e,a(u)}),(function(e){return n("throw",e,a,c)}))}c(s.arg)}(o,i,n,a)}))}return n=n?n.then(a,a):a()}})}function j(e,t,n){var r="suspendedStart";return function(o,i){if("executing"===r)throw new Error("Generator is already running");if("completed"===r){if("throw"===o)throw i;return{value:void 0,done:!0}}for(n.method=o,n.arg=i;;){var a=n.delegate;if(a){var c=x(a,n);if(c){if(c===h)continue;return c}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if("suspendedStart"===r)throw r="completed",n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);r="executing";var s=l(e,t,n);if("normal"===s.type){if(r=n.done?"completed":"suspendedYield",s.arg===h)continue;return{value:s.arg,done:n.done}}"throw"===s.type&&(r="completed",n.method="throw",n.arg=s.arg)}}}function x(e,t){var n=t.method,r=e.iterator[n];if(void 0===r)return t.delegate=null,"throw"===n&&e.iterator.return&&(t.method="return",t.arg=void 0,x(e,t),"throw"===t.method)||"return"!==n&&(t.method="throw",t.arg=new TypeError("The iterator does not provide a '"+n+"' method")),h;var o=l(r,e.iterator,t.arg);if("throw"===o.type)return t.method="throw",t.arg=o.arg,t.delegate=null,h;var i=o.arg;return i?i.done?(t[e.resultName]=i.value,t.next=e.nextLoc,"return"!==t.method&&(t.method="next",t.arg=void 0),t.delegate=null,h):i:(t.method="throw",t.arg=new TypeError("iterator result is not an object"),t.delegate=null,h)}function O(e){var t={tryLoc:e[0]};1 in e&&(t.catchLoc=e[1]),2 in e&&(t.finallyLoc=e[2],t.afterLoc=e[3]),this.tryEntries.push(t)}function E(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function S(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(O,this),this.reset(!0)}function k(e){if(e){var t=e[a];if(t)return t.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var n=-1,o=function t(){for(;++n<e.length;)if(r.call(e,n))return t.value=e[n],t.done=!1,t;return t.value=void 0,t.done=!0,t};return o.next=o}}return{next:L}}function L(){return{value:void 0,done:!0}}return d.prototype=v,o(b,"constructor",{value:v,configurable:!0}),o(v,"constructor",{value:d,configurable:!0}),d.displayName=u(v,s,"GeneratorFunction"),t.isGeneratorFunction=function(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===d||"GeneratorFunction"===(t.displayName||t.name))},t.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,v):(e.__proto__=v,u(e,s,"GeneratorFunction")),e.prototype=Object.create(b),e},t.awrap=function(e){return{__await:e}},w(m.prototype),u(m.prototype,c,(function(){return this})),t.AsyncIterator=m,t.async=function(e,n,r,o,i){void 0===i&&(i=Promise);var a=new m(f(e,n,r,o),i);return t.isGeneratorFunction(n)?a:a.next().then((function(e){return e.done?e.value:a.next()}))},w(b),u(b,s,"Generator"),u(b,a,(function(){return this})),u(b,"toString",(function(){return"[object Generator]"})),t.keys=function(e){var t=Object(e),n=[];for(var r in t)n.push(r);return n.reverse(),function e(){for(;n.length;){var r=n.pop();if(r in t)return e.value=r,e.done=!1,e}return e.done=!0,e}},t.values=k,S.prototype={constructor:S,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(E),!e)for(var t in this)"t"===t.charAt(0)&&r.call(this,t)&&!isNaN(+t.slice(1))&&(this[t]=void 0)},stop:function(){this.done=!0;var e=this.tryEntries[0].completion;if("throw"===e.type)throw e.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var t=this;function n(n,r){return a.type="throw",a.arg=e,t.next=n,r&&(t.method="next",t.arg=void 0),!!r}for(var o=this.tryEntries.length-1;o>=0;--o){var i=this.tryEntries[o],a=i.completion;if("root"===i.tryLoc)return n("end");if(i.tryLoc<=this.prev){var c=r.call(i,"catchLoc"),s=r.call(i,"finallyLoc");if(c&&s){if(this.prev<i.catchLoc)return n(i.catchLoc,!0);if(this.prev<i.finallyLoc)return n(i.finallyLoc)}else if(c){if(this.prev<i.catchLoc)return n(i.catchLoc,!0)}else{if(!s)throw new Error("try statement without catch or finally");if(this.prev<i.finallyLoc)return n(i.finallyLoc)}}}},abrupt:function(e,t){for(var n=this.tryEntries.length-1;n>=0;--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"===e||"continue"===e)&&i.tryLoc<=t&&t<=i.finallyLoc&&(i=null);var a=i?i.completion:{};return a.type=e,a.arg=t,i?(this.method="next",this.next=i.finallyLoc,h):this.complete(a)},complete:function(e,t){if("throw"===e.type)throw e.arg;return"break"===e.type||"continue"===e.type?this.next=e.arg:"return"===e.type?(this.rval=this.arg=e.arg,this.method="return",this.next="end"):"normal"===e.type&&t&&(this.next=t),h},finish:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var n=this.tryEntries[t];if(n.finallyLoc===e)return this.complete(n.completion,n.afterLoc),E(n),h}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var n=this.tryEntries[t];if(n.tryLoc===e){var r=n.completion;if("throw"===r.type){var o=r.arg;E(n)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,n){return this.delegate={iterator:k(e),resultName:t,nextLoc:n},"next"===this.method&&(this.arg=void 0),h}},t}function t(e,t,n,r,o,i,a){try{var c=e[i](a),s=c.value}catch(e){return void n(e)}c.done?t(s):Promise.resolve(s).then(r,o)}function n(e){return function(){var n=this,r=arguments;return new Promise((function(o,i){var a=e.apply(n,r);function c(e){t(a,o,i,c,s,"next",e)}function s(e){t(a,o,i,c,s,"throw",e)}c(void 0)}))}}Object.defineProperty(exports,"__esModule",{value:!0});var r=function(e,t){if("object"==typeof e&&"function"==typeof e.send){var n=this;this.transport=e,this.send=function(e){"string"!=typeof e&&(e=JSON.stringify(e)),n.transport.send(e)},this.transport.onmessage=function(e){var t=e.data;switch("string"==typeof t&&(t=JSON.parse(t)),t.type){case 1:n.handleSignal(t);break;case 10:n.handleResponse(t);break;case 2:n.handlePropertyUpdate(t);break;default:console.error("invalid message received:",e.data)}},this.execCallbacks={},this.execId=0,this.exec=function(e,t){t?(n.execId===Number.MAX_VALUE&&(n.execId=Number.MIN_VALUE),e.hasOwnProperty("id")?console.error("Cannot exec message with property id: "+JSON.stringify(e)):(e.id=n.execId++,n.execCallbacks[e.id]=t,n.send(e))):n.send(e)},this.objects={},this.handleSignal=function(e){var t=n.objects[e.object];t?t.signalEmitted(e.signal,e.args):console.warn("Unhandled signal: "+e.object+"::"+e.signal)},this.handleResponse=function(e){e.hasOwnProperty("id")?(n.execCallbacks[e.id](e.data),delete n.execCallbacks[e.id]):console.error("Invalid response message received: ",JSON.stringify(e))},this.handlePropertyUpdate=function(e){e.data.forEach((function(e){var t=n.objects[e.object];t?t.propertyUpdate(e.signals,e.properties):console.warn("Unhandled property update: "+e.object+"::"+e.signal)})),n.exec({type:4})},this.debug=function(e){n.send({type:5,data:e})},n.exec({type:3},(function(e){for(var r=0,i=Object.keys(e);r<i.length;r++){var a=i[r];new o(a,e[a],n)}for(var c=0,s=Object.keys(n.objects);c<s.length;c++)n.objects[s[c]].unwrapProperties();t&&t(n),n.exec({type:4})}))}else console.error("The QWebChannel expects a transport object with a send function and onmessage callback property. Given is: transport: "+typeof e+", transport.send: "+typeof e.send)};function o(e,t,n){this.__id__=e,n.objects[e]=this,this.__objectSignals__={},this.__propertyCache__={};var r=this;function i(e,t){var o=e[0],i=e[1];r[o]={connect:function(e){"function"==typeof e?(r.__objectSignals__[i]=r.__objectSignals__[i]||[],r.__objectSignals__[i].push(e),t||"destroyed"!==o&&"destroyed()"!==o&&"destroyed(QObject*)"!==o&&1==r.__objectSignals__[i].length&&n.exec({type:7,object:r.__id__,signal:i})):console.error("Bad callback given to connect to signal "+o)},disconnect:function(e){if("function"==typeof e){r.__objectSignals__[i]=r.__objectSignals__[i]||[];var a=r.__objectSignals__[i].indexOf(e);-1!==a?(r.__objectSignals__[i].splice(a,1),t||0!==r.__objectSignals__[i].length||n.exec({type:8,object:r.__id__,signal:i})):console.error("Cannot find connection of signal "+o+" to "+e.name)}else console.error("Bad callback given to disconnect from signal "+o)}}}function a(e,t){var n=r.__objectSignals__[e];n&&n.forEach((function(e){e.apply(e,t)}))}this.unwrapQObject=function(e){if(e instanceof Array)return e.map((function(e){return r.unwrapQObject(e)}));if(!(e instanceof Object))return e;if(!e["__QObject*__"]||void 0===e.id){for(var t={},i=0,a=Object.keys(e);i<a.length;i++){var c=a[i];t[c]=r.unwrapQObject(e[c])}return t}var s=e.id;if(n.objects[s])return n.objects[s];if(e.data){var u=new o(s,e.data,n);return u.destroyed.connect((function(){n.objects[s]===u&&(delete n.objects[s],Object.keys(u).forEach((function(e){return delete u[e]})))})),u.unwrapProperties(),u}console.error("Cannot unwrap unknown QObject "+s+" without data.")},this.unwrapProperties=function(){for(var e=0,t=Object.keys(r.__propertyCache__);e<t.length;e++){var n=t[e];r.__propertyCache__[n]=r.unwrapQObject(r.__propertyCache__[n])}},this.propertyUpdate=function(e,t){for(var n=0,o=Object.keys(t);n<o.length;n++){var i=o[n];r.__propertyCache__[i]=this.unwrapQObject(t[i])}for(var c=0,s=Object.keys(e);c<s.length;c++){var u=s[c];a(u,e[u])}},this.signalEmitted=function(e,t){a(e,this.unwrapQObject(t))},t.methods.forEach((function(e){var t=e[0],i=")"===t[t.length-1]?e[1]:t;r[t]=function(){for(var e,t,a,c=[],s=0;s<arguments.length;++s){var u=arguments[s];"function"==typeof u?e=u:c.push(u instanceof o&&void 0!==n.objects[u.__id__]?{id:u.__id__}:u)}return e||"function"!=typeof Promise||(a=new Promise((function(n,r){e=n,t=r}))),n.exec({type:6,object:r.__id__,method:i,args:c},(function(n){if(void 0!==n){var o=r.unwrapQObject(n);e&&e(o)}else t&&t()})),a}})),t.properties.forEach((function(e){var t=e[0],a=e[1],c=e[2];r.__propertyCache__[t]=e[3],c&&(1===c[0]&&(c[0]=a+"Changed"),i(c,!0)),Object.defineProperty(r,a,{configurable:!0,get:function(){var e=r.__propertyCache__[t];return void 0===e&&console.warn('Undefined value in property cache for property "'+a+'" in object '+r.__id__),e},set:function(e){if(void 0!==e){r.__propertyCache__[t]=e;var i=e;i instanceof o&&void 0!==n.objects[i.__id__]&&(i={id:i.__id__}),n.exec({type:9,object:r.__id__,property:t,value:i})}else console.warn("Property setter for "+a+" called with undefined value!")}})})),t.signals.forEach((function(e){i(e,!1)})),Object.assign(r,t.enums)}var i=function(){function e(){var e=this;this._state="pending",this.promise=new Promise((function(t,n){e._resolve=t,e._reject=n}))}var t,n,r=e.prototype;return r.resolve=function(){if(!this._resolve)throw new Error("Deferred.resolve is undefined");return this._state="fulfilled",this._resolve.apply(this,arguments)},r.reject=function(){if(!this._reject)throw new Error("Deferred.reject is undefined");return this._state="rejected",this._reject.apply(this,arguments)},t=e,(n=[{key:"isFulfilled",get:function(){return"fulfilled"===this._state}},{key:"isRejected",get:function(){return"rejected"===this._state}}])&&function(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,"symbol"==typeof(o=function(e,t){if("object"!=typeof e||null===e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var r=n.call(e,"string");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(r.key))?o:String(o),r)}var o}(t.prototype,n),Object.defineProperty(t,"prototype",{writable:!1}),e}();exports.EasyQWebChannel=function(){function t(e){var t=this;this.context=null,this.deferred=new i,this.onceConnectedSignalName={},new r(window.qt.webChannelTransport,(function(n){t.context=n.objects[e],t.deferred.resolve()}))}var o=t.prototype;return o.ready=function(){return this.deferred.promise},o.answerNative=function(t,r,o){var a=this,c=new i;return this.once(t,n(e().mark((function t(){var n,i,s,u,f=arguments;return e().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:for(n=f.length,i=new Array(n),s=0;s<n;s++)i[s]=f[s];return e.next=3,o(i);case 3:void 0===(u=e.sent)?a.context[r]():a.context[r](u),c.resolve();case 6:case"end":return e.stop()}}),t)})))),c.promise},o.answerNativeHeartBeat=function(t,r,o,i){var a=this;void 0===i&&(i=!1),this.context[t].connect(n(e().mark((function t(){var n,c,s,u,f=arguments;return e().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:for(n=f.length,c=new Array(n),s=0;s<n;s++)c[s]=f[s];return e.next=3,o(c);case 3:void 0===(u=e.sent)?i||a.context[r]():a.context[r](u);case 5:case"end":return e.stop()}}),t)}))))},o.callNative=function(e,t,n){var r=new i;return this.once(t,(function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];r.resolve(t)})),void 0===n?this.context[e]():this.context[e](n),r.promise},o.callNativeWithoutResponse=function(e,t){void 0===t?this.context[e]():this.context[e](t)},o.canUseMethod=function(e){return"function"==typeof this.context[e]},o.canUseSignal=function(e){var t;return"function"===(null==(t=this.context[e])?void 0:t.connect)},o.once=function(){var t=n(e().mark((function t(n,r){var o,a,c=this;return e().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return o=function(){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];var o=c.onceConnectedSignalName[n];o.forEach((function(e){e.isFulfilled||e.isRejected||e.resolve(t)}))},this.onceConnectedSignalName[n]||(this.onceConnectedSignalName[n]=[],this.context[n].connect(o)),a=new i,this.onceConnectedSignalName[n].push(a),e.next=6,a.promise;case 6:r.apply(void 0,e.sent);case 8:case"end":return e.stop()}}),t,this)})));return function(e,n){return t.apply(this,arguments)}}(),t}(); //# sourceMappingURL=easy-qwebchannel.cjs.production.min.js.map