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