@aws-amplify/api-graphql 2.2.19-custom-pk.97 → 2.2.19-custom-pk.156

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.
@@ -11214,131 +11214,6 @@ function (_super) {
11214
11214
 
11215
11215
 
11216
11216
 
11217
- /***/ }),
11218
-
11219
- /***/ "../pubsub/lib-esm/Providers/AWSAppSyncRealTimeProvider/constants.js":
11220
- /*!***************************************************************************!*\
11221
- !*** ../pubsub/lib-esm/Providers/AWSAppSyncRealTimeProvider/constants.js ***!
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 */
11224
- /***/ (function(module, __webpack_exports__, __webpack_require__) {
11225
-
11226
- "use strict";
11227
- __webpack_require__.r(__webpack_exports__);
11228
- /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "MAX_DELAY_MS", function() { return MAX_DELAY_MS; });
11229
- /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "NON_RETRYABLE_CODES", function() { return NON_RETRYABLE_CODES; });
11230
- /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "MESSAGE_TYPES", function() { return MESSAGE_TYPES; });
11231
- /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "SUBSCRIPTION_STATUS", function() { return SUBSCRIPTION_STATUS; });
11232
- /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "SOCKET_STATUS", function() { return SOCKET_STATUS; });
11233
- /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "AMPLIFY_SYMBOL", function() { return AMPLIFY_SYMBOL; });
11234
- /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "AWS_APPSYNC_REALTIME_HEADERS", function() { return AWS_APPSYNC_REALTIME_HEADERS; });
11235
- /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "CONNECTION_INIT_TIMEOUT", function() { return CONNECTION_INIT_TIMEOUT; });
11236
- /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "START_ACK_TIMEOUT", function() { return START_ACK_TIMEOUT; });
11237
- /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "DEFAULT_KEEP_ALIVE_TIMEOUT", function() { return DEFAULT_KEEP_ALIVE_TIMEOUT; });
11238
- var MAX_DELAY_MS = 5000;
11239
- var NON_RETRYABLE_CODES = [400, 401, 403];
11240
- var MESSAGE_TYPES;
11241
-
11242
- (function (MESSAGE_TYPES) {
11243
- /**
11244
- * Client -> Server message.
11245
- * This message type is the first message after handshake and this will initialize AWS AppSync RealTime communication
11246
- */
11247
- MESSAGE_TYPES["GQL_CONNECTION_INIT"] = "connection_init";
11248
- /**
11249
- * Server -> Client message
11250
- * This message type is in case there is an issue with AWS AppSync RealTime when establishing connection
11251
- */
11252
-
11253
- MESSAGE_TYPES["GQL_CONNECTION_ERROR"] = "connection_error";
11254
- /**
11255
- * Server -> Client message.
11256
- * This message type is for the ack response from AWS AppSync RealTime for GQL_CONNECTION_INIT message
11257
- */
11258
-
11259
- MESSAGE_TYPES["GQL_CONNECTION_ACK"] = "connection_ack";
11260
- /**
11261
- * Client -> Server message.
11262
- * This message type is for register subscriptions with AWS AppSync RealTime
11263
- */
11264
-
11265
- MESSAGE_TYPES["GQL_START"] = "start";
11266
- /**
11267
- * Server -> Client message.
11268
- * This message type is for the ack response from AWS AppSync RealTime for GQL_START message
11269
- */
11270
-
11271
- MESSAGE_TYPES["GQL_START_ACK"] = "start_ack";
11272
- /**
11273
- * Server -> Client message.
11274
- * This message type is for subscription message from AWS AppSync RealTime
11275
- */
11276
-
11277
- MESSAGE_TYPES["GQL_DATA"] = "data";
11278
- /**
11279
- * Server -> Client message.
11280
- * This message type helps the client to know is still receiving messages from AWS AppSync RealTime
11281
- */
11282
-
11283
- MESSAGE_TYPES["GQL_CONNECTION_KEEP_ALIVE"] = "ka";
11284
- /**
11285
- * Client -> Server message.
11286
- * This message type is for unregister subscriptions with AWS AppSync RealTime
11287
- */
11288
-
11289
- MESSAGE_TYPES["GQL_STOP"] = "stop";
11290
- /**
11291
- * Server -> Client message.
11292
- * This message type is for the ack response from AWS AppSync RealTime for GQL_STOP message
11293
- */
11294
-
11295
- MESSAGE_TYPES["GQL_COMPLETE"] = "complete";
11296
- /**
11297
- * Server -> Client message.
11298
- * This message type is for sending error messages from AWS AppSync RealTime to the client
11299
- */
11300
-
11301
- MESSAGE_TYPES["GQL_ERROR"] = "error";
11302
- })(MESSAGE_TYPES || (MESSAGE_TYPES = {}));
11303
-
11304
- var SUBSCRIPTION_STATUS;
11305
-
11306
- (function (SUBSCRIPTION_STATUS) {
11307
- SUBSCRIPTION_STATUS[SUBSCRIPTION_STATUS["PENDING"] = 0] = "PENDING";
11308
- SUBSCRIPTION_STATUS[SUBSCRIPTION_STATUS["CONNECTED"] = 1] = "CONNECTED";
11309
- SUBSCRIPTION_STATUS[SUBSCRIPTION_STATUS["FAILED"] = 2] = "FAILED";
11310
- })(SUBSCRIPTION_STATUS || (SUBSCRIPTION_STATUS = {}));
11311
-
11312
- var SOCKET_STATUS;
11313
-
11314
- (function (SOCKET_STATUS) {
11315
- SOCKET_STATUS[SOCKET_STATUS["CLOSED"] = 0] = "CLOSED";
11316
- SOCKET_STATUS[SOCKET_STATUS["READY"] = 1] = "READY";
11317
- SOCKET_STATUS[SOCKET_STATUS["CONNECTING"] = 2] = "CONNECTING";
11318
- })(SOCKET_STATUS || (SOCKET_STATUS = {}));
11319
-
11320
- var AMPLIFY_SYMBOL = typeof Symbol !== 'undefined' && typeof Symbol["for"] === 'function' ? Symbol["for"]('amplify_default') : '@@amplify_default';
11321
- var AWS_APPSYNC_REALTIME_HEADERS = {
11322
- accept: 'application/json, text/javascript',
11323
- 'content-encoding': 'amz-1.0',
11324
- 'content-type': 'application/json; charset=UTF-8'
11325
- };
11326
- /**
11327
- * Time in milleseconds to wait for GQL_CONNECTION_INIT message
11328
- */
11329
-
11330
- var CONNECTION_INIT_TIMEOUT = 15000;
11331
- /**
11332
- * Time in milleseconds to wait for GQL_START_ACK message
11333
- */
11334
-
11335
- var START_ACK_TIMEOUT = 15000;
11336
- /**
11337
- * Default Time in milleseconds to wait for GQL_CONNECTION_KEEP_ALIVE message
11338
- */
11339
-
11340
- var DEFAULT_KEEP_ALIVE_TIMEOUT = 5 * 60 * 1000;
11341
-
11342
11217
  /***/ }),
11343
11218
 
11344
11219
  /***/ "../pubsub/lib-esm/Providers/AWSAppSyncRealTimeProvider/index.js":
