@acrobits/ipc-sdk 0.11.2-alpha.4 → 0.11.2-alpha.6

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(C,y){typeof exports=="object"&&typeof module<"u"?y(exports):typeof define=="function"&&define.amd?define(["exports"],y):(C=typeof globalThis<"u"?globalThis:C||self,y(C["@acrobits/ipc-sdk"]={}))})(this,function(C){"use strict";var Tt=Object.defineProperty;var xt=(C,y,I)=>y in C?Tt(C,y,{enumerable:!0,configurable:!0,writable:!0,value:I}):C[y]=I;var x=(C,y,I)=>(xt(C,typeof y!="symbol"?y+"":y,I),I);var y=(s=>(s.BadgeQuery="BADGE QUERY",s.Lifecycle="LIFECYCLE",s.PushToken="PUSH TOKEN",s.RequestLogs="REQUEST LOGS",s))(y||{}),I=function(s,t){return I=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,r){e.__proto__=r}||function(e,r){for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])},I(s,t)};function U(s,t){if(typeof t!="function"&&t!==null)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");I(s,t);function e(){this.constructor=s}s.prototype=t===null?Object.create(t):(e.prototype=t.prototype,new e)}function H(s){var t=typeof Symbol=="function"&&Symbol.iterator,e=t&&s[t],r=0;if(e)return e.call(s);if(s&&typeof s.length=="number")return{next:function(){return s&&r>=s.length&&(s=void 0),{value:s&&s[r++],done:!s}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function L(s,t){var e=typeof Symbol=="function"&&s[Symbol.iterator];if(!e)return s;var r=e.call(s),n,i=[],o;try{for(;(t===void 0||t-- >0)&&!(n=r.next()).done;)i.push(n.value)}catch(c){o={error:c}}finally{try{n&&!n.done&&(e=r.return)&&e.call(r)}finally{if(o)throw o.error}}return i}function O(s,t,e){if(e||arguments.length===2)for(var r=0,n=t.length,i;r<n;r++)(i||!(r in t))&&(i||(i=Array.prototype.slice.call(t,0,r)),i[r]=t[r]);return s.concat(i||Array.prototype.slice.call(t))}typeof SuppressedError=="function"&&SuppressedError;function E(s){return typeof s=="function"}function j(s){var t=function(r){Error.call(r),r.stack=new Error().stack},e=s(t);return e.prototype=Object.create(Error.prototype),e.prototype.constructor=e,e}var q=j(function(s){return function(e){s(this),this.message=e?e.length+` errors occurred during unsubscription:
2
- `+e.map(function(r,n){return n+1+") "+r.toString()}).join(`
3
- `):"",this.name="UnsubscriptionError",this.errors=e}});function $(s,t){if(s){var e=s.indexOf(t);0<=e&&s.splice(e,1)}}var R=function(){function s(t){this.initialTeardown=t,this.closed=!1,this._parentage=null,this._finalizers=null}return s.prototype.unsubscribe=function(){var t,e,r,n,i;if(!this.closed){this.closed=!0;var o=this._parentage;if(o)if(this._parentage=null,Array.isArray(o))try{for(var c=H(o),a=c.next();!a.done;a=c.next()){var u=a.value;u.remove(this)}}catch(b){t={error:b}}finally{try{a&&!a.done&&(e=c.return)&&e.call(c)}finally{if(t)throw t.error}}else o.remove(this);var h=this.initialTeardown;if(E(h))try{h()}catch(b){i=b instanceof q?b.errors:[b]}var l=this._finalizers;if(l){this._finalizers=null;try{for(var w=H(l),p=w.next();!p.done;p=w.next()){var se=p.value;try{oe(se)}catch(b){i=i??[],b instanceof q?i=O(O([],L(i)),L(b.errors)):i.push(b)}}}catch(b){r={error:b}}finally{try{p&&!p.done&&(n=w.return)&&n.call(w)}finally{if(r)throw r.error}}}if(i)throw new q(i)}},s.prototype.add=function(t){var e;if(t&&t!==this)if(this.closed)oe(t);else{if(t instanceof s){if(t.closed||t._hasParent(this))return;t._addParent(this)}(this._finalizers=(e=this._finalizers)!==null&&e!==void 0?e:[]).push(t)}},s.prototype._hasParent=function(t){var e=this._parentage;return e===t||Array.isArray(e)&&e.includes(t)},s.prototype._addParent=function(t){var e=this._parentage;this._parentage=Array.isArray(e)?(e.push(t),e):e?[e,t]:t},s.prototype._removeParent=function(t){var e=this._parentage;e===t?this._parentage=null:Array.isArray(e)&&$(e,t)},s.prototype.remove=function(t){var e=this._finalizers;e&&$(e,t),t instanceof s&&t._removeParent(this)},s.EMPTY=function(){var t=new s;return t.closed=!0,t}(),s}(),ne=R.EMPTY;function ie(s){return s instanceof R||s&&"closed"in s&&E(s.remove)&&E(s.add)&&E(s.unsubscribe)}function oe(s){E(s)?s():s.unsubscribe()}var ce={onUnhandledError:null,onStoppedNotification:null,Promise:void 0,useDeprecatedSynchronousErrorHandling:!1,useDeprecatedNextContext:!1},ae={setTimeout:function(s,t){for(var e=[],r=2;r<arguments.length;r++)e[r-2]=arguments[r];return setTimeout.apply(void 0,O([s,t],L(e)))},clearTimeout:function(s){var t=ae.delegate;return((t==null?void 0:t.clearTimeout)||clearTimeout)(s)},delegate:void 0};function Ae(s){ae.setTimeout(function(){throw s})}function ue(){}function k(s){s()}var B=function(s){U(t,s);function t(e){var r=s.call(this)||this;return r.isStopped=!1,e?(r.destination=e,ie(e)&&e.add(r)):r.destination=$e,r}return t.create=function(e,r,n){return new D(e,r,n)},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,s.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}(R),_e=Function.prototype.bind;function Q(s,t){return _e.call(s,t)}var Le=function(){function s(t){this.partialObserver=t}return s.prototype.next=function(t){var e=this.partialObserver;if(e.next)try{e.next(t)}catch(r){N(r)}},s.prototype.error=function(t){var e=this.partialObserver;if(e.error)try{e.error(t)}catch(r){N(r)}else N(t)},s.prototype.complete=function(){var t=this.partialObserver;if(t.complete)try{t.complete()}catch(e){N(e)}},s}(),D=function(s){U(t,s);function t(e,r,n){var i=s.call(this)||this,o;if(E(e)||!e)o={next:e??void 0,error:r??void 0,complete:n??void 0};else{var c;i&&ce.useDeprecatedNextContext?(c=Object.create(e),c.unsubscribe=function(){return i.unsubscribe()},o={next:e.next&&Q(e.next,c),error:e.error&&Q(e.error,c),complete:e.complete&&Q(e.complete,c)}):o=e}return i.destination=new Le(o),i}return t}(B);function N(s){Ae(s)}function Oe(s){throw s}var $e={closed:!0,next:ue,error:Oe,complete:ue},ke=function(){return typeof Symbol=="function"&&Symbol.observable||"@@observable"}();function le(s){return s}function De(s){return s.length===0?le:s.length===1?s[0]:function(e){return s.reduce(function(r,n){return n(r)},e)}}var G=function(){function s(t){t&&(this._subscribe=t)}return s.prototype.lift=function(t){var e=new s;return e.source=this,e.operator=t,e},s.prototype.subscribe=function(t,e,r){var n=this,i=Fe(t)?t:new D(t,e,r);return k(function(){var o=n,c=o.operator,a=o.source;i.add(c?c.call(i,a):a?n._subscribe(i):n._trySubscribe(i))}),i},s.prototype._trySubscribe=function(t){try{return this._subscribe(t)}catch(e){t.error(e)}},s.prototype.forEach=function(t,e){var r=this;return e=he(e),new e(function(n,i){var o=new D({next:function(c){try{t(c)}catch(a){i(a),o.unsubscribe()}},error:i,complete:n});r.subscribe(o)})},s.prototype._subscribe=function(t){var e;return(e=this.source)===null||e===void 0?void 0:e.subscribe(t)},s.prototype[ke]=function(){return this},s.prototype.pipe=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return De(t)(this)},s.prototype.toPromise=function(t){var e=this;return t=he(t),new t(function(r,n){var i;e.subscribe(function(o){return i=o},function(o){return n(o)},function(){return r(i)})})},s.create=function(t){return new s(t)},s}();function he(s){var t;return(t=s??ce.Promise)!==null&&t!==void 0?t:Promise}function Ne(s){return s&&E(s.next)&&E(s.error)&&E(s.complete)}function Fe(s){return s&&s instanceof B||Ne(s)&&ie(s)}function Ve(s){return E(s==null?void 0:s.lift)}function de(s){return function(t){if(Ve(t))return t.lift(function(e){try{return s(e,this)}catch(r){this.error(r)}});throw new TypeError("Unable to lift unknown Observable type")}}function pe(s,t,e,r,n){return new He(s,t,e,r,n)}var He=function(s){U(t,s);function t(e,r,n,i,o,c){var a=s.call(this,e)||this;return a.onFinalize=o,a.shouldUnsubscribe=c,a._next=r?function(u){try{r(u)}catch(h){e.error(h)}}:s.prototype._next,a._error=i?function(u){try{i(u)}catch(h){e.error(h)}finally{this.unsubscribe()}}:s.prototype._error,a._complete=n?function(){try{n()}catch(u){e.error(u)}finally{this.unsubscribe()}}:s.prototype._complete,a}return t.prototype.unsubscribe=function(){var e;if(!this.shouldUnsubscribe||this.shouldUnsubscribe()){var r=this.closed;s.prototype.unsubscribe.call(this),!r&&((e=this.onFinalize)===null||e===void 0||e.call(this))}},t}(B),je=j(function(s){return function(){s(this),this.name="ObjectUnsubscribedError",this.message="object unsubscribed"}}),fe=function(s){U(t,s);function t(){var e=s.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 ge(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;k(function(){var n,i;if(r._throwIfClosed(),!r.isStopped){r.currentObservers||(r.currentObservers=Array.from(r.observers));try{for(var o=H(r.currentObservers),c=o.next();!c.done;c=o.next()){var a=c.value;a.next(e)}}catch(u){n={error:u}}finally{try{c&&!c.done&&(i=o.return)&&i.call(o)}finally{if(n)throw n.error}}}})},t.prototype.error=function(e){var r=this;k(function(){if(r._throwIfClosed(),!r.isStopped){r.hasError=r.isStopped=!0,r.thrownError=e;for(var n=r.observers;n.length;)n.shift().error(e)}})},t.prototype.complete=function(){var e=this;k(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(),s.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,n=this,i=n.hasError,o=n.isStopped,c=n.observers;return i||o?ne:(this.currentObservers=null,c.push(e),new R(function(){r.currentObservers=null,$(c,e)}))},t.prototype._checkFinalizedStatuses=function(e){var r=this,n=r.hasError,i=r.thrownError,o=r.isStopped;n?e.error(i):o&&e.complete()},t.prototype.asObservable=function(){var e=new G;return e.source=this,e},t.create=function(e,r){return new ge(e,r)},t}(G),ge=function(s){U(t,s);function t(e,r){var n=s.call(this)||this;return n.destination=e,n.source=r,n}return t.prototype.next=function(e){var r,n;(n=(r=this.destination)===null||r===void 0?void 0:r.next)===null||n===void 0||n.call(r,e)},t.prototype.error=function(e){var r,n;(n=(r=this.destination)===null||r===void 0?void 0:r.error)===null||n===void 0||n.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,n;return(n=(r=this.source)===null||r===void 0?void 0:r.subscribe(e))!==null&&n!==void 0?n:ne},t}(fe),qe={now:function(){return Date.now()},delegate:void 0},Be=function(s){U(t,s);function t(e,r){return s.call(this)||this}return t.prototype.schedule=function(e,r){return this},t}(R),Y={setInterval:function(s,t){for(var e=[],r=2;r<arguments.length;r++)e[r-2]=arguments[r];return setInterval.apply(void 0,O([s,t],L(e)))},clearInterval:function(s){var t=Y.delegate;return((t==null?void 0:t.clearInterval)||clearInterval)(s)},delegate:void 0},Qe=function(s){U(t,s);function t(e,r){var n=s.call(this,e,r)||this;return n.scheduler=e,n.work=r,n.pending=!1,n}return t.prototype.schedule=function(e,r){var n;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=(n=this.id)!==null&&n!==void 0?n:this.requestAsyncId(o,this.id,r),this},t.prototype.requestAsyncId=function(e,r,n){return n===void 0&&(n=0),Y.setInterval(e.flush.bind(e,this),n)},t.prototype.recycleAsyncId=function(e,r,n){if(n===void 0&&(n=0),n!=null&&this.delay===n&&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 n=this._execute(e,r);if(n)return n;this.pending===!1&&this.id!=null&&(this.id=this.recycleAsyncId(this.scheduler,this.id,null))},t.prototype._execute=function(e,r){var n=!1,i;try{this.work(e)}catch(o){n=!0,i=o||new Error("Scheduled action threw falsy error")}if(n)return this.unsubscribe(),i},t.prototype.unsubscribe=function(){if(!this.closed){var e=this,r=e.id,n=e.scheduler,i=n.actions;this.work=this.state=this.scheduler=null,this.pending=!1,$(i,this),r!=null&&(this.id=this.recycleAsyncId(n,r,null)),this.delay=null,s.prototype.unsubscribe.call(this)}},t}(Be),me=function(){function s(t,e){e===void 0&&(e=s.now),this.schedulerActionCtor=t,this.now=e}return s.prototype.schedule=function(t,e,r){return e===void 0&&(e=0),new this.schedulerActionCtor(this,t).schedule(r,e)},s.now=qe.now,s}(),Ge=function(s){U(t,s);function t(e,r){r===void 0&&(r=me.now);var n=s.call(this,e,r)||this;return n.actions=[],n._active=!1,n}return t.prototype.flush=function(e){var r=this.actions;if(this._active){r.push(e);return}var n;this._active=!0;do if(n=e.execute(e.state,e.delay))break;while(e=r.shift());if(this._active=!1,n){for(;e=r.shift();)e.unsubscribe();throw n}},t}(me),Ye=new Ge(Qe),ze=Ye;function Je(s){return s&&E(s.schedule)}var We=j(function(s){return function(){s(this),this.name="EmptyError",this.message="no elements in sequence"}});function P(s,t){var e=typeof t=="object";return new Promise(function(r,n){var i=new D({next:function(o){r(o),i.unsubscribe()},error:n,complete:function(){e?r(t.defaultValue):n(new We)}});s.subscribe(i)})}function Ke(s){return s instanceof Date&&!isNaN(s)}function F(s,t){return de(function(e,r){var n=0;e.subscribe(pe(r,function(i){r.next(s.call(t,i,n++))}))})}function Xe(s,t,e){s===void 0&&(s=0),e===void 0&&(e=ze);var r=-1;return t!=null&&(Je(t)?e=t:r=t),new G(function(n){var i=Ke(s)?+s-e.now():s;i<0&&(i=0);var o=0;return e.schedule(function(){n.closed||(n.next(o++),0<=r?this.schedule(void 0,r):n.complete())},i)})}function Ze(s,t,e){var r=E(s)||t||e?{next:s,error:t,complete:e}:s;return r?de(function(n,i){var o;(o=r.subscribe)===null||o===void 0||o.call(r);var c=!0;n.subscribe(pe(i,function(a){var u;(u=r.next)===null||u===void 0||u.call(r,a),i.next(a)},function(){var a;c=!1,(a=r.complete)===null||a===void 0||a.call(r),i.complete()},function(a){var u;c=!1,(u=r.error)===null||u===void 0||u.call(r,a),i.error(a)},function(){var a,u;c&&((a=r.unsubscribe)===null||a===void 0||a.call(r)),(u=r.finalize)===null||u===void 0||u.call(r)}))}):le}var et=Object.defineProperty,tt=(s,t,e)=>t in s?et(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,T=(s,t,e)=>(tt(s,typeof t!="symbol"?t+"":t,e),e);class d extends Error{constructor(t){super(`Incorrect context (${t}). Cannot perform the requested operation.`),T(this,"context"),this.context=t}}class v extends Error{constructor(t,e,r){super(`Invalid parameter (${t}). ${r}`),this.param=t,this.value=e,this.reason=r}}class ye extends Error{constructor(t,e){super(`'streamId' value of "${t}" is different from what we expected ("${e}")`),this.streamId=t,this.expectedStreamId=e}}class rt extends Error{constructor(t){super(`Invalid version format: ${t}`)}}class ve extends Error{constructor(t){super(`${t} needs to be initialized before it can be used.`)}}class be 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(s){return typeof s=="function"}function st(s){return M(s==null?void 0:s.lift)}function A(s){return function(t){if(st(t))return t.lift(function(e){try{return s(e,this)}catch(r){this.error(r)}});throw new TypeError("Unable to lift unknown Observable type")}}var z=function(s,t){return z=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,r){e.__proto__=r}||function(e,r){for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])},z(s,t)};function J(s,t){if(typeof t!="function"&&t!==null)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");z(s,t);function e(){this.constructor=s}s.prototype=t===null?Object.create(t):(e.prototype=t.prototype,new e)}function we(s){var t=typeof Symbol=="function"&&Symbol.iterator,e=t&&s[t],r=0;if(e)return e.call(s);if(s&&typeof s.length=="number")return{next:function(){return s&&r>=s.length&&(s=void 0),{value:s&&s[r++],done:!s}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function W(s,t){var e=typeof Symbol=="function"&&s[Symbol.iterator];if(!e)return s;var r=e.call(s),n,i=[],o;try{for(;(t===void 0||t-- >0)&&!(n=r.next()).done;)i.push(n.value)}catch(c){o={error:c}}finally{try{n&&!n.done&&(e=r.return)&&e.call(r)}finally{if(o)throw o.error}}return i}function K(s,t,e){if(e||arguments.length===2)for(var r=0,n=t.length,i;r<n;r++)(i||!(r in t))&&(i||(i=Array.prototype.slice.call(t,0,r)),i[r]=t[r]);return s.concat(i||Array.prototype.slice.call(t))}function nt(s){var t=function(r){Error.call(r),r.stack=new Error().stack},e=s(t);return e.prototype=Object.create(Error.prototype),e.prototype.constructor=e,e}var X=nt(function(s){return function(t){s(this),this.message=t?t.length+` errors occurred during unsubscription:
1
+ (function(C,y){typeof exports=="object"&&typeof module<"u"?y(exports):typeof define=="function"&&define.amd?define(["exports"],y):(C=typeof globalThis<"u"?globalThis:C||self,y(C["@acrobits/ipc-sdk"]={}))})(this,function(C){"use strict";var Tt=Object.defineProperty;var xt=(C,y,I)=>y in C?Tt(C,y,{enumerable:!0,configurable:!0,writable:!0,value:I}):C[y]=I;var x=(C,y,I)=>(xt(C,typeof y!="symbol"?y+"":y,I),I);var y=(n=>(n.BadgeQuery="BADGE QUERY",n.Lifecycle="LIFECYCLE",n.PushToken="PUSH TOKEN",n.RequestLogs="REQUEST LOGS",n))(y||{}),I=function(n,t){return I=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])},I(n,t)};function U(n,t){if(typeof t!="function"&&t!==null)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");I(n,t);function e(){this.constructor=n}n.prototype=t===null?Object.create(t):(e.prototype=t.prototype,new e)}function H(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(c){o={error:c}}finally{try{s&&!s.done&&(e=r.return)&&e.call(r)}finally{if(o)throw o.error}}return i}function O(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 j(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=j(function(n){return function(e){n(this),this.message=e?e.length+` errors occurred during unsubscription:
2
+ `+e.map(function(r,s){return s+1+") "+r.toString()}).join(`
3
+ `):"",this.name="UnsubscriptionError",this.errors=e}});function k(n,t){if(n){var e=n.indexOf(t);0<=e&&n.splice(e,1)}}var R=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 c=H(o),a=c.next();!a.done;a=c.next()){var u=a.value;u.remove(this)}}catch(b){t={error:b}}finally{try{a&&!a.done&&(e=c.return)&&e.call(c)}finally{if(t)throw t.error}}else o.remove(this);var h=this.initialTeardown;if(E(h))try{h()}catch(b){i=b instanceof q?b.errors:[b]}var l=this._finalizers;if(l){this._finalizers=null;try{for(var w=H(l),p=w.next();!p.done;p=w.next()){var ne=p.value;try{oe(ne)}catch(b){i=i??[],b instanceof q?i=O(O([],L(i)),L(b.errors)):i.push(b)}}}catch(b){r={error:b}}finally{try{p&&!p.done&&(s=w.return)&&s.call(w)}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)oe(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)&&k(e,t)},n.prototype.remove=function(t){var e=this._finalizers;e&&k(e,t),t instanceof n&&t._removeParent(this)},n.EMPTY=function(){var t=new n;return t.closed=!0,t}(),n}(),se=R.EMPTY;function ie(n){return n instanceof R||n&&"closed"in n&&E(n.remove)&&E(n.add)&&E(n.unsubscribe)}function oe(n){E(n)?n():n.unsubscribe()}var ce={onUnhandledError:null,onStoppedNotification:null,Promise:void 0,useDeprecatedSynchronousErrorHandling:!1,useDeprecatedNextContext:!1},ae={setTimeout:function(n,t){for(var e=[],r=2;r<arguments.length;r++)e[r-2]=arguments[r];return setTimeout.apply(void 0,O([n,t],L(e)))},clearTimeout:function(n){var t=ae.delegate;return((t==null?void 0:t.clearTimeout)||clearTimeout)(n)},delegate:void 0};function Ae(n){ae.setTimeout(function(){throw n})}function ue(){}function $(n){n()}var B=function(n){U(t,n);function t(e){var r=n.call(this)||this;return r.isStopped=!1,e?(r.destination=e,ie(e)&&e.add(r)):r.destination=ke,r}return t.create=function(e,r,s){return new D(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}(R),_e=Function.prototype.bind;function Q(n,t){return _e.call(n,t)}var Le=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}(),D=function(n){U(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 c;i&&ce.useDeprecatedNextContext?(c=Object.create(e),c.unsubscribe=function(){return i.unsubscribe()},o={next:e.next&&Q(e.next,c),error:e.error&&Q(e.error,c),complete:e.complete&&Q(e.complete,c)}):o=e}return i.destination=new Le(o),i}return t}(B);function N(n){Ae(n)}function Oe(n){throw n}var ke={closed:!0,next:ue,error:Oe,complete:ue},$e=function(){return typeof Symbol=="function"&&Symbol.observable||"@@observable"}();function le(n){return n}function De(n){return n.length===0?le:n.length===1?n[0]:function(e){return n.reduce(function(r,s){return s(r)},e)}}var G=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=Fe(t)?t:new D(t,e,r);return $(function(){var o=s,c=o.operator,a=o.source;i.add(c?c.call(i,a):a?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=he(e),new e(function(s,i){var o=new D({next:function(c){try{t(c)}catch(a){i(a),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=he(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 he(n){var t;return(t=n??ce.Promise)!==null&&t!==void 0?t:Promise}function Ne(n){return n&&E(n.next)&&E(n.error)&&E(n.complete)}function Fe(n){return n&&n instanceof B||Ne(n)&&ie(n)}function Ve(n){return E(n==null?void 0:n.lift)}function de(n){return function(t){if(Ve(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 pe(n,t,e,r,s){return new He(n,t,e,r,s)}var He=function(n){U(t,n);function t(e,r,s,i,o,c){var a=n.call(this,e)||this;return a.onFinalize=o,a.shouldUnsubscribe=c,a._next=r?function(u){try{r(u)}catch(h){e.error(h)}}:n.prototype._next,a._error=i?function(u){try{i(u)}catch(h){e.error(h)}finally{this.unsubscribe()}}:n.prototype._error,a._complete=s?function(){try{s()}catch(u){e.error(u)}finally{this.unsubscribe()}}:n.prototype._complete,a}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}(B),je=j(function(n){return function(){n(this),this.name="ObjectUnsubscribedError",this.message="object unsubscribed"}}),fe=function(n){U(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 ge(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;$(function(){var s,i;if(r._throwIfClosed(),!r.isStopped){r.currentObservers||(r.currentObservers=Array.from(r.observers));try{for(var o=H(r.currentObservers),c=o.next();!c.done;c=o.next()){var a=c.value;a.next(e)}}catch(u){s={error:u}}finally{try{c&&!c.done&&(i=o.return)&&i.call(o)}finally{if(s)throw s.error}}}})},t.prototype.error=function(e){var r=this;$(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;$(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,c=s.observers;return i||o?se:(this.currentObservers=null,c.push(e),new R(function(){r.currentObservers=null,k(c,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 G;return e.source=this,e},t.create=function(e,r){return new ge(e,r)},t}(G),ge=function(n){U(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:se},t}(fe),qe={now:function(){return Date.now()},delegate:void 0},Be=function(n){U(t,n);function t(e,r){return n.call(this)||this}return t.prototype.schedule=function(e,r){return this},t}(R),Y={setInterval:function(n,t){for(var e=[],r=2;r<arguments.length;r++)e[r-2]=arguments[r];return setInterval.apply(void 0,O([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){U(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,k(i,this),r!=null&&(this.id=this.recycleAsyncId(s,r,null)),this.delay=null,n.prototype.unsubscribe.call(this)}},t}(Be),me=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=qe.now,n}(),Ge=function(n){U(t,n);function t(e,r){r===void 0&&(r=me.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}(me),Ye=new Ge(Qe),ze=Ye;function Je(n){return n&&E(n.schedule)}var We=j(function(n){return function(){n(this),this.name="EmptyError",this.message="no elements in sequence"}});function P(n,t){var e=typeof t=="object";return new Promise(function(r,s){var i=new D({next:function(o){r(o),i.unsubscribe()},error:s,complete:function(){e?r(t.defaultValue):s(new We)}});n.subscribe(i)})}function Ke(n){return n instanceof Date&&!isNaN(n)}function F(n,t){return de(function(e,r){var s=0;e.subscribe(pe(r,function(i){r.next(n.call(t,i,s++))}))})}function Xe(n,t,e){n===void 0&&(n=0),e===void 0&&(e=ze);var r=-1;return t!=null&&(Je(t)?e=t:r=t),new G(function(s){var i=Ke(n)?+n-e.now():n;i<0&&(i=0);var o=0;return e.schedule(function(){s.closed||(s.next(o++),0<=r?this.schedule(void 0,r):s.complete())},i)})}function Ze(n,t,e){var r=E(n)||t||e?{next:n,error:t,complete:e}:n;return r?de(function(s,i){var o;(o=r.subscribe)===null||o===void 0||o.call(r);var c=!0;s.subscribe(pe(i,function(a){var u;(u=r.next)===null||u===void 0||u.call(r,a),i.next(a)},function(){var a;c=!1,(a=r.complete)===null||a===void 0||a.call(r),i.complete()},function(a){var u;c=!1,(u=r.error)===null||u===void 0||u.call(r,a),i.error(a)},function(){var a,u;c&&((a=r.unsubscribe)===null||a===void 0||a.call(r)),(u=r.finalize)===null||u===void 0||u.call(r)}))}):le}var et=Object.defineProperty,tt=(n,t,e)=>t in n?et(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,T=(n,t,e)=>(tt(n,typeof t!="symbol"?t+"":t,e),e);class d extends Error{constructor(t){super(`Incorrect context (${t}). Cannot perform the requested operation.`),T(this,"context"),this.context=t}}class v extends Error{constructor(t,e,r){super(`Invalid parameter (${t}). ${r}`),this.param=t,this.value=e,this.reason=r}}class ye extends Error{constructor(t,e){super(`'streamId' value of "${t}" is different from what we expected ("${e}")`),this.streamId=t,this.expectedStreamId=e}}class rt extends Error{constructor(t){super(`Invalid version format: ${t}`)}}class ve extends Error{constructor(t){super(`${t} needs to be initialized before it can be used.`)}}class be 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 nt(n){return M(n==null?void 0:n.lift)}function A(n){return function(t){if(nt(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 J(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 W(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(c){o={error:c}}finally{try{s&&!s.done&&(e=r.return)&&e.call(r)}finally{if(o)throw o.error}}return i}function K(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))}function st(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=st(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(s,t){if(s){var e=s.indexOf(t);0<=e&&s.splice(e,1)}}var Z=function(){function s(t){this.initialTeardown=t,this.closed=!1,this._parentage=null,this._finalizers=null}return s.prototype.unsubscribe=function(){var t,e,r,n,i;if(!this.closed){this.closed=!0;var o=this._parentage;if(o)if(this._parentage=null,Array.isArray(o))try{for(var c=we(o),a=c.next();!a.done;a=c.next()){var u=a.value;u.remove(this)}}catch(b){t={error:b}}finally{try{a&&!a.done&&(e=c.return)&&e.call(c)}finally{if(t)throw t.error}}else o.remove(this);var h=this.initialTeardown;if(M(h))try{h()}catch(b){i=b instanceof X?b.errors:[b]}var l=this._finalizers;if(l){this._finalizers=null;try{for(var w=we(l),p=w.next();!p.done;p=w.next()){var se=p.value;try{Ee(se)}catch(b){i=i??[],b instanceof X?i=K(K([],W(i)),W(b.errors)):i.push(b)}}}catch(b){r={error:b}}finally{try{p&&!p.done&&(n=w.return)&&n.call(w)}finally{if(r)throw r.error}}}if(i)throw new X(i)}},s.prototype.add=function(t){var e;if(t&&t!==this)if(this.closed)Ee(t);else{if(t instanceof s){if(t.closed||t._hasParent(this))return;t._addParent(this)}(this._finalizers=(e=this._finalizers)!==null&&e!==void 0?e:[]).push(t)}},s.prototype._hasParent=function(t){var e=this._parentage;return e===t||Array.isArray(e)&&e.includes(t)},s.prototype._addParent=function(t){var e=this._parentage;this._parentage=Array.isArray(e)?(e.push(t),e):e?[e,t]:t},s.prototype._removeParent=function(t){var e=this._parentage;e===t?this._parentage=null:Array.isArray(e)&&Se(e,t)},s.prototype.remove=function(t){var e=this._finalizers;e&&Se(e,t),t instanceof s&&t._removeParent(this)},s.EMPTY=function(){var t=new s;return t.closed=!0,t}(),s}();Z.EMPTY;function Ce(s){return s instanceof Z||s&&"closed"in s&&M(s.remove)&&M(s.add)&&M(s.unsubscribe)}function Ee(s){M(s)?s():s.unsubscribe()}var Me={onUnhandledError:null,onStoppedNotification:null,Promise:void 0,useDeprecatedSynchronousErrorHandling:!1,useDeprecatedNextContext:!1},it={setTimeout:function(s,t){for(var e=[],r=2;r<arguments.length;r++)e[r-2]=arguments[r];return setTimeout.apply(void 0,K([s,t],W(e)))},clearTimeout:function(s){return clearTimeout(s)},delegate:void 0};function ot(s){it.setTimeout(function(){throw s})}function Ie(){}function ct(s){s()}var ee=function(s){J(t,s);function t(e){var r=s.call(this)||this;return r.isStopped=!1,e?(r.destination=e,Ce(e)&&e.add(r)):r.destination=ht,r}return t.create=function(e,r,n){return new re(e,r,n)},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,s.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(s,t){return at.call(s,t)}var ut=function(){function s(t){this.partialObserver=t}return s.prototype.next=function(t){var e=this.partialObserver;if(e.next)try{e.next(t)}catch(r){V(r)}},s.prototype.error=function(t){var e=this.partialObserver;if(e.error)try{e.error(t)}catch(r){V(r)}else V(t)},s.prototype.complete=function(){var t=this.partialObserver;if(t.complete)try{t.complete()}catch(e){V(e)}},s}(),re=function(s){J(t,s);function t(e,r,n){var i=s.call(this)||this,o;if(M(e)||!e)o={next:e??void 0,error:r??void 0,complete:n??void 0};else{var c;i&&Me.useDeprecatedNextContext?(c=Object.create(e),c.unsubscribe=function(){return i.unsubscribe()},o={next:e.next&&te(e.next,c),error:e.error&&te(e.error,c),complete:e.complete&&te(e.complete,c)}):o=e}return i.destination=new ut(o),i}return t}(ee);function V(s){ot(s)}function lt(s){throw s}var ht={closed:!0,next:Ie,error:lt,complete:Ie},dt=function(){return typeof Symbol=="function"&&Symbol.observable||"@@observable"}();function Ue(s){return s}function pt(s){return s.length===0?Ue:s.length===1?s[0]:function(t){return s.reduce(function(e,r){return r(e)},t)}}var ft=function(){function s(t){t&&(this._subscribe=t)}return s.prototype.lift=function(t){var e=new s;return e.source=this,e.operator=t,e},s.prototype.subscribe=function(t,e,r){var n=this,i=mt(t)?t:new re(t,e,r);return ct(function(){var o=n,c=o.operator,a=o.source;i.add(c?c.call(i,a):a?n._subscribe(i):n._trySubscribe(i))}),i},s.prototype._trySubscribe=function(t){try{return this._subscribe(t)}catch(e){t.error(e)}},s.prototype.forEach=function(t,e){var r=this;return e=Te(e),new e(function(n,i){var o=new re({next:function(c){try{t(c)}catch(a){i(a),o.unsubscribe()}},error:i,complete:n});r.subscribe(o)})},s.prototype._subscribe=function(t){var e;return(e=this.source)===null||e===void 0?void 0:e.subscribe(t)},s.prototype[dt]=function(){return this},s.prototype.pipe=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return pt(t)(this)},s.prototype.toPromise=function(t){var e=this;return t=Te(t),new t(function(r,n){var i;e.subscribe(function(o){return i=o},function(o){return n(o)},function(){return r(i)})})},s.create=function(t){return new s(t)},s}();function Te(s){var t;return(t=s??Me.Promise)!==null&&t!==void 0?t:Promise}function gt(s){return s&&M(s.next)&&M(s.error)&&M(s.complete)}function mt(s){return s&&s instanceof ee||gt(s)&&Ce(s)}function _(s,t,e,r,n){return new yt(s,t,e,r,n)}var yt=function(s){J(t,s);function t(e,r,n,i,o,c){var a=s.call(this,e)||this;return a.onFinalize=o,a.shouldUnsubscribe=c,a._next=r?function(u){try{r(u)}catch(h){e.error(h)}}:s.prototype._next,a._error=i?function(u){try{i(u)}catch(h){e.error(h)}finally{this.unsubscribe()}}:s.prototype._error,a._complete=n?function(){try{n()}catch(u){e.error(u)}finally{this.unsubscribe()}}:s.prototype._complete,a}return t.prototype.unsubscribe=function(){var e;if(!this.shouldUnsubscribe||this.shouldUnsubscribe()){var r=this.closed;s.prototype.unsubscribe.call(this),!r&&((e=this.onFinalize)===null||e===void 0||e.call(this))}},t}(ee);function f(s,t){return A(function(e,r){var n=0;e.subscribe(_(r,function(i){r.next(s.call(t,i,n++))}))})}var vt=new ft(function(s){return s.complete()});function S(s){return s<=0?function(){return vt}:A(function(t,e){var r=0;t.subscribe(_(e,function(n){++r<=s&&(e.next(n),s<=r&&e.complete())}))})}function m(s,t){return A(function(e,r){var n=0;e.subscribe(_(r,function(i){return s.call(t,i,n++)&&r.next(i)}))})}function bt(s,t){return t===void 0&&(t=!1),A(function(e,r){var n=0;e.subscribe(_(r,function(i){var o=s(i,n++);(o||t)&&r.next(i),!o&&r.complete()}))})}function g(s,t,e){var r=M(s)||t||e?{next:s,error:t,complete:e}:s;return r?A(function(n,i){var o;(o=r.subscribe)===null||o===void 0||o.call(r);var c=!0;n.subscribe(_(i,function(a){var u;(u=r.next)===null||u===void 0||u.call(r,a),i.next(a)},function(){var a;c=!1,(a=r.complete)===null||a===void 0||a.call(r),i.complete()},function(a){var u;c=!1,(u=r.error)===null||u===void 0||u.call(r,a),i.error(a)},function(){var a,u;c&&((a=r.unsubscribe)===null||a===void 0||a.call(r)),(u=r.finalize)===null||u===void 0||u.call(r)}))}):Ue}const wt=/^(\d+)\.(\d+)$/;function St(s){if(typeof s=="string"){const t=s.match(wt);if(t)return`${t[1]}.${t[2]}`}throw new rt(s)}function xe(s){const t=St(s),[e,r]=t.split("."),[n,i]=[parseInt(e),parseInt(r)];return[n,i]}function Re(s,t){const[e,r]=xe(s),[n,i]=xe(t);return e<n?-1:e>n?1:r<i?-1:r>i?1:0}function Ct(s,t){return Re(s,t)>=0}const Pe="2.0";class Et{constructor(t,e){if(T(this,"negotiatedProtocolVersion"),T(this,"currentContext"),T(this,"incomingMessages$"),T(this,"inIframe",!1),T(this,"embeddedResult"),T(this,"iframePort1"),T(this,"iframePort2"),this.supportedVersions=t,this.logService=e,this.incomingMessages$=new fe,this.supportedVersions=t.filter(r=>Ct(r,Pe)),!this.supportedVersions.length)throw new be(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,n;if(this.inIframe){if(!this.iframePort2)throw new ve("port2");return this.iframePort2}else{if(!((e=(t=window.Acrobits)==null?void 0:t.messageChannel)!=null&&e.port2))throw new ve("port2");return(n=(r=window.Acrobits)==null?void 0:r.messageChannel)==null?void 0:n.port2}}determineContext(){return Xe(1e3).pipe(f(()=>(this.isEmbedded()?this.currentContext="user":this.currentContext="guest",this.currentContext)),S(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(m(n=>n.type===t&&n.replyTo===e.id),f(n=>n),g(this.logReceived()),f(n=>{if(!this.supportedVersions.includes(n.protocolVersion))throw new be(n.protocolVersion,this.supportedVersions[0]);return n.displayName||(n.displayName=n.cloudUsername),n}),g(n=>{this.negotiatedProtocolVersion=n.protocolVersion,this.logService.info(`[IPC] Negotiated IPC Protocol Version: ${this.negotiatedProtocolVersion}`)}),S(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(m(n=>n.type===t&&n.replyTo===e.id),f(n=>n),g(this.logReceived()),S(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:n,jwtToken:i,serverUrl:o,region:c,joinMicMuted:a,joinWithoutCamera:u}=t,h="JOINING ROOM",l=this.createMessage(h,!1);l.roomName=e,l.jwtToken=i,l.serverUrl=o,l.region=c,l.roomInvite=r,l.joinMicMuted=a??!1,l.joinWithoutCamera=u??!1,l.displayName=n,this.logCreated(h,l),this.port2.postMessage(l),this.logSent(h,l)}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(m(e=>e.type===t&&e.target==="client"),f(e=>e),g(this.logReceived()),f(e=>e))}onLeaveRoomMessage(){if(!this.isEmbedded())throw new d(this.currentContext);const t="LEAVE ROOM";return this.incomingMessages$.pipe(m(e=>e.type===t&&e.target==="client"),f(e=>e),g(this.logReceived()),f(e=>e))}onConfigMessage(){if(!this.isEmbedded())throw new d(this.currentContext);const t="CONFIG";return this.incomingMessages$.pipe(m(e=>e.type===t&&e.target==="client"),f(e=>e),g(this.logReceived()),f(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]:[],timeFormat:e.timeFormat??"default"})))}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 n=this.incomingMessages$.pipe(m(i=>i.type===e&&i.replyTo===r.id),f(i=>i),g(this.logReceived()),f(i=>i),S(1));return this.logService.debug(`Created ${e} Reply handler`),this.port2.postMessage(r),this.logSent(e,r),n}layoutChange(t,e,r){if(!this.isEmbedded())throw new d(this.currentContext);const n="LAYOUT CHANGE";let i,o;if(e&&r?(i=this.createMessage(n,!1,r),i.result=e):(i=this.createMessage(n),o=this.incomingMessages$.pipe(m(c=>c.type===n&&c.replyTo===i.id),f(c=>c),g(this.logReceived()),f(c=>c),S(1)),this.logService.debug(`Created ${n} Reply handler`)),i.layout=t,this.logCreated(n,i),this.port2.postMessage(i),this.logSent(n,i),o)return o}onLayoutChangeMessage(){if(!this.isEmbedded())throw new d(this.currentContext);const t="LAYOUT CHANGE";return this.incomingMessages$.pipe(m(e=>e.type===t&&e.target==="client"&&e.replyTo===null),f(e=>e),g(this.logReceived()),f(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 n=this.incomingMessages$.pipe(m(i=>i.type===e&&i.replyTo===r.id),f(i=>i),g(this.logReceived()),S(1));return this.logService.debug(`Created ${e} Reply handler`),this.port2.postMessage(r),this.logSent(e,r),n}openUrl(t,e){if(!this.isEmbedded())throw new d(this.currentContext);const r="OPEN URL",n=this.createMessage(r,!1);n.url=t,n.data=e,this.logCreated(r,n),this.port2.postMessage(n),this.logSent(r,n)}selectContacts(t,e,r,n){if(!this.isEmbedded())throw new d(this.currentContext);if(this.negotiatedProtocolVersion==="2.0"){if(e===void 0||typeof e=="object")throw new v("streamType",e,"streamType is missing or invalid");if(r===void 0||typeof r=="object"||typeof r=="number")throw new v("contactType",r,"contactType is missing or invalid");return this.selectContactsV2_0(t,e,r,n)}if(typeof e<"u"&&typeof e!="object")throw new v("options",e,"options is invalid");if(typeof r<"u"&&!Array.isArray(r))throw new v("currentContacts",r,"currentContacts is invalid");return this.selectContactsV2_1(t,e,r)}selectContactsV2_0(t,e,r,n){if(!this.isEmbedded())throw new d(this.currentContext);n&&n.length>0&&(n=n.map(a=>a.type==="cloudUsername"&&a.contactUser?{...a,cloudId:a.cloudId||a.contactUser.cloudId,networkId:a.networkId||a.contactUser.networkId,cloudUsername:a.cloudUsername||a.contactUser.cloudUsername}:a));const i="SELECT CONTACTS",o=this.createMessage(i,!0);o.streamId=t,o.streamType=e,o.contactType=r,o.resultTypes=[r],o.currentContacts=n,this.logCreated(i,o);const c=this.incomingMessages$.pipe(m(a=>a.type===i&&a.replyTo===o.id),g(this.logReceived()),f(a=>{const u=a;if(u.result==="success"){if(u.streamId!==t)throw new ye(u.streamId,t);e==="direct"&&u.contacts.length>1&&(u.contacts=[u.contacts[0]])}return u}),S(1));return this.logService.debug(`Created ${i} Reply handler`),this.port2.postMessage(o),this.logSent(i,o),c}selectContactsV2_1(t,e,r){if(!this.isEmbedded())throw new d(this.currentContext);const n={allowMultipleSelection:(e==null?void 0:e.allowMultipleSelection)??!1,resultTypes:(e==null?void 0:e.resultTypes)??["cloudUsername"]};if(r&&r.length>0)for(const a of r){if(a.contactId===void 0)throw new v("currentContacts",r,"ContactItem contactId is required since v2.1 on all contacts");if(a.type==="cloudUsername"){if(!a.contactUser)throw new v("currentContacts",a,"CloudUsername contact must include contactUser since v2.1");if(!a.contactUser.cloudId||!a.contactUser.networkId||!a.contactUser.cloudUsername)throw new v("currentContacts",a,"CloudContact must define cloudUsername, cloudId, and networkId since v2.1")}}const i="SELECT CONTACTS",o=this.createMessage(i,!0);o.streamId=t,o.resultTypes=n.resultTypes,o.currentContacts=r,o.allowMultipleSelection=n.allowMultipleSelection,this.logCreated(i,o);const c=this.incomingMessages$.pipe(m(a=>a.type===i&&a.replyTo===o.id),g(this.logReceived()),f(a=>{const u=a;if(u.result==="success"){if(u.streamId!==t)throw new ye(u.streamId,t);const h=u.contacts.length;u.contacts=u.contacts.filter(l=>n.resultTypes.includes(l.type)),u.contacts.length!==h&&this.logService.debug(`[IPC] [SelectContactsReply] Filtered ${h-u.contacts.length} contacts from reply`),!n.allowMultipleSelection&&u.contacts.length>1&&(u.contacts=[u.contacts[0]]);for(const l of u.contacts)if(l.type==="cloudUsername"){if(!l.contactUser)throw new Error(`CloudUsername contact must include contactUser since v2.1. ContactItem: ${JSON.stringify(l)}`);if(!l.contactUser.cloudId||!l.contactUser.networkId||!l.contactUser.cloudUsername)throw new Error(`CloudContact must define cloudUsername, cloudId, and networkId since v2.1. ContactItem: ${JSON.stringify(l)}`)}}return u}),S(1));return this.logService.debug(`Created ${i} Reply handler`),this.port2.postMessage(o),this.logSent(i,o),c}matchContacts(t){if(!this.isEmbedded())throw new d(this.currentContext);if(!Array.isArray(t))throw new v("contacts",t,"contacts is not an array");if(!t.length)throw new v("contacts",t,"At least one contact is required");const e=this.createMessage("MATCH CONTACTS");if(this.compareVersion("2.1")>=0){for(const n of t)if(n.type==="cloudUsername"){if(!n.contactUser)throw new v("contacts",n,"CloudUsername contact must include contactUser");if(!n.contactUser.cloudUsername||!n.contactUser.cloudId||!n.contactUser.networkId)throw new v("contacts",n,"CloudContact must define cloudUsername, cloudId, and networkId")}e.contacts=[...t]}else{for(const n of t)n.type==="cloudUsername"&&n.contactUser&&(n.cloudId=n.contactUser.cloudId,n.networkId=n.contactUser.networkId,n.cloudUsername=n.contactUser.cloudUsername);e.contacts=[...t]}this.logCreated(e.type,e);const r=this.incomingMessages$.pipe(m(n=>n.type===e.type&&n.replyTo===e.id),g(this.logReceived()),f(n=>{const i=n;if(this.compareVersion("2.1")>=0){if(Array.isArray(i.contacts))throw new Error("MatchContactsMessageReply should return a Record<string, DetailedContactItem> of contacts when using IPC Protocol v2.1+");for(const[o,c]of Object.entries(i.contacts)){if(c==null){this.logService.debug(`[IPC] [MatchContactsReply] Received null or undefined contact for ${o}`);continue}if(c.contactId===void 0)throw new Error(`ContactItem 'contactId' is required since v2.1. ContactItem: ${JSON.stringify(c)}`);if(!c.contactUser&&(!c.uri||c.uri.length===0)&&(!c.numbers||c.numbers.length===0))throw new Error(`DetailedContactItem must define at least one contact method (contactUser, uri, or numbers). ContactItem: ${JSON.stringify(c)}`);if(c.contactUser&&(!c.contactUser.cloudId||!c.contactUser.networkId||!c.contactUser.cloudUsername))throw new Error(`When contactUser is defined, cloudId, networkId, and cloudUsername must also be defined. ContactItem: ${JSON.stringify(c)}`)}}else{if(!Array.isArray(i.contacts))throw new Error("MatchContactsMessageReply should return an array of contacts when using IPC Protocol v2.0");if(i.contacts.length!==e.contacts.length)throw new Error("The number of contacts in the reply does not match the number of contacts in the request");for(const o of i.contacts){const c=o;if(c.type==="cloudUsername"&&!("cloudUsername"in c))throw new Error(`CloudUsernameDetailedContactItem must define cloudUsername. ContactItem: ${JSON.stringify(o)}`);if(c.type==="uri"&&(!("uri"in c)||!Array.isArray(c.uri)))throw new Error(`UriDetailedContactItem must define uri as an array. ContactItem: ${JSON.stringify(o)}`)}}return i}),S(1));return this.logService.debug(`Created ${e.type} Reply handler`),this.port2.postMessage(e),this.logSent(e.type,e),r}onPushMessageMessage(){if(!this.isEmbedded())throw new d(this.currentContext);const t="PUSH MESSAGE";return this.incomingMessages$.pipe(m(e=>e.type===t&&e.target==="client"),f(e=>e),g(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(m(n=>n.type===t&&n.replyTo===e.id),g(this.logReceived()),f(n=>n),S(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(m(e=>e.type===t&&e.target==="client"&&e.replyTo===null&&e.expectReply===!1),f(e=>{if(e.pushToken&&e.selector&&e.appId)return e;throw new Error("PushTokenMessage is missing required PushTokenPayload fields")}),g(e=>e.pushToken),g(this.logReceived()))}onBadgeQueryMessage(){if(!this.isEmbedded())throw new d(this.currentContext);const t="BADGE QUERY";return this.incomingMessages$.pipe(m(e=>e.type===t&&e.target==="client"),f(e=>e),g(this.logReceived()))}sendBadgeUpdateMessage(t,e,r){if(!this.isEmbedded())throw new d(this.currentContext);const n="BADGE UPDATE",i=this.createMessage(n,!1,r);i.count=t,i.activity=e??!1,this.logCreated(n,i),this.port2.postMessage(i),this.logSent(n,i)}sendLifecycleMessage(t,e){if(!this.isEmbedded())throw new d(this.currentContext);const r="LIFECYCLE",n=this.createMessage(r,!1);n.eventName=t,n.payload=e,this.logCreated(r,n),this.port2.postMessage(n),this.logSent(r,n)}onLifecycleMessage(){if(!this.isEmbedded())throw new d(this.currentContext);const t="LIFECYCLE";return this.incomingMessages$.pipe(m(e=>e.type===t&&e.target==="client"),f(e=>e),g(this.logReceived()))}sendLogMessage(t,e){if(!this.isEmbedded())throw new d(this.currentContext);const r="LOG",n=this.createMessage(r,!1);n.level=t,n.message=e,this.logCreated(r,n),this.port2.postMessage(n),this.logSent(r,n)}onRequestLogsMessage(){if(!this.isEmbedded())throw new d(this.currentContext);const t="REQUEST LOGS";return this.incomingMessages$.pipe(m(e=>e.type===t&&e.target==="client"),f(e=>e),g(this.logReceived()))}sendRequestLogsMessageReply(t,e,r,n,i){if(!this.isEmbedded())throw new d(this.currentContext);const o="REQUEST LOGS",c=this.createMessage(o,!1,i);c.fileId=t,c.fileHash=e,c.fileSize=r,c.format=n,this.logCreated(o,c),this.port2.postMessage(c),this.logSent(o,c)}sendViewTransitionMessage(t,e){if(!this.isEmbedded())throw new d(this.currentContext);const r="VIEW TRANSITION",n=this.createMessage(r,!1);n.transitionType=t,n.targetView=e,this.logCreated(r,n),this.port2.postMessage(n),this.logSent(r,n)}sendFileRequestMessage(t,e,r,n,i){if(!this.isEmbedded())throw new d(this.currentContext);const o="FILE REQUEST",c=this.createMessage(o);if(c.fileId=t,c.fileHash=e.toLowerCase(),c.intent=r,c.maxChunkSizeInBytes=i,r==="attachment"){if(!n)throw new v("streamId",n,"streamId is required for attachment intent");c.streamId=n}this.logCreated(o,c);let a=0;const u=this.incomingMessages$.pipe(m(h=>h.type===o&&h.replyTo===c.id),g(this.logReceived()),g(()=>a++),f(h=>(h.result==="success"&&(h.chunkHash=h.chunkHash.toLowerCase(),h.fileHash=h.fileHash.toLowerCase()),h)),bt(h=>h.result==="success"&&a<h.totalChunks,!0));return this.port2.postMessage(c),this.logSent(o,c),u}sendFileRequestMessageReply(t,e){if(!this.isEmbedded())throw new d(this.currentContext);const r="FILE REQUEST",n=Object.assign(e,this.createMessage(r,!1,t.id));this.logCreated(r,n),this.port2.postMessage(n),this.logSent(r,n)}onFileRequestMessage(){if(!this.isEmbedded())throw new d(this.currentContext);const t="FILE REQUEST";return this.incomingMessages$.pipe(m(e=>e.type===t&&e.target==="client"&&e.replyTo===null),f(e=>(e.fileHash=e.fileHash.toLowerCase(),e)),g(this.logReceived()))}sendFileSelectionMessage(t="attachment",e,r,n,i,o){if(!this.isEmbedded())throw new d(this.currentContext);const c="FILE SELECTION",a=this.createMessage(c);if(a.intent=t,a.maxCount=n,a.maxFileSizeInBytes=i,a.mimeTypes=o,t==="attachment"){if(!e)throw new v("streamId",e,"streamId is required for attachment intent");if(!r)throw new v("correlationId",r,"correlationId is required for attachment intent");a.streamId=e,a.correlationId=r}this.logCreated(c,a);const u=this.incomingMessages$.pipe(m(h=>h.type===c&&h.replyTo===a.id),f(h=>{var l;return h.result==="success"&&(h.files=(l=h.files)==null?void 0:l.map(w=>(w.original.fileHash=w.original.fileHash.toLowerCase(),w.preview&&(w.preview.fileHash=w.preview.fileHash.toLowerCase()),w))),h}),g(this.logReceived()),S(1));return this.port2.postMessage(a),this.logSent(c,a),u}sendFileDownloadProgressQueryMessage(t,e,r){if(!this.isEmbedded())throw new d(this.currentContext);const n="FILE DOWNLOAD PROGRESS QUERY",i=this.createMessage(n,!0);i.fileHash=t.toLowerCase(),i.url=e,i.correlationId=r,this.logCreated(n,i);const o=this.incomingMessages$.pipe(m(c=>c.type==="FILE DOWNLOAD PROGRESS UPDATE"&&c.replyTo===i.id),g(c=>this.logReceived(c)),f(c=>(c.fileHash&&(c.fileHash=c.fileHash.toLowerCase()),c)),S(1));return this.port2.postMessage(i),this.logSent(n,i),o}onFileDownloadProgressUpdateMessage(){if(!this.isEmbedded())throw new d(this.currentContext);const t="FILE DOWNLOAD PROGRESS UPDATE";return this.incomingMessages$.pipe(m(e=>e.type===t&&e.target==="client"&&e.replyTo===null),f(e=>(e.fileHash&&(e.fileHash=e.fileHash.toLowerCase()),e)),g(this.logReceived()))}sendFileUploadProgressQueryMessage(t,e,r){if(!this.isEmbedded())throw new d(this.currentContext);const n="FILE UPLOAD PROGRESS QUERY",i=this.createMessage(n,!0);i.fileHash=t.toLowerCase(),i.fileId=e,i.correlationId=r,this.logCreated(n,i);const o=this.incomingMessages$.pipe(m(c=>c.type==="FILE UPLOAD PROGRESS UPDATE"&&c.replyTo===i.id),g(this.logReceived()),f(c=>(c.fileHash&&(c.fileHash=c.fileHash.toLowerCase()),c)),S(1));return this.port2.postMessage(i),this.logSent(n,i),o}onFileUploadProgressUpdateMessage(){if(!this.isEmbedded())throw new d(this.currentContext);const t="FILE UPLOAD PROGRESS UPDATE";return this.incomingMessages$.pipe(m(e=>e.type===t&&e.target==="client"&&e.replyTo===null),f(e=>(e.fileHash&&(e.fileHash=e.fileHash.toLowerCase()),e)),g(this.logReceived()))}sendFileDownloadMessage(t,e,r,n,i,o,c,a,u){if(!this.isEmbedded())throw new d(this.currentContext);if(a&&this.compareVersion("2.1")<0)a.type==="cloudUsername"&&a.contactUser&&(a={...a,cloudId:a.cloudId||a.contactUser.cloudId,networkId:a.networkId||a.contactUser.networkId,cloudUsername:a.cloudUsername||a.contactUser.cloudUsername});else if(a&&this.compareVersion("2.1")>=0&&a.type==="cloudUsername"){if(!a.contactUser)throw new v("sender",a,"CloudUsername contact must include contactUser since v2.1");if(!a.contactUser.cloudId||!a.contactUser.networkId||!a.contactUser.cloudUsername)throw new v("sender",a,"CloudContact must define cloudUsername, cloudId, and networkId since v2.1")}const h="FILE DOWNLOAD",l=this.createMessage(h,!0);l.url=t,l.key=e,l.fileHash=r.toLowerCase(),l.mimeType=n,l.fileName=i,l.streamId=o,l.correlationId=c,l.sender=a,l.intent=u??"download",this.logCreated(h,l);const w=this.incomingMessages$.pipe(m(p=>p.type===h&&p.replyTo===l.id),g(this.logReceived()),f(p=>p),S(1));return this.port2.postMessage(l),this.logSent(h,l),w}sendCancelFileDownloadMessage(t,e,r){if(!this.isEmbedded())throw new d(this.currentContext);const n="CANCEL FILE DOWNLOAD",i=this.createMessage(n,!1);i.fileHash=t.toLowerCase(),i.url=e,i.correlationId=r,this.logCreated(n,i),this.port2.postMessage(i),this.logSent(n,i)}sendFileRemoveMessage(t,e){if(!this.isEmbedded())throw new d(this.currentContext);const r="FILE REMOVE",n=this.createMessage(r,!0);n.hash=t.toLowerCase(),n.streamId=e,this.logCreated(r,n);const i=this.incomingMessages$.pipe(m(o=>o.type===r&&o.replyTo===n.id),g(this.logReceived()),f(o=>o),S(1));return this.port2.postMessage(n),this.logSent(r,n),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",n=this.createMessage(r,!1);n.streamId=t,n.correlationId=e,this.logCreated(r,n),this.port2.postMessage(n),this.logSent(r,n)}sendSendMessageMessage(t,e,r,n="TEXT",i,o,c,a=!0,u){if(!this.isEmbedded())throw new d(this.currentContext);const h="SEND MESSAGE",l=this.createMessage(h,!0);if(l.streamId=t,l.correlationId=e,l.body=r,l.messageType=n,i&&i.length>0)if(this.compareVersion("2.1")<0)l.mentions=i.map(p=>p.contactUser?{...p,cloudId:p.cloudId||p.contactUser.cloudId,networkId:p.networkId||p.contactUser.networkId,cloudUsername:p.cloudUsername||p.contactUser.cloudUsername}:p);else{for(const p of i){if(p.type==="cloudUsername"&&!p.contactUser)throw new v("mentions",p,"CloudUsername mention must include contactUser");if(p.contactUser&&(!p.contactUser.cloudId||!p.contactUser.networkId||!p.contactUser.cloudUsername))throw new v("mentions",p,"CloudContact must define cloudUsername, cloudId, and networkId")}l.mentions=i}else l.mentions=[];l.attachments=(o==null?void 0:o.map(p=>p.toLowerCase()))??[],l.relatedMessageId=c,l.setCursors=a,l.threadId=u,this.logCreated(h,l);const w=this.incomingMessages$.pipe(m(p=>p.type===h&&p.replyTo===l.id),g(this.logReceived()),f(p=>p),S(1));return this.port2.postMessage(l),this.logSent(h,l),w}sendCancelSendMessageMessage(t,e){if(!this.isEmbedded())throw new d(this.currentContext);const r="CANCEL SEND MESSAGE",n=this.createMessage(r,!1);n.streamId=t,n.correlationId=e,this.logCreated(r,n),this.port2.postMessage(n),this.logSent(r,n)}sendMessageDeletedMessage(t,e){if(!this.isEmbedded())throw new d(this.currentContext);const r="MESSAGE DELETED",n=this.createMessage(r,!1);n.correlationId=t,n.streamId=e,this.logCreated(r,n),this.port2.postMessage(n),this.logSent(r,n)}sendSendMessageStatusQueryMessage(t,e){if(!this.isEmbedded())throw new d(this.currentContext);const r="SEND MESSAGE STATUS QUERY",n=this.createMessage(r,!0);n.correlationId=t,n.streamId=e,this.logCreated(r,n);const i=this.incomingMessages$.pipe(m(o=>o.type==="SEND MESSAGE STATUS UPDATE"&&o.replyTo===n.id),g(this.logReceived()),f(o=>o),S(1));return this.port2.postMessage(n),this.logSent(r,n),i}onSendMessageStatusUpdateMessage(){if(!this.isEmbedded())throw new d(this.currentContext);const t="SEND MESSAGE STATUS UPDATE";return this.incomingMessages$.pipe(m(e=>e.type===t&&e.target==="client"&&e.replyTo===null),f(e=>e),g(this.logReceived()))}sendSipCallMessage(t){if(!this.isEmbedded())throw new d(this.currentContext);if(this.compareVersion("2.1")<0)t.type==="cloudUsername"&&t.contactUser&&(t={...t,cloudId:t.cloudId||t.contactUser.cloudId,networkId:t.networkId||t.contactUser.networkId,cloudUsername:t.cloudUsername||t.contactUser.cloudUsername});else if(t.type==="cloudUsername"){if(!t.contactUser)throw new v("contact",t,"CloudUsername contact must include contactUser since v2.1");if(!t.contactUser.cloudId||!t.contactUser.networkId||!t.contactUser.cloudUsername)throw new v("contact",t,"CloudContact must define cloudUsername, cloudId, and networkId since v2.1")}const e="SIP CALL",r=this.createMessage(e,!1);r.contact=t,this.logCreated(e,r),this.port2.postMessage(r),this.logSent(e,r)}sendCustomFunctionMessage(t,e){if(!this.isEmbedded())throw new d(this.currentContext);const r="CUSTOM FUNCTION",n=this.createMessage(r,!1);n.customFunctionId=t,n.context=e,this.logCreated(r,n),this.port2.postMessage(n),this.logSent(r,n)}sendSubscribeButtonsMessage(t){if(!this.isEmbedded())throw new d(this.currentContext);const e="SUBSCRIBE BUTTONS",r=this.createMessage(e,!1);r.subscribe=t,this.logCreated(e,r),this.port2.postMessage(r),this.logSent(e,r)}onButtonsMessage(){if(!this.isEmbedded())throw new d(this.currentContext);const t="BUTTONS";return this.incomingMessages$.pipe(m(e=>e.type===t&&e.target==="client"),f(e=>e),g(this.logReceived()))}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 Re(this.negotiatedProtocolVersion,t)}logReceived(t){const e=r=>this.logService.debug(`[IPC] Received ${r.type} message${r.replyTo?" reply":""}`,r);if(t){Mt(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 n=[];e&&(r=r.substr(0,r.indexOf("Q")));for(let i=0;i<t;i++)n.push(r[Math.floor(Math.random()*r.length)]);return n.join("")}}function Mt(s){return s.type==="FILE REQUEST"&&s.replyTo!==null}const It=["2.0","2.1"];class Ut{constructor(t){x(this,"host");x(this,"cloudId");x(this,"cloudUsername");x(this,"displayName");x(this,"logger");x(this,"helper");x(this,"listeners");this.logger=t??console,this.helper=new Et(It,this.logger),this.listeners=new Map,this.listeners.set(y.BadgeQuery,new Set),this.listeners.set(y.Lifecycle,new Set),this.listeners.set(y.PushToken,new Set),this.listeners.set(y.RequestLogs,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 P(this.helper.determineContext(),{defaultValue:"guest"});return this.evaluateContext(t)}initiateConnection(){return P(this.helper.openBridge().pipe(Ze(t=>{this.helper.onBadgeQueryMessage().subscribe(e=>{var r;this.logger.debug("Received Badge Query: ",e);for(const n of((r=this.listeners.get(y.BadgeQuery))==null?void 0:r.values())??[])n()}),this.helper.onLifecycleMessage().subscribe(e=>{var r;this.logger.debug("Received Lifecycle Event: ",e);for(const n of((r=this.listeners.get(y.Lifecycle))==null?void 0:r.values())??[])n(e.eventName,e.payload)}),this.helper.onPushTokenMessage().subscribe(e=>{var r;this.logger.debug("Received Push Token: ",e);for(const n of((r=this.listeners.get(y.PushToken))==null?void 0:r.values())??[])n(e.pushToken,e.appId,e.selector)}),this.helper.onRequestLogsMessage().subscribe(e=>{var r;if(this.logger.debug("Received Request Logs Message: ",e),e.responseType==="file")throw this.logger.error("File response type not supported"),new Error("File response type not supported");for(const n of((r=this.listeners.get(y.RequestLogs))==null?void 0:r.values())??[])n(e.skipCompression)}),this.cloudId=t.cloudId,this.cloudUsername=t.cloudUsername,this.displayName=t.displayName,this.host=t.host}),F(()=>{})))}selectContacts(t,e,r,n){this.logger.debug("Selecting Contacts: ",...arguments);let i;if(this.negotiatedVersion==="2.0"){if(typeof e!="string")throw new v("mode",e,'mode must be "single" or "multi"');if(n==="number")throw new v("contactType",n,'contactType cannot be "number" for version 2.0 of the IPC protocol');i=this.selectContacts_V2_0(t,e??"single",e==="multi"?r:void 0,e==="multi"?n:r)}else{if(typeof e!="object")throw new v("options",e,"options must be an object");i=this.selectContacts_V2_1(t,e)}return P(i.pipe(F(o=>o.result==="error"?{result:"error",errorMessage:o.errorMessage}:o.result==="cancelled"?{result:"cancelled"}:o.contacts)))}selectContacts_V2_0(t,e,r,n){if(this.logger.debug("Selecting Contacts: ",...arguments),e==="multi"){if(!r||!Array.isArray(r))throw new v("currentContacts",r,"currentContacts is required for group streams");return n||(n="cloudUsername"),this.helper.selectContacts(t.toString(),"group",n,r)}else return n||(n="cloudUsername"),this.helper.selectContacts(t.toString(),"direct",n)}selectContacts_V2_1(t,e){if(this.logger.debug("Selecting Contacts: ",e),e.mode==="multi"&&(!e.currentContacts||!Array.isArray(e.currentContacts)))throw new v("currentContacts",e.currentContacts,"currentContacts is required for group streams");return this.helper.selectContacts(t.toString(),{allowMultipleSelection:e.mode==="multi",resultTypes:e.resultTypes??["cloudUsername"]},e.mode==="multi"?e.currentContacts:void 0)}matchContacts(t){return this.logger.debug("Match Contacts: ",t),P(this.helper.matchContacts(t).pipe(F(e=>e.contacts)))}requestPushToken(){return this.logger.debug("Requesting Push Token"),P(this.helper.requestPushToken().pipe(F(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(y.BadgeQuery))==null||e.add(t),()=>{var r;return(r=this.listeners.get(y.BadgeQuery))==null?void 0:r.delete(t)}}onLifecycleEvent(t){var e;return this.logger.debug("Registering for Lifecycle Event"),(e=this.listeners.get(y.Lifecycle))==null||e.add(t),()=>{var r;return(r=this.listeners.get(y.Lifecycle))==null?void 0:r.delete(t)}}onPushToken(t){var e;return this.logger.debug("Registering for Push Token"),(e=this.listeners.get(y.PushToken))==null||e.add(t),()=>{var r;return(r=this.listeners.get(y.PushToken))==null?void 0:r.delete(t)}}onRequestLogsMessage(t){var e;return this.logger.debug("Registering for Request Logs Message"),(e=this.listeners.get(y.RequestLogs))==null||e.add(t),()=>{var r;return(r=this.listeners.get(y.RequestLogs))==null?void 0:r.delete(t)}}evaluateContext(t){if(t==="user")return"host";if(t==="guest")return"standalone"}}C.IPCEvents=y,C.IPCManager=Ut,Object.defineProperty(C,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 c=we(o),a=c.next();!a.done;a=c.next()){var u=a.value;u.remove(this)}}catch(b){t={error:b}}finally{try{a&&!a.done&&(e=c.return)&&e.call(c)}finally{if(t)throw t.error}}else o.remove(this);var h=this.initialTeardown;if(M(h))try{h()}catch(b){i=b instanceof X?b.errors:[b]}var l=this._finalizers;if(l){this._finalizers=null;try{for(var w=we(l),p=w.next();!p.done;p=w.next()){var ne=p.value;try{Ee(ne)}catch(b){i=i??[],b instanceof X?i=K(K([],W(i)),W(b.errors)):i.push(b)}}}catch(b){r={error:b}}finally{try{p&&!p.done&&(s=w.return)&&s.call(w)}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)Ee(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 Ce(n){return n instanceof Z||n&&"closed"in n&&M(n.remove)&&M(n.add)&&M(n.unsubscribe)}function Ee(n){M(n)?n():n.unsubscribe()}var Me={onUnhandledError:null,onStoppedNotification:null,Promise:void 0,useDeprecatedSynchronousErrorHandling:!1,useDeprecatedNextContext:!1},it={setTimeout:function(n,t){for(var e=[],r=2;r<arguments.length;r++)e[r-2]=arguments[r];return setTimeout.apply(void 0,K([n,t],W(e)))},clearTimeout:function(n){return clearTimeout(n)},delegate:void 0};function ot(n){it.setTimeout(function(){throw n})}function Ie(){}function ct(n){n()}var ee=function(n){J(t,n);function t(e){var r=n.call(this)||this;return r.isStopped=!1,e?(r.destination=e,Ce(e)&&e.add(r)):r.destination=ht,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 ut=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){V(r)}},n.prototype.error=function(t){var e=this.partialObserver;if(e.error)try{e.error(t)}catch(r){V(r)}else V(t)},n.prototype.complete=function(){var t=this.partialObserver;if(t.complete)try{t.complete()}catch(e){V(e)}},n}(),re=function(n){J(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 c;i&&Me.useDeprecatedNextContext?(c=Object.create(e),c.unsubscribe=function(){return i.unsubscribe()},o={next:e.next&&te(e.next,c),error:e.error&&te(e.error,c),complete:e.complete&&te(e.complete,c)}):o=e}return i.destination=new ut(o),i}return t}(ee);function V(n){ot(n)}function lt(n){throw n}var ht={closed:!0,next:Ie,error:lt,complete:Ie},dt=function(){return typeof Symbol=="function"&&Symbol.observable||"@@observable"}();function Ue(n){return n}function pt(n){return n.length===0?Ue:n.length===1?n[0]:function(t){return n.reduce(function(e,r){return r(e)},t)}}var ft=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=mt(t)?t:new re(t,e,r);return ct(function(){var o=s,c=o.operator,a=o.source;i.add(c?c.call(i,a):a?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(c){try{t(c)}catch(a){i(a),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[dt]=function(){return this},n.prototype.pipe=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return pt(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??Me.Promise)!==null&&t!==void 0?t:Promise}function gt(n){return n&&M(n.next)&&M(n.error)&&M(n.complete)}function mt(n){return n&&n instanceof ee||gt(n)&&Ce(n)}function _(n,t,e,r,s){return new yt(n,t,e,r,s)}var yt=function(n){J(t,n);function t(e,r,s,i,o,c){var a=n.call(this,e)||this;return a.onFinalize=o,a.shouldUnsubscribe=c,a._next=r?function(u){try{r(u)}catch(h){e.error(h)}}:n.prototype._next,a._error=i?function(u){try{i(u)}catch(h){e.error(h)}finally{this.unsubscribe()}}:n.prototype._error,a._complete=s?function(){try{s()}catch(u){e.error(u)}finally{this.unsubscribe()}}:n.prototype._complete,a}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 f(n,t){return A(function(e,r){var s=0;e.subscribe(_(r,function(i){r.next(n.call(t,i,s++))}))})}var vt=new ft(function(n){return n.complete()});function S(n){return n<=0?function(){return vt}:A(function(t,e){var r=0;t.subscribe(_(e,function(s){++r<=n&&(e.next(s),n<=r&&e.complete())}))})}function m(n,t){return A(function(e,r){var s=0;e.subscribe(_(r,function(i){return n.call(t,i,s++)&&r.next(i)}))})}function bt(n,t){return t===void 0&&(t=!1),A(function(e,r){var s=0;e.subscribe(_(r,function(i){var o=n(i,s++);(o||t)&&r.next(i),!o&&r.complete()}))})}function g(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 c=!0;s.subscribe(_(i,function(a){var u;(u=r.next)===null||u===void 0||u.call(r,a),i.next(a)},function(){var a;c=!1,(a=r.complete)===null||a===void 0||a.call(r),i.complete()},function(a){var u;c=!1,(u=r.error)===null||u===void 0||u.call(r,a),i.error(a)},function(){var a,u;c&&((a=r.unsubscribe)===null||a===void 0||a.call(r)),(u=r.finalize)===null||u===void 0||u.call(r)}))}):Ue}const wt=/^(\d+)\.(\d+)$/;function St(n){if(typeof n=="string"){const t=n.match(wt);if(t)return`${t[1]}.${t[2]}`}throw new rt(n)}function xe(n){const t=St(n),[e,r]=t.split("."),[s,i]=[parseInt(e),parseInt(r)];return[s,i]}function Re(n,t){const[e,r]=xe(n),[s,i]=xe(t);return e<s?-1:e>s?1:r<i?-1:r>i?1:0}function Ct(n,t){return Re(n,t)>=0}const Pe="2.0";class Et{constructor(t,e){if(T(this,"negotiatedProtocolVersion"),T(this,"currentContext"),T(this,"incomingMessages$"),T(this,"inIframe",!1),T(this,"embeddedResult"),T(this,"iframePort1"),T(this,"iframePort2"),this.supportedVersions=t,this.logService=e,this.incomingMessages$=new fe,this.supportedVersions=t.filter(r=>Ct(r,Pe)),!this.supportedVersions.length)throw new be(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 ve("port2");return this.iframePort2}else{if(!((e=(t=window.Acrobits)==null?void 0:t.messageChannel)!=null&&e.port2))throw new ve("port2");return(s=(r=window.Acrobits)==null?void 0:r.messageChannel)==null?void 0:s.port2}}determineContext(){return Xe(1e3).pipe(f(()=>(this.isEmbedded()?this.currentContext="user":this.currentContext="guest",this.currentContext)),S(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(m(s=>s.type===t&&s.replyTo===e.id),f(s=>s),g(this.logReceived()),f(s=>{if(!this.supportedVersions.includes(s.protocolVersion))throw new be(s.protocolVersion,this.supportedVersions[0]);return s.displayName||(s.displayName=s.cloudUsername),s}),g(s=>{this.negotiatedProtocolVersion=s.protocolVersion,this.logService.info(`[IPC] Negotiated IPC Protocol Version: ${this.negotiatedProtocolVersion}`),!s.networkId&&this.compareVersion("2.2")>=0&&this.logService.error(`[IPC] Network ID is not set in the HELLO message reply. 'networkId' is required for protocol version ${this.negotiatedProtocolVersion}, and the client may derive an incorrect network ID from the cloudId.`)}),S(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(m(s=>s.type===t&&s.replyTo===e.id),f(s=>s),g(this.logReceived()),S(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:c,joinMicMuted:a,joinWithoutCamera:u}=t,h="JOINING ROOM",l=this.createMessage(h,!1);l.roomName=e,l.jwtToken=i,l.serverUrl=o,l.region=c,l.roomInvite=r,l.joinMicMuted=a??!1,l.joinWithoutCamera=u??!1,l.displayName=s,this.logCreated(h,l),this.port2.postMessage(l),this.logSent(h,l)}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(m(e=>e.type===t&&e.target==="client"),f(e=>e),g(this.logReceived()),f(e=>e))}onLeaveRoomMessage(){if(!this.isEmbedded())throw new d(this.currentContext);const t="LEAVE ROOM";return this.incomingMessages$.pipe(m(e=>e.type===t&&e.target==="client"),f(e=>e),g(this.logReceived()),f(e=>e))}onConfigMessage(){if(!this.isEmbedded())throw new d(this.currentContext);const t="CONFIG";return this.incomingMessages$.pipe(m(e=>e.type===t&&e.target==="client"),f(e=>e),g(this.logReceived()),f(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]:[],timeFormat:e.timeFormat??"default"})))}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(m(i=>i.type===e&&i.replyTo===r.id),f(i=>i),g(this.logReceived()),f(i=>i),S(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(m(c=>c.type===s&&c.replyTo===i.id),f(c=>c),g(this.logReceived()),f(c=>c),S(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(m(e=>e.type===t&&e.target==="client"&&e.replyTo===null),f(e=>e),g(this.logReceived()),f(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(m(i=>i.type===e&&i.replyTo===r.id),f(i=>i),g(this.logReceived()),S(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(this.negotiatedProtocolVersion==="2.0"){if(e===void 0||typeof e=="object")throw new v("streamType",e,"streamType is missing or invalid");if(r===void 0||typeof r=="object"||typeof r=="number")throw new v("contactType",r,"contactType is missing or invalid");return this.selectContactsV2_0(t,e,r,s)}if(typeof e<"u"&&typeof e!="object")throw new v("options",e,"options is invalid");if(typeof r<"u"&&!Array.isArray(r))throw new v("currentContacts",r,"currentContacts is invalid");return this.selectContactsV2_1(t,e,r)}selectContactsV2_0(t,e,r,s){if(!this.isEmbedded())throw new d(this.currentContext);s&&s.length>0&&(s=s.map(a=>a.type==="cloudUsername"&&a.contactUser?{...a,cloudId:a.cloudId||a.contactUser.cloudId,networkId:a.networkId||a.contactUser.networkId,cloudUsername:a.cloudUsername||a.contactUser.cloudUsername}:a));const i="SELECT CONTACTS",o=this.createMessage(i,!0);o.streamId=t,o.streamType=e,o.contactType=r,o.resultTypes=[r],o.currentContacts=s,this.logCreated(i,o);const c=this.incomingMessages$.pipe(m(a=>a.type===i&&a.replyTo===o.id),g(this.logReceived()),f(a=>{const u=a;if(u.result==="success"){if(u.streamId!==t)throw new ye(u.streamId,t);e==="direct"&&u.contacts.length>1&&(u.contacts=[u.contacts[0]])}return u}),S(1));return this.logService.debug(`Created ${i} Reply handler`),this.port2.postMessage(o),this.logSent(i,o),c}selectContactsV2_1(t,e,r){if(!this.isEmbedded())throw new d(this.currentContext);const s={allowMultipleSelection:(e==null?void 0:e.allowMultipleSelection)??!1,resultTypes:(e==null?void 0:e.resultTypes)??["cloudUsername"]};if(r&&r.length>0)for(const a of r){if(a.contactId===void 0)throw new v("currentContacts",r,"ContactItem contactId is required since v2.1 on all contacts");if(a.type==="cloudUsername"){if(!a.contactUser)throw new v("currentContacts",a,"CloudUsername contact must include contactUser since v2.1");if(!a.contactUser.cloudId||!a.contactUser.networkId||!a.contactUser.cloudUsername)throw new v("currentContacts",a,"CloudContact must define cloudUsername, cloudId, and networkId since v2.1")}}const i="SELECT CONTACTS",o=this.createMessage(i,!0);o.streamId=t,o.resultTypes=s.resultTypes,o.currentContacts=r,o.allowMultipleSelection=s.allowMultipleSelection,this.logCreated(i,o);const c=this.incomingMessages$.pipe(m(a=>a.type===i&&a.replyTo===o.id),g(this.logReceived()),f(a=>{const u=a;if(u.result==="success"){if(u.streamId!==t)throw new ye(u.streamId,t);const h=u.contacts.length;u.contacts=u.contacts.filter(l=>s.resultTypes.includes(l.type)),u.contacts.length!==h&&this.logService.debug(`[IPC] [SelectContactsReply] Filtered ${h-u.contacts.length} contacts from reply`),!s.allowMultipleSelection&&u.contacts.length>1&&(u.contacts=[u.contacts[0]]);for(const l of u.contacts){if(l.type==="cloudUsername"){if(!l.contactUser)throw new Error(`CloudUsername contact must include contactUser since v2.1. ContactItem: ${JSON.stringify(l)}`);if(!l.contactUser.cloudId||!l.contactUser.networkId||!l.contactUser.cloudUsername)throw new Error(`CloudContact must define cloudUsername, cloudId, and networkId since v2.1. ContactItem: ${JSON.stringify(l)}`)}this.negotiatedProtocolVersion==="2.2"&&(l.type==="number"&&l.numbers.length>1?l.numbers=[l.numbers[0]]:l.type==="email"&&l.emails.length>1&&(l.emails=[l.emails[0]]))}}return u}),S(1));return this.logService.debug(`Created ${i} Reply handler`),this.port2.postMessage(o),this.logSent(i,o),c}matchContacts(t){if(!this.isEmbedded())throw new d(this.currentContext);if(!Array.isArray(t))throw new v("contacts",t,"contacts is not an array");if(!t.length)throw new v("contacts",t,"At least one contact is required");const e=this.createMessage("MATCH CONTACTS");if(this.compareVersion("2.1")>=0){for(const s of t)if(s.type==="cloudUsername"){if(!s.contactUser)throw new v("contacts",s,"CloudUsername contact must include contactUser");if(!s.contactUser.cloudUsername||!s.contactUser.cloudId||!s.contactUser.networkId)throw new v("contacts",s,"CloudContact must define cloudUsername, cloudId, and networkId")}e.contacts=[...t]}else{for(const s of t)s.type==="cloudUsername"&&s.contactUser&&(s.cloudId=s.contactUser.cloudId,s.networkId=s.contactUser.networkId,s.cloudUsername=s.contactUser.cloudUsername);e.contacts=[...t]}this.logCreated(e.type,e);const r=this.incomingMessages$.pipe(m(s=>s.type===e.type&&s.replyTo===e.id),g(this.logReceived()),f(s=>{const i=s;if(this.compareVersion("2.1")>=0){if(Array.isArray(i.contacts))throw new Error("MatchContactsMessageReply should return a Record<string, DetailedContactItem> of contacts when using IPC Protocol v2.1+");for(const[o,c]of Object.entries(i.contacts)){if(c==null){this.logService.debug(`[IPC] [MatchContactsReply] Received null or undefined contact for ${o}`);continue}if(c.contactId===void 0)throw new Error(`ContactItem 'contactId' is required since v2.1. ContactItem: ${JSON.stringify(c)}`);if(!c.contactUser&&(!c.uri||c.uri.length===0)&&(!c.numbers||c.numbers.length===0))throw new Error(`DetailedContactItem must define at least one contact method (contactUser, uri, or numbers). ContactItem: ${JSON.stringify(c)}`);if(c.contactUser&&(!c.contactUser.cloudId||!c.contactUser.networkId||!c.contactUser.cloudUsername))throw new Error(`When contactUser is defined, cloudId, networkId, and cloudUsername must also be defined. ContactItem: ${JSON.stringify(c)}`)}}else{if(!Array.isArray(i.contacts))throw new Error("MatchContactsMessageReply should return an array of contacts when using IPC Protocol v2.0");if(i.contacts.length!==e.contacts.length)throw new Error("The number of contacts in the reply does not match the number of contacts in the request");for(const o of i.contacts){const c=o;if(c.type==="cloudUsername"&&!("cloudUsername"in c))throw new Error(`CloudUsernameDetailedContactItem must define cloudUsername. ContactItem: ${JSON.stringify(o)}`);if(c.type==="uri"&&(!("uri"in c)||!Array.isArray(c.uri)))throw new Error(`UriDetailedContactItem must define uri as an array. ContactItem: ${JSON.stringify(o)}`)}}return i}),S(1));return this.logService.debug(`Created ${e.type} Reply handler`),this.port2.postMessage(e),this.logSent(e.type,e),r}onPushMessageMessage(){if(!this.isEmbedded())throw new d(this.currentContext);const t="PUSH MESSAGE";return this.incomingMessages$.pipe(m(e=>e.type===t&&e.target==="client"),f(e=>e),g(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(m(s=>s.type===t&&s.replyTo===e.id),g(this.logReceived()),f(s=>s),S(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(m(e=>e.type===t&&e.target==="client"&&e.replyTo===null&&e.expectReply===!1),f(e=>{if(e.pushToken&&e.selector&&e.appId)return e;throw new Error("PushTokenMessage is missing required PushTokenPayload fields")}),g(e=>e.pushToken),g(this.logReceived()))}onBadgeQueryMessage(){if(!this.isEmbedded())throw new d(this.currentContext);const t="BADGE QUERY";return this.incomingMessages$.pipe(m(e=>e.type===t&&e.target==="client"),f(e=>e),g(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(m(e=>e.type===t&&e.target==="client"),f(e=>e),g(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(m(e=>e.type===t&&e.target==="client"),f(e=>e),g(this.logReceived()))}sendRequestLogsMessageReply(t,e,r,s,i){if(!this.isEmbedded())throw new d(this.currentContext);const o="REQUEST LOGS",c=this.createMessage(o,!1,i);c.fileId=t,c.fileHash=e,c.fileSize=r,c.format=s,this.logCreated(o,c),this.port2.postMessage(c),this.logSent(o,c)}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",c=this.createMessage(o);if(c.fileId=t,c.fileHash=e.toLowerCase(),c.intent=r,c.maxChunkSizeInBytes=i,r==="attachment"){if(!s)throw new v("streamId",s,"streamId is required for attachment intent");c.streamId=s}this.logCreated(o,c);let a=0;const u=this.incomingMessages$.pipe(m(h=>h.type===o&&h.replyTo===c.id),g(this.logReceived()),g(()=>a++),f(h=>(h.result==="success"&&(h.chunkHash=h.chunkHash.toLowerCase(),h.fileHash=h.fileHash.toLowerCase()),h)),bt(h=>h.result==="success"&&a<h.totalChunks,!0));return this.port2.postMessage(c),this.logSent(o,c),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(m(e=>e.type===t&&e.target==="client"&&e.replyTo===null),f(e=>(e.fileHash=e.fileHash.toLowerCase(),e)),g(this.logReceived()))}sendFileSelectionMessage(t="attachment",e,r,s,i,o){if(!this.isEmbedded())throw new d(this.currentContext);const c="FILE SELECTION",a=this.createMessage(c);if(a.intent=t,a.maxCount=s,a.maxFileSizeInBytes=i,a.mimeTypes=o,t==="attachment"){if(!e)throw new v("streamId",e,"streamId is required for attachment intent");if(!r)throw new v("correlationId",r,"correlationId is required for attachment intent");a.streamId=e,a.correlationId=r}this.logCreated(c,a);const u=this.incomingMessages$.pipe(m(h=>h.type===c&&h.replyTo===a.id),f(h=>{var l;return h.result==="success"&&(h.files=(l=h.files)==null?void 0:l.map(w=>(w.original.fileHash=w.original.fileHash.toLowerCase(),w.preview&&(w.preview.fileHash=w.preview.fileHash.toLowerCase()),w))),h}),g(this.logReceived()),S(1));return this.port2.postMessage(a),this.logSent(c,a),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(m(c=>c.type==="FILE DOWNLOAD PROGRESS UPDATE"&&c.replyTo===i.id),g(c=>this.logReceived(c)),f(c=>(c.fileHash&&(c.fileHash=c.fileHash.toLowerCase()),c)),S(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(m(e=>e.type===t&&e.target==="client"&&e.replyTo===null),f(e=>(e.fileHash&&(e.fileHash=e.fileHash.toLowerCase()),e)),g(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(m(c=>c.type==="FILE UPLOAD PROGRESS UPDATE"&&c.replyTo===i.id),g(this.logReceived()),f(c=>(c.fileHash&&(c.fileHash=c.fileHash.toLowerCase()),c)),S(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(m(e=>e.type===t&&e.target==="client"&&e.replyTo===null),f(e=>(e.fileHash&&(e.fileHash=e.fileHash.toLowerCase()),e)),g(this.logReceived()))}sendFileDownloadMessage(t,e,r,s,i,o,c,a,u){if(!this.isEmbedded())throw new d(this.currentContext);if(a&&this.compareVersion("2.1")<0)a.type==="cloudUsername"&&a.contactUser&&(a={...a,cloudId:a.cloudId||a.contactUser.cloudId,networkId:a.networkId||a.contactUser.networkId,cloudUsername:a.cloudUsername||a.contactUser.cloudUsername});else if(a&&this.compareVersion("2.1")>=0&&a.type==="cloudUsername"){if(!a.contactUser)throw new v("sender",a,"CloudUsername contact must include contactUser since v2.1");if(!a.contactUser.cloudId||!a.contactUser.networkId||!a.contactUser.cloudUsername)throw new v("sender",a,"CloudContact must define cloudUsername, cloudId, and networkId since v2.1")}const h="FILE DOWNLOAD",l=this.createMessage(h,!0);l.url=t,l.key=e,l.fileHash=r.toLowerCase(),l.mimeType=s,l.fileName=i,l.streamId=o,l.correlationId=c,l.sender=a,l.intent=u??"download",this.logCreated(h,l);const w=this.incomingMessages$.pipe(m(p=>p.type===h&&p.replyTo===l.id),g(this.logReceived()),f(p=>p),S(1));return this.port2.postMessage(l),this.logSent(h,l),w}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(m(o=>o.type===r&&o.replyTo===s.id),g(this.logReceived()),f(o=>o),S(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,c,a=!0,u){if(!this.isEmbedded())throw new d(this.currentContext);const h="SEND MESSAGE",l=this.createMessage(h,!0);if(l.streamId=t,l.correlationId=e,l.body=r,l.messageType=s,i&&i.length>0)if(this.compareVersion("2.1")<0)l.mentions=i.map(p=>p.contactUser?{...p,cloudId:p.cloudId||p.contactUser.cloudId,networkId:p.networkId||p.contactUser.networkId,cloudUsername:p.cloudUsername||p.contactUser.cloudUsername}:p);else{for(const p of i){if(p.type==="cloudUsername"&&!p.contactUser)throw new v("mentions",p,"CloudUsername mention must include contactUser");if(p.contactUser&&(!p.contactUser.cloudId||!p.contactUser.networkId||!p.contactUser.cloudUsername))throw new v("mentions",p,"CloudContact must define cloudUsername, cloudId, and networkId")}l.mentions=i}else l.mentions=[];l.attachments=(o==null?void 0:o.map(p=>p.toLowerCase()))??[],l.relatedMessageId=c,l.setCursors=a,l.threadId=u,this.logCreated(h,l);const w=this.incomingMessages$.pipe(m(p=>p.type===h&&p.replyTo===l.id),g(this.logReceived()),f(p=>p),S(1));return this.port2.postMessage(l),this.logSent(h,l),w}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(m(o=>o.type==="SEND MESSAGE STATUS UPDATE"&&o.replyTo===s.id),g(this.logReceived()),f(o=>o),S(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(m(e=>e.type===t&&e.target==="client"&&e.replyTo===null),f(e=>e),g(this.logReceived()))}sendSipCallMessage(t){if(!this.isEmbedded())throw new d(this.currentContext);if(this.compareVersion("2.1")<0)t.type==="cloudUsername"&&t.contactUser&&(t={...t,cloudId:t.cloudId||t.contactUser.cloudId,networkId:t.networkId||t.contactUser.networkId,cloudUsername:t.cloudUsername||t.contactUser.cloudUsername});else if(t.type==="cloudUsername"){if(!t.contactUser)throw new v("contact",t,"CloudUsername contact must include contactUser since v2.1");if(!t.contactUser.cloudId||!t.contactUser.networkId||!t.contactUser.cloudUsername)throw new v("contact",t,"CloudContact must define cloudUsername, cloudId, and networkId since v2.1")}const e="SIP CALL",r=this.createMessage(e,!1);r.contact=t,this.logCreated(e,r),this.port2.postMessage(r),this.logSent(e,r)}sendCustomFunctionMessage(t,e){if(!this.isEmbedded())throw new d(this.currentContext);const r="CUSTOM FUNCTION",s=this.createMessage(r,!1);s.customFunctionId=t,s.context=e,this.logCreated(r,s),this.port2.postMessage(s),this.logSent(r,s)}sendSubscribeButtonsMessage(t){if(!this.isEmbedded())throw new d(this.currentContext);const e="SUBSCRIBE BUTTONS",r=this.createMessage(e,!1);r.subscribe=t,this.logCreated(e,r),this.port2.postMessage(r),this.logSent(e,r)}onButtonsMessage(){if(!this.isEmbedded())throw new d(this.currentContext);const t="BUTTONS";return this.incomingMessages$.pipe(m(e=>e.type===t&&e.target==="client"),f(e=>e),g(this.logReceived()))}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 Re(this.negotiatedProtocolVersion,t)}logReceived(t){const e=r=>this.logService.debug(`[IPC] Received ${r.type} message${r.replyTo?" reply":""}`,r);if(t){Mt(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 Mt(n){return n.type==="FILE REQUEST"&&n.replyTo!==null}const It=["2.0","2.1"];class Ut{constructor(t){x(this,"host");x(this,"cloudId");x(this,"cloudUsername");x(this,"displayName");x(this,"logger");x(this,"helper");x(this,"listeners");this.logger=t??console,this.helper=new Et(It,this.logger),this.listeners=new Map,this.listeners.set(y.BadgeQuery,new Set),this.listeners.set(y.Lifecycle,new Set),this.listeners.set(y.PushToken,new Set),this.listeners.set(y.RequestLogs,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 P(this.helper.determineContext(),{defaultValue:"guest"});return this.evaluateContext(t)}initiateConnection(){return P(this.helper.openBridge().pipe(Ze(t=>{this.helper.onBadgeQueryMessage().subscribe(e=>{var r;this.logger.debug("Received Badge Query: ",e);for(const s of((r=this.listeners.get(y.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(y.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(y.PushToken))==null?void 0:r.values())??[])s(e.pushToken,e.appId,e.selector)}),this.helper.onRequestLogsMessage().subscribe(e=>{var r;if(this.logger.debug("Received Request Logs Message: ",e),e.responseType==="file")throw this.logger.error("File response type not supported"),new Error("File response type not supported");for(const s of((r=this.listeners.get(y.RequestLogs))==null?void 0:r.values())??[])s(e.skipCompression)}),this.cloudId=t.cloudId,this.cloudUsername=t.cloudUsername,this.displayName=t.displayName,this.host=t.host}),F(()=>{})))}selectContacts(t,e,r,s){this.logger.debug("Selecting Contacts: ",...arguments);let i;if(this.negotiatedVersion==="2.0"){if(typeof e!="string")throw new v("mode",e,'mode must be "single" or "multi"');if(s==="number")throw new v("contactType",s,'contactType cannot be "number" for version 2.0 of the IPC protocol');i=this.selectContacts_V2_0(t,e??"single",e==="multi"?r:void 0,e==="multi"?s:r)}else{if(typeof e!="object")throw new v("options",e,"options must be an object");i=this.selectContacts_V2_1(t,e)}return P(i.pipe(F(o=>o.result==="error"?{result:"error",errorMessage:o.errorMessage}:o.result==="cancelled"?{result:"cancelled"}:o.contacts)))}selectContacts_V2_0(t,e,r,s){if(this.logger.debug("Selecting Contacts: ",...arguments),e==="multi"){if(!r||!Array.isArray(r))throw new v("currentContacts",r,"currentContacts is required for group streams");return s||(s="cloudUsername"),this.helper.selectContacts(t.toString(),"group",s,r)}else return s||(s="cloudUsername"),this.helper.selectContacts(t.toString(),"direct",s)}selectContacts_V2_1(t,e){if(this.logger.debug("Selecting Contacts: ",e),e.mode==="multi"&&(!e.currentContacts||!Array.isArray(e.currentContacts)))throw new v("currentContacts",e.currentContacts,"currentContacts is required for group streams");return this.helper.selectContacts(t.toString(),{allowMultipleSelection:e.mode==="multi",resultTypes:e.resultTypes??["cloudUsername"]},e.mode==="multi"?e.currentContacts:void 0)}matchContacts(t){return this.logger.debug("Match Contacts: ",t),P(this.helper.matchContacts(t).pipe(F(e=>e.contacts)))}requestPushToken(){return this.logger.debug("Requesting Push Token"),P(this.helper.requestPushToken().pipe(F(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(y.BadgeQuery))==null||e.add(t),()=>{var r;return(r=this.listeners.get(y.BadgeQuery))==null?void 0:r.delete(t)}}onLifecycleEvent(t){var e;return this.logger.debug("Registering for Lifecycle Event"),(e=this.listeners.get(y.Lifecycle))==null||e.add(t),()=>{var r;return(r=this.listeners.get(y.Lifecycle))==null?void 0:r.delete(t)}}onPushToken(t){var e;return this.logger.debug("Registering for Push Token"),(e=this.listeners.get(y.PushToken))==null||e.add(t),()=>{var r;return(r=this.listeners.get(y.PushToken))==null?void 0:r.delete(t)}}onRequestLogsMessage(t){var e;return this.logger.debug("Registering for Request Logs Message"),(e=this.listeners.get(y.RequestLogs))==null||e.add(t),()=>{var r;return(r=this.listeners.get(y.RequestLogs))==null?void 0:r.delete(t)}}evaluateContext(t){if(t==="user")return"host";if(t==="guest")return"standalone"}}C.IPCEvents=y,C.IPCManager=Ut,Object.defineProperty(C,Symbol.toStringTag,{value:"Module"})});