@aws-amplify/pubsub 4.4.7 → 4.4.8-next.2

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.
Files changed (41) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/dist/aws-amplify-pubsub.js +318 -8
  3. package/dist/aws-amplify-pubsub.js.map +1 -1
  4. package/dist/aws-amplify-pubsub.min.js +2 -2
  5. package/dist/aws-amplify-pubsub.min.js.map +1 -1
  6. package/lib/Providers/AWSAppSyncRealTimeProvider/constants.d.ts +4 -0
  7. package/lib/Providers/AWSAppSyncRealTimeProvider/constants.js +4 -0
  8. package/lib/Providers/AWSAppSyncRealTimeProvider/constants.js.map +1 -1
  9. package/lib/Providers/AWSAppSyncRealTimeProvider/index.d.ts +3 -0
  10. package/lib/Providers/AWSAppSyncRealTimeProvider/index.js +34 -5
  11. package/lib/Providers/AWSAppSyncRealTimeProvider/index.js.map +1 -1
  12. package/lib/index.d.ts +2 -0
  13. package/lib/index.js +3 -0
  14. package/lib/index.js.map +1 -1
  15. package/lib/types/index.d.ts +11 -0
  16. package/lib/types/index.js +36 -0
  17. package/lib/types/index.js.map +1 -1
  18. package/lib/utils/ConnectionStateMonitor.d.ts +40 -0
  19. package/lib/utils/ConnectionStateMonitor.js +159 -0
  20. package/lib/utils/ConnectionStateMonitor.js.map +1 -0
  21. package/lib-esm/Providers/AWSAppSyncRealTimeProvider/constants.d.ts +4 -0
  22. package/lib-esm/Providers/AWSAppSyncRealTimeProvider/constants.js +4 -0
  23. package/lib-esm/Providers/AWSAppSyncRealTimeProvider/constants.js.map +1 -1
  24. package/lib-esm/Providers/AWSAppSyncRealTimeProvider/index.d.ts +3 -0
  25. package/lib-esm/Providers/AWSAppSyncRealTimeProvider/index.js +36 -7
  26. package/lib-esm/Providers/AWSAppSyncRealTimeProvider/index.js.map +1 -1
  27. package/lib-esm/index.d.ts +2 -0
  28. package/lib-esm/index.js +2 -0
  29. package/lib-esm/index.js.map +1 -1
  30. package/lib-esm/types/index.d.ts +11 -0
  31. package/lib-esm/types/index.js +36 -0
  32. package/lib-esm/types/index.js.map +1 -1
  33. package/lib-esm/utils/ConnectionStateMonitor.d.ts +40 -0
  34. package/lib-esm/utils/ConnectionStateMonitor.js +154 -0
  35. package/lib-esm/utils/ConnectionStateMonitor.js.map +1 -0
  36. package/package.json +5 -5
  37. package/src/Providers/AWSAppSyncRealTimeProvider/constants.ts +5 -0
  38. package/src/Providers/AWSAppSyncRealTimeProvider/index.ts +56 -4
  39. package/src/index.ts +3 -0
  40. package/src/types/index.ts +36 -0
  41. package/src/utils/ConnectionStateMonitor.ts +191 -0