@@ -11367,8 +11242,9 @@ __webpack_require__.r(__webpack_exports__);
11367
11242
  /* harmony import */ var _aws_amplify_auth__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! @aws-amplify/auth */ "@aws-amplify/auth");
11368
11243
  /* harmony import */ var _aws_amplify_auth__WEBPACK_IMPORTED_MODULE_7___default = /*#__PURE__*/__webpack_require__.n(_aws_amplify_auth__WEBPACK_IMPORTED_MODULE_7__);
11369
11244
  /* harmony import */ var _PubSubProvider__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ../PubSubProvider */ "../pubsub/lib-esm/Providers/PubSubProvider.js");
11370
- /* harmony import */ var _index__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ../../index */ "../pubsub/lib-esm/index.js");
11371
- /* harmony import */ var _constants__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ./constants */ "../pubsub/lib-esm/Providers/AWSAppSyncRealTimeProvider/constants.js");
11245
+ /* harmony import */ var _types_PubSub__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ../../types/PubSub */ "../pubsub/lib-esm/types/PubSub.js");
11246
+ /* harmony import */ var _constants__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ../constants */ "../pubsub/lib-esm/Providers/constants.js");
11247
+ /* harmony import */ var _utils_ConnectionStateMonitor__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(/*! ../../utils/ConnectionStateMonitor */ "../pubsub/lib-esm/utils/ConnectionStateMonitor.js");
11372
11248
  var __extends = undefined && undefined.__extends || function () {
11373
11249
  var _extendStatics = function extendStatics(d, b) {
11374
11250
  _extendStatics = Object.setPrototypeOf || {
@@ -11605,6 +11481,7 @@ var __read = undefined && undefined.__read || function (o, n) {
11605
11481
 
11606
11482
 
11607
11483
 
11484
+
11608
11485
  var logger = new _aws_amplify_core__WEBPACK_IMPORTED_MODULE_5__["Logger"]('AWSAppSyncRealTimeProvider');
11609
11486
 
11610
11487
  var dispatchApiEvent = function dispatchApiEvent(event, data, message) {
@@ -11623,13 +11500,26 @@ var AWSAppSyncRealTimeProvider =
11623
11500
  function (_super) {
11624
11501
  __extends(AWSAppSyncRealTimeProvider, _super);
11625
11502
 
11626
- function AWSAppSyncRealTimeProvider() {
11627
- var _this = _super !== null && _super.apply(this, arguments) || this;
11503
+ function AWSAppSyncRealTimeProvider(options) {
11504
+ if (options === void 0) {
11505
+ options = {};
11506
+ }
11507
+
11508
+ var _this = _super.call(this, options) || this;
11628
11509
 
11629
11510
  _this.socketStatus = _constants__WEBPACK_IMPORTED_MODULE_10__["SOCKET_STATUS"].CLOSED;
11630
11511
  _this.keepAliveTimeout = _constants__WEBPACK_IMPORTED_MODULE_10__["DEFAULT_KEEP_ALIVE_TIMEOUT"];
11631
11512
  _this.subscriptionObserverMap = new Map();
11632
11513
  _this.promiseArray = [];
11514
+ _this.connectionStateMonitor = new _utils_ConnectionStateMonitor__WEBPACK_IMPORTED_MODULE_11__["ConnectionStateMonitor"](); // Monitor the connection state and pass changes along to Hub
11515
+
11516
+ _this.connectionStateMonitor.connectionStateObservable.subscribe(function (ConnectionState) {
11517
+ dispatchApiEvent(_constants__WEBPACK_IMPORTED_MODULE_10__["CONNECTION_STATE_CHANGE"], {
11518
+ provider: _this,
11519
+ connectionState: ConnectionState
11520
+ }, "Connection state is " + ConnectionState);
11521
+ });
11522
+
11633
11523
  return _this;
11634
11524
  }
11635
11525
 
@@ -11677,8 +11567,11 @@ function (_super) {
11677
11567
  subscriptionId: subscriptionId_1
11678
11568
  })["catch"](function (err) {
11679
11569
  observer.error({
11680
- errors: [__assign({}, new graphql__WEBPACK_IMPORTED_MODULE_1__["GraphQLError"](_index__WEBPACK_IMPORTED_MODULE_9__["CONTROL_MSG"].REALTIME_SUBSCRIPTION_INIT_ERROR + ": " + err))]
11570
+ errors: [__assign({}, new graphql__WEBPACK_IMPORTED_MODULE_1__["GraphQLError"](_types_PubSub__WEBPACK_IMPORTED_MODULE_9__["CONTROL_MSG"].REALTIME_SUBSCRIPTION_INIT_ERROR + ": " + err))]
11681
11571
  });
11572
+
11573
+ _this.connectionStateMonitor.record(_utils_ConnectionStateMonitor__WEBPACK_IMPORTED_MODULE_11__["CONNECTION_CHANGE"].CLOSED);
11574
+
11682
11575
  observer.complete();
11683
11576
  });
11684
11577
 
@@ -11823,6 +11716,7 @@ function (_super) {
11823
11716
  case 3:
11824
11717
  _k.trys.push([3, 5,, 6]);
11825
11718
 
11719
+ this.connectionStateMonitor.record(_utils_ConnectionStateMonitor__WEBPACK_IMPORTED_MODULE_11__["CONNECTION_CHANGE"].OPENING_CONNECTION);
11826
11720
  return [4
11827
11721
  /*yield*/
11828
11722
  , this._initializeWebSocketConnection({
@@ -11846,8 +11740,9 @@ function (_super) {
11846
11740
  err: err_2
11847
11741
  });
11848
11742
  message = (_b = err_2['message']) !== null && _b !== void 0 ? _b : '';
11743
+ this.connectionStateMonitor.record(_utils_ConnectionStateMonitor__WEBPACK_IMPORTED_MODULE_11__["CONNECTION_CHANGE"].CLOSED);
11849
11744
  observer.error({
11850
- errors: [__assign({}, new graphql__WEBPACK_IMPORTED_MODULE_1__["GraphQLError"](_index__WEBPACK_IMPORTED_MODULE_9__["CONTROL_MSG"].CONNECTION_FAILED + ": " + message))]
11745
+ errors: [__assign({}, new graphql__WEBPACK_IMPORTED_MODULE_1__["GraphQLError"](_types_PubSub__WEBPACK_IMPORTED_MODULE_9__["CONTROL_MSG"].CONNECTION_FAILED + ": " + message))]
11851
11746
  });
11852
11747
  observer.complete();
11853
11748
  subscriptionFailedCallback_1 = (this.subscriptionObserverMap.get(subscriptionId) || {}).subscriptionFailedCallback; // Notify concurrent unsubscription
@@ -11964,12 +11859,22 @@ function (_super) {
11964
11859
  return;
11965
11860
  }
11966
11861
 
11862
+ this.connectionStateMonitor.record(_utils_ConnectionStateMonitor__WEBPACK_IMPORTED_MODULE_11__["CONNECTION_CHANGE"].CLOSING_CONNECTION);
11863
+
11967
11864
  if (this.awsRealTimeSocket.bufferedAmount > 0) {
11968
11865
  // Still data on the WebSocket
11969
11866
  setTimeout(this._closeSocketIfRequired.bind(this), 1000);
11970
11867
  } else {
11971
11868
  logger.debug('closing WebSocket...');
11972
- if (this.keepAliveTimeoutId) clearTimeout(this.keepAliveTimeoutId);
11869
+
11870
+ if (this.keepAliveTimeoutId) {
11871
+ clearTimeout(this.keepAliveTimeoutId);
11872
+ }
11873
+
11874
+ if (this.keepAliveAlertTimeoutId) {
11875
+ clearTimeout(this.keepAliveAlertTimeoutId);
11876
+ }
11877
+
11973
11878
  var tempSocket = this.awsRealTimeSocket; // Cleaning callbacks to avoid race condition, socket still exists
11974
11879
 
11975
11880
  tempSocket.onclose = null;
@@ -11977,10 +11882,13 @@ function (_super) {
11977
11882
  tempSocket.close(1000);
11978
11883
  this.awsRealTimeSocket = undefined;
11979
11884
  this.socketStatus = _constants__WEBPACK_IMPORTED_MODULE_10__["SOCKET_STATUS"].CLOSED;
11885
+ this.connectionStateMonitor.record(_utils_ConnectionStateMonitor__WEBPACK_IMPORTED_MODULE_11__["CONNECTION_CHANGE"].CLOSED);
11980
11886
  }
11981
11887
  };
11982
11888
 
11983
11889
  AWSAppSyncRealTimeProvider.prototype._handleIncomingSubscriptionMessage = function (message) {
11890
+ var _this = this;
11891
+
11984
11892
  logger.debug("subscription message from AWS AppSync RealTime: " + message.data);
11985
11893
 
11986
11894
  var _a = JSON.parse(message.data),
@@ -12028,7 +11936,7 @@ function (_super) {
12028
11936
  }
12029
11937
 
12030
11938
  if (startAckTimeoutId) clearTimeout(startAckTimeoutId);
12031
- dispatchApiEvent(_index__WEBPACK_IMPORTED_MODULE_9__["CONTROL_MSG"].SUBSCRIPTION_ACK, {
11939
+ dispatchApiEvent(_types_PubSub__WEBPACK_IMPORTED_MODULE_9__["CONTROL_MSG"].SUBSCRIPTION_ACK, {
12032
11940
  query: query,
12033
11941
  variables: variables
12034
11942
  }, 'Connection established for subscription');
@@ -12044,15 +11952,22 @@ function (_super) {
12044
11952
  subscriptionReadyCallback: subscriptionReadyCallback,
12045
11953
  subscriptionFailedCallback: subscriptionFailedCallback
12046
11954
  });
12047
- } // TODO: emit event on hub but it requires to store the id first
12048
-
11955
+ }
12049
11956
 
11957
+ this.connectionStateMonitor.record(_utils_ConnectionStateMonitor__WEBPACK_IMPORTED_MODULE_11__["CONNECTION_CHANGE"].CONNECTION_ESTABLISHED);
12050
11958
  return;
12051
11959
  }
12052
11960
 
12053
11961
  if (type === _constants__WEBPACK_IMPORTED_MODULE_10__["MESSAGE_TYPES"].GQL_CONNECTION_KEEP_ALIVE) {
12054
11962
  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);
11963
+ if (this.keepAliveAlertTimeoutId) clearTimeout(this.keepAliveAlertTimeoutId);
11964
+ this.keepAliveTimeoutId = setTimeout(function () {
11965
+ return _this._errorDisconnect(_types_PubSub__WEBPACK_IMPORTED_MODULE_9__["CONTROL_MSG"].TIMEOUT_DISCONNECT);
11966
+ }, this.keepAliveTimeout);
11967
+ this.keepAliveAlertTimeoutId = setTimeout(function () {
11968
+ _this.connectionStateMonitor.record(_utils_ConnectionStateMonitor__WEBPACK_IMPORTED_MODULE_11__["CONNECTION_CHANGE"].KEEP_ALIVE_MISSED);
11969
+ }, _constants__WEBPACK_IMPORTED_MODULE_10__["DEFAULT_KEEP_ALIVE_ALERT_TIMEOUT"]);
11970
+ this.connectionStateMonitor.record(_utils_ConnectionStateMonitor__WEBPACK_IMPORTED_MODULE_11__["CONNECTION_CHANGE"].KEEP_ALIVE);
12056
11971
  return;
12057
11972
  }
12058
11973
 
@@ -12070,7 +11985,7 @@ function (_super) {
12070
11985
  subscriptionState: subscriptionState
12071
11986
  });
12072
11987
  observer.error({
12073
- errors: [__assign({}, new graphql__WEBPACK_IMPORTED_MODULE_1__["GraphQLError"](_index__WEBPACK_IMPORTED_MODULE_9__["CONTROL_MSG"].CONNECTION_FAILED + ": " + JSON.stringify(payload)))]
11988
+ errors: [__assign({}, new graphql__WEBPACK_IMPORTED_MODULE_1__["GraphQLError"](_types_PubSub__WEBPACK_IMPORTED_MODULE_9__["CONTROL_MSG"].CONNECTION_FAILED + ": " + JSON.stringify(payload)))]
12074
11989
  });
12075
11990
  if (startAckTimeoutId) clearTimeout(startAckTimeoutId);
12076
11991
  observer.complete();
@@ -12096,6 +12011,7 @@ function (_super) {
12096
12011
  this.subscriptionObserverMap.clear();
12097
12012
 
12098
12013
  if (this.awsRealTimeSocket) {
12014
+ this.connectionStateMonitor.record(_utils_ConnectionStateMonitor__WEBPACK_IMPORTED_MODULE_11__["CONNECTION_CHANGE"].CLOSED);
12099
12015
  this.awsRealTimeSocket.close();
12100
12016
  }
12101
12017
 
@@ -12294,6 +12210,8 @@ function (_super) {
12294
12210
  };
12295
12211
 
12296
12212
  newSocket.onclose = function () {
12213
+ _this.connectionStateMonitor.record(_utils_ConnectionStateMonitor__WEBPACK_IMPORTED_MODULE_11__["CONNECTION_CHANGE"].CONNECTION_FAILED);
12214
+
12297
12215
  rej(new Error('Connection handshake error'));
12298
12216
  };
12299
12217
 
@@ -12342,13 +12260,13 @@ function (_super) {
12342
12260
  _this.awsRealTimeSocket.onerror = function (err) {
12343
12261
  logger.debug(err);
12344
12262
 
12345
- _this._errorDisconnect(_index__WEBPACK_IMPORTED_MODULE_9__["CONTROL_MSG"].CONNECTION_CLOSED);
12263
+ _this._errorDisconnect(_types_PubSub__WEBPACK_IMPORTED_MODULE_9__["CONTROL_MSG"].CONNECTION_CLOSED);
12346
12264
  };
12347
12265
 
12348
12266
  _this.awsRealTimeSocket.onclose = function (event) {
12349
12267
  logger.debug("WebSocket closed " + event.reason);
12350
12268
 
12351
- _this._errorDisconnect(_index__WEBPACK_IMPORTED_MODULE_9__["CONTROL_MSG"].CONNECTION_CLOSED);
12269
+ _this._errorDisconnect(_types_PubSub__WEBPACK_IMPORTED_MODULE_9__["CONTROL_MSG"].CONNECTION_CLOSED);
12352
12270
  };
12353
12271
  }
12354
12272
 
@@ -12380,13 +12298,17 @@ function (_super) {
12380
12298
 
12381
12299
  _this.awsRealTimeSocket.send(JSON.stringify(gqlInit));
12382
12300
 
12383
- setTimeout(checkAckOk.bind(_this, ackOk_1), _constants__WEBPACK_IMPORTED_MODULE_10__["CONNECTION_INIT_TIMEOUT"]);
12384
- }
12301
+ var checkAckOk_1 = function checkAckOk_1(ackOk) {
12302
+ if (!ackOk) {
12303
+ _this.connectionStateMonitor.record(_utils_ConnectionStateMonitor__WEBPACK_IMPORTED_MODULE_11__["CONNECTION_CHANGE"].CONNECTION_FAILED);
12385
12304
 
12386
- function checkAckOk(ackOk) {
12387
- if (!ackOk) {
12388
- rej(new Error("Connection timeout: ack from AWSRealTime was not received on " + _constants__WEBPACK_IMPORTED_MODULE_10__["CONNECTION_INIT_TIMEOUT"] + " ms"));
12389
- }
12305
+ rej(new Error("Connection timeout: ack from AWSAppSyncRealTime was not received after " + _constants__WEBPACK_IMPORTED_MODULE_10__["CONNECTION_INIT_TIMEOUT"] + " ms"));
12306
+ }
12307
+ };
12308
+
12309
+ setTimeout(function () {
12310
+ return checkAckOk_1(ackOk_1);
12311
+ }, _constants__WEBPACK_IMPORTED_MODULE_10__["CONNECTION_INIT_TIMEOUT"]);
12390
12312
  }
12391
12313
  });
12392
12314
  }()];
@@ -12953,6 +12875,8 @@ __webpack_require__.r(__webpack_exports__);
12953
12875
  /* harmony import */ var _PubSubProvider__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./PubSubProvider */ "../pubsub/lib-esm/Providers/PubSubProvider.js");
12954
12876
  /* harmony import */ var _aws_amplify_core__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! @aws-amplify/core */ "@aws-amplify/core");
12955
12877
  /* harmony import */ var _aws_amplify_core__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(_aws_amplify_core__WEBPACK_IMPORTED_MODULE_4__);
12878
+ /* harmony import */ var _utils_ConnectionStateMonitor__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ../utils/ConnectionStateMonitor */ "../pubsub/lib-esm/utils/ConnectionStateMonitor.js");
12879
+ /* harmony import */ var _constants__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./constants */ "../pubsub/lib-esm/Providers/constants.js");
12956
12880
  function _typeof(obj) {
12957
12881
  "@babel/helpers - typeof";
12958
12882
 
@@ -13179,6 +13103,8 @@ var __rest = undefined && undefined.__rest || function (s, e) {
13179
13103
 
13180
13104
 
13181
13105
 
13106
+
13107
+
13182
13108
  var logger = new _aws_amplify_core__WEBPACK_IMPORTED_MODULE_4__["ConsoleLogger"]('MqttOverWSProvider');
13183
13109
  function mqttTopicMatch(filter, topic) {
13184
13110
  var filterArray = filter.split('/');
@@ -13244,6 +13170,14 @@ function () {
13244
13170
  return ClientsQueue;
13245
13171
  }();
13246
13172
 
13173
+ var dispatchPubSubEvent = function dispatchPubSubEvent(event, data, message) {
13174
+ _aws_amplify_core__WEBPACK_IMPORTED_MODULE_4__["Hub"].dispatch('pubsub', {
13175
+ event: event,
13176
+ data: data,
13177
+ message: message
13178
+ }, 'PubSub', _constants__WEBPACK_IMPORTED_MODULE_6__["AMPLIFY_SYMBOL"]);
13179
+ };
13180
+
13247
13181
  var topicSymbol = typeof Symbol !== 'undefined' ? Symbol('topic') : '@@topic';
13248
13182
 
13249
13183
  var MqttOverWSProvider =
@@ -13261,8 +13195,17 @@ function (_super) {
13261
13195
  })) || this;
13262
13196
 
13263
13197
  _this._clientsQueue = new ClientsQueue();
13198
+ _this.connectionStateMonitor = new _utils_ConnectionStateMonitor__WEBPACK_IMPORTED_MODULE_5__["ConnectionStateMonitor"]();
13264
13199
  _this._topicObservers = new Map();
13265
- _this._clientIdObservers = new Map();
13200
+ _this._clientIdObservers = new Map(); // Monitor the connection health state and pass changes along to Hub
13201
+
13202
+ _this.connectionStateMonitor.connectionStateObservable.subscribe(function (connectionStateChange) {
13203
+ dispatchPubSubEvent(_constants__WEBPACK_IMPORTED_MODULE_6__["CONNECTION_STATE_CHANGE"], {
13204
+ provider: _this,
13205
+ connectionState: connectionStateChange
13206
+ }, "Connection state is " + connectionStateChange);
13207
+ });
13208
+
13266
13209
  return _this;
13267
13210
  }
