aws-appsync-subscription-link 3.0.9 → 3.0.10

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.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,17 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ <a name="3.0.10"></a>
7
+ ## [3.0.10](https://github.com/awslabs/aws-mobile-appsync-sdk-js/compare/aws-appsync-subscription-link@3.0.9...aws-appsync-subscription-link@3.0.10) (2022-03-04)
8
+
9
+
10
+ ### Bug Fixes
11
+
12
+ * Port over Amplify fix for subscription race conditions ([#509](https://github.com/awslabs/aws-mobile-appsync-sdk-js/issues/509)) ([#704](https://github.com/awslabs/aws-mobile-appsync-sdk-js/issues/704)) ([92b50c4](https://github.com/awslabs/aws-mobile-appsync-sdk-js/commit/92b50c4))
13
+
14
+
15
+
16
+
6
17
  <a name="3.0.9"></a>
7
18
  ## [3.0.9](https://github.com/awslabs/aws-mobile-appsync-sdk-js/compare/aws-appsync-subscription-link@3.0.8...aws-appsync-subscription-link@3.0.9) (2021-09-24)
8
19
 
@@ -16,13 +16,11 @@ export declare class AppSyncRealTimeSubscriptionHandshakeLink extends ApolloLink
16
16
  private subscriptionObserverMap;
17
17
  private promiseArray;
18
18
  constructor({ url: theUrl, region: theRegion, auth: theAuth }: UrlInfo);
19
- request(operation: Operation): Observable<FetchResult<{
20
- [key: string]: any;
21
- }, Record<string, any>, Record<string, any>>>;
19
+ request(operation: Operation): Observable<FetchResult<Record<string, any>, Record<string, any>, Record<string, any>>>;
22
20
  private _verifySubscriptionAlreadyStarted;
23
21
  private _sendUnsubscriptionMessage;
24
22
  private _removeSubscriptionObserver;
25
- private _closeSocketWhenFlushed;
23
+ private _closeSocketIfRequired;
26
24
  private _startSubscriptionWithAWSAppSyncRealTime;
27
25
  private _initializeWebSocketConnection;
28
26
  private _awsRealTimeHeaderBasedAuth;
@@ -220,22 +220,25 @@ var AppSyncRealTimeSubscriptionHandshakeLink = /** @class */ (function (_super)
220
220
  };
221
221
  AppSyncRealTimeSubscriptionHandshakeLink.prototype._removeSubscriptionObserver = function (subscriptionId) {
222
222
  this.subscriptionObserverMap.delete(subscriptionId);
223
- if (this.subscriptionObserverMap.size === 0) {
224
- // Socket could be sending data to unsubscribe so is required to wait until is flushed
225
- this._closeSocketWhenFlushed();
226
- }
223
+ // Verifying for 1000ms after removing subscription in case there are new subscriptions on mount / unmount
224
+ setTimeout(this._closeSocketIfRequired.bind(this), 1000);
227
225
  };
228
- AppSyncRealTimeSubscriptionHandshakeLink.prototype._closeSocketWhenFlushed = function () {
229
- logger("closing WebSocket...");
230
- clearTimeout(this.keepAliveTimeoutId);
226
+ AppSyncRealTimeSubscriptionHandshakeLink.prototype._closeSocketIfRequired = function () {
227
+ if (this.subscriptionObserverMap.size > 0) {
228
+ // There are active subscriptions on the WebSocket
229
+ return;
230
+ }
231
231
  if (!this.awsRealTimeSocket) {
232
232
  this.socketStatus = types_1.SOCKET_STATUS.CLOSED;
233
233
  return;
234
234
  }
235
235
  if (this.awsRealTimeSocket.bufferedAmount > 0) {
236
- setTimeout(this._closeSocketWhenFlushed.bind(this), 1000);
236
+ // There is still data on the WebSocket
237
+ setTimeout(this._closeSocketIfRequired.bind(this), 1000);
237
238
  }
238
239
  else {
240
+ logger("closing WebSocket...");
241
+ clearTimeout(this.keepAliveTimeoutId);
239
242
  var tempSocket = this.awsRealTimeSocket;
240
243
  tempSocket.close(1000);
241
244
  this.awsRealTimeSocket = null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aws-appsync-subscription-link",
3
- "version": "3.0.9",
3
+ "version": "3.0.10",
4
4
  "main": "lib/index.js",
5
5
  "license": "Apache-2.0",
6
6
  "description": "AWS Mobile AppSync SDK for JavaScript",