polfan-server-js-client 0.1.997 → 0.1.999
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 +91 -73
- package/build/index.js.map +1 -1
- package/build/types/WebSocketChatClient.d.ts +3 -1
- package/build/types/state-tracker/TopicHistoryWindow.d.ts +3 -1
- package/package.json +1 -1
- package/src/WebSocketChatClient.ts +13 -7
- package/src/state-tracker/TopicHistoryWindow.ts +26 -14
- package/tests/history-window.test.ts +28 -1
package/build/index.js
CHANGED
|
@@ -668,6 +668,7 @@ var TraversableRemoteCollection = /*#__PURE__*/function (_ObservableIndexedObj)
|
|
|
668
668
|
TopicHistoryWindow_defineProperty(TopicHistoryWindow_assertThisInitialized(_this), "limit", 50);
|
|
669
669
|
TopicHistoryWindow_defineProperty(TopicHistoryWindow_assertThisInitialized(_this), "currentState", WindowState.LIVE);
|
|
670
670
|
TopicHistoryWindow_defineProperty(TopicHistoryWindow_assertThisInitialized(_this), "fetchingState", undefined);
|
|
671
|
+
TopicHistoryWindow_defineProperty(TopicHistoryWindow_assertThisInitialized(_this), "oldestId", null);
|
|
671
672
|
return _this;
|
|
672
673
|
}
|
|
673
674
|
TopicHistoryWindow_createClass(TraversableRemoteCollection, [{
|
|
@@ -684,6 +685,16 @@ var TraversableRemoteCollection = /*#__PURE__*/function (_ObservableIndexedObj)
|
|
|
684
685
|
* Maximum numer of items stored in window.
|
|
685
686
|
* Null for unlimited.
|
|
686
687
|
*/
|
|
688
|
+
}, {
|
|
689
|
+
key: "hasLatest",
|
|
690
|
+
get: function get() {
|
|
691
|
+
return [WindowState.LATEST, WindowState.LIVE].includes(this.state);
|
|
692
|
+
}
|
|
693
|
+
}, {
|
|
694
|
+
key: "hasOldest",
|
|
695
|
+
get: function get() {
|
|
696
|
+
return this.state === WindowState.OLDEST || this.oldestId !== null && this.has(this.oldestId);
|
|
697
|
+
}
|
|
687
698
|
}, {
|
|
688
699
|
key: "resetToLatest",
|
|
689
700
|
value: function () {
|
|
@@ -693,33 +704,32 @@ var TraversableRemoteCollection = /*#__PURE__*/function (_ObservableIndexedObj)
|
|
|
693
704
|
while (1) {
|
|
694
705
|
switch (_context.prev = _context.next) {
|
|
695
706
|
case 0:
|
|
696
|
-
this.
|
|
697
|
-
|
|
698
|
-
_context.next = 3;
|
|
707
|
+
if (!(this.fetchingState || this.currentState === WindowState.LATEST)) {
|
|
708
|
+
_context.next = 2;
|
|
699
709
|
break;
|
|
700
710
|
}
|
|
701
711
|
return _context.abrupt("return");
|
|
702
|
-
case
|
|
712
|
+
case 2:
|
|
703
713
|
this.fetchingState = WindowState.LATEST;
|
|
704
|
-
_context.prev =
|
|
705
|
-
_context.next =
|
|
714
|
+
_context.prev = 3;
|
|
715
|
+
_context.next = 6;
|
|
706
716
|
return this.fetchLatestItems();
|
|
707
|
-
case
|
|
717
|
+
case 6:
|
|
708
718
|
result = _context.sent;
|
|
709
|
-
case
|
|
710
|
-
_context.prev =
|
|
719
|
+
case 7:
|
|
720
|
+
_context.prev = 7;
|
|
711
721
|
this.fetchingState = undefined;
|
|
712
|
-
return _context.finish(
|
|
713
|
-
case
|
|
722
|
+
return _context.finish(7);
|
|
723
|
+
case 10:
|
|
714
724
|
this.deleteAll();
|
|
715
725
|
this.addItems(result, 'tail');
|
|
716
726
|
this.currentState = WindowState.LATEST;
|
|
717
|
-
case
|
|
727
|
+
case 13:
|
|
718
728
|
case "end":
|
|
719
729
|
return _context.stop();
|
|
720
730
|
}
|
|
721
731
|
}
|
|
722
|
-
}, _callee, this, [[
|
|
732
|
+
}, _callee, this, [[3,, 7, 10]]);
|
|
723
733
|
}));
|
|
724
734
|
function resetToLatest() {
|
|
725
735
|
return _resetToLatest.apply(this, arguments);
|
|
@@ -730,51 +740,59 @@ var TraversableRemoteCollection = /*#__PURE__*/function (_ObservableIndexedObj)
|
|
|
730
740
|
key: "fetchPrevious",
|
|
731
741
|
value: function () {
|
|
732
742
|
var _fetchPrevious = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
|
|
733
|
-
var result;
|
|
743
|
+
var result, firstItem;
|
|
734
744
|
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
735
745
|
while (1) {
|
|
736
746
|
switch (_context2.prev = _context2.next) {
|
|
737
747
|
case 0:
|
|
738
|
-
if (!(this.
|
|
748
|
+
if (!(this.fetchingState || this.hasOldest)) {
|
|
739
749
|
_context2.next = 2;
|
|
740
750
|
break;
|
|
741
751
|
}
|
|
742
752
|
return _context2.abrupt("return");
|
|
743
753
|
case 2:
|
|
744
|
-
this.throwIfFetchingInProgress();
|
|
745
754
|
this.fetchingState = WindowState.PAST;
|
|
746
|
-
_context2.prev =
|
|
747
|
-
_context2.next =
|
|
755
|
+
_context2.prev = 3;
|
|
756
|
+
_context2.next = 6;
|
|
748
757
|
return this.fetchItemsBefore();
|
|
749
|
-
case
|
|
758
|
+
case 6:
|
|
750
759
|
result = _context2.sent;
|
|
751
|
-
case
|
|
752
|
-
_context2.prev =
|
|
760
|
+
case 7:
|
|
761
|
+
_context2.prev = 7;
|
|
753
762
|
this.fetchingState = undefined;
|
|
754
|
-
return _context2.finish(
|
|
755
|
-
case
|
|
763
|
+
return _context2.finish(7);
|
|
764
|
+
case 10:
|
|
756
765
|
if (result) {
|
|
757
|
-
_context2.next =
|
|
766
|
+
_context2.next = 12;
|
|
758
767
|
break;
|
|
759
768
|
}
|
|
760
769
|
return _context2.abrupt("return", this.resetToLatest());
|
|
761
|
-
case
|
|
770
|
+
case 12:
|
|
762
771
|
if (result.length) {
|
|
763
|
-
_context2.next =
|
|
772
|
+
_context2.next = 20;
|
|
764
773
|
break;
|
|
765
774
|
}
|
|
766
|
-
|
|
775
|
+
firstItem = this.getAt(0);
|
|
776
|
+
console.log(firstItem);
|
|
777
|
+
this.oldestId = firstItem ? this.getId(firstItem) : null;
|
|
778
|
+
_context2.next = 18;
|
|
779
|
+
return this.refreshFetchedState();
|
|
780
|
+
case 18:
|
|
781
|
+
// LATEST state has priority over OLDEST
|
|
782
|
+
if (this.currentState === WindowState.PAST) {
|
|
783
|
+
this.currentState = WindowState.OLDEST;
|
|
784
|
+
}
|
|
767
785
|
return _context2.abrupt("return");
|
|
768
|
-
case
|
|
786
|
+
case 20:
|
|
769
787
|
this.addItems(result, 'head');
|
|
770
|
-
_context2.next =
|
|
788
|
+
_context2.next = 23;
|
|
771
789
|
return this.refreshFetchedState();
|
|
772
|
-
case
|
|
790
|
+
case 23:
|
|
773
791
|
case "end":
|
|
774
792
|
return _context2.stop();
|
|
775
793
|
}
|
|
776
794
|
}
|
|
777
|
-
}, _callee2, this, [[
|
|
795
|
+
}, _callee2, this, [[3,, 7, 10]]);
|
|
778
796
|
}));
|
|
779
797
|
function fetchPrevious() {
|
|
780
798
|
return _fetchPrevious.apply(this, arguments);
|
|
@@ -790,40 +808,47 @@ var TraversableRemoteCollection = /*#__PURE__*/function (_ObservableIndexedObj)
|
|
|
790
808
|
while (1) {
|
|
791
809
|
switch (_context3.prev = _context3.next) {
|
|
792
810
|
case 0:
|
|
793
|
-
this.
|
|
811
|
+
if (!(this.fetchingState || this.hasLatest)) {
|
|
812
|
+
_context3.next = 2;
|
|
813
|
+
break;
|
|
814
|
+
}
|
|
815
|
+
return _context3.abrupt("return");
|
|
816
|
+
case 2:
|
|
794
817
|
this.fetchingState = WindowState.PAST;
|
|
795
|
-
_context3.prev =
|
|
796
|
-
_context3.next =
|
|
818
|
+
_context3.prev = 3;
|
|
819
|
+
_context3.next = 6;
|
|
797
820
|
return this.fetchItemsAfter();
|
|
798
|
-
case 5:
|
|
799
|
-
result = _context3.sent;
|
|
800
821
|
case 6:
|
|
801
|
-
|
|
822
|
+
result = _context3.sent;
|
|
823
|
+
case 7:
|
|
824
|
+
_context3.prev = 7;
|
|
802
825
|
this.fetchingState = undefined;
|
|
803
|
-
return _context3.finish(
|
|
804
|
-
case
|
|
826
|
+
return _context3.finish(7);
|
|
827
|
+
case 10:
|
|
805
828
|
if (result) {
|
|
806
|
-
_context3.next =
|
|
829
|
+
_context3.next = 14;
|
|
807
830
|
break;
|
|
808
831
|
}
|
|
809
|
-
_context3.next =
|
|
832
|
+
_context3.next = 13;
|
|
810
833
|
return this.resetToLatest();
|
|
811
|
-
case 12:
|
|
812
|
-
return _context3.abrupt("return");
|
|
813
834
|
case 13:
|
|
835
|
+
return _context3.abrupt("return");
|
|
836
|
+
case 14:
|
|
814
837
|
if (!result.length) {
|
|
815
|
-
_context3.next =
|
|
838
|
+
_context3.next = 19;
|
|
816
839
|
break;
|
|
817
840
|
}
|
|
818
841
|
this.addItems(result, 'tail');
|
|
819
|
-
_context3.next =
|
|
842
|
+
_context3.next = 18;
|
|
820
843
|
return this.refreshFetchedState();
|
|
821
|
-
case
|
|
844
|
+
case 18:
|
|
845
|
+
return _context3.abrupt("return");
|
|
846
|
+
case 19:
|
|
822
847
|
case "end":
|
|
823
848
|
return _context3.stop();
|
|
824
849
|
}
|
|
825
850
|
}
|
|
826
|
-
}, _callee3, this, [[
|
|
851
|
+
}, _callee3, this, [[3,, 7, 10]]);
|
|
827
852
|
}));
|
|
828
853
|
function fetchNext() {
|
|
829
854
|
return _fetchNext.apply(this, arguments);
|
|
@@ -877,13 +902,6 @@ var TraversableRemoteCollection = /*#__PURE__*/function (_ObservableIndexedObj)
|
|
|
877
902
|
this.deleteAll();
|
|
878
903
|
this.set.apply(this, TopicHistoryWindow_toConsumableArray(result));
|
|
879
904
|
}
|
|
880
|
-
}, {
|
|
881
|
-
key: "throwIfFetchingInProgress",
|
|
882
|
-
value: function throwIfFetchingInProgress() {
|
|
883
|
-
if (this.fetchingState) {
|
|
884
|
-
throw new Error("Items fetching in progress: ".concat(WindowState[this.fetchingState]));
|
|
885
|
-
}
|
|
886
|
-
}
|
|
887
905
|
|
|
888
906
|
/**
|
|
889
907
|
* Return array with messages of count that matching limit.
|
|
@@ -3622,12 +3640,6 @@ var ChatStateTracker = /*#__PURE__*/function () {
|
|
|
3622
3640
|
}();
|
|
3623
3641
|
;// CONCATENATED MODULE: ./src/WebSocketChatClient.ts
|
|
3624
3642
|
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); }
|
|
3625
|
-
function WebSocketChatClient_toConsumableArray(arr) { return WebSocketChatClient_arrayWithoutHoles(arr) || WebSocketChatClient_iterableToArray(arr) || WebSocketChatClient_unsupportedIterableToArray(arr) || WebSocketChatClient_nonIterableSpread(); }
|
|
3626
|
-
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."); }
|
|
3627
|
-
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); }
|
|
3628
|
-
function WebSocketChatClient_iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
3629
|
-
function WebSocketChatClient_arrayWithoutHoles(arr) { if (Array.isArray(arr)) return WebSocketChatClient_arrayLikeToArray(arr); }
|
|
3630
|
-
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; }
|
|
3631
3643
|
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; }
|
|
3632
3644
|
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); } }
|
|
3633
3645
|
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); }); }; }
|
|
@@ -3730,7 +3742,7 @@ var WebSocketChatClient = /*#__PURE__*/function (_AbstractChatClient) {
|
|
|
3730
3742
|
key: "send",
|
|
3731
3743
|
value: function () {
|
|
3732
3744
|
var _send = WebSocketChatClient_asyncToGenerator( /*#__PURE__*/WebSocketChatClient_regeneratorRuntime().mark(function _callee2(commandType, commandData) {
|
|
3733
|
-
var envelope;
|
|
3745
|
+
var envelope, promise;
|
|
3734
3746
|
return WebSocketChatClient_regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
3735
3747
|
while (1) {
|
|
3736
3748
|
switch (_context2.prev = _context2.next) {
|
|
@@ -3741,23 +3753,24 @@ var WebSocketChatClient = /*#__PURE__*/function (_AbstractChatClient) {
|
|
|
3741
3753
|
}
|
|
3742
3754
|
throw new Error('Cannot send; close or closing connection state');
|
|
3743
3755
|
case 2:
|
|
3756
|
+
envelope = this.createEnvelope(commandType, commandData);
|
|
3757
|
+
promise = this.createPromiseFromCommandEnvelope(envelope);
|
|
3744
3758
|
if (!(this.ws.readyState === this.ws.CONNECTING || !this.authenticated)) {
|
|
3745
|
-
_context2.next =
|
|
3759
|
+
_context2.next = 7;
|
|
3746
3760
|
break;
|
|
3747
3761
|
}
|
|
3748
|
-
this.sendQueue.push(
|
|
3749
|
-
return _context2.abrupt("return");
|
|
3750
|
-
case
|
|
3762
|
+
this.sendQueue.push(envelope);
|
|
3763
|
+
return _context2.abrupt("return", promise);
|
|
3764
|
+
case 7:
|
|
3751
3765
|
if (!(this.ws.readyState !== this.ws.OPEN)) {
|
|
3752
|
-
_context2.next =
|
|
3766
|
+
_context2.next = 9;
|
|
3753
3767
|
break;
|
|
3754
3768
|
}
|
|
3755
3769
|
throw new Error("Invalid websocket state=".concat(this.ws.readyState));
|
|
3756
|
-
case
|
|
3757
|
-
|
|
3758
|
-
|
|
3759
|
-
|
|
3760
|
-
case 10:
|
|
3770
|
+
case 9:
|
|
3771
|
+
this.sendEnvelope(envelope);
|
|
3772
|
+
return _context2.abrupt("return", promise);
|
|
3773
|
+
case 11:
|
|
3761
3774
|
case "end":
|
|
3762
3775
|
return _context2.stop();
|
|
3763
3776
|
}
|
|
@@ -3769,6 +3782,11 @@ var WebSocketChatClient = /*#__PURE__*/function (_AbstractChatClient) {
|
|
|
3769
3782
|
}
|
|
3770
3783
|
return send;
|
|
3771
3784
|
}()
|
|
3785
|
+
}, {
|
|
3786
|
+
key: "sendEnvelope",
|
|
3787
|
+
value: function sendEnvelope(envelope) {
|
|
3788
|
+
this.ws.send(JSON.stringify(envelope));
|
|
3789
|
+
}
|
|
3772
3790
|
}, {
|
|
3773
3791
|
key: "onMessage",
|
|
3774
3792
|
value: function onMessage(event) {
|
|
@@ -3808,9 +3826,9 @@ var WebSocketChatClient = /*#__PURE__*/function (_AbstractChatClient) {
|
|
|
3808
3826
|
var lastDelay = 0;
|
|
3809
3827
|
var _loop = function _loop(dataIndex) {
|
|
3810
3828
|
var _this3$options$awaitQ;
|
|
3811
|
-
var
|
|
3829
|
+
var envelope = _this3.sendQueue[dataIndex];
|
|
3812
3830
|
setTimeout(function () {
|
|
3813
|
-
return _this3.
|
|
3831
|
+
return _this3.sendEnvelope(envelope);
|
|
3814
3832
|
}, lastDelay);
|
|
3815
3833
|
lastDelay += (_this3$options$awaitQ = _this3.options.awaitQueueSendDelayMs) !== null && _this3$options$awaitQ !== void 0 ? _this3$options$awaitQ : 500;
|
|
3816
3834
|
};
|