package/CHANGELOG.md CHANGED
@@ -3,6 +3,22 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [4.4.9](https://github.com/aws-amplify/amplify-js/compare/@aws-amplify/pubsub@4.4.8...@aws-amplify/pubsub@4.4.9) (2022-08-01)
7
+
8
+ **Note:** Version bump only for package @aws-amplify/pubsub
9
+
10
+
11
+
12
+
13
+
14
+ ## [4.4.8](https://github.com/aws-amplify/amplify-js/compare/@aws-amplify/pubsub@4.4.7...@aws-amplify/pubsub@4.4.8) (2022-07-28)
15
+
16
+ **Note:** Version bump only for package @aws-amplify/pubsub
17
+
18
+
19
+
20
+
21
+
6
22
  ## [4.4.7](https://github.com/aws-amplify/amplify-js/compare/@aws-amplify/pubsub@4.4.6...@aws-amplify/pubsub@4.4.7) (2022-07-21)
7
23
 
8
24
  **Note:** Version bump only for package @aws-amplify/pubsub
@@ -7618,7 +7618,7 @@ function (_super) {
7618
7618
  /*!*******************************************************************!*\
7619
7619
  !*** ./lib-esm/Providers/AWSAppSyncRealTimeProvider/constants.js ***!
7620
7620
  \*******************************************************************/
7621
- /*! exports provided: MAX_DELAY_MS, NON_RETRYABLE_CODES, MESSAGE_TYPES, SUBSCRIPTION_STATUS, SOCKET_STATUS, AMPLIFY_SYMBOL, AWS_APPSYNC_REALTIME_HEADERS, CONNECTION_INIT_TIMEOUT, START_ACK_TIMEOUT, DEFAULT_KEEP_ALIVE_TIMEOUT */
7621
+ /*! exports provided: MAX_DELAY_MS, NON_RETRYABLE_CODES, MESSAGE_TYPES, SUBSCRIPTION_STATUS, SOCKET_STATUS, AMPLIFY_SYMBOL, AWS_APPSYNC_REALTIME_HEADERS, CONNECTION_INIT_TIMEOUT, START_ACK_TIMEOUT, DEFAULT_KEEP_ALIVE_TIMEOUT, DEFAULT_KEEP_ALIVE_ALERT_TIMEOUT */
7622
7622
  /***/ (function(module, __webpack_exports__, __webpack_require__) {
7623
7623
 
7624
7624
  "use strict";
@@ -7633,6 +7633,7 @@ __webpack_require__.r(__webpack_exports__);
7633
7633
  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "CONNECTION_INIT_TIMEOUT", function() { return CONNECTION_INIT_TIMEOUT; });
7634
7634
  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "START_ACK_TIMEOUT", function() { return START_ACK_TIMEOUT; });
7635
7635
  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "DEFAULT_KEEP_ALIVE_TIMEOUT", function() { return DEFAULT_KEEP_ALIVE_TIMEOUT; });
7636
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "DEFAULT_KEEP_ALIVE_ALERT_TIMEOUT", function() { return DEFAULT_KEEP_ALIVE_ALERT_TIMEOUT; });
7636
7637
  var MAX_DELAY_MS = 5000;
7637
7638
  var NON_RETRYABLE_CODES = [400, 401, 403];
7638
7639
  var MESSAGE_TYPES;
@@ -7736,6 +7737,11 @@ var START_ACK_TIMEOUT = 15000;
7736
7737
  */
7737
7738
 
7738
7739
  var DEFAULT_KEEP_ALIVE_TIMEOUT = 5 * 60 * 1000;
7740
+ /**
7741
+ * Default Time in milleseconds to alert for missed GQL_CONNECTION_KEEP_ALIVE message
7742
+ */
7743
+
7744
+ var DEFAULT_KEEP_ALIVE_ALERT_TIMEOUT = 65 * 1000;
7739
7745
 
7740
7746
  /***/ }),
7741
7747
 
@@ -7767,6 +7773,7 @@ __webpack_require__.r(__webpack_exports__);
7767
7773
  /* harmony import */ var _PubSubProvider__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ../PubSubProvider */ "./lib-esm/Providers/PubSubProvider.js");
7768
7774
  /* harmony import */ var _index__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ../../index */ "./lib-esm/index.js");
7769
7775
  /* harmony import */ var _constants__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ./constants */ "./lib-esm/Providers/AWSAppSyncRealTimeProvider/constants.js");