13268
13211
 
@@ -13359,6 +13302,7 @@ function (_super) {
13359
13302
  switch (_b.label) {
13360
13303
  case 0:
13361
13304
  logger.debug('Creating new MQTT client', clientId);
13305
+ this.connectionStateMonitor.record(_utils_ConnectionStateMonitor__WEBPACK_IMPORTED_MODULE_5__["CONNECTION_CHANGE"].OPENING_CONNECTION);
13362
13306
  client = new paho_mqtt__WEBPACK_IMPORTED_MODULE_0__["Client"](url, clientId); // client.trace = (args) => logger.debug(clientId, JSON.stringify(args, null, 2));
13363
13307
 
13364
13308
  client.onMessageArrived = function (_a) {
@@ -13376,6 +13320,8 @@ function (_super) {
13376
13320
  clientId: clientId,
13377
13321
  errorCode: errorCode
13378
13322
  }, args));
13323
+
13324
+ _this.connectionStateMonitor.record(_utils_ConnectionStateMonitor__WEBPACK_IMPORTED_MODULE_5__["CONNECTION_CHANGE"].CLOSED);
13379
13325
  };
13380
13326
 
13381
13327
  return [4
@@ -13387,13 +13333,18 @@ function (_super) {
13387
13333
  onSuccess: function onSuccess() {
13388
13334
  return resolve(client);
13389
13335
  },
13390
- onFailure: reject
13336
+ onFailure: function onFailure() {
13337
+ reject();
13338
+
13339
+ _this.connectionStateMonitor.record(_utils_ConnectionStateMonitor__WEBPACK_IMPORTED_MODULE_5__["CONNECTION_CHANGE"].CONNECTION_FAILED);
13340
+ }
13391
13341
  });
