@aws-amplify/api 4.0.48-unstable.2 → 4.0.48-unstable.3

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.
@@ -12141,7 +12141,7 @@ function (_super) {
12141
12141
  /*!***************************************************************************!*\
12142
12142
  !*** ../pubsub/lib-esm/Providers/AWSAppSyncRealTimeProvider/constants.js ***!
12143
12143
  \***************************************************************************/
12144
- /*! 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 */
12144
+ /*! 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 */
12145
12145
  /***/ (function(module, __webpack_exports__, __webpack_require__) {
12146
12146
 
12147
12147
  "use strict";
@@ -12156,6 +12156,7 @@ __webpack_require__.r(__webpack_exports__);
12156
12156
  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "CONNECTION_INIT_TIMEOUT", function() { return CONNECTION_INIT_TIMEOUT; });
12157
12157
  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "START_ACK_TIMEOUT", function() { return START_ACK_TIMEOUT; });
12158
12158
  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "DEFAULT_KEEP_ALIVE_TIMEOUT", function() { return DEFAULT_KEEP_ALIVE_TIMEOUT; });
12159
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "DEFAULT_KEEP_ALIVE_ALERT_TIMEOUT", function() { return DEFAULT_KEEP_ALIVE_ALERT_TIMEOUT; });
12159
12160
  var MAX_DELAY_MS = 5000;
12160
12161
  var NON_RETRYABLE_CODES = [400, 401, 403];
12161
12162
  var MESSAGE_TYPES;
@@ -12259,6 +12260,11 @@ var START_ACK_TIMEOUT = 15000;
12259
12260
  */
12260
12261
 
12261
12262
  var DEFAULT_KEEP_ALIVE_TIMEOUT = 5 * 60 * 1000;
12263
+ /**
12264
+ * Default Time in milleseconds to alert for missed GQL_CONNECTION_KEEP_ALIVE message
12265
+ */
12266
+
12267
+ var DEFAULT_KEEP_ALIVE_ALERT_TIMEOUT = 65 * 1000;
12262
12268
 
12263
12269
  /***/ }),
12264
12270
 
@@ -12290,6 +12296,7 @@ __webpack_require__.r(__webpack_exports__);
12290
12296
  /* harmony import */ var _PubSubProvider__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ../PubSubProvider */ "../pubsub/lib-esm/Providers/PubSubProvider.js");
12291
12297
  /* harmony import */ var _index__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ../../index */ "../pubsub/lib-esm/index.js");
12292
12298
  /* harmony import */ var _constants__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ./constants */ "../pubsub/lib-esm/Providers/AWSAppSyncRealTimeProvider/constants.js");
