@salutejs/jazz-sdk-electron-plugins
Version:
Jazz SDK electron plugins
2 lines (1 loc) • 10.6 kB
JavaScript
"use strict";var t=require("@salutejs/jazz-sdk-electron/preload"),r=require("electron"),e=require("rx-effects"),n=require("rxjs"),o="jazz-sdk-desktop-capturer-ipc-channel",a="jazz-sdk-ask-display-media-stream",i="jazz-sdk-capturer-sources-event";function u(t,r,e,n,o,a,i){try{var u=t[a](i),c=u.value}catch(t){return void e(t)}u.done?r(c):Promise.resolve(c).then(n,o)}function c(t){return function(){var r=this,e=arguments;return new Promise((function(n,o){var a=t.apply(r,e);function i(t){u(a,n,o,i,c,"next",t)}function c(t){u(a,n,o,i,c,"throw",t)}i(void 0)}))}}function s(t){return s="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},s(t)}var f,p=Object.prototype,l=p.hasOwnProperty,h="function"==typeof Symbol?Symbol:{},y=h.iterator||"@@iterator",d=h.asyncIterator||"@@asyncIterator",v=h.toStringTag||"@@toStringTag";function m(t,r,e,n){var o=r&&r.prototype instanceof S?r:S,a=Object.create(o.prototype),i=new C(n||[]);return a._invoke=function(t,r,e){var n=w;return function(o,a){if(n===b)throw new Error("Generator is already running");if(n===k){if("throw"===o)throw a;return T()}for(e.method=o,e.arg=a;;){var i=e.delegate;if(i){var u=G(i,e);if(u){if(u===L)continue;return u}}if("next"===e.method)e.sent=e._sent=e.arg;else if("throw"===e.method){if(n===w)throw n=k,e.arg;e.dispatchException(e.arg)}else"return"===e.method&&e.abrupt("return",e.arg);n=b;var c=g(t,r,e);if("normal"===c.type){if(n=e.done?k:x,c.arg===L)continue;return{value:c.arg,done:e.done}}"throw"===c.type&&(n=k,e.method="throw",e.arg=c.arg)}}}(t,e,i),a}function g(t,r,e){try{return{type:"normal",arg:t.call(r,e)}}catch(t){return{type:"throw",arg:t}}}var w="suspendedStart",x="suspendedYield",b="executing",k="completed",L={};function S(){}function E(){}function j(){}var _={};_[y]=function(){return this};var P=Object.getPrototypeOf,z=P&&P(P(D([])));z&&z!==p&&l.call(z,y)&&(_=z);var O=j.prototype=S.prototype=Object.create(_);function M(t){["next","throw","return"].forEach((function(r){t[r]=function(t){return this._invoke(r,t)}}))}function F(t){var r="function"==typeof t&&t.constructor;return!!r&&(r===E||"GeneratorFunction"===(r.displayName||r.name))}function N(t,r){function e(n,o,a,i){var u=g(t[n],t,o);if("throw"!==u.type){var c=u.arg,f=c.value;return f&&"object"===s(f)&&l.call(f,"__await")?r.resolve(f.__await).then((function(t){e("next",t,a,i)}),(function(t){e("throw",t,a,i)})):r.resolve(f).then((function(t){c.value=t,a(c)}),(function(t){return e("throw",t,a,i)}))}i(u.arg)}var n;this._invoke=function(t,o){function a(){return new r((function(r,n){e(t,o,r,n)}))}return n=n?n.then(a,a):a()}}function G(t,r){var e=t.iterator[r.method];if(e===f){if(r.delegate=null,"throw"===r.method){if(t.iterator.return&&(r.method="return",r.arg=f,G(t,r),"throw"===r.method))return L;r.method="throw",r.arg=new TypeError("The iterator does not provide a 'throw' method")}return L}var n=g(e,t.iterator,r.arg);if("throw"===n.type)return r.method="throw",r.arg=n.arg,r.delegate=null,L;var o=n.arg;return o?o.done?(r[t.resultName]=o.value,r.next=t.nextLoc,"return"!==r.method&&(r.method="next",r.arg=f),r.delegate=null,L):o:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,L)}function A(t){var r={tryLoc:t[0]};1 in t&&(r.catchLoc=t[1]),2 in t&&(r.finallyLoc=t[2],r.afterLoc=t[3]),this.tryEntries.push(r)}function I(t){var r=t.completion||{};r.type="normal",delete r.arg,t.completion=r}function C(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(A,this),this.reset(!0)}function D(t){if(t){var r=t[y];if(r)return r.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var e=-1,n=function r(){for(;++e<t.length;)if(l.call(t,e))return r.value=t[e],r.done=!1,r;return r.value=f,r.done=!0,r};return n.next=n}}return{next:T}}function T(){return{value:f,done:!0}}E.prototype=O.constructor=j,j.constructor=E,j[v]=E.displayName="GeneratorFunction",M(N.prototype),N.prototype[d]=function(){return this},M(O),O[v]="Generator",O[y]=function(){return this},O.toString=function(){return"[object Generator]"},C.prototype={constructor:C,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=f,this.done=!1,this.delegate=null,this.method="next",this.arg=f,this.tryEntries.forEach(I),!t)for(var r in this)"t"===r.charAt(0)&&l.call(this,r)&&!isNaN(+r.slice(1))&&(this[r]=f)},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 r=this;function e(e,n){return a.type="throw",a.arg=t,r.next=e,n&&(r.method="next",r.arg=f),!!n}for(var n=this.tryEntries.length-1;n>=0;--n){var o=this.tryEntries[n],a=o.completion;if("root"===o.tryLoc)return e("end");if(o.tryLoc<=this.prev){var i=l.call(o,"catchLoc"),u=l.call(o,"finallyLoc");if(i&&u){if(this.prev<o.catchLoc)return e(o.catchLoc,!0);if(this.prev<o.finallyLoc)return e(o.finallyLoc)}else if(i){if(this.prev<o.catchLoc)return e(o.catchLoc,!0)}else{if(!u)throw new Error("try statement without catch or finally");if(this.prev<o.finallyLoc)return e(o.finallyLoc)}}}},abrupt:function(t,r){for(var e=this.tryEntries.length-1;e>=0;--e){var n=this.tryEntries[e];if(n.tryLoc<=this.prev&&l.call(n,"finallyLoc")&&this.prev<n.finallyLoc){var o=n;break}}o&&("break"===t||"continue"===t)&&o.tryLoc<=r&&r<=o.finallyLoc&&(o=null);var a=o?o.completion:{};return a.type=t,a.arg=r,o?(this.method="next",this.next=o.finallyLoc,L):this.complete(a)},complete:function(t,r){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&&r&&(this.next=r),L},finish:function(t){for(var r=this.tryEntries.length-1;r>=0;--r){var e=this.tryEntries[r];if(e.finallyLoc===t)return this.complete(e.completion,e.afterLoc),I(e),L}},catch:function(t){for(var r=this.tryEntries.length-1;r>=0;--r){var e=this.tryEntries[r];if(e.tryLoc===t){var n=e.completion;if("throw"===n.type){var o=n.arg;I(e)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,r,e){return this.delegate={iterator:D(t),resultName:r,nextLoc:e},"next"===this.method&&(this.arg=f),L}};var q={wrap:m,isGeneratorFunction:F,AsyncIterator:N,mark:function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,j):(t.__proto__=j,v in t||(t[v]="GeneratorFunction")),t.prototype=Object.create(O),t},awrap:function(t){return{__await:t}},async:function(t,r,e,n,o){void 0===o&&(o=Promise);var a=new N(m(t,r,e,n),o);return F(r)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},keys:function(t){var r=[];for(var e in t)r.push(e);return r.reverse(),function e(){for(;r.length;){var n=r.pop();if(n in t)return e.value=n,e.done=!1,e}return e.done=!0,e}},values:D};function R(){var u=e.createScope(),s=u.createController((function(){return function(r){var u,s=r.ipcRenderer,f=e.createScope(),p=t.createEventBus(),l=function(t){u=t,p({type:"askDisplayMediaStream"})};s.on(a,l),f.add((function(){s.off(a,l)}));var h=function(t,r){p(r)};s.on(i,h),f.add((function(){s.off(i,h)}));var y=function(){var t=c(q.mark((function t(r){var e,n;return q.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return e={payload:r,type:"capturerSourcesStartProcess"},t.next=3,s.invoke(o,e);case 3:return n=t.sent,t.abrupt("return",n.payload);case 5:case"end":return t.stop()}}),t)})));return function(r){return t.apply(this,arguments)}}(),d=function(){var t=c(q.mark((function t(){var r,e;return q.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r={type:"capturerSourcesFinishProcess"},t.next=3,s.invoke(o,r);case 3:return e=t.sent,t.abrupt("return",e.payload);case 5:case"end":return t.stop()}}),t)})));return function(){return t.apply(this,arguments)}}(),v=function(){var t=c(q.mark((function t(r){var e,n;return q.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return e={payload:r,type:"getDesktopCapturerSources"},t.next=3,s.invoke(o,e);case 3:return n=t.sent,t.abrupt("return",n.payload);case 5:case"end":return t.stop()}}),t)})));return function(r){return t.apply(this,arguments)}}(),m=function(){var t=c(q.mark((function t(r){var e,n;return q.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return e={payload:{type:r},type:"askForMediaAccess"},t.next=3,s.invoke(o,e);case 3:return n=t.sent,t.abrupt("return",n.payload);case 5:case"end":return t.stop()}}),t)})));return function(r){return t.apply(this,arguments)}}(),g=function(){var t=c(q.mark((function t(r){var e,n;return q.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return e={payload:{type:r},type:"getMediaAccessStatus"},t.next=3,s.invoke(o,e);case 3:return n=t.sent,t.abrupt("return",n.payload);case 5:case"end":return t.stop()}}),t)})));return function(r){return t.apply(this,arguments)}}(),w=function(){var t=c(q.mark((function t(r){var e,n;return q.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return e={payload:{key:r},type:"systemSettings"},t.next=3,s.invoke(o,e);case 3:return n=t.sent,t.abrupt("return",n.payload);case 5:case"end":return t.stop()}}),t)})));return function(r){return t.apply(this,arguments)}}(),x=function(){var t=c(q.mark((function t(){var r,e;return q.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r={type:"osInfo"},t.next=3,s.invoke(o,r);case 3:return e=t.sent,t.abrupt("return",e.payload);case 5:case"end":return t.stop()}}),t)})));return function(){return t.apply(this,arguments)}}();return{capturerSourcesStartProcess:y,capturerSourcesFinishProcess:d,getDesktopCapturerSources:v,askForMediaAccess:m,getMediaAccessStatus:g,openSystemSettings:w,replyDisplayMediaStream:function(t){var r,e={source:t,audio:arguments.length>1&&void 0!==arguments[1]&&arguments[1]};null===(r=u)||void 0===r||r.sender.send("jazz-sdk-reply-display-media-stream",e),u=void 0},osInfo:x,subscribe:function(t,r){var e=p.event$.pipe(n.filter((function(r){return r.type===t}))).subscribe((function(t){r("payload"in t?t.payload:void 0)}));return function(){return e.unsubscribe()}},once:function(t,r){var e=p.event$.pipe(n.filter((function(r){return r.type===t})),n.take(1)).subscribe((function(t){r("payload"in t?t.payload:void 0)}));return function(){return e.unsubscribe()}},destroy:function(){f.destroy()}}}({ipcRenderer:r.ipcRenderer})})),f={ipcMain:s};return r.contextBridge.exposeInMainWorld("jazz-sdk-desktop-capturer-bridge",f),{destroy:u.destroy}}exports.desktopCapturerPlugin=function(){return t.createModule({name:"DesktopCapturerPlugin",factory:R})};