13392
13342
  })];
13393
13343
 
13394
13344
  case 1:
13395
13345
  _b.sent();
13396
13346
 
13347
+ this.connectionStateMonitor.record(_utils_ConnectionStateMonitor__WEBPACK_IMPORTED_MODULE_5__["CONNECTION_CHANGE"].CONNECTION_ESTABLISHED);
13397
13348
  return [2
13398
13349
  /*return*/
13399
13350
  , client];
@@ -13445,6 +13396,7 @@ function (_super) {
13445
13396
 
13446
13397
  if (client && client.isConnected()) {
13447
13398
  client.disconnect();
13399
+ this.connectionStateMonitor.record(_utils_ConnectionStateMonitor__WEBPACK_IMPORTED_MODULE_5__["CONNECTION_CHANGE"].CLOSED);
13448
13400
  }
13449
13401
 
13450
13402
  this.clientsQueue.remove(clientId);
@@ -13625,6 +13577,8 @@ function (_super) {
13625
13577
  (_a = _this._clientIdObservers.get(clientId)) === null || _a === void 0 ? void 0 : _a["delete"](observer); // No more observers per client => client not needed anymore
13626
13578
 
13627
13579
  if (((_b = _this._clientIdObservers.get(clientId)) === null || _b === void 0 ? void 0 : _b.size) === 0) {
13580
+ _this.connectionStateMonitor.record(_utils_ConnectionStateMonitor__WEBPACK_IMPORTED_MODULE_5__["CONNECTION_CHANGE"].CLOSING_CONNECTION);
13581
+
13628
13582
  _this.disconnect(clientId);
13629
13583
 
13630
13584
  _this._clientIdObservers["delete"](clientId);
@@ -13724,6 +13678,139 @@ function () {
13724
13678
 
13725
13679
 
13726
13680
 
13681
+ /***/ }),
13682
+
13683
+ /***/ "../pubsub/lib-esm/Providers/constants.js":
13684
+ /*!************************************************!*\
13685
+ !*** ../pubsub/lib-esm/Providers/constants.js ***!
13686
+ \************************************************/
13687
+ /*! exports provided: MAX_DELAY_MS, NON_RETRYABLE_CODES, CONNECTION_STATE_CHANGE, 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 */
13688
+ /***/ (function(module, __webpack_exports__, __webpack_require__) {
13689
+
13690
+ "use strict";
13691
+ __webpack_require__.r(__webpack_exports__);
13692
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "MAX_DELAY_MS", function() { return MAX_DELAY_MS; });
13693
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "NON_RETRYABLE_CODES", function() { return NON_RETRYABLE_CODES; });
13694
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "CONNECTION_STATE_CHANGE", function() { return CONNECTION_STATE_CHANGE; });
13695
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "MESSAGE_TYPES", function() { return MESSAGE_TYPES; });
13696
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "SUBSCRIPTION_STATUS", function() { return SUBSCRIPTION_STATUS; });
13697
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "SOCKET_STATUS", function() { return SOCKET_STATUS; });
13698
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "AMPLIFY_SYMBOL", function() { return AMPLIFY_SYMBOL; });
13699
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "AWS_APPSYNC_REALTIME_HEADERS", function() { return AWS_APPSYNC_REALTIME_HEADERS; });
13700
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "CONNECTION_INIT_TIMEOUT", function() { return CONNECTION_INIT_TIMEOUT; });
13701
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "START_ACK_TIMEOUT", function() { return START_ACK_TIMEOUT; });
13702
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "DEFAULT_KEEP_ALIVE_TIMEOUT", function() { return DEFAULT_KEEP_ALIVE_TIMEOUT; });
13703
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "DEFAULT_KEEP_ALIVE_ALERT_TIMEOUT", function() { return DEFAULT_KEEP_ALIVE_ALERT_TIMEOUT; });
13704
+ var MAX_DELAY_MS = 5000;
13705
+ var NON_RETRYABLE_CODES = [400, 401, 403];
13706
+ var CONNECTION_STATE_CHANGE = 'ConnectionStateChange';
13707
+ var MESSAGE_TYPES;
13708
+
13709
+ (function (MESSAGE_TYPES) {
13710
+ /**
13711
+ * Client -> Server message.
13712
+ * This message type is the first message after handshake and this will initialize AWS AppSync RealTime communication
13713
+ */
13714
+ MESSAGE_TYPES["GQL_CONNECTION_INIT"] = "connection_init";
13715
+ /**
13716
+ * Server -> Client message
13717
+ * This message type is in case there is an issue with AWS AppSync RealTime when establishing connection
13718
+ */
13719
+
13720
+ MESSAGE_TYPES["GQL_CONNECTION_ERROR"] = "connection_error";
13721
+ /**
13722
+ * Server -> Client message.
13723
+ * This message type is for the ack response from AWS AppSync RealTime for GQL_CONNECTION_INIT message
13724
+ */
13725
+
13726
+ MESSAGE_TYPES["GQL_CONNECTION_ACK"] = "connection_ack";
13727
+ /**
13728
+ * Client -> Server message.
13729
+ * This message type is for register subscriptions with AWS AppSync RealTime
13730
+ */
13731
+
13732
+ MESSAGE_TYPES["GQL_START"] = "start";
13733
+ /**
13734
+ * Server -> Client message.
13735
+ * This message type is for the ack response from AWS AppSync RealTime for GQL_START message
13736
+ */
13737
+
13738
+ MESSAGE_TYPES["GQL_START_ACK"] = "start_ack";
13739
+ /**
13740
+ * Server -> Client message.
13741
+ * This message type is for subscription message from AWS AppSync RealTime
13742
+ */
13743
+
13744
+ MESSAGE_TYPES["GQL_DATA"] = "data";
13745
+ /**
13746
+ * Server -> Client message.
13747
+ * This message type helps the client to know is still receiving messages from AWS AppSync RealTime
13748
+ */
13749
+
13750
+ MESSAGE_TYPES["GQL_CONNECTION_KEEP_ALIVE"] = "ka";
13751
+ /**
13752
+ * Client -> Server message.
13753
+ * This message type is for unregister subscriptions with AWS AppSync RealTime
13754
+ */
13755
+
13756
+ MESSAGE_TYPES["GQL_STOP"] = "stop";
13757
+ /**
13758
+ * Server -> Client message.
13759
+ * This message type is for the ack response from AWS AppSync RealTime for GQL_STOP message
13760
+ */
13761
+
13762
+ MESSAGE_TYPES["GQL_COMPLETE"] = "complete";
13763
+ /**
13764
+ * Server -> Client message.
13765
+ * This message type is for sending error messages from AWS AppSync RealTime to the client
13766
+ */
13767
+
13768
+ MESSAGE_TYPES["GQL_ERROR"] = "error";
13769
+ })(MESSAGE_TYPES || (MESSAGE_TYPES = {}));
13770
+
13771
+ var SUBSCRIPTION_STATUS;
13772
+
13773
+ (function (SUBSCRIPTION_STATUS) {
13774
+ SUBSCRIPTION_STATUS[SUBSCRIPTION_STATUS["PENDING"] = 0] = "PENDING";
13775
+ SUBSCRIPTION_STATUS[SUBSCRIPTION_STATUS["CONNECTED"] = 1] = "CONNECTED";
13776
+ SUBSCRIPTION_STATUS[SUBSCRIPTION_STATUS["FAILED"] = 2] = "FAILED";
13777
+ })(SUBSCRIPTION_STATUS || (SUBSCRIPTION_STATUS = {}));
13778
+
13779
+ var SOCKET_STATUS;
13780
+
13781
+ (function (SOCKET_STATUS) {
13782
+ SOCKET_STATUS[SOCKET_STATUS["CLOSED"] = 0] = "CLOSED";
13783
+ SOCKET_STATUS[SOCKET_STATUS["READY"] = 1] = "READY";
13784
+ SOCKET_STATUS[SOCKET_STATUS["CONNECTING"] = 2] = "CONNECTING";
13785
+ })(SOCKET_STATUS || (SOCKET_STATUS = {}));
13786
+
13787
+ var AMPLIFY_SYMBOL = typeof Symbol !== 'undefined' && typeof Symbol["for"] === 'function' ? Symbol["for"]('amplify_default') : '@@amplify_default';
13788
+ var AWS_APPSYNC_REALTIME_HEADERS = {
13789
+ accept: 'application/json, text/javascript',
13790
+ 'content-encoding': 'amz-1.0',
13791
+ 'content-type': 'application/json; charset=UTF-8'
13792
+ };
13793
+ /**
13794
+ * Time in milleseconds to wait for GQL_CONNECTION_INIT message
13795
+ */
13796
+
13797
+ var CONNECTION_INIT_TIMEOUT = 15000;
13798
+ /**
13799
+ * Time in milleseconds to wait for GQL_START_ACK message
13800
+ */
13801
+
13802
+ var START_ACK_TIMEOUT = 15000;
13803
+ /**
13804
+ * Default Time in milleseconds to wait for GQL_CONNECTION_KEEP_ALIVE message
13805
+ */
13806
+
13807
+ var DEFAULT_KEEP_ALIVE_TIMEOUT = 5 * 60 * 1000;
13808
+ /**
13809
+ * Default Time in milleseconds to alert for missed GQL_CONNECTION_KEEP_ALIVE message
13810
+ */
13811
+
13812
+ var DEFAULT_KEEP_ALIVE_ALERT_TIMEOUT = 65 * 1000;
13813
+
13727
13814
  /***/ }),