7776
+ /* harmony import */ var _utils_ConnectionStateMonitor__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(/*! ../../utils/ConnectionStateMonitor */ "./lib-esm/utils/ConnectionStateMonitor.js");
7770
7777
  var __extends = undefined && undefined.__extends || function () {
7771
7778
  var _extendStatics = function extendStatics(d, b) {
7772
7779
  _extendStatics = Object.setPrototypeOf || {
@@ -8003,6 +8010,7 @@ var __read = undefined && undefined.__read || function (o, n) {
8003
8010
 
8004
8011
 
8005
8012
 
8013
+
8006
8014
  var logger = new _aws_amplify_core__WEBPACK_IMPORTED_MODULE_5__["Logger"]('AWSAppSyncRealTimeProvider');
8007
8015
 
8008
8016
  var dispatchApiEvent = function dispatchApiEvent(event, data, message) {
@@ -8021,13 +8029,26 @@ var AWSAppSyncRealTimeProvider =
8021
8029
  function (_super) {
8022
8030
  __extends(AWSAppSyncRealTimeProvider, _super);
8023
8031
 
8024
- function AWSAppSyncRealTimeProvider() {
8025
- var _this = _super !== null && _super.apply(this, arguments) || this;
8032
+ function AWSAppSyncRealTimeProvider(options) {
8033
+ if (options === void 0) {
8034
+ options = {};
8035
+ }
8036
+
8037
+ var _this = _super.call(this, options) || this;
8026
8038
 
8027
8039
  _this.socketStatus = _constants__WEBPACK_IMPORTED_MODULE_10__["SOCKET_STATUS"].CLOSED;
8028
8040
  _this.keepAliveTimeout = _constants__WEBPACK_IMPORTED_MODULE_10__["DEFAULT_KEEP_ALIVE_TIMEOUT"];
8029
8041
  _this.subscriptionObserverMap = new Map();
8030
8042
  _this.promiseArray = [];
8043
+ _this.connectionStateMonitor = new _utils_ConnectionStateMonitor__WEBPACK_IMPORTED_MODULE_11__["ConnectionStateMonitor"](); // Monitor the connection state and pass changes along to Hub
8044
+
8045
+ _this.connectionStateMonitor.connectionStateObservable.subscribe(function (ConnectionState) {
8046
+ dispatchApiEvent(_index__WEBPACK_IMPORTED_MODULE_9__["CONNECTION_STATE_CHANGE"], {
8047
+ provider: _this,
8048
+ connectionState: ConnectionState
8049
+ }, "Connection state is " + ConnectionState);
8050
+ });
8051
+
8031
8052
  return _this;
8032
8053
  }
8033
8054
 
@@ -8077,6 +8098,9 @@ function (_super) {
8077
8098
  observer.error({
8078
8099
  errors: [__assign({}, new graphql__WEBPACK_IMPORTED_MODULE_1__["GraphQLError"](_index__WEBPACK_IMPORTED_MODULE_9__["CONTROL_MSG"].REALTIME_SUBSCRIPTION_INIT_ERROR + ": " + err))]
8079
8100
  });
8101
+
8102
+ _this.connectionStateMonitor.record(_utils_ConnectionStateMonitor__WEBPACK_IMPORTED_MODULE_11__["CONNECTION_CHANGE"].CLOSED);
8103
+
8080
8104
  observer.complete();
8081
8105
  });
8082
8106
 
@@ -8221,6 +8245,7 @@ function (_super) {
8221
8245
  case 3:
8222
8246
  _k.trys.push([3, 5,, 6]);
8223
8247
 
8248
+ this.connectionStateMonitor.record(_utils_ConnectionStateMonitor__WEBPACK_IMPORTED_MODULE_11__["CONNECTION_CHANGE"].OPENING_CONNECTION);
8224
8249
  return [4
8225
8250
  /*yield*/
8226
8251
  , this._initializeWebSocketConnection({
@@ -8244,6 +8269,7 @@ function (_super) {
8244
8269
  err: err_2
8245
8270
  });
8246
8271
  message = (_b = err_2['message']) !== null && _b !== void 0 ? _b : '';
8272
+ this.connectionStateMonitor.record(_utils_ConnectionStateMonitor__WEBPACK_IMPORTED_MODULE_11__["CONNECTION_CHANGE"].CLOSED);
8247
8273
  observer.error({
8248
8274
  errors: [__assign({}, new graphql__WEBPACK_IMPORTED_MODULE_1__["GraphQLError"](_index__WEBPACK_IMPORTED_MODULE_9__["CONTROL_MSG"].CONNECTION_FAILED + ": " + message))]
8249
8275
  });
@@ -8362,12 +8388,22 @@ function (_super) {
8362
8388
  return;
8363
8389
  }
8364
8390
 
8391
+ this.connectionStateMonitor.record(_utils_ConnectionStateMonitor__WEBPACK_IMPORTED_MODULE_11__["CONNECTION_CHANGE"].CLOSING_CONNECTION);
8392
+
8365
8393
  if (this.awsRealTimeSocket.bufferedAmount > 0) {
8366
8394
  // Still data on the WebSocket
8367
8395
  setTimeout(this._closeSocketIfRequired.bind(this), 1000);
8368
8396
  } else {
8369
8397
  logger.debug('closing WebSocket...');
8370
- if (this.keepAliveTimeoutId) clearTimeout(this.keepAliveTimeoutId);
8398
+
8399
+ if (this.keepAliveTimeoutId) {
8400
+ clearTimeout(this.keepAliveTimeoutId);
8401
+ }
8402
+
8403
+ if (this.keepAliveAlertTimeoutId) {
8404
+ clearTimeout(this.keepAliveAlertTimeoutId);
8405
+ }
8406
+
8371
8407
  var tempSocket = this.awsRealTimeSocket; // Cleaning callbacks to avoid race condition, socket still exists
8372
8408
 
8373
8409
  tempSocket.onclose = null;
@@ -8375,10 +8411,13 @@ function (_super) {
8375
8411
  tempSocket.close(1000);
8376
8412
  this.awsRealTimeSocket = undefined;
8377
8413
  this.socketStatus = _constants__WEBPACK_IMPORTED_MODULE_10__["SOCKET_STATUS"].CLOSED;
8414
+ this.connectionStateMonitor.record(_utils_ConnectionStateMonitor__WEBPACK_IMPORTED_MODULE_11__["CONNECTION_CHANGE"].CLOSED);
8378
8415
  }
8379
8416
  };
8380
8417
 
8381
8418
  AWSAppSyncRealTimeProvider.prototype._handleIncomingSubscriptionMessage = function (message) {
8419
+ var _this = this;
8420
+
8382
8421
  logger.debug("subscription message from AWS AppSync RealTime: " + message.data);
8383
8422
 
8384
8423
  var _a = JSON.parse(message.data),
@@ -8442,15 +8481,22 @@ function (_super) {
8442
8481
  subscriptionReadyCallback: subscriptionReadyCallback,
8443
8482
  subscriptionFailedCallback: subscriptionFailedCallback
8444
8483
  });
8445
- } // TODO: emit event on hub but it requires to store the id first
8446
-
8484
+ }
8447
8485
 
8486
+ this.connectionStateMonitor.record(_utils_ConnectionStateMonitor__WEBPACK_IMPORTED_MODULE_11__["CONNECTION_CHANGE"].CONNECTION_ESTABLISHED);
8448
8487
  return;
8449
8488
  }
8450
8489
 
8451
8490
  if (type === _constants__WEBPACK_IMPORTED_MODULE_10__["MESSAGE_TYPES"].GQL_CONNECTION_KEEP_ALIVE) {
8452
8491
  if (this.keepAliveTimeoutId) clearTimeout(this.keepAliveTimeoutId);
8453
- this.keepAliveTimeoutId = setTimeout(this._errorDisconnect.bind(this, _index__WEBPACK_IMPORTED_MODULE_9__["CONTROL_MSG"].TIMEOUT_DISCONNECT), this.keepAliveTimeout);
8492
+ if (this.keepAliveAlertTimeoutId) clearTimeout(this.keepAliveAlertTimeoutId);
8493
+ this.keepAliveTimeoutId = setTimeout(function () {
8494
+ return _this._errorDisconnect(_index__WEBPACK_IMPORTED_MODULE_9__["CONTROL_MSG"].TIMEOUT_DISCONNECT);
8495
+ }, this.keepAliveTimeout);
8496
+ this.keepAliveAlertTimeoutId = setTimeout(function () {
8497
+ _this.connectionStateMonitor.record(_utils_ConnectionStateMonitor__WEBPACK_IMPORTED_MODULE_11__["CONNECTION_CHANGE"].KEEP_ALIVE_MISSED);
8498
+ }, _constants__WEBPACK_IMPORTED_MODULE_10__["DEFAULT_KEEP_ALIVE_ALERT_TIMEOUT"]);
8499
+ this.connectionStateMonitor.record(_utils_ConnectionStateMonitor__WEBPACK_IMPORTED_MODULE_11__["CONNECTION_CHANGE"].KEEP_ALIVE);
8454
8500
  return;
8455
8501
  }
8456
8502
 
@@ -8494,6 +8540,7 @@ function (_super) {
8494
8540
  this.subscriptionObserverMap.clear();
8495
8541
 
8496
8542
  if (this.awsRealTimeSocket) {
8543
+ this.connectionStateMonitor.record(_utils_ConnectionStateMonitor__WEBPACK_IMPORTED_MODULE_11__["CONNECTION_CHANGE"].CLOSED);
8497
8544
  this.awsRealTimeSocket.close();
8498
8545
  }
8499
8546
 
@@ -8692,6 +8739,8 @@ function (_super) {
8692
8739
  };
8693
8740
 
8694
8741
  newSocket.onclose = function () {
8742
+ _this.connectionStateMonitor.record(_utils_ConnectionStateMonitor__WEBPACK_IMPORTED_MODULE_11__["CONNECTION_CHANGE"].CONNECTION_FAILED);
8743
+
8695
8744
  rej(new Error('Connection handshake error'));
8696
8745
  };
8697
8746
 
@@ -8783,6 +8832,7 @@ function (_super) {
8783
8832
 
8784
8833
  function checkAckOk(ackOk) {
8785
8834
  if (!ackOk) {
8835
+ this.connectionStateMonitor.record(_utils_ConnectionStateMonitor__WEBPACK_IMPORTED_MODULE_11__["CONNECTION_CHANGE"].CONNECTION_FAILED);
8786
8836
  rej(new Error("Connection timeout: ack from AWSRealTime was not received on " + _constants__WEBPACK_IMPORTED_MODULE_10__["CONNECTION_INIT_TIMEOUT"] + " ms"));
8787
8837
  }
8788
8838
  }
@@ -10555,11 +10605,12 @@ _aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__["Amplify"].register(PubSub);
10555
10605
  /*!**************************!*\
10556
10606
  !*** ./lib-esm/index.js ***!
10557
10607
  \**************************/
10558
- /*! exports provided: AbstractPubSubProvider, AWSAppSyncProvider, AWSAppSyncRealTimeProvider, AWSIoTProvider, mqttTopicMatch, MqttOverWSProvider, PubSub, CONTROL_MSG, default */
10608
+ /*! exports provided: AbstractPubSubProvider, AWSAppSyncProvider, AWSAppSyncRealTimeProvider, AWSIoTProvider, mqttTopicMatch, MqttOverWSProvider, CONNECTION_STATE_CHANGE, ConnectionState, PubSub, CONTROL_MSG, default */
10559
10609
  /***/ (function(module, __webpack_exports__, __webpack_require__) {
10560
10610
 
10561
10611
  "use strict";
10562
10612
  __webpack_require__.r(__webpack_exports__);
10613
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "CONNECTION_STATE_CHANGE", function() { return CONNECTION_STATE_CHANGE; });
10563
10614
  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "CONTROL_MSG", function() { return CONTROL_MSG; });
10564
10615
  /* harmony import */ var _PubSub__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./PubSub */ "./lib-esm/PubSub.js");
10565
10616
  /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "PubSub", function() { return _PubSub__WEBPACK_IMPORTED_MODULE_0__["PubSub"]; });
@@ -10577,6 +10628,9 @@ __webpack_require__.r(__webpack_exports__);
10577
10628
 
10578
10629
  /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MqttOverWSProvider", function() { return _Providers__WEBPACK_IMPORTED_MODULE_1__["MqttOverWSProvider"]; });
10579
10630
 
10631
+ /* harmony import */ var _types__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./types */ "./lib-esm/types/index.js");
10632
+ /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "ConnectionState", function() { return _types__WEBPACK_IMPORTED_MODULE_2__["ConnectionState"]; });
10633
+
10580
10634
  /*
10581
10635
  * Copyright 2017-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
10582
10636
  *
@@ -10601,6 +10655,8 @@ var CONTROL_MSG;
10601
10655
  CONTROL_MSG["TIMEOUT_DISCONNECT"] = "Timeout disconnect";
10602
10656
  })(CONTROL_MSG || (CONTROL_MSG = {}));
10603
10657
 
10658
+ var CONNECTION_STATE_CHANGE = 'ConnectionStateChange';
10659
+
10604
10660
 
10605
10661
  /**
10606
10662
  * @deprecated use named import
@@ -10608,6 +10664,260 @@ var CONTROL_MSG;
10608
10664
 
10609
10665
  /* harmony default export */ __webpack_exports__["default"] = (_PubSub__WEBPACK_IMPORTED_MODULE_0__["PubSub"]);
10610
10666
 
10667
+ /***/ }),
10668
+
10669
+ /***/ "./lib-esm/types/index.js":
10670
+ /*!********************************!*\
10671
+ !*** ./lib-esm/types/index.js ***!
10672
+ \********************************/
10673
+ /*! exports provided: ConnectionState */
10674
+ /***/ (function(module, __webpack_exports__, __webpack_require__) {
10675
+
10676
+ "use strict";
10677
+ __webpack_require__.r(__webpack_exports__);
10678
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "ConnectionState", function() { return ConnectionState; });
10679
+ /** @enum {string} */
10680
+ var ConnectionState;
10681
+
10682
+ (function (ConnectionState) {
10683
+ /*
10684
+ * The connection is alive and healthy
10685
+ */
10686
+ ConnectionState["Connected"] = "Connected";
10687
+ /*
10688
+ * The connection is alive, but the connection is offline
10689
+ */
10690
+
10691
+ ConnectionState["ConnectedPendingNetwork"] = "ConnectedPendingNetwork";
10692
+ /*
10693
+ * The connection has been disconnected while in use
10694
+ */
10695
+
10696
+ ConnectionState["ConnectionDisrupted"] = "ConnectionDisrupted";
10697
+ /*
10698
+ * The connection has been disconnected and the network is offline
10699
+ */
10700
+
10701
+ ConnectionState["ConnectionDisruptedPendingNetwork"] = "ConnectionDisruptedPendingNetwork";
10702
+ /*
10703
+ * The connection is in the process of connecting
10704
+ */
10705
+
10706
+ ConnectionState["Connecting"] = "Connecting";
10707
+ /*
10708
+ * The connection is not in use and is being disconnected
10709
+ */
10710
+
10711
+ ConnectionState["ConnectedPendingDisconnect"] = "ConnectedPendingDisconnect";
10712
+ /*
10713
+ * The connection is not in use and has been disconnected
10714
+ */
10715
+
10716
+ ConnectionState["Disconnected"] = "Disconnected";
10717
+ /*
10718
+ * The connection is alive, but a keep alive message has been missed
10719
+ */
10720
+
10721
+ ConnectionState["ConnectedPendingKeepAlive"] = "ConnectedPendingKeepAlive";
10722
+ })(ConnectionState || (ConnectionState = {}));
10723
+
10724
+ /***/ }),
10725
+
10726
+ /***/ "./lib-esm/utils/ConnectionStateMonitor.js":
10727
+ /*!*************************************************!*\
10728
+ !*** ./lib-esm/utils/ConnectionStateMonitor.js ***!
10729
+ \*************************************************/
10730
+ /*! exports provided: CONNECTION_CHANGE, ConnectionStateMonitor */
10731
+ /***/ (function(module, __webpack_exports__, __webpack_require__) {
10732
+
10733
+ "use strict";
10734
+ __webpack_require__.r(__webpack_exports__);
10735
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "CONNECTION_CHANGE", function() { return CONNECTION_CHANGE; });
10736
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "ConnectionStateMonitor", function() { return ConnectionStateMonitor; });
10737
+ /* harmony import */ var _aws_amplify_core__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @aws-amplify/core */ "@aws-amplify/core");
10738
+ /* harmony import */ var _aws_amplify_core__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_aws_amplify_core__WEBPACK_IMPORTED_MODULE_0__);
10739
+ /* harmony import */ var zen_observable_ts__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! zen-observable-ts */ "../../node_modules/zen-observable-ts/lib/bundle.esm.js");
10740
+ /* harmony import */ var _index__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../index */ "./lib-esm/index.js");
10741
+ /*
10742
+ * Copyright 2017-2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
10743
+ *
10744
+ * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
10745
+ * the License. A copy of the License is located at
10746
+ *
10747
+ * http://aws.amazon.com/apache2.0/
10748
+ *
10749
+ * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10750
+ * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
10751
+ * and limitations under the License.
10752
+ */
10753
+ var __assign = undefined && undefined.__assign || function () {
10754
+ __assign = Object.assign || function (t) {
10755
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
10756
+ s = arguments[i];
10757
+
10758
+ for (var p in s) {
10759
+ if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
10760
+ }
10761
+ }
10762
+
10763
+ return t;
10764
+ };
10765
+
10766
+ return __assign.apply(this, arguments);
10767
+ };
10768
+
10769
+
10770
+
10771
+
10772
+ var CONNECTION_CHANGE = {
10773
+ KEEP_ALIVE_MISSED: {
10774
+ keepAliveState: 'unhealthy'
10775
+ },
10776
+ KEEP_ALIVE: {
10777
+ keepAliveState: 'healthy'
10778
+ },
10779
+ CONNECTION_ESTABLISHED: {
10780
+ connectionState: 'connected'
10781
+ },
10782
+ CONNECTION_FAILED: {
10783
+ intendedConnectionState: 'disconnected',
10784
+ connectionState: 'disconnected'
10785
+ },
10786
+ CLOSING_CONNECTION: {
10787
+ intendedConnectionState: 'disconnected'
10788
+ },
10789
+ OPENING_CONNECTION: {
10790
+ intendedConnectionState: 'connected',
10791
+ connectionState: 'connecting'
10792
+ },
10793
+ CLOSED: {
10794
+ connectionState: 'disconnected'
10795
+ },
10796
+ ONLINE: {
10797
+ networkState: 'connected'
10798
+ },
10799
+ OFFLINE: {
10800
+ networkState: 'disconnected'
10801
+ }
10802
+ };
10803
+
10804
+ var ConnectionStateMonitor =
10805
+ /** @class */
10806
+ function () {
10807
+ function ConnectionStateMonitor() {
10808
+ var _this = this;
10809
+
10810
+ this._networkMonitoringSubscription = undefined;
10811
+ this._linkedConnectionState = {
10812
+ networkState: 'connected',
10813
+ connectionState: 'disconnected',
10814
+ intendedConnectionState: 'disconnected',
10815
+ keepAliveState: 'healthy'
10816
+ };
10817
+ this._linkedConnectionStateObservable = new zen_observable_ts__WEBPACK_IMPORTED_MODULE_1__["default"](function (connectionStateObserver) {
10818
+ connectionStateObserver.next(_this._linkedConnectionState);
10819
+ _this._linkedConnectionStateObserver = connectionStateObserver;
10820
+ });
10821
+ }
10822
+ /**
10823
+ * Turn network state monitoring on if it isn't on already
10824
+ */
10825
+
10826
+
10827
+ ConnectionStateMonitor.prototype.enableNetworkMonitoring = function () {
10828
+ var _this = this; // Maintain the network state based on the reachability monitor
10829
+
10830
+
10831
+ if (this._networkMonitoringSubscription === undefined) {
10832
+ this._networkMonitoringSubscription = new _aws_amplify_core__WEBPACK_IMPORTED_MODULE_0__["Reachability"]().networkMonitor().subscribe(function (_a) {
10833
+ var online = _a.online;
10834
+
10835
+ _this.record(online ? CONNECTION_CHANGE.ONLINE : CONNECTION_CHANGE.OFFLINE);
10836
+ });
10837
+ }
10838
+ };
10839
+ /**
10840
+ * Turn network state monitoring off if it isn't off already
10841
+ */
10842
+
10843
+
10844
+ ConnectionStateMonitor.prototype.disableNetworkMonitoring = function () {
10845
+ var _a;
10846
+
10847
+ (_a = this._networkMonitoringSubscription) === null || _a === void 0 ? void 0 : _a.unsubscribe();
10848
+ this._networkMonitoringSubscription = undefined;
10849
+ };
10850
+
10851
+ Object.defineProperty(ConnectionStateMonitor.prototype, "connectionStateObservable", {
10852
+ /**
10853
+ * Get the observable that allows us to monitor the connection state
10854
+ *
10855
+ * @returns {Observable<ConnectionState>} - The observable that emits ConnectionState updates
10856
+ */
10857
+ get: function get() {
10858
+ var _this = this;
10859
+
10860
+ var previous; // The linked state aggregates state changes to any of the network, connection,
10861
+ // intendedConnection and keepAliveHealth. Some states will change these independent
10862
+ // states without changing the overall connection state.
10863
+ // After translating from linked states to ConnectionState, then remove any duplicates
10864
+
10865
+ return this._linkedConnectionStateObservable.map(function (value) {
10866
+ return _this.connectionStatesTranslator(value);
10867
+ }).filter(function (current) {
10868
+ var toInclude = current !== previous;
10869
+ previous = current;
10870
+ return toInclude;
10871
+ });
10872
+ },
10873
+ enumerable: true,
10874
+ configurable: true
10875
+ });
10876
+ /*
10877
+ * Updates local connection state and emits the full state to the observer.
10878
+ */
10879
+
10880
+ ConnectionStateMonitor.prototype.record = function (statusUpdates) {
10881
+ // Maintain the network monitor
10882
+ if (statusUpdates.intendedConnectionState === 'connected') {
10883
+ this.enableNetworkMonitoring();
10884
+ } else if (statusUpdates.intendedConnectionState === 'disconnected') {
10885
+ this.disableNetworkMonitoring();
10886
+ } // Maintain the socket state
10887
+
10888
+
10889
+ var newSocketStatus = __assign(__assign({}, this._linkedConnectionState), statusUpdates);
10890
+
10891
+ this._linkedConnectionState = __assign({}, newSocketStatus);
10892
+
10893
+ this._linkedConnectionStateObserver.next(this._linkedConnectionState);
10894
+ };
10895
+ /*
10896
+ * Translate the ConnectionState structure into a specific ConnectionState string literal union
10897
+ */
10898
+
10899
+
10900
+ ConnectionStateMonitor.prototype.connectionStatesTranslator = function (_a) {
10901
+ var connectionState = _a.connectionState,
10902
+ networkState = _a.networkState,
10903
+ intendedConnectionState = _a.intendedConnectionState,
10904
+ keepAliveState = _a.keepAliveState;
10905
+ if (connectionState === 'connected' && networkState === 'disconnected') return _index__WEBPACK_IMPORTED_MODULE_2__["ConnectionState"].ConnectedPendingNetwork;
10906
+ if (connectionState === 'connected' && intendedConnectionState === 'disconnected') return _index__WEBPACK_IMPORTED_MODULE_2__["ConnectionState"].ConnectedPendingDisconnect;
10907
+ if (connectionState === 'disconnected' && intendedConnectionState === 'connected' && networkState === 'disconnected') return _index__WEBPACK_IMPORTED_MODULE_2__["ConnectionState"].ConnectionDisruptedPendingNetwork;
10908
+ if (connectionState === 'disconnected' && intendedConnectionState === 'connected') return _index__WEBPACK_IMPORTED_MODULE_2__["ConnectionState"].ConnectionDisrupted;
10909
+ if (connectionState === 'connected' && keepAliveState === 'unhealthy') return _index__WEBPACK_IMPORTED_MODULE_2__["ConnectionState"].ConnectedPendingKeepAlive; // All remaining states directly correspond to the connection state
10910
+
10911
+ if (connectionState === 'connecting') return _index__WEBPACK_IMPORTED_MODULE_2__["ConnectionState"].Connecting;
10912
+ if (connectionState === 'disconnected') return _index__WEBPACK_IMPORTED_MODULE_2__["ConnectionState"].Disconnected;
10913
+ return _index__WEBPACK_IMPORTED_MODULE_2__["ConnectionState"].Connected;
10914
+ };
10915
+
10916
+ return ConnectionStateMonitor;
10917
+ }();
10918
+
10919
+
10920
+
10611
10921
  /***/ }),
10612
10922
 
10613
10923
  /***/ "@aws-amplify/auth":