@aws-amplify/api-graphql 2.3.12-unstable.2 → 2.3.12-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.
@@ -11220,7 +11220,7 @@ function (_super) {
11220
11220
  /*!***************************************************************************!*\
11221
11221
  !*** ../pubsub/lib-esm/Providers/AWSAppSyncRealTimeProvider/constants.js ***!
11222
11222
  \***************************************************************************/
11223
- /*! 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 */
11223
+ /*! 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 */
11224
11224
  /***/ (function(module, __webpack_exports__, __webpack_require__) {
11225
11225
 
11226
11226
  "use strict";
@@ -11235,6 +11235,7 @@ __webpack_require__.r(__webpack_exports__);
11235
11235
  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "CONNECTION_INIT_TIMEOUT", function() { return CONNECTION_INIT_TIMEOUT; });
11236
11236
  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "START_ACK_TIMEOUT", function() { return START_ACK_TIMEOUT; });
11237
11237
  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "DEFAULT_KEEP_ALIVE_TIMEOUT", function() { return DEFAULT_KEEP_ALIVE_TIMEOUT; });
11238
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "DEFAULT_KEEP_ALIVE_ALERT_TIMEOUT", function() { return DEFAULT_KEEP_ALIVE_ALERT_TIMEOUT; });
11238
11239
  var MAX_DELAY_MS = 5000;
11239
11240
  var NON_RETRYABLE_CODES = [400, 401, 403];
11240
11241
  var MESSAGE_TYPES;
@@ -11338,6 +11339,11 @@ var START_ACK_TIMEOUT = 15000;
11338
11339
  */
11339
11340
 
11340
11341
  var DEFAULT_KEEP_ALIVE_TIMEOUT = 5 * 60 * 1000;
11342
+ /**
11343
+ * Default Time in milleseconds to alert for missed GQL_CONNECTION_KEEP_ALIVE message
11344
+ */
11345
+
11346
+ var DEFAULT_KEEP_ALIVE_ALERT_TIMEOUT = 65 * 1000;
11341
11347
 
11342
11348
  /***/ }),
11343
11349
 
@@ -11369,6 +11375,7 @@ __webpack_require__.r(__webpack_exports__);
11369
11375
  /* harmony import */ var _PubSubProvider__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ../PubSubProvider */ "../pubsub/lib-esm/Providers/PubSubProvider.js");
11370
11376
  /* harmony import */ var _index__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ../../index */ "../pubsub/lib-esm/index.js");
11371
11377
  /* harmony import */ var _constants__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ./constants */ "../pubsub/lib-esm/Providers/AWSAppSyncRealTimeProvider/constants.js");