13728
13815
 
13729
13816
  /***/ "../pubsub/lib-esm/Providers/index.js":
@@ -14157,12 +14244,11 @@ _aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__["Amplify"].register(PubSub);
14157
14244
  /*!**********************************!*\
14158
14245
  !*** ../pubsub/lib-esm/index.js ***!
14159
14246
  \**********************************/
14160
- /*! exports provided: AbstractPubSubProvider, AWSAppSyncProvider, AWSAppSyncRealTimeProvider, AWSIoTProvider, mqttTopicMatch, MqttOverWSProvider, PubSub, CONTROL_MSG, default */
14247
+ /*! exports provided: AbstractPubSubProvider, AWSAppSyncProvider, AWSAppSyncRealTimeProvider, AWSIoTProvider, mqttTopicMatch, MqttOverWSProvider, CONNECTION_STATE_CHANGE, ConnectionState, CONTROL_MSG, PubSub, default */
14161
14248
  /***/ (function(module, __webpack_exports__, __webpack_require__) {
14162
14249
 
14163
14250
  "use strict";
14164
14251
  __webpack_require__.r(__webpack_exports__);
14165
- /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "CONTROL_MSG", function() { return CONTROL_MSG; });
14166
14252
  /* harmony import */ var _PubSub__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./PubSub */ "../pubsub/lib-esm/PubSub.js");
