polfan-server-js-client 0.1.16 → 0.1.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/index.js +1746 -1
- package/build/index.js.map +1 -1
- package/package.json +1 -1
- package/src/ChatStateTracker.ts +1 -0
- package/webpack.config.js +1 -1
package/build/index.js
CHANGED
|
@@ -1,2 +1,1747 @@
|
|
|
1
|
-
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.PServ=e():t.PServ=e()}(self,(()=>(()=>{"use strict";var t={d:(e,r)=>{for(var n in r)t.o(r,n)&&!t.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:r[n]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r:t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},e={};function r(t){return r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},r(t)}function n(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,i(n.key),n)}}function o(t,e,r){return(e=i(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function i(t){var e=function(t,e){if("object"!==r(t)||null===t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var o=n.call(t,e||"default");if("object"!==r(o))return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"===r(e)?e:String(e)}t.r(e),t.d(e,{AuthClient:()=>zt,IndexedCollection:()=>D,IndexedObjectCollection:()=>F,ObservableIndexedCollection:()=>J,ObservableIndexedObjectCollection:()=>B,WebApiChatClient:()=>Lt,WebSocketChatClient:()=>dt});var a=function(){function t(){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),o(this,"events",new Map),o(this,"onceEvents",new Map)}var e,r,i;return e=t,(r=[{key:"on",value:function(t,e){return this.addHandler(this.events,t,e),this}},{key:"once",value:function(t,e){return this.addHandler(this.onceEvents,t,e),this}},{key:"emit",value:function(t,e){return this.callHandlers(this.events,t,e),this.callHandlers(this.onceEvents,t,e),this.onceEvents.delete(t),this}},{key:"addHandler",value:function(t,e,r){var n,o=null!==(n=t.get(e))&&void 0!==n?n:[];o.push(r),t.set(e,o)}},{key:"callHandlers",value:function(t,e,r){var n;null===(n=t.get(e))||void 0===n||n.forEach((function(t){return t(r)}))}}])&&n(e.prototype,r),i&&n(e,i),Object.defineProperty(e,"prototype",{writable:!1}),t}();function c(t){return c="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},c(t)}function u(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function s(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,g(n.key),n)}}function l(){return l="undefined"!=typeof Reflect&&Reflect.get?Reflect.get.bind():function(t,e,r){var n=f(t,e);if(n){var o=Object.getOwnPropertyDescriptor(n,e);return o.get?o.get.call(arguments.length<3?t:r):o.value}},l.apply(this,arguments)}function f(t,e){for(;!Object.prototype.hasOwnProperty.call(t,e)&&null!==(t=v(t)););return t}function h(t,e){return h=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},h(t,e)}function p(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}();return function(){var r,n=v(t);if(e){var o=v(this).constructor;r=Reflect.construct(n,arguments,o)}else r=n.apply(this,arguments);return d(this,r)}}function d(t,e){if(e&&("object"===c(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return y(t)}function y(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function v(t){return v=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},v(t)}function m(t,e,r){return(e=g(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function g(t){var e=function(t,e){if("object"!==c(t)||null===t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var n=r.call(t,e||"default");if("object"!==c(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"===c(e)?e:String(e)}var b=function(t){!function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&h(t,e)}(i,t);var e,r,n,o=p(i);function i(){var t;u(this,i);for(var e=arguments.length,r=new Array(e),n=0;n<e;n++)r[n]=arguments[n];return m(y(t=o.call.apply(o,[this].concat(r))),"awaitingResponse",new Map),m(y(t),"sentCounter",0),t}return e=i,r=[{key:"on",value:function(t,e){return l(v(i.prototype),"on",this).call(this,t,e)}},{key:"once",value:function(t,e){return l(v(i.prototype),"once",this).call(this,t,e)}},{key:"createEnvelope",value:function(t,e){return{type:t,data:e,ref:(++this.sentCounter).toString()}}},{key:"createPromiseFromCommandEnvelope",value:function(t){var e=this;return new Promise((function(){for(var r=arguments.length,n=new Array(r),o=0;o<r;o++)n[o]=arguments[o];return e.awaitingResponse.set(t.ref,n)}))}},{key:"handleIncomingEnvelope",value:function(t){if(this.awaitingResponse.has(t.ref)){var e="Error"===t.type;this.awaitingResponse.get(t.ref)[0]({data:e?null:t.data,error:e?t.data:null}),this.awaitingResponse.delete(t.ref)}}},{key:"handleEnvelopeSendError",value:function(t,e){this.awaitingResponse.has(t.ref)&&(this.awaitingResponse.get(t.ref)[0](e),this.awaitingResponse.delete(t.ref))}}],r&&s(e.prototype,r),n&&s(e,n),Object.defineProperty(e,"prototype",{writable:!1}),i}(a);function w(t){return w="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},w(t)}function k(){return k="undefined"!=typeof Reflect&&Reflect.get?Reflect.get.bind():function(t,e,r){var n=S(t,e);if(n){var o=Object.getOwnPropertyDescriptor(n,e);return o.get?o.get.call(arguments.length<3?t:r):o.value}},k.apply(this,arguments)}function S(t,e){for(;!Object.prototype.hasOwnProperty.call(t,e)&&null!==(t=P(t)););return t}function E(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&j(t,e)}function j(t,e){return j=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},j(t,e)}function x(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}();return function(){var r,n=P(t);if(e){var o=P(this).constructor;r=Reflect.construct(n,arguments,o)}else r=n.apply(this,arguments);return O(this,r)}}function O(t,e){if(e&&("object"===w(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return L(t)}function L(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function P(t){return P=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},P(t)}function _(t,e){var r="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!r){if(Array.isArray(t)||(r=T(t))||e&&t&&"number"==typeof t.length){r&&(t=r);var n=0,o=function(){};return{s:o,n:function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}},e:function(t){throw t},f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,a=!0,c=!1;return{s:function(){r=r.call(t)},n:function(){var t=r.next();return a=t.done,t},e:function(t){c=!0,i=t},f:function(){try{a||null==r.return||r.return()}finally{if(c)throw i}}}}function R(t){return function(t){if(Array.isArray(t))return I(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||T(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function T(t,e){if(t){if("string"==typeof t)return I(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?I(t,e):void 0}}function I(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r<e;r++)n[r]=t[r];return n}function M(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function A(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,C(n.key),n)}}function N(t,e,r){return e&&A(t.prototype,e),r&&A(t,r),Object.defineProperty(t,"prototype",{writable:!1}),t}function G(t,e,r){return(e=C(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function C(t){var e=function(t,e){if("object"!==w(t)||null===t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var n=r.call(t,e||"default");if("object"!==w(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"===w(e)?e:String(e)}var D=function(){function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];M(this,t),G(this,"_items",new Map),this.set.apply(this,R(e))}return N(t,[{key:"items",get:function(){return this._items}},{key:"length",get:function(){return this._items.size}},{key:"set",value:function(){for(var t=arguments.length,e=new Array(t),r=0;r<t;r++)e[r]=arguments[r];for(var n=0,o=e;n<o.length;n++){var i=o[n];this._items.set(i[0],i[1])}}},{key:"get",value:function(t){return this.items.get(t)}},{key:"has",value:function(t){return this.items.has(t)}},{key:"delete",value:function(){for(var t=arguments.length,e=new Array(t),r=0;r<t;r++)e[r]=arguments[r];for(var n=0,o=e;n<o.length;n++){var i=o[n];this.items.delete(i)}}},{key:"deleteAll",value:function(){this.items.clear()}},{key:"findBy",value:function(e,r){for(var n,o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,i=new t;!((n=this.items.entries().next().value).done||o&&i.length===o);)n[1][e]===r&&i.set(n);return i}},{key:"map",value:function(t){return Array.from(this.items.entries()).map((function(e){return t(e[1],e[0])}))}}]),t}(),F=function(){function t(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[];M(this,t),this.id=e,G(this,"_items",void 0),this._items=new D,this.set.apply(this,R(r))}return N(t,[{key:"items",get:function(){return Array.from(this._items.items.values())}},{key:"length",get:function(){return this._items.length}},{key:"set",value:function(){for(var t,e=this,r=arguments.length,n=new Array(r),o=0;o<r;o++)n[o]=arguments[o];(t=this._items).set.apply(t,R(n.map((function(t){return[e.getId(t),t]}))))}},{key:"get",value:function(t){return this._items.get(t)}},{key:"getAt",value:function(t){return this.items[t]}},{key:"has",value:function(t){return this._items.has(t)}},{key:"delete",value:function(){var t;(t=this._items).delete.apply(t,arguments)}},{key:"deleteAll",value:function(){this._items.deleteAll()}},{key:"findBy",value:function(e,r){var n,o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,i=new t(this.id),a=_(this.items);try{for(a.s();!(n=a.n()).done;){var c=n.value;if(o&&i.length===o)break;c[e]===r&&i.set(c)}}catch(t){a.e(t)}finally{a.f()}return i}},{key:"map",value:function(t){return this.items.map(t)}},{key:"getId",value:function(t){return"function"==typeof this.id?this.id(t):t[this.id]}}]),t}(),J=function(t){E(r,t);var e=x(r);function r(){var t,n,o=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];return M(this,r),G(L(n=e.call(this)),"eventTarget",void 0),n.eventTarget=new a,(t=n).set.apply(t,R(o)),n}return N(r,[{key:"set",value:function(){for(var t=arguments.length,e=new Array(t),n=0;n<t;n++)e[n]=arguments[n];var o;e.length&&((o=k(P(r.prototype),"set",this)).call.apply(o,[this].concat(e)),this.eventTarget.emit("change",{setItems:e.map((function(t){return t[0]}))}))}},{key:"delete",value:function(){for(var t=arguments.length,e=new Array(t),n=0;n<t;n++)e[n]=arguments[n];var o;e.length&&((o=k(P(r.prototype),"delete",this)).call.apply(o,[this].concat(e)),this.eventTarget.emit("change",{deletedItems:e}))}},{key:"deleteAll",value:function(){if(this.length){var t=this._items.keys();k(P(r.prototype),"deleteAll",this).call(this),this.eventTarget.emit("change",{deletedItems:Array.from(t)})}}},{key:"on",value:function(t,e){return this.eventTarget.on(t,e),this}},{key:"once",value:function(t,e){return this.eventTarget.once(t,e),this}}]),r}(D),B=function(t){E(r,t);var e=x(r);function r(t){var n,o,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[];return M(this,r),(o=e.call(this,t)).id=t,G(L(o),"eventTarget",void 0),o.eventTarget=new a,(n=o).set.apply(n,R(i)),o}return N(r,[{key:"set",value:function(){for(var t,e=this,n=arguments.length,o=new Array(n),i=0;i<n;i++)o[i]=arguments[i];o.length&&((t=k(P(r.prototype),"set",this)).call.apply(t,[this].concat(o)),this.eventTarget.emit("change",{setItems:o.map((function(t){return e.getId(t)}))}))}},{key:"delete",value:function(){for(var t=arguments.length,e=new Array(t),n=0;n<t;n++)e[n]=arguments[n];var o;e.length&&((o=k(P(r.prototype),"delete",this)).call.apply(o,[this].concat(e)),this.eventTarget.emit("change",{deletedItems:e}))}},{key:"deleteAll",value:function(){if(this.length){var t=this._items.items.keys();k(P(r.prototype),"deleteAll",this).call(this),this.eventTarget.emit("change",{deletedItems:Array.from(t)})}}},{key:"on",value:function(t,e){return this.eventTarget.on(t,e),this}},{key:"once",value:function(t,e){return this.eventTarget.once(t,e),this}}]),r}(F);function U(t){return U="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},U(t)}function Y(t){return function(t){if(Array.isArray(t))return Q(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||function(t,e){if(!t)return;if("string"==typeof t)return Q(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);"Object"===r&&t.constructor&&(r=t.constructor.name);if("Map"===r||"Set"===r)return Array.from(t);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return Q(t,e)}(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function Q(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r<e;r++)n[r]=t[r];return n}function H(){/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */H=function(){return t};var t={},e=Object.prototype,r=e.hasOwnProperty,n=Object.defineProperty||function(t,e,r){t[e]=r.value},o="function"==typeof Symbol?Symbol:{},i=o.iterator||"@@iterator",a=o.asyncIterator||"@@asyncIterator",c=o.toStringTag||"@@toStringTag";function u(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{u({},"")}catch(t){u=function(t,e,r){return t[e]=r}}function s(t,e,r,o){var i=e&&e.prototype instanceof h?e:h,a=Object.create(i.prototype),c=new x(o||[]);return n(a,"_invoke",{value:k(t,r,c)}),a}function l(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}t.wrap=s;var f={};function h(){}function p(){}function d(){}var y={};u(y,i,(function(){return this}));var v=Object.getPrototypeOf,m=v&&v(v(O([])));m&&m!==e&&r.call(m,i)&&(y=m);var g=d.prototype=h.prototype=Object.create(y);function b(t){["next","throw","return"].forEach((function(e){u(t,e,(function(t){return this._invoke(e,t)}))}))}function w(t,e){function o(n,i,a,c){var u=l(t[n],t,i);if("throw"!==u.type){var s=u.arg,f=s.value;return f&&"object"==U(f)&&r.call(f,"__await")?e.resolve(f.__await).then((function(t){o("next",t,a,c)}),(function(t){o("throw",t,a,c)})):e.resolve(f).then((function(t){s.value=t,a(s)}),(function(t){return o("throw",t,a,c)}))}c(u.arg)}var i;n(this,"_invoke",{value:function(t,r){function n(){return new e((function(e,n){o(t,r,e,n)}))}return i=i?i.then(n,n):n()}})}function k(t,e,r){var n="suspendedStart";return function(o,i){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===o)throw i;return L()}for(r.method=o,r.arg=i;;){var a=r.delegate;if(a){var c=S(a,r);if(c){if(c===f)continue;return c}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if("suspendedStart"===n)throw n="completed",r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n="executing";var u=l(t,e,r);if("normal"===u.type){if(n=r.done?"completed":"suspendedYield",u.arg===f)continue;return{value:u.arg,done:r.done}}"throw"===u.type&&(n="completed",r.method="throw",r.arg=u.arg)}}}function S(t,e){var r=e.method,n=t.iterator[r];if(void 0===n)return e.delegate=null,"throw"===r&&t.iterator.return&&(e.method="return",e.arg=void 0,S(t,e),"throw"===e.method)||"return"!==r&&(e.method="throw",e.arg=new TypeError("The iterator does not provide a '"+r+"' method")),f;var o=l(n,t.iterator,e.arg);if("throw"===o.type)return e.method="throw",e.arg=o.arg,e.delegate=null,f;var i=o.arg;return i?i.done?(e[t.resultName]=i.value,e.next=t.nextLoc,"return"!==e.method&&(e.method="next",e.arg=void 0),e.delegate=null,f):i:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,f)}function E(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function j(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function x(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(E,this),this.reset(!0)}function O(t){if(t){var e=t[i];if(e)return e.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var n=-1,o=function e(){for(;++n<t.length;)if(r.call(t,n))return e.value=t[n],e.done=!1,e;return e.value=void 0,e.done=!0,e};return o.next=o}}return{next:L}}function L(){return{value:void 0,done:!0}}return p.prototype=d,n(g,"constructor",{value:d,configurable:!0}),n(d,"constructor",{value:p,configurable:!0}),p.displayName=u(d,c,"GeneratorFunction"),t.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===p||"GeneratorFunction"===(e.displayName||e.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,d):(t.__proto__=d,u(t,c,"GeneratorFunction")),t.prototype=Object.create(g),t},t.awrap=function(t){return{__await:t}},b(w.prototype),u(w.prototype,a,(function(){return this})),t.AsyncIterator=w,t.async=function(e,r,n,o,i){void 0===i&&(i=Promise);var a=new w(s(e,r,n,o),i);return t.isGeneratorFunction(r)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},b(g),u(g,c,"Generator"),u(g,i,(function(){return this})),u(g,"toString",(function(){return"[object Generator]"})),t.keys=function(t){var e=Object(t),r=[];for(var n in e)r.push(n);return r.reverse(),function t(){for(;r.length;){var n=r.pop();if(n in e)return t.value=n,t.done=!1,t}return t.done=!0,t}},t.values=O,x.prototype={constructor:x,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(j),!t)for(var e in this)"t"===e.charAt(0)&&r.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=void 0)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var e=this;function n(r,n){return a.type="throw",a.arg=t,e.next=r,n&&(e.method="next",e.arg=void 0),!!n}for(var o=this.tryEntries.length-1;o>=0;--o){var i=this.tryEntries[o],a=i.completion;if("root"===i.tryLoc)return n("end");if(i.tryLoc<=this.prev){var c=r.call(i,"catchLoc"),u=r.call(i,"finallyLoc");if(c&&u){if(this.prev<i.catchLoc)return n(i.catchLoc,!0);if(this.prev<i.finallyLoc)return n(i.finallyLoc)}else if(c){if(this.prev<i.catchLoc)return n(i.catchLoc,!0)}else{if(!u)throw new Error("try statement without catch or finally");if(this.prev<i.finallyLoc)return n(i.finallyLoc)}}}},abrupt:function(t,e){for(var n=this.tryEntries.length-1;n>=0;--n){var o=this.tryEntries[n];if(o.tryLoc<=this.prev&&r.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var i=o;break}}i&&("break"===t||"continue"===t)&&i.tryLoc<=e&&e<=i.finallyLoc&&(i=null);var a=i?i.completion:{};return a.type=t,a.arg=e,i?(this.method="next",this.next=i.finallyLoc,f):this.complete(a)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),f},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),j(r),f}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var o=n.arg;j(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,r){return this.delegate={iterator:O(t),resultName:e,nextLoc:r},"next"===this.method&&(this.arg=void 0),f}},t}function z(t,e,r,n,o,i,a){try{var c=t[i](a),u=c.value}catch(t){return void r(t)}c.done?e(u):Promise.resolve(u).then(n,o)}function $(t){return function(){var e=this,r=arguments;return new Promise((function(n,o){var i=t.apply(e,r);function a(t){z(i,n,o,a,c,"next",t)}function c(t){z(i,n,o,a,c,"throw",t)}a(void 0)}))}}function W(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,K(n.key),n)}}function q(t,e,r){return(e=K(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function K(t){var e=function(t,e){if("object"!==U(t)||null===t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var n=r.call(t,e||"default");if("object"!==U(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"===U(e)?e:String(e)}var V,X=function(){function t(e){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.client=e,q(this,"joinedSpaces",new B("id")),q(this,"joinedRooms",new B("id")),q(this,"spacesRoles",new D),q(this,"roomsTopics",new D),q(this,"topicsMessages",new D),q(this,"spacesRooms",new D),q(this,"spacesMembers",new D),q(this,"roomsMembers",new D),q(this,"deferredGetters",new D),q(this,"reconnecting",!1),q(this,"me",null),this.bind()}var e,r,n,o,i,a,c,u,s,l,f,h,p;return e=t,r=[{key:"getMe",value:(p=$(H().mark((function t(){return H().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.deferredGetterReadiness("session");case 2:return t.abrupt("return",this.me);case 3:case"end":return t.stop()}}),t,this)}))),function(){return p.apply(this,arguments)})},{key:"getJoinedSpaces",value:(h=$(H().mark((function t(){return H().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.deferredGetterReadiness("session");case 2:return t.abrupt("return",this.joinedSpaces);case 3:case"end":return t.stop()}}),t,this)}))),function(){return h.apply(this,arguments)})},{key:"getJoinedRooms",value:(f=$(H().mark((function t(){return H().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.deferredGetterReadiness("session");case 2:return t.abrupt("return",this.joinedRooms);case 3:case"end":return t.stop()}}),t,this)}))),function(){return f.apply(this,arguments)})},{key:"getSpaceRoles",value:(l=$(H().mark((function t(e){return H().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.deferredGetterReadiness("session");case 2:return t.abrupt("return",this.spacesRoles.get(e));case 3:case"end":return t.stop()}}),t,this)}))),function(t){return l.apply(this,arguments)})},{key:"getRoomTopics",value:(s=$(H().mark((function t(e){return H().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.deferredGetterReadiness("session");case 2:return t.abrupt("return",this.roomsTopics.get(e));case 3:case"end":return t.stop()}}),t,this)}))),function(t){return s.apply(this,arguments)})},{key:"getTopicMessages",value:(u=$(H().mark((function t(e){return H().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",this.topicsMessages.get(e));case 1:case"end":return t.stop()}}),t,this)}))),function(t){return u.apply(this,arguments)})},{key:"getSpaceRooms",value:(c=$(H().mark((function t(e){var r;return H().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r="spaces-rooms-".concat(e),this.spacesRooms.has(e)||this.deferredGetters.has(r)||(this.createDeferredGetter(r),this.client.send("GetSpaceRooms",{id:e})),t.next=4,this.deferredGetterReadiness(r);case 4:return t.abrupt("return",this.spacesRooms.get(e));case 5:case"end":return t.stop()}}),t,this)}))),function(t){return c.apply(this,arguments)})},{key:"getSpaceMembers",value:(a=$(H().mark((function t(e){var r;return H().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r="spaces-members-".concat(e),this.spacesMembers.has(e)||this.deferredGetters.has(r)||(this.createDeferredGetter(r),this.client.send("GetSpaceMembers",{id:e})),t.next=4,this.deferredGetterReadiness(r);case 4:return t.abrupt("return",this.spacesMembers.get(e));case 5:case"end":return t.stop()}}),t,this)}))),function(t){return a.apply(this,arguments)})},{key:"getRoomMembers",value:(i=$(H().mark((function t(e){var r;return H().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r="rooms-members-".concat(e),this.roomsMembers.has(e)||this.deferredGetters.has(r)||(this.createDeferredGetter(r),this.client.send("GetRoomMembers",{id:e})),t.next=4,this.deferredGetterReadiness(r);case 4:return t.abrupt("return",this.roomsMembers.get(e));case 5:case"end":return t.stop()}}),t,this)}))),function(t){return i.apply(this,arguments)})},{key:"deferredGetterReadiness",value:(o=$(H().mark((function t(e){var r;return H().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(!this.deferredGetters.has(e)){t.next=3;break}return t.next=3,null===(r=this.deferredGetters.get(e))||void 0===r?void 0:r.promise;case 3:case"end":return t.stop()}}),t,this)}))),function(t){return o.apply(this,arguments)})},{key:"bind",value:function(){var t=this;this.client.on(this.client.Event.disconnect,(function(e){return t.handleDisconnect(e)})),this.client.on("NewMessage",(function(e){return t.handleNewMessage(e)})),this.client.on("NewRole",(function(e){return t.handleNewRole(e)})),this.client.on("NewRoom",(function(e){return t.handleNewRoom(e)})),this.client.on("NewTopic",(function(e){return t.handleNewTopic(e)})),this.client.on("RoleDeleted",(function(e){return t.handleRoleDeleted(e)})),this.client.on("RoomDeleted",(function(e){return t.handleRoomDeleted(e)})),this.client.on("RoomJoined",(function(e){return t.handleRoomJoined(e)})),this.client.on("RoomLeft",(function(e){return t.handleRoomLeft(e)})),this.client.on("RoomMemberJoined",(function(e){return t.handleRoomMemberJoined(e)})),this.client.on("RoomMemberLeft",(function(e){return t.handleRoomMemberLeft(e)})),this.client.on("RoomMembers",(function(e){return t.handleRoomMembers(e)})),this.client.on("Session",(function(e){return t.handleSession(e)})),this.client.on("SpaceDeleted",(function(e){return t.handleSpaceDeleted(e)})),this.client.on("SpaceJoined",(function(e){return t.handleSpaceJoined(e)})),this.client.on("SpaceLeft",(function(e){return t.handleSpaceLeft(e)})),this.client.on("SpaceMemberJoined",(function(e){return t.handleSpaceMemberJoined(e)})),this.client.on("SpaceMemberLeft",(function(e){return t.handleSpaceMemberLeft(e)})),this.client.on("SpaceMembers",(function(e){return t.handleSpaceMembers(e)})),this.client.on("SpaceRooms",(function(e){return t.handleSpaceRooms(e)})),this.client.on("SpaceMemberUpdate",(function(e){return t.handleSpaceMemberUpdate(e)})),this.client.on("TopicDeleted",(function(e){return t.handleTopicDeleted(e)}))}},{key:"createDeferredGetter",value:function(t){if(!this.deferredGetters.has(t)){var e={promise:void 0,resolver:void 0};e.promise=new Promise((function(t){return e.resolver=t})),this.deferredGetters.set([t,e])}}},{key:"handleDisconnect",value:function(t){t&&(this.reconnecting=!0)}},{key:"handleNewMessage",value:function(t){this.topicsMessages.get(t.topicId).set(t.message)}},{key:"handleNewRole",value:function(t){var e=this.spacesRoles.get(t.spaceId);e.set(t.role),this.joinedSpaces.get(t.spaceId).roles=e.items}},{key:"handleNewRoom",value:function(t){var e;null===(e=this.spacesRooms.get(t.spaceId))||void 0===e||e.set(t.summary)}},{key:"handleNewTopic",value:function(t){var e=this.roomsTopics.get(t.roomId);e.set(t.topic),this.joinedRooms.get(t.roomId).topics=e.items}},{key:"handleRoleDeleted",value:function(t){var e=this.spacesRoles.get(t.spaceId);e.delete(t.id),this.joinedSpaces.get(t.spaceId).roles=e.items}},{key:"handleRoomDeleted",value:function(t){t.spaceId&&this.spacesRooms.get(t.spaceId).delete(t.id),this.joinedRooms.delete(t.id),this.roomsMembers.delete(t.id),this.roomsTopics.delete(t.id)}},{key:"handleRoomJoined",value:function(t){this.addJoinedRooms(t.room)}},{key:"addJoinedRooms",value:function(){for(var t,e,r=arguments.length,n=new Array(r),o=0;o<r;o++)n[o]=arguments[o];(t=this.roomsTopics).set.apply(t,Y(n.map((function(t){return[t.id,new B("id",t.topics)]})))),(e=this.joinedRooms).set.apply(e,n)}},{key:"handleRoomLeft",value:function(t){this.joinedRooms.delete(t.id),this.roomsMembers.delete(t.id),this.roomsTopics.delete(t.id)}},{key:"handleRoomMemberJoined",value:function(t){this.roomsMembers.has(t.roomId)&&this.roomsMembers.get(t.roomId).set(t.member)}},{key:"handleRoomMemberLeft",value:function(t){this.roomsMembers.has(t.roomId)&&this.roomsMembers.get(t.roomId).delete(t.userId)}},{key:"handleRoomMembers",value:function(t){var e;this.roomsMembers.has(t.id)||(this.roomsMembers.set([t.id,new B((function(t){var e;return null!==(e=null==t?void 0:t.user.id)&&void 0!==e?e:t.spaceMember.user.id}),t.members)]),null===(e=this.deferredGetters.get("rooms-members-".concat(t.id)))||void 0===e||e.resolver())}},{key:"handleSession",value:function(t){var e;this.me&&!this.reconnecting||(this.me=t.user,this.reconnecting=!1,this.joinedRooms.deleteAll(),this.roomsTopics.deleteAll(),this.roomsMembers.deleteAll(),this.joinedSpaces.deleteAll(),this.spacesRoles.deleteAll(),this.spacesRooms.deleteAll(),this.spacesMembers.deleteAll(),this.addJoinedRooms.apply(this,Y(t.state.rooms)),this.addJoinedSpaces.apply(this,Y(t.state.spaces)),null===(e=this.deferredGetters.get("session"))||void 0===e||e.resolver())}},{key:"handleSpaceDeleted",value:function(t){this.spacesRoles.delete(t.id),this.spacesMembers.delete(t.id),this.spacesRooms.delete(t.id),this.joinedSpaces.delete(t.id)}},{key:"handleSpaceJoined",value:function(t){this.addJoinedSpaces(t.space)}},{key:"addJoinedSpaces",value:function(){for(var t,e,r=arguments.length,n=new Array(r),o=0;o<r;o++)n[o]=arguments[o];(t=this.spacesRoles).set.apply(t,Y(n.map((function(t){return[t.id,new B("id",t.roles)]})))),(e=this.joinedSpaces).set.apply(e,n)}},{key:"handleSpaceLeft",value:function(t){this.spacesRoles.delete(t.id),this.spacesMembers.delete(t.id),this.spacesRooms.delete(t.id),this.joinedSpaces.delete(t.id)}},{key:"handleSpaceMemberJoined",value:function(t){this.spacesMembers.has(t.spaceId)&&this.spacesMembers.get(t.spaceId).set(t.member)}},{key:"handleSpaceMemberLeft",value:function(t){this.spacesMembers.has(t.spaceId)&&this.spacesMembers.get(t.spaceId).delete(t.userId)}},{key:"handleSpaceMembers",value:function(t){var e;this.spacesMembers.has(t.id)||(this.spacesMembers.set([t.id,new B((function(t){return null==t?void 0:t.user.id}),t.members)]),null===(e=this.deferredGetters.get("spaces-members-".concat(t.id)))||void 0===e||e.resolver())}},{key:"handleSpaceRooms",value:function(t){var e;this.spacesRooms.has(t.id)||(this.spacesRooms.set([t.id,new B("id",t.summaries)]),null===(e=this.deferredGetters.get("spaces-rooms-".concat(t.id)))||void 0===e||e.resolver())}},{key:"handleSpaceMemberUpdate",value:function(t){this.spacesMembers.has(t.spaceId)&&this.spacesMembers.get(t.spaceId).set(t.member)}},{key:"handleTopicDeleted",value:function(t){var e=this.roomsTopics.get(t.roomId);e.delete(t.id),this.joinedRooms.get(t.roomId).topics=e.items}}],r&&W(e.prototype,r),n&&W(e,n),Object.defineProperty(e,"prototype",{writable:!1}),t}();function Z(t){return Z="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},Z(t)}function tt(t){return function(t){if(Array.isArray(t))return et(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||function(t,e){if(!t)return;if("string"==typeof t)return et(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);"Object"===r&&t.constructor&&(r=t.constructor.name);if("Map"===r||"Set"===r)return Array.from(t);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return et(t,e)}(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function et(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r<e;r++)n[r]=t[r];return n}function rt(){/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */rt=function(){return t};var t={},e=Object.prototype,r=e.hasOwnProperty,n=Object.defineProperty||function(t,e,r){t[e]=r.value},o="function"==typeof Symbol?Symbol:{},i=o.iterator||"@@iterator",a=o.asyncIterator||"@@asyncIterator",c=o.toStringTag||"@@toStringTag";function u(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{u({},"")}catch(t){u=function(t,e,r){return t[e]=r}}function s(t,e,r,o){var i=e&&e.prototype instanceof h?e:h,a=Object.create(i.prototype),c=new x(o||[]);return n(a,"_invoke",{value:k(t,r,c)}),a}function l(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}t.wrap=s;var f={};function h(){}function p(){}function d(){}var y={};u(y,i,(function(){return this}));var v=Object.getPrototypeOf,m=v&&v(v(O([])));m&&m!==e&&r.call(m,i)&&(y=m);var g=d.prototype=h.prototype=Object.create(y);function b(t){["next","throw","return"].forEach((function(e){u(t,e,(function(t){return this._invoke(e,t)}))}))}function w(t,e){function o(n,i,a,c){var u=l(t[n],t,i);if("throw"!==u.type){var s=u.arg,f=s.value;return f&&"object"==Z(f)&&r.call(f,"__await")?e.resolve(f.__await).then((function(t){o("next",t,a,c)}),(function(t){o("throw",t,a,c)})):e.resolve(f).then((function(t){s.value=t,a(s)}),(function(t){return o("throw",t,a,c)}))}c(u.arg)}var i;n(this,"_invoke",{value:function(t,r){function n(){return new e((function(e,n){o(t,r,e,n)}))}return i=i?i.then(n,n):n()}})}function k(t,e,r){var n="suspendedStart";return function(o,i){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===o)throw i;return L()}for(r.method=o,r.arg=i;;){var a=r.delegate;if(a){var c=S(a,r);if(c){if(c===f)continue;return c}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if("suspendedStart"===n)throw n="completed",r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n="executing";var u=l(t,e,r);if("normal"===u.type){if(n=r.done?"completed":"suspendedYield",u.arg===f)continue;return{value:u.arg,done:r.done}}"throw"===u.type&&(n="completed",r.method="throw",r.arg=u.arg)}}}function S(t,e){var r=e.method,n=t.iterator[r];if(void 0===n)return e.delegate=null,"throw"===r&&t.iterator.return&&(e.method="return",e.arg=void 0,S(t,e),"throw"===e.method)||"return"!==r&&(e.method="throw",e.arg=new TypeError("The iterator does not provide a '"+r+"' method")),f;var o=l(n,t.iterator,e.arg);if("throw"===o.type)return e.method="throw",e.arg=o.arg,e.delegate=null,f;var i=o.arg;return i?i.done?(e[t.resultName]=i.value,e.next=t.nextLoc,"return"!==e.method&&(e.method="next",e.arg=void 0),e.delegate=null,f):i:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,f)}function E(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function j(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function x(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(E,this),this.reset(!0)}function O(t){if(t){var e=t[i];if(e)return e.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var n=-1,o=function e(){for(;++n<t.length;)if(r.call(t,n))return e.value=t[n],e.done=!1,e;return e.value=void 0,e.done=!0,e};return o.next=o}}return{next:L}}function L(){return{value:void 0,done:!0}}return p.prototype=d,n(g,"constructor",{value:d,configurable:!0}),n(d,"constructor",{value:p,configurable:!0}),p.displayName=u(d,c,"GeneratorFunction"),t.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===p||"GeneratorFunction"===(e.displayName||e.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,d):(t.__proto__=d,u(t,c,"GeneratorFunction")),t.prototype=Object.create(g),t},t.awrap=function(t){return{__await:t}},b(w.prototype),u(w.prototype,a,(function(){return this})),t.AsyncIterator=w,t.async=function(e,r,n,o,i){void 0===i&&(i=Promise);var a=new w(s(e,r,n,o),i);return t.isGeneratorFunction(r)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},b(g),u(g,c,"Generator"),u(g,i,(function(){return this})),u(g,"toString",(function(){return"[object Generator]"})),t.keys=function(t){var e=Object(t),r=[];for(var n in e)r.push(n);return r.reverse(),function t(){for(;r.length;){var n=r.pop();if(n in e)return t.value=n,t.done=!1,t}return t.done=!0,t}},t.values=O,x.prototype={constructor:x,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(j),!t)for(var e in this)"t"===e.charAt(0)&&r.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=void 0)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var e=this;function n(r,n){return a.type="throw",a.arg=t,e.next=r,n&&(e.method="next",e.arg=void 0),!!n}for(var o=this.tryEntries.length-1;o>=0;--o){var i=this.tryEntries[o],a=i.completion;if("root"===i.tryLoc)return n("end");if(i.tryLoc<=this.prev){var c=r.call(i,"catchLoc"),u=r.call(i,"finallyLoc");if(c&&u){if(this.prev<i.catchLoc)return n(i.catchLoc,!0);if(this.prev<i.finallyLoc)return n(i.finallyLoc)}else if(c){if(this.prev<i.catchLoc)return n(i.catchLoc,!0)}else{if(!u)throw new Error("try statement without catch or finally");if(this.prev<i.finallyLoc)return n(i.finallyLoc)}}}},abrupt:function(t,e){for(var n=this.tryEntries.length-1;n>=0;--n){var o=this.tryEntries[n];if(o.tryLoc<=this.prev&&r.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var i=o;break}}i&&("break"===t||"continue"===t)&&i.tryLoc<=e&&e<=i.finallyLoc&&(i=null);var a=i?i.completion:{};return a.type=t,a.arg=e,i?(this.method="next",this.next=i.finallyLoc,f):this.complete(a)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),f},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),j(r),f}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var o=n.arg;j(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,r){return this.delegate={iterator:O(t),resultName:e,nextLoc:r},"next"===this.method&&(this.arg=void 0),f}},t}function nt(t,e,r,n,o,i,a){try{var c=t[i](a),u=c.value}catch(t){return void r(t)}c.done?e(u):Promise.resolve(u).then(n,o)}function ot(t){return function(){var e=this,r=arguments;return new Promise((function(n,o){var i=t.apply(e,r);function a(t){nt(i,n,o,a,c,"next",t)}function c(t){nt(i,n,o,a,c,"throw",t)}a(void 0)}))}}function it(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,ht(n.key),n)}}function at(t,e){return at=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},at(t,e)}function ct(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}();return function(){var r,n=lt(t);if(e){var o=lt(this).constructor;r=Reflect.construct(n,arguments,o)}else r=n.apply(this,arguments);return ut(this,r)}}function ut(t,e){if(e&&("object"===Z(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return st(t)}function st(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function lt(t){return lt=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},lt(t)}function ft(t,e,r){return(e=ht(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function ht(t){var e=function(t,e){if("object"!==Z(t)||null===t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var n=r.call(t,e||"default");if("object"!==Z(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"===Z(e)?e:String(e)}!function(t){t.connect="connect",t.disconnect="disconnect",t.message="message",t.error="error"}(V||(V={}));var pt,dt=function(t){!function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&at(t,e)}(c,t);var e,r,n,o,i,a=ct(c);function c(t){var e,r;if(function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,c),(r=a.call(this)).options=t,ft(st(r),"Event",V),ft(st(r),"state",void 0),ft(st(r),"ws",null),ft(st(r),"sendQueue",[]),ft(st(r),"connectingTimeoutId",void 0),ft(st(r),"authenticated",void 0),ft(st(r),"authenticatedResolvers",void 0),!r.options.token&&!r.options.temporaryNick)throw new Error("Token or temporary nick is required");return(null===(e=r.options.stateTracking)||void 0===e||e)&&(r.state=new X(st(r))),r}return e=c,r=[{key:"connect",value:(i=ot(rt().mark((function t(){var e,r,n=this;return rt().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=this.options.token?"token=".concat(this.options.token):"nick=".concat(this.options.temporaryNick),this.ws=new WebSocket("".concat(this.options.url,"?").concat(r)),this.ws.onclose=function(t){return n.onClose(t)},this.ws.onmessage=function(t){return n.onMessage(t)},this.connectingTimeoutId=setTimeout((function(){return n.triggerConnectionTimeout()}),null!==(e=this.options.connectingTimeoutMs)&&void 0!==e?e:1e4),this.authenticated=!1,t.abrupt("return",new Promise((function(){for(var t=arguments.length,e=new Array(t),r=0;r<t;r++)e[r]=arguments[r];return n.authenticatedResolvers=e})));case 7:case"end":return t.stop()}}),t,this)}))),function(){return i.apply(this,arguments)})},{key:"disconnect",value:function(){var t;this.sendQueue=[],null===(t=this.ws)||void 0===t||t.close(),this.ws=null}},{key:"send",value:(o=ot(rt().mark((function t(e,r){var n;return rt().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(this.ws&&![this.ws.CLOSED,this.ws.CLOSING].includes(this.ws.readyState)){t.next=2;break}throw new Error("Cannot send; close or closing connection state");case 2:if(this.ws.readyState!==this.ws.CONNECTING&&this.authenticated){t.next=5;break}return this.sendQueue.push([e,r]),t.abrupt("return");case 5:if(this.ws.readyState===this.ws.OPEN){t.next=7;break}throw new Error("Invalid websocket state=".concat(this.ws.readyState));case 7:return n=this.createEnvelope(e,r),this.ws.send(JSON.stringify(n)),t.abrupt("return",this.createPromiseFromCommandEnvelope(n));case 10:case"end":return t.stop()}}),t,this)}))),function(t,e){return o.apply(this,arguments)})},{key:"onMessage",value:function(t){var e=JSON.parse(t.data);if(this.handleIncomingEnvelope(e),this.emit(e.type,e.data),this.emit(this.Event.message,e),!this.authenticated){var r="Error"!==e.type;this.authenticated=r,r?(this.authenticatedResolvers[0](),this.emit(this.Event.connect),this.sendFromQueue()):this.authenticatedResolvers[1](e.data)}}},{key:"onClose",value:function(t){clearTimeout(this.connectingTimeoutId);var e=1e3!==t.code;e&&this.connect(),this.emit(this.Event.disconnect,e)}},{key:"sendFromQueue",value:function(){var t=this,e=0,r=function(r){var n,o=t.sendQueue[r];setTimeout((function(){return t.send.apply(t,tt(o))}),e),e+=null!==(n=t.options.awaitQueueSendDelayMs)&&void 0!==n?n:500};for(var n in this.sendQueue)r(n);this.sendQueue=[],clearTimeout(this.connectingTimeoutId)}},{key:"triggerConnectionTimeout",value:function(){this.disconnect(),this.emit(this.Event.error,new Error("Connection timeout"))}}],r&&it(e.prototype,r),n&&it(e,n),Object.defineProperty(e,"prototype",{writable:!1}),c}(b);function yt(t){return yt="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},yt(t)}function vt(){/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */vt=function(){return t};var t={},e=Object.prototype,r=e.hasOwnProperty,n=Object.defineProperty||function(t,e,r){t[e]=r.value},o="function"==typeof Symbol?Symbol:{},i=o.iterator||"@@iterator",a=o.asyncIterator||"@@asyncIterator",c=o.toStringTag||"@@toStringTag";function u(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{u({},"")}catch(t){u=function(t,e,r){return t[e]=r}}function s(t,e,r,o){var i=e&&e.prototype instanceof h?e:h,a=Object.create(i.prototype),c=new x(o||[]);return n(a,"_invoke",{value:k(t,r,c)}),a}function l(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}t.wrap=s;var f={};function h(){}function p(){}function d(){}var y={};u(y,i,(function(){return this}));var v=Object.getPrototypeOf,m=v&&v(v(O([])));m&&m!==e&&r.call(m,i)&&(y=m);var g=d.prototype=h.prototype=Object.create(y);function b(t){["next","throw","return"].forEach((function(e){u(t,e,(function(t){return this._invoke(e,t)}))}))}function w(t,e){function o(n,i,a,c){var u=l(t[n],t,i);if("throw"!==u.type){var s=u.arg,f=s.value;return f&&"object"==yt(f)&&r.call(f,"__await")?e.resolve(f.__await).then((function(t){o("next",t,a,c)}),(function(t){o("throw",t,a,c)})):e.resolve(f).then((function(t){s.value=t,a(s)}),(function(t){return o("throw",t,a,c)}))}c(u.arg)}var i;n(this,"_invoke",{value:function(t,r){function n(){return new e((function(e,n){o(t,r,e,n)}))}return i=i?i.then(n,n):n()}})}function k(t,e,r){var n="suspendedStart";return function(o,i){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===o)throw i;return L()}for(r.method=o,r.arg=i;;){var a=r.delegate;if(a){var c=S(a,r);if(c){if(c===f)continue;return c}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if("suspendedStart"===n)throw n="completed",r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n="executing";var u=l(t,e,r);if("normal"===u.type){if(n=r.done?"completed":"suspendedYield",u.arg===f)continue;return{value:u.arg,done:r.done}}"throw"===u.type&&(n="completed",r.method="throw",r.arg=u.arg)}}}function S(t,e){var r=e.method,n=t.iterator[r];if(void 0===n)return e.delegate=null,"throw"===r&&t.iterator.return&&(e.method="return",e.arg=void 0,S(t,e),"throw"===e.method)||"return"!==r&&(e.method="throw",e.arg=new TypeError("The iterator does not provide a '"+r+"' method")),f;var o=l(n,t.iterator,e.arg);if("throw"===o.type)return e.method="throw",e.arg=o.arg,e.delegate=null,f;var i=o.arg;return i?i.done?(e[t.resultName]=i.value,e.next=t.nextLoc,"return"!==e.method&&(e.method="next",e.arg=void 0),e.delegate=null,f):i:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,f)}function E(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function j(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function x(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(E,this),this.reset(!0)}function O(t){if(t){var e=t[i];if(e)return e.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var n=-1,o=function e(){for(;++n<t.length;)if(r.call(t,n))return e.value=t[n],e.done=!1,e;return e.value=void 0,e.done=!0,e};return o.next=o}}return{next:L}}function L(){return{value:void 0,done:!0}}return p.prototype=d,n(g,"constructor",{value:d,configurable:!0}),n(d,"constructor",{value:p,configurable:!0}),p.displayName=u(d,c,"GeneratorFunction"),t.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===p||"GeneratorFunction"===(e.displayName||e.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,d):(t.__proto__=d,u(t,c,"GeneratorFunction")),t.prototype=Object.create(g),t},t.awrap=function(t){return{__await:t}},b(w.prototype),u(w.prototype,a,(function(){return this})),t.AsyncIterator=w,t.async=function(e,r,n,o,i){void 0===i&&(i=Promise);var a=new w(s(e,r,n,o),i);return t.isGeneratorFunction(r)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},b(g),u(g,c,"Generator"),u(g,i,(function(){return this})),u(g,"toString",(function(){return"[object Generator]"})),t.keys=function(t){var e=Object(t),r=[];for(var n in e)r.push(n);return r.reverse(),function t(){for(;r.length;){var n=r.pop();if(n in e)return t.value=n,t.done=!1,t}return t.done=!0,t}},t.values=O,x.prototype={constructor:x,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(j),!t)for(var e in this)"t"===e.charAt(0)&&r.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=void 0)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var e=this;function n(r,n){return a.type="throw",a.arg=t,e.next=r,n&&(e.method="next",e.arg=void 0),!!n}for(var o=this.tryEntries.length-1;o>=0;--o){var i=this.tryEntries[o],a=i.completion;if("root"===i.tryLoc)return n("end");if(i.tryLoc<=this.prev){var c=r.call(i,"catchLoc"),u=r.call(i,"finallyLoc");if(c&&u){if(this.prev<i.catchLoc)return n(i.catchLoc,!0);if(this.prev<i.finallyLoc)return n(i.finallyLoc)}else if(c){if(this.prev<i.catchLoc)return n(i.catchLoc,!0)}else{if(!u)throw new Error("try statement without catch or finally");if(this.prev<i.finallyLoc)return n(i.finallyLoc)}}}},abrupt:function(t,e){for(var n=this.tryEntries.length-1;n>=0;--n){var o=this.tryEntries[n];if(o.tryLoc<=this.prev&&r.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var i=o;break}}i&&("break"===t||"continue"===t)&&i.tryLoc<=e&&e<=i.finallyLoc&&(i=null);var a=i?i.completion:{};return a.type=t,a.arg=e,i?(this.method="next",this.next=i.finallyLoc,f):this.complete(a)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),f},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),j(r),f}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var o=n.arg;j(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,r){return this.delegate={iterator:O(t),resultName:e,nextLoc:r},"next"===this.method&&(this.arg=void 0),f}},t}function mt(t,e,r,n,o,i,a){try{var c=t[i](a),u=c.value}catch(t){return void r(t)}c.done?e(u):Promise.resolve(u).then(n,o)}function gt(t){return function(){var e=this,r=arguments;return new Promise((function(n,o){var i=t.apply(e,r);function a(t){mt(i,n,o,a,c,"next",t)}function c(t){mt(i,n,o,a,c,"throw",t)}a(void 0)}))}}function bt(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,Ot(n.key),n)}}function wt(t,e){return wt=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},wt(t,e)}function kt(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}();return function(){var r,n=jt(t);if(e){var o=jt(this).constructor;r=Reflect.construct(n,arguments,o)}else r=n.apply(this,arguments);return St(this,r)}}function St(t,e){if(e&&("object"===yt(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return Et(t)}function Et(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function jt(t){return jt=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},jt(t)}function xt(t,e,r){return(e=Ot(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function Ot(t){var e=function(t,e){if("object"!==yt(t)||null===t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var n=r.call(t,e||"default");if("object"!==yt(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"===yt(e)?e:String(e)}!function(t){t.message="message",t.error="error",t.destroy="destroy"}(pt||(pt={}));var Lt=function(t){!function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&wt(t,e)}(c,t);var e,r,n,o,i,a=kt(c);function c(t){var e;if(function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,c),(e=a.call(this)).options=t,xt(Et(e),"Event",pt),xt(Et(e),"sendStack",void 0),!e.options.token&&!e.options.temporaryNick)throw new Error("Token or temporary nick is required");return e}return e=c,r=[{key:"send",value:(i=gt(vt().mark((function t(e,r){var n;return vt().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return n=this.createEnvelope(e,r),this.sendStack.push({data:n,attempts:0,lastTimeoutId:null}),this.makeApiCall(this.sendStack.length-1),t.abrupt("return",this.createPromiseFromCommandEnvelope(n));case 4:case"end":return t.stop()}}),t,this)}))),function(t,e){return i.apply(this,arguments)})},{key:"destroy",value:function(){var t=this;this.sendStack.forEach((function(e){e.lastTimeoutId&&clearTimeout(e.lastTimeoutId),t.awaitingResponse.delete(e.data.ref)})),this.sendStack=[],this.emit(this.Event.destroy,!1)}},{key:"onMessage",value:(o=gt(vt().mark((function t(e,r){var n;return vt().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return this.sendStack.splice(e,1),t.next=3,r.json();case 3:n=t.sent,this.handleIncomingEnvelope(n),this.emit(n.type,n.data),this.emit(this.Event.message,n);case 7:case"end":return t.stop()}}),t,this)}))),function(t,e){return o.apply(this,arguments)})},{key:"onError",value:function(t,e){var r,n,o=this;if(this.sendStack[t].attempts>=(null!==(r=this.options.attemptsToSend)&&void 0!==r?r:10))return this.sendStack.splice(t,1),void this.handleEnvelopeSendError(this.sendStack[t].data,new Error("Cannot send ".concat(e,"; aborting after reaching the maximum connection errors")));this.sendStack[t].lastTimeoutId=setTimeout((function(){return o.makeApiCall(t)}),null!==(n=this.options.attemptDelayMs)&&void 0!==n?n:3e3)}},{key:"makeApiCall",value:function(t){var e=this;this.sendStack[t].attempts++;var r=JSON.stringify(this.sendStack[t].data),n={"Content-Type":"application/json",Accept:"application/json"};this.options.token?n.Authorization="Bearer ".concat(this.options.token):this.options.temporaryNick&&(n.Authorization="Temp ".concat(this.options.temporaryNick)),fetch(this.options.url,{headers:n,body:r,method:"POST"}).then((function(r){return e.onMessage(t,r)})).catch((function(){return e.onError(t,r)}))}}],r&&bt(e.prototype,r),n&&bt(e,n),Object.defineProperty(e,"prototype",{writable:!1}),c}(b);function Pt(t){return Pt="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},Pt(t)}function _t(){/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */_t=function(){return t};var t={},e=Object.prototype,r=e.hasOwnProperty,n=Object.defineProperty||function(t,e,r){t[e]=r.value},o="function"==typeof Symbol?Symbol:{},i=o.iterator||"@@iterator",a=o.asyncIterator||"@@asyncIterator",c=o.toStringTag||"@@toStringTag";function u(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{u({},"")}catch(t){u=function(t,e,r){return t[e]=r}}function s(t,e,r,o){var i=e&&e.prototype instanceof h?e:h,a=Object.create(i.prototype),c=new x(o||[]);return n(a,"_invoke",{value:k(t,r,c)}),a}function l(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}t.wrap=s;var f={};function h(){}function p(){}function d(){}var y={};u(y,i,(function(){return this}));var v=Object.getPrototypeOf,m=v&&v(v(O([])));m&&m!==e&&r.call(m,i)&&(y=m);var g=d.prototype=h.prototype=Object.create(y);function b(t){["next","throw","return"].forEach((function(e){u(t,e,(function(t){return this._invoke(e,t)}))}))}function w(t,e){function o(n,i,a,c){var u=l(t[n],t,i);if("throw"!==u.type){var s=u.arg,f=s.value;return f&&"object"==Pt(f)&&r.call(f,"__await")?e.resolve(f.__await).then((function(t){o("next",t,a,c)}),(function(t){o("throw",t,a,c)})):e.resolve(f).then((function(t){s.value=t,a(s)}),(function(t){return o("throw",t,a,c)}))}c(u.arg)}var i;n(this,"_invoke",{value:function(t,r){function n(){return new e((function(e,n){o(t,r,e,n)}))}return i=i?i.then(n,n):n()}})}function k(t,e,r){var n="suspendedStart";return function(o,i){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===o)throw i;return L()}for(r.method=o,r.arg=i;;){var a=r.delegate;if(a){var c=S(a,r);if(c){if(c===f)continue;return c}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if("suspendedStart"===n)throw n="completed",r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n="executing";var u=l(t,e,r);if("normal"===u.type){if(n=r.done?"completed":"suspendedYield",u.arg===f)continue;return{value:u.arg,done:r.done}}"throw"===u.type&&(n="completed",r.method="throw",r.arg=u.arg)}}}function S(t,e){var r=e.method,n=t.iterator[r];if(void 0===n)return e.delegate=null,"throw"===r&&t.iterator.return&&(e.method="return",e.arg=void 0,S(t,e),"throw"===e.method)||"return"!==r&&(e.method="throw",e.arg=new TypeError("The iterator does not provide a '"+r+"' method")),f;var o=l(n,t.iterator,e.arg);if("throw"===o.type)return e.method="throw",e.arg=o.arg,e.delegate=null,f;var i=o.arg;return i?i.done?(e[t.resultName]=i.value,e.next=t.nextLoc,"return"!==e.method&&(e.method="next",e.arg=void 0),e.delegate=null,f):i:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,f)}function E(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function j(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function x(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(E,this),this.reset(!0)}function O(t){if(t){var e=t[i];if(e)return e.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var n=-1,o=function e(){for(;++n<t.length;)if(r.call(t,n))return e.value=t[n],e.done=!1,e;return e.value=void 0,e.done=!0,e};return o.next=o}}return{next:L}}function L(){return{value:void 0,done:!0}}return p.prototype=d,n(g,"constructor",{value:d,configurable:!0}),n(d,"constructor",{value:p,configurable:!0}),p.displayName=u(d,c,"GeneratorFunction"),t.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===p||"GeneratorFunction"===(e.displayName||e.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,d):(t.__proto__=d,u(t,c,"GeneratorFunction")),t.prototype=Object.create(g),t},t.awrap=function(t){return{__await:t}},b(w.prototype),u(w.prototype,a,(function(){return this})),t.AsyncIterator=w,t.async=function(e,r,n,o,i){void 0===i&&(i=Promise);var a=new w(s(e,r,n,o),i);return t.isGeneratorFunction(r)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},b(g),u(g,c,"Generator"),u(g,i,(function(){return this})),u(g,"toString",(function(){return"[object Generator]"})),t.keys=function(t){var e=Object(t),r=[];for(var n in e)r.push(n);return r.reverse(),function t(){for(;r.length;){var n=r.pop();if(n in e)return t.value=n,t.done=!1,t}return t.done=!0,t}},t.values=O,x.prototype={constructor:x,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(j),!t)for(var e in this)"t"===e.charAt(0)&&r.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=void 0)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var e=this;function n(r,n){return a.type="throw",a.arg=t,e.next=r,n&&(e.method="next",e.arg=void 0),!!n}for(var o=this.tryEntries.length-1;o>=0;--o){var i=this.tryEntries[o],a=i.completion;if("root"===i.tryLoc)return n("end");if(i.tryLoc<=this.prev){var c=r.call(i,"catchLoc"),u=r.call(i,"finallyLoc");if(c&&u){if(this.prev<i.catchLoc)return n(i.catchLoc,!0);if(this.prev<i.finallyLoc)return n(i.finallyLoc)}else if(c){if(this.prev<i.catchLoc)return n(i.catchLoc,!0)}else{if(!u)throw new Error("try statement without catch or finally");if(this.prev<i.finallyLoc)return n(i.finallyLoc)}}}},abrupt:function(t,e){for(var n=this.tryEntries.length-1;n>=0;--n){var o=this.tryEntries[n];if(o.tryLoc<=this.prev&&r.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var i=o;break}}i&&("break"===t||"continue"===t)&&i.tryLoc<=e&&e<=i.finallyLoc&&(i=null);var a=i?i.completion:{};return a.type=t,a.arg=e,i?(this.method="next",this.next=i.finallyLoc,f):this.complete(a)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),f},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),j(r),f}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var o=n.arg;j(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,r){return this.delegate={iterator:O(t),resultName:e,nextLoc:r},"next"===this.method&&(this.arg=void 0),f}},t}function Rt(t,e,r,n,o,i,a){try{var c=t[i](a),u=c.value}catch(t){return void r(t)}c.done?e(u):Promise.resolve(u).then(n,o)}function Tt(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,It(n.key),n)}}function It(t){var e=function(t,e){if("object"!==Pt(t)||null===t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var n=r.call(t,e||"default");if("object"!==Pt(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"===Pt(e)?e:String(e)}function Mt(t){return Mt="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},Mt(t)}function At(){/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */At=function(){return t};var t={},e=Object.prototype,r=e.hasOwnProperty,n=Object.defineProperty||function(t,e,r){t[e]=r.value},o="function"==typeof Symbol?Symbol:{},i=o.iterator||"@@iterator",a=o.asyncIterator||"@@asyncIterator",c=o.toStringTag||"@@toStringTag";function u(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{u({},"")}catch(t){u=function(t,e,r){return t[e]=r}}function s(t,e,r,o){var i=e&&e.prototype instanceof h?e:h,a=Object.create(i.prototype),c=new x(o||[]);return n(a,"_invoke",{value:k(t,r,c)}),a}function l(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}t.wrap=s;var f={};function h(){}function p(){}function d(){}var y={};u(y,i,(function(){return this}));var v=Object.getPrototypeOf,m=v&&v(v(O([])));m&&m!==e&&r.call(m,i)&&(y=m);var g=d.prototype=h.prototype=Object.create(y);function b(t){["next","throw","return"].forEach((function(e){u(t,e,(function(t){return this._invoke(e,t)}))}))}function w(t,e){function o(n,i,a,c){var u=l(t[n],t,i);if("throw"!==u.type){var s=u.arg,f=s.value;return f&&"object"==Mt(f)&&r.call(f,"__await")?e.resolve(f.__await).then((function(t){o("next",t,a,c)}),(function(t){o("throw",t,a,c)})):e.resolve(f).then((function(t){s.value=t,a(s)}),(function(t){return o("throw",t,a,c)}))}c(u.arg)}var i;n(this,"_invoke",{value:function(t,r){function n(){return new e((function(e,n){o(t,r,e,n)}))}return i=i?i.then(n,n):n()}})}function k(t,e,r){var n="suspendedStart";return function(o,i){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===o)throw i;return L()}for(r.method=o,r.arg=i;;){var a=r.delegate;if(a){var c=S(a,r);if(c){if(c===f)continue;return c}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if("suspendedStart"===n)throw n="completed",r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n="executing";var u=l(t,e,r);if("normal"===u.type){if(n=r.done?"completed":"suspendedYield",u.arg===f)continue;return{value:u.arg,done:r.done}}"throw"===u.type&&(n="completed",r.method="throw",r.arg=u.arg)}}}function S(t,e){var r=e.method,n=t.iterator[r];if(void 0===n)return e.delegate=null,"throw"===r&&t.iterator.return&&(e.method="return",e.arg=void 0,S(t,e),"throw"===e.method)||"return"!==r&&(e.method="throw",e.arg=new TypeError("The iterator does not provide a '"+r+"' method")),f;var o=l(n,t.iterator,e.arg);if("throw"===o.type)return e.method="throw",e.arg=o.arg,e.delegate=null,f;var i=o.arg;return i?i.done?(e[t.resultName]=i.value,e.next=t.nextLoc,"return"!==e.method&&(e.method="next",e.arg=void 0),e.delegate=null,f):i:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,f)}function E(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function j(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function x(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(E,this),this.reset(!0)}function O(t){if(t){var e=t[i];if(e)return e.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var n=-1,o=function e(){for(;++n<t.length;)if(r.call(t,n))return e.value=t[n],e.done=!1,e;return e.value=void 0,e.done=!0,e};return o.next=o}}return{next:L}}function L(){return{value:void 0,done:!0}}return p.prototype=d,n(g,"constructor",{value:d,configurable:!0}),n(d,"constructor",{value:p,configurable:!0}),p.displayName=u(d,c,"GeneratorFunction"),t.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===p||"GeneratorFunction"===(e.displayName||e.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,d):(t.__proto__=d,u(t,c,"GeneratorFunction")),t.prototype=Object.create(g),t},t.awrap=function(t){return{__await:t}},b(w.prototype),u(w.prototype,a,(function(){return this})),t.AsyncIterator=w,t.async=function(e,r,n,o,i){void 0===i&&(i=Promise);var a=new w(s(e,r,n,o),i);return t.isGeneratorFunction(r)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},b(g),u(g,c,"Generator"),u(g,i,(function(){return this})),u(g,"toString",(function(){return"[object Generator]"})),t.keys=function(t){var e=Object(t),r=[];for(var n in e)r.push(n);return r.reverse(),function t(){for(;r.length;){var n=r.pop();if(n in e)return t.value=n,t.done=!1,t}return t.done=!0,t}},t.values=O,x.prototype={constructor:x,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(j),!t)for(var e in this)"t"===e.charAt(0)&&r.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=void 0)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var e=this;function n(r,n){return a.type="throw",a.arg=t,e.next=r,n&&(e.method="next",e.arg=void 0),!!n}for(var o=this.tryEntries.length-1;o>=0;--o){var i=this.tryEntries[o],a=i.completion;if("root"===i.tryLoc)return n("end");if(i.tryLoc<=this.prev){var c=r.call(i,"catchLoc"),u=r.call(i,"finallyLoc");if(c&&u){if(this.prev<i.catchLoc)return n(i.catchLoc,!0);if(this.prev<i.finallyLoc)return n(i.finallyLoc)}else if(c){if(this.prev<i.catchLoc)return n(i.catchLoc,!0)}else{if(!u)throw new Error("try statement without catch or finally");if(this.prev<i.finallyLoc)return n(i.finallyLoc)}}}},abrupt:function(t,e){for(var n=this.tryEntries.length-1;n>=0;--n){var o=this.tryEntries[n];if(o.tryLoc<=this.prev&&r.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var i=o;break}}i&&("break"===t||"continue"===t)&&i.tryLoc<=e&&e<=i.finallyLoc&&(i=null);var a=i?i.completion:{};return a.type=t,a.arg=e,i?(this.method="next",this.next=i.finallyLoc,f):this.complete(a)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),f},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),j(r),f}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var o=n.arg;j(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,r){return this.delegate={iterator:O(t),resultName:e,nextLoc:r},"next"===this.method&&(this.arg=void 0),f}},t}function Nt(t,e,r,n,o,i,a){try{var c=t[i](a),u=c.value}catch(t){return void r(t)}c.done?e(u):Promise.resolve(u).then(n,o)}function Gt(t){return function(){var e=this,r=arguments;return new Promise((function(n,o){var i=t.apply(e,r);function a(t){Nt(i,n,o,a,c,"next",t)}function c(t){Nt(i,n,o,a,c,"throw",t)}a(void 0)}))}}function Ct(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function Dt(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,Ht(n.key),n)}}function Ft(t,e){return Ft=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},Ft(t,e)}function Jt(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}();return function(){var r,n=Yt(t);if(e){var o=Yt(this).constructor;r=Reflect.construct(n,arguments,o)}else r=n.apply(this,arguments);return Bt(this,r)}}function Bt(t,e){if(e&&("object"===Mt(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return Ut(t)}function Ut(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function Yt(t){return Yt=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},Yt(t)}function Qt(t,e,r){return(e=Ht(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function Ht(t){var e=function(t,e){if("object"!==Mt(t)||null===t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var n=r.call(t,e||"default");if("object"!==Mt(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"===Mt(e)?e:String(e)}var zt=function(t){!function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&Ft(t,e)}(u,t);var e,r,n,o,i,a,c=Jt(u);function u(){var t;Ct(this,u);for(var e=arguments.length,r=new Array(e),n=0;n<e;n++)r[n]=arguments[n];return Qt(Ut(t=c.call.apply(c,[this].concat(r))),"defaultUrl","https://polfan.pl/webservice/api"),t}return e=u,r=[{key:"deleteToken",value:(a=Gt(At().mark((function t(e){var r;return At().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.send("DELETE","auth/tokens/".concat(e));case 2:if((r=t.sent).ok){t.next=5;break}throw new Error("Cannot delete access token: ".concat(r.data.errors[0]));case 5:case"end":return t.stop()}}),t,this)}))),function(t){return a.apply(this,arguments)})},{key:"getMe",value:(i=Gt(At().mark((function t(){var e;return At().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.send("GET","auth/me");case 2:if(!(e=t.sent).ok){t.next=6;break}return e.data.id=e.data.id.toString(),t.abrupt("return",e.data);case 6:throw new Error("Cannot get current user account: ".concat(e.data.errors[0]));case 7:case"end":return t.stop()}}),t,this)}))),function(){return i.apply(this,arguments)})}],n=[{key:"createToken",value:(o=Gt(At().mark((function t(e,r){var n,o,i=arguments;return At().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return n=i.length>2&&void 0!==i[2]?i[2]:"pserv-js-client",t.next=3,new u({token:null}).send("POST","auth/tokens",{login:e,password:r,client_name:n});case 3:if(!(o=t.sent).ok){t.next=6;break}return t.abrupt("return",o.data);case 6:throw new Error("Cannot create user token: ".concat(o.data.errors[0]));case 7:case"end":return t.stop()}}),t)}))),function(t,e){return o.apply(this,arguments)})}],r&&Dt(e.prototype,r),n&&Dt(e,n),Object.defineProperty(e,"prototype",{writable:!1}),u}(function(){function t(e){var r,n,o;!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.options=e,r=this,o=void 0,(n=It(n="defaultUrl"))in r?Object.defineProperty(r,n,{value:o,enumerable:!0,configurable:!0,writable:!0}):r[n]=o}var e,r,n,o,i;return e=t,r=[{key:"send",value:(o=_t().mark((function t(e,r){var n,o,i,a,c,u=arguments;return _t().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return n=u.length>2&&void 0!==u[2]?u[2]:void 0,o={"Content-Type":"application/json",Accept:"application/json"},this.options.token&&(o.Authorization="Bearer ".concat(this.options.token)),i=this.getUrl(r),a=void 0,n&&(["GET","DELETE"].includes(e)?i+=new URLSearchParams(n).toString():a=JSON.stringify(n)),t.next=8,fetch(i,{method:e,body:a,headers:o});case 8:return c=t.sent,t.t0=c.ok,t.t1=c.status,t.next=13,c.json();case 13:return t.t2=t.sent,t.abrupt("return",{ok:t.t0,status:t.t1,data:t.t2});case 15:case"end":return t.stop()}}),t,this)})),i=function(){var t=this,e=arguments;return new Promise((function(r,n){var i=o.apply(t,e);function a(t){Rt(i,r,n,a,c,"next",t)}function c(t){Rt(i,r,n,a,c,"throw",t)}a(void 0)}))},function(t,e){return i.apply(this,arguments)})},{key:"getUrl",value:function(t){var e;return this.removeEndingSlash(null!==(e=this.options.url)&&void 0!==e?e:this.defaultUrl)+"/"+this.removeStartingSlash(t)}},{key:"removeStartingSlash",value:function(t){return t.replace(/^\/+/,"")}},{key:"removeEndingSlash",value:function(t){return t.replace(/\/+$/,"")}}],r&&Tt(e.prototype,r),n&&Tt(e,n),Object.defineProperty(e,"prototype",{writable:!1}),t}());return e})()));
|
|
1
|
+
(function webpackUniversalModuleDefinition(root, factory) {
|
|
2
|
+
if(typeof exports === 'object' && typeof module === 'object')
|
|
3
|
+
module.exports = factory();
|
|
4
|
+
else if(typeof define === 'function' && define.amd)
|
|
5
|
+
define([], factory);
|
|
6
|
+
else if(typeof exports === 'object')
|
|
7
|
+
exports["PServ"] = factory();
|
|
8
|
+
else
|
|
9
|
+
root["PServ"] = factory();
|
|
10
|
+
})(self, () => {
|
|
11
|
+
return /******/ (() => { // webpackBootstrap
|
|
12
|
+
/******/ "use strict";
|
|
13
|
+
/******/ // The require scope
|
|
14
|
+
/******/ var __webpack_require__ = {};
|
|
15
|
+
/******/
|
|
16
|
+
/************************************************************************/
|
|
17
|
+
/******/ /* webpack/runtime/define property getters */
|
|
18
|
+
/******/ (() => {
|
|
19
|
+
/******/ // define getter functions for harmony exports
|
|
20
|
+
/******/ __webpack_require__.d = (exports, definition) => {
|
|
21
|
+
/******/ for(var key in definition) {
|
|
22
|
+
/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
|
|
23
|
+
/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
|
|
24
|
+
/******/ }
|
|
25
|
+
/******/ }
|
|
26
|
+
/******/ };
|
|
27
|
+
/******/ })();
|
|
28
|
+
/******/
|
|
29
|
+
/******/ /* webpack/runtime/hasOwnProperty shorthand */
|
|
30
|
+
/******/ (() => {
|
|
31
|
+
/******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
|
|
32
|
+
/******/ })();
|
|
33
|
+
/******/
|
|
34
|
+
/******/ /* webpack/runtime/make namespace object */
|
|
35
|
+
/******/ (() => {
|
|
36
|
+
/******/ // define __esModule on exports
|
|
37
|
+
/******/ __webpack_require__.r = (exports) => {
|
|
38
|
+
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
|
|
39
|
+
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
40
|
+
/******/ }
|
|
41
|
+
/******/ Object.defineProperty(exports, '__esModule', { value: true });
|
|
42
|
+
/******/ };
|
|
43
|
+
/******/ })();
|
|
44
|
+
/******/
|
|
45
|
+
/************************************************************************/
|
|
46
|
+
var __webpack_exports__ = {};
|
|
47
|
+
// ESM COMPAT FLAG
|
|
48
|
+
__webpack_require__.r(__webpack_exports__);
|
|
49
|
+
|
|
50
|
+
// EXPORTS
|
|
51
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
52
|
+
"AuthClient": () => (/* reexport */ AuthClient),
|
|
53
|
+
"IndexedCollection": () => (/* reexport */ IndexedCollection),
|
|
54
|
+
"IndexedObjectCollection": () => (/* reexport */ IndexedObjectCollection),
|
|
55
|
+
"ObservableIndexedCollection": () => (/* reexport */ ObservableIndexedCollection),
|
|
56
|
+
"ObservableIndexedObjectCollection": () => (/* reexport */ ObservableIndexedObjectCollection),
|
|
57
|
+
"WebApiChatClient": () => (/* reexport */ WebApiChatClient),
|
|
58
|
+
"WebSocketChatClient": () => (/* reexport */ WebSocketChatClient)
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
;// CONCATENATED MODULE: ./src/EventTarget.ts
|
|
62
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
63
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
64
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
65
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
66
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
67
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
68
|
+
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
69
|
+
var EventTarget = /*#__PURE__*/function () {
|
|
70
|
+
function EventTarget() {
|
|
71
|
+
_classCallCheck(this, EventTarget);
|
|
72
|
+
_defineProperty(this, "events", new Map());
|
|
73
|
+
_defineProperty(this, "onceEvents", new Map());
|
|
74
|
+
}
|
|
75
|
+
_createClass(EventTarget, [{
|
|
76
|
+
key: "on",
|
|
77
|
+
value: function on(eventName, handler) {
|
|
78
|
+
this.addHandler(this.events, eventName, handler);
|
|
79
|
+
return this;
|
|
80
|
+
}
|
|
81
|
+
}, {
|
|
82
|
+
key: "once",
|
|
83
|
+
value: function once(eventName, handler) {
|
|
84
|
+
this.addHandler(this.onceEvents, eventName, handler);
|
|
85
|
+
return this;
|
|
86
|
+
}
|
|
87
|
+
}, {
|
|
88
|
+
key: "emit",
|
|
89
|
+
value: function emit(eventName, event) {
|
|
90
|
+
this.callHandlers(this.events, eventName, event);
|
|
91
|
+
this.callHandlers(this.onceEvents, eventName, event);
|
|
92
|
+
this.onceEvents["delete"](eventName);
|
|
93
|
+
return this;
|
|
94
|
+
}
|
|
95
|
+
}, {
|
|
96
|
+
key: "addHandler",
|
|
97
|
+
value: function addHandler(map, eventName, handler) {
|
|
98
|
+
var _map$get;
|
|
99
|
+
var handlers = (_map$get = map.get(eventName)) !== null && _map$get !== void 0 ? _map$get : [];
|
|
100
|
+
handlers.push(handler);
|
|
101
|
+
map.set(eventName, handlers);
|
|
102
|
+
}
|
|
103
|
+
}, {
|
|
104
|
+
key: "callHandlers",
|
|
105
|
+
value: function callHandlers(map, eventName, event) {
|
|
106
|
+
var _map$get2;
|
|
107
|
+
(_map$get2 = map.get(eventName)) === null || _map$get2 === void 0 ? void 0 : _map$get2.forEach(function (callback) {
|
|
108
|
+
return callback(event);
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
}]);
|
|
112
|
+
return EventTarget;
|
|
113
|
+
}();
|
|
114
|
+
;// CONCATENATED MODULE: ./src/AbstractChatClient.ts
|
|
115
|
+
function AbstractChatClient_typeof(obj) { "@babel/helpers - typeof"; return AbstractChatClient_typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, AbstractChatClient_typeof(obj); }
|
|
116
|
+
function AbstractChatClient_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
117
|
+
function AbstractChatClient_defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, AbstractChatClient_toPropertyKey(descriptor.key), descriptor); } }
|
|
118
|
+
function AbstractChatClient_createClass(Constructor, protoProps, staticProps) { if (protoProps) AbstractChatClient_defineProperties(Constructor.prototype, protoProps); if (staticProps) AbstractChatClient_defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
119
|
+
function _get() { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get.bind(); } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(arguments.length < 3 ? target : receiver); } return desc.value; }; } return _get.apply(this, arguments); }
|
|
120
|
+
function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
|
|
121
|
+
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
122
|
+
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
123
|
+
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
124
|
+
function _possibleConstructorReturn(self, call) { if (call && (AbstractChatClient_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
|
|
125
|
+
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
126
|
+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
127
|
+
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
128
|
+
function AbstractChatClient_defineProperty(obj, key, value) { key = AbstractChatClient_toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
129
|
+
function AbstractChatClient_toPropertyKey(arg) { var key = AbstractChatClient_toPrimitive(arg, "string"); return AbstractChatClient_typeof(key) === "symbol" ? key : String(key); }
|
|
130
|
+
function AbstractChatClient_toPrimitive(input, hint) { if (AbstractChatClient_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (AbstractChatClient_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
131
|
+
|
|
132
|
+
var AbstractChatClient = /*#__PURE__*/function (_EventTarget) {
|
|
133
|
+
_inherits(AbstractChatClient, _EventTarget);
|
|
134
|
+
var _super = _createSuper(AbstractChatClient);
|
|
135
|
+
function AbstractChatClient() {
|
|
136
|
+
var _this;
|
|
137
|
+
AbstractChatClient_classCallCheck(this, AbstractChatClient);
|
|
138
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
139
|
+
args[_key] = arguments[_key];
|
|
140
|
+
}
|
|
141
|
+
_this = _super.call.apply(_super, [this].concat(args));
|
|
142
|
+
AbstractChatClient_defineProperty(_assertThisInitialized(_this), "awaitingResponse", new Map());
|
|
143
|
+
AbstractChatClient_defineProperty(_assertThisInitialized(_this), "sentCounter", 0);
|
|
144
|
+
return _this;
|
|
145
|
+
}
|
|
146
|
+
AbstractChatClient_createClass(AbstractChatClient, [{
|
|
147
|
+
key: "on",
|
|
148
|
+
value: function on(eventName, handler) {
|
|
149
|
+
return _get(_getPrototypeOf(AbstractChatClient.prototype), "on", this).call(this, eventName, handler);
|
|
150
|
+
}
|
|
151
|
+
}, {
|
|
152
|
+
key: "once",
|
|
153
|
+
value: function once(eventName, handler) {
|
|
154
|
+
return _get(_getPrototypeOf(AbstractChatClient.prototype), "once", this).call(this, eventName, handler);
|
|
155
|
+
}
|
|
156
|
+
}, {
|
|
157
|
+
key: "createEnvelope",
|
|
158
|
+
value: function createEnvelope(type, data) {
|
|
159
|
+
return {
|
|
160
|
+
type: type,
|
|
161
|
+
data: data,
|
|
162
|
+
ref: (++this.sentCounter).toString()
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
}, {
|
|
166
|
+
key: "createPromiseFromCommandEnvelope",
|
|
167
|
+
value: function createPromiseFromCommandEnvelope(envelope) {
|
|
168
|
+
var _this2 = this;
|
|
169
|
+
return new Promise(function () {
|
|
170
|
+
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
171
|
+
args[_key2] = arguments[_key2];
|
|
172
|
+
}
|
|
173
|
+
return _this2.awaitingResponse.set(envelope.ref, args);
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
}, {
|
|
177
|
+
key: "handleIncomingEnvelope",
|
|
178
|
+
value: function handleIncomingEnvelope(envelope) {
|
|
179
|
+
if (!this.awaitingResponse.has(envelope.ref)) {
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
var isError = envelope.type === 'Error';
|
|
183
|
+
this.awaitingResponse.get(envelope.ref)[0]({
|
|
184
|
+
data: isError ? null : envelope.data,
|
|
185
|
+
error: isError ? envelope.data : null
|
|
186
|
+
});
|
|
187
|
+
this.awaitingResponse["delete"](envelope.ref);
|
|
188
|
+
}
|
|
189
|
+
}, {
|
|
190
|
+
key: "handleEnvelopeSendError",
|
|
191
|
+
value: function handleEnvelopeSendError(envelope, error) {
|
|
192
|
+
if (!this.awaitingResponse.has(envelope.ref)) {
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
this.awaitingResponse.get(envelope.ref)[0](error);
|
|
196
|
+
this.awaitingResponse["delete"](envelope.ref);
|
|
197
|
+
}
|
|
198
|
+
}]);
|
|
199
|
+
return AbstractChatClient;
|
|
200
|
+
}(EventTarget);
|
|
201
|
+
;// CONCATENATED MODULE: ./src/IndexedObjectCollection.ts
|
|
202
|
+
function IndexedObjectCollection_typeof(obj) { "@babel/helpers - typeof"; return IndexedObjectCollection_typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, IndexedObjectCollection_typeof(obj); }
|
|
203
|
+
function IndexedObjectCollection_get() { if (typeof Reflect !== "undefined" && Reflect.get) { IndexedObjectCollection_get = Reflect.get.bind(); } else { IndexedObjectCollection_get = function _get(target, property, receiver) { var base = IndexedObjectCollection_superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(arguments.length < 3 ? target : receiver); } return desc.value; }; } return IndexedObjectCollection_get.apply(this, arguments); }
|
|
204
|
+
function IndexedObjectCollection_superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = IndexedObjectCollection_getPrototypeOf(object); if (object === null) break; } return object; }
|
|
205
|
+
function IndexedObjectCollection_inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) IndexedObjectCollection_setPrototypeOf(subClass, superClass); }
|
|
206
|
+
function IndexedObjectCollection_setPrototypeOf(o, p) { IndexedObjectCollection_setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return IndexedObjectCollection_setPrototypeOf(o, p); }
|
|
207
|
+
function IndexedObjectCollection_createSuper(Derived) { var hasNativeReflectConstruct = IndexedObjectCollection_isNativeReflectConstruct(); return function _createSuperInternal() { var Super = IndexedObjectCollection_getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = IndexedObjectCollection_getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return IndexedObjectCollection_possibleConstructorReturn(this, result); }; }
|
|
208
|
+
function IndexedObjectCollection_possibleConstructorReturn(self, call) { if (call && (IndexedObjectCollection_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return IndexedObjectCollection_assertThisInitialized(self); }
|
|
209
|
+
function IndexedObjectCollection_assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
210
|
+
function IndexedObjectCollection_isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
211
|
+
function IndexedObjectCollection_getPrototypeOf(o) { IndexedObjectCollection_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return IndexedObjectCollection_getPrototypeOf(o); }
|
|
212
|
+
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
|
|
213
|
+
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
214
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
215
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
216
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
217
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
218
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
219
|
+
function IndexedObjectCollection_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
220
|
+
function IndexedObjectCollection_defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, IndexedObjectCollection_toPropertyKey(descriptor.key), descriptor); } }
|
|
221
|
+
function IndexedObjectCollection_createClass(Constructor, protoProps, staticProps) { if (protoProps) IndexedObjectCollection_defineProperties(Constructor.prototype, protoProps); if (staticProps) IndexedObjectCollection_defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
222
|
+
function IndexedObjectCollection_defineProperty(obj, key, value) { key = IndexedObjectCollection_toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
223
|
+
function IndexedObjectCollection_toPropertyKey(arg) { var key = IndexedObjectCollection_toPrimitive(arg, "string"); return IndexedObjectCollection_typeof(key) === "symbol" ? key : String(key); }
|
|
224
|
+
function IndexedObjectCollection_toPrimitive(input, hint) { if (IndexedObjectCollection_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (IndexedObjectCollection_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
225
|
+
|
|
226
|
+
var IndexedCollection = /*#__PURE__*/function () {
|
|
227
|
+
function IndexedCollection() {
|
|
228
|
+
var items = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
229
|
+
IndexedObjectCollection_classCallCheck(this, IndexedCollection);
|
|
230
|
+
IndexedObjectCollection_defineProperty(this, "_items", new Map());
|
|
231
|
+
this.set.apply(this, _toConsumableArray(items));
|
|
232
|
+
}
|
|
233
|
+
IndexedObjectCollection_createClass(IndexedCollection, [{
|
|
234
|
+
key: "items",
|
|
235
|
+
get: function get() {
|
|
236
|
+
return this._items;
|
|
237
|
+
}
|
|
238
|
+
}, {
|
|
239
|
+
key: "length",
|
|
240
|
+
get: function get() {
|
|
241
|
+
return this._items.size;
|
|
242
|
+
}
|
|
243
|
+
}, {
|
|
244
|
+
key: "set",
|
|
245
|
+
value: function set() {
|
|
246
|
+
for (var _len = arguments.length, items = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
247
|
+
items[_key] = arguments[_key];
|
|
248
|
+
}
|
|
249
|
+
for (var _i = 0, _items = items; _i < _items.length; _i++) {
|
|
250
|
+
var _item = _items[_i];
|
|
251
|
+
this._items.set(_item[0], _item[1]);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
}, {
|
|
255
|
+
key: "get",
|
|
256
|
+
value: function get(id) {
|
|
257
|
+
return this.items.get(id);
|
|
258
|
+
}
|
|
259
|
+
}, {
|
|
260
|
+
key: "has",
|
|
261
|
+
value: function has(id) {
|
|
262
|
+
return this.items.has(id);
|
|
263
|
+
}
|
|
264
|
+
}, {
|
|
265
|
+
key: "delete",
|
|
266
|
+
value: function _delete() {
|
|
267
|
+
for (var _len2 = arguments.length, ids = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
268
|
+
ids[_key2] = arguments[_key2];
|
|
269
|
+
}
|
|
270
|
+
for (var _i2 = 0, _ids = ids; _i2 < _ids.length; _i2++) {
|
|
271
|
+
var _id = _ids[_i2];
|
|
272
|
+
this.items["delete"](_id);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
}, {
|
|
276
|
+
key: "deleteAll",
|
|
277
|
+
value: function deleteAll() {
|
|
278
|
+
this.items.clear();
|
|
279
|
+
}
|
|
280
|
+
}, {
|
|
281
|
+
key: "findBy",
|
|
282
|
+
value: function findBy(field, valueToFind) {
|
|
283
|
+
var limit = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
|
|
284
|
+
var result = new IndexedCollection();
|
|
285
|
+
var item;
|
|
286
|
+
while (!(item = this.items.entries().next().value).done) {
|
|
287
|
+
if (limit && result.length === limit) {
|
|
288
|
+
break;
|
|
289
|
+
}
|
|
290
|
+
if (item[1][field] === valueToFind) {
|
|
291
|
+
result.set(item);
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
return result;
|
|
295
|
+
}
|
|
296
|
+
}, {
|
|
297
|
+
key: "map",
|
|
298
|
+
value: function map(callback) {
|
|
299
|
+
return Array.from(this.items.entries()).map(function (entry) {
|
|
300
|
+
return callback(entry[1], entry[0]);
|
|
301
|
+
});
|
|
302
|
+
}
|
|
303
|
+
}]);
|
|
304
|
+
return IndexedCollection;
|
|
305
|
+
}();
|
|
306
|
+
var IndexedObjectCollection = /*#__PURE__*/function () {
|
|
307
|
+
function IndexedObjectCollection(id) {
|
|
308
|
+
var items = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
309
|
+
IndexedObjectCollection_classCallCheck(this, IndexedObjectCollection);
|
|
310
|
+
this.id = id;
|
|
311
|
+
IndexedObjectCollection_defineProperty(this, "_items", void 0);
|
|
312
|
+
this._items = new IndexedCollection();
|
|
313
|
+
this.set.apply(this, _toConsumableArray(items));
|
|
314
|
+
}
|
|
315
|
+
IndexedObjectCollection_createClass(IndexedObjectCollection, [{
|
|
316
|
+
key: "items",
|
|
317
|
+
get: function get() {
|
|
318
|
+
return Array.from(this._items.items.values());
|
|
319
|
+
}
|
|
320
|
+
}, {
|
|
321
|
+
key: "length",
|
|
322
|
+
get: function get() {
|
|
323
|
+
return this._items.length;
|
|
324
|
+
}
|
|
325
|
+
}, {
|
|
326
|
+
key: "set",
|
|
327
|
+
value: function set() {
|
|
328
|
+
var _this$_items,
|
|
329
|
+
_this = this;
|
|
330
|
+
for (var _len3 = arguments.length, items = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
|
|
331
|
+
items[_key3] = arguments[_key3];
|
|
332
|
+
}
|
|
333
|
+
(_this$_items = this._items).set.apply(_this$_items, _toConsumableArray(items.map(function (item) {
|
|
334
|
+
return [_this.getId(item), item];
|
|
335
|
+
})));
|
|
336
|
+
}
|
|
337
|
+
}, {
|
|
338
|
+
key: "get",
|
|
339
|
+
value: function get(id) {
|
|
340
|
+
return this._items.get(id);
|
|
341
|
+
}
|
|
342
|
+
}, {
|
|
343
|
+
key: "getAt",
|
|
344
|
+
value: function getAt(index) {
|
|
345
|
+
return this.items[index];
|
|
346
|
+
}
|
|
347
|
+
}, {
|
|
348
|
+
key: "has",
|
|
349
|
+
value: function has(id) {
|
|
350
|
+
return this._items.has(id);
|
|
351
|
+
}
|
|
352
|
+
}, {
|
|
353
|
+
key: "delete",
|
|
354
|
+
value: function _delete() {
|
|
355
|
+
var _this$_items2;
|
|
356
|
+
(_this$_items2 = this._items)["delete"].apply(_this$_items2, arguments);
|
|
357
|
+
}
|
|
358
|
+
}, {
|
|
359
|
+
key: "deleteAll",
|
|
360
|
+
value: function deleteAll() {
|
|
361
|
+
this._items.deleteAll();
|
|
362
|
+
}
|
|
363
|
+
}, {
|
|
364
|
+
key: "findBy",
|
|
365
|
+
value: function findBy(field, valueToFind) {
|
|
366
|
+
var limit = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
|
|
367
|
+
var result = new IndexedObjectCollection(this.id);
|
|
368
|
+
var _iterator = _createForOfIteratorHelper(this.items),
|
|
369
|
+
_step;
|
|
370
|
+
try {
|
|
371
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
372
|
+
var _value = _step.value;
|
|
373
|
+
if (limit && result.length === limit) {
|
|
374
|
+
break;
|
|
375
|
+
}
|
|
376
|
+
if (_value[field] === valueToFind) {
|
|
377
|
+
result.set(_value);
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
} catch (err) {
|
|
381
|
+
_iterator.e(err);
|
|
382
|
+
} finally {
|
|
383
|
+
_iterator.f();
|
|
384
|
+
}
|
|
385
|
+
return result;
|
|
386
|
+
}
|
|
387
|
+
}, {
|
|
388
|
+
key: "map",
|
|
389
|
+
value: function map(callback) {
|
|
390
|
+
return this.items.map(callback);
|
|
391
|
+
}
|
|
392
|
+
}, {
|
|
393
|
+
key: "getId",
|
|
394
|
+
value: function getId(item) {
|
|
395
|
+
return typeof this.id === 'function' ? this.id(item) : item[this.id];
|
|
396
|
+
}
|
|
397
|
+
}]);
|
|
398
|
+
return IndexedObjectCollection;
|
|
399
|
+
}();
|
|
400
|
+
var ObservableIndexedCollection = /*#__PURE__*/function (_IndexedCollection) {
|
|
401
|
+
IndexedObjectCollection_inherits(ObservableIndexedCollection, _IndexedCollection);
|
|
402
|
+
var _super = IndexedObjectCollection_createSuper(ObservableIndexedCollection);
|
|
403
|
+
function ObservableIndexedCollection() {
|
|
404
|
+
var _this3;
|
|
405
|
+
var _this2;
|
|
406
|
+
var items = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
407
|
+
IndexedObjectCollection_classCallCheck(this, ObservableIndexedCollection);
|
|
408
|
+
_this2 = _super.call(this);
|
|
409
|
+
IndexedObjectCollection_defineProperty(IndexedObjectCollection_assertThisInitialized(_this2), "eventTarget", void 0);
|
|
410
|
+
_this2.eventTarget = new EventTarget();
|
|
411
|
+
(_this3 = _this2).set.apply(_this3, _toConsumableArray(items));
|
|
412
|
+
return _this2;
|
|
413
|
+
}
|
|
414
|
+
IndexedObjectCollection_createClass(ObservableIndexedCollection, [{
|
|
415
|
+
key: "set",
|
|
416
|
+
value: function set() {
|
|
417
|
+
for (var _len4 = arguments.length, items = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
|
|
418
|
+
items[_key4] = arguments[_key4];
|
|
419
|
+
}
|
|
420
|
+
if (items.length) {
|
|
421
|
+
var _get2;
|
|
422
|
+
(_get2 = IndexedObjectCollection_get(IndexedObjectCollection_getPrototypeOf(ObservableIndexedCollection.prototype), "set", this)).call.apply(_get2, [this].concat(items));
|
|
423
|
+
this.eventTarget.emit('change', {
|
|
424
|
+
setItems: items.map(function (item) {
|
|
425
|
+
return item[0];
|
|
426
|
+
})
|
|
427
|
+
});
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
}, {
|
|
431
|
+
key: "delete",
|
|
432
|
+
value: function _delete() {
|
|
433
|
+
for (var _len5 = arguments.length, ids = new Array(_len5), _key5 = 0; _key5 < _len5; _key5++) {
|
|
434
|
+
ids[_key5] = arguments[_key5];
|
|
435
|
+
}
|
|
436
|
+
if (ids.length) {
|
|
437
|
+
var _get3;
|
|
438
|
+
(_get3 = IndexedObjectCollection_get(IndexedObjectCollection_getPrototypeOf(ObservableIndexedCollection.prototype), "delete", this)).call.apply(_get3, [this].concat(ids));
|
|
439
|
+
this.eventTarget.emit('change', {
|
|
440
|
+
deletedItems: ids
|
|
441
|
+
});
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
}, {
|
|
445
|
+
key: "deleteAll",
|
|
446
|
+
value: function deleteAll() {
|
|
447
|
+
if (this.length) {
|
|
448
|
+
var ids = this._items.keys();
|
|
449
|
+
IndexedObjectCollection_get(IndexedObjectCollection_getPrototypeOf(ObservableIndexedCollection.prototype), "deleteAll", this).call(this);
|
|
450
|
+
this.eventTarget.emit('change', {
|
|
451
|
+
deletedItems: Array.from(ids)
|
|
452
|
+
});
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
}, {
|
|
456
|
+
key: "on",
|
|
457
|
+
value: function on(eventName, handler) {
|
|
458
|
+
this.eventTarget.on(eventName, handler);
|
|
459
|
+
return this;
|
|
460
|
+
}
|
|
461
|
+
}, {
|
|
462
|
+
key: "once",
|
|
463
|
+
value: function once(eventName, handler) {
|
|
464
|
+
this.eventTarget.once(eventName, handler);
|
|
465
|
+
return this;
|
|
466
|
+
}
|
|
467
|
+
}]);
|
|
468
|
+
return ObservableIndexedCollection;
|
|
469
|
+
}(IndexedCollection);
|
|
470
|
+
var ObservableIndexedObjectCollection = /*#__PURE__*/function (_IndexedObjectCollect) {
|
|
471
|
+
IndexedObjectCollection_inherits(ObservableIndexedObjectCollection, _IndexedObjectCollect);
|
|
472
|
+
var _super2 = IndexedObjectCollection_createSuper(ObservableIndexedObjectCollection);
|
|
473
|
+
function ObservableIndexedObjectCollection(id) {
|
|
474
|
+
var _this5;
|
|
475
|
+
var _this4;
|
|
476
|
+
var items = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
477
|
+
IndexedObjectCollection_classCallCheck(this, ObservableIndexedObjectCollection);
|
|
478
|
+
_this4 = _super2.call(this, id);
|
|
479
|
+
_this4.id = id;
|
|
480
|
+
IndexedObjectCollection_defineProperty(IndexedObjectCollection_assertThisInitialized(_this4), "eventTarget", void 0);
|
|
481
|
+
_this4.eventTarget = new EventTarget();
|
|
482
|
+
(_this5 = _this4).set.apply(_this5, _toConsumableArray(items));
|
|
483
|
+
return _this4;
|
|
484
|
+
}
|
|
485
|
+
IndexedObjectCollection_createClass(ObservableIndexedObjectCollection, [{
|
|
486
|
+
key: "set",
|
|
487
|
+
value: function set() {
|
|
488
|
+
var _this6 = this;
|
|
489
|
+
for (var _len6 = arguments.length, items = new Array(_len6), _key6 = 0; _key6 < _len6; _key6++) {
|
|
490
|
+
items[_key6] = arguments[_key6];
|
|
491
|
+
}
|
|
492
|
+
if (items.length) {
|
|
493
|
+
var _get4;
|
|
494
|
+
(_get4 = IndexedObjectCollection_get(IndexedObjectCollection_getPrototypeOf(ObservableIndexedObjectCollection.prototype), "set", this)).call.apply(_get4, [this].concat(items));
|
|
495
|
+
this.eventTarget.emit('change', {
|
|
496
|
+
setItems: items.map(function (item) {
|
|
497
|
+
return _this6.getId(item);
|
|
498
|
+
})
|
|
499
|
+
});
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
}, {
|
|
503
|
+
key: "delete",
|
|
504
|
+
value: function _delete() {
|
|
505
|
+
for (var _len7 = arguments.length, ids = new Array(_len7), _key7 = 0; _key7 < _len7; _key7++) {
|
|
506
|
+
ids[_key7] = arguments[_key7];
|
|
507
|
+
}
|
|
508
|
+
if (ids.length) {
|
|
509
|
+
var _get5;
|
|
510
|
+
(_get5 = IndexedObjectCollection_get(IndexedObjectCollection_getPrototypeOf(ObservableIndexedObjectCollection.prototype), "delete", this)).call.apply(_get5, [this].concat(ids));
|
|
511
|
+
this.eventTarget.emit('change', {
|
|
512
|
+
deletedItems: ids
|
|
513
|
+
});
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
}, {
|
|
517
|
+
key: "deleteAll",
|
|
518
|
+
value: function deleteAll() {
|
|
519
|
+
if (this.length) {
|
|
520
|
+
var ids = this._items.items.keys();
|
|
521
|
+
IndexedObjectCollection_get(IndexedObjectCollection_getPrototypeOf(ObservableIndexedObjectCollection.prototype), "deleteAll", this).call(this);
|
|
522
|
+
this.eventTarget.emit('change', {
|
|
523
|
+
deletedItems: Array.from(ids)
|
|
524
|
+
});
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
}, {
|
|
528
|
+
key: "on",
|
|
529
|
+
value: function on(eventName, handler) {
|
|
530
|
+
this.eventTarget.on(eventName, handler);
|
|
531
|
+
return this;
|
|
532
|
+
}
|
|
533
|
+
}, {
|
|
534
|
+
key: "once",
|
|
535
|
+
value: function once(eventName, handler) {
|
|
536
|
+
this.eventTarget.once(eventName, handler);
|
|
537
|
+
return this;
|
|
538
|
+
}
|
|
539
|
+
}]);
|
|
540
|
+
return ObservableIndexedObjectCollection;
|
|
541
|
+
}(IndexedObjectCollection);
|
|
542
|
+
;// CONCATENATED MODULE: ./src/ChatStateTracker.ts
|
|
543
|
+
function ChatStateTracker_typeof(obj) { "@babel/helpers - typeof"; return ChatStateTracker_typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, ChatStateTracker_typeof(obj); }
|
|
544
|
+
function ChatStateTracker_toConsumableArray(arr) { return ChatStateTracker_arrayWithoutHoles(arr) || ChatStateTracker_iterableToArray(arr) || ChatStateTracker_unsupportedIterableToArray(arr) || ChatStateTracker_nonIterableSpread(); }
|
|
545
|
+
function ChatStateTracker_nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
546
|
+
function ChatStateTracker_unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return ChatStateTracker_arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return ChatStateTracker_arrayLikeToArray(o, minLen); }
|
|
547
|
+
function ChatStateTracker_iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
548
|
+
function ChatStateTracker_arrayWithoutHoles(arr) { if (Array.isArray(arr)) return ChatStateTracker_arrayLikeToArray(arr); }
|
|
549
|
+
function ChatStateTracker_arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
550
|
+
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, defineProperty = Object.defineProperty || function (obj, key, desc) { obj[key] = desc.value; }, $Symbol = "function" == typeof Symbol ? Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []); return defineProperty(generator, "_invoke", { value: makeInvokeMethod(innerFn, self, context) }), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = Object.getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); function defineIteratorMethods(prototype) { ["next", "throw", "return"].forEach(function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == ChatStateTracker_typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; defineProperty(this, "_invoke", { value: function value(method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; } function maybeInvokeDelegate(delegate, context) { var methodName = context.method, method = delegate.iterator[methodName]; if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator["return"] && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel; var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) { if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; } return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), defineProperty(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (val) { var object = Object(val), keys = []; for (var key in object) { keys.push(key); } return keys.reverse(), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) { "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); } }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, "catch": function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; }
|
|
551
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
552
|
+
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
553
|
+
function ChatStateTracker_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
554
|
+
function ChatStateTracker_defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, ChatStateTracker_toPropertyKey(descriptor.key), descriptor); } }
|
|
555
|
+
function ChatStateTracker_createClass(Constructor, protoProps, staticProps) { if (protoProps) ChatStateTracker_defineProperties(Constructor.prototype, protoProps); if (staticProps) ChatStateTracker_defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
556
|
+
function ChatStateTracker_defineProperty(obj, key, value) { key = ChatStateTracker_toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
557
|
+
function ChatStateTracker_toPropertyKey(arg) { var key = ChatStateTracker_toPrimitive(arg, "string"); return ChatStateTracker_typeof(key) === "symbol" ? key : String(key); }
|
|
558
|
+
function ChatStateTracker_toPrimitive(input, hint) { if (ChatStateTracker_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (ChatStateTracker_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
559
|
+
|
|
560
|
+
var ChatStateTracker = /*#__PURE__*/function () {
|
|
561
|
+
// Temporary not lazy loaded; server must implement GetTopicMessages command.
|
|
562
|
+
|
|
563
|
+
// lazy loaded collections
|
|
564
|
+
|
|
565
|
+
function ChatStateTracker(client) {
|
|
566
|
+
ChatStateTracker_classCallCheck(this, ChatStateTracker);
|
|
567
|
+
this.client = client;
|
|
568
|
+
ChatStateTracker_defineProperty(this, "joinedSpaces", new ObservableIndexedObjectCollection('id'));
|
|
569
|
+
ChatStateTracker_defineProperty(this, "joinedRooms", new ObservableIndexedObjectCollection('id'));
|
|
570
|
+
ChatStateTracker_defineProperty(this, "spacesRoles", new IndexedCollection());
|
|
571
|
+
ChatStateTracker_defineProperty(this, "roomsTopics", new IndexedCollection());
|
|
572
|
+
ChatStateTracker_defineProperty(this, "topicsMessages", new IndexedCollection());
|
|
573
|
+
ChatStateTracker_defineProperty(this, "spacesRooms", new IndexedCollection());
|
|
574
|
+
ChatStateTracker_defineProperty(this, "spacesMembers", new IndexedCollection());
|
|
575
|
+
ChatStateTracker_defineProperty(this, "roomsMembers", new IndexedCollection());
|
|
576
|
+
ChatStateTracker_defineProperty(this, "deferredGetters", new IndexedCollection());
|
|
577
|
+
ChatStateTracker_defineProperty(this, "reconnecting", false);
|
|
578
|
+
ChatStateTracker_defineProperty(this, "me", null);
|
|
579
|
+
this.createDeferredGetter('session');
|
|
580
|
+
this.bind();
|
|
581
|
+
}
|
|
582
|
+
ChatStateTracker_createClass(ChatStateTracker, [{
|
|
583
|
+
key: "getMe",
|
|
584
|
+
value: function () {
|
|
585
|
+
var _getMe = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
586
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
587
|
+
while (1) {
|
|
588
|
+
switch (_context.prev = _context.next) {
|
|
589
|
+
case 0:
|
|
590
|
+
_context.next = 2;
|
|
591
|
+
return this.deferredGetterReadiness('session');
|
|
592
|
+
case 2:
|
|
593
|
+
return _context.abrupt("return", this.me);
|
|
594
|
+
case 3:
|
|
595
|
+
case "end":
|
|
596
|
+
return _context.stop();
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
}, _callee, this);
|
|
600
|
+
}));
|
|
601
|
+
function getMe() {
|
|
602
|
+
return _getMe.apply(this, arguments);
|
|
603
|
+
}
|
|
604
|
+
return getMe;
|
|
605
|
+
}()
|
|
606
|
+
}, {
|
|
607
|
+
key: "getJoinedSpaces",
|
|
608
|
+
value: function () {
|
|
609
|
+
var _getJoinedSpaces = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
|
|
610
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
611
|
+
while (1) {
|
|
612
|
+
switch (_context2.prev = _context2.next) {
|
|
613
|
+
case 0:
|
|
614
|
+
_context2.next = 2;
|
|
615
|
+
return this.deferredGetterReadiness('session');
|
|
616
|
+
case 2:
|
|
617
|
+
return _context2.abrupt("return", this.joinedSpaces);
|
|
618
|
+
case 3:
|
|
619
|
+
case "end":
|
|
620
|
+
return _context2.stop();
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
}, _callee2, this);
|
|
624
|
+
}));
|
|
625
|
+
function getJoinedSpaces() {
|
|
626
|
+
return _getJoinedSpaces.apply(this, arguments);
|
|
627
|
+
}
|
|
628
|
+
return getJoinedSpaces;
|
|
629
|
+
}()
|
|
630
|
+
}, {
|
|
631
|
+
key: "getJoinedRooms",
|
|
632
|
+
value: function () {
|
|
633
|
+
var _getJoinedRooms = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
|
|
634
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
635
|
+
while (1) {
|
|
636
|
+
switch (_context3.prev = _context3.next) {
|
|
637
|
+
case 0:
|
|
638
|
+
_context3.next = 2;
|
|
639
|
+
return this.deferredGetterReadiness('session');
|
|
640
|
+
case 2:
|
|
641
|
+
return _context3.abrupt("return", this.joinedRooms);
|
|
642
|
+
case 3:
|
|
643
|
+
case "end":
|
|
644
|
+
return _context3.stop();
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
}, _callee3, this);
|
|
648
|
+
}));
|
|
649
|
+
function getJoinedRooms() {
|
|
650
|
+
return _getJoinedRooms.apply(this, arguments);
|
|
651
|
+
}
|
|
652
|
+
return getJoinedRooms;
|
|
653
|
+
}()
|
|
654
|
+
}, {
|
|
655
|
+
key: "getSpaceRoles",
|
|
656
|
+
value: function () {
|
|
657
|
+
var _getSpaceRoles = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(spaceId) {
|
|
658
|
+
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
659
|
+
while (1) {
|
|
660
|
+
switch (_context4.prev = _context4.next) {
|
|
661
|
+
case 0:
|
|
662
|
+
_context4.next = 2;
|
|
663
|
+
return this.deferredGetterReadiness('session');
|
|
664
|
+
case 2:
|
|
665
|
+
return _context4.abrupt("return", this.spacesRoles.get(spaceId));
|
|
666
|
+
case 3:
|
|
667
|
+
case "end":
|
|
668
|
+
return _context4.stop();
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
}, _callee4, this);
|
|
672
|
+
}));
|
|
673
|
+
function getSpaceRoles(_x) {
|
|
674
|
+
return _getSpaceRoles.apply(this, arguments);
|
|
675
|
+
}
|
|
676
|
+
return getSpaceRoles;
|
|
677
|
+
}()
|
|
678
|
+
}, {
|
|
679
|
+
key: "getRoomTopics",
|
|
680
|
+
value: function () {
|
|
681
|
+
var _getRoomTopics = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(roomId) {
|
|
682
|
+
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
683
|
+
while (1) {
|
|
684
|
+
switch (_context5.prev = _context5.next) {
|
|
685
|
+
case 0:
|
|
686
|
+
_context5.next = 2;
|
|
687
|
+
return this.deferredGetterReadiness('session');
|
|
688
|
+
case 2:
|
|
689
|
+
return _context5.abrupt("return", this.roomsTopics.get(roomId));
|
|
690
|
+
case 3:
|
|
691
|
+
case "end":
|
|
692
|
+
return _context5.stop();
|
|
693
|
+
}
|
|
694
|
+
}
|
|
695
|
+
}, _callee5, this);
|
|
696
|
+
}));
|
|
697
|
+
function getRoomTopics(_x2) {
|
|
698
|
+
return _getRoomTopics.apply(this, arguments);
|
|
699
|
+
}
|
|
700
|
+
return getRoomTopics;
|
|
701
|
+
}()
|
|
702
|
+
}, {
|
|
703
|
+
key: "getTopicMessages",
|
|
704
|
+
value: function () {
|
|
705
|
+
var _getTopicMessages = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(topicId) {
|
|
706
|
+
return _regeneratorRuntime().wrap(function _callee6$(_context6) {
|
|
707
|
+
while (1) {
|
|
708
|
+
switch (_context6.prev = _context6.next) {
|
|
709
|
+
case 0:
|
|
710
|
+
return _context6.abrupt("return", this.topicsMessages.get(topicId));
|
|
711
|
+
case 1:
|
|
712
|
+
case "end":
|
|
713
|
+
return _context6.stop();
|
|
714
|
+
}
|
|
715
|
+
}
|
|
716
|
+
}, _callee6, this);
|
|
717
|
+
}));
|
|
718
|
+
function getTopicMessages(_x3) {
|
|
719
|
+
return _getTopicMessages.apply(this, arguments);
|
|
720
|
+
}
|
|
721
|
+
return getTopicMessages;
|
|
722
|
+
}()
|
|
723
|
+
}, {
|
|
724
|
+
key: "getSpaceRooms",
|
|
725
|
+
value: function () {
|
|
726
|
+
var _getSpaceRooms = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(spaceId) {
|
|
727
|
+
var deferredGetterName;
|
|
728
|
+
return _regeneratorRuntime().wrap(function _callee7$(_context7) {
|
|
729
|
+
while (1) {
|
|
730
|
+
switch (_context7.prev = _context7.next) {
|
|
731
|
+
case 0:
|
|
732
|
+
deferredGetterName = "spaces-rooms-".concat(spaceId);
|
|
733
|
+
if (!this.spacesRooms.has(spaceId) && !this.deferredGetters.has(deferredGetterName)) {
|
|
734
|
+
this.createDeferredGetter(deferredGetterName);
|
|
735
|
+
this.client.send('GetSpaceRooms', {
|
|
736
|
+
id: spaceId
|
|
737
|
+
});
|
|
738
|
+
}
|
|
739
|
+
_context7.next = 4;
|
|
740
|
+
return this.deferredGetterReadiness(deferredGetterName);
|
|
741
|
+
case 4:
|
|
742
|
+
return _context7.abrupt("return", this.spacesRooms.get(spaceId));
|
|
743
|
+
case 5:
|
|
744
|
+
case "end":
|
|
745
|
+
return _context7.stop();
|
|
746
|
+
}
|
|
747
|
+
}
|
|
748
|
+
}, _callee7, this);
|
|
749
|
+
}));
|
|
750
|
+
function getSpaceRooms(_x4) {
|
|
751
|
+
return _getSpaceRooms.apply(this, arguments);
|
|
752
|
+
}
|
|
753
|
+
return getSpaceRooms;
|
|
754
|
+
}()
|
|
755
|
+
}, {
|
|
756
|
+
key: "getSpaceMembers",
|
|
757
|
+
value: function () {
|
|
758
|
+
var _getSpaceMembers = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(spaceId) {
|
|
759
|
+
var deferredGetterName;
|
|
760
|
+
return _regeneratorRuntime().wrap(function _callee8$(_context8) {
|
|
761
|
+
while (1) {
|
|
762
|
+
switch (_context8.prev = _context8.next) {
|
|
763
|
+
case 0:
|
|
764
|
+
deferredGetterName = "spaces-members-".concat(spaceId);
|
|
765
|
+
if (!this.spacesMembers.has(spaceId) && !this.deferredGetters.has(deferredGetterName)) {
|
|
766
|
+
this.createDeferredGetter(deferredGetterName);
|
|
767
|
+
this.client.send('GetSpaceMembers', {
|
|
768
|
+
id: spaceId
|
|
769
|
+
});
|
|
770
|
+
}
|
|
771
|
+
_context8.next = 4;
|
|
772
|
+
return this.deferredGetterReadiness(deferredGetterName);
|
|
773
|
+
case 4:
|
|
774
|
+
return _context8.abrupt("return", this.spacesMembers.get(spaceId));
|
|
775
|
+
case 5:
|
|
776
|
+
case "end":
|
|
777
|
+
return _context8.stop();
|
|
778
|
+
}
|
|
779
|
+
}
|
|
780
|
+
}, _callee8, this);
|
|
781
|
+
}));
|
|
782
|
+
function getSpaceMembers(_x5) {
|
|
783
|
+
return _getSpaceMembers.apply(this, arguments);
|
|
784
|
+
}
|
|
785
|
+
return getSpaceMembers;
|
|
786
|
+
}()
|
|
787
|
+
}, {
|
|
788
|
+
key: "getRoomMembers",
|
|
789
|
+
value: function () {
|
|
790
|
+
var _getRoomMembers = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(roomId) {
|
|
791
|
+
var deferredGetterName;
|
|
792
|
+
return _regeneratorRuntime().wrap(function _callee9$(_context9) {
|
|
793
|
+
while (1) {
|
|
794
|
+
switch (_context9.prev = _context9.next) {
|
|
795
|
+
case 0:
|
|
796
|
+
deferredGetterName = "rooms-members-".concat(roomId);
|
|
797
|
+
if (!this.roomsMembers.has(roomId) && !this.deferredGetters.has(deferredGetterName)) {
|
|
798
|
+
this.createDeferredGetter(deferredGetterName);
|
|
799
|
+
this.client.send('GetRoomMembers', {
|
|
800
|
+
id: roomId
|
|
801
|
+
});
|
|
802
|
+
}
|
|
803
|
+
_context9.next = 4;
|
|
804
|
+
return this.deferredGetterReadiness(deferredGetterName);
|
|
805
|
+
case 4:
|
|
806
|
+
return _context9.abrupt("return", this.roomsMembers.get(roomId));
|
|
807
|
+
case 5:
|
|
808
|
+
case "end":
|
|
809
|
+
return _context9.stop();
|
|
810
|
+
}
|
|
811
|
+
}
|
|
812
|
+
}, _callee9, this);
|
|
813
|
+
}));
|
|
814
|
+
function getRoomMembers(_x6) {
|
|
815
|
+
return _getRoomMembers.apply(this, arguments);
|
|
816
|
+
}
|
|
817
|
+
return getRoomMembers;
|
|
818
|
+
}()
|
|
819
|
+
}, {
|
|
820
|
+
key: "deferredGetterReadiness",
|
|
821
|
+
value: function () {
|
|
822
|
+
var _deferredGetterReadiness = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(name) {
|
|
823
|
+
var _this$deferredGetters;
|
|
824
|
+
return _regeneratorRuntime().wrap(function _callee10$(_context10) {
|
|
825
|
+
while (1) {
|
|
826
|
+
switch (_context10.prev = _context10.next) {
|
|
827
|
+
case 0:
|
|
828
|
+
if (!this.deferredGetters.has(name)) {
|
|
829
|
+
_context10.next = 3;
|
|
830
|
+
break;
|
|
831
|
+
}
|
|
832
|
+
_context10.next = 3;
|
|
833
|
+
return (_this$deferredGetters = this.deferredGetters.get(name)) === null || _this$deferredGetters === void 0 ? void 0 : _this$deferredGetters.promise;
|
|
834
|
+
case 3:
|
|
835
|
+
case "end":
|
|
836
|
+
return _context10.stop();
|
|
837
|
+
}
|
|
838
|
+
}
|
|
839
|
+
}, _callee10, this);
|
|
840
|
+
}));
|
|
841
|
+
function deferredGetterReadiness(_x7) {
|
|
842
|
+
return _deferredGetterReadiness.apply(this, arguments);
|
|
843
|
+
}
|
|
844
|
+
return deferredGetterReadiness;
|
|
845
|
+
}()
|
|
846
|
+
}, {
|
|
847
|
+
key: "bind",
|
|
848
|
+
value: function bind() {
|
|
849
|
+
var _this = this;
|
|
850
|
+
this.client.on(this.client.Event.disconnect, function (ev) {
|
|
851
|
+
return _this.handleDisconnect(ev);
|
|
852
|
+
});
|
|
853
|
+
this.client.on('NewMessage', function (ev) {
|
|
854
|
+
return _this.handleNewMessage(ev);
|
|
855
|
+
});
|
|
856
|
+
this.client.on('NewRole', function (ev) {
|
|
857
|
+
return _this.handleNewRole(ev);
|
|
858
|
+
});
|
|
859
|
+
this.client.on('NewRoom', function (ev) {
|
|
860
|
+
return _this.handleNewRoom(ev);
|
|
861
|
+
});
|
|
862
|
+
this.client.on('NewTopic', function (ev) {
|
|
863
|
+
return _this.handleNewTopic(ev);
|
|
864
|
+
});
|
|
865
|
+
this.client.on('RoleDeleted', function (ev) {
|
|
866
|
+
return _this.handleRoleDeleted(ev);
|
|
867
|
+
});
|
|
868
|
+
this.client.on('RoomDeleted', function (ev) {
|
|
869
|
+
return _this.handleRoomDeleted(ev);
|
|
870
|
+
});
|
|
871
|
+
this.client.on('RoomJoined', function (ev) {
|
|
872
|
+
return _this.handleRoomJoined(ev);
|
|
873
|
+
});
|
|
874
|
+
this.client.on('RoomLeft', function (ev) {
|
|
875
|
+
return _this.handleRoomLeft(ev);
|
|
876
|
+
});
|
|
877
|
+
this.client.on('RoomMemberJoined', function (ev) {
|
|
878
|
+
return _this.handleRoomMemberJoined(ev);
|
|
879
|
+
});
|
|
880
|
+
this.client.on('RoomMemberLeft', function (ev) {
|
|
881
|
+
return _this.handleRoomMemberLeft(ev);
|
|
882
|
+
});
|
|
883
|
+
this.client.on('RoomMembers', function (ev) {
|
|
884
|
+
return _this.handleRoomMembers(ev);
|
|
885
|
+
});
|
|
886
|
+
this.client.on('Session', function (ev) {
|
|
887
|
+
return _this.handleSession(ev);
|
|
888
|
+
});
|
|
889
|
+
this.client.on('SpaceDeleted', function (ev) {
|
|
890
|
+
return _this.handleSpaceDeleted(ev);
|
|
891
|
+
});
|
|
892
|
+
this.client.on('SpaceJoined', function (ev) {
|
|
893
|
+
return _this.handleSpaceJoined(ev);
|
|
894
|
+
});
|
|
895
|
+
this.client.on('SpaceLeft', function (ev) {
|
|
896
|
+
return _this.handleSpaceLeft(ev);
|
|
897
|
+
});
|
|
898
|
+
this.client.on('SpaceMemberJoined', function (ev) {
|
|
899
|
+
return _this.handleSpaceMemberJoined(ev);
|
|
900
|
+
});
|
|
901
|
+
this.client.on('SpaceMemberLeft', function (ev) {
|
|
902
|
+
return _this.handleSpaceMemberLeft(ev);
|
|
903
|
+
});
|
|
904
|
+
this.client.on('SpaceMembers', function (ev) {
|
|
905
|
+
return _this.handleSpaceMembers(ev);
|
|
906
|
+
});
|
|
907
|
+
this.client.on('SpaceRooms', function (ev) {
|
|
908
|
+
return _this.handleSpaceRooms(ev);
|
|
909
|
+
});
|
|
910
|
+
this.client.on('SpaceMemberUpdate', function (ev) {
|
|
911
|
+
return _this.handleSpaceMemberUpdate(ev);
|
|
912
|
+
});
|
|
913
|
+
this.client.on('TopicDeleted', function (ev) {
|
|
914
|
+
return _this.handleTopicDeleted(ev);
|
|
915
|
+
});
|
|
916
|
+
}
|
|
917
|
+
}, {
|
|
918
|
+
key: "createDeferredGetter",
|
|
919
|
+
value: function createDeferredGetter(name) {
|
|
920
|
+
if (this.deferredGetters.has(name)) {
|
|
921
|
+
return;
|
|
922
|
+
}
|
|
923
|
+
var deferred = {
|
|
924
|
+
promise: undefined,
|
|
925
|
+
resolver: undefined
|
|
926
|
+
};
|
|
927
|
+
deferred.promise = new Promise(function (resolve) {
|
|
928
|
+
return deferred.resolver = resolve;
|
|
929
|
+
});
|
|
930
|
+
this.deferredGetters.set([name, deferred]);
|
|
931
|
+
}
|
|
932
|
+
}, {
|
|
933
|
+
key: "handleDisconnect",
|
|
934
|
+
value: function handleDisconnect(reconnect) {
|
|
935
|
+
if (reconnect) {
|
|
936
|
+
this.reconnecting = true;
|
|
937
|
+
return;
|
|
938
|
+
}
|
|
939
|
+
}
|
|
940
|
+
}, {
|
|
941
|
+
key: "handleNewMessage",
|
|
942
|
+
value: function handleNewMessage(ev) {
|
|
943
|
+
this.topicsMessages.get(ev.topicId).set(ev.message);
|
|
944
|
+
}
|
|
945
|
+
}, {
|
|
946
|
+
key: "handleNewRole",
|
|
947
|
+
value: function handleNewRole(ev) {
|
|
948
|
+
var collection = this.spacesRoles.get(ev.spaceId);
|
|
949
|
+
collection.set(ev.role);
|
|
950
|
+
this.joinedSpaces.get(ev.spaceId).roles = collection.items;
|
|
951
|
+
}
|
|
952
|
+
}, {
|
|
953
|
+
key: "handleNewRoom",
|
|
954
|
+
value: function handleNewRoom(ev) {
|
|
955
|
+
var _this$spacesRooms$get;
|
|
956
|
+
(_this$spacesRooms$get = this.spacesRooms.get(ev.spaceId)) === null || _this$spacesRooms$get === void 0 ? void 0 : _this$spacesRooms$get.set(ev.summary);
|
|
957
|
+
}
|
|
958
|
+
}, {
|
|
959
|
+
key: "handleNewTopic",
|
|
960
|
+
value: function handleNewTopic(ev) {
|
|
961
|
+
var collection = this.roomsTopics.get(ev.roomId);
|
|
962
|
+
collection.set(ev.topic);
|
|
963
|
+
this.joinedRooms.get(ev.roomId).topics = collection.items;
|
|
964
|
+
}
|
|
965
|
+
}, {
|
|
966
|
+
key: "handleRoleDeleted",
|
|
967
|
+
value: function handleRoleDeleted(ev) {
|
|
968
|
+
var collection = this.spacesRoles.get(ev.spaceId);
|
|
969
|
+
collection["delete"](ev.id);
|
|
970
|
+
this.joinedSpaces.get(ev.spaceId).roles = collection.items;
|
|
971
|
+
}
|
|
972
|
+
}, {
|
|
973
|
+
key: "handleRoomDeleted",
|
|
974
|
+
value: function handleRoomDeleted(ev) {
|
|
975
|
+
if (ev.spaceId) {
|
|
976
|
+
this.spacesRooms.get(ev.spaceId)["delete"](ev.id);
|
|
977
|
+
}
|
|
978
|
+
this.joinedRooms["delete"](ev.id);
|
|
979
|
+
this.roomsMembers["delete"](ev.id);
|
|
980
|
+
this.roomsTopics["delete"](ev.id);
|
|
981
|
+
}
|
|
982
|
+
}, {
|
|
983
|
+
key: "handleRoomJoined",
|
|
984
|
+
value: function handleRoomJoined(ev) {
|
|
985
|
+
this.addJoinedRooms(ev.room);
|
|
986
|
+
}
|
|
987
|
+
}, {
|
|
988
|
+
key: "addJoinedRooms",
|
|
989
|
+
value: function addJoinedRooms() {
|
|
990
|
+
var _this$roomsTopics, _this$joinedRooms;
|
|
991
|
+
for (var _len = arguments.length, rooms = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
992
|
+
rooms[_key] = arguments[_key];
|
|
993
|
+
}
|
|
994
|
+
(_this$roomsTopics = this.roomsTopics).set.apply(_this$roomsTopics, ChatStateTracker_toConsumableArray(rooms.map(function (room) {
|
|
995
|
+
return [room.id, new ObservableIndexedObjectCollection('id', room.topics)];
|
|
996
|
+
})));
|
|
997
|
+
(_this$joinedRooms = this.joinedRooms).set.apply(_this$joinedRooms, rooms);
|
|
998
|
+
}
|
|
999
|
+
}, {
|
|
1000
|
+
key: "handleRoomLeft",
|
|
1001
|
+
value: function handleRoomLeft(ev) {
|
|
1002
|
+
this.joinedRooms["delete"](ev.id);
|
|
1003
|
+
this.roomsMembers["delete"](ev.id);
|
|
1004
|
+
this.roomsTopics["delete"](ev.id);
|
|
1005
|
+
}
|
|
1006
|
+
}, {
|
|
1007
|
+
key: "handleRoomMemberJoined",
|
|
1008
|
+
value: function handleRoomMemberJoined(ev) {
|
|
1009
|
+
if (this.roomsMembers.has(ev.roomId)) {
|
|
1010
|
+
this.roomsMembers.get(ev.roomId).set(ev.member);
|
|
1011
|
+
}
|
|
1012
|
+
}
|
|
1013
|
+
}, {
|
|
1014
|
+
key: "handleRoomMemberLeft",
|
|
1015
|
+
value: function handleRoomMemberLeft(ev) {
|
|
1016
|
+
if (this.roomsMembers.has(ev.roomId)) {
|
|
1017
|
+
this.roomsMembers.get(ev.roomId)["delete"](ev.userId);
|
|
1018
|
+
}
|
|
1019
|
+
}
|
|
1020
|
+
}, {
|
|
1021
|
+
key: "handleRoomMembers",
|
|
1022
|
+
value: function handleRoomMembers(ev) {
|
|
1023
|
+
if (!this.roomsMembers.has(ev.id)) {
|
|
1024
|
+
var _this$deferredGetters2;
|
|
1025
|
+
this.roomsMembers.set([ev.id, new ObservableIndexedObjectCollection(function (member) {
|
|
1026
|
+
var _member$user$id;
|
|
1027
|
+
return (_member$user$id = member === null || member === void 0 ? void 0 : member.user.id) !== null && _member$user$id !== void 0 ? _member$user$id : member.spaceMember.user.id;
|
|
1028
|
+
}, ev.members)]);
|
|
1029
|
+
(_this$deferredGetters2 = this.deferredGetters.get("rooms-members-".concat(ev.id))) === null || _this$deferredGetters2 === void 0 ? void 0 : _this$deferredGetters2.resolver();
|
|
1030
|
+
}
|
|
1031
|
+
}
|
|
1032
|
+
}, {
|
|
1033
|
+
key: "handleSession",
|
|
1034
|
+
value: function handleSession(ev) {
|
|
1035
|
+
var _this$deferredGetters3;
|
|
1036
|
+
if (this.me && !this.reconnecting) {
|
|
1037
|
+
return;
|
|
1038
|
+
}
|
|
1039
|
+
this.me = ev.user;
|
|
1040
|
+
this.reconnecting = false;
|
|
1041
|
+
this.joinedRooms.deleteAll();
|
|
1042
|
+
this.roomsTopics.deleteAll();
|
|
1043
|
+
this.roomsMembers.deleteAll();
|
|
1044
|
+
this.joinedSpaces.deleteAll();
|
|
1045
|
+
this.spacesRoles.deleteAll();
|
|
1046
|
+
this.spacesRooms.deleteAll();
|
|
1047
|
+
this.spacesMembers.deleteAll();
|
|
1048
|
+
this.addJoinedRooms.apply(this, ChatStateTracker_toConsumableArray(ev.state.rooms));
|
|
1049
|
+
this.addJoinedSpaces.apply(this, ChatStateTracker_toConsumableArray(ev.state.spaces));
|
|
1050
|
+
(_this$deferredGetters3 = this.deferredGetters.get('session')) === null || _this$deferredGetters3 === void 0 ? void 0 : _this$deferredGetters3.resolver();
|
|
1051
|
+
}
|
|
1052
|
+
}, {
|
|
1053
|
+
key: "handleSpaceDeleted",
|
|
1054
|
+
value: function handleSpaceDeleted(ev) {
|
|
1055
|
+
this.spacesRoles["delete"](ev.id);
|
|
1056
|
+
this.spacesMembers["delete"](ev.id);
|
|
1057
|
+
this.spacesRooms["delete"](ev.id);
|
|
1058
|
+
this.joinedSpaces["delete"](ev.id);
|
|
1059
|
+
}
|
|
1060
|
+
}, {
|
|
1061
|
+
key: "handleSpaceJoined",
|
|
1062
|
+
value: function handleSpaceJoined(ev) {
|
|
1063
|
+
this.addJoinedSpaces(ev.space);
|
|
1064
|
+
}
|
|
1065
|
+
}, {
|
|
1066
|
+
key: "addJoinedSpaces",
|
|
1067
|
+
value: function addJoinedSpaces() {
|
|
1068
|
+
var _this$spacesRoles, _this$joinedSpaces;
|
|
1069
|
+
for (var _len2 = arguments.length, spaces = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
1070
|
+
spaces[_key2] = arguments[_key2];
|
|
1071
|
+
}
|
|
1072
|
+
(_this$spacesRoles = this.spacesRoles).set.apply(_this$spacesRoles, ChatStateTracker_toConsumableArray(spaces.map(function (space) {
|
|
1073
|
+
return [space.id, new ObservableIndexedObjectCollection('id', space.roles)];
|
|
1074
|
+
})));
|
|
1075
|
+
(_this$joinedSpaces = this.joinedSpaces).set.apply(_this$joinedSpaces, spaces);
|
|
1076
|
+
}
|
|
1077
|
+
}, {
|
|
1078
|
+
key: "handleSpaceLeft",
|
|
1079
|
+
value: function handleSpaceLeft(ev) {
|
|
1080
|
+
this.spacesRoles["delete"](ev.id);
|
|
1081
|
+
this.spacesMembers["delete"](ev.id);
|
|
1082
|
+
this.spacesRooms["delete"](ev.id);
|
|
1083
|
+
this.joinedSpaces["delete"](ev.id);
|
|
1084
|
+
}
|
|
1085
|
+
}, {
|
|
1086
|
+
key: "handleSpaceMemberJoined",
|
|
1087
|
+
value: function handleSpaceMemberJoined(ev) {
|
|
1088
|
+
if (this.spacesMembers.has(ev.spaceId)) {
|
|
1089
|
+
this.spacesMembers.get(ev.spaceId).set(ev.member);
|
|
1090
|
+
}
|
|
1091
|
+
}
|
|
1092
|
+
}, {
|
|
1093
|
+
key: "handleSpaceMemberLeft",
|
|
1094
|
+
value: function handleSpaceMemberLeft(ev) {
|
|
1095
|
+
if (this.spacesMembers.has(ev.spaceId)) {
|
|
1096
|
+
this.spacesMembers.get(ev.spaceId)["delete"](ev.userId);
|
|
1097
|
+
}
|
|
1098
|
+
}
|
|
1099
|
+
}, {
|
|
1100
|
+
key: "handleSpaceMembers",
|
|
1101
|
+
value: function handleSpaceMembers(ev) {
|
|
1102
|
+
if (!this.spacesMembers.has(ev.id)) {
|
|
1103
|
+
var _this$deferredGetters4;
|
|
1104
|
+
this.spacesMembers.set([ev.id, new ObservableIndexedObjectCollection(function (member) {
|
|
1105
|
+
return member === null || member === void 0 ? void 0 : member.user.id;
|
|
1106
|
+
}, ev.members)]);
|
|
1107
|
+
(_this$deferredGetters4 = this.deferredGetters.get("spaces-members-".concat(ev.id))) === null || _this$deferredGetters4 === void 0 ? void 0 : _this$deferredGetters4.resolver();
|
|
1108
|
+
}
|
|
1109
|
+
}
|
|
1110
|
+
}, {
|
|
1111
|
+
key: "handleSpaceRooms",
|
|
1112
|
+
value: function handleSpaceRooms(ev) {
|
|
1113
|
+
if (!this.spacesRooms.has(ev.id)) {
|
|
1114
|
+
var _this$deferredGetters5;
|
|
1115
|
+
this.spacesRooms.set([ev.id, new ObservableIndexedObjectCollection('id', ev.summaries)]);
|
|
1116
|
+
(_this$deferredGetters5 = this.deferredGetters.get("spaces-rooms-".concat(ev.id))) === null || _this$deferredGetters5 === void 0 ? void 0 : _this$deferredGetters5.resolver();
|
|
1117
|
+
}
|
|
1118
|
+
}
|
|
1119
|
+
}, {
|
|
1120
|
+
key: "handleSpaceMemberUpdate",
|
|
1121
|
+
value: function handleSpaceMemberUpdate(ev) {
|
|
1122
|
+
if (this.spacesMembers.has(ev.spaceId)) {
|
|
1123
|
+
this.spacesMembers.get(ev.spaceId).set(ev.member);
|
|
1124
|
+
}
|
|
1125
|
+
}
|
|
1126
|
+
}, {
|
|
1127
|
+
key: "handleTopicDeleted",
|
|
1128
|
+
value: function handleTopicDeleted(ev) {
|
|
1129
|
+
var collection = this.roomsTopics.get(ev.roomId);
|
|
1130
|
+
collection["delete"](ev.id);
|
|
1131
|
+
this.joinedRooms.get(ev.roomId).topics = collection.items;
|
|
1132
|
+
}
|
|
1133
|
+
}]);
|
|
1134
|
+
return ChatStateTracker;
|
|
1135
|
+
}();
|
|
1136
|
+
;// CONCATENATED MODULE: ./src/WebSocketChatClient.ts
|
|
1137
|
+
function WebSocketChatClient_typeof(obj) { "@babel/helpers - typeof"; return WebSocketChatClient_typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, WebSocketChatClient_typeof(obj); }
|
|
1138
|
+
function WebSocketChatClient_toConsumableArray(arr) { return WebSocketChatClient_arrayWithoutHoles(arr) || WebSocketChatClient_iterableToArray(arr) || WebSocketChatClient_unsupportedIterableToArray(arr) || WebSocketChatClient_nonIterableSpread(); }
|
|
1139
|
+
function WebSocketChatClient_nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
1140
|
+
function WebSocketChatClient_unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return WebSocketChatClient_arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return WebSocketChatClient_arrayLikeToArray(o, minLen); }
|
|
1141
|
+
function WebSocketChatClient_iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
1142
|
+
function WebSocketChatClient_arrayWithoutHoles(arr) { if (Array.isArray(arr)) return WebSocketChatClient_arrayLikeToArray(arr); }
|
|
1143
|
+
function WebSocketChatClient_arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
1144
|
+
function WebSocketChatClient_regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ WebSocketChatClient_regeneratorRuntime = function _regeneratorRuntime() { return exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, defineProperty = Object.defineProperty || function (obj, key, desc) { obj[key] = desc.value; }, $Symbol = "function" == typeof Symbol ? Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []); return defineProperty(generator, "_invoke", { value: makeInvokeMethod(innerFn, self, context) }), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = Object.getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); function defineIteratorMethods(prototype) { ["next", "throw", "return"].forEach(function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == WebSocketChatClient_typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; defineProperty(this, "_invoke", { value: function value(method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; } function maybeInvokeDelegate(delegate, context) { var methodName = context.method, method = delegate.iterator[methodName]; if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator["return"] && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel; var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) { if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; } return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), defineProperty(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (val) { var object = Object(val), keys = []; for (var key in object) { keys.push(key); } return keys.reverse(), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) { "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); } }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, "catch": function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; }
|
|
1145
|
+
function WebSocketChatClient_asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
1146
|
+
function WebSocketChatClient_asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { WebSocketChatClient_asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { WebSocketChatClient_asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
1147
|
+
function WebSocketChatClient_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
1148
|
+
function WebSocketChatClient_defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, WebSocketChatClient_toPropertyKey(descriptor.key), descriptor); } }
|
|
1149
|
+
function WebSocketChatClient_createClass(Constructor, protoProps, staticProps) { if (protoProps) WebSocketChatClient_defineProperties(Constructor.prototype, protoProps); if (staticProps) WebSocketChatClient_defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
1150
|
+
function WebSocketChatClient_inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) WebSocketChatClient_setPrototypeOf(subClass, superClass); }
|
|
1151
|
+
function WebSocketChatClient_setPrototypeOf(o, p) { WebSocketChatClient_setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return WebSocketChatClient_setPrototypeOf(o, p); }
|
|
1152
|
+
function WebSocketChatClient_createSuper(Derived) { var hasNativeReflectConstruct = WebSocketChatClient_isNativeReflectConstruct(); return function _createSuperInternal() { var Super = WebSocketChatClient_getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = WebSocketChatClient_getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return WebSocketChatClient_possibleConstructorReturn(this, result); }; }
|
|
1153
|
+
function WebSocketChatClient_possibleConstructorReturn(self, call) { if (call && (WebSocketChatClient_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return WebSocketChatClient_assertThisInitialized(self); }
|
|
1154
|
+
function WebSocketChatClient_assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
1155
|
+
function WebSocketChatClient_isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
1156
|
+
function WebSocketChatClient_getPrototypeOf(o) { WebSocketChatClient_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return WebSocketChatClient_getPrototypeOf(o); }
|
|
1157
|
+
function WebSocketChatClient_defineProperty(obj, key, value) { key = WebSocketChatClient_toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
1158
|
+
function WebSocketChatClient_toPropertyKey(arg) { var key = WebSocketChatClient_toPrimitive(arg, "string"); return WebSocketChatClient_typeof(key) === "symbol" ? key : String(key); }
|
|
1159
|
+
function WebSocketChatClient_toPrimitive(input, hint) { if (WebSocketChatClient_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (WebSocketChatClient_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
1160
|
+
|
|
1161
|
+
|
|
1162
|
+
var WebSocketChatClientEvent;
|
|
1163
|
+
(function (WebSocketChatClientEvent) {
|
|
1164
|
+
WebSocketChatClientEvent["connect"] = "connect";
|
|
1165
|
+
WebSocketChatClientEvent["disconnect"] = "disconnect";
|
|
1166
|
+
WebSocketChatClientEvent["message"] = "message";
|
|
1167
|
+
WebSocketChatClientEvent["error"] = "error";
|
|
1168
|
+
})(WebSocketChatClientEvent || (WebSocketChatClientEvent = {}));
|
|
1169
|
+
var WebSocketChatClient = /*#__PURE__*/function (_AbstractChatClient) {
|
|
1170
|
+
WebSocketChatClient_inherits(WebSocketChatClient, _AbstractChatClient);
|
|
1171
|
+
var _super = WebSocketChatClient_createSuper(WebSocketChatClient);
|
|
1172
|
+
function WebSocketChatClient(options) {
|
|
1173
|
+
var _this$options$stateTr;
|
|
1174
|
+
var _this;
|
|
1175
|
+
WebSocketChatClient_classCallCheck(this, WebSocketChatClient);
|
|
1176
|
+
_this = _super.call(this);
|
|
1177
|
+
_this.options = options;
|
|
1178
|
+
WebSocketChatClient_defineProperty(WebSocketChatClient_assertThisInitialized(_this), "Event", WebSocketChatClientEvent);
|
|
1179
|
+
WebSocketChatClient_defineProperty(WebSocketChatClient_assertThisInitialized(_this), "state", void 0);
|
|
1180
|
+
WebSocketChatClient_defineProperty(WebSocketChatClient_assertThisInitialized(_this), "ws", null);
|
|
1181
|
+
WebSocketChatClient_defineProperty(WebSocketChatClient_assertThisInitialized(_this), "sendQueue", []);
|
|
1182
|
+
WebSocketChatClient_defineProperty(WebSocketChatClient_assertThisInitialized(_this), "connectingTimeoutId", void 0);
|
|
1183
|
+
WebSocketChatClient_defineProperty(WebSocketChatClient_assertThisInitialized(_this), "authenticated", void 0);
|
|
1184
|
+
WebSocketChatClient_defineProperty(WebSocketChatClient_assertThisInitialized(_this), "authenticatedResolvers", void 0);
|
|
1185
|
+
if (!_this.options.token && !_this.options.temporaryNick) {
|
|
1186
|
+
throw new Error('Token or temporary nick is required');
|
|
1187
|
+
}
|
|
1188
|
+
if ((_this$options$stateTr = _this.options.stateTracking) !== null && _this$options$stateTr !== void 0 ? _this$options$stateTr : true) {
|
|
1189
|
+
_this.state = new ChatStateTracker(WebSocketChatClient_assertThisInitialized(_this));
|
|
1190
|
+
}
|
|
1191
|
+
return _this;
|
|
1192
|
+
}
|
|
1193
|
+
WebSocketChatClient_createClass(WebSocketChatClient, [{
|
|
1194
|
+
key: "connect",
|
|
1195
|
+
value: function () {
|
|
1196
|
+
var _connect = WebSocketChatClient_asyncToGenerator( /*#__PURE__*/WebSocketChatClient_regeneratorRuntime().mark(function _callee() {
|
|
1197
|
+
var _this2 = this,
|
|
1198
|
+
_this$options$connect;
|
|
1199
|
+
var authString;
|
|
1200
|
+
return WebSocketChatClient_regeneratorRuntime().wrap(function _callee$(_context) {
|
|
1201
|
+
while (1) {
|
|
1202
|
+
switch (_context.prev = _context.next) {
|
|
1203
|
+
case 0:
|
|
1204
|
+
authString = this.options.token ? "token=".concat(this.options.token) : "nick=".concat(this.options.temporaryNick);
|
|
1205
|
+
this.ws = new WebSocket("".concat(this.options.url, "?").concat(authString));
|
|
1206
|
+
this.ws.onclose = function (ev) {
|
|
1207
|
+
return _this2.onClose(ev);
|
|
1208
|
+
};
|
|
1209
|
+
this.ws.onmessage = function (ev) {
|
|
1210
|
+
return _this2.onMessage(ev);
|
|
1211
|
+
};
|
|
1212
|
+
this.connectingTimeoutId = setTimeout(function () {
|
|
1213
|
+
return _this2.triggerConnectionTimeout();
|
|
1214
|
+
}, (_this$options$connect = this.options.connectingTimeoutMs) !== null && _this$options$connect !== void 0 ? _this$options$connect : 10000);
|
|
1215
|
+
this.authenticated = false;
|
|
1216
|
+
return _context.abrupt("return", new Promise(function () {
|
|
1217
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
1218
|
+
args[_key] = arguments[_key];
|
|
1219
|
+
}
|
|
1220
|
+
return _this2.authenticatedResolvers = args;
|
|
1221
|
+
}));
|
|
1222
|
+
case 7:
|
|
1223
|
+
case "end":
|
|
1224
|
+
return _context.stop();
|
|
1225
|
+
}
|
|
1226
|
+
}
|
|
1227
|
+
}, _callee, this);
|
|
1228
|
+
}));
|
|
1229
|
+
function connect() {
|
|
1230
|
+
return _connect.apply(this, arguments);
|
|
1231
|
+
}
|
|
1232
|
+
return connect;
|
|
1233
|
+
}()
|
|
1234
|
+
}, {
|
|
1235
|
+
key: "disconnect",
|
|
1236
|
+
value: function disconnect() {
|
|
1237
|
+
var _this$ws;
|
|
1238
|
+
this.sendQueue = [];
|
|
1239
|
+
(_this$ws = this.ws) === null || _this$ws === void 0 ? void 0 : _this$ws.close();
|
|
1240
|
+
this.ws = null;
|
|
1241
|
+
}
|
|
1242
|
+
}, {
|
|
1243
|
+
key: "send",
|
|
1244
|
+
value: function () {
|
|
1245
|
+
var _send = WebSocketChatClient_asyncToGenerator( /*#__PURE__*/WebSocketChatClient_regeneratorRuntime().mark(function _callee2(commandType, commandData) {
|
|
1246
|
+
var envelope;
|
|
1247
|
+
return WebSocketChatClient_regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
1248
|
+
while (1) {
|
|
1249
|
+
switch (_context2.prev = _context2.next) {
|
|
1250
|
+
case 0:
|
|
1251
|
+
if (!(!this.ws || [this.ws.CLOSED, this.ws.CLOSING].includes(this.ws.readyState))) {
|
|
1252
|
+
_context2.next = 2;
|
|
1253
|
+
break;
|
|
1254
|
+
}
|
|
1255
|
+
throw new Error('Cannot send; close or closing connection state');
|
|
1256
|
+
case 2:
|
|
1257
|
+
if (!(this.ws.readyState === this.ws.CONNECTING || !this.authenticated)) {
|
|
1258
|
+
_context2.next = 5;
|
|
1259
|
+
break;
|
|
1260
|
+
}
|
|
1261
|
+
this.sendQueue.push([commandType, commandData]);
|
|
1262
|
+
return _context2.abrupt("return");
|
|
1263
|
+
case 5:
|
|
1264
|
+
if (!(this.ws.readyState !== this.ws.OPEN)) {
|
|
1265
|
+
_context2.next = 7;
|
|
1266
|
+
break;
|
|
1267
|
+
}
|
|
1268
|
+
throw new Error("Invalid websocket state=".concat(this.ws.readyState));
|
|
1269
|
+
case 7:
|
|
1270
|
+
envelope = this.createEnvelope(commandType, commandData);
|
|
1271
|
+
this.ws.send(JSON.stringify(envelope));
|
|
1272
|
+
return _context2.abrupt("return", this.createPromiseFromCommandEnvelope(envelope));
|
|
1273
|
+
case 10:
|
|
1274
|
+
case "end":
|
|
1275
|
+
return _context2.stop();
|
|
1276
|
+
}
|
|
1277
|
+
}
|
|
1278
|
+
}, _callee2, this);
|
|
1279
|
+
}));
|
|
1280
|
+
function send(_x, _x2) {
|
|
1281
|
+
return _send.apply(this, arguments);
|
|
1282
|
+
}
|
|
1283
|
+
return send;
|
|
1284
|
+
}()
|
|
1285
|
+
}, {
|
|
1286
|
+
key: "onMessage",
|
|
1287
|
+
value: function onMessage(event) {
|
|
1288
|
+
var envelope = JSON.parse(event.data);
|
|
1289
|
+
this.handleIncomingEnvelope(envelope);
|
|
1290
|
+
this.emit(envelope.type, envelope.data);
|
|
1291
|
+
this.emit(this.Event.message, envelope);
|
|
1292
|
+
|
|
1293
|
+
// Login successfully
|
|
1294
|
+
if (!this.authenticated) {
|
|
1295
|
+
var isAuthenticated = envelope.type !== 'Error';
|
|
1296
|
+
this.authenticated = isAuthenticated;
|
|
1297
|
+
if (isAuthenticated) {
|
|
1298
|
+
this.authenticatedResolvers[0]();
|
|
1299
|
+
this.emit(this.Event.connect);
|
|
1300
|
+
this.sendFromQueue();
|
|
1301
|
+
} else {
|
|
1302
|
+
this.authenticatedResolvers[1](envelope.data);
|
|
1303
|
+
}
|
|
1304
|
+
}
|
|
1305
|
+
}
|
|
1306
|
+
}, {
|
|
1307
|
+
key: "onClose",
|
|
1308
|
+
value: function onClose(event) {
|
|
1309
|
+
clearTimeout(this.connectingTimeoutId);
|
|
1310
|
+
var reconnect = event.code !== 1000; // Connection was closed because of error
|
|
1311
|
+
if (reconnect) {
|
|
1312
|
+
this.connect();
|
|
1313
|
+
}
|
|
1314
|
+
this.emit(this.Event.disconnect, reconnect);
|
|
1315
|
+
}
|
|
1316
|
+
}, {
|
|
1317
|
+
key: "sendFromQueue",
|
|
1318
|
+
value: function sendFromQueue() {
|
|
1319
|
+
var _this3 = this;
|
|
1320
|
+
// Send awaiting data to server
|
|
1321
|
+
var lastDelay = 0;
|
|
1322
|
+
var _loop = function _loop(dataIndex) {
|
|
1323
|
+
var _this3$options$awaitQ;
|
|
1324
|
+
var data = _this3.sendQueue[dataIndex];
|
|
1325
|
+
setTimeout(function () {
|
|
1326
|
+
return _this3.send.apply(_this3, WebSocketChatClient_toConsumableArray(data));
|
|
1327
|
+
}, lastDelay);
|
|
1328
|
+
lastDelay += (_this3$options$awaitQ = _this3.options.awaitQueueSendDelayMs) !== null && _this3$options$awaitQ !== void 0 ? _this3$options$awaitQ : 500;
|
|
1329
|
+
};
|
|
1330
|
+
for (var dataIndex in this.sendQueue) {
|
|
1331
|
+
_loop(dataIndex);
|
|
1332
|
+
}
|
|
1333
|
+
this.sendQueue = [];
|
|
1334
|
+
clearTimeout(this.connectingTimeoutId);
|
|
1335
|
+
}
|
|
1336
|
+
}, {
|
|
1337
|
+
key: "triggerConnectionTimeout",
|
|
1338
|
+
value: function triggerConnectionTimeout() {
|
|
1339
|
+
this.disconnect();
|
|
1340
|
+
this.emit(this.Event.error, new Error('Connection timeout'));
|
|
1341
|
+
}
|
|
1342
|
+
}]);
|
|
1343
|
+
return WebSocketChatClient;
|
|
1344
|
+
}(AbstractChatClient);
|
|
1345
|
+
;// CONCATENATED MODULE: ./src/WebApiChatClient.ts
|
|
1346
|
+
function WebApiChatClient_typeof(obj) { "@babel/helpers - typeof"; return WebApiChatClient_typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, WebApiChatClient_typeof(obj); }
|
|
1347
|
+
function WebApiChatClient_regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ WebApiChatClient_regeneratorRuntime = function _regeneratorRuntime() { return exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, defineProperty = Object.defineProperty || function (obj, key, desc) { obj[key] = desc.value; }, $Symbol = "function" == typeof Symbol ? Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []); return defineProperty(generator, "_invoke", { value: makeInvokeMethod(innerFn, self, context) }), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = Object.getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); function defineIteratorMethods(prototype) { ["next", "throw", "return"].forEach(function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == WebApiChatClient_typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; defineProperty(this, "_invoke", { value: function value(method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; } function maybeInvokeDelegate(delegate, context) { var methodName = context.method, method = delegate.iterator[methodName]; if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator["return"] && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel; var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) { if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; } return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), defineProperty(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (val) { var object = Object(val), keys = []; for (var key in object) { keys.push(key); } return keys.reverse(), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) { "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); } }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, "catch": function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; }
|
|
1348
|
+
function WebApiChatClient_asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
1349
|
+
function WebApiChatClient_asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { WebApiChatClient_asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { WebApiChatClient_asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
1350
|
+
function WebApiChatClient_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
1351
|
+
function WebApiChatClient_defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, WebApiChatClient_toPropertyKey(descriptor.key), descriptor); } }
|
|
1352
|
+
function WebApiChatClient_createClass(Constructor, protoProps, staticProps) { if (protoProps) WebApiChatClient_defineProperties(Constructor.prototype, protoProps); if (staticProps) WebApiChatClient_defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
1353
|
+
function WebApiChatClient_inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) WebApiChatClient_setPrototypeOf(subClass, superClass); }
|
|
1354
|
+
function WebApiChatClient_setPrototypeOf(o, p) { WebApiChatClient_setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return WebApiChatClient_setPrototypeOf(o, p); }
|
|
1355
|
+
function WebApiChatClient_createSuper(Derived) { var hasNativeReflectConstruct = WebApiChatClient_isNativeReflectConstruct(); return function _createSuperInternal() { var Super = WebApiChatClient_getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = WebApiChatClient_getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return WebApiChatClient_possibleConstructorReturn(this, result); }; }
|
|
1356
|
+
function WebApiChatClient_possibleConstructorReturn(self, call) { if (call && (WebApiChatClient_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return WebApiChatClient_assertThisInitialized(self); }
|
|
1357
|
+
function WebApiChatClient_assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
1358
|
+
function WebApiChatClient_isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
1359
|
+
function WebApiChatClient_getPrototypeOf(o) { WebApiChatClient_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return WebApiChatClient_getPrototypeOf(o); }
|
|
1360
|
+
function WebApiChatClient_defineProperty(obj, key, value) { key = WebApiChatClient_toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
1361
|
+
function WebApiChatClient_toPropertyKey(arg) { var key = WebApiChatClient_toPrimitive(arg, "string"); return WebApiChatClient_typeof(key) === "symbol" ? key : String(key); }
|
|
1362
|
+
function WebApiChatClient_toPrimitive(input, hint) { if (WebApiChatClient_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (WebApiChatClient_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
1363
|
+
|
|
1364
|
+
var WebApiChatClientEvent;
|
|
1365
|
+
(function (WebApiChatClientEvent) {
|
|
1366
|
+
WebApiChatClientEvent["message"] = "message";
|
|
1367
|
+
WebApiChatClientEvent["error"] = "error";
|
|
1368
|
+
WebApiChatClientEvent["destroy"] = "destroy";
|
|
1369
|
+
})(WebApiChatClientEvent || (WebApiChatClientEvent = {}));
|
|
1370
|
+
var WebApiChatClient = /*#__PURE__*/function (_AbstractChatClient) {
|
|
1371
|
+
WebApiChatClient_inherits(WebApiChatClient, _AbstractChatClient);
|
|
1372
|
+
var _super = WebApiChatClient_createSuper(WebApiChatClient);
|
|
1373
|
+
function WebApiChatClient(options) {
|
|
1374
|
+
var _this;
|
|
1375
|
+
WebApiChatClient_classCallCheck(this, WebApiChatClient);
|
|
1376
|
+
_this = _super.call(this);
|
|
1377
|
+
_this.options = options;
|
|
1378
|
+
WebApiChatClient_defineProperty(WebApiChatClient_assertThisInitialized(_this), "Event", WebApiChatClientEvent);
|
|
1379
|
+
WebApiChatClient_defineProperty(WebApiChatClient_assertThisInitialized(_this), "sendStack", void 0);
|
|
1380
|
+
if (!_this.options.token && !_this.options.temporaryNick) {
|
|
1381
|
+
throw new Error('Token or temporary nick is required');
|
|
1382
|
+
}
|
|
1383
|
+
return _this;
|
|
1384
|
+
}
|
|
1385
|
+
WebApiChatClient_createClass(WebApiChatClient, [{
|
|
1386
|
+
key: "send",
|
|
1387
|
+
value: function () {
|
|
1388
|
+
var _send = WebApiChatClient_asyncToGenerator( /*#__PURE__*/WebApiChatClient_regeneratorRuntime().mark(function _callee(commandType, commandData) {
|
|
1389
|
+
var envelope;
|
|
1390
|
+
return WebApiChatClient_regeneratorRuntime().wrap(function _callee$(_context) {
|
|
1391
|
+
while (1) {
|
|
1392
|
+
switch (_context.prev = _context.next) {
|
|
1393
|
+
case 0:
|
|
1394
|
+
envelope = this.createEnvelope(commandType, commandData);
|
|
1395
|
+
this.sendStack.push({
|
|
1396
|
+
data: envelope,
|
|
1397
|
+
attempts: 0,
|
|
1398
|
+
lastTimeoutId: null
|
|
1399
|
+
});
|
|
1400
|
+
this.makeApiCall(this.sendStack.length - 1);
|
|
1401
|
+
return _context.abrupt("return", this.createPromiseFromCommandEnvelope(envelope));
|
|
1402
|
+
case 4:
|
|
1403
|
+
case "end":
|
|
1404
|
+
return _context.stop();
|
|
1405
|
+
}
|
|
1406
|
+
}
|
|
1407
|
+
}, _callee, this);
|
|
1408
|
+
}));
|
|
1409
|
+
function send(_x, _x2) {
|
|
1410
|
+
return _send.apply(this, arguments);
|
|
1411
|
+
}
|
|
1412
|
+
return send;
|
|
1413
|
+
}()
|
|
1414
|
+
}, {
|
|
1415
|
+
key: "destroy",
|
|
1416
|
+
value: function destroy() {
|
|
1417
|
+
var _this2 = this;
|
|
1418
|
+
// Cancel all awaiting requests
|
|
1419
|
+
this.sendStack.forEach(function (item) {
|
|
1420
|
+
if (item.lastTimeoutId) {
|
|
1421
|
+
clearTimeout(item.lastTimeoutId);
|
|
1422
|
+
}
|
|
1423
|
+
_this2.awaitingResponse["delete"](item.data.ref);
|
|
1424
|
+
});
|
|
1425
|
+
this.sendStack = [];
|
|
1426
|
+
this.emit(this.Event.destroy, false);
|
|
1427
|
+
}
|
|
1428
|
+
}, {
|
|
1429
|
+
key: "onMessage",
|
|
1430
|
+
value: function () {
|
|
1431
|
+
var _onMessage = WebApiChatClient_asyncToGenerator( /*#__PURE__*/WebApiChatClient_regeneratorRuntime().mark(function _callee2(reqId, response) {
|
|
1432
|
+
var envelope;
|
|
1433
|
+
return WebApiChatClient_regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
1434
|
+
while (1) {
|
|
1435
|
+
switch (_context2.prev = _context2.next) {
|
|
1436
|
+
case 0:
|
|
1437
|
+
this.sendStack.splice(reqId, 1);
|
|
1438
|
+
_context2.next = 3;
|
|
1439
|
+
return response.json();
|
|
1440
|
+
case 3:
|
|
1441
|
+
envelope = _context2.sent;
|
|
1442
|
+
this.handleIncomingEnvelope(envelope);
|
|
1443
|
+
this.emit(envelope.type, envelope.data);
|
|
1444
|
+
this.emit(this.Event.message, envelope);
|
|
1445
|
+
case 7:
|
|
1446
|
+
case "end":
|
|
1447
|
+
return _context2.stop();
|
|
1448
|
+
}
|
|
1449
|
+
}
|
|
1450
|
+
}, _callee2, this);
|
|
1451
|
+
}));
|
|
1452
|
+
function onMessage(_x3, _x4) {
|
|
1453
|
+
return _onMessage.apply(this, arguments);
|
|
1454
|
+
}
|
|
1455
|
+
return onMessage;
|
|
1456
|
+
}()
|
|
1457
|
+
}, {
|
|
1458
|
+
key: "onError",
|
|
1459
|
+
value: function onError(reqId, body) {
|
|
1460
|
+
var _this$options$attempt,
|
|
1461
|
+
_this3 = this,
|
|
1462
|
+
_this$options$attempt2;
|
|
1463
|
+
if (this.sendStack[reqId].attempts >= ((_this$options$attempt = this.options.attemptsToSend) !== null && _this$options$attempt !== void 0 ? _this$options$attempt : 10)) {
|
|
1464
|
+
this.sendStack.splice(reqId, 1);
|
|
1465
|
+
this.handleEnvelopeSendError(this.sendStack[reqId].data, new Error("Cannot send ".concat(body, "; aborting after reaching the maximum connection errors")));
|
|
1466
|
+
return;
|
|
1467
|
+
}
|
|
1468
|
+
this.sendStack[reqId].lastTimeoutId = setTimeout(function () {
|
|
1469
|
+
return _this3.makeApiCall(reqId);
|
|
1470
|
+
}, (_this$options$attempt2 = this.options.attemptDelayMs) !== null && _this$options$attempt2 !== void 0 ? _this$options$attempt2 : 3000);
|
|
1471
|
+
}
|
|
1472
|
+
}, {
|
|
1473
|
+
key: "makeApiCall",
|
|
1474
|
+
value: function makeApiCall(reqId) {
|
|
1475
|
+
var _this4 = this;
|
|
1476
|
+
this.sendStack[reqId].attempts++;
|
|
1477
|
+
var bodyJson = JSON.stringify(this.sendStack[reqId].data);
|
|
1478
|
+
var headers = {
|
|
1479
|
+
'Content-Type': 'application/json',
|
|
1480
|
+
Accept: 'application/json'
|
|
1481
|
+
};
|
|
1482
|
+
if (this.options.token) {
|
|
1483
|
+
headers.Authorization = "Bearer ".concat(this.options.token);
|
|
1484
|
+
} else if (this.options.temporaryNick) {
|
|
1485
|
+
headers.Authorization = "Temp ".concat(this.options.temporaryNick);
|
|
1486
|
+
}
|
|
1487
|
+
fetch(this.options.url, {
|
|
1488
|
+
headers: headers,
|
|
1489
|
+
body: bodyJson,
|
|
1490
|
+
method: 'POST'
|
|
1491
|
+
}).then(function (response) {
|
|
1492
|
+
return _this4.onMessage(reqId, response);
|
|
1493
|
+
})["catch"](function () {
|
|
1494
|
+
return _this4.onError(reqId, bodyJson);
|
|
1495
|
+
});
|
|
1496
|
+
}
|
|
1497
|
+
}]);
|
|
1498
|
+
return WebApiChatClient;
|
|
1499
|
+
}(AbstractChatClient);
|
|
1500
|
+
;// CONCATENATED MODULE: ./src/AbstractRestClient.ts
|
|
1501
|
+
function AbstractRestClient_typeof(obj) { "@babel/helpers - typeof"; return AbstractRestClient_typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, AbstractRestClient_typeof(obj); }
|
|
1502
|
+
function AbstractRestClient_regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ AbstractRestClient_regeneratorRuntime = function _regeneratorRuntime() { return exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, defineProperty = Object.defineProperty || function (obj, key, desc) { obj[key] = desc.value; }, $Symbol = "function" == typeof Symbol ? Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []); return defineProperty(generator, "_invoke", { value: makeInvokeMethod(innerFn, self, context) }), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = Object.getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); function defineIteratorMethods(prototype) { ["next", "throw", "return"].forEach(function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == AbstractRestClient_typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; defineProperty(this, "_invoke", { value: function value(method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; } function maybeInvokeDelegate(delegate, context) { var methodName = context.method, method = delegate.iterator[methodName]; if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator["return"] && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel; var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) { if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; } return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), defineProperty(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (val) { var object = Object(val), keys = []; for (var key in object) { keys.push(key); } return keys.reverse(), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) { "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); } }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, "catch": function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; }
|
|
1503
|
+
function AbstractRestClient_asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
1504
|
+
function AbstractRestClient_asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { AbstractRestClient_asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { AbstractRestClient_asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
1505
|
+
function AbstractRestClient_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
1506
|
+
function AbstractRestClient_defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, AbstractRestClient_toPropertyKey(descriptor.key), descriptor); } }
|
|
1507
|
+
function AbstractRestClient_createClass(Constructor, protoProps, staticProps) { if (protoProps) AbstractRestClient_defineProperties(Constructor.prototype, protoProps); if (staticProps) AbstractRestClient_defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
1508
|
+
function AbstractRestClient_defineProperty(obj, key, value) { key = AbstractRestClient_toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
1509
|
+
function AbstractRestClient_toPropertyKey(arg) { var key = AbstractRestClient_toPrimitive(arg, "string"); return AbstractRestClient_typeof(key) === "symbol" ? key : String(key); }
|
|
1510
|
+
function AbstractRestClient_toPrimitive(input, hint) { if (AbstractRestClient_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (AbstractRestClient_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
1511
|
+
var AbstractRestClient = /*#__PURE__*/function () {
|
|
1512
|
+
function AbstractRestClient(options) {
|
|
1513
|
+
AbstractRestClient_classCallCheck(this, AbstractRestClient);
|
|
1514
|
+
this.options = options;
|
|
1515
|
+
AbstractRestClient_defineProperty(this, "defaultUrl", void 0);
|
|
1516
|
+
}
|
|
1517
|
+
AbstractRestClient_createClass(AbstractRestClient, [{
|
|
1518
|
+
key: "send",
|
|
1519
|
+
value: function () {
|
|
1520
|
+
var _send = AbstractRestClient_asyncToGenerator( /*#__PURE__*/AbstractRestClient_regeneratorRuntime().mark(function _callee(method, uri) {
|
|
1521
|
+
var data,
|
|
1522
|
+
headers,
|
|
1523
|
+
url,
|
|
1524
|
+
body,
|
|
1525
|
+
result,
|
|
1526
|
+
_args = arguments;
|
|
1527
|
+
return AbstractRestClient_regeneratorRuntime().wrap(function _callee$(_context) {
|
|
1528
|
+
while (1) {
|
|
1529
|
+
switch (_context.prev = _context.next) {
|
|
1530
|
+
case 0:
|
|
1531
|
+
data = _args.length > 2 && _args[2] !== undefined ? _args[2] : undefined;
|
|
1532
|
+
headers = {
|
|
1533
|
+
'Content-Type': 'application/json',
|
|
1534
|
+
Accept: 'application/json'
|
|
1535
|
+
};
|
|
1536
|
+
if (this.options.token) {
|
|
1537
|
+
headers.Authorization = "Bearer ".concat(this.options.token);
|
|
1538
|
+
}
|
|
1539
|
+
url = this.getUrl(uri);
|
|
1540
|
+
body = undefined;
|
|
1541
|
+
if (data) {
|
|
1542
|
+
if (['GET', 'DELETE'].includes(method)) {
|
|
1543
|
+
url += new URLSearchParams(data).toString();
|
|
1544
|
+
} else {
|
|
1545
|
+
body = JSON.stringify(data);
|
|
1546
|
+
}
|
|
1547
|
+
}
|
|
1548
|
+
_context.next = 8;
|
|
1549
|
+
return fetch(url, {
|
|
1550
|
+
method: method,
|
|
1551
|
+
body: body,
|
|
1552
|
+
headers: headers
|
|
1553
|
+
});
|
|
1554
|
+
case 8:
|
|
1555
|
+
result = _context.sent;
|
|
1556
|
+
_context.t0 = result.ok;
|
|
1557
|
+
_context.t1 = result.status;
|
|
1558
|
+
_context.next = 13;
|
|
1559
|
+
return result.json();
|
|
1560
|
+
case 13:
|
|
1561
|
+
_context.t2 = _context.sent;
|
|
1562
|
+
return _context.abrupt("return", {
|
|
1563
|
+
ok: _context.t0,
|
|
1564
|
+
status: _context.t1,
|
|
1565
|
+
data: _context.t2
|
|
1566
|
+
});
|
|
1567
|
+
case 15:
|
|
1568
|
+
case "end":
|
|
1569
|
+
return _context.stop();
|
|
1570
|
+
}
|
|
1571
|
+
}
|
|
1572
|
+
}, _callee, this);
|
|
1573
|
+
}));
|
|
1574
|
+
function send(_x, _x2) {
|
|
1575
|
+
return _send.apply(this, arguments);
|
|
1576
|
+
}
|
|
1577
|
+
return send;
|
|
1578
|
+
}()
|
|
1579
|
+
}, {
|
|
1580
|
+
key: "getUrl",
|
|
1581
|
+
value: function getUrl(uri) {
|
|
1582
|
+
var _this$options$url;
|
|
1583
|
+
return this.removeEndingSlash((_this$options$url = this.options.url) !== null && _this$options$url !== void 0 ? _this$options$url : this.defaultUrl) + '/' + this.removeStartingSlash(uri);
|
|
1584
|
+
}
|
|
1585
|
+
}, {
|
|
1586
|
+
key: "removeStartingSlash",
|
|
1587
|
+
value: function removeStartingSlash(text) {
|
|
1588
|
+
return text.replace(/^\/+/, '');
|
|
1589
|
+
}
|
|
1590
|
+
}, {
|
|
1591
|
+
key: "removeEndingSlash",
|
|
1592
|
+
value: function removeEndingSlash(text) {
|
|
1593
|
+
return text.replace(/\/+$/, '');
|
|
1594
|
+
}
|
|
1595
|
+
}]);
|
|
1596
|
+
return AbstractRestClient;
|
|
1597
|
+
}();
|
|
1598
|
+
;// CONCATENATED MODULE: ./src/AuthClient.ts
|
|
1599
|
+
function AuthClient_typeof(obj) { "@babel/helpers - typeof"; return AuthClient_typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, AuthClient_typeof(obj); }
|
|
1600
|
+
function AuthClient_regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ AuthClient_regeneratorRuntime = function _regeneratorRuntime() { return exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, defineProperty = Object.defineProperty || function (obj, key, desc) { obj[key] = desc.value; }, $Symbol = "function" == typeof Symbol ? Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []); return defineProperty(generator, "_invoke", { value: makeInvokeMethod(innerFn, self, context) }), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = Object.getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); function defineIteratorMethods(prototype) { ["next", "throw", "return"].forEach(function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == AuthClient_typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; defineProperty(this, "_invoke", { value: function value(method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; } function maybeInvokeDelegate(delegate, context) { var methodName = context.method, method = delegate.iterator[methodName]; if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator["return"] && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel; var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) { if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; } return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), defineProperty(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (val) { var object = Object(val), keys = []; for (var key in object) { keys.push(key); } return keys.reverse(), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) { "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); } }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, "catch": function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; }
|
|
1601
|
+
function AuthClient_asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
1602
|
+
function AuthClient_asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { AuthClient_asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { AuthClient_asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
1603
|
+
function AuthClient_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
1604
|
+
function AuthClient_defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, AuthClient_toPropertyKey(descriptor.key), descriptor); } }
|
|
1605
|
+
function AuthClient_createClass(Constructor, protoProps, staticProps) { if (protoProps) AuthClient_defineProperties(Constructor.prototype, protoProps); if (staticProps) AuthClient_defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
1606
|
+
function AuthClient_inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) AuthClient_setPrototypeOf(subClass, superClass); }
|
|
1607
|
+
function AuthClient_setPrototypeOf(o, p) { AuthClient_setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return AuthClient_setPrototypeOf(o, p); }
|
|
1608
|
+
function AuthClient_createSuper(Derived) { var hasNativeReflectConstruct = AuthClient_isNativeReflectConstruct(); return function _createSuperInternal() { var Super = AuthClient_getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = AuthClient_getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return AuthClient_possibleConstructorReturn(this, result); }; }
|
|
1609
|
+
function AuthClient_possibleConstructorReturn(self, call) { if (call && (AuthClient_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return AuthClient_assertThisInitialized(self); }
|
|
1610
|
+
function AuthClient_assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
1611
|
+
function AuthClient_isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
1612
|
+
function AuthClient_getPrototypeOf(o) { AuthClient_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return AuthClient_getPrototypeOf(o); }
|
|
1613
|
+
function AuthClient_defineProperty(obj, key, value) { key = AuthClient_toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
1614
|
+
function AuthClient_toPropertyKey(arg) { var key = AuthClient_toPrimitive(arg, "string"); return AuthClient_typeof(key) === "symbol" ? key : String(key); }
|
|
1615
|
+
function AuthClient_toPrimitive(input, hint) { if (AuthClient_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (AuthClient_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
1616
|
+
|
|
1617
|
+
var AuthClient = /*#__PURE__*/function (_AbstractRestClient) {
|
|
1618
|
+
AuthClient_inherits(AuthClient, _AbstractRestClient);
|
|
1619
|
+
var _super = AuthClient_createSuper(AuthClient);
|
|
1620
|
+
function AuthClient() {
|
|
1621
|
+
var _this;
|
|
1622
|
+
AuthClient_classCallCheck(this, AuthClient);
|
|
1623
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
1624
|
+
args[_key] = arguments[_key];
|
|
1625
|
+
}
|
|
1626
|
+
_this = _super.call.apply(_super, [this].concat(args));
|
|
1627
|
+
AuthClient_defineProperty(AuthClient_assertThisInitialized(_this), "defaultUrl", 'https://polfan.pl/webservice/api');
|
|
1628
|
+
return _this;
|
|
1629
|
+
}
|
|
1630
|
+
AuthClient_createClass(AuthClient, [{
|
|
1631
|
+
key: "deleteToken",
|
|
1632
|
+
value: function () {
|
|
1633
|
+
var _deleteToken = AuthClient_asyncToGenerator( /*#__PURE__*/AuthClient_regeneratorRuntime().mark(function _callee(token) {
|
|
1634
|
+
var response;
|
|
1635
|
+
return AuthClient_regeneratorRuntime().wrap(function _callee$(_context) {
|
|
1636
|
+
while (1) {
|
|
1637
|
+
switch (_context.prev = _context.next) {
|
|
1638
|
+
case 0:
|
|
1639
|
+
_context.next = 2;
|
|
1640
|
+
return this.send('DELETE', "auth/tokens/".concat(token));
|
|
1641
|
+
case 2:
|
|
1642
|
+
response = _context.sent;
|
|
1643
|
+
if (response.ok) {
|
|
1644
|
+
_context.next = 5;
|
|
1645
|
+
break;
|
|
1646
|
+
}
|
|
1647
|
+
throw new Error("Cannot delete access token: ".concat(response.data.errors[0]));
|
|
1648
|
+
case 5:
|
|
1649
|
+
case "end":
|
|
1650
|
+
return _context.stop();
|
|
1651
|
+
}
|
|
1652
|
+
}
|
|
1653
|
+
}, _callee, this);
|
|
1654
|
+
}));
|
|
1655
|
+
function deleteToken(_x) {
|
|
1656
|
+
return _deleteToken.apply(this, arguments);
|
|
1657
|
+
}
|
|
1658
|
+
return deleteToken;
|
|
1659
|
+
}()
|
|
1660
|
+
}, {
|
|
1661
|
+
key: "getMe",
|
|
1662
|
+
value: function () {
|
|
1663
|
+
var _getMe = AuthClient_asyncToGenerator( /*#__PURE__*/AuthClient_regeneratorRuntime().mark(function _callee2() {
|
|
1664
|
+
var response;
|
|
1665
|
+
return AuthClient_regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
1666
|
+
while (1) {
|
|
1667
|
+
switch (_context2.prev = _context2.next) {
|
|
1668
|
+
case 0:
|
|
1669
|
+
_context2.next = 2;
|
|
1670
|
+
return this.send('GET', 'auth/me');
|
|
1671
|
+
case 2:
|
|
1672
|
+
response = _context2.sent;
|
|
1673
|
+
if (!response.ok) {
|
|
1674
|
+
_context2.next = 6;
|
|
1675
|
+
break;
|
|
1676
|
+
}
|
|
1677
|
+
response.data.id = response.data.id.toString();
|
|
1678
|
+
return _context2.abrupt("return", response.data);
|
|
1679
|
+
case 6:
|
|
1680
|
+
throw new Error("Cannot get current user account: ".concat(response.data.errors[0]));
|
|
1681
|
+
case 7:
|
|
1682
|
+
case "end":
|
|
1683
|
+
return _context2.stop();
|
|
1684
|
+
}
|
|
1685
|
+
}
|
|
1686
|
+
}, _callee2, this);
|
|
1687
|
+
}));
|
|
1688
|
+
function getMe() {
|
|
1689
|
+
return _getMe.apply(this, arguments);
|
|
1690
|
+
}
|
|
1691
|
+
return getMe;
|
|
1692
|
+
}()
|
|
1693
|
+
}], [{
|
|
1694
|
+
key: "createToken",
|
|
1695
|
+
value: function () {
|
|
1696
|
+
var _createToken = AuthClient_asyncToGenerator( /*#__PURE__*/AuthClient_regeneratorRuntime().mark(function _callee3(login, password) {
|
|
1697
|
+
var clientName,
|
|
1698
|
+
response,
|
|
1699
|
+
_args3 = arguments;
|
|
1700
|
+
return AuthClient_regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
1701
|
+
while (1) {
|
|
1702
|
+
switch (_context3.prev = _context3.next) {
|
|
1703
|
+
case 0:
|
|
1704
|
+
clientName = _args3.length > 2 && _args3[2] !== undefined ? _args3[2] : 'pserv-js-client';
|
|
1705
|
+
_context3.next = 3;
|
|
1706
|
+
return new AuthClient({
|
|
1707
|
+
token: null
|
|
1708
|
+
}).send('POST', 'auth/tokens', {
|
|
1709
|
+
login: login,
|
|
1710
|
+
password: password,
|
|
1711
|
+
client_name: clientName
|
|
1712
|
+
});
|
|
1713
|
+
case 3:
|
|
1714
|
+
response = _context3.sent;
|
|
1715
|
+
if (!response.ok) {
|
|
1716
|
+
_context3.next = 6;
|
|
1717
|
+
break;
|
|
1718
|
+
}
|
|
1719
|
+
return _context3.abrupt("return", response.data);
|
|
1720
|
+
case 6:
|
|
1721
|
+
throw new Error("Cannot create user token: ".concat(response.data.errors[0]));
|
|
1722
|
+
case 7:
|
|
1723
|
+
case "end":
|
|
1724
|
+
return _context3.stop();
|
|
1725
|
+
}
|
|
1726
|
+
}
|
|
1727
|
+
}, _callee3);
|
|
1728
|
+
}));
|
|
1729
|
+
function createToken(_x2, _x3) {
|
|
1730
|
+
return _createToken.apply(this, arguments);
|
|
1731
|
+
}
|
|
1732
|
+
return createToken;
|
|
1733
|
+
}()
|
|
1734
|
+
}]);
|
|
1735
|
+
return AuthClient;
|
|
1736
|
+
}(AbstractRestClient);
|
|
1737
|
+
;// CONCATENATED MODULE: ./src/index.ts
|
|
1738
|
+
|
|
1739
|
+
|
|
1740
|
+
|
|
1741
|
+
|
|
1742
|
+
|
|
1743
|
+
/******/ return __webpack_exports__;
|
|
1744
|
+
/******/ })()
|
|
1745
|
+
;
|
|
1746
|
+
});
|
|
2
1747
|
//# sourceMappingURL=index.js.map
|