11378
+ /* harmony import */ var _utils_ConnectionStateMonitor__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(/*! ../../utils/ConnectionStateMonitor */ "../pubsub/lib-esm/utils/ConnectionStateMonitor.js");
11372
11379
  var __extends = undefined && undefined.__extends || function () {
11373
11380
  var _extendStatics = function extendStatics(d, b) {
11374
11381
  _extendStatics = Object.setPrototypeOf || {
@@ -11605,6 +11612,7 @@ var __read = undefined && undefined.__read || function (o, n) {
11605
11612
 
11606
11613
 
11607
11614
 
11615
+
11608
11616
  var logger = new _aws_amplify_core__WEBPACK_IMPORTED_MODULE_5__["Logger"]('AWSAppSyncRealTimeProvider');
11609
11617
 
11610
11618
  var dispatchApiEvent = function dispatchApiEvent(event, data, message) {
@@ -11623,13 +11631,26 @@ var AWSAppSyncRealTimeProvider =
11623
11631
  function (_super) {
11624
11632
  __extends(AWSAppSyncRealTimeProvider, _super);
11625
11633
 
11626
- function AWSAppSyncRealTimeProvider() {
11627
- var _this = _super !== null && _super.apply(this, arguments) || this;
11634
+ function AWSAppSyncRealTimeProvider(options) {
11635
+ if (options === void 0) {
11636
+ options = {};
11637
+ }
11638
+
11639
+ var _this = _super.call(this, options) || this;
11628
11640
 
11629
11641
  _this.socketStatus = _constants__WEBPACK_IMPORTED_MODULE_10__["SOCKET_STATUS"].CLOSED;
11630
11642
  _this.keepAliveTimeout = _constants__WEBPACK_IMPORTED_MODULE_10__["DEFAULT_KEEP_ALIVE_TIMEOUT"];
11631
11643
  _this.subscriptionObserverMap = new Map();
11632
11644
  _this.promiseArray = [];
11645
+ _this.connectionStateMonitor = new _utils_ConnectionStateMonitor__WEBPACK_IMPORTED_MODULE_11__["ConnectionStateMonitor"](); // Monitor the connection state and pass changes along to Hub
11646
+
11647
+ _this.connectionStateMonitor.connectionStateObservable.subscribe(function (ConnectionState) {
11648
+ dispatchApiEvent(_index__WEBPACK_IMPORTED_MODULE_9__["CONNECTION_STATE_CHANGE"], {
11649
+ provider: _this,
11650
+ connectionState: ConnectionState
11651
+ }, "Connection state is " + ConnectionState);
11652
+ });
11653
+
11633
11654
  return _this;
11634
11655
  }
11635
11656
 
@@ -11679,6 +11700,9 @@ function (_super) {
11679
11700
  observer.error({
11680
11701
  errors: [__assign({}, new graphql__WEBPACK_IMPORTED_MODULE_1__["GraphQLError"](_index__WEBPACK_IMPORTED_MODULE_9__["CONTROL_MSG"].REALTIME_SUBSCRIPTION_INIT_ERROR + ": " + err))]
11681
11702
  });
11703
+
11704
+ _this.connectionStateMonitor.record(_utils_ConnectionStateMonitor__WEBPACK_IMPORTED_MODULE_11__["CONNECTION_CHANGE"].CLOSED);
11705
+
11682
11706
  observer.complete();
11683
11707
  });
11684
11708
 
@@ -11823,6 +11847,7 @@ function (_super) {
11823
11847
  case 3:
11824
11848
  _k.trys.push([3, 5,, 6]);
11825
11849
 
11850
+ this.connectionStateMonitor.record(_utils_ConnectionStateMonitor__WEBPACK_IMPORTED_MODULE_11__["CONNECTION_CHANGE"].OPENING_CONNECTION);
11826
11851
  return [4
11827
11852
  /*yield*/
11828
11853
  , this._initializeWebSocketConnection({
@@ -11846,6 +11871,7 @@ function (_super) {
11846
11871
  err: err_2
11847
11872
  });
11848
11873
  message = (_b = err_2['message']) !== null && _b !== void 0 ? _b : '';
11874
+ this.connectionStateMonitor.record(_utils_ConnectionStateMonitor__WEBPACK_IMPORTED_MODULE_11__["CONNECTION_CHANGE"].CLOSED);
11849
11875
  observer.error({
11850
11876
  errors: [__assign({}, new graphql__WEBPACK_IMPORTED_MODULE_1__["GraphQLError"](_index__WEBPACK_IMPORTED_MODULE_9__["CONTROL_MSG"].CONNECTION_FAILED + ": " + message))]
11851
11877
  });
@@ -11964,12 +11990,22 @@ function (_super) {
11964
11990
  return;
11965
11991
  }
11966
11992
 
11993
+ this.connectionStateMonitor.record(_utils_ConnectionStateMonitor__WEBPACK_IMPORTED_MODULE_11__["CONNECTION_CHANGE"].CLOSING_CONNECTION);
11994
+
11967
11995
  if (this.awsRealTimeSocket.bufferedAmount > 0) {
11968
11996
  // Still data on the WebSocket
11969
11997
  setTimeout(this._closeSocketIfRequired.bind(this), 1000);
11970
11998
  } else {
11971
11999
  logger.debug('closing WebSocket...');
11972
- if (this.keepAliveTimeoutId) clearTimeout(this.keepAliveTimeoutId);
12000
+
12001
+ if (this.keepAliveTimeoutId) {
12002
+ clearTimeout(this.keepAliveTimeoutId);
12003
+ }
12004
+
12005
+ if (this.keepAliveAlertTimeoutId) {
12006
+ clearTimeout(this.keepAliveAlertTimeoutId);
12007
+ }
12008
+
11973
12009
  var tempSocket = this.awsRealTimeSocket; // Cleaning callbacks to avoid race condition, socket still exists
11974
12010
 
11975
12011
  tempSocket.onclose = null;
@@ -11977,10 +12013,13 @@ function (_super) {
11977
12013
  tempSocket.close(1000);
11978
12014
  this.awsRealTimeSocket = undefined;
11979
12015
  this.socketStatus = _constants__WEBPACK_IMPORTED_MODULE_10__["SOCKET_STATUS"].CLOSED;
12016
+ this.connectionStateMonitor.record(_utils_ConnectionStateMonitor__WEBPACK_IMPORTED_MODULE_11__["CONNECTION_CHANGE"].CLOSED);
11980
12017
  }
11981
12018
  };
11982
12019
 
11983
12020
  AWSAppSyncRealTimeProvider.prototype._handleIncomingSubscriptionMessage = function (message) {
12021
+ var _this = this;
12022
+
11984
12023
  logger.debug("subscription message from AWS AppSync RealTime: " + message.data);
11985
12024
 
11986
12025
  var _a = JSON.parse(message.data),
@@ -12044,15 +12083,22 @@ function (_super) {
12044
12083
  subscriptionReadyCallback: subscriptionReadyCallback,
12045
12084
  subscriptionFailedCallback: subscriptionFailedCallback
12046
12085
  });
12047
- } // TODO: emit event on hub but it requires to store the id first
12048
-
12086
+ }
12049
12087
 
12088
+ this.connectionStateMonitor.record(_utils_ConnectionStateMonitor__WEBPACK_IMPORTED_MODULE_11__["CONNECTION_CHANGE"].CONNECTION_ESTABLISHED);
12050
12089
  return;
12051
12090
  }
12052
12091
 
12053
12092
  if (type === _constants__WEBPACK_IMPORTED_MODULE_10__["MESSAGE_TYPES"].GQL_CONNECTION_KEEP_ALIVE) {
12054
12093
  if (this.keepAliveTimeoutId) clearTimeout(this.keepAliveTimeoutId);
12055
- this.keepAliveTimeoutId = setTimeout(this._errorDisconnect.bind(this, _index__WEBPACK_IMPORTED_MODULE_9__["CONTROL_MSG"].TIMEOUT_DISCONNECT), this.keepAliveTimeout);
12094
+ if (this.keepAliveAlertTimeoutId) clearTimeout(this.keepAliveAlertTimeoutId);
12095
+ this.keepAliveTimeoutId = setTimeout(function () {
12096
+ return _this._errorDisconnect(_index__WEBPACK_IMPORTED_MODULE_9__["CONTROL_MSG"].TIMEOUT_DISCONNECT);
12097
+ }, this.keepAliveTimeout);
12098
+ this.keepAliveAlertTimeoutId = setTimeout(function () {
12099
+ _this.connectionStateMonitor.record(_utils_ConnectionStateMonitor__WEBPACK_IMPORTED_MODULE_11__["CONNECTION_CHANGE"].KEEP_ALIVE_MISSED);
12100
+ }, _constants__WEBPACK_IMPORTED_MODULE_10__["DEFAULT_KEEP_ALIVE_ALERT_TIMEOUT"]);
12101
+ this.connectionStateMonitor.record(_utils_ConnectionStateMonitor__WEBPACK_IMPORTED_MODULE_11__["CONNECTION_CHANGE"].KEEP_ALIVE);
12056
12102
  return;
12057
12103
  }
12058
12104
 
@@ -12096,6 +12142,7 @@ function (_super) {
12096
12142
  this.subscriptionObserverMap.clear();
12097
12143
 
12098
12144
  if (this.awsRealTimeSocket) {
12145
+ this.connectionStateMonitor.record(_utils_ConnectionStateMonitor__WEBPACK_IMPORTED_MODULE_11__["CONNECTION_CHANGE"].CLOSED);
12099
12146
  this.awsRealTimeSocket.close();
12100
12147
  }
12101
12148
 
@@ -12294,6 +12341,8 @@ function (_super) {
12294
12341
  };
12295
12342
 
12296
12343
  newSocket.onclose = function () {
12344
+ _this.connectionStateMonitor.record(_utils_ConnectionStateMonitor__WEBPACK_IMPORTED_MODULE_11__["CONNECTION_CHANGE"].CONNECTION_FAILED);
12345
+
12297
12346
  rej(new Error('Connection handshake error'));
12298
12347
  };
12299
12348
 
@@ -12385,6 +12434,7 @@ function (_super) {
12385
12434
 
12386
12435
  function checkAckOk(ackOk) {
12387
12436
  if (!ackOk) {
12437
+ this.connectionStateMonitor.record(_utils_ConnectionStateMonitor__WEBPACK_IMPORTED_MODULE_11__["CONNECTION_CHANGE"].CONNECTION_FAILED);
12388
12438
  rej(new Error("Connection timeout: ack from AWSRealTime was not received on " + _constants__WEBPACK_IMPORTED_MODULE_10__["CONNECTION_INIT_TIMEOUT"] + " ms"));
12389
12439
  }
12390
12440
  }
@@ -14157,11 +14207,12 @@ _aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__["Amplify"].register(PubSub);
14157
14207
  /*!**********************************!*\
14158
14208
  !*** ../pubsub/lib-esm/index.js ***!
14159
14209
  \**********************************/
14160
- /*! exports provided: AbstractPubSubProvider, AWSAppSyncProvider, AWSAppSyncRealTimeProvider, AWSIoTProvider, mqttTopicMatch, MqttOverWSProvider, PubSub, CONTROL_MSG, default */
14210
+ /*! exports provided: AbstractPubSubProvider, AWSAppSyncProvider, AWSAppSyncRealTimeProvider, AWSIoTProvider, mqttTopicMatch, MqttOverWSProvider, CONNECTION_STATE_CHANGE, ConnectionState, PubSub, CONTROL_MSG, default */
14161
14211
  /***/ (function(module, __webpack_exports__, __webpack_require__) {
14162
14212
 
14163
14213
  "use strict";
14164
14214
  __webpack_require__.r(__webpack_exports__);
14215
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "CONNECTION_STATE_CHANGE", function() { return CONNECTION_STATE_CHANGE; });
14165
14216
  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "CONTROL_MSG", function() { return CONTROL_MSG; });
14166
14217
  /* harmony import */ var _PubSub__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./PubSub */ "../pubsub/lib-esm/PubSub.js");
14167
14218
  /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "PubSub", function() { return _PubSub__WEBPACK_IMPORTED_MODULE_0__["PubSub"]; });
@@ -14179,6 +14230,9 @@ __webpack_require__.r(__webpack_exports__);
14179
14230
 
14180
14231
  /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MqttOverWSProvider", function() { return _Providers__WEBPACK_IMPORTED_MODULE_1__["MqttOverWSProvider"]; });
14181
14232
 
14233
+ /* harmony import */ var _types__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./types */ "../pubsub/lib-esm/types/index.js");
14234
+ /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "ConnectionState", function() { return _types__WEBPACK_IMPORTED_MODULE_2__["ConnectionState"]; });
14235
+
14182
14236
  /*
14183
14237
  * Copyright 2017-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
14184
14238
  *
@@ -14203,6 +14257,8 @@ var CONTROL_MSG;
14203
14257
  CONTROL_MSG["TIMEOUT_DISCONNECT"] = "Timeout disconnect";
14204
14258
  })(CONTROL_MSG || (CONTROL_MSG = {}));
14205
14259
 
14260
+ var CONNECTION_STATE_CHANGE = 'ConnectionStateChange';
14261
+
14206
14262
 
14207
14263
  /**
14208
14264
  * @deprecated use named import
@@ -14210,6 +14266,260 @@ var CONTROL_MSG;
14210
14266
 
14211
14267
  /* harmony default export */ __webpack_exports__["default"] = (_PubSub__WEBPACK_IMPORTED_MODULE_0__["PubSub"]);
14212
14268
 
14269
+ /***/ }),
14270
+
14271
+ /***/ "../pubsub/lib-esm/types/index.js":
14272
+ /*!****************************************!*\
14273
+ !*** ../pubsub/lib-esm/types/index.js ***!
14274
+ \****************************************/
14275
+ /*! exports provided: ConnectionState */
14276
+ /***/ (function(module, __webpack_exports__, __webpack_require__) {
14277
+
14278
+ "use strict";
14279
+ __webpack_require__.r(__webpack_exports__);
14280
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "ConnectionState", function() { return ConnectionState; });
14281
+ /** @enum {string} */
14282
+ var ConnectionState;
14283
+
14284
+ (function (ConnectionState) {
14285
+ /*
14286
+ * The connection is alive and healthy
14287
+ */
14288
+ ConnectionState["Connected"] = "Connected";
14289
+ /*
14290
+ * The connection is alive, but the connection is offline
14291
+ */
14292
+
14293
+ ConnectionState["ConnectedPendingNetwork"] = "ConnectedPendingNetwork";
14294
+ /*
14295
+ * The connection has been disconnected while in use
14296
+ */
14297
+
14298
+ ConnectionState["ConnectionDisrupted"] = "ConnectionDisrupted";
14299
+ /*
14300
+ * The connection has been disconnected and the network is offline
14301
+ */
14302
+
14303
+ ConnectionState["ConnectionDisruptedPendingNetwork"] = "ConnectionDisruptedPendingNetwork";
14304
+ /*
14305
+ * The connection is in the process of connecting
14306
+ */
14307
+
14308
+ ConnectionState["Connecting"] = "Connecting";
14309
+ /*
14310
+ * The connection is not in use and is being disconnected
14311
+ */
14312
+
14313
+ ConnectionState["ConnectedPendingDisconnect"] = "ConnectedPendingDisconnect";
14314
+ /*
14315
+ * The connection is not in use and has been disconnected
14316
+ */
14317
+
14318
+ ConnectionState["Disconnected"] = "Disconnected";
14319
+ /*
14320
+ * The connection is alive, but a keep alive message has been missed
14321
+ */
14322
+
14323
+ ConnectionState["ConnectedPendingKeepAlive"] = "ConnectedPendingKeepAlive";
14324
+ })(ConnectionState || (ConnectionState = {}));
14325
+
14326
+ /***/ }),
14327
+
14328
+ /***/ "../pubsub/lib-esm/utils/ConnectionStateMonitor.js":
14329
+ /*!*********************************************************!*\
14330
+ !*** ../pubsub/lib-esm/utils/ConnectionStateMonitor.js ***!
14331
+ \*********************************************************/
14332
+ /*! exports provided: CONNECTION_CHANGE, ConnectionStateMonitor */
14333
+ /***/ (function(module, __webpack_exports__, __webpack_require__) {
14334
+
14335
+ "use strict";
14336
+ __webpack_require__.r(__webpack_exports__);
14337
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "CONNECTION_CHANGE", function() { return CONNECTION_CHANGE; });
14338
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "ConnectionStateMonitor", function() { return ConnectionStateMonitor; });
14339
+ /* harmony import */ var _aws_amplify_core__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @aws-amplify/core */ "@aws-amplify/core");
14340
+ /* harmony import */ var _aws_amplify_core__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_aws_amplify_core__WEBPACK_IMPORTED_MODULE_0__);
14341
+ /* harmony import */ var zen_observable_ts__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! zen-observable-ts */ "../../node_modules/zen-observable-ts/lib/bundle.esm.js");
14342
+ /* harmony import */ var _index__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../index */ "../pubsub/lib-esm/index.js");
14343
+ /*
14344
+ * Copyright 2017-2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
14345
+ *
14346
+ * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
14347
+ * the License. A copy of the License is located at
14348
+ *
14349
+ * http://aws.amazon.com/apache2.0/
14350
+ *
14351
+ * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
14352
+ * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
14353
+ * and limitations under the License.
14354
+ */
14355
+ var __assign = undefined && undefined.__assign || function () {
14356
+ __assign = Object.assign || function (t) {
14357
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
14358
+ s = arguments[i];
14359
+
14360
+ for (var p in s) {
14361
+ if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
14362
+ }
14363
+ }
14364
+
14365
+ return t;
14366
+ };
14367
+
14368
+ return __assign.apply(this, arguments);
14369
+ };
14370
+
14371
+
14372
+
14373
+
14374
+ var CONNECTION_CHANGE = {
14375
+ KEEP_ALIVE_MISSED: {
14376
+ keepAliveState: 'unhealthy'
14377
+ },
14378
+ KEEP_ALIVE: {
14379
+ keepAliveState: 'healthy'
14380
+ },
14381
+ CONNECTION_ESTABLISHED: {
14382
+ connectionState: 'connected'
14383
+ },
14384
+ CONNECTION_FAILED: {
14385
+ intendedConnectionState: 'disconnected',
14386
+ connectionState: 'disconnected'
14387
+ },
14388
+ CLOSING_CONNECTION: {
14389
+ intendedConnectionState: 'disconnected'
14390
+ },
14391
+ OPENING_CONNECTION: {
14392
+ intendedConnectionState: 'connected',
14393
+ connectionState: 'connecting'
14394
+ },
14395
+ CLOSED: {
14396
+ connectionState: 'disconnected'
14397
+ },
14398
+ ONLINE: {
14399
+ networkState: 'connected'
14400
+ },
14401
+ OFFLINE: {
14402
+ networkState: 'disconnected'
14403
+ }
14404
+ };
14405
+
14406
+ var ConnectionStateMonitor =
14407
+ /** @class */
14408
+ function () {
14409
+ function ConnectionStateMonitor() {
14410
+ var _this = this;
14411
+
14412
+ this._networkMonitoringSubscription = undefined;
14413
+ this._linkedConnectionState = {
14414
+ networkState: 'connected',
14415
+ connectionState: 'disconnected',
14416
+ intendedConnectionState: 'disconnected',
14417
+ keepAliveState: 'healthy'
14418
+ };
14419
+ this._linkedConnectionStateObservable = new zen_observable_ts__WEBPACK_IMPORTED_MODULE_1__["default"](function (connectionStateObserver) {
14420
+ connectionStateObserver.next(_this._linkedConnectionState);
14421
+ _this._linkedConnectionStateObserver = connectionStateObserver;
14422
+ });
14423
+ }
14424
+ /**
14425
+ * Turn network state monitoring on if it isn't on already
14426
+ */
14427
+
14428
+
14429
+ ConnectionStateMonitor.prototype.enableNetworkMonitoring = function () {
14430
+ var _this = this; // Maintain the network state based on the reachability monitor
14431
+
14432
+
14433
+ if (this._networkMonitoringSubscription === undefined) {
14434
+ this._networkMonitoringSubscription = new _aws_amplify_core__WEBPACK_IMPORTED_MODULE_0__["Reachability"]().networkMonitor().subscribe(function (_a) {
14435
+ var online = _a.online;
14436
+
14437
+ _this.record(online ? CONNECTION_CHANGE.ONLINE : CONNECTION_CHANGE.OFFLINE);
14438
+ });
14439
+ }
14440
+ };
14441
+ /**
14442
+ * Turn network state monitoring off if it isn't off already
14443
+ */
14444
+
14445
+
14446
+ ConnectionStateMonitor.prototype.disableNetworkMonitoring = function () {
14447
+ var _a;
14448
+
14449
+ (_a = this._networkMonitoringSubscription) === null || _a === void 0 ? void 0 : _a.unsubscribe();
14450
+ this._networkMonitoringSubscription = undefined;
14451
+ };
14452
+
14453
+ Object.defineProperty(ConnectionStateMonitor.prototype, "connectionStateObservable", {
14454
+ /**
14455
+ * Get the observable that allows us to monitor the connection state
14456
+ *
14457
+ * @returns {Observable<ConnectionState>} - The observable that emits ConnectionState updates
14458
+ */
14459
+ get: function get() {
14460
+ var _this = this;
14461
+
14462
+ var previous; // The linked state aggregates state changes to any of the network, connection,
14463
+ // intendedConnection and keepAliveHealth. Some states will change these independent
14464
+ // states without changing the overall connection state.
14465
+ // After translating from linked states to ConnectionState, then remove any duplicates
14466
+
14467
+ return this._linkedConnectionStateObservable.map(function (value) {
14468
+ return _this.connectionStatesTranslator(value);
14469
+ }).filter(function (current) {
14470
+ var toInclude = current !== previous;
14471
+ previous = current;
14472
+ return toInclude;
14473
+ });
14474
+ },
14475
+ enumerable: true,
14476
+ configurable: true
14477
+ });
14478
+ /*
14479
+ * Updates local connection state and emits the full state to the observer.
14480
+ */
14481
+
14482
+ ConnectionStateMonitor.prototype.record = function (statusUpdates) {
14483
+ // Maintain the network monitor
14484
+ if (statusUpdates.intendedConnectionState === 'connected') {
14485
+ this.enableNetworkMonitoring();
14486
+ } else if (statusUpdates.intendedConnectionState === 'disconnected') {
14487
+ this.disableNetworkMonitoring();
14488
+ } // Maintain the socket state
14489
+
14490
+
14491
+ var newSocketStatus = __assign(__assign({}, this._linkedConnectionState), statusUpdates);
14492
+
14493
+ this._linkedConnectionState = __assign({}, newSocketStatus);
14494
+
14495
+ this._linkedConnectionStateObserver.next(this._linkedConnectionState);
14496
+ };
14497
+ /*
14498
+ * Translate the ConnectionState structure into a specific ConnectionState string literal union
14499
+ */
14500
+
14501
+
14502
+ ConnectionStateMonitor.prototype.connectionStatesTranslator = function (_a) {
14503
+ var connectionState = _a.connectionState,
14504
+ networkState = _a.networkState,
14505
+ intendedConnectionState = _a.intendedConnectionState,
14506
+ keepAliveState = _a.keepAliveState;
14507
+ if (connectionState === 'connected' && networkState === 'disconnected') return _index__WEBPACK_IMPORTED_MODULE_2__["ConnectionState"].ConnectedPendingNetwork;
14508
+ if (connectionState === 'connected' && intendedConnectionState === 'disconnected') return _index__WEBPACK_IMPORTED_MODULE_2__["ConnectionState"].ConnectedPendingDisconnect;
14509
+ if (connectionState === 'disconnected' && intendedConnectionState === 'connected' && networkState === 'disconnected') return _index__WEBPACK_IMPORTED_MODULE_2__["ConnectionState"].ConnectionDisruptedPendingNetwork;
14510
+ if (connectionState === 'disconnected' && intendedConnectionState === 'connected') return _index__WEBPACK_IMPORTED_MODULE_2__["ConnectionState"].ConnectionDisrupted;
14511
+ if (connectionState === 'connected' && keepAliveState === 'unhealthy') return _index__WEBPACK_IMPORTED_MODULE_2__["ConnectionState"].ConnectedPendingKeepAlive; // All remaining states directly correspond to the connection state
14512
+
14513
+ if (connectionState === 'connecting') return _index__WEBPACK_IMPORTED_MODULE_2__["ConnectionState"].Connecting;
14514
+ if (connectionState === 'disconnected') return _index__WEBPACK_IMPORTED_MODULE_2__["ConnectionState"].Disconnected;
14515
+ return _index__WEBPACK_IMPORTED_MODULE_2__["ConnectionState"].Connected;
14516
+ };
14517
+
14518
+ return ConnectionStateMonitor;
14519
+ }();
14520
+
14521
+
14522
+
14213
14523
  /***/ }),
14214
14524
 
14215
14525
  /***/ "./lib-esm/GraphQLAPI.js":