12299
+ /* harmony import */ var _utils_ConnectionStateMonitor__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(/*! ../../utils/ConnectionStateMonitor */ "../pubsub/lib-esm/utils/ConnectionStateMonitor.js");
12293
12300
  var __extends = undefined && undefined.__extends || function () {
12294
12301
  var _extendStatics = function extendStatics(d, b) {
12295
12302
  _extendStatics = Object.setPrototypeOf || {
@@ -12526,6 +12533,7 @@ var __read = undefined && undefined.__read || function (o, n) {
12526
12533
 
12527
12534
 
12528
12535
 
12536
+
12529
12537
  var logger = new _aws_amplify_core__WEBPACK_IMPORTED_MODULE_5__["Logger"]('AWSAppSyncRealTimeProvider');
12530
12538
 
12531
12539
  var dispatchApiEvent = function dispatchApiEvent(event, data, message) {
@@ -12544,13 +12552,26 @@ var AWSAppSyncRealTimeProvider =
12544
12552
  function (_super) {
12545
12553
  __extends(AWSAppSyncRealTimeProvider, _super);
12546
12554
 
12547
- function AWSAppSyncRealTimeProvider() {
12548
- var _this = _super !== null && _super.apply(this, arguments) || this;
12555
+ function AWSAppSyncRealTimeProvider(options) {
12556
+ if (options === void 0) {
12557
+ options = {};
12558
+ }
12559
+
12560
+ var _this = _super.call(this, options) || this;
12549
12561
 
12550
12562
  _this.socketStatus = _constants__WEBPACK_IMPORTED_MODULE_10__["SOCKET_STATUS"].CLOSED;
12551
12563
  _this.keepAliveTimeout = _constants__WEBPACK_IMPORTED_MODULE_10__["DEFAULT_KEEP_ALIVE_TIMEOUT"];
12552
12564
  _this.subscriptionObserverMap = new Map();
12553
12565
  _this.promiseArray = [];
12566
+ _this.connectionStateMonitor = new _utils_ConnectionStateMonitor__WEBPACK_IMPORTED_MODULE_11__["ConnectionStateMonitor"](); // Monitor the connection state and pass changes along to Hub
12567
+
12568
+ _this.connectionStateMonitor.connectionStateObservable.subscribe(function (ConnectionState) {
12569
+ dispatchApiEvent(_index__WEBPACK_IMPORTED_MODULE_9__["CONNECTION_STATE_CHANGE"], {
12570
+ provider: _this,
12571
+ connectionState: ConnectionState
12572
+ }, "Connection state is " + ConnectionState);
12573
+ });
12574
+
12554
12575
  return _this;
12555
12576
  }
12556
12577
 
@@ -12600,6 +12621,9 @@ function (_super) {
12600
12621
  observer.error({
12601
12622
  errors: [__assign({}, new graphql__WEBPACK_IMPORTED_MODULE_1__["GraphQLError"](_index__WEBPACK_IMPORTED_MODULE_9__["CONTROL_MSG"].REALTIME_SUBSCRIPTION_INIT_ERROR + ": " + err))]
12602
12623
  });
12624
+
12625
+ _this.connectionStateMonitor.record(_utils_ConnectionStateMonitor__WEBPACK_IMPORTED_MODULE_11__["CONNECTION_CHANGE"].CLOSED);
12626
+
12603
12627
  observer.complete();
12604
12628
  });
12605
12629
 
@@ -12744,6 +12768,7 @@ function (_super) {
12744
12768
  case 3:
12745
12769
  _k.trys.push([3, 5,, 6]);
12746
12770
 
12771
+ this.connectionStateMonitor.record(_utils_ConnectionStateMonitor__WEBPACK_IMPORTED_MODULE_11__["CONNECTION_CHANGE"].OPENING_CONNECTION);
12747
12772
  return [4
12748
12773
  /*yield*/
12749
12774
  , this._initializeWebSocketConnection({
@@ -12767,6 +12792,7 @@ function (_super) {
12767
12792
  err: err_2
12768
12793
  });
12769
12794
  message = (_b = err_2['message']) !== null && _b !== void 0 ? _b : '';
12795
+ this.connectionStateMonitor.record(_utils_ConnectionStateMonitor__WEBPACK_IMPORTED_MODULE_11__["CONNECTION_CHANGE"].CLOSED);
12770
12796
  observer.error({
12771
12797
  errors: [__assign({}, new graphql__WEBPACK_IMPORTED_MODULE_1__["GraphQLError"](_index__WEBPACK_IMPORTED_MODULE_9__["CONTROL_MSG"].CONNECTION_FAILED + ": " + message))]
12772
12798
  });
@@ -12885,12 +12911,22 @@ function (_super) {
12885
12911
  return;
12886
12912
  }
12887
12913
 
12914
+ this.connectionStateMonitor.record(_utils_ConnectionStateMonitor__WEBPACK_IMPORTED_MODULE_11__["CONNECTION_CHANGE"].CLOSING_CONNECTION);
12915
+
12888
12916
  if (this.awsRealTimeSocket.bufferedAmount > 0) {
12889
12917
  // Still data on the WebSocket
12890
12918
  setTimeout(this._closeSocketIfRequired.bind(this), 1000);
12891
12919
  } else {
12892
12920
  logger.debug('closing WebSocket...');
12893
- if (this.keepAliveTimeoutId) clearTimeout(this.keepAliveTimeoutId);
12921
+
12922
+ if (this.keepAliveTimeoutId) {
12923
+ clearTimeout(this.keepAliveTimeoutId);
12924
+ }
12925
+
12926
+ if (this.keepAliveAlertTimeoutId) {
12927
+ clearTimeout(this.keepAliveAlertTimeoutId);
12928
+ }
12929
+
12894
12930
  var tempSocket = this.awsRealTimeSocket; // Cleaning callbacks to avoid race condition, socket still exists
12895
12931
 
12896
12932
  tempSocket.onclose = null;
@@ -12898,10 +12934,13 @@ function (_super) {
12898
12934
  tempSocket.close(1000);
12899
12935
  this.awsRealTimeSocket = undefined;
12900
12936
  this.socketStatus = _constants__WEBPACK_IMPORTED_MODULE_10__["SOCKET_STATUS"].CLOSED;
12937
+ this.connectionStateMonitor.record(_utils_ConnectionStateMonitor__WEBPACK_IMPORTED_MODULE_11__["CONNECTION_CHANGE"].CLOSED);
12901
12938
  }
12902
12939
  };
12903
12940
 
12904
12941
  AWSAppSyncRealTimeProvider.prototype._handleIncomingSubscriptionMessage = function (message) {
12942
+ var _this = this;
12943
+
12905
12944
  logger.debug("subscription message from AWS AppSync RealTime: " + message.data);
12906
12945
 
12907
12946
  var _a = JSON.parse(message.data),
@@ -12965,15 +13004,22 @@ function (_super) {
12965
13004
  subscriptionReadyCallback: subscriptionReadyCallback,
12966
13005
  subscriptionFailedCallback: subscriptionFailedCallback
12967
13006
  });
12968
- } // TODO: emit event on hub but it requires to store the id first
12969
-
13007
+ }
12970
13008
 
13009
+ this.connectionStateMonitor.record(_utils_ConnectionStateMonitor__WEBPACK_IMPORTED_MODULE_11__["CONNECTION_CHANGE"].CONNECTION_ESTABLISHED);
12971
13010
  return;
12972
13011
  }
12973
13012
 
12974
13013
  if (type === _constants__WEBPACK_IMPORTED_MODULE_10__["MESSAGE_TYPES"].GQL_CONNECTION_KEEP_ALIVE) {
12975
13014
  if (this.keepAliveTimeoutId) clearTimeout(this.keepAliveTimeoutId);
12976
- this.keepAliveTimeoutId = setTimeout(this._errorDisconnect.bind(this, _index__WEBPACK_IMPORTED_MODULE_9__["CONTROL_MSG"].TIMEOUT_DISCONNECT), this.keepAliveTimeout);
13015
+ if (this.keepAliveAlertTimeoutId) clearTimeout(this.keepAliveAlertTimeoutId);
13016
+ this.keepAliveTimeoutId = setTimeout(function () {
13017
+ return _this._errorDisconnect(_index__WEBPACK_IMPORTED_MODULE_9__["CONTROL_MSG"].TIMEOUT_DISCONNECT);
13018
+ }, this.keepAliveTimeout);
13019
+ this.keepAliveAlertTimeoutId = setTimeout(function () {
13020
+ _this.connectionStateMonitor.record(_utils_ConnectionStateMonitor__WEBPACK_IMPORTED_MODULE_11__["CONNECTION_CHANGE"].KEEP_ALIVE_MISSED);
13021
+ }, _constants__WEBPACK_IMPORTED_MODULE_10__["DEFAULT_KEEP_ALIVE_ALERT_TIMEOUT"]);
13022
+ this.connectionStateMonitor.record(_utils_ConnectionStateMonitor__WEBPACK_IMPORTED_MODULE_11__["CONNECTION_CHANGE"].KEEP_ALIVE);
12977
13023
  return;
12978
13024
  }
12979
13025
 
@@ -13017,6 +13063,7 @@ function (_super) {
13017
13063
  this.subscriptionObserverMap.clear();
13018
13064
 
13019
13065
  if (this.awsRealTimeSocket) {
13066
+ this.connectionStateMonitor.record(_utils_ConnectionStateMonitor__WEBPACK_IMPORTED_MODULE_11__["CONNECTION_CHANGE"].CLOSED);
13020
13067
  this.awsRealTimeSocket.close();
13021
13068
  }
13022
13069
 
@@ -13215,6 +13262,8 @@ function (_super) {
13215
13262
  };
13216
13263
 
13217
13264
  newSocket.onclose = function () {
13265
+ _this.connectionStateMonitor.record(_utils_ConnectionStateMonitor__WEBPACK_IMPORTED_MODULE_11__["CONNECTION_CHANGE"].CONNECTION_FAILED);
13266
+
13218
13267
  rej(new Error('Connection handshake error'));
13219
13268
  };
13220
13269
 
@@ -13306,6 +13355,7 @@ function (_super) {
13306
13355
 
13307
13356
  function checkAckOk(ackOk) {
13308
13357
  if (!ackOk) {
13358
+ this.connectionStateMonitor.record(_utils_ConnectionStateMonitor__WEBPACK_IMPORTED_MODULE_11__["CONNECTION_CHANGE"].CONNECTION_FAILED);
13309
13359
  rej(new Error("Connection timeout: ack from AWSRealTime was not received on " + _constants__WEBPACK_IMPORTED_MODULE_10__["CONNECTION_INIT_TIMEOUT"] + " ms"));
13310
13360
  }
13311
13361
  }
@@ -15078,11 +15128,12 @@ _aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__["Amplify"].register(PubSub);
15078
15128
  /*!**********************************!*\
15079
15129
  !*** ../pubsub/lib-esm/index.js ***!
15080
15130
  \**********************************/
15081
- /*! exports provided: AbstractPubSubProvider, AWSAppSyncProvider, AWSAppSyncRealTimeProvider, AWSIoTProvider, mqttTopicMatch, MqttOverWSProvider, PubSub, CONTROL_MSG, default */
15131
+ /*! exports provided: AbstractPubSubProvider, AWSAppSyncProvider, AWSAppSyncRealTimeProvider, AWSIoTProvider, mqttTopicMatch, MqttOverWSProvider, CONNECTION_STATE_CHANGE, ConnectionState, PubSub, CONTROL_MSG, default */
15082
15132
  /***/ (function(module, __webpack_exports__, __webpack_require__) {
15083
15133
 
15084
15134
  "use strict";
15085
15135
  __webpack_require__.r(__webpack_exports__);
15136
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "CONNECTION_STATE_CHANGE", function() { return CONNECTION_STATE_CHANGE; });
15086
15137
  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "CONTROL_MSG", function() { return CONTROL_MSG; });
15087
15138
  /* harmony import */ var _PubSub__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./PubSub */ "../pubsub/lib-esm/PubSub.js");
15088
15139
  /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "PubSub", function() { return _PubSub__WEBPACK_IMPORTED_MODULE_0__["PubSub"]; });
@@ -15100,6 +15151,9 @@ __webpack_require__.r(__webpack_exports__);
15100
15151
 
15101
15152
  /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MqttOverWSProvider", function() { return _Providers__WEBPACK_IMPORTED_MODULE_1__["MqttOverWSProvider"]; });
15102
15153
 
15154
+ /* harmony import */ var _types__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./types */ "../pubsub/lib-esm/types/index.js");
15155
+ /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "ConnectionState", function() { return _types__WEBPACK_IMPORTED_MODULE_2__["ConnectionState"]; });
15156
+
15103
15157
  /*
15104
15158
  * Copyright 2017-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
15105
15159
  *
@@ -15124,6 +15178,8 @@ var CONTROL_MSG;
15124
15178
  CONTROL_MSG["TIMEOUT_DISCONNECT"] = "Timeout disconnect";
15125
15179
  })(CONTROL_MSG || (CONTROL_MSG = {}));
15126
15180
 
15181
+ var CONNECTION_STATE_CHANGE = 'ConnectionStateChange';
15182
+
15127
15183
 
15128
15184
  /**
15129
15185
  * @deprecated use named import
@@ -15131,6 +15187,260 @@ var CONTROL_MSG;
15131
15187
 
15132
15188
  /* harmony default export */ __webpack_exports__["default"] = (_PubSub__WEBPACK_IMPORTED_MODULE_0__["PubSub"]);
15133
15189
 
15190
+ /***/ }),
15191
+
15192
+ /***/ "../pubsub/lib-esm/types/index.js":
15193
+ /*!****************************************!*\
15194
+ !*** ../pubsub/lib-esm/types/index.js ***!
15195
+ \****************************************/
15196
+ /*! exports provided: ConnectionState */
15197
+ /***/ (function(module, __webpack_exports__, __webpack_require__) {
15198
+
15199
+ "use strict";
15200
+ __webpack_require__.r(__webpack_exports__);
15201
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "ConnectionState", function() { return ConnectionState; });
15202
+ /** @enum {string} */
15203
+ var ConnectionState;
15204
+
15205
+ (function (ConnectionState) {
15206
+ /*
15207
+ * The connection is alive and healthy
15208
+ */
15209
+ ConnectionState["Connected"] = "Connected";
15210
+ /*
15211
+ * The connection is alive, but the connection is offline
15212
+ */
15213
+
15214
+ ConnectionState["ConnectedPendingNetwork"] = "ConnectedPendingNetwork";
15215
+ /*
15216
+ * The connection has been disconnected while in use
15217
+ */
15218
+
15219
+ ConnectionState["ConnectionDisrupted"] = "ConnectionDisrupted";
15220
+ /*
15221
+ * The connection has been disconnected and the network is offline
15222
+ */
15223
+
15224
+ ConnectionState["ConnectionDisruptedPendingNetwork"] = "ConnectionDisruptedPendingNetwork";
15225
+ /*
15226
+ * The connection is in the process of connecting
15227
+ */
15228
+
15229
+ ConnectionState["Connecting"] = "Connecting";
15230
+ /*
15231
+ * The connection is not in use and is being disconnected
15232
+ */
15233
+
15234
+ ConnectionState["ConnectedPendingDisconnect"] = "ConnectedPendingDisconnect";
15235
+ /*
15236
+ * The connection is not in use and has been disconnected
15237
+ */
15238
+
15239
+ ConnectionState["Disconnected"] = "Disconnected";
15240
+ /*
15241
+ * The connection is alive, but a keep alive message has been missed
15242
+ */
15243
+
15244
+ ConnectionState["ConnectedPendingKeepAlive"] = "ConnectedPendingKeepAlive";
15245
+ })(ConnectionState || (ConnectionState = {}));
15246
+
15247
+ /***/ }),
15248
+
15249
+ /***/ "../pubsub/lib-esm/utils/ConnectionStateMonitor.js":
15250
+ /*!*********************************************************!*\
15251
+ !*** ../pubsub/lib-esm/utils/ConnectionStateMonitor.js ***!
15252
+ \*********************************************************/
15253
+ /*! exports provided: CONNECTION_CHANGE, ConnectionStateMonitor */
15254
+ /***/ (function(module, __webpack_exports__, __webpack_require__) {
15255
+
15256
+ "use strict";
15257
+ __webpack_require__.r(__webpack_exports__);
15258
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "CONNECTION_CHANGE", function() { return CONNECTION_CHANGE; });
15259
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "ConnectionStateMonitor", function() { return ConnectionStateMonitor; });
15260
+ /* harmony import */ var _aws_amplify_core__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @aws-amplify/core */ "@aws-amplify/core");
15261
+ /* harmony import */ var _aws_amplify_core__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_aws_amplify_core__WEBPACK_IMPORTED_MODULE_0__);
15262
+ /* harmony import */ var zen_observable_ts__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! zen-observable-ts */ "../../node_modules/zen-observable-ts/lib/bundle.esm.js");
15263
+ /* harmony import */ var _index__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../index */ "../pubsub/lib-esm/index.js");
15264
+ /*
15265
+ * Copyright 2017-2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
15266
+ *
15267
+ * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
15268
+ * the License. A copy of the License is located at
15269
+ *
15270
+ * http://aws.amazon.com/apache2.0/
15271
+ *
15272
+ * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
15273
+ * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
15274
+ * and limitations under the License.
15275
+ */
15276
+ var __assign = undefined && undefined.__assign || function () {
15277
+ __assign = Object.assign || function (t) {
15278
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
15279
+ s = arguments[i];
15280
+
15281
+ for (var p in s) {
15282
+ if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
15283
+ }
15284
+ }
15285
+
15286
+ return t;
15287
+ };
15288
+
15289
+ return __assign.apply(this, arguments);
15290
+ };
15291
+
15292
+
15293
+
15294
+
15295
+ var CONNECTION_CHANGE = {
15296
+ KEEP_ALIVE_MISSED: {
15297
+ keepAliveState: 'unhealthy'
15298
+ },
15299
+ KEEP_ALIVE: {
15300
+ keepAliveState: 'healthy'
15301
+ },
15302
+ CONNECTION_ESTABLISHED: {
15303
+ connectionState: 'connected'
15304
+ },
15305
+ CONNECTION_FAILED: {
15306
+ intendedConnectionState: 'disconnected',
15307
+ connectionState: 'disconnected'
15308
+ },
15309
+ CLOSING_CONNECTION: {
15310
+ intendedConnectionState: 'disconnected'
15311
+ },
15312
+ OPENING_CONNECTION: {
15313
+ intendedConnectionState: 'connected',
15314
+ connectionState: 'connecting'
15315
+ },
15316
+ CLOSED: {
15317
+ connectionState: 'disconnected'
15318
+ },
15319
+ ONLINE: {
15320
+ networkState: 'connected'
15321
+ },
15322
+ OFFLINE: {
15323
+ networkState: 'disconnected'
15324
+ }
15325
+ };
15326
+
15327
+ var ConnectionStateMonitor =
15328
+ /** @class */
15329
+ function () {
15330
+ function ConnectionStateMonitor() {
15331
+ var _this = this;
15332
+
15333
+ this._networkMonitoringSubscription = undefined;
15334
+ this._linkedConnectionState = {
15335
+ networkState: 'connected',
15336
+ connectionState: 'disconnected',
15337
+ intendedConnectionState: 'disconnected',
15338
+ keepAliveState: 'healthy'
15339
+ };
15340
+ this._linkedConnectionStateObservable = new zen_observable_ts__WEBPACK_IMPORTED_MODULE_1__["default"](function (connectionStateObserver) {
15341
+ connectionStateObserver.next(_this._linkedConnectionState);
15342
+ _this._linkedConnectionStateObserver = connectionStateObserver;
15343
+ });
15344
+ }
15345
+ /**
15346
+ * Turn network state monitoring on if it isn't on already
15347
+ */
15348
+
15349
+
15350
+ ConnectionStateMonitor.prototype.enableNetworkMonitoring = function () {
15351
+ var _this = this; // Maintain the network state based on the reachability monitor
15352
+
15353
+
15354
+ if (this._networkMonitoringSubscription === undefined) {
15355
+ this._networkMonitoringSubscription = new _aws_amplify_core__WEBPACK_IMPORTED_MODULE_0__["Reachability"]().networkMonitor().subscribe(function (_a) {
15356
+ var online = _a.online;
15357
+
15358
+ _this.record(online ? CONNECTION_CHANGE.ONLINE : CONNECTION_CHANGE.OFFLINE);
15359
+ });
15360
+ }
15361
+ };
15362
+ /**
15363
+ * Turn network state monitoring off if it isn't off already
15364
+ */
15365
+
15366
+
15367
+ ConnectionStateMonitor.prototype.disableNetworkMonitoring = function () {
15368
+ var _a;
15369
+
15370
+ (_a = this._networkMonitoringSubscription) === null || _a === void 0 ? void 0 : _a.unsubscribe();
15371
+ this._networkMonitoringSubscription = undefined;
15372
+ };
15373
+
15374
+ Object.defineProperty(ConnectionStateMonitor.prototype, "connectionStateObservable", {
15375
+ /**
15376
+ * Get the observable that allows us to monitor the connection state
15377
+ *
15378
+ * @returns {Observable<ConnectionState>} - The observable that emits ConnectionState updates
15379
+ */
15380
+ get: function get() {
15381
+ var _this = this;
15382
+
15383
+ var previous; // The linked state aggregates state changes to any of the network, connection,
15384
+ // intendedConnection and keepAliveHealth. Some states will change these independent
15385
+ // states without changing the overall connection state.
15386
+ // After translating from linked states to ConnectionState, then remove any duplicates
15387
+
15388
+ return this._linkedConnectionStateObservable.map(function (value) {
15389
+ return _this.connectionStatesTranslator(value);
15390
+ }).filter(function (current) {
15391
+ var toInclude = current !== previous;
15392
+ previous = current;
15393
+ return toInclude;
15394
+ });
15395
+ },
15396
+ enumerable: true,
15397
+ configurable: true
15398
+ });
15399
+ /*
15400
+ * Updates local connection state and emits the full state to the observer.
15401
+ */
15402
+
15403
+ ConnectionStateMonitor.prototype.record = function (statusUpdates) {
15404
+ // Maintain the network monitor
15405
+ if (statusUpdates.intendedConnectionState === 'connected') {
15406
+ this.enableNetworkMonitoring();
15407
+ } else if (statusUpdates.intendedConnectionState === 'disconnected') {
15408
+ this.disableNetworkMonitoring();
15409
+ } // Maintain the socket state
15410
+
15411
+
15412
+ var newSocketStatus = __assign(__assign({}, this._linkedConnectionState), statusUpdates);
15413
+
15414
+ this._linkedConnectionState = __assign({}, newSocketStatus);
15415
+
15416
+ this._linkedConnectionStateObserver.next(this._linkedConnectionState);
15417
+ };
15418
+ /*
15419
+ * Translate the ConnectionState structure into a specific ConnectionState string literal union
15420
+ */
15421
+
15422
+
15423
+ ConnectionStateMonitor.prototype.connectionStatesTranslator = function (_a) {
15424
+ var connectionState = _a.connectionState,
15425
+ networkState = _a.networkState,
15426
+ intendedConnectionState = _a.intendedConnectionState,
15427
+ keepAliveState = _a.keepAliveState;
15428
+ if (connectionState === 'connected' && networkState === 'disconnected') return _index__WEBPACK_IMPORTED_MODULE_2__["ConnectionState"].ConnectedPendingNetwork;
15429
+ if (connectionState === 'connected' && intendedConnectionState === 'disconnected') return _index__WEBPACK_IMPORTED_MODULE_2__["ConnectionState"].ConnectedPendingDisconnect;
15430
+ if (connectionState === 'disconnected' && intendedConnectionState === 'connected' && networkState === 'disconnected') return _index__WEBPACK_IMPORTED_MODULE_2__["ConnectionState"].ConnectionDisruptedPendingNetwork;
15431
+ if (connectionState === 'disconnected' && intendedConnectionState === 'connected') return _index__WEBPACK_IMPORTED_MODULE_2__["ConnectionState"].ConnectionDisrupted;
15432
+ if (connectionState === 'connected' && keepAliveState === 'unhealthy') return _index__WEBPACK_IMPORTED_MODULE_2__["ConnectionState"].ConnectedPendingKeepAlive; // All remaining states directly correspond to the connection state
15433
+
15434
+ if (connectionState === 'connecting') return _index__WEBPACK_IMPORTED_MODULE_2__["ConnectionState"].Connecting;
15435
+ if (connectionState === 'disconnected') return _index__WEBPACK_IMPORTED_MODULE_2__["ConnectionState"].Disconnected;
15436
+ return _index__WEBPACK_IMPORTED_MODULE_2__["ConnectionState"].Connected;
15437
+ };
15438
+
15439
+ return ConnectionStateMonitor;
15440
+ }();
15441
+
15442
+
15443
+
15134
15444
  /***/ }),
15135
15445
 
15136
15446
  /***/ "./lib-esm/API.js":