14167
14253
  /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "PubSub", function() { return _PubSub__WEBPACK_IMPORTED_MODULE_0__["PubSub"]; });
14168
14254
 
@@ -14179,6 +14265,14 @@ __webpack_require__.r(__webpack_exports__);
14179
14265
 
14180
14266
  /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MqttOverWSProvider", function() { return _Providers__WEBPACK_IMPORTED_MODULE_1__["MqttOverWSProvider"]; });
14181
14267
 
14268
+ /* harmony import */ var _Providers_constants__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./Providers/constants */ "../pubsub/lib-esm/Providers/constants.js");
14269
+ /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "CONNECTION_STATE_CHANGE", function() { return _Providers_constants__WEBPACK_IMPORTED_MODULE_2__["CONNECTION_STATE_CHANGE"]; });
14270
+
14271
+ /* harmony import */ var _types__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./types */ "../pubsub/lib-esm/types/index.js");
14272
+ /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "ConnectionState", function() { return _types__WEBPACK_IMPORTED_MODULE_3__["ConnectionState"]; });
14273
+
14274
+ /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "CONTROL_MSG", function() { return _types__WEBPACK_IMPORTED_MODULE_3__["CONTROL_MSG"]; });
14275
+
14182
14276
  /*
14183
14277
  * Copyright 2017-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
14184
14278
  *
@@ -14193,6 +14287,40 @@ __webpack_require__.r(__webpack_exports__);
14193
14287
  */
14194
14288
 
14195
14289
 
14290
+
14291
+
14292
+
14293
+ /**
14294
+ * @deprecated use named import
14295
+ */
14296
+
14297
+ /* harmony default export */ __webpack_exports__["default"] = (_PubSub__WEBPACK_IMPORTED_MODULE_0__["PubSub"]);
14298
+
14299
+ /***/ }),
14300
+
14301
+ /***/ "../pubsub/lib-esm/types/PubSub.js":
14302
+ /*!*****************************************!*\
14303
+ !*** ../pubsub/lib-esm/types/PubSub.js ***!
14304
+ \*****************************************/
14305
+ /*! exports provided: CONTROL_MSG, ConnectionState */
14306
+ /***/ (function(module, __webpack_exports__, __webpack_require__) {
14307
+
14308
+ "use strict";
14309
+ __webpack_require__.r(__webpack_exports__);
14310
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "CONTROL_MSG", function() { return CONTROL_MSG; });
14311
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "ConnectionState", function() { return ConnectionState; });
14312
+ /*
14313
+ * Copyright 2017-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
14314
+ *
14315
+ * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
14316
+ * the License. A copy of the License is located at
14317
+ *
14318
+ * http://aws.amazon.com/apache2.0/
14319
+ *
14320
+ * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
14321
+ * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
14322
+ * and limitations under the License.
14323
+ */
14196
14324
  var CONTROL_MSG;
14197
14325
 
14198
14326
  (function (CONTROL_MSG) {
@@ -14202,13 +14330,285 @@ var CONTROL_MSG;
14202
14330
  CONTROL_MSG["SUBSCRIPTION_ACK"] = "Subscription ack";
14203
14331
  CONTROL_MSG["TIMEOUT_DISCONNECT"] = "Timeout disconnect";
14204
14332
  })(CONTROL_MSG || (CONTROL_MSG = {}));
14333
+ /** @enum {string} */
14205
14334
 
14206
14335
 
