@aws-amplify/pubsub 4.3.1 → 4.3.2-unstable.5
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/dist/aws-amplify-pubsub.js +227 -198
- package/dist/aws-amplify-pubsub.js.map +1 -1
- package/dist/aws-amplify-pubsub.min.js +2 -2
- package/dist/aws-amplify-pubsub.min.js.map +1 -1
- package/lib/Providers/AWSAppSyncRealTimeProvider.d.ts +2 -2
- package/lib/Providers/AWSAppSyncRealTimeProvider.js +174 -154
- package/lib/Providers/AWSAppSyncRealTimeProvider.js.map +1 -1
- package/lib/Providers/MqttOverWSProvider.d.ts +4 -5
- package/lib/Providers/MqttOverWSProvider.js +17 -10
- package/lib/Providers/MqttOverWSProvider.js.map +1 -1
- package/lib-esm/Providers/AWSAppSyncRealTimeProvider.d.ts +2 -2
- package/lib-esm/Providers/AWSAppSyncRealTimeProvider.js +174 -154
- package/lib-esm/Providers/AWSAppSyncRealTimeProvider.js.map +1 -1
- package/lib-esm/Providers/MqttOverWSProvider.d.ts +4 -5
- package/lib-esm/Providers/MqttOverWSProvider.js +17 -10
- package/lib-esm/Providers/MqttOverWSProvider.js.map +1 -1
- package/package.json +5 -5
- package/src/Providers/AWSAppSyncRealTimeProvider.ts +231 -188
- package/src/Providers/MqttOverWSProvider.ts +37 -16
|
@@ -8031,9 +8031,9 @@ function (_super) {
|
|
|
8031
8031
|
AWSAppSyncRealTimeProvider.prototype.subscribe = function (_topics, options) {
|
|
8032
8032
|
var _this = this;
|
|
8033
8033
|
|
|
8034
|
-
var appSyncGraphqlEndpoint = options.appSyncGraphqlEndpoint;
|
|
8034
|
+
var appSyncGraphqlEndpoint = options === null || options === void 0 ? void 0 : options.appSyncGraphqlEndpoint;
|
|
8035
8035
|
return new zen_observable_ts__WEBPACK_IMPORTED_MODULE_0__["default"](function (observer) {
|
|
8036
|
-
if (!appSyncGraphqlEndpoint) {
|
|
8036
|
+
if (!options || !appSyncGraphqlEndpoint) {
|
|
8037
8037
|
observer.error({
|
|
8038
8038
|
errors: [__assign({}, new graphql__WEBPACK_IMPORTED_MODULE_1__["GraphQLError"]("Subscribe only available for AWS AppSync endpoint"))]
|
|
8039
8039
|
});
|
|
@@ -8126,19 +8126,22 @@ function (_super) {
|
|
|
8126
8126
|
var options = _a.options,
|
|
8127
8127
|
observer = _a.observer,
|
|
8128
8128
|
subscriptionId = _a.subscriptionId;
|
|
8129
|
+
|
|
8130
|
+
var _b, _c;
|
|
8131
|
+
|
|
8129
8132
|
return __awaiter(this, void 0, void 0, function () {
|
|
8130
|
-
var appSyncGraphqlEndpoint, authenticationType, query, variables, apiKey, region,
|
|
8133
|
+
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;
|
|
8131
8134
|
|
|
8132
|
-
var
|
|
8135
|
+
var _j;
|
|
8133
8136
|
|
|
8134
8137
|
var _this = this;
|
|
8135
8138
|
|
|
8136
|
-
return __generator(this, function (
|
|
8137
|
-
switch (
|
|
8139
|
+
return __generator(this, function (_k) {
|
|
8140
|
+
switch (_k.label) {
|
|
8138
8141
|
case 0:
|
|
8139
|
-
appSyncGraphqlEndpoint = options.appSyncGraphqlEndpoint, authenticationType = options.authenticationType, query = options.query, variables = options.variables, apiKey = options.apiKey, region = options.region,
|
|
8142
|
+
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 () {
|
|
8140
8143
|
return {};
|
|
8141
|
-
} :
|
|
8144
|
+
} : _d, _e = options.additionalHeaders, additionalHeaders = _e === void 0 ? {} : _e;
|
|
8142
8145
|
subscriptionState = SUBSCRIPTION_STATUS.PENDING;
|
|
8143
8146
|
data = {
|
|
8144
8147
|
query: query,
|
|
@@ -8147,13 +8150,13 @@ function (_super) {
|
|
|
8147
8150
|
|
|
8148
8151
|
this.subscriptionObserverMap.set(subscriptionId, {
|
|
8149
8152
|
observer: observer,
|
|
8150
|
-
query: query,
|
|
8151
|
-
variables: variables,
|
|
8153
|
+
query: query !== null && query !== void 0 ? query : '',
|
|
8154
|
+
variables: variables !== null && variables !== void 0 ? variables : {},
|
|
8152
8155
|
subscriptionState: subscriptionState,
|
|
8153
|
-
startAckTimeoutId:
|
|
8156
|
+
startAckTimeoutId: undefined
|
|
8154
8157
|
});
|
|
8155
8158
|
dataString = JSON.stringify(data);
|
|
8156
|
-
|
|
8159
|
+
_f = [{}];
|
|
8157
8160
|
return [4
|
|
8158
8161
|
/*yield*/
|
|
8159
8162
|
, this._awsRealTimeHeaderBasedAuth({
|
|
@@ -8167,13 +8170,13 @@ function (_super) {
|
|
|
8167
8170
|
})];
|
|
8168
8171
|
|
|
8169
8172
|
case 1:
|
|
8170
|
-
|
|
8173
|
+
_g = [__assign.apply(void 0, _f.concat([_k.sent()]))];
|
|
8171
8174
|
return [4
|
|
8172
8175
|
/*yield*/
|
|
8173
8176
|
, graphql_headers()];
|
|
8174
8177
|
|
|
8175
8178
|
case 2:
|
|
8176
|
-
headerObj = __assign.apply(void 0, [__assign.apply(void 0, [__assign.apply(void 0,
|
|
8179
|
+
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)]);
|
|
8177
8180
|
subscriptionMessage = {
|
|
8178
8181
|
id: subscriptionId,
|
|
8179
8182
|
payload: {
|
|
@@ -8185,10 +8188,10 @@ function (_super) {
|
|
|
8185
8188
|
type: MESSAGE_TYPES.GQL_START
|
|
8186
8189
|
};
|
|
8187
8190
|
stringToAWSRealTime = JSON.stringify(subscriptionMessage);
|
|
8188
|
-
|
|
8191
|
+
_k.label = 3;
|
|
8189
8192
|
|
|
8190
8193
|
case 3:
|
|
8191
|
-
|
|
8194
|
+
_k.trys.push([3, 5,, 6]);
|
|
8192
8195
|
|
|
8193
8196
|
return [4
|
|
8194
8197
|
/*yield*/
|
|
@@ -8201,18 +8204,18 @@ function (_super) {
|
|
|
8201
8204
|
})];
|
|
8202
8205
|
|
|
8203
8206
|
case 4:
|
|
8204
|
-
|
|
8207
|
+
_k.sent();
|
|
8205
8208
|
|
|
8206
8209
|
return [3
|
|
8207
8210
|
/*break*/
|
|
8208
8211
|
, 6];
|
|
8209
8212
|
|
|
8210
8213
|
case 5:
|
|
8211
|
-
err_2 =
|
|
8214
|
+
err_2 = _k.sent();
|
|
8212
8215
|
logger.debug({
|
|
8213
8216
|
err: err_2
|
|
8214
8217
|
});
|
|
8215
|
-
|
|
8218
|
+
message = (_b = err_2['message']) !== null && _b !== void 0 ? _b : '';
|
|
8216
8219
|
observer.error({
|
|
8217
8220
|
errors: [__assign({}, new graphql__WEBPACK_IMPORTED_MODULE_1__["GraphQLError"](_index__WEBPACK_IMPORTED_MODULE_9__["CONTROL_MSG"].CONNECTION_FAILED + ": " + message))]
|
|
8218
8221
|
});
|
|
@@ -8228,13 +8231,13 @@ function (_super) {
|
|
|
8228
8231
|
];
|
|
8229
8232
|
|
|
8230
8233
|
case 6:
|
|
8231
|
-
|
|
8234
|
+
_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
|
|
8232
8235
|
|
|
8233
8236
|
this.subscriptionObserverMap.set(subscriptionId, {
|
|
8234
8237
|
observer: observer,
|
|
8235
8238
|
subscriptionState: subscriptionState,
|
|
8236
|
-
|
|
8237
|
-
|
|
8239
|
+
query: query !== null && query !== void 0 ? query : '',
|
|
8240
|
+
variables: variables !== null && variables !== void 0 ? variables : {},
|
|
8238
8241
|
subscriptionReadyCallback: subscriptionReadyCallback,
|
|
8239
8242
|
subscriptionFailedCallback: subscriptionFailedCallback,
|
|
8240
8243
|
startAckTimeoutId: setTimeout(function () {
|
|
@@ -8257,32 +8260,35 @@ function (_super) {
|
|
|
8257
8260
|
|
|
8258
8261
|
AWSAppSyncRealTimeProvider.prototype._waitForSubscriptionToBeConnected = function (subscriptionId) {
|
|
8259
8262
|
return __awaiter(this, void 0, void 0, function () {
|
|
8260
|
-
var subscriptionState;
|
|
8263
|
+
var subscriptionObserver, subscriptionState;
|
|
8261
8264
|
|
|
8262
8265
|
var _this = this;
|
|
8263
8266
|
|
|
8264
8267
|
return __generator(this, function (_a) {
|
|
8265
|
-
|
|
8268
|
+
subscriptionObserver = this.subscriptionObserverMap.get(subscriptionId);
|
|
8266
8269
|
|
|
8267
|
-
if (
|
|
8268
|
-
|
|
8269
|
-
|
|
8270
|
-
|
|
8271
|
-
|
|
8272
|
-
|
|
8273
|
-
|
|
8274
|
-
|
|
8275
|
-
|
|
8276
|
-
|
|
8277
|
-
|
|
8278
|
-
|
|
8279
|
-
|
|
8280
|
-
|
|
8281
|
-
|
|
8282
|
-
|
|
8283
|
-
|
|
8284
|
-
|
|
8285
|
-
|
|
8270
|
+
if (subscriptionObserver) {
|
|
8271
|
+
subscriptionState = subscriptionObserver.subscriptionState; // This in case unsubscribe is invoked before sending start subscription message
|
|
8272
|
+
|
|
8273
|
+
if (subscriptionState === SUBSCRIPTION_STATUS.PENDING) {
|
|
8274
|
+
return [2
|
|
8275
|
+
/*return*/
|
|
8276
|
+
, new Promise(function (res, rej) {
|
|
8277
|
+
var observer = subscriptionObserver.observer,
|
|
8278
|
+
subscriptionState = subscriptionObserver.subscriptionState,
|
|
8279
|
+
variables = subscriptionObserver.variables,
|
|
8280
|
+
query = subscriptionObserver.query;
|
|
8281
|
+
|
|
8282
|
+
_this.subscriptionObserverMap.set(subscriptionId, {
|
|
8283
|
+
observer: observer,
|
|
8284
|
+
subscriptionState: subscriptionState,
|
|
8285
|
+
variables: variables,
|
|
8286
|
+
query: query,
|
|
8287
|
+
subscriptionReadyCallback: res,
|
|
8288
|
+
subscriptionFailedCallback: rej
|
|
8289
|
+
});
|
|
8290
|
+
})];
|
|
8291
|
+
}
|
|
8286
8292
|
}
|
|
8287
8293
|
|
|
8288
8294
|
return [2
|
|
@@ -8333,13 +8339,13 @@ function (_super) {
|
|
|
8333
8339
|
setTimeout(this._closeSocketIfRequired.bind(this), 1000);
|
|
8334
8340
|
} else {
|
|
8335
8341
|
logger.debug('closing WebSocket...');
|
|
8336
|
-
clearTimeout(this.keepAliveTimeoutId);
|
|
8342
|
+
if (this.keepAliveTimeoutId) clearTimeout(this.keepAliveTimeoutId);
|
|
8337
8343
|
var tempSocket = this.awsRealTimeSocket; // Cleaning callbacks to avoid race condition, socket still exists
|
|
8338
8344
|
|
|
8339
|
-
tempSocket.onclose =
|
|
8340
|
-
tempSocket.onerror =
|
|
8345
|
+
tempSocket.onclose = null;
|
|
8346
|
+
tempSocket.onerror = null;
|
|
8341
8347
|
tempSocket.close(1000);
|
|
8342
|
-
this.awsRealTimeSocket =
|
|
8348
|
+
this.awsRealTimeSocket = undefined;
|
|
8343
8349
|
this.socketStatus = SOCKET_STATUS.CLOSED;
|
|
8344
8350
|
}
|
|
8345
8351
|
};
|
|
@@ -8391,50 +8397,57 @@ function (_super) {
|
|
|
8391
8397
|
subscriptionReadyCallback();
|
|
8392
8398
|
}
|
|
8393
8399
|
|
|
8394
|
-
clearTimeout(startAckTimeoutId);
|
|
8400
|
+
if (startAckTimeoutId) clearTimeout(startAckTimeoutId);
|
|
8395
8401
|
dispatchApiEvent(_index__WEBPACK_IMPORTED_MODULE_9__["CONTROL_MSG"].SUBSCRIPTION_ACK, {
|
|
8396
8402
|
query: query,
|
|
8397
8403
|
variables: variables
|
|
8398
8404
|
}, 'Connection established for subscription');
|
|
8399
8405
|
var subscriptionState = SUBSCRIPTION_STATUS.CONNECTED;
|
|
8400
|
-
|
|
8401
|
-
|
|
8402
|
-
|
|
8403
|
-
|
|
8404
|
-
|
|
8405
|
-
|
|
8406
|
-
|
|
8407
|
-
|
|
8408
|
-
|
|
8406
|
+
|
|
8407
|
+
if (observer) {
|
|
8408
|
+
this.subscriptionObserverMap.set(id, {
|
|
8409
|
+
observer: observer,
|
|
8410
|
+
query: query,
|
|
8411
|
+
variables: variables,
|
|
8412
|
+
startAckTimeoutId: undefined,
|
|
8413
|
+
subscriptionState: subscriptionState,
|
|
8414
|
+
subscriptionReadyCallback: subscriptionReadyCallback,
|
|
8415
|
+
subscriptionFailedCallback: subscriptionFailedCallback
|
|
8416
|
+
});
|
|
8417
|
+
} // TODO: emit event on hub but it requires to store the id first
|
|
8418
|
+
|
|
8409
8419
|
|
|
8410
8420
|
return;
|
|
8411
8421
|
}
|
|
8412
8422
|
|
|
8413
8423
|
if (type === MESSAGE_TYPES.GQL_CONNECTION_KEEP_ALIVE) {
|
|
8414
|
-
clearTimeout(this.keepAliveTimeoutId);
|
|
8424
|
+
if (this.keepAliveTimeoutId) clearTimeout(this.keepAliveTimeoutId);
|
|
8415
8425
|
this.keepAliveTimeoutId = setTimeout(this._errorDisconnect.bind(this, _index__WEBPACK_IMPORTED_MODULE_9__["CONTROL_MSG"].TIMEOUT_DISCONNECT), this.keepAliveTimeout);
|
|
8416
8426
|
return;
|
|
8417
8427
|
}
|
|
8418
8428
|
|
|
8419
8429
|
if (type === MESSAGE_TYPES.GQL_ERROR) {
|
|
8420
8430
|
var subscriptionState = SUBSCRIPTION_STATUS.FAILED;
|
|
8421
|
-
this.subscriptionObserverMap.set(id, {
|
|
8422
|
-
observer: observer,
|
|
8423
|
-
query: query,
|
|
8424
|
-
variables: variables,
|
|
8425
|
-
startAckTimeoutId: startAckTimeoutId,
|
|
8426
|
-
subscriptionReadyCallback: subscriptionReadyCallback,
|
|
8427
|
-
subscriptionFailedCallback: subscriptionFailedCallback,
|
|
8428
|
-
subscriptionState: subscriptionState
|
|
8429
|
-
});
|
|
8430
|
-
observer.error({
|
|
8431
|
-
errors: [__assign({}, new graphql__WEBPACK_IMPORTED_MODULE_1__["GraphQLError"](_index__WEBPACK_IMPORTED_MODULE_9__["CONTROL_MSG"].CONNECTION_FAILED + ": " + JSON.stringify(payload)))]
|
|
8432
|
-
});
|
|
8433
|
-
clearTimeout(startAckTimeoutId);
|
|
8434
|
-
observer.complete();
|
|
8435
8431
|
|
|
8436
|
-
if (
|
|
8437
|
-
|
|
8432
|
+
if (observer) {
|
|
8433
|
+
this.subscriptionObserverMap.set(id, {
|
|
8434
|
+
observer: observer,
|
|
8435
|
+
query: query,
|
|
8436
|
+
variables: variables,
|
|
8437
|
+
startAckTimeoutId: startAckTimeoutId,
|
|
8438
|
+
subscriptionReadyCallback: subscriptionReadyCallback,
|
|
8439
|
+
subscriptionFailedCallback: subscriptionFailedCallback,
|
|
8440
|
+
subscriptionState: subscriptionState
|
|
8441
|
+
});
|
|
8442
|
+
observer.error({
|
|
8443
|
+
errors: [__assign({}, new graphql__WEBPACK_IMPORTED_MODULE_1__["GraphQLError"](_index__WEBPACK_IMPORTED_MODULE_9__["CONTROL_MSG"].CONNECTION_FAILED + ": " + JSON.stringify(payload)))]
|
|
8444
|
+
});
|
|
8445
|
+
if (startAckTimeoutId) clearTimeout(startAckTimeoutId);
|
|
8446
|
+
observer.complete();
|
|
8447
|
+
|
|
8448
|
+
if (typeof subscriptionFailedCallback === 'function') {
|
|
8449
|
+
subscriptionFailedCallback();
|
|
8450
|
+
}
|
|
8438
8451
|
}
|
|
8439
8452
|
}
|
|
8440
8453
|
};
|
|
@@ -8460,37 +8473,40 @@ function (_super) {
|
|
|
8460
8473
|
};
|
|
8461
8474
|
|
|
8462
8475
|
AWSAppSyncRealTimeProvider.prototype._timeoutStartSubscriptionAck = function (subscriptionId) {
|
|
8463
|
-
var
|
|
8464
|
-
observer = _a.observer,
|
|
8465
|
-
query = _a.query,
|
|
8466
|
-
variables = _a.variables;
|
|
8476
|
+
var subscriptionObserver = this.subscriptionObserverMap.get(subscriptionId);
|
|
8467
8477
|
|
|
8468
|
-
if (
|
|
8469
|
-
|
|
8470
|
-
|
|
8478
|
+
if (subscriptionObserver) {
|
|
8479
|
+
var observer = subscriptionObserver.observer,
|
|
8480
|
+
query = subscriptionObserver.query,
|
|
8481
|
+
variables = subscriptionObserver.variables;
|
|
8471
8482
|
|
|
8472
|
-
|
|
8473
|
-
|
|
8474
|
-
|
|
8475
|
-
variables: variables,
|
|
8476
|
-
subscriptionState: SUBSCRIPTION_STATUS.FAILED
|
|
8477
|
-
});
|
|
8483
|
+
if (!observer) {
|
|
8484
|
+
return;
|
|
8485
|
+
}
|
|
8478
8486
|
|
|
8479
|
-
|
|
8480
|
-
|
|
8481
|
-
|
|
8482
|
-
|
|
8483
|
-
|
|
8484
|
-
|
|
8485
|
-
}); // Cleanup will be automatically executed
|
|
8487
|
+
this.subscriptionObserverMap.set(subscriptionId, {
|
|
8488
|
+
observer: observer,
|
|
8489
|
+
query: query,
|
|
8490
|
+
variables: variables,
|
|
8491
|
+
subscriptionState: SUBSCRIPTION_STATUS.FAILED
|
|
8492
|
+
});
|
|
8486
8493
|
|
|
8487
|
-
observer.
|
|
8488
|
-
|
|
8494
|
+
if (observer && !observer.closed) {
|
|
8495
|
+
observer.error({
|
|
8496
|
+
errors: [__assign({}, new graphql__WEBPACK_IMPORTED_MODULE_1__["GraphQLError"]("Subscription timeout " + JSON.stringify({
|
|
8497
|
+
query: query,
|
|
8498
|
+
variables: variables
|
|
8499
|
+
})))]
|
|
8500
|
+
}); // Cleanup will be automatically executed
|
|
8489
8501
|
|
|
8490
|
-
|
|
8491
|
-
|
|
8492
|
-
|
|
8493
|
-
|
|
8502
|
+
observer.complete();
|
|
8503
|
+
}
|
|
8504
|
+
|
|
8505
|
+
logger.debug('timeoutStartSubscription', JSON.stringify({
|
|
8506
|
+
query: query,
|
|
8507
|
+
variables: variables
|
|
8508
|
+
}));
|
|
8509
|
+
}
|
|
8494
8510
|
};
|
|
8495
8511
|
|
|
8496
8512
|
AWSAppSyncRealTimeProvider.prototype._initializeWebSocketConnection = function (_a) {
|
|
@@ -8544,7 +8560,7 @@ function (_super) {
|
|
|
8544
8560
|
headerString = _b.apply(_a, [_c.sent()]);
|
|
8545
8561
|
headerQs = buffer__WEBPACK_IMPORTED_MODULE_4__["Buffer"].from(headerString).toString('base64');
|
|
8546
8562
|
payloadQs = buffer__WEBPACK_IMPORTED_MODULE_4__["Buffer"].from(payloadString).toString('base64');
|
|
8547
|
-
discoverableEndpoint = appSyncGraphqlEndpoint;
|
|
8563
|
+
discoverableEndpoint = appSyncGraphqlEndpoint !== null && appSyncGraphqlEndpoint !== void 0 ? appSyncGraphqlEndpoint : '';
|
|
8548
8564
|
|
|
8549
8565
|
if (this.isCustomDomain(discoverableEndpoint)) {
|
|
8550
8566
|
discoverableEndpoint = discoverableEndpoint.concat(customDomainPath);
|
|
@@ -8557,9 +8573,7 @@ function (_super) {
|
|
|
8557
8573
|
awsRealTimeUrl = discoverableEndpoint + "?header=" + headerQs + "&payload=" + payloadQs;
|
|
8558
8574
|
return [4
|
|
8559
8575
|
/*yield*/
|
|
8560
|
-
, this._initializeRetryableHandshake(
|
|
8561
|
-
awsRealTimeUrl: awsRealTimeUrl
|
|
8562
|
-
})];
|
|
8576
|
+
, this._initializeRetryableHandshake(awsRealTimeUrl)];
|
|
8563
8577
|
|
|
8564
8578
|
case 3:
|
|
8565
8579
|
_c.sent();
|
|
@@ -8587,7 +8601,7 @@ function (_super) {
|
|
|
8587
8601
|
this.awsRealTimeSocket.close(3001);
|
|
8588
8602
|
}
|
|
8589
8603
|
|
|
8590
|
-
this.awsRealTimeSocket =
|
|
8604
|
+
this.awsRealTimeSocket = undefined;
|
|
8591
8605
|
this.socketStatus = SOCKET_STATUS.CLOSED;
|
|
8592
8606
|
return [3
|
|
8593
8607
|
/*break*/
|
|
@@ -8603,21 +8617,18 @@ function (_super) {
|
|
|
8603
8617
|
});
|
|
8604
8618
|
};
|
|
8605
8619
|
|
|
8606
|
-
AWSAppSyncRealTimeProvider.prototype._initializeRetryableHandshake = function (
|
|
8607
|
-
var awsRealTimeUrl = _a.awsRealTimeUrl;
|
|
8620
|
+
AWSAppSyncRealTimeProvider.prototype._initializeRetryableHandshake = function (awsRealTimeUrl) {
|
|
8608
8621
|
return __awaiter(this, void 0, void 0, function () {
|
|
8609
|
-
return __generator(this, function (
|
|
8610
|
-
switch (
|
|
8622
|
+
return __generator(this, function (_a) {
|
|
8623
|
+
switch (_a.label) {
|
|
8611
8624
|
case 0:
|
|
8612
8625
|
logger.debug("Initializaling retryable Handshake");
|
|
8613
8626
|
return [4
|
|
8614
8627
|
/*yield*/
|
|
8615
|
-
, Object(_aws_amplify_core__WEBPACK_IMPORTED_MODULE_5__["jitteredExponentialRetry"])(this._initializeHandshake.bind(this), [
|
|
8616
|
-
awsRealTimeUrl: awsRealTimeUrl
|
|
8617
|
-
}], MAX_DELAY_MS)];
|
|
8628
|
+
, Object(_aws_amplify_core__WEBPACK_IMPORTED_MODULE_5__["jitteredExponentialRetry"])(this._initializeHandshake.bind(this), [awsRealTimeUrl], MAX_DELAY_MS)];
|
|
8618
8629
|
|
|
8619
8630
|
case 1:
|
|
8620
|
-
|
|
8631
|
+
_a.sent();
|
|
8621
8632
|
|
|
8622
8633
|
return [2
|
|
8623
8634
|
/*return*/
|
|
@@ -8627,10 +8638,9 @@ function (_super) {
|
|
|
8627
8638
|
});
|
|
8628
8639
|
};
|
|
8629
8640
|
|
|
8630
|
-
AWSAppSyncRealTimeProvider.prototype._initializeHandshake = function (
|
|
8631
|
-
var awsRealTimeUrl = _a.awsRealTimeUrl;
|
|
8641
|
+
AWSAppSyncRealTimeProvider.prototype._initializeHandshake = function (awsRealTimeUrl) {
|
|
8632
8642
|
return __awaiter(this, void 0, void 0, function () {
|
|
8633
|
-
var err_4, errorType, errorCode;
|
|
8643
|
+
var err_4, _a, errorType, errorCode;
|
|
8634
8644
|
|
|
8635
8645
|
var _this = this;
|
|
8636
8646
|
|
|
@@ -8672,77 +8682,82 @@ function (_super) {
|
|
|
8672
8682
|
/*yield*/
|
|
8673
8683
|
, function () {
|
|
8674
8684
|
return new Promise(function (res, rej) {
|
|
8675
|
-
|
|
8685
|
+
if (_this.awsRealTimeSocket) {
|
|
8686
|
+
var ackOk_1 = false;
|
|
8676
8687
|
|
|
8677
|
-
|
|
8678
|
-
|
|
8679
|
-
|
|
8688
|
+
_this.awsRealTimeSocket.onerror = function (error) {
|
|
8689
|
+
logger.debug("WebSocket error " + JSON.stringify(error));
|
|
8690
|
+
};
|
|
8680
8691
|
|
|
8681
|
-
|
|
8682
|
-
|
|
8683
|
-
|
|
8684
|
-
|
|
8692
|
+
_this.awsRealTimeSocket.onclose = function (event) {
|
|
8693
|
+
logger.debug("WebSocket closed " + event.reason);
|
|
8694
|
+
rej(new Error(JSON.stringify(event)));
|
|
8695
|
+
};
|
|
8685
8696
|
|
|
8686
|
-
|
|
8687
|
-
|
|
8688
|
-
|
|
8689
|
-
|
|
8690
|
-
|
|
8691
|
-
|
|
8692
|
-
|
|
8697
|
+
_this.awsRealTimeSocket.onmessage = function (message) {
|
|
8698
|
+
logger.debug("subscription message from AWS AppSyncRealTime: " + message.data + " ");
|
|
8699
|
+
var data = JSON.parse(message.data);
|
|
8700
|
+
var type = data.type,
|
|
8701
|
+
_a = data.payload,
|
|
8702
|
+
_b = (_a === void 0 ? {} : _a).connectionTimeoutMs,
|
|
8703
|
+
connectionTimeoutMs = _b === void 0 ? DEFAULT_KEEP_ALIVE_TIMEOUT : _b;
|
|
8693
8704
|
|
|
8694
|
-
|
|
8695
|
-
|
|
8696
|
-
_this.keepAliveTimeout = connectionTimeoutMs;
|
|
8697
|
-
_this.awsRealTimeSocket.onmessage = _this._handleIncomingSubscriptionMessage.bind(_this);
|
|
8705
|
+
if (type === MESSAGE_TYPES.GQL_CONNECTION_ACK) {
|
|
8706
|
+
ackOk_1 = true;
|
|
8698
8707
|
|
|
8699
|
-
|
|
8700
|
-
|
|
8708
|
+
if (_this.awsRealTimeSocket) {
|
|
8709
|
+
_this.keepAliveTimeout = connectionTimeoutMs;
|
|
8710
|
+
_this.awsRealTimeSocket.onmessage = _this._handleIncomingSubscriptionMessage.bind(_this);
|
|
8701
8711
|
|
|
8702
|
-
|
|
8703
|
-
|
|
8712
|
+
_this.awsRealTimeSocket.onerror = function (err) {
|
|
8713
|
+
logger.debug(err);
|
|
8704
8714
|
|
|
8705
|
-
|
|
8706
|
-
|
|
8715
|
+
_this._errorDisconnect(_index__WEBPACK_IMPORTED_MODULE_9__["CONTROL_MSG"].CONNECTION_CLOSED);
|
|
8716
|
+
};
|
|
8707
8717
|
|
|
8708
|
-
|
|
8709
|
-
|
|
8718
|
+
_this.awsRealTimeSocket.onclose = function (event) {
|
|
8719
|
+
logger.debug("WebSocket closed " + event.reason);
|
|
8710
8720
|
|
|
8711
|
-
|
|
8712
|
-
|
|
8713
|
-
|
|
8721
|
+
_this._errorDisconnect(_index__WEBPACK_IMPORTED_MODULE_9__["CONTROL_MSG"].CONNECTION_CLOSED);
|
|
8722
|
+
};
|
|
8723
|
+
}
|
|
8714
8724
|
|
|
8715
|
-
|
|
8716
|
-
|
|
8717
|
-
|
|
8718
|
-
_e = __read(_d === void 0 ? [] : _d, 1),
|
|
8719
|
-
_f = _e[0],
|
|
8720
|
-
_g = _f === void 0 ? {} : _f,
|
|
8721
|
-
_h = _g.errorType,
|
|
8722
|
-
errorType = _h === void 0 ? '' : _h,
|
|
8723
|
-
_j = _g.errorCode,
|
|
8724
|
-
errorCode = _j === void 0 ? 0 : _j;
|
|
8725
|
-
|
|
8726
|
-
rej({
|
|
8727
|
-
errorType: errorType,
|
|
8728
|
-
errorCode: errorCode
|
|
8729
|
-
});
|
|
8730
|
-
}
|
|
8731
|
-
};
|
|
8725
|
+
res('Cool, connected to AWS AppSyncRealTime');
|
|
8726
|
+
return;
|
|
8727
|
+
}
|
|
8732
8728
|
|
|
8733
|
-
|
|
8734
|
-
|
|
8735
|
-
|
|
8729
|
+
if (type === MESSAGE_TYPES.GQL_CONNECTION_ERROR) {
|
|
8730
|
+
var _c = data.payload,
|
|
8731
|
+
_d = (_c === void 0 ? {} : _c).errors,
|
|
8732
|
+
_e = __read(_d === void 0 ? [] : _d, 1),
|
|
8733
|
+
_f = _e[0],
|
|
8734
|
+
_g = _f === void 0 ? {} : _f,
|
|
8735
|
+
_h = _g.errorType,
|
|
8736
|
+
errorType = _h === void 0 ? '' : _h,
|
|
8737
|
+
_j = _g.errorCode,
|
|
8738
|
+
errorCode = _j === void 0 ? 0 : _j;
|
|
8739
|
+
|
|
8740
|
+
rej({
|
|
8741
|
+
errorType: errorType,
|
|
8742
|
+
errorCode: errorCode
|
|
8743
|
+
});
|
|
8744
|
+
}
|
|
8745
|
+
};
|
|
8746
|
+
|
|
8747
|
+
var gqlInit = {
|
|
8748
|
+
type: MESSAGE_TYPES.GQL_CONNECTION_INIT
|
|
8749
|
+
};
|
|
8736
8750
|
|
|
8737
|
-
|
|
8751
|
+
_this.awsRealTimeSocket.send(JSON.stringify(gqlInit));
|
|
8738
8752
|
|
|
8739
|
-
|
|
8753
|
+
setTimeout(checkAckOk.bind(_this, ackOk_1), CONNECTION_INIT_TIMEOUT);
|
|
8754
|
+
}
|
|
8755
|
+
|
|
8756
|
+
function checkAckOk(ackOk) {
|
|
8740
8757
|
if (!ackOk) {
|
|
8741
8758
|
rej(new Error("Connection timeout: ack from AWSRealTime was not received on " + CONNECTION_INIT_TIMEOUT + " ms"));
|
|
8742
8759
|
}
|
|
8743
8760
|
}
|
|
8744
|
-
|
|
8745
|
-
setTimeout(checkAckOk.bind(_this), CONNECTION_INIT_TIMEOUT);
|
|
8746
8761
|
});
|
|
8747
8762
|
}()];
|
|
8748
8763
|
|
|
@@ -8756,7 +8771,7 @@ function (_super) {
|
|
|
8756
8771
|
|
|
8757
8772
|
case 4:
|
|
8758
8773
|
err_4 = _b.sent();
|
|
8759
|
-
errorType =
|
|
8774
|
+
_a = err_4, errorType = _a.errorType, errorCode = _a.errorCode;
|
|
8760
8775
|
|
|
8761
8776
|
if (NON_RETRYABLE_CODES.includes(errorCode)) {
|
|
8762
8777
|
throw new _aws_amplify_core__WEBPACK_IMPORTED_MODULE_5__["NonRetryableError"](errorType);
|
|
@@ -8799,16 +8814,17 @@ function (_super) {
|
|
|
8799
8814
|
AMAZON_COGNITO_USER_POOLS: this._awsRealTimeCUPHeader.bind(this),
|
|
8800
8815
|
AWS_LAMBDA: this._customAuthHeader
|
|
8801
8816
|
};
|
|
8802
|
-
|
|
8803
|
-
|
|
8804
|
-
|
|
8805
|
-
|
|
8806
|
-
|
|
8807
|
-
|
|
8808
|
-
|
|
8809
|
-
}
|
|
8817
|
+
if (!(!authenticationType || !headerHandler[authenticationType])) return [3
|
|
8818
|
+
/*break*/
|
|
8819
|
+
, 1];
|
|
8820
|
+
logger.debug("Authentication type " + authenticationType + " not supported");
|
|
8821
|
+
return [2
|
|
8822
|
+
/*return*/
|
|
8823
|
+
, ''];
|
|
8810
8824
|
|
|
8811
|
-
|
|
8825
|
+
case 1:
|
|
8826
|
+
handler = headerHandler[authenticationType];
|
|
8827
|
+
host = url__WEBPACK_IMPORTED_MODULE_2__["parse"](appSyncGraphqlEndpoint !== null && appSyncGraphqlEndpoint !== void 0 ? appSyncGraphqlEndpoint : '').host;
|
|
8812
8828
|
return [4
|
|
8813
8829
|
/*yield*/
|
|
8814
8830
|
, handler({
|
|
@@ -8821,7 +8837,7 @@ function (_super) {
|
|
|
8821
8837
|
additionalHeaders: additionalHeaders
|
|
8822
8838
|
})];
|
|
8823
8839
|
|
|
8824
|
-
case
|
|
8840
|
+
case 2:
|
|
8825
8841
|
result = _b.sent();
|
|
8826
8842
|
return [2
|
|
8827
8843
|
/*return*/
|
|
@@ -8953,10 +8969,14 @@ function (_super) {
|
|
|
8953
8969
|
return [4
|
|
8954
8970
|
/*yield*/
|
|
8955
8971
|
, _aws_amplify_core__WEBPACK_IMPORTED_MODULE_5__["Credentials"].get().then(function (credentials) {
|
|
8972
|
+
var _a = credentials,
|
|
8973
|
+
secretAccessKey = _a.secretAccessKey,
|
|
8974
|
+
accessKeyId = _a.accessKeyId,
|
|
8975
|
+
sessionToken = _a.sessionToken;
|
|
8956
8976
|
return {
|
|
8957
|
-
secret_key:
|
|
8958
|
-
access_key:
|
|
8959
|
-
session_token:
|
|
8977
|
+
secret_key: secretAccessKey,
|
|
8978
|
+
access_key: accessKeyId,
|
|
8979
|
+
session_token: sessionToken
|
|
8960
8980
|
};
|
|
8961
8981
|
})];
|
|
8962
8982
|
|
|
@@ -8981,7 +9001,7 @@ function (_super) {
|
|
|
8981
9001
|
var host = _a.host,
|
|
8982
9002
|
additionalHeaders = _a.additionalHeaders;
|
|
8983
9003
|
|
|
8984
|
-
if (!additionalHeaders
|
|
9004
|
+
if (!additionalHeaders || !additionalHeaders['Authorization']) {
|
|
8985
9005
|
throw new Error('No auth token specified');
|
|
8986
9006
|
}
|
|
8987
9007
|
|
|
@@ -9553,21 +9573,27 @@ function () {
|
|
|
9553
9573
|
|
|
9554
9574
|
ClientsQueue.prototype.get = function (clientId, clientFactory) {
|
|
9555
9575
|
return __awaiter(this, void 0, void 0, function () {
|
|
9556
|
-
var
|
|
9576
|
+
var cachedPromise, newPromise;
|
|
9557
9577
|
return __generator(this, function (_a) {
|
|
9558
|
-
|
|
9578
|
+
cachedPromise = this.promises.get(clientId);
|
|
9559
9579
|
|
|
9560
|
-
if (
|
|
9580
|
+
if (cachedPromise) {
|
|
9561
9581
|
return [2
|
|
9562
9582
|
/*return*/
|
|
9563
|
-
,
|
|
9583
|
+
, cachedPromise];
|
|
9584
|
+
}
|
|
9585
|
+
|
|
9586
|
+
if (clientFactory) {
|
|
9587
|
+
newPromise = clientFactory(clientId);
|
|
9588
|
+
this.promises.set(clientId, newPromise);
|
|
9589
|
+
return [2
|
|
9590
|
+
/*return*/
|
|
9591
|
+
, newPromise];
|
|
9564
9592
|
}
|
|
9565
9593
|
|
|
9566
|
-
promise = clientFactory(clientId);
|
|
9567
|
-
this.promises.set(clientId, promise);
|
|
9568
9594
|
return [2
|
|
9569
9595
|
/*return*/
|
|
9570
|
-
,
|
|
9596
|
+
, undefined];
|
|
9571
9597
|
});
|
|
9572
9598
|
});
|
|
9573
9599
|
};
|
|
@@ -9659,6 +9685,10 @@ function (_super) {
|
|
|
9659
9685
|
}, args), null, 2));
|
|
9660
9686
|
var topicsToDelete_1 = [];
|
|
9661
9687
|
|
|
9688
|
+
if (!clientId) {
|
|
9689
|
+
return;
|
|
9690
|
+
}
|
|
9691
|
+
|
|
9662
9692
|
var clientIdObservers = this._clientIdObservers.get(clientId);
|
|
9663
9693
|
|
|
9664
9694
|
if (!clientIdObservers) {
|
|
@@ -9777,9 +9807,7 @@ function (_super) {
|
|
|
9777
9807
|
case 0:
|
|
9778
9808
|
return [4
|
|
9779
9809
|
/*yield*/
|
|
9780
|
-
, this.clientsQueue.get(clientId
|
|
9781
|
-
return null;
|
|
9782
|
-
})];
|
|
9810
|
+
, this.clientsQueue.get(clientId)];
|
|
9783
9811
|
|
|
9784
9812
|
case 1:
|
|
9785
9813
|
client = _a.sent();
|
|
@@ -9958,13 +9986,14 @@ function (_super) {
|
|
|
9958
9986
|
})();
|
|
9959
9987
|
|
|
9960
9988
|
return function () {
|
|
9989
|
+
var _a, _b;
|
|
9990
|
+
|
|
9961
9991
|
logger.debug('Unsubscribing from topic(s)', targetTopics.join(','));
|
|
9962
9992
|
|
|
9963
9993
|
if (client) {
|
|
9964
|
-
_this._clientIdObservers.get(clientId)["delete"](observer); // No more observers per client => client not needed anymore
|
|
9965
|
-
|
|
9994
|
+
(_a = _this._clientIdObservers.get(clientId)) === null || _a === void 0 ? void 0 : _a["delete"](observer); // No more observers per client => client not needed anymore
|
|
9966
9995
|
|
|
9967
|
-
if (_this._clientIdObservers.get(clientId).size === 0) {
|
|
9996
|
+
if (((_b = _this._clientIdObservers.get(clientId)) === null || _b === void 0 ? void 0 : _b.size) === 0) {
|
|
9968
9997
|
_this.disconnect(clientId);
|
|
9969
9998
|
|
|
9970
9999
|
_this._clientIdObservers["delete"](clientId);
|