@acrobits/ipc-sdk 0.9.3 → 0.10.1

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.
@@ -1,5 +1,5 @@
1
- (function(S,v){typeof exports=="object"&&typeof module<"u"?v(exports):typeof define=="function"&&define.amd?define(["exports"],v):(S=typeof globalThis<"u"?globalThis:S||self,v(S["@acrobits/ipc-sdk"]={}))})(this,function(S){"use strict";var Tt=Object.defineProperty;var Rt=(S,v,C)=>v in S?Tt(S,v,{enumerable:!0,configurable:!0,writable:!0,value:C}):S[v]=C;var R=(S,v,C)=>(Rt(S,typeof v!="symbol"?v+"":v,C),C);var v=(n=>(n.BadgeQuery="BADGE QUERY",n.Lifecycle="LIFECYCLE",n.PushToken="PUSH TOKEN",n))(v||{}),C=function(n,t){return C=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,r){e.__proto__=r}||function(e,r){for(var s in r)Object.prototype.hasOwnProperty.call(r,s)&&(e[s]=r[s])},C(n,t)};function x(n,t){if(typeof t!="function"&&t!==null)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");C(n,t);function e(){this.constructor=n}n.prototype=t===null?Object.create(t):(e.prototype=t.prototype,new e)}function j(n){var t=typeof Symbol=="function"&&Symbol.iterator,e=t&&n[t],r=0;if(e)return e.call(n);if(n&&typeof n.length=="number")return{next:function(){return n&&r>=n.length&&(n=void 0),{value:n&&n[r++],done:!n}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function L(n,t){var e=typeof Symbol=="function"&&n[Symbol.iterator];if(!e)return n;var r=e.call(n),s,i=[],o;try{for(;(t===void 0||t-- >0)&&!(s=r.next()).done;)i.push(s.value)}catch(a){o={error:a}}finally{try{s&&!s.done&&(e=r.return)&&e.call(r)}finally{if(o)throw o.error}}return i}function U(n,t,e){if(e||arguments.length===2)for(var r=0,s=t.length,i;r<s;r++)(i||!(r in t))&&(i||(i=Array.prototype.slice.call(t,0,r)),i[r]=t[r]);return n.concat(i||Array.prototype.slice.call(t))}typeof SuppressedError=="function"&&SuppressedError;function E(n){return typeof n=="function"}function V(n){var t=function(r){Error.call(r),r.stack=new Error().stack},e=n(t);return e.prototype=Object.create(Error.prototype),e.prototype.constructor=e,e}var Q=V(function(n){return function(e){n(this),this.message=e?e.length+` errors occurred during unsubscription:
1
+ (function(S,v){typeof exports=="object"&&typeof module<"u"?v(exports):typeof define=="function"&&define.amd?define(["exports"],v):(S=typeof globalThis<"u"?globalThis:S||self,v(S["@acrobits/ipc-sdk"]={}))})(this,function(S){"use strict";var Tt=Object.defineProperty;var Rt=(S,v,C)=>v in S?Tt(S,v,{enumerable:!0,configurable:!0,writable:!0,value:C}):S[v]=C;var T=(S,v,C)=>Rt(S,typeof v!="symbol"?v+"":v,C);var v=(n=>(n.BadgeQuery="BADGE QUERY",n.Lifecycle="LIFECYCLE",n.PushToken="PUSH TOKEN",n))(v||{}),C=function(n,t){return C=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,r){e.__proto__=r}||function(e,r){for(var s in r)Object.prototype.hasOwnProperty.call(r,s)&&(e[s]=r[s])},C(n,t)};function x(n,t){if(typeof t!="function"&&t!==null)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");C(n,t);function e(){this.constructor=n}n.prototype=t===null?Object.create(t):(e.prototype=t.prototype,new e)}function j(n){var t=typeof Symbol=="function"&&Symbol.iterator,e=t&&n[t],r=0;if(e)return e.call(n);if(n&&typeof n.length=="number")return{next:function(){return n&&r>=n.length&&(n=void 0),{value:n&&n[r++],done:!n}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function L(n,t){var e=typeof Symbol=="function"&&n[Symbol.iterator];if(!e)return n;var r=e.call(n),s,i=[],o;try{for(;(t===void 0||t-- >0)&&!(s=r.next()).done;)i.push(s.value)}catch(a){o={error:a}}finally{try{s&&!s.done&&(e=r.return)&&e.call(r)}finally{if(o)throw o.error}}return i}function U(n,t,e){if(e||arguments.length===2)for(var r=0,s=t.length,i;r<s;r++)(i||!(r in t))&&(i||(i=Array.prototype.slice.call(t,0,r)),i[r]=t[r]);return n.concat(i||Array.prototype.slice.call(t))}typeof SuppressedError=="function"&&SuppressedError;function E(n){return typeof n=="function"}function V(n){var t=function(r){Error.call(r),r.stack=new Error().stack},e=n(t);return e.prototype=Object.create(Error.prototype),e.prototype.constructor=e,e}var Q=V(function(n){return function(e){n(this),this.message=e?e.length+` errors occurred during unsubscription:
2
2
  `+e.map(function(r,s){return s+1+") "+r.toString()}).join(`
3
- `):"",this.name="UnsubscriptionError",this.errors=e}});function $(n,t){if(n){var e=n.indexOf(t);0<=e&&n.splice(e,1)}}var P=function(){function n(t){this.initialTeardown=t,this.closed=!1,this._parentage=null,this._finalizers=null}return n.prototype.unsubscribe=function(){var t,e,r,s,i;if(!this.closed){this.closed=!0;var o=this._parentage;if(o)if(this._parentage=null,Array.isArray(o))try{for(var a=j(o),c=a.next();!c.done;c=a.next()){var u=c.value;u.remove(this)}}catch(b){t={error:b}}finally{try{c&&!c.done&&(e=a.return)&&e.call(a)}finally{if(t)throw t.error}}else o.remove(this);var l=this.initialTeardown;if(E(l))try{l()}catch(b){i=b instanceof Q?b.errors:[b]}var h=this._finalizers;if(h){this._finalizers=null;try{for(var m=j(h),y=m.next();!y.done;y=m.next()){var se=y.value;try{ae(se)}catch(b){i=i??[],b instanceof Q?i=U(U([],L(i)),L(b.errors)):i.push(b)}}}catch(b){r={error:b}}finally{try{y&&!y.done&&(s=m.return)&&s.call(m)}finally{if(r)throw r.error}}}if(i)throw new Q(i)}},n.prototype.add=function(t){var e;if(t&&t!==this)if(this.closed)ae(t);else{if(t instanceof n){if(t.closed||t._hasParent(this))return;t._addParent(this)}(this._finalizers=(e=this._finalizers)!==null&&e!==void 0?e:[]).push(t)}},n.prototype._hasParent=function(t){var e=this._parentage;return e===t||Array.isArray(e)&&e.includes(t)},n.prototype._addParent=function(t){var e=this._parentage;this._parentage=Array.isArray(e)?(e.push(t),e):e?[e,t]:t},n.prototype._removeParent=function(t){var e=this._parentage;e===t?this._parentage=null:Array.isArray(e)&&$(e,t)},n.prototype.remove=function(t){var e=this._finalizers;e&&$(e,t),t instanceof n&&t._removeParent(this)},n.EMPTY=function(){var t=new n;return t.closed=!0,t}(),n}(),ie=P.EMPTY;function oe(n){return n instanceof P||n&&"closed"in n&&E(n.remove)&&E(n.add)&&E(n.unsubscribe)}function ae(n){E(n)?n():n.unsubscribe()}var ce={onUnhandledError:null,onStoppedNotification:null,Promise:void 0,useDeprecatedSynchronousErrorHandling:!1,useDeprecatedNextContext:!1},ue={setTimeout:function(n,t){for(var e=[],r=2;r<arguments.length;r++)e[r-2]=arguments[r];return setTimeout.apply(void 0,U([n,t],L(e)))},clearTimeout:function(n){var t=ue.delegate;return((t==null?void 0:t.clearTimeout)||clearTimeout)(n)},delegate:void 0};function _e(n){ue.setTimeout(function(){throw n})}function le(){}function D(n){n()}var q=function(n){x(t,n);function t(e){var r=n.call(this)||this;return r.isStopped=!1,e?(r.destination=e,oe(e)&&e.add(r)):r.destination=Ue,r}return t.create=function(e,r,s){return new F(e,r,s)},t.prototype.next=function(e){this.isStopped||this._next(e)},t.prototype.error=function(e){this.isStopped||(this.isStopped=!0,this._error(e))},t.prototype.complete=function(){this.isStopped||(this.isStopped=!0,this._complete())},t.prototype.unsubscribe=function(){this.closed||(this.isStopped=!0,n.prototype.unsubscribe.call(this),this.destination=null)},t.prototype._next=function(e){this.destination.next(e)},t.prototype._error=function(e){try{this.destination.error(e)}finally{this.unsubscribe()}},t.prototype._complete=function(){try{this.destination.complete()}finally{this.unsubscribe()}},t}(P),Ae=Function.prototype.bind;function G(n,t){return Ae.call(n,t)}var Oe=function(){function n(t){this.partialObserver=t}return n.prototype.next=function(t){var e=this.partialObserver;if(e.next)try{e.next(t)}catch(r){H(r)}},n.prototype.error=function(t){var e=this.partialObserver;if(e.error)try{e.error(t)}catch(r){H(r)}else H(t)},n.prototype.complete=function(){var t=this.partialObserver;if(t.complete)try{t.complete()}catch(e){H(e)}},n}(),F=function(n){x(t,n);function t(e,r,s){var i=n.call(this)||this,o;if(E(e)||!e)o={next:e??void 0,error:r??void 0,complete:s??void 0};else{var a;i&&ce.useDeprecatedNextContext?(a=Object.create(e),a.unsubscribe=function(){return i.unsubscribe()},o={next:e.next&&G(e.next,a),error:e.error&&G(e.error,a),complete:e.complete&&G(e.complete,a)}):o=e}return i.destination=new Oe(o),i}return t}(q);function H(n){_e(n)}function Le(n){throw n}var Ue={closed:!0,next:le,error:Le,complete:le},$e=function(){return typeof Symbol=="function"&&Symbol.observable||"@@observable"}();function he(n){return n}function De(n){return n.length===0?he:n.length===1?n[0]:function(e){return n.reduce(function(r,s){return s(r)},e)}}var B=function(){function n(t){t&&(this._subscribe=t)}return n.prototype.lift=function(t){var e=new n;return e.source=this,e.operator=t,e},n.prototype.subscribe=function(t,e,r){var s=this,i=He(t)?t:new F(t,e,r);return D(function(){var o=s,a=o.operator,c=o.source;i.add(a?a.call(i,c):c?s._subscribe(i):s._trySubscribe(i))}),i},n.prototype._trySubscribe=function(t){try{return this._subscribe(t)}catch(e){t.error(e)}},n.prototype.forEach=function(t,e){var r=this;return e=de(e),new e(function(s,i){var o=new F({next:function(a){try{t(a)}catch(c){i(c),o.unsubscribe()}},error:i,complete:s});r.subscribe(o)})},n.prototype._subscribe=function(t){var e;return(e=this.source)===null||e===void 0?void 0:e.subscribe(t)},n.prototype[$e]=function(){return this},n.prototype.pipe=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return De(t)(this)},n.prototype.toPromise=function(t){var e=this;return t=de(t),new t(function(r,s){var i;e.subscribe(function(o){return i=o},function(o){return s(o)},function(){return r(i)})})},n.create=function(t){return new n(t)},n}();function de(n){var t;return(t=n??ce.Promise)!==null&&t!==void 0?t:Promise}function Fe(n){return n&&E(n.next)&&E(n.error)&&E(n.complete)}function He(n){return n&&n instanceof q||Fe(n)&&oe(n)}function ke(n){return E(n==null?void 0:n.lift)}function pe(n){return function(t){if(ke(t))return t.lift(function(e){try{return n(e,this)}catch(r){this.error(r)}});throw new TypeError("Unable to lift unknown Observable type")}}function fe(n,t,e,r,s){return new Ne(n,t,e,r,s)}var Ne=function(n){x(t,n);function t(e,r,s,i,o,a){var c=n.call(this,e)||this;return c.onFinalize=o,c.shouldUnsubscribe=a,c._next=r?function(u){try{r(u)}catch(l){e.error(l)}}:n.prototype._next,c._error=i?function(u){try{i(u)}catch(l){e.error(l)}finally{this.unsubscribe()}}:n.prototype._error,c._complete=s?function(){try{s()}catch(u){e.error(u)}finally{this.unsubscribe()}}:n.prototype._complete,c}return t.prototype.unsubscribe=function(){var e;if(!this.shouldUnsubscribe||this.shouldUnsubscribe()){var r=this.closed;n.prototype.unsubscribe.call(this),!r&&((e=this.onFinalize)===null||e===void 0||e.call(this))}},t}(q),je=V(function(n){return function(){n(this),this.name="ObjectUnsubscribedError",this.message="object unsubscribed"}}),ge=function(n){x(t,n);function t(){var e=n.call(this)||this;return e.closed=!1,e.currentObservers=null,e.observers=[],e.isStopped=!1,e.hasError=!1,e.thrownError=null,e}return t.prototype.lift=function(e){var r=new ve(this,this);return r.operator=e,r},t.prototype._throwIfClosed=function(){if(this.closed)throw new je},t.prototype.next=function(e){var r=this;D(function(){var s,i;if(r._throwIfClosed(),!r.isStopped){r.currentObservers||(r.currentObservers=Array.from(r.observers));try{for(var o=j(r.currentObservers),a=o.next();!a.done;a=o.next()){var c=a.value;c.next(e)}}catch(u){s={error:u}}finally{try{a&&!a.done&&(i=o.return)&&i.call(o)}finally{if(s)throw s.error}}}})},t.prototype.error=function(e){var r=this;D(function(){if(r._throwIfClosed(),!r.isStopped){r.hasError=r.isStopped=!0,r.thrownError=e;for(var s=r.observers;s.length;)s.shift().error(e)}})},t.prototype.complete=function(){var e=this;D(function(){if(e._throwIfClosed(),!e.isStopped){e.isStopped=!0;for(var r=e.observers;r.length;)r.shift().complete()}})},t.prototype.unsubscribe=function(){this.isStopped=this.closed=!0,this.observers=this.currentObservers=null},Object.defineProperty(t.prototype,"observed",{get:function(){var e;return((e=this.observers)===null||e===void 0?void 0:e.length)>0},enumerable:!1,configurable:!0}),t.prototype._trySubscribe=function(e){return this._throwIfClosed(),n.prototype._trySubscribe.call(this,e)},t.prototype._subscribe=function(e){return this._throwIfClosed(),this._checkFinalizedStatuses(e),this._innerSubscribe(e)},t.prototype._innerSubscribe=function(e){var r=this,s=this,i=s.hasError,o=s.isStopped,a=s.observers;return i||o?ie:(this.currentObservers=null,a.push(e),new P(function(){r.currentObservers=null,$(a,e)}))},t.prototype._checkFinalizedStatuses=function(e){var r=this,s=r.hasError,i=r.thrownError,o=r.isStopped;s?e.error(i):o&&e.complete()},t.prototype.asObservable=function(){var e=new B;return e.source=this,e},t.create=function(e,r){return new ve(e,r)},t}(B),ve=function(n){x(t,n);function t(e,r){var s=n.call(this)||this;return s.destination=e,s.source=r,s}return t.prototype.next=function(e){var r,s;(s=(r=this.destination)===null||r===void 0?void 0:r.next)===null||s===void 0||s.call(r,e)},t.prototype.error=function(e){var r,s;(s=(r=this.destination)===null||r===void 0?void 0:r.error)===null||s===void 0||s.call(r,e)},t.prototype.complete=function(){var e,r;(r=(e=this.destination)===null||e===void 0?void 0:e.complete)===null||r===void 0||r.call(e)},t.prototype._subscribe=function(e){var r,s;return(s=(r=this.source)===null||r===void 0?void 0:r.subscribe(e))!==null&&s!==void 0?s:ie},t}(ge),Ve={now:function(){return Date.now()},delegate:void 0},Qe=function(n){x(t,n);function t(e,r){return n.call(this)||this}return t.prototype.schedule=function(e,r){return this},t}(P),Y={setInterval:function(n,t){for(var e=[],r=2;r<arguments.length;r++)e[r-2]=arguments[r];return setInterval.apply(void 0,U([n,t],L(e)))},clearInterval:function(n){var t=Y.delegate;return((t==null?void 0:t.clearInterval)||clearInterval)(n)},delegate:void 0},qe=function(n){x(t,n);function t(e,r){var s=n.call(this,e,r)||this;return s.scheduler=e,s.work=r,s.pending=!1,s}return t.prototype.schedule=function(e,r){var s;if(r===void 0&&(r=0),this.closed)return this;this.state=e;var i=this.id,o=this.scheduler;return i!=null&&(this.id=this.recycleAsyncId(o,i,r)),this.pending=!0,this.delay=r,this.id=(s=this.id)!==null&&s!==void 0?s:this.requestAsyncId(o,this.id,r),this},t.prototype.requestAsyncId=function(e,r,s){return s===void 0&&(s=0),Y.setInterval(e.flush.bind(e,this),s)},t.prototype.recycleAsyncId=function(e,r,s){if(s===void 0&&(s=0),s!=null&&this.delay===s&&this.pending===!1)return r;r!=null&&Y.clearInterval(r)},t.prototype.execute=function(e,r){if(this.closed)return new Error("executing a cancelled action");this.pending=!1;var s=this._execute(e,r);if(s)return s;this.pending===!1&&this.id!=null&&(this.id=this.recycleAsyncId(this.scheduler,this.id,null))},t.prototype._execute=function(e,r){var s=!1,i;try{this.work(e)}catch(o){s=!0,i=o||new Error("Scheduled action threw falsy error")}if(s)return this.unsubscribe(),i},t.prototype.unsubscribe=function(){if(!this.closed){var e=this,r=e.id,s=e.scheduler,i=s.actions;this.work=this.state=this.scheduler=null,this.pending=!1,$(i,this),r!=null&&(this.id=this.recycleAsyncId(s,r,null)),this.delay=null,n.prototype.unsubscribe.call(this)}},t}(Qe),ye=function(){function n(t,e){e===void 0&&(e=n.now),this.schedulerActionCtor=t,this.now=e}return n.prototype.schedule=function(t,e,r){return e===void 0&&(e=0),new this.schedulerActionCtor(this,t).schedule(r,e)},n.now=Ve.now,n}(),Ge=function(n){x(t,n);function t(e,r){r===void 0&&(r=ye.now);var s=n.call(this,e,r)||this;return s.actions=[],s._active=!1,s}return t.prototype.flush=function(e){var r=this.actions;if(this._active){r.push(e);return}var s;this._active=!0;do if(s=e.execute(e.state,e.delay))break;while(e=r.shift());if(this._active=!1,s){for(;e=r.shift();)e.unsubscribe();throw s}},t}(ye),Be=new Ge(qe),Ye=Be,ze=V(function(n){return function(){n(this),this.name="EmptyError",this.message="no elements in sequence"}});function _(n,t){var e=typeof t=="object";return new Promise(function(r,s){var i=new F({next:function(o){r(o),i.unsubscribe()},error:s,complete:function(){e?r(t.defaultValue):s(new ze)}});n.subscribe(i)})}function We(n){return n instanceof Date&&!isNaN(n)}function k(n,t){return pe(function(e,r){var s=0;e.subscribe(fe(r,function(i){r.next(n.call(t,i,s++))}))})}function Ke(n,t,e){return e===void 0&&(e=Ye),new B(function(r){var s=We(n)?+n-e.now():n;s<0&&(s=0);var i=0;return e.schedule(function(){r.closed||(r.next(i++),r.complete())},s)})}function Je(n,t,e){var r=E(n)||t||e?{next:n,error:t,complete:e}:n;return r?pe(function(s,i){var o;(o=r.subscribe)===null||o===void 0||o.call(r);var a=!0;s.subscribe(fe(i,function(c){var u;(u=r.next)===null||u===void 0||u.call(r,c),i.next(c)},function(){var c;a=!1,(c=r.complete)===null||c===void 0||c.call(r),i.complete()},function(c){var u;a=!1,(u=r.error)===null||u===void 0||u.call(r,c),i.error(c)},function(){var c,u;a&&((c=r.unsubscribe)===null||c===void 0||c.call(r)),(u=r.finalize)===null||u===void 0||u.call(r)}))}):he}var Xe=Object.defineProperty,Ze=(n,t,e)=>t in n?Xe(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,I=(n,t,e)=>(Ze(n,typeof t!="symbol"?t+"":t,e),e);class d extends Error{constructor(t){super(`Incorrect context (${t}). Cannot perform the requested operation.`),I(this,"context"),this.context=t}}class T extends Error{constructor(t,e,r){super(`Invalid parameter (${t}). ${r}`),this.param=t,this.value=e,this.reason=r}}class et extends Error{constructor(t,e){super(`'streamId' value of "${t}" is different from what we expected ("${e}")`),this.streamId=t,this.expectedStreamId=e}}class tt extends Error{constructor(t){super(`Invalid version format: ${t}`)}}class be extends Error{constructor(t){super(`${t} needs to be initialized before it can be used.`)}}class me extends Error{constructor(t,e){let r=`Unsupported Protocol ${Array.isArray(t)?"versions":"version"}: (${t}).`;e&&(r+=` Minimum version supported is ${e}.`),super(r),this.version=t}}function M(n){return typeof n=="function"}function rt(n){return M(n==null?void 0:n.lift)}function A(n){return function(t){if(rt(t))return t.lift(function(e){try{return n(e,this)}catch(r){this.error(r)}});throw new TypeError("Unable to lift unknown Observable type")}}var z=function(n,t){return z=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,r){e.__proto__=r}||function(e,r){for(var s in r)Object.prototype.hasOwnProperty.call(r,s)&&(e[s]=r[s])},z(n,t)};function W(n,t){if(typeof t!="function"&&t!==null)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");z(n,t);function e(){this.constructor=n}n.prototype=t===null?Object.create(t):(e.prototype=t.prototype,new e)}function we(n){var t=typeof Symbol=="function"&&Symbol.iterator,e=t&&n[t],r=0;if(e)return e.call(n);if(n&&typeof n.length=="number")return{next:function(){return n&&r>=n.length&&(n=void 0),{value:n&&n[r++],done:!n}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function K(n,t){var e=typeof Symbol=="function"&&n[Symbol.iterator];if(!e)return n;var r=e.call(n),s,i=[],o;try{for(;(t===void 0||t-- >0)&&!(s=r.next()).done;)i.push(s.value)}catch(a){o={error:a}}finally{try{s&&!s.done&&(e=r.return)&&e.call(r)}finally{if(o)throw o.error}}return i}function J(n,t,e){if(arguments.length===2)for(var r=0,s=t.length,i;r<s;r++)(i||!(r in t))&&(i||(i=Array.prototype.slice.call(t,0,r)),i[r]=t[r]);return n.concat(i||Array.prototype.slice.call(t))}function nt(n){var t=function(r){Error.call(r),r.stack=new Error().stack},e=n(t);return e.prototype=Object.create(Error.prototype),e.prototype.constructor=e,e}var X=nt(function(n){return function(t){n(this),this.message=t?t.length+` errors occurred during unsubscription:
3
+ `):"",this.name="UnsubscriptionError",this.errors=e}});function $(n,t){if(n){var e=n.indexOf(t);0<=e&&n.splice(e,1)}}var P=function(){function n(t){this.initialTeardown=t,this.closed=!1,this._parentage=null,this._finalizers=null}return n.prototype.unsubscribe=function(){var t,e,r,s,i;if(!this.closed){this.closed=!0;var o=this._parentage;if(o)if(this._parentage=null,Array.isArray(o))try{for(var a=j(o),c=a.next();!c.done;c=a.next()){var u=c.value;u.remove(this)}}catch(b){t={error:b}}finally{try{c&&!c.done&&(e=a.return)&&e.call(a)}finally{if(t)throw t.error}}else o.remove(this);var l=this.initialTeardown;if(E(l))try{l()}catch(b){i=b instanceof Q?b.errors:[b]}var h=this._finalizers;if(h){this._finalizers=null;try{for(var m=j(h),y=m.next();!y.done;y=m.next()){var se=y.value;try{ae(se)}catch(b){i=i??[],b instanceof Q?i=U(U([],L(i)),L(b.errors)):i.push(b)}}}catch(b){r={error:b}}finally{try{y&&!y.done&&(s=m.return)&&s.call(m)}finally{if(r)throw r.error}}}if(i)throw new Q(i)}},n.prototype.add=function(t){var e;if(t&&t!==this)if(this.closed)ae(t);else{if(t instanceof n){if(t.closed||t._hasParent(this))return;t._addParent(this)}(this._finalizers=(e=this._finalizers)!==null&&e!==void 0?e:[]).push(t)}},n.prototype._hasParent=function(t){var e=this._parentage;return e===t||Array.isArray(e)&&e.includes(t)},n.prototype._addParent=function(t){var e=this._parentage;this._parentage=Array.isArray(e)?(e.push(t),e):e?[e,t]:t},n.prototype._removeParent=function(t){var e=this._parentage;e===t?this._parentage=null:Array.isArray(e)&&$(e,t)},n.prototype.remove=function(t){var e=this._finalizers;e&&$(e,t),t instanceof n&&t._removeParent(this)},n.EMPTY=function(){var t=new n;return t.closed=!0,t}(),n}(),ie=P.EMPTY;function oe(n){return n instanceof P||n&&"closed"in n&&E(n.remove)&&E(n.add)&&E(n.unsubscribe)}function ae(n){E(n)?n():n.unsubscribe()}var ce={onUnhandledError:null,onStoppedNotification:null,Promise:void 0,useDeprecatedSynchronousErrorHandling:!1,useDeprecatedNextContext:!1},ue={setTimeout:function(n,t){for(var e=[],r=2;r<arguments.length;r++)e[r-2]=arguments[r];return setTimeout.apply(void 0,U([n,t],L(e)))},clearTimeout:function(n){var t=ue.delegate;return((t==null?void 0:t.clearTimeout)||clearTimeout)(n)},delegate:void 0};function _e(n){ue.setTimeout(function(){throw n})}function le(){}function D(n){n()}var q=function(n){x(t,n);function t(e){var r=n.call(this)||this;return r.isStopped=!1,e?(r.destination=e,oe(e)&&e.add(r)):r.destination=Ue,r}return t.create=function(e,r,s){return new F(e,r,s)},t.prototype.next=function(e){this.isStopped||this._next(e)},t.prototype.error=function(e){this.isStopped||(this.isStopped=!0,this._error(e))},t.prototype.complete=function(){this.isStopped||(this.isStopped=!0,this._complete())},t.prototype.unsubscribe=function(){this.closed||(this.isStopped=!0,n.prototype.unsubscribe.call(this),this.destination=null)},t.prototype._next=function(e){this.destination.next(e)},t.prototype._error=function(e){try{this.destination.error(e)}finally{this.unsubscribe()}},t.prototype._complete=function(){try{this.destination.complete()}finally{this.unsubscribe()}},t}(P),Ae=Function.prototype.bind;function G(n,t){return Ae.call(n,t)}var Oe=function(){function n(t){this.partialObserver=t}return n.prototype.next=function(t){var e=this.partialObserver;if(e.next)try{e.next(t)}catch(r){H(r)}},n.prototype.error=function(t){var e=this.partialObserver;if(e.error)try{e.error(t)}catch(r){H(r)}else H(t)},n.prototype.complete=function(){var t=this.partialObserver;if(t.complete)try{t.complete()}catch(e){H(e)}},n}(),F=function(n){x(t,n);function t(e,r,s){var i=n.call(this)||this,o;if(E(e)||!e)o={next:e??void 0,error:r??void 0,complete:s??void 0};else{var a;i&&ce.useDeprecatedNextContext?(a=Object.create(e),a.unsubscribe=function(){return i.unsubscribe()},o={next:e.next&&G(e.next,a),error:e.error&&G(e.error,a),complete:e.complete&&G(e.complete,a)}):o=e}return i.destination=new Oe(o),i}return t}(q);function H(n){_e(n)}function Le(n){throw n}var Ue={closed:!0,next:le,error:Le,complete:le},$e=function(){return typeof Symbol=="function"&&Symbol.observable||"@@observable"}();function he(n){return n}function De(n){return n.length===0?he:n.length===1?n[0]:function(e){return n.reduce(function(r,s){return s(r)},e)}}var B=function(){function n(t){t&&(this._subscribe=t)}return n.prototype.lift=function(t){var e=new n;return e.source=this,e.operator=t,e},n.prototype.subscribe=function(t,e,r){var s=this,i=He(t)?t:new F(t,e,r);return D(function(){var o=s,a=o.operator,c=o.source;i.add(a?a.call(i,c):c?s._subscribe(i):s._trySubscribe(i))}),i},n.prototype._trySubscribe=function(t){try{return this._subscribe(t)}catch(e){t.error(e)}},n.prototype.forEach=function(t,e){var r=this;return e=de(e),new e(function(s,i){var o=new F({next:function(a){try{t(a)}catch(c){i(c),o.unsubscribe()}},error:i,complete:s});r.subscribe(o)})},n.prototype._subscribe=function(t){var e;return(e=this.source)===null||e===void 0?void 0:e.subscribe(t)},n.prototype[$e]=function(){return this},n.prototype.pipe=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return De(t)(this)},n.prototype.toPromise=function(t){var e=this;return t=de(t),new t(function(r,s){var i;e.subscribe(function(o){return i=o},function(o){return s(o)},function(){return r(i)})})},n.create=function(t){return new n(t)},n}();function de(n){var t;return(t=n??ce.Promise)!==null&&t!==void 0?t:Promise}function Fe(n){return n&&E(n.next)&&E(n.error)&&E(n.complete)}function He(n){return n&&n instanceof q||Fe(n)&&oe(n)}function Ne(n){return E(n==null?void 0:n.lift)}function pe(n){return function(t){if(Ne(t))return t.lift(function(e){try{return n(e,this)}catch(r){this.error(r)}});throw new TypeError("Unable to lift unknown Observable type")}}function fe(n,t,e,r,s){return new ke(n,t,e,r,s)}var ke=function(n){x(t,n);function t(e,r,s,i,o,a){var c=n.call(this,e)||this;return c.onFinalize=o,c.shouldUnsubscribe=a,c._next=r?function(u){try{r(u)}catch(l){e.error(l)}}:n.prototype._next,c._error=i?function(u){try{i(u)}catch(l){e.error(l)}finally{this.unsubscribe()}}:n.prototype._error,c._complete=s?function(){try{s()}catch(u){e.error(u)}finally{this.unsubscribe()}}:n.prototype._complete,c}return t.prototype.unsubscribe=function(){var e;if(!this.shouldUnsubscribe||this.shouldUnsubscribe()){var r=this.closed;n.prototype.unsubscribe.call(this),!r&&((e=this.onFinalize)===null||e===void 0||e.call(this))}},t}(q),je=V(function(n){return function(){n(this),this.name="ObjectUnsubscribedError",this.message="object unsubscribed"}}),ge=function(n){x(t,n);function t(){var e=n.call(this)||this;return e.closed=!1,e.currentObservers=null,e.observers=[],e.isStopped=!1,e.hasError=!1,e.thrownError=null,e}return t.prototype.lift=function(e){var r=new ve(this,this);return r.operator=e,r},t.prototype._throwIfClosed=function(){if(this.closed)throw new je},t.prototype.next=function(e){var r=this;D(function(){var s,i;if(r._throwIfClosed(),!r.isStopped){r.currentObservers||(r.currentObservers=Array.from(r.observers));try{for(var o=j(r.currentObservers),a=o.next();!a.done;a=o.next()){var c=a.value;c.next(e)}}catch(u){s={error:u}}finally{try{a&&!a.done&&(i=o.return)&&i.call(o)}finally{if(s)throw s.error}}}})},t.prototype.error=function(e){var r=this;D(function(){if(r._throwIfClosed(),!r.isStopped){r.hasError=r.isStopped=!0,r.thrownError=e;for(var s=r.observers;s.length;)s.shift().error(e)}})},t.prototype.complete=function(){var e=this;D(function(){if(e._throwIfClosed(),!e.isStopped){e.isStopped=!0;for(var r=e.observers;r.length;)r.shift().complete()}})},t.prototype.unsubscribe=function(){this.isStopped=this.closed=!0,this.observers=this.currentObservers=null},Object.defineProperty(t.prototype,"observed",{get:function(){var e;return((e=this.observers)===null||e===void 0?void 0:e.length)>0},enumerable:!1,configurable:!0}),t.prototype._trySubscribe=function(e){return this._throwIfClosed(),n.prototype._trySubscribe.call(this,e)},t.prototype._subscribe=function(e){return this._throwIfClosed(),this._checkFinalizedStatuses(e),this._innerSubscribe(e)},t.prototype._innerSubscribe=function(e){var r=this,s=this,i=s.hasError,o=s.isStopped,a=s.observers;return i||o?ie:(this.currentObservers=null,a.push(e),new P(function(){r.currentObservers=null,$(a,e)}))},t.prototype._checkFinalizedStatuses=function(e){var r=this,s=r.hasError,i=r.thrownError,o=r.isStopped;s?e.error(i):o&&e.complete()},t.prototype.asObservable=function(){var e=new B;return e.source=this,e},t.create=function(e,r){return new ve(e,r)},t}(B),ve=function(n){x(t,n);function t(e,r){var s=n.call(this)||this;return s.destination=e,s.source=r,s}return t.prototype.next=function(e){var r,s;(s=(r=this.destination)===null||r===void 0?void 0:r.next)===null||s===void 0||s.call(r,e)},t.prototype.error=function(e){var r,s;(s=(r=this.destination)===null||r===void 0?void 0:r.error)===null||s===void 0||s.call(r,e)},t.prototype.complete=function(){var e,r;(r=(e=this.destination)===null||e===void 0?void 0:e.complete)===null||r===void 0||r.call(e)},t.prototype._subscribe=function(e){var r,s;return(s=(r=this.source)===null||r===void 0?void 0:r.subscribe(e))!==null&&s!==void 0?s:ie},t}(ge),Ve={now:function(){return Date.now()},delegate:void 0},Qe=function(n){x(t,n);function t(e,r){return n.call(this)||this}return t.prototype.schedule=function(e,r){return this},t}(P),Y={setInterval:function(n,t){for(var e=[],r=2;r<arguments.length;r++)e[r-2]=arguments[r];return setInterval.apply(void 0,U([n,t],L(e)))},clearInterval:function(n){var t=Y.delegate;return((t==null?void 0:t.clearInterval)||clearInterval)(n)},delegate:void 0},qe=function(n){x(t,n);function t(e,r){var s=n.call(this,e,r)||this;return s.scheduler=e,s.work=r,s.pending=!1,s}return t.prototype.schedule=function(e,r){var s;if(r===void 0&&(r=0),this.closed)return this;this.state=e;var i=this.id,o=this.scheduler;return i!=null&&(this.id=this.recycleAsyncId(o,i,r)),this.pending=!0,this.delay=r,this.id=(s=this.id)!==null&&s!==void 0?s:this.requestAsyncId(o,this.id,r),this},t.prototype.requestAsyncId=function(e,r,s){return s===void 0&&(s=0),Y.setInterval(e.flush.bind(e,this),s)},t.prototype.recycleAsyncId=function(e,r,s){if(s===void 0&&(s=0),s!=null&&this.delay===s&&this.pending===!1)return r;r!=null&&Y.clearInterval(r)},t.prototype.execute=function(e,r){if(this.closed)return new Error("executing a cancelled action");this.pending=!1;var s=this._execute(e,r);if(s)return s;this.pending===!1&&this.id!=null&&(this.id=this.recycleAsyncId(this.scheduler,this.id,null))},t.prototype._execute=function(e,r){var s=!1,i;try{this.work(e)}catch(o){s=!0,i=o||new Error("Scheduled action threw falsy error")}if(s)return this.unsubscribe(),i},t.prototype.unsubscribe=function(){if(!this.closed){var e=this,r=e.id,s=e.scheduler,i=s.actions;this.work=this.state=this.scheduler=null,this.pending=!1,$(i,this),r!=null&&(this.id=this.recycleAsyncId(s,r,null)),this.delay=null,n.prototype.unsubscribe.call(this)}},t}(Qe),ye=function(){function n(t,e){e===void 0&&(e=n.now),this.schedulerActionCtor=t,this.now=e}return n.prototype.schedule=function(t,e,r){return e===void 0&&(e=0),new this.schedulerActionCtor(this,t).schedule(r,e)},n.now=Ve.now,n}(),Ge=function(n){x(t,n);function t(e,r){r===void 0&&(r=ye.now);var s=n.call(this,e,r)||this;return s.actions=[],s._active=!1,s}return t.prototype.flush=function(e){var r=this.actions;if(this._active){r.push(e);return}var s;this._active=!0;do if(s=e.execute(e.state,e.delay))break;while(e=r.shift());if(this._active=!1,s){for(;e=r.shift();)e.unsubscribe();throw s}},t}(ye),Be=new Ge(qe),Ye=Be,ze=V(function(n){return function(){n(this),this.name="EmptyError",this.message="no elements in sequence"}});function _(n,t){var e=typeof t=="object";return new Promise(function(r,s){var i=new F({next:function(o){r(o),i.unsubscribe()},error:s,complete:function(){e?r(t.defaultValue):s(new ze)}});n.subscribe(i)})}function We(n){return n instanceof Date&&!isNaN(n)}function N(n,t){return pe(function(e,r){var s=0;e.subscribe(fe(r,function(i){r.next(n.call(t,i,s++))}))})}function Ke(n,t,e){return e===void 0&&(e=Ye),new B(function(r){var s=We(n)?+n-e.now():n;s<0&&(s=0);var i=0;return e.schedule(function(){r.closed||(r.next(i++),r.complete())},s)})}function Je(n,t,e){var r=E(n)||t||e?{next:n,error:t,complete:e}:n;return r?pe(function(s,i){var o;(o=r.subscribe)===null||o===void 0||o.call(r);var a=!0;s.subscribe(fe(i,function(c){var u;(u=r.next)===null||u===void 0||u.call(r,c),i.next(c)},function(){var c;a=!1,(c=r.complete)===null||c===void 0||c.call(r),i.complete()},function(c){var u;a=!1,(u=r.error)===null||u===void 0||u.call(r,c),i.error(c)},function(){var c,u;a&&((c=r.unsubscribe)===null||c===void 0||c.call(r)),(u=r.finalize)===null||u===void 0||u.call(r)}))}):he}var Xe=Object.defineProperty,Ze=(n,t,e)=>t in n?Xe(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,I=(n,t,e)=>Ze(n,typeof t!="symbol"?t+"":t,e);class d extends Error{constructor(t){super(`Incorrect context (${t}). Cannot perform the requested operation.`),I(this,"context"),this.context=t}}class R extends Error{constructor(t,e,r){super(`Invalid parameter (${t}). ${r}`),this.param=t,this.value=e,this.reason=r}}class et extends Error{constructor(t,e){super(`'streamId' value of "${t}" is different from what we expected ("${e}")`),this.streamId=t,this.expectedStreamId=e}}class tt extends Error{constructor(t){super(`Invalid version format: ${t}`)}}class be extends Error{constructor(t){super(`${t} needs to be initialized before it can be used.`)}}class me extends Error{constructor(t,e){let r=`Unsupported Protocol ${Array.isArray(t)?"versions":"version"}: (${t}).`;e&&(r+=` Minimum version supported is ${e}.`),super(r),this.version=t}}function M(n){return typeof n=="function"}function rt(n){return M(n==null?void 0:n.lift)}function A(n){return function(t){if(rt(t))return t.lift(function(e){try{return n(e,this)}catch(r){this.error(r)}});throw new TypeError("Unable to lift unknown Observable type")}}var z=function(n,t){return z=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,r){e.__proto__=r}||function(e,r){for(var s in r)Object.prototype.hasOwnProperty.call(r,s)&&(e[s]=r[s])},z(n,t)};function W(n,t){if(typeof t!="function"&&t!==null)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");z(n,t);function e(){this.constructor=n}n.prototype=t===null?Object.create(t):(e.prototype=t.prototype,new e)}function we(n){var t=typeof Symbol=="function"&&Symbol.iterator,e=t&&n[t],r=0;if(e)return e.call(n);if(n&&typeof n.length=="number")return{next:function(){return n&&r>=n.length&&(n=void 0),{value:n&&n[r++],done:!n}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function K(n,t){var e=typeof Symbol=="function"&&n[Symbol.iterator];if(!e)return n;var r=e.call(n),s,i=[],o;try{for(;(t===void 0||t-- >0)&&!(s=r.next()).done;)i.push(s.value)}catch(a){o={error:a}}finally{try{s&&!s.done&&(e=r.return)&&e.call(r)}finally{if(o)throw o.error}}return i}function J(n,t,e){if(arguments.length===2)for(var r=0,s=t.length,i;r<s;r++)(i||!(r in t))&&(i||(i=Array.prototype.slice.call(t,0,r)),i[r]=t[r]);return n.concat(i||Array.prototype.slice.call(t))}function nt(n){var t=function(r){Error.call(r),r.stack=new Error().stack},e=n(t);return e.prototype=Object.create(Error.prototype),e.prototype.constructor=e,e}var X=nt(function(n){return function(t){n(this),this.message=t?t.length+` errors occurred during unsubscription:
4
4
  `+t.map(function(e,r){return r+1+") "+e.toString()}).join(`
5
- `):"",this.name="UnsubscriptionError",this.errors=t}});function Se(n,t){if(n){var e=n.indexOf(t);0<=e&&n.splice(e,1)}}var Z=function(){function n(t){this.initialTeardown=t,this.closed=!1,this._parentage=null,this._finalizers=null}return n.prototype.unsubscribe=function(){var t,e,r,s,i;if(!this.closed){this.closed=!0;var o=this._parentage;if(o)if(this._parentage=null,Array.isArray(o))try{for(var a=we(o),c=a.next();!c.done;c=a.next()){var u=c.value;u.remove(this)}}catch(b){t={error:b}}finally{try{c&&!c.done&&(e=a.return)&&e.call(a)}finally{if(t)throw t.error}}else o.remove(this);var l=this.initialTeardown;if(M(l))try{l()}catch(b){i=b instanceof X?b.errors:[b]}var h=this._finalizers;if(h){this._finalizers=null;try{for(var m=we(h),y=m.next();!y.done;y=m.next()){var se=y.value;try{Me(se)}catch(b){i=i??[],b instanceof X?i=J(J([],K(i)),K(b.errors)):i.push(b)}}}catch(b){r={error:b}}finally{try{y&&!y.done&&(s=m.return)&&s.call(m)}finally{if(r)throw r.error}}}if(i)throw new X(i)}},n.prototype.add=function(t){var e;if(t&&t!==this)if(this.closed)Me(t);else{if(t instanceof n){if(t.closed||t._hasParent(this))return;t._addParent(this)}(this._finalizers=(e=this._finalizers)!==null&&e!==void 0?e:[]).push(t)}},n.prototype._hasParent=function(t){var e=this._parentage;return e===t||Array.isArray(e)&&e.includes(t)},n.prototype._addParent=function(t){var e=this._parentage;this._parentage=Array.isArray(e)?(e.push(t),e):e?[e,t]:t},n.prototype._removeParent=function(t){var e=this._parentage;e===t?this._parentage=null:Array.isArray(e)&&Se(e,t)},n.prototype.remove=function(t){var e=this._finalizers;e&&Se(e,t),t instanceof n&&t._removeParent(this)},n.EMPTY=function(){var t=new n;return t.closed=!0,t}(),n}();Z.EMPTY;function Ee(n){return n instanceof Z||n&&"closed"in n&&M(n.remove)&&M(n.add)&&M(n.unsubscribe)}function Me(n){M(n)?n():n.unsubscribe()}var Ce={onUnhandledError:null,onStoppedNotification:null,Promise:void 0,useDeprecatedSynchronousErrorHandling:!1,useDeprecatedNextContext:!1},st={setTimeout:function(n,t){for(var e=[],r=2;r<arguments.length;r++)e[r-2]=arguments[r];return setTimeout.apply(void 0,J([n,t],K(e)))},clearTimeout:function(n){return clearTimeout(n)},delegate:void 0};function it(n){st.setTimeout(function(){throw n})}function xe(){}function ot(n){n()}var ee=function(n){W(t,n);function t(e){var r=n.call(this)||this;return r.isStopped=!1,e?(r.destination=e,Ee(e)&&e.add(r)):r.destination=lt,r}return t.create=function(e,r,s){return new re(e,r,s)},t.prototype.next=function(e){this.isStopped||this._next(e)},t.prototype.error=function(e){this.isStopped||(this.isStopped=!0,this._error(e))},t.prototype.complete=function(){this.isStopped||(this.isStopped=!0,this._complete())},t.prototype.unsubscribe=function(){this.closed||(this.isStopped=!0,n.prototype.unsubscribe.call(this),this.destination=null)},t.prototype._next=function(e){this.destination.next(e)},t.prototype._error=function(e){try{this.destination.error(e)}finally{this.unsubscribe()}},t.prototype._complete=function(){try{this.destination.complete()}finally{this.unsubscribe()}},t}(Z),at=Function.prototype.bind;function te(n,t){return at.call(n,t)}var ct=function(){function n(t){this.partialObserver=t}return n.prototype.next=function(t){var e=this.partialObserver;if(e.next)try{e.next(t)}catch(r){N(r)}},n.prototype.error=function(t){var e=this.partialObserver;if(e.error)try{e.error(t)}catch(r){N(r)}else N(t)},n.prototype.complete=function(){var t=this.partialObserver;if(t.complete)try{t.complete()}catch(e){N(e)}},n}(),re=function(n){W(t,n);function t(e,r,s){var i=n.call(this)||this,o;if(M(e)||!e)o={next:e??void 0,error:r??void 0,complete:s??void 0};else{var a;i&&Ce.useDeprecatedNextContext?(a=Object.create(e),a.unsubscribe=function(){return i.unsubscribe()},o={next:e.next&&te(e.next,a),error:e.error&&te(e.error,a),complete:e.complete&&te(e.complete,a)}):o=e}return i.destination=new ct(o),i}return t}(ee);function N(n){it(n)}function ut(n){throw n}var lt={closed:!0,next:xe,error:ut,complete:xe},ht=function(){return typeof Symbol=="function"&&Symbol.observable||"@@observable"}();function Ie(n){return n}function dt(n){return n.length===0?Ie:n.length===1?n[0]:function(t){return n.reduce(function(e,r){return r(e)},t)}}var pt=function(){function n(t){t&&(this._subscribe=t)}return n.prototype.lift=function(t){var e=new n;return e.source=this,e.operator=t,e},n.prototype.subscribe=function(t,e,r){var s=this,i=gt(t)?t:new re(t,e,r);return ot(function(){var o=s,a=o.operator,c=o.source;i.add(a?a.call(i,c):c?s._subscribe(i):s._trySubscribe(i))}),i},n.prototype._trySubscribe=function(t){try{return this._subscribe(t)}catch(e){t.error(e)}},n.prototype.forEach=function(t,e){var r=this;return e=Te(e),new e(function(s,i){var o=new re({next:function(a){try{t(a)}catch(c){i(c),o.unsubscribe()}},error:i,complete:s});r.subscribe(o)})},n.prototype._subscribe=function(t){var e;return(e=this.source)===null||e===void 0?void 0:e.subscribe(t)},n.prototype[ht]=function(){return this},n.prototype.pipe=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return dt(t)(this)},n.prototype.toPromise=function(t){var e=this;return t=Te(t),new t(function(r,s){var i;e.subscribe(function(o){return i=o},function(o){return s(o)},function(){return r(i)})})},n.create=function(t){return new n(t)},n}();function Te(n){var t;return(t=n??Ce.Promise)!==null&&t!==void 0?t:Promise}function ft(n){return n&&M(n.next)&&M(n.error)&&M(n.complete)}function gt(n){return n&&n instanceof ee||ft(n)&&Ee(n)}function O(n,t,e,r,s){return new vt(n,t,e,r,s)}var vt=function(n){W(t,n);function t(e,r,s,i,o,a){var c=n.call(this,e)||this;return c.onFinalize=o,c.shouldUnsubscribe=a,c._next=r?function(u){try{r(u)}catch(l){e.error(l)}}:n.prototype._next,c._error=i?function(u){try{i(u)}catch(l){e.error(l)}finally{this.unsubscribe()}}:n.prototype._error,c._complete=s?function(){try{s()}catch(u){e.error(u)}finally{this.unsubscribe()}}:n.prototype._complete,c}return t.prototype.unsubscribe=function(){var e;if(!this.shouldUnsubscribe||this.shouldUnsubscribe()){var r=this.closed;n.prototype.unsubscribe.call(this),!r&&((e=this.onFinalize)===null||e===void 0||e.call(this))}},t}(ee);function p(n,t){return A(function(e,r){var s=0;e.subscribe(O(r,function(i){r.next(n.call(t,i,s++))}))})}var yt=new pt(function(n){return n.complete()});function w(n){return n<=0?function(){return yt}:A(function(t,e){var r=0;t.subscribe(O(e,function(s){++r<=n&&(e.next(s),n<=r&&e.complete())}))})}function g(n,t){return A(function(e,r){var s=0;e.subscribe(O(r,function(i){return n.call(t,i,s++)&&r.next(i)}))})}function bt(n,t){return A(function(e,r){var s=0;e.subscribe(O(r,function(i){var o=n(i,s++);(o||t)&&r.next(i),!o&&r.complete()}))})}function f(n,t,e){var r=M(n)||t||e?{next:n,error:t,complete:e}:n;return r?A(function(s,i){var o;(o=r.subscribe)===null||o===void 0||o.call(r);var a=!0;s.subscribe(O(i,function(c){var u;(u=r.next)===null||u===void 0||u.call(r,c),i.next(c)},function(){var c;a=!1,(c=r.complete)===null||c===void 0||c.call(r),i.complete()},function(c){var u;a=!1,(u=r.error)===null||u===void 0||u.call(r,c),i.error(c)},function(){var c,u;a&&((c=r.unsubscribe)===null||c===void 0||c.call(r)),(u=r.finalize)===null||u===void 0||u.call(r)}))}):Ie}const mt=/^(\d+)\.(\d+)$/;function wt(n){if(typeof n=="string"){const t=n.match(mt);if(t)return`${t[1]}.${t[2]}`}throw new tt(n)}function Re(n){const t=wt(n),[e,r]=t.split("."),[s,i]=[parseInt(e),parseInt(r)];return[s,i]}function ne(n,t){const[e,r]=Re(n),[s,i]=Re(t);return e<s?-1:e>s?1:r<i?-1:r>i?1:0}function St(n,t){return ne(n,t)===1}function Et(n,t){return ne(n,t)>=0}const Pe="2.0";class Mt{constructor(t,e){if(I(this,"negotiatedProtocolVersion"),I(this,"currentContext"),I(this,"incomingMessages$"),I(this,"inIframe",!1),I(this,"embeddedResult"),I(this,"iframePort1"),I(this,"iframePort2"),this.supportedVersions=t,this.logService=e,this.incomingMessages$=new ge,this.supportedVersions=t.filter(r=>Et(r,Pe)),!this.supportedVersions.length)throw new me(t,Pe);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 t,e;return this.inIframe?this.iframePort1:(e=(t=window.Acrobits)==null?void 0:t.messageChannel)==null?void 0:e.port1}get port2(){var t,e,r,s;if(this.inIframe){if(!this.iframePort2)throw new be("port2");return this.iframePort2}else{if(!((e=(t=window.Acrobits)==null?void 0:t.messageChannel)!=null&&e.port2))throw new be("port2");return(s=(r=window.Acrobits)==null?void 0:r.messageChannel)==null?void 0:s.port2}}determineContext(){return Ke(1e3).pipe(p(()=>(this.isEmbedded()?this.currentContext="user":this.currentContext="guest",this.currentContext)),w(1))}openBridge(){if(!this.isEmbedded())throw new d(this.currentContext);const t="HELLO",e=this.createMessage(t);e.protocolVersions=this.supportedVersions,this.logCreated(t,e);const r=this.incomingMessages$.pipe(g(s=>s.type===t&&s.replyTo===e.id),p(s=>s),f(this.logReceived()),p(s=>{if(this.supportedVersions.some(i=>St(i,s.protocolVersion)))throw new me(s.protocolVersion,this.supportedVersions[0]);return s}),f(s=>{this.negotiatedProtocolVersion=s.protocolVersion,this.logService.info(`[IPC] Negotiated IPC Protocol Version: ${this.negotiatedProtocolVersion}`)}),w(1));return this.logService.debug(`Created ${t} Reply handler`),this.inIframe?this.createIframeChannel().then(()=>this.finishIpcSetup(e)):this.finishIpcSetup(e),r}requestSSOToken(){if(!this.isEmbedded())throw new d(this.currentContext);const t="TOKEN",e=this.createMessage(t);this.logCreated(t,e);const r=this.incomingMessages$.pipe(g(s=>s.type===t&&s.replyTo===e.id),p(s=>s),f(this.logReceived()),w(1));return this.logService.debug(`Created ${t} Reply handler`),this.port2.postMessage(e),this.logSent(t,e),r}sendJoiningRoomMessage(t){if(!this.isEmbedded())throw new d(this.currentContext);const{roomName:e,roomInvite:r,displayName:s,jwtToken:i,serverUrl:o,region:a,joinMicMuted:c,joinWithoutCamera:u}=t,l="JOINING ROOM",h=this.createMessage(l,!1);h.roomName=e,h.jwtToken=i,h.serverUrl=o,h.region=a,h.roomInvite=r,h.joinMicMuted=c??!1,h.joinWithoutCamera=u??!1,h.displayName=s,this.logCreated(l,h),this.port2.postMessage(h),this.logSent(l,h)}sendLeavingRoomMessage(t){if(!this.isEmbedded())throw new d(this.currentContext);const e="LEAVING ROOM",r=this.createMessage(e,!1);r.roomName=t,this.logCreated(e,r),this.port2.postMessage(r),this.logSent(e,r)}onJoinRoomMessage(){if(!this.isEmbedded())throw new d(this.currentContext);const t="JOIN ROOM";return this.incomingMessages$.pipe(g(e=>e.type===t&&e.target==="client"),p(e=>e),f(this.logReceived()),p(e=>e))}onLeaveRoomMessage(){if(!this.isEmbedded())throw new d(this.currentContext);const t="LEAVE ROOM";return this.incomingMessages$.pipe(g(e=>e.type===t&&e.target==="client"),p(e=>e),f(this.logReceived()),p(e=>e))}onConfigMessage(){if(!this.isEmbedded())throw new d(this.currentContext);const t="CONFIG";return this.incomingMessages$.pipe(g(e=>e.type===t&&e.target==="client"),p(e=>e),f(this.logReceived()),p(e=>({preferredCameraType:e.preferredCameraType,preferredMicType:e.preferredMicType,preferredOutputType:e.preferredOutputType,preferredCameraDeviceLabel:e.preferredCameraDeviceLabel,preferredMicDeviceLabel:e.preferredMicDeviceLabel,preferredOutputDeviceLabel:e.preferredOutputDeviceLabel,performanceProfile:e.performanceProfile,cloudUsername:e.cloudUsername,configuredOAuthProviders:e.configuredOAuthProviders,locales:e.locales?[...e.locales]:[]})))}sendScreenshareSourceMessage(t){if(!this.isEmbedded())throw new d(this.currentContext);const e="SCREENSHARE SOURCE",r=this.createMessage(e);r.sourceTypes=t,this.logCreated(e,r);const s=this.incomingMessages$.pipe(g(i=>i.type===e&&i.replyTo===r.id),p(i=>i),f(this.logReceived()),p(i=>i),w(1));return this.logService.debug(`Created ${e} Reply handler`),this.port2.postMessage(r),this.logSent(e,r),s}layoutChange(t,e,r){if(!this.isEmbedded())throw new d(this.currentContext);const s="LAYOUT CHANGE";let i,o;if(e&&r?(i=this.createMessage(s,!1,r),i.result=e):(i=this.createMessage(s),o=this.incomingMessages$.pipe(g(a=>a.type===s&&a.replyTo===i.id),p(a=>a),f(this.logReceived()),p(a=>a),w(1)),this.logService.debug(`Created ${s} Reply handler`)),i.layout=t,this.logCreated(s,i),this.port2.postMessage(i),this.logSent(s,i),o)return o}onLayoutChangeMessage(){if(!this.isEmbedded())throw new d(this.currentContext);const t="LAYOUT CHANGE";return this.incomingMessages$.pipe(g(e=>e.type===t&&e.target==="client"&&e.replyTo===null),p(e=>e),f(this.logReceived()),p(e=>e))}requestOAuthToken(t){if(!this.isEmbedded())throw new d(this.currentContext);Array.isArray(t)||(t=[t]);const e="OAUTH TOKEN",r=this.createMessage(e);r.providerTypes=t,this.logCreated(e,r);const s=this.incomingMessages$.pipe(g(i=>i.type===e&&i.replyTo===r.id),p(i=>i),f(this.logReceived()),w(1));return this.logService.debug(`Created ${e} Reply handler`),this.port2.postMessage(r),this.logSent(e,r),s}openUrl(t,e){if(!this.isEmbedded())throw new d(this.currentContext);const r="OPEN URL",s=this.createMessage(r,!1);s.url=t,s.data=e,this.logCreated(r,s),this.port2.postMessage(s),this.logSent(r,s)}selectContacts(t,e,r,s){if(!this.isEmbedded())throw new d(this.currentContext);if(e==="group"&&s===void 0)throw new T("currentContacts",s,"currentContacts is required for group streams");if(e==="direct"&&s!==void 0)throw new T("currentContacts",s,"currentContacts should not be passed for direct streams");const i="SELECT CONTACTS",o=this.createMessage(i,!0);o.streamType=e,o.streamId=t,o.contactType=r,o.currentContacts=s,this.logCreated(i,o);const a=this.incomingMessages$.pipe(g(c=>c.type===i&&c.replyTo===o.id),f(this.logReceived()),p(c=>{const u=c;if(u.result==="success"){if(u.streamId!==t)throw new et(u.streamId,t);e==="direct"&&u.contacts.length>1&&(u.contacts=[u.contacts[0]])}return u}),w(1));return this.logService.debug(`Created ${i} Reply handler`),this.port2.postMessage(o),this.logSent(i,o),a}matchContacts(t){if(!this.isEmbedded())throw new d(this.currentContext);if(!t.length)throw new T("contacts",t,"At least one contact is required");const e="MATCH CONTACTS",r=this.createMessage(e);r.contacts=[...t],this.logCreated(e,r);const s=this.incomingMessages$.pipe(g(i=>i.type===e&&i.replyTo===r.id),f(this.logReceived()),p(i=>i),w(1));return this.logService.debug(`Created ${e} Reply handler`),this.port2.postMessage(r),this.logSent(e,r),s}onPushMessageMessage(){if(!this.isEmbedded())throw new d(this.currentContext);const t="PUSH MESSAGE";return this.incomingMessages$.pipe(g(e=>e.type===t&&e.target==="client"),p(e=>e),f(this.logReceived()))}requestPushToken(){if(!this.isEmbedded())throw new d(this.currentContext);const t="PUSH TOKEN",e=this.createMessage(t);this.logCreated(t,e);const r=this.incomingMessages$.pipe(g(s=>s.type===t&&s.replyTo===e.id),f(this.logReceived()),p(s=>s),w(1));return this.logService.debug(`Created ${t} Reply handler`),this.port2.postMessage(e),this.logSent(t,e),r}onPushTokenMessage(){if(!this.isEmbedded())throw new d(this.currentContext);const t="PUSH TOKEN";return this.incomingMessages$.pipe(g(e=>e.type===t&&e.target==="client"&&e.replyTo===null&&e.expectReply===!1),p(e=>{if(e.pushToken&&e.selector&&e.appId)return e;throw new Error("PushTokenMessage is missing required PushTokenPayload fields")}),f(e=>e.pushToken),f(this.logReceived()))}onBadgeQueryMessage(){if(!this.isEmbedded())throw new d(this.currentContext);const t="BADGE QUERY";return this.incomingMessages$.pipe(g(e=>e.type===t&&e.target==="client"),p(e=>e),f(this.logReceived()))}sendBadgeUpdateMessage(t,e,r){if(!this.isEmbedded())throw new d(this.currentContext);const s="BADGE UPDATE",i=this.createMessage(s,!1,r);i.count=t,i.activity=e??!1,this.logCreated(s,i),this.port2.postMessage(i),this.logSent(s,i)}sendLifecycleMessage(t,e){if(!this.isEmbedded())throw new d(this.currentContext);const r="LIFECYCLE",s=this.createMessage(r,!1);s.eventName=t,s.payload=e,this.logCreated(r,s),this.port2.postMessage(s),this.logSent(r,s)}onLifecycleMessage(){if(!this.isEmbedded())throw new d(this.currentContext);const t="LIFECYCLE";return this.incomingMessages$.pipe(g(e=>e.type===t&&e.target==="client"),p(e=>e),f(this.logReceived()))}sendLogMessage(t,e){if(!this.isEmbedded())throw new d(this.currentContext);const r="LOG",s=this.createMessage(r,!1);s.level=t,s.message=e,this.logCreated(r,s),this.port2.postMessage(s),this.logSent(r,s)}onRequestLogsMessage(){if(!this.isEmbedded())throw new d(this.currentContext);const t="REQUEST LOGS";return this.incomingMessages$.pipe(g(e=>e.type===t&&e.target==="client"),p(e=>e),f(this.logReceived()))}sendRequestLogsMessageReply(t,e,r,s,i){if(!this.isEmbedded())throw new d(this.currentContext);const o="REQUEST LOGS",a=this.createMessage(o,!1,i);a.fileId=t,a.fileHash=e,a.fileSize=r,a.format=s,this.logCreated(o,a),this.port2.postMessage(a),this.logSent(o,a)}sendViewTransitionMessage(t,e){if(!this.isEmbedded())throw new d(this.currentContext);const r="VIEW TRANSITION",s=this.createMessage(r,!1);s.transitionType=t,s.targetView=e,this.logCreated(r,s),this.port2.postMessage(s),this.logSent(r,s)}sendFileRequestMessage(t,e,r,s,i){if(!this.isEmbedded())throw new d(this.currentContext);const o="FILE REQUEST",a=this.createMessage(o);if(a.fileId=t,a.fileHash=e.toLowerCase(),a.intent=r,a.maxChunkSizeInBytes=i,r==="attachment"){if(!s)throw new T("streamId",s,"streamId is required for attachment intent");a.streamId=s}this.logCreated(o,a);let c=0;const u=this.incomingMessages$.pipe(g(l=>l.type===o&&l.replyTo===a.id),f(this.logReceived()),f(()=>c++),p(l=>(l.result==="success"&&(l.chunkHash=l.chunkHash.toLowerCase(),l.fileHash=l.fileHash.toLowerCase()),l)),bt(l=>l.result==="success"&&c<l.totalChunks,!0));return this.port2.postMessage(a),this.logSent(o,a),u}sendFileRequestMessageReply(t,e){if(!this.isEmbedded())throw new d(this.currentContext);const r="FILE REQUEST",s=Object.assign(e,this.createMessage(r,!1,t.id));this.logCreated(r,s),this.port2.postMessage(s),this.logSent(r,s)}onFileRequestMessage(){if(!this.isEmbedded())throw new d(this.currentContext);const t="FILE REQUEST";return this.incomingMessages$.pipe(g(e=>e.type===t&&e.target==="client"&&e.replyTo===null),p(e=>(e.fileHash=e.fileHash.toLowerCase(),e)),f(this.logReceived()))}sendFileSelectionMessage(t="attachment",e,r,s,i,o){if(!this.isEmbedded())throw new d(this.currentContext);const a="FILE SELECTION",c=this.createMessage(a);if(c.intent=t,c.maxCount=s,c.maxFileSizeInBytes=i,c.mimeTypes=o,t==="attachment"){if(!e)throw new T("streamId",e,"streamId is required for attachment intent");if(!r)throw new T("correlationId",r,"correlationId is required for attachment intent");c.streamId=e,c.correlationId=r}this.logCreated(a,c);const u=this.incomingMessages$.pipe(g(l=>l.type===a&&l.replyTo===c.id),p(l=>{var h;return l.result==="success"&&(l.files=(h=l.files)==null?void 0:h.map(m=>(m.original.fileHash=m.original.fileHash.toLowerCase(),m.preview&&(m.preview.fileHash=m.preview.fileHash.toLowerCase()),m))),l}),f(this.logReceived()),w(1));return this.port2.postMessage(c),this.logSent(a,c),u}sendFileDownloadProgressQueryMessage(t,e,r){if(!this.isEmbedded())throw new d(this.currentContext);const s="FILE DOWNLOAD PROGRESS QUERY",i=this.createMessage(s,!0);i.fileHash=t.toLowerCase(),i.url=e,i.correlationId=r,this.logCreated(s,i);const o=this.incomingMessages$.pipe(g(a=>a.type==="FILE DOWNLOAD PROGRESS UPDATE"&&a.replyTo===i.id),f(a=>this.logReceived(a)),p(a=>(a.fileHash&&(a.fileHash=a.fileHash.toLowerCase()),a)),w(1));return this.port2.postMessage(i),this.logSent(s,i),o}onFileDownloadProgressUpdateMessage(){if(!this.isEmbedded())throw new d(this.currentContext);const t="FILE DOWNLOAD PROGRESS UPDATE";return this.incomingMessages$.pipe(g(e=>e.type===t&&e.target==="client"&&e.replyTo===null),p(e=>(e.fileHash&&(e.fileHash=e.fileHash.toLowerCase()),e)),f(this.logReceived()))}sendFileUploadProgressQueryMessage(t,e,r){if(!this.isEmbedded())throw new d(this.currentContext);const s="FILE UPLOAD PROGRESS QUERY",i=this.createMessage(s,!0);i.fileHash=t.toLowerCase(),i.fileId=e,i.correlationId=r,this.logCreated(s,i);const o=this.incomingMessages$.pipe(g(a=>a.type==="FILE UPLOAD PROGRESS UPDATE"&&a.replyTo===i.id),f(this.logReceived()),p(a=>(a.fileHash&&(a.fileHash=a.fileHash.toLowerCase()),a)),w(1));return this.port2.postMessage(i),this.logSent(s,i),o}onFileUploadProgressUpdateMessage(){if(!this.isEmbedded())throw new d(this.currentContext);const t="FILE UPLOAD PROGRESS UPDATE";return this.incomingMessages$.pipe(g(e=>e.type===t&&e.target==="client"&&e.replyTo===null),p(e=>(e.fileHash&&(e.fileHash=e.fileHash.toLowerCase()),e)),f(this.logReceived()))}sendFileDownloadMessage(t,e,r,s,i,o,a,c,u){if(!this.isEmbedded())throw new d(this.currentContext);const l="FILE DOWNLOAD",h=this.createMessage(l,!0);h.url=t,h.key=e,h.fileHash=r.toLowerCase(),h.mimeType=s,h.fileName=i,h.streamId=o,h.correlationId=a,h.sender=c,h.intent=u??"download",this.logCreated(l,h);const m=this.incomingMessages$.pipe(g(y=>y.type===l&&y.replyTo===h.id),f(this.logReceived()),p(y=>y),w(1));return this.port2.postMessage(h),this.logSent(l,h),m}sendCancelFileDownloadMessage(t,e,r){if(!this.isEmbedded())throw new d(this.currentContext);const s="CANCEL FILE DOWNLOAD",i=this.createMessage(s,!1);i.fileHash=t.toLowerCase(),i.url=e,i.correlationId=r,this.logCreated(s,i),this.port2.postMessage(i),this.logSent(s,i)}sendFileRemoveMessage(t,e){if(!this.isEmbedded())throw new d(this.currentContext);const r="FILE REMOVE",s=this.createMessage(r,!0);s.hash=t.toLowerCase(),s.streamId=e,this.logCreated(r,s);const i=this.incomingMessages$.pipe(g(o=>o.type===r&&o.replyTo===s.id),f(this.logReceived()),p(o=>o),w(1));return this.port2.postMessage(s),this.logSent(r,s),i}sendAppResetMessage(){if(!this.isEmbedded())throw new d(this.currentContext);const t="APP RESET",e=this.createMessage(t,!1);this.logCreated(t,e),this.port2.postMessage(e),this.logSent(t,e)}sendMessageSentMessage(t,e){if(!this.isEmbedded())throw new d(this.currentContext);const r="MESSAGE SENT",s=this.createMessage(r,!1);s.streamId=t,s.correlationId=e,this.logCreated(r,s),this.port2.postMessage(s),this.logSent(r,s)}sendSendMessageMessage(t,e,r,s="TEXT",i,o,a,c=!0,u){if(!this.isEmbedded())throw new d(this.currentContext);const l="SEND MESSAGE",h=this.createMessage(l,!0);h.streamId=t,h.correlationId=e,h.body=r,h.messageType=s,h.mentions=i??[],h.attachments=(o==null?void 0:o.map(y=>y.toLowerCase()))??[],h.relatedMessageId=a,h.setCursors=c,h.threadId=u,this.logCreated(l,h);const m=this.incomingMessages$.pipe(g(y=>y.type===l&&y.replyTo===h.id),f(this.logReceived()),p(y=>y),w(1));return this.port2.postMessage(h),this.logSent(l,h),m}sendCancelSendMessageMessage(t,e){if(!this.isEmbedded())throw new d(this.currentContext);const r="CANCEL SEND MESSAGE",s=this.createMessage(r,!1);s.streamId=t,s.correlationId=e,this.logCreated(r,s),this.port2.postMessage(s),this.logSent(r,s)}sendMessageDeletedMessage(t,e){if(!this.isEmbedded())throw new d(this.currentContext);const r="MESSAGE DELETED",s=this.createMessage(r,!1);s.correlationId=t,s.streamId=e,this.logCreated(r,s),this.port2.postMessage(s),this.logSent(r,s)}sendSendMessageStatusQueryMessage(t,e){if(!this.isEmbedded())throw new d(this.currentContext);const r="SEND MESSAGE STATUS QUERY",s=this.createMessage(r,!0);s.correlationId=t,s.streamId=e,this.logCreated(r,s);const i=this.incomingMessages$.pipe(g(o=>o.type==="SEND MESSAGE STATUS UPDATE"&&o.replyTo===s.id),f(this.logReceived()),p(o=>o),w(1));return this.port2.postMessage(s),this.logSent(r,s),i}onSendMessageStatusUpdateMessage(){if(!this.isEmbedded())throw new d(this.currentContext);const t="SEND MESSAGE STATUS UPDATE";return this.incomingMessages$.pipe(g(e=>e.type===t&&e.target==="client"&&e.replyTo===null),p(e=>e),f(this.logReceived()))}sendSipCallMessage(t){if(!this.isEmbedded())throw new d(this.currentContext);const e="SIP CALL",r=this.createMessage(e,!1);r.contact=t,this.logCreated(e,r),this.port2.postMessage(r),this.logSent(e,r)}isEmbedded(){if(this.embeddedResult!==null)return this.embeddedResult;let t=!1;return this.logService.debug("Checking if running in iframe..."),t=!!this.frameElement,t||(t=this.self!==this.parent),t?(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..."),!t&&(t=!!window.Acrobits,t)?(this.logService.debug("In native app"),this.embeddedResult=!0,t):(this.logService.debug("Not running in native app"),this.embeddedResult=!1,this.embeddedResult))}compareVersion(t){return ne(this.negotiatedProtocolVersion,t)}logReceived(t){const e=r=>this.logService.debug(`[IPC] Received ${r.type} message${r.replyTo?" reply":""}`,r);if(t){Ct(t)&&(t={...t,data:"..."}),e(t);return}else return e}logSent(t,e){e.type==="FILE REQUEST"&&e.result==="success"&&(e={...e,data:"..."}),this.logService.debug(`[IPC] Sent ${t} message`,e)}logCreated(t,e){e.type==="FILE REQUEST"&&e.result==="success"&&(e={...e,data:"..."}),this.logService.debug(`[IPC] Created ${t} message`,e)}async createIframeChannel(){return new Promise(t=>{const e=r=>{r.data==="message channel port"&&(this.iframePort2=r.ports[0],this.self.removeEventListener("message",e),t())};this.self.addEventListener("message",e),this.parent.postMessage("get channel","*")})}finishIpcSetup(t){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(t),this.logSent("HELLO",t)}handleIpcMessage(t){const{data:e}=t;!e.id||e.target!=="client"||this.incomingMessages$.next(e)}createMessage(t,e=!0,r){return{type:t,id:this.generateId(),target:"host",expectReply:e,replyTo:r??null}}generateId(t=8,e=!1){let r="1234567890qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM";const s=[];e&&(r=r.substr(0,r.indexOf("Q")));for(let i=0;i<t;i++)s.push(r[Math.floor(Math.random()*r.length)]);return s.join("")}}function Ct(n){return n.type==="FILE REQUEST"&&n.replyTo!==null}const xt=["2.0"];class It{constructor(t){R(this,"host");R(this,"cloudId");R(this,"cloudUsername");R(this,"logger");R(this,"helper");R(this,"listeners");this.logger=t??console,this.helper=new Mt(xt,this.logger),this.listeners=new Map,this.listeners.set(v.BadgeQuery,new Set),this.listeners.set(v.Lifecycle,new Set),this.listeners.set(v.PushToken,new Set)}get context(){return this.evaluateContext(this.helper.currentContext)}get isConnected(){return!!(this.helper.currentContext==="user"&&this.host&&this.cloudId)}get negotiatedVersion(){return this.helper.negotiatedProtocolVersion}async determineContext(){const t=await _(this.helper.determineContext(),{defaultValue:"guest"});return this.evaluateContext(t)}initiateConnection(){return _(this.helper.openBridge().pipe(Je(t=>{this.helper.onBadgeQueryMessage().subscribe(e=>{var r;this.logger.debug("Received Badge Query: ",e);for(const s of((r=this.listeners.get(v.BadgeQuery))==null?void 0:r.values())??[])s()}),this.helper.onLifecycleMessage().subscribe(e=>{var r;this.logger.debug("Received Lifecycle Event: ",e);for(const s of((r=this.listeners.get(v.Lifecycle))==null?void 0:r.values())??[])s(e.eventName,e.payload)}),this.helper.onPushTokenMessage().subscribe(e=>{var r;this.logger.debug("Received Push Token: ",e);for(const s of((r=this.listeners.get(v.PushToken))==null?void 0:r.values())??[])s(e.pushToken,e.appId,e.selector)}),this.cloudId=t.cloudId,this.cloudUsername=t.cloudUsername,this.host=t.host}),k(()=>{})))}selectContacts(t,e,r,s){this.logger.debug("Selecting Contacts: ",...arguments);let i;if(e==="multi"){if(!r||!Array.isArray(r))throw new T("currentContacts",r,"currentContacts is required for group streams");s||(s="cloudUsername"),i=this.helper.selectContacts(t.toString(),"group",s,r)}else r?s=r:s="cloudUsername",i=this.helper.selectContacts(t.toString(),"direct",s);return _(i.pipe(k(o=>o.result==="error"?{result:"error",errorMessage:o.errorMessage}:o.result==="cancelled"?{result:"cancelled"}:o.contacts)))}matchContacts(t){return this.logger.debug("Match Contacts: ",t),_(this.helper.matchContacts(t).pipe(k(e=>e.contacts)))}requestPushToken(){return this.logger.debug("Requesting Push Token"),_(this.helper.requestPushToken().pipe(k(t=>t.pushToken)))}badgeUpdate(t,e=!1){this.logger.debug(`Sending Badge Update, count: ${t}, activity: ${e}`),this.helper.sendBadgeUpdateMessage(t,e)}requestAppReset(){this.logger.debug("Requesting App Reset"),this.helper.sendAppResetMessage()}openUrl(t,e){this.logger.debug("Opening URL: ",t),this.helper.openUrl(t,e)}sipCall(t){this.logger.debug("Initiating SIP Call: ",t),this.helper.sendSipCallMessage(t)}onBadgeQueryRequest(t){var e;return this.logger.debug("Registering for Badge Query"),(e=this.listeners.get(v.BadgeQuery))==null||e.add(t),()=>{var r;return(r=this.listeners.get(v.BadgeQuery))==null?void 0:r.delete(t)}}onLifecycleEvent(t){var e;return this.logger.debug("Registering for Lifecycle Event"),(e=this.listeners.get(v.Lifecycle))==null||e.add(t),()=>{var r;return(r=this.listeners.get(v.Lifecycle))==null?void 0:r.delete(t)}}onPushToken(t){var e;return this.logger.debug("Registering for Push Token"),(e=this.listeners.get(v.PushToken))==null||e.add(t),()=>{var r;return(r=this.listeners.get(v.PushToken))==null?void 0:r.delete(t)}}evaluateContext(t){if(t==="user")return"host";if(t==="guest")return"standalone"}}S.IPCEvents=v,S.IPCManager=It,Object.defineProperty(S,Symbol.toStringTag,{value:"Module"})});
5
+ `):"",this.name="UnsubscriptionError",this.errors=t}});function Se(n,t){if(n){var e=n.indexOf(t);0<=e&&n.splice(e,1)}}var Z=function(){function n(t){this.initialTeardown=t,this.closed=!1,this._parentage=null,this._finalizers=null}return n.prototype.unsubscribe=function(){var t,e,r,s,i;if(!this.closed){this.closed=!0;var o=this._parentage;if(o)if(this._parentage=null,Array.isArray(o))try{for(var a=we(o),c=a.next();!c.done;c=a.next()){var u=c.value;u.remove(this)}}catch(b){t={error:b}}finally{try{c&&!c.done&&(e=a.return)&&e.call(a)}finally{if(t)throw t.error}}else o.remove(this);var l=this.initialTeardown;if(M(l))try{l()}catch(b){i=b instanceof X?b.errors:[b]}var h=this._finalizers;if(h){this._finalizers=null;try{for(var m=we(h),y=m.next();!y.done;y=m.next()){var se=y.value;try{Me(se)}catch(b){i=i??[],b instanceof X?i=J(J([],K(i)),K(b.errors)):i.push(b)}}}catch(b){r={error:b}}finally{try{y&&!y.done&&(s=m.return)&&s.call(m)}finally{if(r)throw r.error}}}if(i)throw new X(i)}},n.prototype.add=function(t){var e;if(t&&t!==this)if(this.closed)Me(t);else{if(t instanceof n){if(t.closed||t._hasParent(this))return;t._addParent(this)}(this._finalizers=(e=this._finalizers)!==null&&e!==void 0?e:[]).push(t)}},n.prototype._hasParent=function(t){var e=this._parentage;return e===t||Array.isArray(e)&&e.includes(t)},n.prototype._addParent=function(t){var e=this._parentage;this._parentage=Array.isArray(e)?(e.push(t),e):e?[e,t]:t},n.prototype._removeParent=function(t){var e=this._parentage;e===t?this._parentage=null:Array.isArray(e)&&Se(e,t)},n.prototype.remove=function(t){var e=this._finalizers;e&&Se(e,t),t instanceof n&&t._removeParent(this)},n.EMPTY=function(){var t=new n;return t.closed=!0,t}(),n}();Z.EMPTY;function Ee(n){return n instanceof Z||n&&"closed"in n&&M(n.remove)&&M(n.add)&&M(n.unsubscribe)}function Me(n){M(n)?n():n.unsubscribe()}var Ce={onUnhandledError:null,onStoppedNotification:null,Promise:void 0,useDeprecatedSynchronousErrorHandling:!1,useDeprecatedNextContext:!1},st={setTimeout:function(n,t){for(var e=[],r=2;r<arguments.length;r++)e[r-2]=arguments[r];return setTimeout.apply(void 0,J([n,t],K(e)))},clearTimeout:function(n){return clearTimeout(n)},delegate:void 0};function it(n){st.setTimeout(function(){throw n})}function xe(){}function ot(n){n()}var ee=function(n){W(t,n);function t(e){var r=n.call(this)||this;return r.isStopped=!1,e?(r.destination=e,Ee(e)&&e.add(r)):r.destination=lt,r}return t.create=function(e,r,s){return new re(e,r,s)},t.prototype.next=function(e){this.isStopped||this._next(e)},t.prototype.error=function(e){this.isStopped||(this.isStopped=!0,this._error(e))},t.prototype.complete=function(){this.isStopped||(this.isStopped=!0,this._complete())},t.prototype.unsubscribe=function(){this.closed||(this.isStopped=!0,n.prototype.unsubscribe.call(this),this.destination=null)},t.prototype._next=function(e){this.destination.next(e)},t.prototype._error=function(e){try{this.destination.error(e)}finally{this.unsubscribe()}},t.prototype._complete=function(){try{this.destination.complete()}finally{this.unsubscribe()}},t}(Z),at=Function.prototype.bind;function te(n,t){return at.call(n,t)}var ct=function(){function n(t){this.partialObserver=t}return n.prototype.next=function(t){var e=this.partialObserver;if(e.next)try{e.next(t)}catch(r){k(r)}},n.prototype.error=function(t){var e=this.partialObserver;if(e.error)try{e.error(t)}catch(r){k(r)}else k(t)},n.prototype.complete=function(){var t=this.partialObserver;if(t.complete)try{t.complete()}catch(e){k(e)}},n}(),re=function(n){W(t,n);function t(e,r,s){var i=n.call(this)||this,o;if(M(e)||!e)o={next:e??void 0,error:r??void 0,complete:s??void 0};else{var a;i&&Ce.useDeprecatedNextContext?(a=Object.create(e),a.unsubscribe=function(){return i.unsubscribe()},o={next:e.next&&te(e.next,a),error:e.error&&te(e.error,a),complete:e.complete&&te(e.complete,a)}):o=e}return i.destination=new ct(o),i}return t}(ee);function k(n){it(n)}function ut(n){throw n}var lt={closed:!0,next:xe,error:ut,complete:xe},ht=function(){return typeof Symbol=="function"&&Symbol.observable||"@@observable"}();function Ie(n){return n}function dt(n){return n.length===0?Ie:n.length===1?n[0]:function(t){return n.reduce(function(e,r){return r(e)},t)}}var pt=function(){function n(t){t&&(this._subscribe=t)}return n.prototype.lift=function(t){var e=new n;return e.source=this,e.operator=t,e},n.prototype.subscribe=function(t,e,r){var s=this,i=gt(t)?t:new re(t,e,r);return ot(function(){var o=s,a=o.operator,c=o.source;i.add(a?a.call(i,c):c?s._subscribe(i):s._trySubscribe(i))}),i},n.prototype._trySubscribe=function(t){try{return this._subscribe(t)}catch(e){t.error(e)}},n.prototype.forEach=function(t,e){var r=this;return e=Te(e),new e(function(s,i){var o=new re({next:function(a){try{t(a)}catch(c){i(c),o.unsubscribe()}},error:i,complete:s});r.subscribe(o)})},n.prototype._subscribe=function(t){var e;return(e=this.source)===null||e===void 0?void 0:e.subscribe(t)},n.prototype[ht]=function(){return this},n.prototype.pipe=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return dt(t)(this)},n.prototype.toPromise=function(t){var e=this;return t=Te(t),new t(function(r,s){var i;e.subscribe(function(o){return i=o},function(o){return s(o)},function(){return r(i)})})},n.create=function(t){return new n(t)},n}();function Te(n){var t;return(t=n??Ce.Promise)!==null&&t!==void 0?t:Promise}function ft(n){return n&&M(n.next)&&M(n.error)&&M(n.complete)}function gt(n){return n&&n instanceof ee||ft(n)&&Ee(n)}function O(n,t,e,r,s){return new vt(n,t,e,r,s)}var vt=function(n){W(t,n);function t(e,r,s,i,o,a){var c=n.call(this,e)||this;return c.onFinalize=o,c.shouldUnsubscribe=a,c._next=r?function(u){try{r(u)}catch(l){e.error(l)}}:n.prototype._next,c._error=i?function(u){try{i(u)}catch(l){e.error(l)}finally{this.unsubscribe()}}:n.prototype._error,c._complete=s?function(){try{s()}catch(u){e.error(u)}finally{this.unsubscribe()}}:n.prototype._complete,c}return t.prototype.unsubscribe=function(){var e;if(!this.shouldUnsubscribe||this.shouldUnsubscribe()){var r=this.closed;n.prototype.unsubscribe.call(this),!r&&((e=this.onFinalize)===null||e===void 0||e.call(this))}},t}(ee);function p(n,t){return A(function(e,r){var s=0;e.subscribe(O(r,function(i){r.next(n.call(t,i,s++))}))})}var yt=new pt(function(n){return n.complete()});function w(n){return n<=0?function(){return yt}:A(function(t,e){var r=0;t.subscribe(O(e,function(s){++r<=n&&(e.next(s),n<=r&&e.complete())}))})}function g(n,t){return A(function(e,r){var s=0;e.subscribe(O(r,function(i){return n.call(t,i,s++)&&r.next(i)}))})}function bt(n,t){return A(function(e,r){var s=0;e.subscribe(O(r,function(i){var o=n(i,s++);(o||t)&&r.next(i),!o&&r.complete()}))})}function f(n,t,e){var r=M(n)||t||e?{next:n,error:t,complete:e}:n;return r?A(function(s,i){var o;(o=r.subscribe)===null||o===void 0||o.call(r);var a=!0;s.subscribe(O(i,function(c){var u;(u=r.next)===null||u===void 0||u.call(r,c),i.next(c)},function(){var c;a=!1,(c=r.complete)===null||c===void 0||c.call(r),i.complete()},function(c){var u;a=!1,(u=r.error)===null||u===void 0||u.call(r,c),i.error(c)},function(){var c,u;a&&((c=r.unsubscribe)===null||c===void 0||c.call(r)),(u=r.finalize)===null||u===void 0||u.call(r)}))}):Ie}const mt=/^(\d+)\.(\d+)$/;function wt(n){if(typeof n=="string"){const t=n.match(mt);if(t)return`${t[1]}.${t[2]}`}throw new tt(n)}function Re(n){const t=wt(n),[e,r]=t.split("."),[s,i]=[parseInt(e),parseInt(r)];return[s,i]}function ne(n,t){const[e,r]=Re(n),[s,i]=Re(t);return e<s?-1:e>s?1:r<i?-1:r>i?1:0}function St(n,t){return ne(n,t)===1}function Et(n,t){return ne(n,t)>=0}const Pe="2.0";class Mt{constructor(t,e){if(I(this,"negotiatedProtocolVersion"),I(this,"currentContext"),I(this,"incomingMessages$"),I(this,"inIframe",!1),I(this,"embeddedResult"),I(this,"iframePort1"),I(this,"iframePort2"),this.supportedVersions=t,this.logService=e,this.incomingMessages$=new ge,this.supportedVersions=t.filter(r=>Et(r,Pe)),!this.supportedVersions.length)throw new me(t,Pe);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 t,e;return this.inIframe?this.iframePort1:(e=(t=window.Acrobits)==null?void 0:t.messageChannel)==null?void 0:e.port1}get port2(){var t,e,r,s;if(this.inIframe){if(!this.iframePort2)throw new be("port2");return this.iframePort2}else{if(!((e=(t=window.Acrobits)==null?void 0:t.messageChannel)!=null&&e.port2))throw new be("port2");return(s=(r=window.Acrobits)==null?void 0:r.messageChannel)==null?void 0:s.port2}}determineContext(){return Ke(1e3).pipe(p(()=>(this.isEmbedded()?this.currentContext="user":this.currentContext="guest",this.currentContext)),w(1))}openBridge(){if(!this.isEmbedded())throw new d(this.currentContext);const t="HELLO",e=this.createMessage(t);e.protocolVersions=this.supportedVersions,this.logCreated(t,e);const r=this.incomingMessages$.pipe(g(s=>s.type===t&&s.replyTo===e.id),p(s=>s),f(this.logReceived()),p(s=>{if(this.supportedVersions.some(i=>St(i,s.protocolVersion)))throw new me(s.protocolVersion,this.supportedVersions[0]);return s.displayName||(s.displayName=s.cloudUsername),s}),f(s=>{this.negotiatedProtocolVersion=s.protocolVersion,this.logService.info(`[IPC] Negotiated IPC Protocol Version: ${this.negotiatedProtocolVersion}`)}),w(1));return this.logService.debug(`Created ${t} Reply handler`),this.inIframe?this.createIframeChannel().then(()=>this.finishIpcSetup(e)):this.finishIpcSetup(e),r}requestSSOToken(){if(!this.isEmbedded())throw new d(this.currentContext);const t="TOKEN",e=this.createMessage(t);this.logCreated(t,e);const r=this.incomingMessages$.pipe(g(s=>s.type===t&&s.replyTo===e.id),p(s=>s),f(this.logReceived()),w(1));return this.logService.debug(`Created ${t} Reply handler`),this.port2.postMessage(e),this.logSent(t,e),r}sendJoiningRoomMessage(t){if(!this.isEmbedded())throw new d(this.currentContext);const{roomName:e,roomInvite:r,displayName:s,jwtToken:i,serverUrl:o,region:a,joinMicMuted:c,joinWithoutCamera:u}=t,l="JOINING ROOM",h=this.createMessage(l,!1);h.roomName=e,h.jwtToken=i,h.serverUrl=o,h.region=a,h.roomInvite=r,h.joinMicMuted=c??!1,h.joinWithoutCamera=u??!1,h.displayName=s,this.logCreated(l,h),this.port2.postMessage(h),this.logSent(l,h)}sendLeavingRoomMessage(t){if(!this.isEmbedded())throw new d(this.currentContext);const e="LEAVING ROOM",r=this.createMessage(e,!1);r.roomName=t,this.logCreated(e,r),this.port2.postMessage(r),this.logSent(e,r)}onJoinRoomMessage(){if(!this.isEmbedded())throw new d(this.currentContext);const t="JOIN ROOM";return this.incomingMessages$.pipe(g(e=>e.type===t&&e.target==="client"),p(e=>e),f(this.logReceived()),p(e=>e))}onLeaveRoomMessage(){if(!this.isEmbedded())throw new d(this.currentContext);const t="LEAVE ROOM";return this.incomingMessages$.pipe(g(e=>e.type===t&&e.target==="client"),p(e=>e),f(this.logReceived()),p(e=>e))}onConfigMessage(){if(!this.isEmbedded())throw new d(this.currentContext);const t="CONFIG";return this.incomingMessages$.pipe(g(e=>e.type===t&&e.target==="client"),p(e=>e),f(this.logReceived()),p(e=>({preferredCameraType:e.preferredCameraType,preferredMicType:e.preferredMicType,preferredOutputType:e.preferredOutputType,preferredCameraDeviceLabel:e.preferredCameraDeviceLabel,preferredMicDeviceLabel:e.preferredMicDeviceLabel,preferredOutputDeviceLabel:e.preferredOutputDeviceLabel,performanceProfile:e.performanceProfile,cloudUsername:e.cloudUsername,configuredOAuthProviders:e.configuredOAuthProviders,locales:e.locales?[...e.locales]:[]})))}sendScreenshareSourceMessage(t){if(!this.isEmbedded())throw new d(this.currentContext);const e="SCREENSHARE SOURCE",r=this.createMessage(e);r.sourceTypes=t,this.logCreated(e,r);const s=this.incomingMessages$.pipe(g(i=>i.type===e&&i.replyTo===r.id),p(i=>i),f(this.logReceived()),p(i=>i),w(1));return this.logService.debug(`Created ${e} Reply handler`),this.port2.postMessage(r),this.logSent(e,r),s}layoutChange(t,e,r){if(!this.isEmbedded())throw new d(this.currentContext);const s="LAYOUT CHANGE";let i,o;if(e&&r?(i=this.createMessage(s,!1,r),i.result=e):(i=this.createMessage(s),o=this.incomingMessages$.pipe(g(a=>a.type===s&&a.replyTo===i.id),p(a=>a),f(this.logReceived()),p(a=>a),w(1)),this.logService.debug(`Created ${s} Reply handler`)),i.layout=t,this.logCreated(s,i),this.port2.postMessage(i),this.logSent(s,i),o)return o}onLayoutChangeMessage(){if(!this.isEmbedded())throw new d(this.currentContext);const t="LAYOUT CHANGE";return this.incomingMessages$.pipe(g(e=>e.type===t&&e.target==="client"&&e.replyTo===null),p(e=>e),f(this.logReceived()),p(e=>e))}requestOAuthToken(t){if(!this.isEmbedded())throw new d(this.currentContext);Array.isArray(t)||(t=[t]);const e="OAUTH TOKEN",r=this.createMessage(e);r.providerTypes=t,this.logCreated(e,r);const s=this.incomingMessages$.pipe(g(i=>i.type===e&&i.replyTo===r.id),p(i=>i),f(this.logReceived()),w(1));return this.logService.debug(`Created ${e} Reply handler`),this.port2.postMessage(r),this.logSent(e,r),s}openUrl(t,e){if(!this.isEmbedded())throw new d(this.currentContext);const r="OPEN URL",s=this.createMessage(r,!1);s.url=t,s.data=e,this.logCreated(r,s),this.port2.postMessage(s),this.logSent(r,s)}selectContacts(t,e,r,s){if(!this.isEmbedded())throw new d(this.currentContext);if(e==="group"&&s===void 0)throw new R("currentContacts",s,"currentContacts is required for group streams");if(e==="direct"&&s!==void 0)throw new R("currentContacts",s,"currentContacts should not be passed for direct streams");const i="SELECT CONTACTS",o=this.createMessage(i,!0);o.streamType=e,o.streamId=t,o.contactType=r,o.currentContacts=s,this.logCreated(i,o);const a=this.incomingMessages$.pipe(g(c=>c.type===i&&c.replyTo===o.id),f(this.logReceived()),p(c=>{const u=c;if(u.result==="success"){if(u.streamId!==t)throw new et(u.streamId,t);e==="direct"&&u.contacts.length>1&&(u.contacts=[u.contacts[0]])}return u}),w(1));return this.logService.debug(`Created ${i} Reply handler`),this.port2.postMessage(o),this.logSent(i,o),a}matchContacts(t){if(!this.isEmbedded())throw new d(this.currentContext);if(!t.length)throw new R("contacts",t,"At least one contact is required");const e="MATCH CONTACTS",r=this.createMessage(e);r.contacts=[...t],this.logCreated(e,r);const s=this.incomingMessages$.pipe(g(i=>i.type===e&&i.replyTo===r.id),f(this.logReceived()),p(i=>i),w(1));return this.logService.debug(`Created ${e} Reply handler`),this.port2.postMessage(r),this.logSent(e,r),s}onPushMessageMessage(){if(!this.isEmbedded())throw new d(this.currentContext);const t="PUSH MESSAGE";return this.incomingMessages$.pipe(g(e=>e.type===t&&e.target==="client"),p(e=>e),f(this.logReceived()))}requestPushToken(){if(!this.isEmbedded())throw new d(this.currentContext);const t="PUSH TOKEN",e=this.createMessage(t);this.logCreated(t,e);const r=this.incomingMessages$.pipe(g(s=>s.type===t&&s.replyTo===e.id),f(this.logReceived()),p(s=>s),w(1));return this.logService.debug(`Created ${t} Reply handler`),this.port2.postMessage(e),this.logSent(t,e),r}onPushTokenMessage(){if(!this.isEmbedded())throw new d(this.currentContext);const t="PUSH TOKEN";return this.incomingMessages$.pipe(g(e=>e.type===t&&e.target==="client"&&e.replyTo===null&&e.expectReply===!1),p(e=>{if(e.pushToken&&e.selector&&e.appId)return e;throw new Error("PushTokenMessage is missing required PushTokenPayload fields")}),f(e=>e.pushToken),f(this.logReceived()))}onBadgeQueryMessage(){if(!this.isEmbedded())throw new d(this.currentContext);const t="BADGE QUERY";return this.incomingMessages$.pipe(g(e=>e.type===t&&e.target==="client"),p(e=>e),f(this.logReceived()))}sendBadgeUpdateMessage(t,e,r){if(!this.isEmbedded())throw new d(this.currentContext);const s="BADGE UPDATE",i=this.createMessage(s,!1,r);i.count=t,i.activity=e??!1,this.logCreated(s,i),this.port2.postMessage(i),this.logSent(s,i)}sendLifecycleMessage(t,e){if(!this.isEmbedded())throw new d(this.currentContext);const r="LIFECYCLE",s=this.createMessage(r,!1);s.eventName=t,s.payload=e,this.logCreated(r,s),this.port2.postMessage(s),this.logSent(r,s)}onLifecycleMessage(){if(!this.isEmbedded())throw new d(this.currentContext);const t="LIFECYCLE";return this.incomingMessages$.pipe(g(e=>e.type===t&&e.target==="client"),p(e=>e),f(this.logReceived()))}sendLogMessage(t,e){if(!this.isEmbedded())throw new d(this.currentContext);const r="LOG",s=this.createMessage(r,!1);s.level=t,s.message=e,this.logCreated(r,s),this.port2.postMessage(s),this.logSent(r,s)}onRequestLogsMessage(){if(!this.isEmbedded())throw new d(this.currentContext);const t="REQUEST LOGS";return this.incomingMessages$.pipe(g(e=>e.type===t&&e.target==="client"),p(e=>e),f(this.logReceived()))}sendRequestLogsMessageReply(t,e,r,s,i){if(!this.isEmbedded())throw new d(this.currentContext);const o="REQUEST LOGS",a=this.createMessage(o,!1,i);a.fileId=t,a.fileHash=e,a.fileSize=r,a.format=s,this.logCreated(o,a),this.port2.postMessage(a),this.logSent(o,a)}sendViewTransitionMessage(t,e){if(!this.isEmbedded())throw new d(this.currentContext);const r="VIEW TRANSITION",s=this.createMessage(r,!1);s.transitionType=t,s.targetView=e,this.logCreated(r,s),this.port2.postMessage(s),this.logSent(r,s)}sendFileRequestMessage(t,e,r,s,i){if(!this.isEmbedded())throw new d(this.currentContext);const o="FILE REQUEST",a=this.createMessage(o);if(a.fileId=t,a.fileHash=e.toLowerCase(),a.intent=r,a.maxChunkSizeInBytes=i,r==="attachment"){if(!s)throw new R("streamId",s,"streamId is required for attachment intent");a.streamId=s}this.logCreated(o,a);let c=0;const u=this.incomingMessages$.pipe(g(l=>l.type===o&&l.replyTo===a.id),f(this.logReceived()),f(()=>c++),p(l=>(l.result==="success"&&(l.chunkHash=l.chunkHash.toLowerCase(),l.fileHash=l.fileHash.toLowerCase()),l)),bt(l=>l.result==="success"&&c<l.totalChunks,!0));return this.port2.postMessage(a),this.logSent(o,a),u}sendFileRequestMessageReply(t,e){if(!this.isEmbedded())throw new d(this.currentContext);const r="FILE REQUEST",s=Object.assign(e,this.createMessage(r,!1,t.id));this.logCreated(r,s),this.port2.postMessage(s),this.logSent(r,s)}onFileRequestMessage(){if(!this.isEmbedded())throw new d(this.currentContext);const t="FILE REQUEST";return this.incomingMessages$.pipe(g(e=>e.type===t&&e.target==="client"&&e.replyTo===null),p(e=>(e.fileHash=e.fileHash.toLowerCase(),e)),f(this.logReceived()))}sendFileSelectionMessage(t="attachment",e,r,s,i,o){if(!this.isEmbedded())throw new d(this.currentContext);const a="FILE SELECTION",c=this.createMessage(a);if(c.intent=t,c.maxCount=s,c.maxFileSizeInBytes=i,c.mimeTypes=o,t==="attachment"){if(!e)throw new R("streamId",e,"streamId is required for attachment intent");if(!r)throw new R("correlationId",r,"correlationId is required for attachment intent");c.streamId=e,c.correlationId=r}this.logCreated(a,c);const u=this.incomingMessages$.pipe(g(l=>l.type===a&&l.replyTo===c.id),p(l=>{var h;return l.result==="success"&&(l.files=(h=l.files)==null?void 0:h.map(m=>(m.original.fileHash=m.original.fileHash.toLowerCase(),m.preview&&(m.preview.fileHash=m.preview.fileHash.toLowerCase()),m))),l}),f(this.logReceived()),w(1));return this.port2.postMessage(c),this.logSent(a,c),u}sendFileDownloadProgressQueryMessage(t,e,r){if(!this.isEmbedded())throw new d(this.currentContext);const s="FILE DOWNLOAD PROGRESS QUERY",i=this.createMessage(s,!0);i.fileHash=t.toLowerCase(),i.url=e,i.correlationId=r,this.logCreated(s,i);const o=this.incomingMessages$.pipe(g(a=>a.type==="FILE DOWNLOAD PROGRESS UPDATE"&&a.replyTo===i.id),f(a=>this.logReceived(a)),p(a=>(a.fileHash&&(a.fileHash=a.fileHash.toLowerCase()),a)),w(1));return this.port2.postMessage(i),this.logSent(s,i),o}onFileDownloadProgressUpdateMessage(){if(!this.isEmbedded())throw new d(this.currentContext);const t="FILE DOWNLOAD PROGRESS UPDATE";return this.incomingMessages$.pipe(g(e=>e.type===t&&e.target==="client"&&e.replyTo===null),p(e=>(e.fileHash&&(e.fileHash=e.fileHash.toLowerCase()),e)),f(this.logReceived()))}sendFileUploadProgressQueryMessage(t,e,r){if(!this.isEmbedded())throw new d(this.currentContext);const s="FILE UPLOAD PROGRESS QUERY",i=this.createMessage(s,!0);i.fileHash=t.toLowerCase(),i.fileId=e,i.correlationId=r,this.logCreated(s,i);const o=this.incomingMessages$.pipe(g(a=>a.type==="FILE UPLOAD PROGRESS UPDATE"&&a.replyTo===i.id),f(this.logReceived()),p(a=>(a.fileHash&&(a.fileHash=a.fileHash.toLowerCase()),a)),w(1));return this.port2.postMessage(i),this.logSent(s,i),o}onFileUploadProgressUpdateMessage(){if(!this.isEmbedded())throw new d(this.currentContext);const t="FILE UPLOAD PROGRESS UPDATE";return this.incomingMessages$.pipe(g(e=>e.type===t&&e.target==="client"&&e.replyTo===null),p(e=>(e.fileHash&&(e.fileHash=e.fileHash.toLowerCase()),e)),f(this.logReceived()))}sendFileDownloadMessage(t,e,r,s,i,o,a,c,u){if(!this.isEmbedded())throw new d(this.currentContext);const l="FILE DOWNLOAD",h=this.createMessage(l,!0);h.url=t,h.key=e,h.fileHash=r.toLowerCase(),h.mimeType=s,h.fileName=i,h.streamId=o,h.correlationId=a,h.sender=c,h.intent=u??"download",this.logCreated(l,h);const m=this.incomingMessages$.pipe(g(y=>y.type===l&&y.replyTo===h.id),f(this.logReceived()),p(y=>y),w(1));return this.port2.postMessage(h),this.logSent(l,h),m}sendCancelFileDownloadMessage(t,e,r){if(!this.isEmbedded())throw new d(this.currentContext);const s="CANCEL FILE DOWNLOAD",i=this.createMessage(s,!1);i.fileHash=t.toLowerCase(),i.url=e,i.correlationId=r,this.logCreated(s,i),this.port2.postMessage(i),this.logSent(s,i)}sendFileRemoveMessage(t,e){if(!this.isEmbedded())throw new d(this.currentContext);const r="FILE REMOVE",s=this.createMessage(r,!0);s.hash=t.toLowerCase(),s.streamId=e,this.logCreated(r,s);const i=this.incomingMessages$.pipe(g(o=>o.type===r&&o.replyTo===s.id),f(this.logReceived()),p(o=>o),w(1));return this.port2.postMessage(s),this.logSent(r,s),i}sendAppResetMessage(){if(!this.isEmbedded())throw new d(this.currentContext);const t="APP RESET",e=this.createMessage(t,!1);this.logCreated(t,e),this.port2.postMessage(e),this.logSent(t,e)}sendMessageSentMessage(t,e){if(!this.isEmbedded())throw new d(this.currentContext);const r="MESSAGE SENT",s=this.createMessage(r,!1);s.streamId=t,s.correlationId=e,this.logCreated(r,s),this.port2.postMessage(s),this.logSent(r,s)}sendSendMessageMessage(t,e,r,s="TEXT",i,o,a,c=!0,u){if(!this.isEmbedded())throw new d(this.currentContext);const l="SEND MESSAGE",h=this.createMessage(l,!0);h.streamId=t,h.correlationId=e,h.body=r,h.messageType=s,h.mentions=i??[],h.attachments=(o==null?void 0:o.map(y=>y.toLowerCase()))??[],h.relatedMessageId=a,h.setCursors=c,h.threadId=u,this.logCreated(l,h);const m=this.incomingMessages$.pipe(g(y=>y.type===l&&y.replyTo===h.id),f(this.logReceived()),p(y=>y),w(1));return this.port2.postMessage(h),this.logSent(l,h),m}sendCancelSendMessageMessage(t,e){if(!this.isEmbedded())throw new d(this.currentContext);const r="CANCEL SEND MESSAGE",s=this.createMessage(r,!1);s.streamId=t,s.correlationId=e,this.logCreated(r,s),this.port2.postMessage(s),this.logSent(r,s)}sendMessageDeletedMessage(t,e){if(!this.isEmbedded())throw new d(this.currentContext);const r="MESSAGE DELETED",s=this.createMessage(r,!1);s.correlationId=t,s.streamId=e,this.logCreated(r,s),this.port2.postMessage(s),this.logSent(r,s)}sendSendMessageStatusQueryMessage(t,e){if(!this.isEmbedded())throw new d(this.currentContext);const r="SEND MESSAGE STATUS QUERY",s=this.createMessage(r,!0);s.correlationId=t,s.streamId=e,this.logCreated(r,s);const i=this.incomingMessages$.pipe(g(o=>o.type==="SEND MESSAGE STATUS UPDATE"&&o.replyTo===s.id),f(this.logReceived()),p(o=>o),w(1));return this.port2.postMessage(s),this.logSent(r,s),i}onSendMessageStatusUpdateMessage(){if(!this.isEmbedded())throw new d(this.currentContext);const t="SEND MESSAGE STATUS UPDATE";return this.incomingMessages$.pipe(g(e=>e.type===t&&e.target==="client"&&e.replyTo===null),p(e=>e),f(this.logReceived()))}sendSipCallMessage(t){if(!this.isEmbedded())throw new d(this.currentContext);const e="SIP CALL",r=this.createMessage(e,!1);r.contact=t,this.logCreated(e,r),this.port2.postMessage(r),this.logSent(e,r)}isEmbedded(){if(this.embeddedResult!==null)return this.embeddedResult;let t=!1;return this.logService.debug("Checking if running in iframe..."),t=!!this.frameElement,t||(t=this.self!==this.parent),t?(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..."),!t&&(t=!!window.Acrobits,t)?(this.logService.debug("In native app"),this.embeddedResult=!0,t):(this.logService.debug("Not running in native app"),this.embeddedResult=!1,this.embeddedResult))}compareVersion(t){return ne(this.negotiatedProtocolVersion,t)}logReceived(t){const e=r=>this.logService.debug(`[IPC] Received ${r.type} message${r.replyTo?" reply":""}`,r);if(t){Ct(t)&&(t={...t,data:"..."}),e(t);return}else return e}logSent(t,e){e.type==="FILE REQUEST"&&e.result==="success"&&(e={...e,data:"..."}),this.logService.debug(`[IPC] Sent ${t} message`,e)}logCreated(t,e){e.type==="FILE REQUEST"&&e.result==="success"&&(e={...e,data:"..."}),this.logService.debug(`[IPC] Created ${t} message`,e)}async createIframeChannel(){return new Promise(t=>{const e=r=>{r.data==="message channel port"&&(this.iframePort2=r.ports[0],this.self.removeEventListener("message",e),t())};this.self.addEventListener("message",e),this.parent.postMessage("get channel","*")})}finishIpcSetup(t){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(t),this.logSent("HELLO",t)}handleIpcMessage(t){const{data:e}=t;!e.id||e.target!=="client"||this.incomingMessages$.next(e)}createMessage(t,e=!0,r){return{type:t,id:this.generateId(),target:"host",expectReply:e,replyTo:r??null}}generateId(t=8,e=!1){let r="1234567890qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM";const s=[];e&&(r=r.substr(0,r.indexOf("Q")));for(let i=0;i<t;i++)s.push(r[Math.floor(Math.random()*r.length)]);return s.join("")}}function Ct(n){return n.type==="FILE REQUEST"&&n.replyTo!==null}const xt=["2.0"];class It{constructor(t){T(this,"host");T(this,"cloudId");T(this,"cloudUsername");T(this,"displayName");T(this,"logger");T(this,"helper");T(this,"listeners");this.logger=t??console,this.helper=new Mt(xt,this.logger),this.listeners=new Map,this.listeners.set(v.BadgeQuery,new Set),this.listeners.set(v.Lifecycle,new Set),this.listeners.set(v.PushToken,new Set)}get context(){return this.evaluateContext(this.helper.currentContext)}get isConnected(){return!!(this.helper.currentContext==="user"&&this.host&&this.cloudId)}get negotiatedVersion(){return this.helper.negotiatedProtocolVersion}async determineContext(){const t=await _(this.helper.determineContext(),{defaultValue:"guest"});return this.evaluateContext(t)}initiateConnection(){return _(this.helper.openBridge().pipe(Je(t=>{this.helper.onBadgeQueryMessage().subscribe(e=>{var r;this.logger.debug("Received Badge Query: ",e);for(const s of((r=this.listeners.get(v.BadgeQuery))==null?void 0:r.values())??[])s()}),this.helper.onLifecycleMessage().subscribe(e=>{var r;this.logger.debug("Received Lifecycle Event: ",e);for(const s of((r=this.listeners.get(v.Lifecycle))==null?void 0:r.values())??[])s(e.eventName,e.payload)}),this.helper.onPushTokenMessage().subscribe(e=>{var r;this.logger.debug("Received Push Token: ",e);for(const s of((r=this.listeners.get(v.PushToken))==null?void 0:r.values())??[])s(e.pushToken,e.appId,e.selector)}),this.cloudId=t.cloudId,this.cloudUsername=t.cloudUsername,this.displayName=t.displayName,this.host=t.host}),N(()=>{})))}selectContacts(t,e,r,s){this.logger.debug("Selecting Contacts: ",...arguments);let i;if(e==="multi"){if(!r||!Array.isArray(r))throw new R("currentContacts",r,"currentContacts is required for group streams");s||(s="cloudUsername"),i=this.helper.selectContacts(t.toString(),"group",s,r)}else r?s=r:s="cloudUsername",i=this.helper.selectContacts(t.toString(),"direct",s);return _(i.pipe(N(o=>o.result==="error"?{result:"error",errorMessage:o.errorMessage}:o.result==="cancelled"?{result:"cancelled"}:o.contacts)))}matchContacts(t){return this.logger.debug("Match Contacts: ",t),_(this.helper.matchContacts(t).pipe(N(e=>e.contacts)))}requestPushToken(){return this.logger.debug("Requesting Push Token"),_(this.helper.requestPushToken().pipe(N(t=>t.pushToken)))}badgeUpdate(t,e=!1){this.logger.debug(`Sending Badge Update, count: ${t}, activity: ${e}`),this.helper.sendBadgeUpdateMessage(t,e)}requestAppReset(){this.logger.debug("Requesting App Reset"),this.helper.sendAppResetMessage()}openUrl(t,e){this.logger.debug("Opening URL: ",t),this.helper.openUrl(t,e)}sipCall(t){this.logger.debug("Initiating SIP Call: ",t),this.helper.sendSipCallMessage(t)}onBadgeQueryRequest(t){var e;return this.logger.debug("Registering for Badge Query"),(e=this.listeners.get(v.BadgeQuery))==null||e.add(t),()=>{var r;return(r=this.listeners.get(v.BadgeQuery))==null?void 0:r.delete(t)}}onLifecycleEvent(t){var e;return this.logger.debug("Registering for Lifecycle Event"),(e=this.listeners.get(v.Lifecycle))==null||e.add(t),()=>{var r;return(r=this.listeners.get(v.Lifecycle))==null?void 0:r.delete(t)}}onPushToken(t){var e;return this.logger.debug("Registering for Push Token"),(e=this.listeners.get(v.PushToken))==null||e.add(t),()=>{var r;return(r=this.listeners.get(v.PushToken))==null?void 0:r.delete(t)}}evaluateContext(t){if(t==="user")return"host";if(t==="guest")return"standalone"}}S.IPCEvents=v,S.IPCManager=It,Object.defineProperty(S,Symbol.toStringTag,{value:"Module"})});