14207
- /**
14208
- * @deprecated use named import
14336
+ var ConnectionState;
14337
+
14338
+ (function (ConnectionState) {
14339
+ /*
14340
+ * The connection is alive and healthy
14341
+ */
14342
+ ConnectionState["Connected"] = "Connected";
14343
+ /*
14344
+ * The connection is alive, but the connection is offline
14345
+ */
14346
+
14347
+ ConnectionState["ConnectedPendingNetwork"] = "ConnectedPendingNetwork";
14348
+ /*
14349
+ * The connection has been disconnected while in use
14350
+ */
14351
+
14352
+ ConnectionState["ConnectionDisrupted"] = "ConnectionDisrupted";
14353
+ /*
14354
+ * The connection has been disconnected and the network is offline
14355
+ */
14356
+
14357
+ ConnectionState["ConnectionDisruptedPendingNetwork"] = "ConnectionDisruptedPendingNetwork";
14358
+ /*
14359
+ * The connection is in the process of connecting
14360
+ */
14361
+
14362
+ ConnectionState["Connecting"] = "Connecting";
14363
+ /*
14364
+ * The connection is not in use and is being disconnected
14365
+ */
14366
+
14367
+ ConnectionState["ConnectedPendingDisconnect"] = "ConnectedPendingDisconnect";
14368
+ /*
14369
+ * The connection is not in use and has been disconnected
14370
+ */
14371
+
14372
+ ConnectionState["Disconnected"] = "Disconnected";
14373
+ /*
14374
+ * The connection is alive, but a keep alive message has been missed
14375
+ */
14376
+
14377
+ ConnectionState["ConnectedPendingKeepAlive"] = "ConnectedPendingKeepAlive";
14378
+ })(ConnectionState || (ConnectionState = {}));
14379
+
14380
+ /***/ }),
14381
+
14382
+ /***/ "../pubsub/lib-esm/types/index.js":
14383
+ /*!****************************************!*\
14384
+ !*** ../pubsub/lib-esm/types/index.js ***!
14385
+ \****************************************/
14386
+ /*! exports provided: CONTROL_MSG, ConnectionState */
14387
+ /***/ (function(module, __webpack_exports__, __webpack_require__) {
14388
+
14389
+ "use strict";
14390
+ __webpack_require__.r(__webpack_exports__);
14391
+ /* harmony import */ var _PubSub__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./PubSub */ "../pubsub/lib-esm/types/PubSub.js");
14392
+ /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "CONTROL_MSG", function() { return _PubSub__WEBPACK_IMPORTED_MODULE_0__["CONTROL_MSG"]; });
14393
+
14394
+ /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "ConnectionState", function() { return _PubSub__WEBPACK_IMPORTED_MODULE_0__["ConnectionState"]; });
14395
+
14396
+
14397
+
14398
+ /***/ }),
14399
+
14400
+ /***/ "../pubsub/lib-esm/utils/ConnectionStateMonitor.js":
14401
+ /*!*********************************************************!*\
14402
+ !*** ../pubsub/lib-esm/utils/ConnectionStateMonitor.js ***!
14403
+ \*********************************************************/
14404
+ /*! exports provided: CONNECTION_CHANGE, ConnectionStateMonitor */
14405
+ /***/ (function(module, __webpack_exports__, __webpack_require__) {
14406
+
14407
+ "use strict";
14408
+ __webpack_require__.r(__webpack_exports__);
14409
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "CONNECTION_CHANGE", function() { return CONNECTION_CHANGE; });
14410
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "ConnectionStateMonitor", function() { return ConnectionStateMonitor; });
14411
+ /* harmony import */ var zen_observable_ts__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! zen-observable-ts */ "../../node_modules/zen-observable-ts/lib/bundle.esm.js");
14412
+ /* harmony import */ var _types_PubSub__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../types/PubSub */ "../pubsub/lib-esm/types/PubSub.js");
14413
+ /* harmony import */ var _ReachabilityMonitor__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./ReachabilityMonitor */ "../pubsub/lib-esm/utils/ReachabilityMonitor/index.js");
14414
+ /*
14415
+ * Copyright 2017-2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
14416
+ *
14417
+ * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
14418
+ * the License. A copy of the License is located at
14419
+ *
14420
+ * http://aws.amazon.com/apache2.0/
14421
+ *
14422
+ * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
14423
+ * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
14424
+ * and limitations under the License.
14209
14425
  */
