@aws-amplify/api-graphql 2.3.12-unstable.5 → 2.3.13-next.13

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,137 +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, DEFAULT_KEEP_ALIVE_ALERT_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
- /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "DEFAULT_KEEP_ALIVE_ALERT_TIMEOUT", function() { return DEFAULT_KEEP_ALIVE_ALERT_TIMEOUT; });
11239
- var MAX_DELAY_MS = 5000;
11240
- var NON_RETRYABLE_CODES = [400, 401, 403];
11241
- var MESSAGE_TYPES;
11242
-
11243
- (function (MESSAGE_TYPES) {
11244
- /**
11245
- * Client -> Server message.
11246
- * This message type is the first message after handshake and this will initialize AWS AppSync RealTime communication
11247
- */
11248
- MESSAGE_TYPES["GQL_CONNECTION_INIT"] = "connection_init";
11249
- /**
11250
- * Server -> Client message
11251
- * This message type is in case there is an issue with AWS AppSync RealTime when establishing connection
11252
- */
11253
-
11254
- MESSAGE_TYPES["GQL_CONNECTION_ERROR"] = "connection_error";
11255
- /**
11256
- * Server -> Client message.
11257
- * This message type is for the ack response from AWS AppSync RealTime for GQL_CONNECTION_INIT message
11258
- */
11259
-
11260
- MESSAGE_TYPES["GQL_CONNECTION_ACK"] = "connection_ack";
11261
- /**
11262
- * Client -> Server message.
11263
- * This message type is for register subscriptions with AWS AppSync RealTime
11264
- */
11265
-
11266
- MESSAGE_TYPES["GQL_START"] = "start";
11267
- /**
11268
- * Server -> Client message.
11269
- * This message type is for the ack response from AWS AppSync RealTime for GQL_START message
11270
- */
11271
-
11272
- MESSAGE_TYPES["GQL_START_ACK"] = "start_ack";
11273
- /**
11274
- * Server -> Client message.
11275
- * This message type is for subscription message from AWS AppSync RealTime
11276
- */
11277
-
11278
- MESSAGE_TYPES["GQL_DATA"] = "data";
11279
- /**
11280
- * Server -> Client message.
11281
- * This message type helps the client to know is still receiving messages from AWS AppSync RealTime
11282
- */
11283
-
11284
- MESSAGE_TYPES["GQL_CONNECTION_KEEP_ALIVE"] = "ka";
11285
- /**
11286
- * Client -> Server message.
11287
- * This message type is for unregister subscriptions with AWS AppSync RealTime
11288
- */
11289
-
11290
- MESSAGE_TYPES["GQL_STOP"] = "stop";
11291
- /**
11292
- * Server -> Client message.
11293
- * This message type is for the ack response from AWS AppSync RealTime for GQL_STOP message
11294
- */
11295
-
11296
- MESSAGE_TYPES["GQL_COMPLETE"] = "complete";
11297
- /**
11298
- * Server -> Client message.
11299
- * This message type is for sending error messages from AWS AppSync RealTime to the client
11300
- */
11301
-
11302
- MESSAGE_TYPES["GQL_ERROR"] = "error";
11303
- })(MESSAGE_TYPES || (MESSAGE_TYPES = {}));
11304
-
11305
- var SUBSCRIPTION_STATUS;
11306
-
11307
- (function (SUBSCRIPTION_STATUS) {
11308
- SUBSCRIPTION_STATUS[SUBSCRIPTION_STATUS["PENDING"] = 0] = "PENDING";
11309
- SUBSCRIPTION_STATUS[SUBSCRIPTION_STATUS["CONNECTED"] = 1] = "CONNECTED";
11310
- SUBSCRIPTION_STATUS[SUBSCRIPTION_STATUS["FAILED"] = 2] = "FAILED";
11311
- })(SUBSCRIPTION_STATUS || (SUBSCRIPTION_STATUS = {}));
11312
-
11313
- var SOCKET_STATUS;
11314
-
11315
- (function (SOCKET_STATUS) {
11316
- SOCKET_STATUS[SOCKET_STATUS["CLOSED"] = 0] = "CLOSED";
11317
- SOCKET_STATUS[SOCKET_STATUS["READY"] = 1] = "READY";
11318
- SOCKET_STATUS[SOCKET_STATUS["CONNECTING"] = 2] = "CONNECTING";
11319
- })(SOCKET_STATUS || (SOCKET_STATUS = {}));
11320
-
11321
- var AMPLIFY_SYMBOL = typeof Symbol !== 'undefined' && typeof Symbol["for"] === 'function' ? Symbol["for"]('amplify_default') : '@@amplify_default';
11322
- var AWS_APPSYNC_REALTIME_HEADERS = {
11323
- accept: 'application/json, text/javascript',
11324
- 'content-encoding': 'amz-1.0',
11325
- 'content-type': 'application/json; charset=UTF-8'
11326
- };
11327
- /**
11328
- * Time in milleseconds to wait for GQL_CONNECTION_INIT message
11329
- */
11330
-
11331
- var CONNECTION_INIT_TIMEOUT = 15000;
11332
- /**
11333
- * Time in milleseconds to wait for GQL_START_ACK message
11334
- */
11335
-
11336
- var START_ACK_TIMEOUT = 15000;
11337
- /**
11338
- * Default Time in milleseconds to wait for GQL_CONNECTION_KEEP_ALIVE message
11339
- */
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;
11347
-
11348
11217
  /***/ }),
11349
11218
 
11350
11219
  /***/ "../pubsub/lib-esm/Providers/AWSAppSyncRealTimeProvider/index.js":
@@ -11373,9 +11242,10 @@ __webpack_require__.r(__webpack_exports__);
11373
11242
  /* harmony import */ var _aws_amplify_auth__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! @aws-amplify/auth */ "@aws-amplify/auth");
11374
11243
  /* harmony import */ var _aws_amplify_auth__WEBPACK_IMPORTED_MODULE_7___default = /*#__PURE__*/__webpack_require__.n(_aws_amplify_auth__WEBPACK_IMPORTED_MODULE_7__);
11375
11244
  /* harmony import */ var _PubSubProvider__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ../PubSubProvider */ "../pubsub/lib-esm/Providers/PubSubProvider.js");
11376
- /* harmony import */ var _index__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ../../index */ "../pubsub/lib-esm/index.js");
11377
- /* 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");
11378
11247
  /* harmony import */ var _utils_ConnectionStateMonitor__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(/*! ../../utils/ConnectionStateMonitor */ "../pubsub/lib-esm/utils/ConnectionStateMonitor.js");
