@aws-amplify/api-graphql 4.7.2-graphql-data-ka.518fb2c.0 → 4.7.2-poc-list-paths.25da28f.0
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/cjs/Providers/AWSWebSocketProvider/index.js +25 -43
- package/dist/cjs/Providers/AWSWebSocketProvider/index.js.map +1 -1
- package/dist/cjs/Providers/constants.js +1 -5
- package/dist/cjs/Providers/constants.js.map +1 -1
- package/dist/esm/Providers/AWSWebSocketProvider/index.d.ts +3 -5
- package/dist/esm/Providers/AWSWebSocketProvider/index.mjs +26 -44
- package/dist/esm/Providers/AWSWebSocketProvider/index.mjs.map +1 -1
- package/dist/esm/Providers/constants.d.ts +0 -4
- package/dist/esm/Providers/constants.mjs +1 -5
- package/dist/esm/Providers/constants.mjs.map +1 -1
- package/package.json +4 -4
- package/src/Providers/AWSWebSocketProvider/index.ts +27 -58
- package/src/Providers/constants.ts +0 -5
|
@@ -23,7 +23,7 @@ import {
|
|
|
23
23
|
CONNECTION_INIT_TIMEOUT,
|
|
24
24
|
CONNECTION_STATE_CHANGE,
|
|
25
25
|
DEFAULT_KEEP_ALIVE_ALERT_TIMEOUT,
|
|
26
|
-
|
|
26
|
+
DEFAULT_KEEP_ALIVE_TIMEOUT,
|
|
27
27
|
MAX_DELAY_MS,
|
|
28
28
|
MESSAGE_TYPES,
|
|
29
29
|
NON_RETRYABLE_CODES,
|
|
@@ -83,8 +83,9 @@ export abstract class AWSWebSocketProvider {
|
|
|
83
83
|
|
|
84
84
|
protected awsRealTimeSocket?: WebSocket;
|
|
85
85
|
private socketStatus: SOCKET_STATUS = SOCKET_STATUS.CLOSED;
|
|
86
|
-
private
|
|
87
|
-
private
|
|
86
|
+
private keepAliveTimeoutId?: ReturnType<typeof setTimeout>;
|
|
87
|
+
private keepAliveTimeout = DEFAULT_KEEP_ALIVE_TIMEOUT;
|
|
88
|
+
private keepAliveAlertTimeoutId?: ReturnType<typeof setTimeout>;
|
|
88
89
|
private promiseArray: { res(): void; rej(reason?: any): void }[] = [];
|
|
89
90
|
private connectionState: ConnectionState | undefined;
|
|
90
91
|
private readonly connectionStateMonitor = new ConnectionStateMonitor();
|
|
@@ -118,7 +119,6 @@ export abstract class AWSWebSocketProvider {
|
|
|
118
119
|
return new Promise<void>((resolve, reject) => {
|
|
119
120
|
if (this.awsRealTimeSocket) {
|
|
120
121
|
this.awsRealTimeSocket.onclose = (_: CloseEvent) => {
|
|
121
|
-
this._closeSocket();
|
|
122
122
|
this.subscriptionObserverMap = new Map();
|
|
123
123
|
this.awsRealTimeSocket = undefined;
|
|
124
124
|
resolve();
|
|
@@ -171,7 +171,7 @@ export abstract class AWSWebSocketProvider {
|
|
|
171
171
|
this.logger.debug(
|
|
172
172
|
`${CONTROL_MSG.REALTIME_SUBSCRIPTION_INIT_ERROR}: ${err}`,
|
|
173
173
|
);
|
|
174
|
-
this.
|
|
174
|
+
this.connectionStateMonitor.record(CONNECTION_CHANGE.CLOSED);
|
|
175
175
|
})
|
|
176
176
|
.finally(() => {
|
|
177
177
|
subscriptionStartInProgress = false;
|
|
@@ -435,7 +435,7 @@ export abstract class AWSWebSocketProvider {
|
|
|
435
435
|
this.logger.debug({ err });
|
|
436
436
|
const message = String(err.message ?? '');
|
|
437
437
|
// Resolving to give the state observer time to propogate the update
|
|
438
|
-
this.
|
|
438
|
+
this.connectionStateMonitor.record(CONNECTION_CHANGE.CLOSED);
|
|
439
439
|
|
|
440
440
|
// Capture the error only when the network didn't cause disruption
|
|
441
441
|
if (
|
|
@@ -544,7 +544,12 @@ export abstract class AWSWebSocketProvider {
|
|
|
544
544
|
setTimeout(this._closeSocketIfRequired.bind(this), 1000);
|
|
545
545
|
} else {
|
|
546
546
|
this.logger.debug('closing WebSocket...');
|
|
547
|
-
|
|
547
|
+
if (this.keepAliveTimeoutId) {
|
|
548
|
+
clearTimeout(this.keepAliveTimeoutId);
|
|
549
|
+
}
|
|
550
|
+
if (this.keepAliveAlertTimeoutId) {
|
|
551
|
+
clearTimeout(this.keepAliveAlertTimeoutId);
|
|
552
|
+
}
|
|
548
553
|
const tempSocket = this.awsRealTimeSocket;
|
|
549
554
|
// Cleaning callbacks to avoid race condition, socket still exists
|
|
550
555
|
tempSocket.onclose = null;
|
|
@@ -552,7 +557,7 @@ export abstract class AWSWebSocketProvider {
|
|
|
552
557
|
tempSocket.close(1000);
|
|
553
558
|
this.awsRealTimeSocket = undefined;
|
|
554
559
|
this.socketStatus = SOCKET_STATUS.CLOSED;
|
|
555
|
-
this.
|
|
560
|
+
this.connectionStateMonitor.record(CONNECTION_CHANGE.CLOSED);
|
|
556
561
|
}
|
|
557
562
|
}
|
|
558
563
|
|
|
@@ -572,43 +577,13 @@ export abstract class AWSWebSocketProvider {
|
|
|
572
577
|
errorType: string;
|
|
573
578
|
};
|
|
574
579
|
|
|
575
|
-
private maintainKeepAlive() {
|
|
576
|
-
this.kaTimestamp = Date.now();
|
|
577
|
-
}
|
|
578
|
-
|
|
579
|
-
private keepAliveHeartbeat(connectionTimeoutMs: number) {
|
|
580
|
-
const currentTime = Date.now();
|
|
581
|
-
|
|
582
|
-
// Check for missed KA message
|
|
583
|
-
if (
|
|
584
|
-
this.kaTimestamp &&
|
|
585
|
-
currentTime - this.kaTimestamp > DEFAULT_KEEP_ALIVE_ALERT_TIMEOUT
|
|
586
|
-
) {
|
|
587
|
-
this.connectionStateMonitor.record(CONNECTION_CHANGE.KEEP_ALIVE_MISSED);
|
|
588
|
-
} else {
|
|
589
|
-
this.connectionStateMonitor.record(CONNECTION_CHANGE.KEEP_ALIVE);
|
|
590
|
-
}
|
|
591
|
-
|
|
592
|
-
// Recognize we are disconnected if we haven't seen messages in the keep alive timeout period
|
|
593
|
-
if (
|
|
594
|
-
this.kaTimestamp &&
|
|
595
|
-
currentTime - this.kaTimestamp > connectionTimeoutMs
|
|
596
|
-
) {
|
|
597
|
-
this._errorDisconnect(CONTROL_MSG.TIMEOUT_DISCONNECT);
|
|
598
|
-
}
|
|
599
|
-
}
|
|
600
|
-
|
|
601
580
|
private _handleIncomingSubscriptionMessage(message: MessageEvent) {
|
|
602
581
|
if (typeof message.data !== 'string') {
|
|
603
582
|
return;
|
|
604
583
|
}
|
|
605
584
|
|
|
606
585
|
const [isData, data] = this._handleSubscriptionData(message);
|
|
607
|
-
if (isData)
|
|
608
|
-
this.maintainKeepAlive();
|
|
609
|
-
|
|
610
|
-
return;
|
|
611
|
-
}
|
|
586
|
+
if (isData) return;
|
|
612
587
|
|
|
613
588
|
const { type, id, payload } = data;
|
|
614
589
|
|
|
@@ -657,7 +632,16 @@ export abstract class AWSWebSocketProvider {
|
|
|
657
632
|
}
|
|
658
633
|
|
|
659
634
|
if (type === MESSAGE_TYPES.GQL_CONNECTION_KEEP_ALIVE) {
|
|
660
|
-
this.
|
|
635
|
+
if (this.keepAliveTimeoutId) clearTimeout(this.keepAliveTimeoutId);
|
|
636
|
+
if (this.keepAliveAlertTimeoutId)
|
|
637
|
+
clearTimeout(this.keepAliveAlertTimeoutId);
|
|
638
|
+
this.keepAliveTimeoutId = setTimeout(() => {
|
|
639
|
+
this._errorDisconnect(CONTROL_MSG.TIMEOUT_DISCONNECT);
|
|
640
|
+
}, this.keepAliveTimeout);
|
|
641
|
+
this.keepAliveAlertTimeoutId = setTimeout(() => {
|
|
642
|
+
this.connectionStateMonitor.record(CONNECTION_CHANGE.KEEP_ALIVE_MISSED);
|
|
643
|
+
}, DEFAULT_KEEP_ALIVE_ALERT_TIMEOUT);
|
|
644
|
+
this.connectionStateMonitor.record(CONNECTION_CHANGE.KEEP_ALIVE);
|
|
661
645
|
|
|
662
646
|
return;
|
|
663
647
|
}
|
|
@@ -702,21 +686,13 @@ export abstract class AWSWebSocketProvider {
|
|
|
702
686
|
this.logger.debug(`Disconnect error: ${msg}`);
|
|
703
687
|
|
|
704
688
|
if (this.awsRealTimeSocket) {
|
|
705
|
-
this.
|
|
689
|
+
this.connectionStateMonitor.record(CONNECTION_CHANGE.CLOSED);
|
|
706
690
|
this.awsRealTimeSocket.close();
|
|
707
691
|
}
|
|
708
692
|
|
|
709
693
|
this.socketStatus = SOCKET_STATUS.CLOSED;
|
|
710
694
|
}
|
|
711
695
|
|
|
712
|
-
private _closeSocket() {
|
|
713
|
-
if (this.keepAliveHeartbeatIntervalId) {
|
|
714
|
-
clearInterval(this.keepAliveHeartbeatIntervalId);
|
|
715
|
-
this.keepAliveHeartbeatIntervalId = undefined;
|
|
716
|
-
}
|
|
717
|
-
this.connectionStateMonitor.record(CONNECTION_CHANGE.CLOSED);
|
|
718
|
-
}
|
|
719
|
-
|
|
720
696
|
private _timeoutStartSubscriptionAck(subscriptionId: string) {
|
|
721
697
|
const subscriptionObserver =
|
|
722
698
|
this.subscriptionObserverMap.get(subscriptionId);
|
|
@@ -732,7 +708,7 @@ export abstract class AWSWebSocketProvider {
|
|
|
732
708
|
subscriptionState: SUBSCRIPTION_STATUS.FAILED,
|
|
733
709
|
});
|
|
734
710
|
|
|
735
|
-
this.
|
|
711
|
+
this.connectionStateMonitor.record(CONNECTION_CHANGE.CLOSED);
|
|
736
712
|
this.logger.debug(
|
|
737
713
|
'timeoutStartSubscription',
|
|
738
714
|
JSON.stringify({ query, variables }),
|
|
@@ -844,7 +820,6 @@ export abstract class AWSWebSocketProvider {
|
|
|
844
820
|
this.logger.debug(`WebSocket connection error`);
|
|
845
821
|
};
|
|
846
822
|
newSocket.onclose = () => {
|
|
847
|
-
this._closeSocket();
|
|
848
823
|
reject(new Error('Connection handshake error'));
|
|
849
824
|
};
|
|
850
825
|
newSocket.onopen = () => {
|
|
@@ -874,7 +849,6 @@ export abstract class AWSWebSocketProvider {
|
|
|
874
849
|
|
|
875
850
|
this.awsRealTimeSocket.onclose = event => {
|
|
876
851
|
this.logger.debug(`WebSocket closed ${event.reason}`);
|
|
877
|
-
this._closeSocket();
|
|
878
852
|
reject(new Error(JSON.stringify(event)));
|
|
879
853
|
};
|
|
880
854
|
|
|
@@ -938,11 +912,7 @@ export abstract class AWSWebSocketProvider {
|
|
|
938
912
|
return;
|
|
939
913
|
}
|
|
940
914
|
|
|
941
|
-
|
|
942
|
-
this.keepAliveHeartbeatIntervalId = setInterval(() => {
|
|
943
|
-
this.keepAliveHeartbeat(connectionTimeoutMs);
|
|
944
|
-
}, DEFAULT_KEEP_ALIVE_HEARTBEAT_TIMEOUT);
|
|
945
|
-
|
|
915
|
+
this.keepAliveTimeout = connectionTimeoutMs;
|
|
946
916
|
this.awsRealTimeSocket.onmessage =
|
|
947
917
|
this._handleIncomingSubscriptionMessage.bind(this);
|
|
948
918
|
|
|
@@ -953,7 +923,6 @@ export abstract class AWSWebSocketProvider {
|
|
|
953
923
|
|
|
954
924
|
this.awsRealTimeSocket.onclose = event => {
|
|
955
925
|
this.logger.debug(`WebSocket closed ${event.reason}`);
|
|
956
|
-
this._closeSocket();
|
|
957
926
|
this._errorDisconnect(CONTROL_MSG.CONNECTION_CLOSED);
|
|
958
927
|
};
|
|
959
928
|
}
|
|
@@ -128,11 +128,6 @@ export const START_ACK_TIMEOUT = 15000;
|
|
|
128
128
|
*/
|
|
129
129
|
export const DEFAULT_KEEP_ALIVE_TIMEOUT = 5 * 60 * 1000;
|
|
130
130
|
|
|
131
|
-
/**
|
|
132
|
-
* Default Time in milleseconds between monitoring checks of keep alive status
|
|
133
|
-
*/
|
|
134
|
-
export const DEFAULT_KEEP_ALIVE_HEARTBEAT_TIMEOUT = 5 * 1000;
|
|
135
|
-
|
|
136
131
|
/**
|
|
137
132
|
* Default Time in milleseconds to alert for missed GQL_CONNECTION_KEEP_ALIVE message
|
|
138
133
|
*/
|