14426
+ var __assign = undefined && undefined.__assign || function () {
14427
+ __assign = Object.assign || function (t) {
14428
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
14429
+ s = arguments[i];
14210
14430
 
14211
- /* harmony default export */ __webpack_exports__["default"] = (_PubSub__WEBPACK_IMPORTED_MODULE_0__["PubSub"]);
14431
+ for (var p in s) {
14432
+ if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
14433
+ }
14434
+ }
14435
+
14436
+ return t;
14437
+ };
14438
+
14439
+ return __assign.apply(this, arguments);
14440
+ };
14441
+
14442
+
14443
+
14444
+
14445
+ var CONNECTION_CHANGE = {
14446
+ KEEP_ALIVE_MISSED: {
14447
+ keepAliveState: 'unhealthy'
14448
+ },
14449
+ KEEP_ALIVE: {
14450
+ keepAliveState: 'healthy'
14451
+ },
14452
+ CONNECTION_ESTABLISHED: {
14453
+ connectionState: 'connected'
14454
+ },
14455
+ CONNECTION_FAILED: {
14456
+ intendedConnectionState: 'disconnected',
14457
+ connectionState: 'disconnected'
14458
+ },
14459
+ CLOSING_CONNECTION: {
14460
+ intendedConnectionState: 'disconnected'
14461
+ },
14462
+ OPENING_CONNECTION: {
14463
+ intendedConnectionState: 'connected',
14464
+ connectionState: 'connecting'
14465
+ },
14466
+ CLOSED: {
14467
+ connectionState: 'disconnected'
14468
+ },
14469
+ ONLINE: {
14470
+ networkState: 'connected'
14471
+ },
14472
+ OFFLINE: {
14473
+ networkState: 'disconnected'
14474
+ }
14475
+ };
14476
+
14477
+ var ConnectionStateMonitor =
14478
+ /** @class */
14479
+ function () {
14480
+ function ConnectionStateMonitor() {
14481
+ var _this = this;
14482
+
14483
+ this._networkMonitoringSubscription = undefined;
14484
+ this._linkedConnectionState = {
14485
+ networkState: 'connected',
14486
+ connectionState: 'disconnected',
14487
+ intendedConnectionState: 'disconnected',
14488
+ keepAliveState: 'healthy'
14489
+ };
14490
+ this._linkedConnectionStateObservable = new zen_observable_ts__WEBPACK_IMPORTED_MODULE_0__["default"](function (connectionStateObserver) {
14491
+ connectionStateObserver.next(_this._linkedConnectionState);
14492
+ _this._linkedConnectionStateObserver = connectionStateObserver;
14493
+ });
14494
+ }
14495
+ /**
14496
+ * Turn network state monitoring on if it isn't on already
14497
+ */
14498
+
14499
+
14500
+ ConnectionStateMonitor.prototype.enableNetworkMonitoring = function () {
14501
+ var _this = this; // Maintain the network state based on the reachability monitor
14502
+
14503
+
14504
+ if (this._networkMonitoringSubscription === undefined) {
14505
+ this._networkMonitoringSubscription = Object(_ReachabilityMonitor__WEBPACK_IMPORTED_MODULE_2__["ReachabilityMonitor"])().subscribe(function (_a) {
14506
+ var online = _a.online;
14507
+
14508
+ _this.record(online ? CONNECTION_CHANGE.ONLINE : CONNECTION_CHANGE.OFFLINE);
14509
+ });
14510
+ }
14511
+ };
14512
+ /**
14513
+ * Turn network state monitoring off if it isn't off already
14514
+ */
14515
+
14516
+
14517
+ ConnectionStateMonitor.prototype.disableNetworkMonitoring = function () {
14518
+ var _a;
14519
+
14520
+ (_a = this._networkMonitoringSubscription) === null || _a === void 0 ? void 0 : _a.unsubscribe();
14521
+ this._networkMonitoringSubscription = undefined;
14522
+ };
14523
+
14524
+ Object.defineProperty(ConnectionStateMonitor.prototype, "connectionStateObservable", {
14525
+ /**
14526
+ * Get the observable that allows us to monitor the connection state
14527
+ *
14528
+ * @returns {Observable<ConnectionState>} - The observable that emits ConnectionState updates
14529
+ */
14530
+ get: function get() {
14531
+ var _this = this;
14532
+
14533
+ var previous; // The linked state aggregates state changes to any of the network, connection,
14534
+ // intendedConnection and keepAliveHealth. Some states will change these independent
14535
+ // states without changing the overall connection state.
14536
+ // After translating from linked states to ConnectionState, then remove any duplicates
14537
+
14538
+ return this._linkedConnectionStateObservable.map(function (value) {
14539
+ return _this.connectionStatesTranslator(value);
14540
+ }).filter(function (current) {
14541
+ var toInclude = current !== previous;
14542
+ previous = current;
14543
+ return toInclude;
14544
+ });
14545
+ },
14546
+ enumerable: true,
14547
+ configurable: true
14548
+ });
14549
+ /*
14550
+ * Updates local connection state and emits the full state to the observer.
14551
+ */
14552
+
14553
+ ConnectionStateMonitor.prototype.record = function (statusUpdates) {
14554
+ // Maintain the network monitor
14555
+ if (statusUpdates.intendedConnectionState === 'connected') {
14556
+ this.enableNetworkMonitoring();
14557
+ } else if (statusUpdates.intendedConnectionState === 'disconnected') {
14558
+ this.disableNetworkMonitoring();
14559
+ } // Maintain the socket state
14560
+
14561
+
14562
+ var newSocketStatus = __assign(__assign({}, this._linkedConnectionState), statusUpdates);
14563
+
14564
+ this._linkedConnectionState = __assign({}, newSocketStatus);
14565
+
14566
+ this._linkedConnectionStateObserver.next(this._linkedConnectionState);
14567
+ };
14568
+ /*
14569
+ * Translate the ConnectionState structure into a specific ConnectionState string literal union
14570
+ */
14571
+
14572
+
14573
+ ConnectionStateMonitor.prototype.connectionStatesTranslator = function (_a) {
14574
+ var connectionState = _a.connectionState,
14575
+ networkState = _a.networkState,
14576
+ intendedConnectionState = _a.intendedConnectionState,
14577
+ keepAliveState = _a.keepAliveState;
14578
+ if (connectionState === 'connected' && networkState === 'disconnected') return _types_PubSub__WEBPACK_IMPORTED_MODULE_1__["ConnectionState"].ConnectedPendingNetwork;
14579
+ if (connectionState === 'connected' && intendedConnectionState === 'disconnected') return _types_PubSub__WEBPACK_IMPORTED_MODULE_1__["ConnectionState"].ConnectedPendingDisconnect;
14580
+ if (connectionState === 'disconnected' && intendedConnectionState === 'connected' && networkState === 'disconnected') return _types_PubSub__WEBPACK_IMPORTED_MODULE_1__["ConnectionState"].ConnectionDisruptedPendingNetwork;
14581
+ if (connectionState === 'disconnected' && intendedConnectionState === 'connected') return _types_PubSub__WEBPACK_IMPORTED_MODULE_1__["ConnectionState"].ConnectionDisrupted;
14582
+ if (connectionState === 'connected' && keepAliveState === 'unhealthy') return _types_PubSub__WEBPACK_IMPORTED_MODULE_1__["ConnectionState"].ConnectedPendingKeepAlive; // All remaining states directly correspond to the connection state
14583
+
14584
+ if (connectionState === 'connecting') return _types_PubSub__WEBPACK_IMPORTED_MODULE_1__["ConnectionState"].Connecting;
14585
+ if (connectionState === 'disconnected') return _types_PubSub__WEBPACK_IMPORTED_MODULE_1__["ConnectionState"].Disconnected;
14586
+ return _types_PubSub__WEBPACK_IMPORTED_MODULE_1__["ConnectionState"].Connected;
14587
+ };
14588
+
14589
+ return ConnectionStateMonitor;
14590
+ }();
14591
+
14592
+
14593
+
14594
+ /***/ }),
14595
+
14596
+ /***/ "../pubsub/lib-esm/utils/ReachabilityMonitor/index.js":
14597
+ /*!************************************************************!*\
14598
+ !*** ../pubsub/lib-esm/utils/ReachabilityMonitor/index.js ***!
14599
+ \************************************************************/
14600
+ /*! exports provided: ReachabilityMonitor */
14601
+ /***/ (function(module, __webpack_exports__, __webpack_require__) {
14602
+
14603
+ "use strict";
14604
+ __webpack_require__.r(__webpack_exports__);
14605
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "ReachabilityMonitor", function() { return ReachabilityMonitor; });
14606
+ /* harmony import */ var _aws_amplify_core__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @aws-amplify/core */ "@aws-amplify/core");
14607
+ /* harmony import */ var _aws_amplify_core__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_aws_amplify_core__WEBPACK_IMPORTED_MODULE_0__);
14608
+
14609
+ var ReachabilityMonitor = function ReachabilityMonitor() {
14610
+ return new _aws_amplify_core__WEBPACK_IMPORTED_MODULE_0__["Reachability"]().networkMonitor();
14611
+ };
14212
14612
 
14213
14613
  /***/ }),
14214
14614
 
@@ -15016,8 +15416,8 @@ function () {
15016
15416
  } : _c;
15017
15417
  var authenticationType = defaultAuthenticationType || aws_appsync_authenticationType || 'AWS_IAM';
15018
15418
 
15019
- if (_aws_amplify_pubsub__WEBPACK_IMPORTED_MODULE_2__["default"] && typeof _aws_amplify_pubsub__WEBPACK_IMPORTED_MODULE_2__["default"].subscribe === 'function') {
15020
- return _aws_amplify_pubsub__WEBPACK_IMPORTED_MODULE_2__["default"].subscribe('', {
15419
+ if (_aws_amplify_pubsub__WEBPACK_IMPORTED_MODULE_2__["PubSub"] && typeof _aws_amplify_pubsub__WEBPACK_IMPORTED_MODULE_2__["PubSub"].subscribe === 'function') {
15420
+ return _aws_amplify_pubsub__WEBPACK_IMPORTED_MODULE_2__["PubSub"].subscribe('', {
15021
15421
  provider: _aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__["INTERNAL_AWS_APPSYNC_REALTIME_PUBSUB_PROVIDER"],
15022
15422
  appSyncGraphqlEndpoint: appSyncGraphqlEndpoint,
15023
15423
  authenticationType: authenticationType,