@acrobits/ipc-sdk 0.0.14 → 0.0.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/ipc-sdk.js +44 -48
- package/lib/ipc-sdk.js.map +1 -1
- package/lib/ipc-sdk.umd.cjs +1 -1
- package/lib/ipc-sdk.umd.cjs.map +1 -1
- package/package.json +1 -1
package/lib/ipc-sdk.umd.cjs
CHANGED
|
@@ -2,4 +2,4 @@ var ys=Object.defineProperty;var bs=(x,$,j)=>$ in x?ys(x,$,{enumerable:!0,config
|
|
|
2
2
|
`+e.map(function(t,n){return n+1+") "+t.toString()}).join(`
|
|
3
3
|
`):"",this.name="UnsubscriptionError",this.errors=e}});function xe(r,e){if(r){var t=r.indexOf(e);0<=t&&r.splice(t,1)}}var ve=function(){function r(e){this.initialTeardown=e,this.closed=!1,this._parentage=null,this._finalizers=null}return r.prototype.unsubscribe=function(){var e,t,n,i,s;if(!this.closed){this.closed=!0;var a=this._parentage;if(a)if(this._parentage=null,Array.isArray(a))try{for(var c=nt(a),o=c.next();!o.done;o=c.next()){var l=o.value;l.remove(this)}}catch(I){e={error:I}}finally{try{o&&!o.done&&(t=c.return)&&t.call(c)}finally{if(e)throw e.error}}else a.remove(this);var u=this.initialTeardown;if(F(u))try{u()}catch(I){s=I instanceof it?I.errors:[I]}var p=this._finalizers;if(p){this._finalizers=null;try{for(var w=nt(p),f=w.next();!f.done;f=w.next()){var g=f.value;try{tr(g)}catch(I){s=s??[],I instanceof it?s=de(de([],fe(s)),fe(I.errors)):s.push(I)}}}catch(I){n={error:I}}finally{try{f&&!f.done&&(i=w.return)&&i.call(w)}finally{if(n)throw n.error}}}if(s)throw new it(s)}},r.prototype.add=function(e){var t;if(e&&e!==this)if(this.closed)tr(e);else{if(e instanceof r){if(e.closed||e._hasParent(this))return;e._addParent(this)}(this._finalizers=(t=this._finalizers)!==null&&t!==void 0?t:[]).push(e)}},r.prototype._hasParent=function(e){var t=this._parentage;return t===e||Array.isArray(t)&&t.includes(e)},r.prototype._addParent=function(e){var t=this._parentage;this._parentage=Array.isArray(t)?(t.push(e),t):t?[t,e]:e},r.prototype._removeParent=function(e){var t=this._parentage;t===e?this._parentage=null:Array.isArray(t)&&xe(t,e)},r.prototype.remove=function(e){var t=this._finalizers;t&&xe(t,e),e instanceof r&&e._removeParent(this)},r.EMPTY=function(){var e=new r;return e.closed=!0,e}(),r}(),Zt=ve.EMPTY;function er(r){return r instanceof ve||r&&"closed"in r&&F(r.remove)&&F(r.add)&&F(r.unsubscribe)}function tr(r){F(r)?r():r.unsubscribe()}var rr={onUnhandledError:null,onStoppedNotification:null,Promise:void 0,useDeprecatedSynchronousErrorHandling:!1,useDeprecatedNextContext:!1},$i={setTimeout:function(r,e){for(var t=[],n=2;n<arguments.length;n++)t[n-2]=arguments[n];return setTimeout.apply(void 0,de([r,e],fe(t)))},clearTimeout:function(r){return clearTimeout(r)},delegate:void 0};function Oi(r){$i.setTimeout(function(){throw r})}function nr(){}function Ne(r){r()}var st=function(r){Q(e,r);function e(t){var n=r.call(this)||this;return n.isStopped=!1,t?(n.destination=t,er(t)&&t.add(n)):n.destination=xi,n}return e.create=function(t,n,i){return new at(t,n,i)},e.prototype.next=function(t){this.isStopped||this._next(t)},e.prototype.error=function(t){this.isStopped||(this.isStopped=!0,this._error(t))},e.prototype.complete=function(){this.isStopped||(this.isStopped=!0,this._complete())},e.prototype.unsubscribe=function(){this.closed||(this.isStopped=!0,r.prototype.unsubscribe.call(this),this.destination=null)},e.prototype._next=function(t){this.destination.next(t)},e.prototype._error=function(t){try{this.destination.error(t)}finally{this.unsubscribe()}},e.prototype._complete=function(){try{this.destination.complete()}finally{this.unsubscribe()}},e}(ve),Ai=Function.prototype.bind;function ot(r,e){return Ai.call(r,e)}var Ti=function(){function r(e){this.partialObserver=e}return r.prototype.next=function(e){var t=this.partialObserver;if(t.next)try{t.next(e)}catch(n){Le(n)}},r.prototype.error=function(e){var t=this.partialObserver;if(t.error)try{t.error(e)}catch(n){Le(n)}else Le(e)},r.prototype.complete=function(){var e=this.partialObserver;if(e.complete)try{e.complete()}catch(t){Le(t)}},r}(),at=function(r){Q(e,r);function e(t,n,i){var s=r.call(this)||this,a;if(F(t)||!t)a={next:t??void 0,error:n??void 0,complete:i??void 0};else{var c;s&&rr.useDeprecatedNextContext?(c=Object.create(t),c.unsubscribe=function(){return s.unsubscribe()},a={next:t.next&&ot(t.next,c),error:t.error&&ot(t.error,c),complete:t.complete&&ot(t.complete,c)}):a=t}return s.destination=new Ti(a),s}return e}(st);function Le(r){Oi(r)}function Ci(r){throw r}var xi={closed:!0,next:nr,error:Ci,complete:nr},Ni=function(){return typeof Symbol=="function"&&Symbol.observable||"@@observable"}();function ir(r){return r}function Li(r){return r.length===0?ir:r.length===1?r[0]:function(e){return r.reduce(function(t,n){return n(t)},e)}}var Pe=function(){function r(e){e&&(this._subscribe=e)}return r.prototype.lift=function(e){var t=new r;return t.source=this,t.operator=e,t},r.prototype.subscribe=function(e,t,n){var i=this,s=Mi(e)?e:new at(e,t,n);return Ne(function(){var a=i,c=a.operator,o=a.source;s.add(c?c.call(s,o):o?i._subscribe(s):i._trySubscribe(s))}),s},r.prototype._trySubscribe=function(e){try{return this._subscribe(e)}catch(t){e.error(t)}},r.prototype.forEach=function(e,t){var n=this;return t=sr(t),new t(function(i,s){var a=new at({next:function(c){try{e(c)}catch(o){s(o),a.unsubscribe()}},error:s,complete:i});n.subscribe(a)})},r.prototype._subscribe=function(e){var t;return(t=this.source)===null||t===void 0?void 0:t.subscribe(e)},r.prototype[Ni]=function(){return this},r.prototype.pipe=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return Li(e)(this)},r.prototype.toPromise=function(e){var t=this;return e=sr(e),new e(function(n,i){var s;t.subscribe(function(a){return s=a},function(a){return i(a)},function(){return n(s)})})},r.create=function(e){return new r(e)},r}();function sr(r){var e;return(e=r??rr.Promise)!==null&&e!==void 0?e:Promise}function Pi(r){return r&&F(r.next)&&F(r.error)&&F(r.complete)}function Mi(r){return r&&r instanceof st||Pi(r)&&er(r)}function _i(r){return F(r==null?void 0:r.lift)}function Me(r){return function(e){if(_i(e))return e.lift(function(t){try{return r(t,this)}catch(n){this.error(n)}});throw new TypeError("Unable to lift unknown Observable type")}}function _e(r,e,t,n,i){return new Di(r,e,t,n,i)}var Di=function(r){Q(e,r);function e(t,n,i,s,a,c){var o=r.call(this,t)||this;return o.onFinalize=a,o.shouldUnsubscribe=c,o._next=n?function(l){try{n(l)}catch(u){t.error(u)}}:r.prototype._next,o._error=s?function(l){try{s(l)}catch(u){t.error(u)}finally{this.unsubscribe()}}:r.prototype._error,o._complete=i?function(){try{i()}catch(l){t.error(l)}finally{this.unsubscribe()}}:r.prototype._complete,o}return e.prototype.unsubscribe=function(){var t;if(!this.shouldUnsubscribe||this.shouldUnsubscribe()){var n=this.closed;r.prototype.unsubscribe.call(this),!n&&((t=this.onFinalize)===null||t===void 0||t.call(this))}},e}(st),Ui=Jt(function(r){return function(){r(this),this.name="ObjectUnsubscribedError",this.message="object unsubscribed"}}),or=function(r){Q(e,r);function e(){var t=r.call(this)||this;return t.closed=!1,t.currentObservers=null,t.observers=[],t.isStopped=!1,t.hasError=!1,t.thrownError=null,t}return e.prototype.lift=function(t){var n=new ar(this,this);return n.operator=t,n},e.prototype._throwIfClosed=function(){if(this.closed)throw new Ui},e.prototype.next=function(t){var n=this;Ne(function(){var i,s;if(n._throwIfClosed(),!n.isStopped){n.currentObservers||(n.currentObservers=Array.from(n.observers));try{for(var a=nt(n.currentObservers),c=a.next();!c.done;c=a.next()){var o=c.value;o.next(t)}}catch(l){i={error:l}}finally{try{c&&!c.done&&(s=a.return)&&s.call(a)}finally{if(i)throw i.error}}}})},e.prototype.error=function(t){var n=this;Ne(function(){if(n._throwIfClosed(),!n.isStopped){n.hasError=n.isStopped=!0,n.thrownError=t;for(var i=n.observers;i.length;)i.shift().error(t)}})},e.prototype.complete=function(){var t=this;Ne(function(){if(t._throwIfClosed(),!t.isStopped){t.isStopped=!0;for(var n=t.observers;n.length;)n.shift().complete()}})},e.prototype.unsubscribe=function(){this.isStopped=this.closed=!0,this.observers=this.currentObservers=null},Object.defineProperty(e.prototype,"observed",{get:function(){var t;return((t=this.observers)===null||t===void 0?void 0:t.length)>0},enumerable:!1,configurable:!0}),e.prototype._trySubscribe=function(t){return this._throwIfClosed(),r.prototype._trySubscribe.call(this,t)},e.prototype._subscribe=function(t){return this._throwIfClosed(),this._checkFinalizedStatuses(t),this._innerSubscribe(t)},e.prototype._innerSubscribe=function(t){var n=this,i=this,s=i.hasError,a=i.isStopped,c=i.observers;return s||a?Zt:(this.currentObservers=null,c.push(t),new ve(function(){n.currentObservers=null,xe(c,t)}))},e.prototype._checkFinalizedStatuses=function(t){var n=this,i=n.hasError,s=n.thrownError,a=n.isStopped;i?t.error(s):a&&t.complete()},e.prototype.asObservable=function(){var t=new Pe;return t.source=this,t},e.create=function(t,n){return new ar(t,n)},e}(Pe),ar=function(r){Q(e,r);function e(t,n){var i=r.call(this)||this;return i.destination=t,i.source=n,i}return e.prototype.next=function(t){var n,i;(i=(n=this.destination)===null||n===void 0?void 0:n.next)===null||i===void 0||i.call(n,t)},e.prototype.error=function(t){var n,i;(i=(n=this.destination)===null||n===void 0?void 0:n.error)===null||i===void 0||i.call(n,t)},e.prototype.complete=function(){var t,n;(n=(t=this.destination)===null||t===void 0?void 0:t.complete)===null||n===void 0||n.call(t)},e.prototype._subscribe=function(t){var n,i;return(i=(n=this.source)===null||n===void 0?void 0:n.subscribe(t))!==null&&i!==void 0?i:Zt},e}(or),ji={now:function(){return Date.now()},delegate:void 0},Fi=function(r){Q(e,r);function e(t,n){return r.call(this)||this}return e.prototype.schedule=function(t,n){return this},e}(ve),lt={setInterval:function(r,e){for(var t=[],n=2;n<arguments.length;n++)t[n-2]=arguments[n];var i=lt.delegate;return i!=null&&i.setInterval?i.setInterval.apply(i,de([r,e],fe(t))):setInterval.apply(void 0,de([r,e],fe(t)))},clearInterval:function(r){return clearInterval(r)},delegate:void 0},Gi=function(r){Q(e,r);function e(t,n){var i=r.call(this,t,n)||this;return i.scheduler=t,i.work=n,i.pending=!1,i}return e.prototype.schedule=function(t,n){var i;if(n===void 0&&(n=0),this.closed)return this;this.state=t;var s=this.id,a=this.scheduler;return s!=null&&(this.id=this.recycleAsyncId(a,s,n)),this.pending=!0,this.delay=n,this.id=(i=this.id)!==null&&i!==void 0?i:this.requestAsyncId(a,this.id,n),this},e.prototype.requestAsyncId=function(t,n,i){return i===void 0&&(i=0),lt.setInterval(t.flush.bind(t,this),i)},e.prototype.recycleAsyncId=function(t,n,i){if(i===void 0&&(i=0),i!=null&&this.delay===i&&this.pending===!1)return n;n!=null&<.clearInterval(n)},e.prototype.execute=function(t,n){if(this.closed)return new Error("executing a cancelled action");this.pending=!1;var i=this._execute(t,n);if(i)return i;this.pending===!1&&this.id!=null&&(this.id=this.recycleAsyncId(this.scheduler,this.id,null))},e.prototype._execute=function(t,n){var i=!1,s;try{this.work(t)}catch(a){i=!0,s=a||new Error("Scheduled action threw falsy error")}if(i)return this.unsubscribe(),s},e.prototype.unsubscribe=function(){if(!this.closed){var t=this,n=t.id,i=t.scheduler,s=i.actions;this.work=this.state=this.scheduler=null,this.pending=!1,xe(s,this),n!=null&&(this.id=this.recycleAsyncId(i,n,null)),this.delay=null,r.prototype.unsubscribe.call(this)}},e}(Fi),lr=function(){function r(e,t){t===void 0&&(t=r.now),this.schedulerActionCtor=e,this.now=t}return r.prototype.schedule=function(e,t,n){return t===void 0&&(t=0),new this.schedulerActionCtor(this,e).schedule(n,t)},r.now=ji.now,r}(),ki=function(r){Q(e,r);function e(t,n){n===void 0&&(n=lr.now);var i=r.call(this,t,n)||this;return i.actions=[],i._active=!1,i}return e.prototype.flush=function(t){var n=this.actions;if(this._active){n.push(t);return}var i;this._active=!0;do if(i=t.execute(t.state,t.delay))break;while(t=n.shift());if(this._active=!1,i){for(;t=n.shift();)t.unsubscribe();throw i}},e}(lr),Vi=new ki(Gi),Hi=Vi,Xi=new Pe(function(r){return r.complete()});function Bi(r){return r&&F(r.schedule)}function qi(r){return r instanceof Date&&!isNaN(r)}function C(r,e){return Me(function(t,n){var i=0;t.subscribe(_e(n,function(s){n.next(r.call(e,s,i++))}))})}function Yi(r,e,t){r===void 0&&(r=0),t===void 0&&(t=Hi);var n=-1;return e!=null&&(Bi(e)?t=e:n=e),new Pe(function(i){var s=qi(r)?+r-t.now():r;s<0&&(s=0);var a=0;return t.schedule(function(){i.closed||(i.next(a++),0<=n?this.schedule(void 0,n):i.complete())},s)})}function U(r,e){return Me(function(t,n){var i=0;t.subscribe(_e(n,function(s){return r.call(e,s,i++)&&n.next(s)}))})}function Y(r){return r<=0?function(){return Xi}:Me(function(e,t){var n=0;e.subscribe(_e(t,function(i){++n<=r&&(t.next(i),r<=n&&t.complete())}))})}function _(r,e,t){var n=F(r)||e||t?{next:r,error:e,complete:t}:r;return n?Me(function(i,s){var a;(a=n.subscribe)===null||a===void 0||a.call(n);var c=!0;i.subscribe(_e(s,function(o){var l;(l=n.next)===null||l===void 0||l.call(n,o),s.next(o)},function(){var o;c=!1,(o=n.complete)===null||o===void 0||o.call(n),s.complete()},function(o){var l;c=!1,(l=n.error)===null||l===void 0||l.call(n,o),s.error(o)},function(){var o,l;c&&((o=n.unsubscribe)===null||o===void 0||o.call(n)),(l=n.finalize)===null||l===void 0||l.call(n)}))}):ir}class ee{static gte(e,t){return t===void 0?n=>ee.gte(n,e)?n:!1:N.gte(N.coerce(e),N.coerce(t))}static lte(e,t){return t===void 0?n=>ee.lte(n,e)?n:!1:N.lte(N.coerce(e),N.coerce(t))}static gt(e,t){return t===void 0?n=>ee.gt(n,e)?n:!1:N.gt(N.coerce(e),N.coerce(t))}static lt(e,t){return t===void 0?n=>ee.lt(n,e)?n:!1:N.lt(N.coerce(e),N.coerce(t))}static eq(e,t){return N.eq(N.coerce(e),N.coerce(t))}static neq(e,t){return N.neq(N.coerce(e),N.coerce(t))}static compare(e,t){return N.compare(N.coerce(e),N.coerce(t))}}const cr="1.0";class zi{constructor(e,t){if(z(this,"negotiatedProtocolVersion"),z(this,"currentContext"),z(this,"incomingMessages$"),z(this,"inIframe",!1),z(this,"embeddedResult"),z(this,"iframePort1"),z(this,"iframePort2"),this.supportedVersions=e,this.logService=t,this.incomingMessages$=new or,this.supportedVersions=e.filter(ee.gte(cr)),!this.supportedVersions.length)throw new Kt(e,cr);this.negotiatedProtocolVersion=this.supportedVersions[0],this.embeddedResult=null,this.iframePort2=null}get parent(){return window.parent}get self(){return window.self}get frameElement(){return window.frameElement}get port1(){var e,t;return this.inIframe?this.iframePort1:(t=(e=window.Acrobits)==null?void 0:e.messageChannel)==null?void 0:t.port1}get port2(){var e,t,n,i;if(this.inIframe){if(!this.iframePort2)throw new Wt("port2");return this.iframePort2}else{if(!((t=(e=window.Acrobits)==null?void 0:e.messageChannel)!=null&&t.port2))throw new Wt("port2");return(i=(n=window.Acrobits)==null?void 0:n.messageChannel)==null?void 0:i.port2}}determineContext(){return Yi(1e3).pipe(C(()=>(this.isEmbedded()?this.currentContext="user":this.currentContext="guest",this.currentContext)),Y(1))}openBridge(){if(!this.isEmbedded())throw new L(this.currentContext);const e="HELLO",t=this.createMessage(e);t.protocolVersions=this.supportedVersions,this.logCreated(e,t);const n=this.incomingMessages$.pipe(U(i=>i.type===e&&i.replyTo===t.id),C(i=>i),_(this.logReceived(e)),C(i=>{if(this.supportedVersions.some(ee.gt(i.protocolVersion)))throw new Kt(i.protocolVersion,this.supportedVersions[0]);return i}),_(i=>{this.negotiatedProtocolVersion=i.protocolVersion,this.logService.info(`[IPC] Negotiated IPC Protocol Version: ${this.negotiatedProtocolVersion}`)}),Y(1));return this.logService.debug(`Created ${e} Reply handler`),this.inIframe?this.createIframeChannel().then(()=>this.finishIpcSetup(t)):this.finishIpcSetup(t),n}requestSSOToken(){if(!this.isEmbedded())throw new L(this.currentContext);const e="TOKEN",t=this.createMessage(e);this.logCreated(e,t);const n=this.incomingMessages$.pipe(U(i=>i.type===e&&i.replyTo===t.id),C(i=>i),_(this.logReceived(e)),Y(1));return this.logService.debug(`Created ${e} Reply handler`),this.port2.postMessage(t),this.logSent(e,t),n}sendJoiningRoomMessage(e){if(!this.isEmbedded())throw new L(this.currentContext);const{roomName:t,roomInvite:n,displayName:i,jwtToken:s,serverUrl:a,region:c,joinMicMuted:o,joinWithoutCamera:l}=e,u="JOINING ROOM",p=this.createMessage(u,!1);p.roomName=t,p.jwtToken=s,p.serverUrl=a,p.region=c,p.roomInvite=n,p.joinMicMuted=o??!1,p.joinWithoutCamera=l??!1,p.displayName=i,this.logCreated(u,p),this.port2.postMessage(p),this.logSent(u,p)}sendLeavingRoomMessage(e){if(!this.isEmbedded())throw new L(this.currentContext);const t="LEAVING ROOM",n=this.createMessage(t,!1);n.roomName=e,this.logCreated(t,n),this.port2.postMessage(n),this.logSent(t,n)}onJoinRoomMessage(){if(!this.isEmbedded())throw new L(this.currentContext);const e="JOIN ROOM";return this.incomingMessages$.pipe(U(t=>t.type===e&&t.target==="client"),C(t=>t),_(this.logReceived(e)),C(t=>t))}onLeaveRoomMessage(){if(!this.isEmbedded())throw new L(this.currentContext);const e="LEAVE ROOM";return this.incomingMessages$.pipe(U(t=>t.type===e&&t.target==="client"),C(t=>t),_(this.logReceived(e)),C(t=>t))}onConfigMessage(){if(!this.isEmbedded())throw new L(this.currentContext);const e="CONFIG";return this.incomingMessages$.pipe(U(t=>t.type===e&&t.target==="client"),C(t=>t),_(this.logReceived(e)),C(t=>({preferredCameraType:t.preferredCameraType,preferredMicType:t.preferredMicType,preferredOutputType:t.preferredOutputType,preferredCameraDeviceLabel:t.preferredCameraDeviceLabel,preferredMicDeviceLabel:t.preferredMicDeviceLabel,preferredOutputDeviceLabel:t.preferredOutputDeviceLabel,performanceProfile:t.performanceProfile,cloudUsername:t.cloudUsername,configuredOAuthProviders:t.configuredOAuthProviders,locales:t.locales?[...t.locales]:[]})))}sendScreenshareSourceMessage(e){if(!this.isEmbedded())throw new L(this.currentContext);const t="SCREENSHARE SOURCE",n=this.createMessage(t);n.sourceTypes=e,this.logCreated(t,n);const i=this.incomingMessages$.pipe(U(s=>s.type===t&&s.replyTo===n.id),C(s=>s),_(this.logReceived(t)),C(s=>s),Y(1));return this.logService.debug(`Created ${t} Reply handler`),this.port2.postMessage(n),this.logSent(t,n),i}layoutChange(e,t,n){if(!this.isEmbedded())throw new L(this.currentContext);const i="LAYOUT CHANGE";let s,a;if(t&&n?(s=this.createMessage(i,!1,n),s.result=t):(s=this.createMessage(i),a=this.incomingMessages$.pipe(U(c=>c.type===i&&c.replyTo===s.id),C(c=>c),_(this.logReceived(i)),C(c=>c),Y(1)),this.logService.debug(`Created ${i} Reply handler`)),s.layout=e,this.logCreated(i,s),this.port2.postMessage(s),this.logSent(i,s),a)return a}onLayoutChangeMessage(){if(!this.isEmbedded())throw new L(this.currentContext);const e="LAYOUT CHANGE";return this.incomingMessages$.pipe(U(t=>t.type===e&&t.target==="client"&&t.replyTo===null),C(t=>t),_(this.logReceived(e)),C(t=>t))}requestOAuthToken(e){if(!this.isEmbedded())throw new L(this.currentContext);Array.isArray(e)||(e=[e]);const t="OAUTH TOKEN",n=this.createMessage(t);n.providerTypes=e,this.logCreated(t,n);const i=this.incomingMessages$.pipe(U(s=>s.type===t&&s.replyTo===n.id),C(s=>s),_(this.logReceived(t)),Y(1));return this.logService.debug(`Created ${t} Reply handler`),this.port2.postMessage(n),this.logSent(t,n),i}openUrl(e,t){if(!this.isEmbedded())throw new L(this.currentContext);const n="OPEN URL",i=this.createMessage(n,!1);i.url=e,i.data=t,this.logCreated(n,i),this.port2.postMessage(i),this.logSent(n,i)}selectContacts(e,t,n){if(!this.isEmbedded())throw new L(this.currentContext);if(t==="group"&&n===void 0)throw new Ce("currentContacts",n,"currentContacts is required for group streams");if(t==="direct"&&n!==void 0)throw new Ce("currentContacts",n,"currentContacts should not be passed for direct streams");const i="SELECT CONTACTS",s=this.createMessage(i,!0);s.streamType=t,s.streamId=e,s.currentContacts=n,this.logCreated(i,s);const a=this.incomingMessages$.pipe(U(c=>c.type===i&&c.replyTo===s.id),_(this.logReceived(i)),C(c=>{const o=c;if(o.streamId!==e)throw new Si(o.streamId,e);return t==="direct"&&o.contacts.length>1&&(o.contacts=[o.contacts[0]]),o}),Y(1));return this.logService.debug(`Created ${i} Reply handler`),this.port2.postMessage(s),this.logSent(i,s),a}matchContacts(e){if(!this.isEmbedded())throw new L(this.currentContext);if(!e.length)throw new Ce("contacts",e,"At least one contact is required");const t="MATCH CONTACTS",n=this.createMessage(t);n.contacts=[...e],this.logCreated(t,n);const i=this.incomingMessages$.pipe(U(s=>s.type===t&&s.replyTo===n.id),_(this.logReceived(t)),C(s=>s),Y(1));return this.logService.debug(`Created ${t} Reply handler`),this.port2.postMessage(n),this.logSent(t,n),i}onPushMessageMessage(){if(!this.isEmbedded())throw new L(this.currentContext);const e="PUSH MESSAGE";return this.incomingMessages$.pipe(U(t=>t.type===e&&t.target==="client"),C(t=>t),_(this.logReceived(e)))}requestPushToken(){if(!this.isEmbedded())throw new L(this.currentContext);const e="PUSH TOKEN",t=this.createMessage(e);this.logCreated(e,t);const n=this.incomingMessages$.pipe(U(i=>i.type===e&&i.replyTo===t.id),_(this.logReceived(e)),C(i=>i),Y(1));return this.logService.debug(`Created ${e} Reply handler`),this.port2.postMessage(t),this.logSent(e,t),n}onBadgeQueryMessage(){if(!this.isEmbedded())throw new L(this.currentContext);const e="BADGE QUERY";return this.incomingMessages$.pipe(U(t=>t.type===e&&t.target==="client"),C(t=>t),_(this.logReceived(e)))}sendBadgeUpdateMessage(e,t){if(!this.isEmbedded())throw new L(this.currentContext);const n="BADGE UPDATE",i=this.createMessage(n,!1,t);i.count=e,this.logCreated(n,i),this.port2.postMessage(i),this.logSent(n,i)}onHostInForegroundMessage(){if(!this.isEmbedded())throw new L(this.currentContext);const e="HOST IN FOREGROUND";return this.incomingMessages$.pipe(U(t=>t.type===e&&t.target==="client"),C(t=>t),_(this.logReceived(e)))}isEmbedded(){if(this.embeddedResult!==null)return this.embeddedResult;let e=!1;return this.logService.debug("Checking if running in iframe..."),e=!!this.frameElement,e||(e=this.self!==this.parent),e?(this.logService.debug("In iframe"),this.inIframe=!0,this.embeddedResult=!0,!0):(this.logService.debug("Not in iframe"),this.logService.debug("Checking if running in native app..."),!e&&(e=!!window.Acrobits,e)?(this.logService.debug("In native app"),this.embeddedResult=!0,e):(this.logService.debug("Not running in native app"),this.embeddedResult=!1,this.embeddedResult))}logReceived(e,t){const n=i=>this.logService.debug(`[IPC] Received ${e} message`,i);return t&&n(t),n}logSent(e,t){this.logService.debug(`[IPC] Sent ${e} message`,t)}logCreated(e,t){this.logService.debug(`[IPC] Created ${e} message`,t)}async createIframeChannel(){return new Promise(e=>{const t=n=>{n.data==="message channel port"&&(this.iframePort2=n.ports[0],this.self.removeEventListener("message",t),e())};this.self.addEventListener("message",t),this.parent.postMessage("get channel","*")})}finishIpcSetup(e){this.logService.debug("Registering listener on port2..."),this.port2.addEventListener("message",this.handleIpcMessage.bind(this)),this.port2.start(),this.logService.debug("Started listening on port2"),this.port2.postMessage(e),this.logSent("HELLO",e)}handleIpcMessage(e){const{data:t}=e;!t.id||t.target!=="client"||this.incomingMessages$.next(t)}createMessage(e,t=!0,n){return{type:e,id:this.generateId(),target:"host",expectReply:t,replyTo:n??null}}generateId(e=8,t=!1){let n="1234567890qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM";const i=[];t&&(n=n.substr(0,n.indexOf("Q")));for(let s=0;s<e;s++)i.push(n[Math.floor(Math.random()*n.length)]);return i.join("")}}var ct=function(r,e){return ct=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,n){t.__proto__=n}||function(t,n){for(var i in n)Object.prototype.hasOwnProperty.call(n,i)&&(t[i]=n[i])},ct(r,e)};function ut(r,e){if(typeof e!="function"&&e!==null)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");ct(r,e);function t(){this.constructor=r}r.prototype=e===null?Object.create(e):(t.prototype=e.prototype,new t)}function ur(r){var e=typeof Symbol=="function"&&Symbol.iterator,t=e&&r[e],n=0;if(t)return t.call(r);if(r&&typeof r.length=="number")return{next:function(){return r&&n>=r.length&&(r=void 0),{value:r&&r[n++],done:!r}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}function De(r,e){var t=typeof Symbol=="function"&&r[Symbol.iterator];if(!t)return r;var n=t.call(r),i,s=[],a;try{for(;(e===void 0||e-- >0)&&!(i=n.next()).done;)s.push(i.value)}catch(c){a={error:c}}finally{try{i&&!i.done&&(t=n.return)&&t.call(n)}finally{if(a)throw a.error}}return s}function Ue(r,e,t){if(t||arguments.length===2)for(var n=0,i=e.length,s;n<i;n++)(s||!(n in e))&&(s||(s=Array.prototype.slice.call(e,0,n)),s[n]=e[n]);return r.concat(s||Array.prototype.slice.call(e))}function W(r){return typeof r=="function"}function hr(r){var e=function(n){Error.call(n),n.stack=new Error().stack},t=r(e);return t.prototype=Object.create(Error.prototype),t.prototype.constructor=t,t}var ht=hr(function(r){return function(t){r(this),this.message=t?t.length+` errors occurred during unsubscription:
|
|
4
4
|
`+t.map(function(n,i){return i+1+") "+n.toString()}).join(`
|
|
5
|
-
`):"",this.name="UnsubscriptionError",this.errors=t}});function pr(r,e){if(r){var t=r.indexOf(e);0<=t&&r.splice(t,1)}}var pt=function(){function r(e){this.initialTeardown=e,this.closed=!1,this._parentage=null,this._finalizers=null}return r.prototype.unsubscribe=function(){var e,t,n,i,s;if(!this.closed){this.closed=!0;var a=this._parentage;if(a)if(this._parentage=null,Array.isArray(a))try{for(var c=ur(a),o=c.next();!o.done;o=c.next()){var l=o.value;l.remove(this)}}catch(I){e={error:I}}finally{try{o&&!o.done&&(t=c.return)&&t.call(c)}finally{if(e)throw e.error}}else a.remove(this);var u=this.initialTeardown;if(W(u))try{u()}catch(I){s=I instanceof ht?I.errors:[I]}var p=this._finalizers;if(p){this._finalizers=null;try{for(var w=ur(p),f=w.next();!f.done;f=w.next()){var g=f.value;try{fr(g)}catch(I){s=s??[],I instanceof ht?s=Ue(Ue([],De(s)),De(I.errors)):s.push(I)}}}catch(I){n={error:I}}finally{try{f&&!f.done&&(i=w.return)&&i.call(w)}finally{if(n)throw n.error}}}if(s)throw new ht(s)}},r.prototype.add=function(e){var t;if(e&&e!==this)if(this.closed)fr(e);else{if(e instanceof r){if(e.closed||e._hasParent(this))return;e._addParent(this)}(this._finalizers=(t=this._finalizers)!==null&&t!==void 0?t:[]).push(e)}},r.prototype._hasParent=function(e){var t=this._parentage;return t===e||Array.isArray(t)&&t.includes(e)},r.prototype._addParent=function(e){var t=this._parentage;this._parentage=Array.isArray(t)?(t.push(e),t):t?[t,e]:e},r.prototype._removeParent=function(e){var t=this._parentage;t===e?this._parentage=null:Array.isArray(t)&&pr(t,e)},r.prototype.remove=function(e){var t=this._finalizers;t&&pr(t,e),e instanceof r&&e._removeParent(this)},r.EMPTY=function(){var e=new r;return e.closed=!0,e}(),r}();pt.EMPTY;function Qi(r){return r instanceof pt||r&&"closed"in r&&W(r.remove)&&W(r.add)&&W(r.unsubscribe)}function fr(r){W(r)?r():r.unsubscribe()}var Wi={onUnhandledError:null,onStoppedNotification:null,Promise:void 0,useDeprecatedSynchronousErrorHandling:!1,useDeprecatedNextContext:!1},ft={setTimeout:function(r,e){for(var t=[],n=2;n<arguments.length;n++)t[n-2]=arguments[n];var i=ft.delegate;return i!=null&&i.setTimeout?i.setTimeout.apply(i,Ue([r,e],De(t))):setTimeout.apply(void 0,Ue([r,e],De(t)))},clearTimeout:function(r){var e=ft.delegate;return((e==null?void 0:e.clearTimeout)||clearTimeout)(r)},delegate:void 0};function Ki(r){ft.setTimeout(function(){throw r})}function dr(){}var vr=function(r){ut(e,r);function e(t){var n=r.call(this)||this;return n.isStopped=!1,t?(n.destination=t,Qi(t)&&t.add(n)):n.destination=ts,n}return e.create=function(t,n,i){return new gr(t,n,i)},e.prototype.next=function(t){this.isStopped||this._next(t)},e.prototype.error=function(t){this.isStopped||(this.isStopped=!0,this._error(t))},e.prototype.complete=function(){this.isStopped||(this.isStopped=!0,this._complete())},e.prototype.unsubscribe=function(){this.closed||(this.isStopped=!0,r.prototype.unsubscribe.call(this),this.destination=null)},e.prototype._next=function(t){this.destination.next(t)},e.prototype._error=function(t){try{this.destination.error(t)}finally{this.unsubscribe()}},e.prototype._complete=function(){try{this.destination.complete()}finally{this.unsubscribe()}},e}(pt),Ji=Function.prototype.bind;function dt(r,e){return Ji.call(r,e)}var Zi=function(){function r(e){this.partialObserver=e}return r.prototype.next=function(e){var t=this.partialObserver;if(t.next)try{t.next(e)}catch(n){je(n)}},r.prototype.error=function(e){var t=this.partialObserver;if(t.error)try{t.error(e)}catch(n){je(n)}else je(e)},r.prototype.complete=function(){var e=this.partialObserver;if(e.complete)try{e.complete()}catch(t){je(t)}},r}(),gr=function(r){ut(e,r);function e(t,n,i){var s=r.call(this)||this,a;if(W(t)||!t)a={next:t??void 0,error:n??void 0,complete:i??void 0};else{var c;s&&Wi.useDeprecatedNextContext?(c=Object.create(t),c.unsubscribe=function(){return s.unsubscribe()},a={next:t.next&&dt(t.next,c),error:t.error&&dt(t.error,c),complete:t.complete&&dt(t.complete,c)}):a=t}return s.destination=new Zi(a),s}return e}(vr);function je(r){Ki(r)}function es(r){throw r}var ts={closed:!0,next:dr,error:es,complete:dr};function rs(r){return r}function ns(r){return W(r==null?void 0:r.lift)}function mr(r){return function(e){if(ns(e))return e.lift(function(t){try{return r(t,this)}catch(n){this.error(n)}});throw new TypeError("Unable to lift unknown Observable type")}}function Er(r,e,t,n,i){return new is(r,e,t,n,i)}var is=function(r){ut(e,r);function e(t,n,i,s,a,c){var o=r.call(this,t)||this;return o.onFinalize=a,o.shouldUnsubscribe=c,o._next=n?function(l){try{n(l)}catch(u){t.error(u)}}:r.prototype._next,o._error=s?function(l){try{s(l)}catch(u){t.error(u)}finally{this.unsubscribe()}}:r.prototype._error,o._complete=i?function(){try{i()}catch(l){t.error(l)}finally{this.unsubscribe()}}:r.prototype._complete,o}return e.prototype.unsubscribe=function(){var t;if(!this.shouldUnsubscribe||this.shouldUnsubscribe()){var n=this.closed;r.prototype.unsubscribe.call(this),!n&&((t=this.onFinalize)===null||t===void 0||t.call(this))}},e}(vr),ss=hr(function(r){return function(){r(this),this.name="EmptyError",this.message="no elements in sequence"}});function ge(r,e){var t=typeof e=="object";return new Promise(function(n,i){var s=new gr({next:function(a){n(a),s.unsubscribe()},error:i,complete:function(){t?n(e.defaultValue):i(new ss)}});r.subscribe(s)})}function Fe(r,e){return mr(function(t,n){var i=0;t.subscribe(Er(n,function(s){n.next(r.call(e,s,i++))}))})}function os(r,e,t){var n=W(r)||e||t?{next:r,error:e,complete:t}:r;return n?mr(function(i,s){var a;(a=n.subscribe)===null||a===void 0||a.call(n);var c=!0;i.subscribe(Er(s,function(o){var l;(l=n.next)===null||l===void 0||l.call(n,o),s.next(o)},function(){var o;c=!1,(o=n.complete)===null||o===void 0||o.call(n),s.complete()},function(o){var l;c=!1,(l=n.error)===null||l===void 0||l.call(n,o),s.error(o)},function(){var o,l;c&&((o=n.unsubscribe)===null||o===void 0||o.call(n)),(l=n.finalize)===null||l===void 0||l.call(n)}))}):rs}function as(){
|
|
5
|
+
`):"",this.name="UnsubscriptionError",this.errors=t}});function pr(r,e){if(r){var t=r.indexOf(e);0<=t&&r.splice(t,1)}}var pt=function(){function r(e){this.initialTeardown=e,this.closed=!1,this._parentage=null,this._finalizers=null}return r.prototype.unsubscribe=function(){var e,t,n,i,s;if(!this.closed){this.closed=!0;var a=this._parentage;if(a)if(this._parentage=null,Array.isArray(a))try{for(var c=ur(a),o=c.next();!o.done;o=c.next()){var l=o.value;l.remove(this)}}catch(I){e={error:I}}finally{try{o&&!o.done&&(t=c.return)&&t.call(c)}finally{if(e)throw e.error}}else a.remove(this);var u=this.initialTeardown;if(W(u))try{u()}catch(I){s=I instanceof ht?I.errors:[I]}var p=this._finalizers;if(p){this._finalizers=null;try{for(var w=ur(p),f=w.next();!f.done;f=w.next()){var g=f.value;try{fr(g)}catch(I){s=s??[],I instanceof ht?s=Ue(Ue([],De(s)),De(I.errors)):s.push(I)}}}catch(I){n={error:I}}finally{try{f&&!f.done&&(i=w.return)&&i.call(w)}finally{if(n)throw n.error}}}if(s)throw new ht(s)}},r.prototype.add=function(e){var t;if(e&&e!==this)if(this.closed)fr(e);else{if(e instanceof r){if(e.closed||e._hasParent(this))return;e._addParent(this)}(this._finalizers=(t=this._finalizers)!==null&&t!==void 0?t:[]).push(e)}},r.prototype._hasParent=function(e){var t=this._parentage;return t===e||Array.isArray(t)&&t.includes(e)},r.prototype._addParent=function(e){var t=this._parentage;this._parentage=Array.isArray(t)?(t.push(e),t):t?[t,e]:e},r.prototype._removeParent=function(e){var t=this._parentage;t===e?this._parentage=null:Array.isArray(t)&&pr(t,e)},r.prototype.remove=function(e){var t=this._finalizers;t&&pr(t,e),e instanceof r&&e._removeParent(this)},r.EMPTY=function(){var e=new r;return e.closed=!0,e}(),r}();pt.EMPTY;function Qi(r){return r instanceof pt||r&&"closed"in r&&W(r.remove)&&W(r.add)&&W(r.unsubscribe)}function fr(r){W(r)?r():r.unsubscribe()}var Wi={onUnhandledError:null,onStoppedNotification:null,Promise:void 0,useDeprecatedSynchronousErrorHandling:!1,useDeprecatedNextContext:!1},ft={setTimeout:function(r,e){for(var t=[],n=2;n<arguments.length;n++)t[n-2]=arguments[n];var i=ft.delegate;return i!=null&&i.setTimeout?i.setTimeout.apply(i,Ue([r,e],De(t))):setTimeout.apply(void 0,Ue([r,e],De(t)))},clearTimeout:function(r){var e=ft.delegate;return((e==null?void 0:e.clearTimeout)||clearTimeout)(r)},delegate:void 0};function Ki(r){ft.setTimeout(function(){throw r})}function dr(){}var vr=function(r){ut(e,r);function e(t){var n=r.call(this)||this;return n.isStopped=!1,t?(n.destination=t,Qi(t)&&t.add(n)):n.destination=ts,n}return e.create=function(t,n,i){return new gr(t,n,i)},e.prototype.next=function(t){this.isStopped||this._next(t)},e.prototype.error=function(t){this.isStopped||(this.isStopped=!0,this._error(t))},e.prototype.complete=function(){this.isStopped||(this.isStopped=!0,this._complete())},e.prototype.unsubscribe=function(){this.closed||(this.isStopped=!0,r.prototype.unsubscribe.call(this),this.destination=null)},e.prototype._next=function(t){this.destination.next(t)},e.prototype._error=function(t){try{this.destination.error(t)}finally{this.unsubscribe()}},e.prototype._complete=function(){try{this.destination.complete()}finally{this.unsubscribe()}},e}(pt),Ji=Function.prototype.bind;function dt(r,e){return Ji.call(r,e)}var Zi=function(){function r(e){this.partialObserver=e}return r.prototype.next=function(e){var t=this.partialObserver;if(t.next)try{t.next(e)}catch(n){je(n)}},r.prototype.error=function(e){var t=this.partialObserver;if(t.error)try{t.error(e)}catch(n){je(n)}else je(e)},r.prototype.complete=function(){var e=this.partialObserver;if(e.complete)try{e.complete()}catch(t){je(t)}},r}(),gr=function(r){ut(e,r);function e(t,n,i){var s=r.call(this)||this,a;if(W(t)||!t)a={next:t??void 0,error:n??void 0,complete:i??void 0};else{var c;s&&Wi.useDeprecatedNextContext?(c=Object.create(t),c.unsubscribe=function(){return s.unsubscribe()},a={next:t.next&&dt(t.next,c),error:t.error&&dt(t.error,c),complete:t.complete&&dt(t.complete,c)}):a=t}return s.destination=new Zi(a),s}return e}(vr);function je(r){Ki(r)}function es(r){throw r}var ts={closed:!0,next:dr,error:es,complete:dr};function rs(r){return r}function ns(r){return W(r==null?void 0:r.lift)}function mr(r){return function(e){if(ns(e))return e.lift(function(t){try{return r(t,this)}catch(n){this.error(n)}});throw new TypeError("Unable to lift unknown Observable type")}}function Er(r,e,t,n,i){return new is(r,e,t,n,i)}var is=function(r){ut(e,r);function e(t,n,i,s,a,c){var o=r.call(this,t)||this;return o.onFinalize=a,o.shouldUnsubscribe=c,o._next=n?function(l){try{n(l)}catch(u){t.error(u)}}:r.prototype._next,o._error=s?function(l){try{s(l)}catch(u){t.error(u)}finally{this.unsubscribe()}}:r.prototype._error,o._complete=i?function(){try{i()}catch(l){t.error(l)}finally{this.unsubscribe()}}:r.prototype._complete,o}return e.prototype.unsubscribe=function(){var t;if(!this.shouldUnsubscribe||this.shouldUnsubscribe()){var n=this.closed;r.prototype.unsubscribe.call(this),!n&&((t=this.onFinalize)===null||t===void 0||t.call(this))}},e}(vr),ss=hr(function(r){return function(){r(this),this.name="EmptyError",this.message="no elements in sequence"}});function ge(r,e){var t=typeof e=="object";return new Promise(function(n,i){var s=new gr({next:function(a){n(a),s.unsubscribe()},error:i,complete:function(){t?n(e.defaultValue):i(new ss)}});r.subscribe(s)})}function Fe(r,e){return mr(function(t,n){var i=0;t.subscribe(Er(n,function(s){n.next(r.call(e,s,i++))}))})}function os(r,e,t){var n=W(r)||e||t?{next:r,error:e,complete:t}:r;return n?mr(function(i,s){var a;(a=n.subscribe)===null||a===void 0||a.call(n);var c=!0;i.subscribe(Er(s,function(o){var l;(l=n.next)===null||l===void 0||l.call(n,o),s.next(o)},function(){var o;c=!1,(o=n.complete)===null||o===void 0||o.call(n),s.complete()},function(o){var l;c=!1,(l=n.error)===null||l===void 0||l.call(n,o),s.error(o)},function(){var o,l;c&&((o=n.unsubscribe)===null||o===void 0||o.call(n)),(l=n.finalize)===null||l===void 0||l.call(n)}))}):rs}function as(){return import("@acrobits/log-helper").then(r=>r.LogHelper.getLogger("IpcSDK")).catch(()=>(console.log("Failed to load @acrobits/log-helper, using console logger"),Promise.resolve(console)))}const ls=["1.0"];class cs{constructor(e){yr(this,me);le(this,"host");le(this,"cloudId");le(this,"logger");le(this,"helper");le(this,"listeners");e?this.logger=e:(this.logger=console,as().then(t=>{this.logger=t})),this.helper=new zi(ls,this.logger),this.listeners=new Map,this.listeners.set($.BadgeQuery,new Set),this.listeners.set($.HostInForeground,new Set)}get context(){return vt(this,me,gt).call(this,this.helper.currentContext)}get isConnected(){return!!(this.helper.currentContext==="user"&&this.host&&this.cloudId)}get negotiatedVersion(){return this.helper.negotiatedProtocolVersion}async determineContext(){const e=await ge(this.helper.determineContext(),{defaultValue:"guest"});return vt(this,me,gt).call(this,e)}initiateConnection(){return ge(this.helper.openBridge().pipe(os(e=>{this.helper.onBadgeQueryMessage().subscribe(t=>{var n;this.logger.debug("Received Badge Query: ",t);for(const i of((n=this.listeners.get($.BadgeQuery))==null?void 0:n.values())??[])i()}),this.helper.onHostInForegroundMessage().subscribe(t=>{var n;this.logger.debug("Received Host In Foreground: ",t);for(const i of((n=this.listeners.get($.HostInForeground))==null?void 0:n.values())??[])i()}),this.cloudId=e.cloudId,this.host=e.host}),Fe(()=>{})))}selectContacts(e,t,n){this.logger.debug("Selecting Contacts: ",...arguments);let i;if(t==="multi"){if(!n)throw new Ce("currentContacts",n,"currentContacts is required for group streams");i=this.helper.selectContacts(e.toString(),"group",n)}else i=this.helper.selectContacts(e.toString(),"direct");return ge(i.pipe(Fe(s=>s.contacts)))}matchContacts(e){return this.logger.debug("Match Contacts: ",e),ge(this.helper.matchContacts(e).pipe(Fe(t=>t.contacts)))}requestPushToken(){return this.logger.debug("Requesting Push Token"),ge(this.helper.requestPushToken().pipe(Fe(e=>e.pushToken)))}badgeUpdate(e){this.logger.debug("Sending Badge Update: ",e),this.helper.sendBadgeUpdateMessage(e)}onBadgeQueryRequest(e){var t;return this.logger.debug("Registering for Badge Query"),(t=this.listeners.get($.BadgeQuery))==null||t.add(e),()=>{var n;return(n=this.listeners.get($.BadgeQuery))==null?void 0:n.delete(e)}}onHostInForeground(e){var t;return this.logger.debug("Registering for Host In Foreground"),(t=this.listeners.get($.HostInForeground))==null||t.add(e),()=>{var n;return(n=this.listeners.get($.HostInForeground))==null?void 0:n.delete(e)}}}me=new WeakSet,gt=function(e){if(e==="user")return"host";if(e==="guest")return"standalone"},x.IPCEvents=$,x.IPCManager=cs,Object.defineProperty(x,Symbol.toStringTag,{value:"Module"})});
|