11248
+ /* harmony import */ var _utils_ReconnectionMonitor__WEBPACK_IMPORTED_MODULE_12__ = __webpack_require__(/*! ../../utils/ReconnectionMonitor */ "../pubsub/lib-esm/utils/ReconnectionMonitor.js");
11379
11249
  var __extends = undefined && undefined.__extends || function () {
11380
11250
  var _extendStatics = function extendStatics(d, b) {
11381
11251
  _extendStatics = Object.setPrototypeOf || {
@@ -11613,6 +11483,7 @@ var __read = undefined && undefined.__read || function (o, n) {
11613
11483
 
11614
11484
 
11615
11485
 
11486
+
11616
11487
  var logger = new _aws_amplify_core__WEBPACK_IMPORTED_MODULE_5__["Logger"]('AWSAppSyncRealTimeProvider');
11617
11488
 
11618
11489
  var dispatchApiEvent = function dispatchApiEvent(event, data, message) {
@@ -11642,17 +11513,42 @@ function (_super) {
11642
11513
  _this.keepAliveTimeout = _constants__WEBPACK_IMPORTED_MODULE_10__["DEFAULT_KEEP_ALIVE_TIMEOUT"];
11643
11514
  _this.subscriptionObserverMap = new Map();
11644
11515
  _this.promiseArray = [];
11645
- _this.connectionStateMonitor = new _utils_ConnectionStateMonitor__WEBPACK_IMPORTED_MODULE_11__["ConnectionStateMonitor"](); // Monitor the connection state and pass changes along to Hub
11516
+ _this.connectionStateMonitor = new _utils_ConnectionStateMonitor__WEBPACK_IMPORTED_MODULE_11__["ConnectionStateMonitor"]();
11517
+ _this.reconnectionMonitor = new _utils_ReconnectionMonitor__WEBPACK_IMPORTED_MODULE_12__["ReconnectionMonitor"](); // Monitor the connection state and pass changes along to Hub
11646
11518
 
11647
- _this.connectionStateMonitor.connectionStateObservable.subscribe(function (ConnectionState) {
11648
- dispatchApiEvent(_index__WEBPACK_IMPORTED_MODULE_9__["CONNECTION_STATE_CHANGE"], {
11519
+ _this.connectionStateMonitorSubscription = _this.connectionStateMonitor.connectionStateObservable.subscribe(function (connectionState) {
11520
+ dispatchApiEvent(_constants__WEBPACK_IMPORTED_MODULE_10__["CONNECTION_STATE_CHANGE"], {
11649
11521
  provider: _this,
11650
- connectionState: ConnectionState
11651
- }, "Connection state is " + ConnectionState);
11652
- });
11522
+ connectionState: connectionState
11523
+ }, "Connection state is " + connectionState);
11524
+ _this.connectionState = connectionState; // Trigger START_RECONNECT when the connection is disrupted
11653
11525
 
11526
+ if (connectionState === _types_PubSub__WEBPACK_IMPORTED_MODULE_9__["ConnectionState"].ConnectionDisrupted) {
11527
+ _this.reconnectionMonitor.record(_utils_ReconnectionMonitor__WEBPACK_IMPORTED_MODULE_12__["ReconnectEvent"].START_RECONNECT);
11528
+ } // Trigger HALT_RECONNECT to halt reconnection attempts when the state is anything other than
11529
+ // ConnectionDisrupted or Connecting
11530
+
11531
+
11532
+ if ([_types_PubSub__WEBPACK_IMPORTED_MODULE_9__["ConnectionState"].Connected, _types_PubSub__WEBPACK_IMPORTED_MODULE_9__["ConnectionState"].ConnectedPendingDisconnect, _types_PubSub__WEBPACK_IMPORTED_MODULE_9__["ConnectionState"].ConnectedPendingKeepAlive, _types_PubSub__WEBPACK_IMPORTED_MODULE_9__["ConnectionState"].ConnectedPendingNetwork, _types_PubSub__WEBPACK_IMPORTED_MODULE_9__["ConnectionState"].ConnectedPendingNetwork, _types_PubSub__WEBPACK_IMPORTED_MODULE_9__["ConnectionState"].ConnectionDisruptedPendingNetwork, _types_PubSub__WEBPACK_IMPORTED_MODULE_9__["ConnectionState"].Disconnected].includes(connectionState)) {
11533
+ _this.reconnectionMonitor.record(_utils_ReconnectionMonitor__WEBPACK_IMPORTED_MODULE_12__["ReconnectEvent"].HALT_RECONNECT);
11534
+ }
11535
+ });
11654
11536
  return _this;
11655
11537
  }
11538
+ /**
11539
+ * Mark the socket closed and release all active listeners
11540
+ */
11541
+
11542
+
11543
+ AWSAppSyncRealTimeProvider.prototype.close = function () {
11544
+ // Mark the socket closed both in status and the connection monitor
11545
+ this.socketStatus = _constants__WEBPACK_IMPORTED_MODULE_10__["SOCKET_STATUS"].CLOSED;
11546
+ this.connectionStateMonitor.record(_utils_ConnectionStateMonitor__WEBPACK_IMPORTED_MODULE_11__["CONNECTION_CHANGE"].CONNECTION_FAILED); // Turn off the subscription monitor Hub publishing
11547
+
11548
+ this.connectionStateMonitorSubscription.unsubscribe(); // Complete all reconnect observers
11549
+
11550
+ this.reconnectionMonitor.close();
11551
+ };
11656
11552
 
11657
11553
  AWSAppSyncRealTimeProvider.prototype.getNewWebSocket = function (url, protocol) {
11658
11554
  return new WebSocket(url, protocol);
@@ -11690,36 +11586,56 @@ function (_super) {
11690
11586
  });
11691
11587
  observer.complete();
11692
11588
  } else {
11589
+ var subscriptionStartActive_1 = false;
11693
11590
  var subscriptionId_1 = Object(uuid__WEBPACK_IMPORTED_MODULE_3__["v4"])();
11694
11591
 
11695
- _this._startSubscriptionWithAWSAppSyncRealTime({
11696
- options: options,
11697
- observer: observer,
11698
- subscriptionId: subscriptionId_1
11699
- })["catch"](function (err) {
11700
- observer.error({
11701
- errors: [__assign({}, new graphql__WEBPACK_IMPORTED_MODULE_1__["GraphQLError"](_index__WEBPACK_IMPORTED_MODULE_9__["CONTROL_MSG"].REALTIME_SUBSCRIPTION_INIT_ERROR + ": " + err))]
11702
- });
11592
+ var startSubscription_1 = function startSubscription_1() {
11593
+ if (!subscriptionStartActive_1) {
11594
+ subscriptionStartActive_1 = true;
11703
11595
 
11704
- _this.connectionStateMonitor.record(_utils_ConnectionStateMonitor__WEBPACK_IMPORTED_MODULE_11__["CONNECTION_CHANGE"].CLOSED);
11596
+ var startSubscriptionPromise = _this._startSubscriptionWithAWSAppSyncRealTime({
11597
+ options: options,
11598
+ observer: observer,
11599
+ subscriptionId: subscriptionId_1
11600
+ })["catch"](function (err) {
11601
+ logger.debug(_types_PubSub__WEBPACK_IMPORTED_MODULE_9__["CONTROL_MSG"].REALTIME_SUBSCRIPTION_INIT_ERROR + ": " + err);
11705
11602
 
11706
- observer.complete();
11707
- });
11603
+ _this.connectionStateMonitor.record(_utils_ConnectionStateMonitor__WEBPACK_IMPORTED_MODULE_11__["CONNECTION_CHANGE"].CLOSED);
11604
+ });
11605
+
11606
+ startSubscriptionPromise["finally"](function () {
11607
+ subscriptionStartActive_1 = false;
11608
+ });
11609
+ }
11610
+ };
11708
11611
 
11612
+ var reconnectSubscription_1; // Add an observable to the reconnection list to manage reconnection for this subscription
11613
+
11614
+ reconnectSubscription_1 = new zen_observable_ts__WEBPACK_IMPORTED_MODULE_0__["default"](function (observer) {
11615
+ _this.reconnectionMonitor.addObserver(observer);
11616
+ }).subscribe(function () {
11617
+ startSubscription_1();
11618
+ });
11619
+ startSubscription_1();
11709
11620
  return function () {
11710
11621
  return __awaiter(_this, void 0, void 0, function () {
11711
11622
  var subscriptionState, err_1;
11712
11623
  return __generator(this, function (_a) {
11713
11624
  switch (_a.label) {
11714
11625
  case 0:
11715
- _a.trys.push([0, 2, 3, 4]); // Waiting that subscription has been connected before trying to unsubscribe
11626
+ // Cleanup reconnection subscription
11627
+ reconnectSubscription_1 === null || reconnectSubscription_1 === void 0 ? void 0 : reconnectSubscription_1.unsubscribe();
11628
+ _a.label = 1;
11629
+
11630
+ case 1:
11631
+ _a.trys.push([1, 3, 4, 5]); // Waiting that subscription has been connected before trying to unsubscribe
11716
11632
 
11717
11633
 
11718
11634
  return [4
11719
11635
  /*yield*/
11720
11636
  , this._waitForSubscriptionToBeConnected(subscriptionId_1)];
11721
11637
 
11722
- case 1:
11638
+ case 2:
11723
11639
  // Waiting that subscription has been connected before trying to unsubscribe
11724
11640
  _a.sent();
11725
11641
 
@@ -11740,23 +11656,23 @@ function (_super) {
11740
11656
 
11741
11657
  return [3
11742
11658
  /*break*/
11743
- , 4];
11659
+ , 5];
11744
11660
 
11745
- case 2:
11661
+ case 3:
11746
11662
  err_1 = _a.sent();
11747
11663
  logger.debug("Error while unsubscribing " + err_1);
11748
11664
  return [3
11749
11665
  /*break*/
11750
- , 4];
11666
+ , 5];
11751
11667
 
11752
- case 3:
11668
+ case 4:
11753
11669
  this._removeSubscriptionObserver(subscriptionId_1);
11754
11670
 
11755
11671
  return [7
11756
11672
  /*endfinally*/
11757
11673
  ];
11758
11674
 
11759
- case 4:
11675
+ case 5:
11760
11676
  return [2
11761
11677
  /*return*/
11762
11678
  ];
@@ -11781,21 +11697,21 @@ function (_super) {
11781
11697
  observer = _a.observer,
11782
11698
  subscriptionId = _a.subscriptionId;
11783
11699
 
11784
- var _b, _c;
11700
+ var _b;
11785
11701
 
11786
11702
  return __awaiter(this, void 0, void 0, function () {
11787
- var appSyncGraphqlEndpoint, authenticationType, query, variables, apiKey, region, _d, graphql_headers, _e, additionalHeaders, subscriptionState, data, dataString, headerObj, _f, _g, subscriptionMessage, stringToAWSRealTime, err_2, message, subscriptionFailedCallback_1, _h, subscriptionFailedCallback, subscriptionReadyCallback;
11703
+ var appSyncGraphqlEndpoint, authenticationType, query, variables, apiKey, region, _c, graphql_headers, _d, additionalHeaders, subscriptionState, data, dataString, headerObj, _e, _f, subscriptionMessage, stringToAWSRealTime, err_2, _g, subscriptionFailedCallback, subscriptionReadyCallback;
11788
11704
 
11789
- var _j;
11705
+ var _h;
11790
11706
 
11791
11707
  var _this = this;
11792
11708
 
11793
- return __generator(this, function (_k) {
11794
- switch (_k.label) {
11709
+ return __generator(this, function (_j) {
11710
+ switch (_j.label) {
11795
11711
  case 0:
11796
- appSyncGraphqlEndpoint = options.appSyncGraphqlEndpoint, authenticationType = options.authenticationType, query = options.query, variables = options.variables, apiKey = options.apiKey, region = options.region, _d = options.graphql_headers, graphql_headers = _d === void 0 ? function () {
11712
+ appSyncGraphqlEndpoint = options.appSyncGraphqlEndpoint, authenticationType = options.authenticationType, query = options.query, variables = options.variables, apiKey = options.apiKey, region = options.region, _c = options.graphql_headers, graphql_headers = _c === void 0 ? function () {
11797
11713
  return {};
11798
- } : _d, _e = options.additionalHeaders, additionalHeaders = _e === void 0 ? {} : _e;
11714
+ } : _c, _d = options.additionalHeaders, additionalHeaders = _d === void 0 ? {} : _d;
11799
11715
  subscriptionState = _constants__WEBPACK_IMPORTED_MODULE_10__["SUBSCRIPTION_STATUS"].PENDING;
11800
11716
  data = {
11801
11717
  query: query,
@@ -11810,7 +11726,7 @@ function (_super) {
11810
11726
  startAckTimeoutId: undefined
11811
11727
  });
11812
11728
  dataString = JSON.stringify(data);
11813
- _f = [{}];
11729
+ _e = [{}];
11814
11730
  return [4
11815
11731
  /*yield*/
11816
11732
  , this._awsRealTimeHeaderBasedAuth({
@@ -11824,13 +11740,13 @@ function (_super) {
11824
11740
  })];
11825
11741
 
11826
11742
  case 1:
11827
- _g = [__assign.apply(void 0, _f.concat([_k.sent()]))];
11743
+ _f = [__assign.apply(void 0, _e.concat([_j.sent()]))];
11828
11744
  return [4
11829
11745
  /*yield*/
11830
11746
  , graphql_headers()];
11831
11747
 
11832
11748
  case 2:
11833
- headerObj = __assign.apply(void 0, [__assign.apply(void 0, [__assign.apply(void 0, _g.concat([_k.sent()])), additionalHeaders]), (_j = {}, _j[_aws_amplify_core__WEBPACK_IMPORTED_MODULE_5__["USER_AGENT_HEADER"]] = _aws_amplify_core__WEBPACK_IMPORTED_MODULE_5__["Constants"].userAgent, _j)]);
11749
+ headerObj = __assign.apply(void 0, [__assign.apply(void 0, [__assign.apply(void 0, _f.concat([_j.sent()])), additionalHeaders]), (_h = {}, _h[_aws_amplify_core__WEBPACK_IMPORTED_MODULE_5__["USER_AGENT_HEADER"]] = _aws_amplify_core__WEBPACK_IMPORTED_MODULE_5__["Constants"].userAgent, _h)]);
11834
11750
  subscriptionMessage = {
11835
11751
  id: subscriptionId,
11836
11752
  payload: {
@@ -11842,10 +11758,10 @@ function (_super) {
11842
11758
  type: _constants__WEBPACK_IMPORTED_MODULE_10__["MESSAGE_TYPES"].GQL_START
11843
11759
  };
11844
11760
  stringToAWSRealTime = JSON.stringify(subscriptionMessage);
11845
- _k.label = 3;
11761
+ _j.label = 3;
11846
11762
 
11847
11763
  case 3:
11848
- _k.trys.push([3, 5,, 6]);
11764
+ _j.trys.push([3, 5,, 6]);
11849
11765
 
11850
11766
  this.connectionStateMonitor.record(_utils_ConnectionStateMonitor__WEBPACK_IMPORTED_MODULE_11__["CONNECTION_CHANGE"].OPENING_CONNECTION);
11851
11767
  return [4
@@ -11859,35 +11775,23 @@ function (_super) {
11859
11775
  })];
11860
11776
 
11861
11777
  case 4:
11862
- _k.sent();
11778
+ _j.sent();
11863
11779
 
11864
11780
  return [3
11865
11781
  /*break*/
11866
11782
  , 6];
11867
11783
 
11868
11784
  case 5:
11869
- err_2 = _k.sent();
11870
- logger.debug({
11871
- err: err_2
11872
- });
11873
- message = (_b = err_2['message']) !== null && _b !== void 0 ? _b : '';
11874
- this.connectionStateMonitor.record(_utils_ConnectionStateMonitor__WEBPACK_IMPORTED_MODULE_11__["CONNECTION_CHANGE"].CLOSED);
11875
- observer.error({
11876
- errors: [__assign({}, new graphql__WEBPACK_IMPORTED_MODULE_1__["GraphQLError"](_index__WEBPACK_IMPORTED_MODULE_9__["CONTROL_MSG"].CONNECTION_FAILED + ": " + message))]
11877
- });
11878
- observer.complete();
11879
- subscriptionFailedCallback_1 = (this.subscriptionObserverMap.get(subscriptionId) || {}).subscriptionFailedCallback; // Notify concurrent unsubscription
11785
+ err_2 = _j.sent();
11880
11786
 
11881
- if (typeof subscriptionFailedCallback_1 === 'function') {
11882
- subscriptionFailedCallback_1();
11883
- }
11787
+ this._logStartSubscriptionError(subscriptionId, observer, err_2);
11884
11788
 
11885
11789
  return [2
11886
11790
  /*return*/
11887
11791
  ];
11888
11792
 
11889
11793
  case 6:
11890
- _h = (_c = this.subscriptionObserverMap.get(subscriptionId)) !== null && _c !== void 0 ? _c : {}, subscriptionFailedCallback = _h.subscriptionFailedCallback, subscriptionReadyCallback = _h.subscriptionReadyCallback; // This must be done before sending the message in order to be listening immediately
11794
+ _g = (_b = this.subscriptionObserverMap.get(subscriptionId)) !== null && _b !== void 0 ? _b : {}, subscriptionFailedCallback = _g.subscriptionFailedCallback, subscriptionReadyCallback = _g.subscriptionReadyCallback; // This must be done before sending the message in order to be listening immediately
11891
11795
 
11892
11796
  this.subscriptionObserverMap.set(subscriptionId, {
11893
11797
  observer: observer,
@@ -11911,6 +11815,35 @@ function (_super) {
11911
11815
  }
11912
11816
  });
11913
11817
  });
11818
+ }; // Log logic for start subscription failures
11819
+
11820
+
11821
+ AWSAppSyncRealTimeProvider.prototype._logStartSubscriptionError = function (subscriptionId, observer, err) {
11822
+ var _a;
11823
+
11824
+ logger.debug({
11825
+ err: err
11826
+ });
11827
+ var message = (_a = err['message']) !== null && _a !== void 0 ? _a : ''; // Resolving to give the state observer time to propogate the update
11828
+
11829
+ Promise.resolve(this.connectionStateMonitor.record(_utils_ConnectionStateMonitor__WEBPACK_IMPORTED_MODULE_11__["CONNECTION_CHANGE"].CLOSED)); // Capture the error only when the network didn't cause disruption
11830
+
11831
+ if (this.connectionState !== _types_PubSub__WEBPACK_IMPORTED_MODULE_9__["ConnectionState"].ConnectionDisruptedPendingNetwork) {
11832
+ // When the error is non-retriable, error out the observable
11833
+ if (Object(_aws_amplify_core__WEBPACK_IMPORTED_MODULE_5__["isNonRetryableError"])(err)) {
11834
+ observer.error({
11835
+ errors: [__assign({}, new graphql__WEBPACK_IMPORTED_MODULE_1__["GraphQLError"](_types_PubSub__WEBPACK_IMPORTED_MODULE_9__["CONTROL_MSG"].CONNECTION_FAILED + ": " + message))]
11836
+ });
11837
+ } else {
11838
+ logger.debug(_types_PubSub__WEBPACK_IMPORTED_MODULE_9__["CONTROL_MSG"].CONNECTION_FAILED + ": " + message);
11839
+ }
11840
+
11841
+ var subscriptionFailedCallback = (this.subscriptionObserverMap.get(subscriptionId) || {}).subscriptionFailedCallback; // Notify concurrent unsubscription
11842
+
11843
+ if (typeof subscriptionFailedCallback === 'function') {
11844
+ subscriptionFailedCallback();
11845
+ }
11846
+ }
11914
11847
  }; // Waiting that subscription has been connected before trying to unsubscribe
11915
11848
 
11916
11849
 
@@ -12067,7 +12000,7 @@ function (_super) {
12067
12000
  }
12068
12001
 
12069
12002
  if (startAckTimeoutId) clearTimeout(startAckTimeoutId);
12070
- dispatchApiEvent(_index__WEBPACK_IMPORTED_MODULE_9__["CONTROL_MSG"].SUBSCRIPTION_ACK, {
12003
+ dispatchApiEvent(_types_PubSub__WEBPACK_IMPORTED_MODULE_9__["CONTROL_MSG"].SUBSCRIPTION_ACK, {
12071
12004
  query: query,
12072
12005
  variables: variables
12073
12006
  }, 'Connection established for subscription');
@@ -12093,7 +12026,7 @@ function (_super) {
12093
12026
  if (this.keepAliveTimeoutId) clearTimeout(this.keepAliveTimeoutId);
12094
12027
  if (this.keepAliveAlertTimeoutId) clearTimeout(this.keepAliveAlertTimeoutId);
12095
12028
  this.keepAliveTimeoutId = setTimeout(function () {
12096
- return _this._errorDisconnect(_index__WEBPACK_IMPORTED_MODULE_9__["CONTROL_MSG"].TIMEOUT_DISCONNECT);
12029
+ return _this._errorDisconnect(_types_PubSub__WEBPACK_IMPORTED_MODULE_9__["CONTROL_MSG"].TIMEOUT_DISCONNECT);
12097
12030
  }, this.keepAliveTimeout);
12098
12031
  this.keepAliveAlertTimeoutId = setTimeout(function () {
12099
12032
  _this.connectionStateMonitor.record(_utils_ConnectionStateMonitor__WEBPACK_IMPORTED_MODULE_11__["CONNECTION_CHANGE"].KEEP_ALIVE_MISSED);
@@ -12115,11 +12048,11 @@ function (_super) {
12115
12048
  subscriptionFailedCallback: subscriptionFailedCallback,
12116
12049
  subscriptionState: subscriptionState
12117
12050
  });
12051
+ logger.debug(_types_PubSub__WEBPACK_IMPORTED_MODULE_9__["CONTROL_MSG"].CONNECTION_FAILED + ": " + JSON.stringify(payload));
12118
12052
  observer.error({
12119
- errors: [__assign({}, new graphql__WEBPACK_IMPORTED_MODULE_1__["GraphQLError"](_index__WEBPACK_IMPORTED_MODULE_9__["CONTROL_MSG"].CONNECTION_FAILED + ": " + JSON.stringify(payload)))]
12053
+ errors: [__assign({}, new graphql__WEBPACK_IMPORTED_MODULE_1__["GraphQLError"](_types_PubSub__WEBPACK_IMPORTED_MODULE_9__["CONTROL_MSG"].CONNECTION_FAILED + ": " + JSON.stringify(payload)))]
12120
12054
  });
12121
12055
  if (startAckTimeoutId) clearTimeout(startAckTimeoutId);
12122
- observer.complete();
12123
12056
 
12124
12057
  if (typeof subscriptionFailedCallback === 'function') {
12125
12058
  subscriptionFailedCallback();
@@ -12130,16 +12063,6 @@ function (_super) {
12130
12063
 
12131
12064
  AWSAppSyncRealTimeProvider.prototype._errorDisconnect = function (msg) {
12132
12065
  logger.debug("Disconnect error: " + msg);
12133
- this.subscriptionObserverMap.forEach(function (_a) {
12134
- var observer = _a.observer;
12135
-
12136
- if (observer && !observer.closed) {
12137
- observer.error({
12138
- errors: [__assign({}, new graphql__WEBPACK_IMPORTED_MODULE_1__["GraphQLError"](msg))]
12139
- });
12140
- }
12141
- });
12142
- this.subscriptionObserverMap.clear();
12143
12066
 
12144
12067
  if (this.awsRealTimeSocket) {
12145
12068
  this.connectionStateMonitor.record(_utils_ConnectionStateMonitor__WEBPACK_IMPORTED_MODULE_11__["CONNECTION_CHANGE"].CLOSED);
@@ -12167,18 +12090,7 @@ function (_super) {
12167
12090
  variables: variables,
12168
12091
  subscriptionState: _constants__WEBPACK_IMPORTED_MODULE_10__["SUBSCRIPTION_STATUS"].FAILED
12169
12092
  });
12170
-
12171
- if (observer && !observer.closed) {
12172
- observer.error({
12173
- errors: [__assign({}, new graphql__WEBPACK_IMPORTED_MODULE_1__["GraphQLError"]("Subscription timeout " + JSON.stringify({
12174
- query: query,
12175
- variables: variables
12176
- })))]
12177
- }); // Cleanup will be automatically executed
12178
-
12179
- observer.complete();
12180
- }
12181
-
12093
+ this.connectionStateMonitor.record(_utils_ConnectionStateMonitor__WEBPACK_IMPORTED_MODULE_11__["CONNECTION_CHANGE"].CLOSED);
12182
12094
  logger.debug('timeoutStartSubscription', JSON.stringify({
12183
12095
  query: query,
12184
12096
  variables: variables
@@ -12268,6 +12180,7 @@ function (_super) {
12268
12180
 
12269
12181
  case 4:
12270
12182
  err_3 = _c.sent();
12183
+ logger.debug('Connection exited with', err_3);
12271
12184
  this.promiseArray.forEach(function (_a) {
12272
12185
  var rej = _a.rej;
12273
12186
  return rej(err_3);
@@ -12341,8 +12254,6 @@ function (_super) {
12341
12254
  };
12342
12255
 
12343
12256
  newSocket.onclose = function () {
12344
- _this.connectionStateMonitor.record(_utils_ConnectionStateMonitor__WEBPACK_IMPORTED_MODULE_11__["CONNECTION_CHANGE"].CONNECTION_FAILED);
12345
-
12346
12257
  rej(new Error('Connection handshake error'));
12347
12258
  };
12348
12259
 
@@ -12391,13 +12302,13 @@ function (_super) {
12391
12302
  _this.awsRealTimeSocket.onerror = function (err) {
12392
12303
  logger.debug(err);
12393
12304
 
12394
- _this._errorDisconnect(_index__WEBPACK_IMPORTED_MODULE_9__["CONTROL_MSG"].CONNECTION_CLOSED);
12305
+ _this._errorDisconnect(_types_PubSub__WEBPACK_IMPORTED_MODULE_9__["CONTROL_MSG"].CONNECTION_CLOSED);
12395
12306
  };
12396
12307
 
12397
12308
  _this.awsRealTimeSocket.onclose = function (event) {
12398
12309
  logger.debug("WebSocket closed " + event.reason);
12399
12310
 
12400
- _this._errorDisconnect(_index__WEBPACK_IMPORTED_MODULE_9__["CONTROL_MSG"].CONNECTION_CLOSED);
12311
+ _this._errorDisconnect(_types_PubSub__WEBPACK_IMPORTED_MODULE_9__["CONTROL_MSG"].CONNECTION_CLOSED);
12401
12312
  };
12402
12313
  }
12403
12314
 
@@ -12429,14 +12340,17 @@ function (_super) {
12429
12340
 
12430
12341
  _this.awsRealTimeSocket.send(JSON.stringify(gqlInit));
12431
12342
 
12432
- setTimeout(checkAckOk.bind(_this, ackOk_1), _constants__WEBPACK_IMPORTED_MODULE_10__["CONNECTION_INIT_TIMEOUT"]);
12433
- }
12343
+ var checkAckOk_1 = function checkAckOk_1(ackOk) {
12344
+ if (!ackOk) {
12345
+ _this.connectionStateMonitor.record(_utils_ConnectionStateMonitor__WEBPACK_IMPORTED_MODULE_11__["CONNECTION_CHANGE"].CONNECTION_FAILED);
12434
12346
 
12435
- function checkAckOk(ackOk) {
12436
- if (!ackOk) {
12437
- this.connectionStateMonitor.record(_utils_ConnectionStateMonitor__WEBPACK_IMPORTED_MODULE_11__["CONNECTION_CHANGE"].CONNECTION_FAILED);
12438
- rej(new Error("Connection timeout: ack from AWSRealTime was not received on " + _constants__WEBPACK_IMPORTED_MODULE_10__["CONNECTION_INIT_TIMEOUT"] + " ms"));
12439
- }
12347
+ rej(new Error("Connection timeout: ack from AWSAppSyncRealTime was not received after " + _constants__WEBPACK_IMPORTED_MODULE_10__["CONNECTION_INIT_TIMEOUT"] + " ms"));
12348
+ }
12349
+ };
12350
+
12351
+ setTimeout(function () {
12352
+ return checkAckOk_1(ackOk_1);
12353
+ }, _constants__WEBPACK_IMPORTED_MODULE_10__["CONNECTION_INIT_TIMEOUT"]);
12440
12354
  }
12441
12355
  });
12442
12356
  }()];
@@ -13001,8 +12915,12 @@ __webpack_require__.r(__webpack_exports__);
13001
12915
  /* harmony import */ var uuid__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(uuid__WEBPACK_IMPORTED_MODULE_1__);
13002
12916
  /* harmony import */ var zen_observable_ts__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! zen-observable-ts */ "../../node_modules/zen-observable-ts/lib/bundle.esm.js");
13003
12917
  /* harmony import */ var _PubSubProvider__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./PubSubProvider */ "../pubsub/lib-esm/Providers/PubSubProvider.js");
13004
- /* harmony import */ var _aws_amplify_core__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! @aws-amplify/core */ "@aws-amplify/core");
13005
- /* harmony import */ var _aws_amplify_core__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(_aws_amplify_core__WEBPACK_IMPORTED_MODULE_4__);
12918
+ /* harmony import */ var _types_PubSub__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../types/PubSub */ "../pubsub/lib-esm/types/PubSub.js");
12919
+ /* harmony import */ var _aws_amplify_core__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! @aws-amplify/core */ "@aws-amplify/core");
12920
+ /* harmony import */ var _aws_amplify_core__WEBPACK_IMPORTED_MODULE_5___default = /*#__PURE__*/__webpack_require__.n(_aws_amplify_core__WEBPACK_IMPORTED_MODULE_5__);
12921
+ /* harmony import */ var _utils_ConnectionStateMonitor__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ../utils/ConnectionStateMonitor */ "../pubsub/lib-esm/utils/ConnectionStateMonitor.js");
12922
+ /* harmony import */ var _utils_ReconnectionMonitor__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ../utils/ReconnectionMonitor */ "../pubsub/lib-esm/utils/ReconnectionMonitor.js");
12923
+ /* harmony import */ var _constants__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ./constants */ "../pubsub/lib-esm/Providers/constants.js");
13006
12924
  function _typeof(obj) {
13007
12925
  "@babel/helpers - typeof";
13008
12926
 
@@ -13229,7 +13147,11 @@ var __rest = undefined && undefined.__rest || function (s, e) {
13229
13147
 
13230
13148
 
13231
13149
 
13232
- var logger = new _aws_amplify_core__WEBPACK_IMPORTED_MODULE_4__["ConsoleLogger"]('MqttOverWSProvider');
13150
+
13151
+
13152
+
13153
+
13154
+ var logger = new _aws_amplify_core__WEBPACK_IMPORTED_MODULE_5__["ConsoleLogger"]('MqttOverWSProvider');
13233
13155
  function mqttTopicMatch(filter, topic) {
13234
13156
  var filterArray = filter.split('/');
13235
13157
  var length = filterArray.length;
@@ -13255,18 +13177,21 @@ function () {
13255
13177
  ClientsQueue.prototype.get = function (clientId, clientFactory) {
13256
13178
  return __awaiter(this, void 0, void 0, function () {
13257
13179
  var cachedPromise, newPromise;
13180
+
13181
+ var _this = this;
13182
+
13258
13183
  return __generator(this, function (_a) {
13259
13184
  cachedPromise = this.promises.get(clientId);
13260
-
13261
- if (cachedPromise) {
13262
- return [2
13263
- /*return*/
13264
- , cachedPromise];
13265
- }
13185
+ if (cachedPromise) return [2
13186
+ /*return*/
13187
+ , cachedPromise];
13266
13188
 
13267
13189
  if (clientFactory) {
13268
13190
  newPromise = clientFactory(clientId);
13269
13191
  this.promises.set(clientId, newPromise);
13192
+ newPromise["catch"](function (v) {
13193
+ return _this.promises["delete"](clientId);
13194
+ });
13270
13195
  return [2
13271
13196
  /*return*/
13272
13197
  , newPromise];
@@ -13294,6 +13219,14 @@ function () {
13294
13219
  return ClientsQueue;
13295
13220
  }();
13296
13221
 
13222
+ var dispatchPubSubEvent = function dispatchPubSubEvent(event, data, message) {
13223
+ _aws_amplify_core__WEBPACK_IMPORTED_MODULE_5__["Hub"].dispatch('pubsub', {
13224
+ event: event,
13225
+ data: data,
13226
+ message: message
13227
+ }, 'PubSub', _constants__WEBPACK_IMPORTED_MODULE_8__["AMPLIFY_SYMBOL"]);
13228
+ };
13229
+
13297
13230
  var topicSymbol = typeof Symbol !== 'undefined' ? Symbol('topic') : '@@topic';
13298
13231
 
13299
13232
  var MqttOverWSProvider =
@@ -13311,8 +13244,26 @@ function (_super) {
13311
13244
  })) || this;
13312
13245
 
13313
13246
  _this._clientsQueue = new ClientsQueue();
13247
+ _this.connectionStateMonitor = new _utils_ConnectionStateMonitor__WEBPACK_IMPORTED_MODULE_6__["ConnectionStateMonitor"]();
13248
+ _this.reconnectionMonitor = new _utils_ReconnectionMonitor__WEBPACK_IMPORTED_MODULE_7__["ReconnectionMonitor"]();
13314
13249
  _this._topicObservers = new Map();
13315
- _this._clientIdObservers = new Map();
13250
+ _this._clientIdObservers = new Map(); // Monitor the connection health state and pass changes along to Hub
13251
+
13252
+ _this.connectionStateMonitor.connectionStateObservable.subscribe(function (connectionStateChange) {
13253
+ dispatchPubSubEvent(_constants__WEBPACK_IMPORTED_MODULE_8__["CONNECTION_STATE_CHANGE"], {
13254
+ provider: _this,
13255
+ connectionState: connectionStateChange
13256
+ }, "Connection state is " + connectionStateChange);
13257
+ _this.connectionState = connectionStateChange; // Trigger reconnection when the connection is disrupted
13258
+
13259
+ if (connectionStateChange === _types_PubSub__WEBPACK_IMPORTED_MODULE_4__["ConnectionState"].ConnectionDisrupted) {
13260
+ _this.reconnectionMonitor.record(_utils_ReconnectionMonitor__WEBPACK_IMPORTED_MODULE_7__["ReconnectEvent"].START_RECONNECT);
13261
+ } else if (connectionStateChange !== _types_PubSub__WEBPACK_IMPORTED_MODULE_4__["ConnectionState"].Connecting) {
13262
+ // Trigger connected to halt reconnection attempts
13263
+ _this.reconnectionMonitor.record(_utils_ReconnectionMonitor__WEBPACK_IMPORTED_MODULE_7__["ReconnectEvent"].HALT_RECONNECT);
13264
+ }
13265
+ });
13266
+
13316
13267
  return _this;
13317
13268
  }
13318
13269
 
@@ -13354,8 +13305,6 @@ function (_super) {
13354
13305
  };
13355
13306
 
13356
13307
  MqttOverWSProvider.prototype.onDisconnect = function (_a) {
13357
- var _this = this;
13358
-
13359
13308
  var clientId = _a.clientId,
13360
13309
  errorCode = _a.errorCode,
13361
13310
  args = __rest(_a, ["clientId", "errorCode"]);
@@ -13364,7 +13313,6 @@ function (_super) {
13364
13313
  logger.warn(clientId, JSON.stringify(__assign({
13365
13314
  errorCode: errorCode
13366
13315
  }, args), null, 2));
13367
- var topicsToDelete_1 = [];
13368
13316
 
13369
13317
  if (!clientId) {
13370
13318
  return;
@@ -13376,24 +13324,7 @@ function (_super) {
13376
13324
  return;
13377
13325
  }
13378
13326
 
13379
- clientIdObservers.forEach(function (observer) {
13380
- observer.error('Disconnected, error code: ' + errorCode); // removing observers for disconnected clientId
13381
-
13382
- _this._topicObservers.forEach(function (observerForTopic, observerTopic) {
13383
- observerForTopic["delete"](observer);
13384
-
13385
- if (observerForTopic.size === 0) {
13386
- topicsToDelete_1.push(observerTopic);
13387
- }
13388
- });
13389
- }); // forgiving any trace of clientId
13390
-
13391
- this._clientIdObservers["delete"](clientId); // Removing topics that are not listen by an observer
13392
-
13393
-
13394
- topicsToDelete_1.forEach(function (topic) {
13395
- _this._topicObservers["delete"](topic);
13396
- });
13327
+ this.disconnect(clientId);
13397
13328
  }
13398
13329
  };
13399
13330
 
@@ -13401,7 +13332,7 @@ function (_super) {
13401
13332
  var url = _a.url,
13402
13333
  clientId = _a.clientId;
13403
13334
  return __awaiter(this, void 0, void 0, function () {
13404
- var client;
13335
+ var client, connected;
13405
13336
 
13406
13337
  var _this = this;
13407
13338
 
@@ -13409,7 +13340,8 @@ function (_super) {
13409
13340
  switch (_b.label) {
13410
13341
  case 0:
13411
13342
  logger.debug('Creating new MQTT client', clientId);
13412
- client = new paho_mqtt__WEBPACK_IMPORTED_MODULE_0__["Client"](url, clientId); // client.trace = (args) => logger.debug(clientId, JSON.stringify(args, null, 2));
13343
+ this.connectionStateMonitor.record(_utils_ConnectionStateMonitor__WEBPACK_IMPORTED_MODULE_6__["CONNECTION_CHANGE"].OPENING_CONNECTION);
13344
+ client = new paho_mqtt__WEBPACK_IMPORTED_MODULE_0__["Client"](url, clientId);
13413
13345
 
13414
13346
  client.onMessageArrived = function (_a) {
13415
13347
  var topic = _a.destinationName,
@@ -13426,6 +13358,8 @@ function (_super) {
13426
13358
  clientId: clientId,
13427
13359
  errorCode: errorCode
13428
13360
  }, args));
13361
+
13362
+ _this.connectionStateMonitor.record(_utils_ConnectionStateMonitor__WEBPACK_IMPORTED_MODULE_6__["CONNECTION_CHANGE"].CLOSED);
13429
13363
  };
13430
13364
 
13431
13365
  return [4
@@ -13435,14 +13369,24 @@ function (_super) {
13435
13369
  useSSL: _this.isSSLEnabled,
13436
13370
  mqttVersion: 3,
13437
13371
  onSuccess: function onSuccess() {
13438
- return resolve(client);
13372
+ return resolve(true);
13439
13373
  },
13440
- onFailure: reject
13374
+ onFailure: function onFailure(x) {
13375
+ if (clientId) _this._clientsQueue.remove(clientId);
13376
+
13377
+ _this.connectionStateMonitor.record(_utils_ConnectionStateMonitor__WEBPACK_IMPORTED_MODULE_6__["CONNECTION_CHANGE"].CLOSED);
13378
+
13379
+ resolve(false);
13380
+ }
13441
13381
  });
13442
13382
  })];
13443
13383
 
13444
13384
  case 1:
13445
- _b.sent();
13385
+ connected = _b.sent();
13386
+
13387
+ if (connected) {
13388
+ this.connectionStateMonitor.record(_utils_ConnectionStateMonitor__WEBPACK_IMPORTED_MODULE_6__["CONNECTION_CHANGE"].CONNECTION_ESTABLISHED);
13389
+ }
13446
13390
 
13447
13391
  return [2
13448
13392
  /*return*/
@@ -13466,9 +13410,33 @@ function (_super) {
13466
13410
  return [4
13467
13411
  /*yield*/
13468
13412
  , this.clientsQueue.get(clientId, function (clientId) {
13469
- return _this.newClient(__assign(__assign({}, options), {
13470
- clientId: clientId
13471
- }));
13413
+ return __awaiter(_this, void 0, void 0, function () {
13414
+ var client;
13415
+ return __generator(this, function (_a) {
13416
+ switch (_a.label) {
13417
+ case 0:
13418
+ return [4
13419
+ /*yield*/
13420
+ , this.newClient(__assign(__assign({}, options), {
13421
+ clientId: clientId
13422
+ }))];
13423
+
13424
+ case 1:
13425
+ client = _a.sent();
13426
+
13427
+ if (client) {
13428
+ // Once connected, subscribe to all topics registered observers
13429
+ this._topicObservers.forEach(function (_value, key) {
13430
+ client.subscribe(key);
13431
+ });
13432
+ }
13433
+
13434
+ return [2
13435
+ /*return*/
13436
+ , client];
13437
+ }
13438
+ });
13439
+ });
13472
13440
  })];
13473
13441
 
13474
13442
  case 1:
@@ -13498,6 +13466,7 @@ function (_super) {
13498
13466
  }
13499
13467
 
13500
13468
  this.clientsQueue.remove(clientId);
13469
+ this.connectionStateMonitor.record(_utils_ConnectionStateMonitor__WEBPACK_IMPORTED_MODULE_6__["CONNECTION_CHANGE"].CLOSED);
13501
13470
  return [2
13502
13471
  /*return*/
13503
13472
  ];
@@ -13508,7 +13477,7 @@ function (_super) {
13508
13477
 
13509
13478
  MqttOverWSProvider.prototype.publish = function (topics, msg) {
13510
13479
  return __awaiter(this, void 0, void 0, function () {
13511
- var targetTopics, message, url, client;
13480
+ var targetTopics, message, client;
13512
13481
  return __generator(this, function (_a) {
13513
13482
  switch (_a.label) {
13514
13483
  case 0:
@@ -13516,24 +13485,22 @@ function (_super) {
13516
13485
  message = JSON.stringify(msg);
13517
13486
  return [4
13518
13487
  /*yield*/
13519
- , this.endpoint];
13488
+ , this.clientsQueue.get(this.clientId)];
13520
13489
 
13521
13490
  case 1:
13522
- url = _a.sent();
13523
- return [4
13524
- /*yield*/
13525
- , this.connect(this.clientId, {
13526
- url: url
13527
- })];
13528
-
13529
- case 2:
13530
13491
  client = _a.sent();
13531
- logger.debug('Publishing to topic(s)', targetTopics.join(','), message);
13532
- targetTopics.forEach(function (topic) {
13533
- return client.send(topic, message);
13534
- });
13535
- return [2
13536
- /*return*/
13492
+
13493
+ if (client) {
13494
+ logger.debug('Publishing to topic(s)', targetTopics.join(','), message);
13495
+ targetTopics.forEach(function (topic) {
13496
+ return client.send(topic, message);
13497
+ });
13498
+ } else {
13499
+ logger.debug('Publishing to topic(s) failed', targetTopics.join(','), message);
13500
+ }
13501
+
13502
+ return [2
13503
+ /*return*/
13537
13504
  ];
13538
13505
  }
13539
13506
  });
@@ -13575,6 +13542,7 @@ function (_super) {
13575
13542
 
13576
13543
  var targetTopics = [].concat(topics);
13577
13544
  logger.debug('Subscribing to topic(s)', targetTopics.join(','));
13545
+ var reconnectSubscription;
13578
13546
  return new zen_observable_ts__WEBPACK_IMPORTED_MODULE_2__["default"](function (observer) {
13579
13547
  targetTopics.forEach(function (topic) {
13580
13548
  // this._topicObservers is used to notify the observers according to the topic received on the message
@@ -13587,9 +13555,7 @@ function (_super) {
13587
13555
  }
13588
13556
 
13589
13557
  observersForTopic.add(observer);
13590
- }); // @ts-ignore
13591
-
13592
- var client;
13558
+ });
13593
13559
  var _a = options.clientId,
13594
13560
  clientId = _a === void 0 ? _this.clientId : _a; // this._clientIdObservers is used to close observers when client gets disconnected
13595
13561
 
@@ -13605,59 +13571,92 @@ function (_super) {
13605
13571
 
13606
13572
  (function () {
13607
13573
  return __awaiter(_this, void 0, void 0, function () {
13608
- var _a, url, _b, e_1;
13574
+ var getClient;
13609
13575
 
13610
- return __generator(this, function (_c) {
13611
- switch (_c.label) {
13576
+ var _this = this;
13577
+
13578
+ return __generator(this, function (_a) {
13579
+ switch (_a.label) {
13612
13580
  case 0:
13613
- _a = options.url;
13614
- if (!(_a === void 0)) return [3
13615
- /*break*/
13616
- , 2];
13617
- return [4
13618
- /*yield*/
13619
- , this.endpoint];
13581
+ getClient = function getClient() {
13582
+ return __awaiter(_this, void 0, void 0, function () {
13583
+ var _a, url, _b, client_1, e_1;
13620
13584
 
13621
- case 1:
13622
- _b = _c.sent();
13623
- return [3
13624
- /*break*/
13625
- , 3];
13585
+ return __generator(this, function (_c) {
13586
+ switch (_c.label) {
13587
+ case 0:
13588
+ _c.trys.push([0, 5,, 6]);
13626
13589
 
13627
- case 2:
13628
- _b = _a;
13629
- _c.label = 3;
13590
+ _a = options.url;
13591
+ if (!(_a === void 0)) return [3
13592
+ /*break*/
13593
+ , 2];
13594
+ return [4
13595
+ /*yield*/
13596
+ , this.endpoint];
13597
+
13598
+ case 1:
13599
+ _b = _c.sent();
13600
+ return [3
13601
+ /*break*/
13602
+ , 3];
13630
13603
 
13631
- case 3:
13632
- url = _b;
13633
- _c.label = 4;
13604
+ case 2:
13605
+ _b = _a;
13606
+ _c.label = 3;
13607
+
13608
+ case 3:
13609
+ url = _b;
13610
+ return [4
13611
+ /*yield*/
13612
+ , this.connect(clientId, {
13613
+ url: url
13614
+ })];
13615
+
13616
+ case 4:
13617
+ client_1 = _c.sent();
13618
+
13619
+ if (client_1 !== undefined) {
13620
+ targetTopics.forEach(function (topic) {
13621
+ client_1.subscribe(topic);
13622
+ });
13623
+ }
13624
+
13625
+ return [3
13626
+ /*break*/
13627
+ , 6];
13628
+
13629
+ case 5:
13630
+ e_1 = _c.sent();
13631
+ logger.debug('Error forming connection', e_1);
13632
+ return [3
13633
+ /*break*/
13634
+ , 6];
13635
+
13636
+ case 6:
13637
+ return [2
13638
+ /*return*/
13639
+ ];
13640
+ }
13641
+ });
13642
+ });
13643
+ }; // Establish the initial connection
13634
13644
 
13635
- case 4:
13636
- _c.trys.push([4, 6,, 7]);
13637
13645
 
13638
13646
  return [4
13639
13647
  /*yield*/
13640
- , this.connect(clientId, {
13641
- url: url
13642
- })];
13648
+ , getClient()];
13643
13649
 
13644
- case 5:
13645
- client = _c.sent();
13646
- targetTopics.forEach(function (topic) {
13647
- client.subscribe(topic);
13648
- });
13649
- return [3
13650
- /*break*/
13651
- , 7];
13650
+ case 1:
13651
+ // Establish the initial connection
13652
+ _a.sent(); // Add an observable to the reconnection list to manage reconnection for this subscription
13652
13653
 
13653
- case 6:
13654
- e_1 = _c.sent();
13655
- observer.error(e_1);
13656
- return [3
13657
- /*break*/
13658
- , 7];
13659
13654
 
13660
- case 7:
13655
+ reconnectSubscription = new zen_observable_ts__WEBPACK_IMPORTED_MODULE_2__["default"](function (observer) {
13656
+ _this.reconnectionMonitor.addObserver(observer);
13657
+ }).subscribe(function () {
13658
+ getClient();
13659
+ });
13661
13660
  return [2
13662
13661
  /*return*/
13663
13662
  ];
@@ -13667,34 +13666,54 @@ function (_super) {
13667
13666
  })();
13668
13667
 
13669
13668
  return function () {
13670
- var _a, _b;
13669
+ return __awaiter(_this, void 0, void 0, function () {
13670
+ var client;
13671
13671
 
13672
- logger.debug('Unsubscribing from topic(s)', targetTopics.join(','));
13672
+ var _this = this;
13673
13673
 
13674
- if (client) {
13675
- (_a = _this._clientIdObservers.get(clientId)) === null || _a === void 0 ? void 0 : _a["delete"](observer); // No more observers per client => client not needed anymore
13674
+ var _a, _b;
13676
13675
 
13677
- if (((_b = _this._clientIdObservers.get(clientId)) === null || _b === void 0 ? void 0 : _b.size) === 0) {
13678
- _this.disconnect(clientId);
13676
+ return __generator(this, function (_c) {
13677
+ switch (_c.label) {
13678
+ case 0:
13679
+ return [4
13680
+ /*yield*/
13681
+ , this.clientsQueue.get(clientId)];
13679
13682
 
13680
- _this._clientIdObservers["delete"](clientId);
13681
- }
13683
+ case 1:
13684
+ client = _c.sent();
13685
+ reconnectSubscription === null || reconnectSubscription === void 0 ? void 0 : reconnectSubscription.unsubscribe();
13682
13686
 
13683
- targetTopics.forEach(function (topic) {
13684
- var observersForTopic = _this._topicObservers.get(topic) || new Set();
13685
- observersForTopic["delete"](observer); // if no observers exists for the topic, topic should be removed
13687
+ if (client) {
13688
+ (_a = this._clientIdObservers.get(clientId)) === null || _a === void 0 ? void 0 : _a["delete"](observer); // No more observers per client => client not needed anymore
13686
13689
 
13687
- if (observersForTopic.size === 0) {
13688
- _this._topicObservers["delete"](topic);
13690
+ if (((_b = this._clientIdObservers.get(clientId)) === null || _b === void 0 ? void 0 : _b.size) === 0) {
13691
+ this.disconnect(clientId);
13692
+ this.connectionStateMonitor.record(_utils_ConnectionStateMonitor__WEBPACK_IMPORTED_MODULE_6__["CONNECTION_CHANGE"].CLOSING_CONNECTION);
13689
13693
 
13690
- if (client.isConnected()) {
13691
- client.unsubscribe(topic);
13692
- }
13694
+ this._clientIdObservers["delete"](clientId);
13695
+ }
13696
+
13697
+ targetTopics.forEach(function (topic) {
13698
+ var observersForTopic = _this._topicObservers.get(topic) || new Set();
13699
+ observersForTopic["delete"](observer); // if no observers exists for the topic, topic should be removed
13700
+
13701
+ if (observersForTopic.size === 0) {
13702
+ _this._topicObservers["delete"](topic);
13703
+
13704
+ if (client.isConnected()) {
13705
+ client.unsubscribe(topic);
13706
+ }
13707
+ }
13708
+ });
13709
+ }
13710
+
13711
+ return [2
13712
+ /*return*/
13713
+ , null];
13693
13714
  }
13694
13715
  });
13695
- }
13696
-
13697
- return null;
13716
+ });
13698
13717
  };
13699
13718
  });
13700
13719
  };
@@ -13774,6 +13793,151 @@ function () {
13774
13793
 
13775
13794
 
13776
13795
 
13796
+ /***/ }),
13797
+
13798
+ /***/ "../pubsub/lib-esm/Providers/constants.js":
13799
+ /*!************************************************!*\
13800
+ !*** ../pubsub/lib-esm/Providers/constants.js ***!
13801
+ \************************************************/
13802
+ /*! 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, RECONNECT_DELAY, RECONNECT_INTERVAL */
13803
+ /***/ (function(module, __webpack_exports__, __webpack_require__) {
13804
+
13805
+ "use strict";
13806
+ __webpack_require__.r(__webpack_exports__);
13807
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "MAX_DELAY_MS", function() { return MAX_DELAY_MS; });
13808
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "NON_RETRYABLE_CODES", function() { return NON_RETRYABLE_CODES; });
13809
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "CONNECTION_STATE_CHANGE", function() { return CONNECTION_STATE_CHANGE; });
13810
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "MESSAGE_TYPES", function() { return MESSAGE_TYPES; });
13811
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "SUBSCRIPTION_STATUS", function() { return SUBSCRIPTION_STATUS; });
13812
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "SOCKET_STATUS", function() { return SOCKET_STATUS; });
13813
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "AMPLIFY_SYMBOL", function() { return AMPLIFY_SYMBOL; });
13814
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "AWS_APPSYNC_REALTIME_HEADERS", function() { return AWS_APPSYNC_REALTIME_HEADERS; });
13815
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "CONNECTION_INIT_TIMEOUT", function() { return CONNECTION_INIT_TIMEOUT; });
13816
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "START_ACK_TIMEOUT", function() { return START_ACK_TIMEOUT; });
13817
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "DEFAULT_KEEP_ALIVE_TIMEOUT", function() { return DEFAULT_KEEP_ALIVE_TIMEOUT; });
13818
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "DEFAULT_KEEP_ALIVE_ALERT_TIMEOUT", function() { return DEFAULT_KEEP_ALIVE_ALERT_TIMEOUT; });
13819
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "RECONNECT_DELAY", function() { return RECONNECT_DELAY; });
13820
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "RECONNECT_INTERVAL", function() { return RECONNECT_INTERVAL; });
13821
+ var MAX_DELAY_MS = 5000;
13822
+ var NON_RETRYABLE_CODES = [400, 401, 403];
13823
+ var CONNECTION_STATE_CHANGE = 'ConnectionStateChange';
13824
+ var MESSAGE_TYPES;
13825
+
13826
+ (function (MESSAGE_TYPES) {
13827
+ /**
13828
+ * Client -> Server message.
13829
+ * This message type is the first message after handshake and this will initialize AWS AppSync RealTime communication
13830
+ */
13831
+ MESSAGE_TYPES["GQL_CONNECTION_INIT"] = "connection_init";
13832
+ /**
13833
+ * Server -> Client message
13834
+ * This message type is in case there is an issue with AWS AppSync RealTime when establishing connection
13835
+ */
13836
+
13837
+ MESSAGE_TYPES["GQL_CONNECTION_ERROR"] = "connection_error";
13838
+ /**
13839
+ * Server -> Client message.
13840
+ * This message type is for the ack response from AWS AppSync RealTime for GQL_CONNECTION_INIT message
13841
+ */
13842
+
13843
+ MESSAGE_TYPES["GQL_CONNECTION_ACK"] = "connection_ack";
13844
+ /**
13845
+ * Client -> Server message.
13846
+ * This message type is for register subscriptions with AWS AppSync RealTime
13847
+ */
13848
+
13849
+ MESSAGE_TYPES["GQL_START"] = "start";
13850
+ /**
13851
+ * Server -> Client message.
13852
+ * This message type is for the ack response from AWS AppSync RealTime for GQL_START message
13853
+ */
13854
+
13855
+ MESSAGE_TYPES["GQL_START_ACK"] = "start_ack";
13856
+ /**
13857
+ * Server -> Client message.
13858
+ * This message type is for subscription message from AWS AppSync RealTime
13859
+ */
13860
+
13861
+ MESSAGE_TYPES["GQL_DATA"] = "data";
13862
+ /**
13863
+ * Server -> Client message.
13864
+ * This message type helps the client to know is still receiving messages from AWS AppSync RealTime
13865
+ */
13866
+
13867
+ MESSAGE_TYPES["GQL_CONNECTION_KEEP_ALIVE"] = "ka";
13868
+ /**
13869
+ * Client -> Server message.
13870
+ * This message type is for unregister subscriptions with AWS AppSync RealTime
13871
+ */
13872
+
13873
+ MESSAGE_TYPES["GQL_STOP"] = "stop";
13874
+ /**
13875
+ * Server -> Client message.
13876
+ * This message type is for the ack response from AWS AppSync RealTime for GQL_STOP message
13877
+ */
13878
+
13879
+ MESSAGE_TYPES["GQL_COMPLETE"] = "complete";
13880
+ /**
13881
+ * Server -> Client message.
13882
+ * This message type is for sending error messages from AWS AppSync RealTime to the client
13883
+ */
13884
+
13885
+ MESSAGE_TYPES["GQL_ERROR"] = "error";
13886
+ })(MESSAGE_TYPES || (MESSAGE_TYPES = {}));
13887
+
13888
+ var SUBSCRIPTION_STATUS;
13889
+
13890
+ (function (SUBSCRIPTION_STATUS) {
13891
+ SUBSCRIPTION_STATUS[SUBSCRIPTION_STATUS["PENDING"] = 0] = "PENDING";
13892
+ SUBSCRIPTION_STATUS[SUBSCRIPTION_STATUS["CONNECTED"] = 1] = "CONNECTED";
13893
+ SUBSCRIPTION_STATUS[SUBSCRIPTION_STATUS["FAILED"] = 2] = "FAILED";
13894
+ })(SUBSCRIPTION_STATUS || (SUBSCRIPTION_STATUS = {}));
13895
+
13896
+ var SOCKET_STATUS;
13897
+
13898
+ (function (SOCKET_STATUS) {
13899
+ SOCKET_STATUS[SOCKET_STATUS["CLOSED"] = 0] = "CLOSED";
13900
+ SOCKET_STATUS[SOCKET_STATUS["READY"] = 1] = "READY";
13901
+ SOCKET_STATUS[SOCKET_STATUS["CONNECTING"] = 2] = "CONNECTING";
13902
+ })(SOCKET_STATUS || (SOCKET_STATUS = {}));
13903
+
13904
+ var AMPLIFY_SYMBOL = typeof Symbol !== 'undefined' && typeof Symbol["for"] === 'function' ? Symbol["for"]('amplify_default') : '@@amplify_default';
13905
+ var AWS_APPSYNC_REALTIME_HEADERS = {
13906
+ accept: 'application/json, text/javascript',
13907
+ 'content-encoding': 'amz-1.0',
13908
+ 'content-type': 'application/json; charset=UTF-8'
13909
+ };
13910
+ /**
13911
+ * Time in milleseconds to wait for GQL_CONNECTION_INIT message
13912
+ */
13913
+
13914
+ var CONNECTION_INIT_TIMEOUT = 15000;
13915
+ /**
13916
+ * Time in milleseconds to wait for GQL_START_ACK message
13917
+ */
13918
+
13919
+ var START_ACK_TIMEOUT = 15000;
13920
+ /**
13921
+ * Default Time in milleseconds to wait for GQL_CONNECTION_KEEP_ALIVE message
13922
+ */
13923
+
13924
+ var DEFAULT_KEEP_ALIVE_TIMEOUT = 5 * 60 * 1000;
13925
+ /**
13926
+ * Default Time in milleseconds to alert for missed GQL_CONNECTION_KEEP_ALIVE message
13927
+ */
13928
+
13929
+ var DEFAULT_KEEP_ALIVE_ALERT_TIMEOUT = 65 * 1000;
13930
+ /**
13931
+ * Default delay time in milleseconds between when reconnect is triggered vs when it is attempted
13932
+ */
13933
+
13934
+ var RECONNECT_DELAY = 5 * 1000;
13935
+ /**
13936
+ * Default interval time in milleseconds between when reconnect is re-attempted
13937
+ */
13938
+
13939
+ var RECONNECT_INTERVAL = 60 * 1000;
13940
+
13777
13941
  /***/ }),
13778
13942
 
13779
13943
  /***/ "../pubsub/lib-esm/Providers/index.js":
@@ -14207,13 +14371,11 @@ _aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__["Amplify"].register(PubSub);
14207
14371
  /*!**********************************!*\
14208
14372
  !*** ../pubsub/lib-esm/index.js ***!
14209
14373
  \**********************************/
14210
- /*! exports provided: AbstractPubSubProvider, AWSAppSyncProvider, AWSAppSyncRealTimeProvider, AWSIoTProvider, mqttTopicMatch, MqttOverWSProvider, CONNECTION_STATE_CHANGE, ConnectionState, PubSub, CONTROL_MSG, default */
14374
+ /*! exports provided: AbstractPubSubProvider, AWSAppSyncProvider, AWSAppSyncRealTimeProvider, AWSIoTProvider, mqttTopicMatch, MqttOverWSProvider, CONNECTION_STATE_CHANGE, ConnectionState, CONTROL_MSG, PubSub, default */
14211
14375
  /***/ (function(module, __webpack_exports__, __webpack_require__) {
14212
14376
 
14213
14377
  "use strict";
14214
14378
  __webpack_require__.r(__webpack_exports__);
14215
- /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "CONNECTION_STATE_CHANGE", function() { return CONNECTION_STATE_CHANGE; });
14216
- /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "CONTROL_MSG", function() { return CONTROL_MSG; });
14217
14379
  /* harmony import */ var _PubSub__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./PubSub */ "../pubsub/lib-esm/PubSub.js");
14218
14380
  /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "PubSub", function() { return _PubSub__WEBPACK_IMPORTED_MODULE_0__["PubSub"]; });
14219
14381
 
@@ -14230,8 +14392,13 @@ __webpack_require__.r(__webpack_exports__);
14230
14392
 
14231
14393
  /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MqttOverWSProvider", function() { return _Providers__WEBPACK_IMPORTED_MODULE_1__["MqttOverWSProvider"]; });
14232
14394
 
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"]; });
14395
+ /* harmony import */ var _Providers_constants__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./Providers/constants */ "../pubsub/lib-esm/Providers/constants.js");
14396
+ /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "CONNECTION_STATE_CHANGE", function() { return _Providers_constants__WEBPACK_IMPORTED_MODULE_2__["CONNECTION_STATE_CHANGE"]; });
14397
+
14398
+ /* harmony import */ var _types__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./types */ "../pubsub/lib-esm/types/index.js");
14399
+ /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "ConnectionState", function() { return _types__WEBPACK_IMPORTED_MODULE_3__["ConnectionState"]; });
14400
+
14401
+ /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "CONTROL_MSG", function() { return _types__WEBPACK_IMPORTED_MODULE_3__["CONTROL_MSG"]; });
14235
14402
 
14236
14403
  /*
14237
14404
  * Copyright 2017-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
@@ -14247,17 +14414,7 @@ __webpack_require__.r(__webpack_exports__);
14247
14414
  */
14248
14415
 
14249
14416
 
14250
- var CONTROL_MSG;
14251
-
14252
- (function (CONTROL_MSG) {
14253
- CONTROL_MSG["CONNECTION_CLOSED"] = "Connection closed";
14254
- CONTROL_MSG["CONNECTION_FAILED"] = "Connection failed";
14255
- CONTROL_MSG["REALTIME_SUBSCRIPTION_INIT_ERROR"] = "AppSync Realtime subscription init error";
14256
- CONTROL_MSG["SUBSCRIPTION_ACK"] = "Subscription ack";
14257
- CONTROL_MSG["TIMEOUT_DISCONNECT"] = "Timeout disconnect";
14258
- })(CONTROL_MSG || (CONTROL_MSG = {}));
14259
14417
 
14260
- var CONNECTION_STATE_CHANGE = 'ConnectionStateChange';
14261
14418
 
14262
14419
 
14263
14420
  /**
@@ -14268,17 +14425,41 @@ var CONNECTION_STATE_CHANGE = 'ConnectionStateChange';
14268
14425
 
14269
14426
  /***/ }),
14270
14427
 
14271
- /***/ "../pubsub/lib-esm/types/index.js":
14272
- /*!****************************************!*\
14273
- !*** ../pubsub/lib-esm/types/index.js ***!
14274
- \****************************************/
14275
- /*! exports provided: ConnectionState */
14428
+ /***/ "../pubsub/lib-esm/types/PubSub.js":
14429
+ /*!*****************************************!*\
14430
+ !*** ../pubsub/lib-esm/types/PubSub.js ***!
14431
+ \*****************************************/
14432
+ /*! exports provided: CONTROL_MSG, ConnectionState */
14276
14433
  /***/ (function(module, __webpack_exports__, __webpack_require__) {
14277
14434
 
14278
14435
  "use strict";
14279
14436
  __webpack_require__.r(__webpack_exports__);
14437
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "CONTROL_MSG", function() { return CONTROL_MSG; });
14280
14438
  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "ConnectionState", function() { return ConnectionState; });
14439
+ /*
14440
+ * Copyright 2017-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
14441
+ *
14442
+ * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
14443
+ * the License. A copy of the License is located at
14444
+ *
14445
+ * http://aws.amazon.com/apache2.0/
14446
+ *
14447
+ * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
14448
+ * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
14449
+ * and limitations under the License.
14450
+ */
14451
+ var CONTROL_MSG;
14452
+
14453
+ (function (CONTROL_MSG) {
14454
+ CONTROL_MSG["CONNECTION_CLOSED"] = "Connection closed";
14455
+ CONTROL_MSG["CONNECTION_FAILED"] = "Connection failed";
14456
+ CONTROL_MSG["REALTIME_SUBSCRIPTION_INIT_ERROR"] = "AppSync Realtime subscription init error";
14457
+ CONTROL_MSG["SUBSCRIPTION_ACK"] = "Subscription ack";
14458
+ CONTROL_MSG["TIMEOUT_DISCONNECT"] = "Timeout disconnect";
14459
+ })(CONTROL_MSG || (CONTROL_MSG = {}));
14281
14460
  /** @enum {string} */
14461
+
14462
+
14282
14463
  var ConnectionState;
14283
14464
 
14284
14465
  (function (ConnectionState) {
@@ -14323,6 +14504,24 @@ var ConnectionState;
14323
14504
  ConnectionState["ConnectedPendingKeepAlive"] = "ConnectedPendingKeepAlive";
14324
14505
  })(ConnectionState || (ConnectionState = {}));
14325
14506
 
14507
+ /***/ }),
14508
+
14509
+ /***/ "../pubsub/lib-esm/types/index.js":
14510
+ /*!****************************************!*\
14511
+ !*** ../pubsub/lib-esm/types/index.js ***!
14512
+ \****************************************/
14513
+ /*! exports provided: CONTROL_MSG, ConnectionState */
14514
+ /***/ (function(module, __webpack_exports__, __webpack_require__) {
14515
+
14516
+ "use strict";
14517
+ __webpack_require__.r(__webpack_exports__);
14518
+ /* harmony import */ var _PubSub__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./PubSub */ "../pubsub/lib-esm/types/PubSub.js");
14519
+ /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "CONTROL_MSG", function() { return _PubSub__WEBPACK_IMPORTED_MODULE_0__["CONTROL_MSG"]; });
14520
+
14521
+ /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "ConnectionState", function() { return _PubSub__WEBPACK_IMPORTED_MODULE_0__["ConnectionState"]; });
14522
+
14523
+
14524
+
14326
14525
  /***/ }),
14327
14526
 
14328
14527
  /***/ "../pubsub/lib-esm/utils/ConnectionStateMonitor.js":
@@ -14336,10 +14535,9 @@ var ConnectionState;
14336
14535
  __webpack_require__.r(__webpack_exports__);
14337
14536
  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "CONNECTION_CHANGE", function() { return CONNECTION_CHANGE; });
14338
14537
  /* 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");
14538
+ /* harmony import */ var zen_observable_ts__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! zen-observable-ts */ "../../node_modules/zen-observable-ts/lib/bundle.esm.js");
14539
+ /* harmony import */ var _types_PubSub__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../types/PubSub */ "../pubsub/lib-esm/types/PubSub.js");
14540
+ /* harmony import */ var _ReachabilityMonitor__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./ReachabilityMonitor */ "../pubsub/lib-esm/utils/ReachabilityMonitor/index.js");
14343
14541
  /*
14344
14542
  * Copyright 2017-2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
14345
14543
  *
@@ -14415,8 +14613,18 @@ function () {
14415
14613
  connectionState: 'disconnected',
14416
14614
  intendedConnectionState: 'disconnected',
14417
14615
  keepAliveState: 'healthy'
14418
- };
14419
- this._linkedConnectionStateObservable = new zen_observable_ts__WEBPACK_IMPORTED_MODULE_1__["default"](function (connectionStateObserver) {
14616
+ }; // Attempt to update the state with the current actual network state
14617
+
14618
+ this._initialNetworkStateSubscription = Object(_ReachabilityMonitor__WEBPACK_IMPORTED_MODULE_2__["ReachabilityMonitor"])().subscribe(function (_a) {
14619
+ var online = _a.online;
14620
+
14621
+ var _b;
14622
+
14623
+ _this.record(online ? CONNECTION_CHANGE.ONLINE : CONNECTION_CHANGE.OFFLINE);
14624
+
14625
+ (_b = _this._initialNetworkStateSubscription) === null || _b === void 0 ? void 0 : _b.unsubscribe();
14626
+ });
14627
+ this._linkedConnectionStateObservable = new zen_observable_ts__WEBPACK_IMPORTED_MODULE_0__["default"](function (connectionStateObserver) {
14420
14628
  connectionStateObserver.next(_this._linkedConnectionState);
14421
14629
  _this._linkedConnectionStateObserver = connectionStateObserver;
14422
14630
  });
@@ -14427,11 +14635,15 @@ function () {
14427
14635
 
14428
14636
 
14429
14637
  ConnectionStateMonitor.prototype.enableNetworkMonitoring = function () {
14430
- var _this = this; // Maintain the network state based on the reachability monitor
14638
+ var _this = this;
14639
+
14640
+ var _a; // If no initial network state was discovered, stop trying
14431
14641
 
14432
14642
 
14643
+ (_a = this._initialNetworkStateSubscription) === null || _a === void 0 ? void 0 : _a.unsubscribe(); // Maintain the network state based on the reachability monitor
14644
+
14433
14645
  if (this._networkMonitoringSubscription === undefined) {
14434
- this._networkMonitoringSubscription = new _aws_amplify_core__WEBPACK_IMPORTED_MODULE_0__["Reachability"]().networkMonitor().subscribe(function (_a) {
14646
+ this._networkMonitoringSubscription = Object(_ReachabilityMonitor__WEBPACK_IMPORTED_MODULE_2__["ReachabilityMonitor"])().subscribe(function (_a) {
14435
14647
  var online = _a.online;
14436
14648
 
14437
14649
  _this.record(online ? CONNECTION_CHANGE.ONLINE : CONNECTION_CHANGE.OFFLINE);
@@ -14504,15 +14716,15 @@ function () {
14504
14716
  networkState = _a.networkState,
14505
14717
  intendedConnectionState = _a.intendedConnectionState,
14506
14718
  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;
14719
+ if (connectionState === 'connected' && networkState === 'disconnected') return _types_PubSub__WEBPACK_IMPORTED_MODULE_1__["ConnectionState"].ConnectedPendingNetwork;
14720
+ if (connectionState === 'connected' && intendedConnectionState === 'disconnected') return _types_PubSub__WEBPACK_IMPORTED_MODULE_1__["ConnectionState"].ConnectedPendingDisconnect;
14721
+ if (connectionState === 'disconnected' && intendedConnectionState === 'connected' && networkState === 'disconnected') return _types_PubSub__WEBPACK_IMPORTED_MODULE_1__["ConnectionState"].ConnectionDisruptedPendingNetwork;
14722
+ if (connectionState === 'disconnected' && intendedConnectionState === 'connected') return _types_PubSub__WEBPACK_IMPORTED_MODULE_1__["ConnectionState"].ConnectionDisrupted;
14723
+ if (connectionState === 'connected' && keepAliveState === 'unhealthy') return _types_PubSub__WEBPACK_IMPORTED_MODULE_1__["ConnectionState"].ConnectedPendingKeepAlive; // All remaining states directly correspond to the connection state
14724
+
14725
+ if (connectionState === 'connecting') return _types_PubSub__WEBPACK_IMPORTED_MODULE_1__["ConnectionState"].Connecting;
14726
+ if (connectionState === 'disconnected') return _types_PubSub__WEBPACK_IMPORTED_MODULE_1__["ConnectionState"].Disconnected;
14727
+ return _types_PubSub__WEBPACK_IMPORTED_MODULE_1__["ConnectionState"].Connected;
14516
14728
  };
14517
14729
 
14518
14730
  return ConnectionStateMonitor;
@@ -14520,6 +14732,129 @@ function () {
14520
14732
 
14521
14733
 
14522
14734
 
14735
+ /***/ }),
14736
+
14737
+ /***/ "../pubsub/lib-esm/utils/ReachabilityMonitor/index.js":
14738
+ /*!************************************************************!*\
14739
+ !*** ../pubsub/lib-esm/utils/ReachabilityMonitor/index.js ***!
14740
+ \************************************************************/
14741
+ /*! exports provided: ReachabilityMonitor */
14742
+ /***/ (function(module, __webpack_exports__, __webpack_require__) {
14743
+
14744
+ "use strict";
14745
+ __webpack_require__.r(__webpack_exports__);
14746
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "ReachabilityMonitor", function() { return ReachabilityMonitor; });
14747
+ /* harmony import */ var _aws_amplify_core__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @aws-amplify/core */ "@aws-amplify/core");
14748
+ /* harmony import */ var _aws_amplify_core__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_aws_amplify_core__WEBPACK_IMPORTED_MODULE_0__);
14749
+
14750
+ var ReachabilityMonitor = function ReachabilityMonitor() {
14751
+ return new _aws_amplify_core__WEBPACK_IMPORTED_MODULE_0__["Reachability"]().networkMonitor();
14752
+ };
14753
+
14754
+ /***/ }),
14755
+
14756
+ /***/ "../pubsub/lib-esm/utils/ReconnectionMonitor.js":
14757
+ /*!******************************************************!*\
14758
+ !*** ../pubsub/lib-esm/utils/ReconnectionMonitor.js ***!
14759
+ \******************************************************/
14760
+ /*! exports provided: ReconnectEvent, ReconnectionMonitor */
14761
+ /***/ (function(module, __webpack_exports__, __webpack_require__) {
14762
+
14763
+ "use strict";
14764
+ __webpack_require__.r(__webpack_exports__);
14765
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "ReconnectEvent", function() { return ReconnectEvent; });
14766
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "ReconnectionMonitor", function() { return ReconnectionMonitor; });
14767
+ /* harmony import */ var _Providers_constants__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../Providers/constants */ "../pubsub/lib-esm/Providers/constants.js");
14768
+
14769
+ var ReconnectEvent;
14770
+
14771
+ (function (ReconnectEvent) {
14772
+ ReconnectEvent["START_RECONNECT"] = "START_RECONNECT";
14773
+ ReconnectEvent["HALT_RECONNECT"] = "HALT_RECONNECT";
14774
+ })(ReconnectEvent || (ReconnectEvent = {}));
14775
+ /**
14776
+ * Captures the reconnect event logic used to determine when to reconnect to PubSub providers.
14777
+ * Reconnnect attempts are delayed by 5 seconds to let the interface settle.
14778
+ * Attempting to reconnect only once creates unrecoverable states when the network state isn't
14779
+ * supported by the browser, so this keeps retrying every minute until halted.
14780
+ */
14781
+
14782
+
14783
+ var ReconnectionMonitor =
14784
+ /** @class */
14785
+ function () {
14786
+ function ReconnectionMonitor() {
14787
+ this.reconnectObservers = [];
14788
+ }
14789
+ /**
14790
+ * Add reconnect observer to the list of observers to alert on reconnect
14791
+ */
14792
+
14793
+
14794
+ ReconnectionMonitor.prototype.addObserver = function (reconnectObserver) {
14795
+ this.reconnectObservers.push(reconnectObserver);
14796
+ };
14797
+ /**
14798
+ * Given a reconnect event, start the appropriate behavior
14799
+ */
14800
+
14801
+
14802
+ ReconnectionMonitor.prototype.record = function (event) {
14803
+ var _this = this;
14804
+
14805
+ if (event === ReconnectEvent.START_RECONNECT) {
14806
+ // If the reconnection hasn't been started
14807
+ if (this.reconnectSetTimeoutId === undefined && this.reconnectIntervalId === undefined) {
14808
+ this.reconnectSetTimeoutId = setTimeout(function () {
14809
+ // Reconnect now
14810
+ _this._triggerReconnect(); // Retry reconnect every periodically until it works
14811
+
14812
+
14813
+ _this.reconnectIntervalId = setInterval(function () {
14814
+ _this._triggerReconnect();
14815
+ }, _Providers_constants__WEBPACK_IMPORTED_MODULE_0__["RECONNECT_INTERVAL"]);
14816
+ }, _Providers_constants__WEBPACK_IMPORTED_MODULE_0__["RECONNECT_DELAY"]);
14817
+ }
14818
+ }
14819
+
14820
+ if (event === ReconnectEvent.HALT_RECONNECT) {
14821
+ if (this.reconnectIntervalId) {
14822
+ clearInterval(this.reconnectIntervalId);
14823
+ this.reconnectIntervalId = undefined;
14824
+ }
14825
+
14826
+ if (this.reconnectSetTimeoutId) {
14827
+ clearTimeout(this.reconnectSetTimeoutId);
14828
+ this.reconnectSetTimeoutId = undefined;
14829
+ }
14830
+ }
14831
+ };
14832
+ /**
14833
+ * Complete all reconnect observers
14834
+ */
14835
+
14836
+
14837
+ ReconnectionMonitor.prototype.close = function () {
14838
+ this.reconnectObservers.forEach(function (reconnectObserver) {
14839
+ var _a;
14840
+
14841
+ (_a = reconnectObserver.complete) === null || _a === void 0 ? void 0 : _a.call(reconnectObserver);
14842
+ });
14843
+ };
14844
+
14845
+ ReconnectionMonitor.prototype._triggerReconnect = function () {
14846
+ this.reconnectObservers.forEach(function (reconnectObserver) {
14847
+ var _a;
14848
+
14849
+ (_a = reconnectObserver.next) === null || _a === void 0 ? void 0 : _a.call(reconnectObserver);
14850
+ });
14851
+ };
14852
+
14853
+ return ReconnectionMonitor;
14854
+ }();
14855
+
14856
+
14857
+
14523
14858
  /***/ }),
14524
14859
 
14525
14860
  /***/ "./lib-esm/GraphQLAPI.js":
@@ -15326,8 +15661,8 @@ function () {
15326
15661
  } : _c;
15327
15662
  var authenticationType = defaultAuthenticationType || aws_appsync_authenticationType || 'AWS_IAM';
15328
15663
 
15329
- if (_aws_amplify_pubsub__WEBPACK_IMPORTED_MODULE_2__["default"] && typeof _aws_amplify_pubsub__WEBPACK_IMPORTED_MODULE_2__["default"].subscribe === 'function') {
15330
- return _aws_amplify_pubsub__WEBPACK_IMPORTED_MODULE_2__["default"].subscribe('', {
15664
+ if (_aws_amplify_pubsub__WEBPACK_IMPORTED_MODULE_2__["PubSub"] && typeof _aws_amplify_pubsub__WEBPACK_IMPORTED_MODULE_2__["PubSub"].subscribe === 'function') {
15665
+ return _aws_amplify_pubsub__WEBPACK_IMPORTED_MODULE_2__["PubSub"].subscribe('', {
15331
15666
  provider: _aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__["INTERNAL_AWS_APPSYNC_REALTIME_PUBSUB_PROVIDER"],
15332
15667
  appSyncGraphqlEndpoint: appSyncGraphqlEndpoint,
15333
15668
  authenticationType: authenticationType,