@aws-amplify/pubsub 4.5.11 → 4.5.12-unstable.2
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 +0 -8
- package/lib/.tsbuildinfo +3 -0
- package/lib/Providers/AWSAppSyncProvider.d.ts +21 -0
- package/lib/Providers/AWSAppSyncProvider.js +20 -102
- package/lib/Providers/AWSAppSyncProvider.js.map +1 -1
- package/lib/Providers/AWSAppSyncRealTimeProvider/index.d.ts +75 -0
- package/lib/Providers/AWSAppSyncRealTimeProvider/index.js +158 -210
- package/lib/Providers/AWSAppSyncRealTimeProvider/index.js.map +1 -1
- package/lib/Providers/AWSIotProvider.d.ts +11 -0
- package/lib/Providers/AWSIotProvider.js +6 -64
- package/lib/Providers/AWSIotProvider.js.map +1 -1
- package/lib/Providers/MqttOverWSProvider.d.ts +41 -0
- package/lib/Providers/MqttOverWSProvider.js +158 -204
- package/lib/Providers/MqttOverWSProvider.js.map +1 -1
- package/lib/Providers/PubSubProvider.d.ts +13 -0
- package/lib/Providers/PubSubProvider.js +3 -13
- package/lib/Providers/PubSubProvider.js.map +1 -1
- package/lib/Providers/constants.d.ts +95 -0
- package/lib/Providers/constants.js +8 -0
- package/lib/Providers/constants.js.map +1 -1
- package/lib/Providers/index.d.ts +5 -0
- package/lib/Providers/index.js +13 -20
- package/lib/Providers/index.js.map +1 -1
- package/lib/PubSub.d.ts +51 -0
- package/lib/PubSub.js +8 -56
- package/lib/PubSub.js.map +1 -1
- package/lib/index.d.ts +4 -0
- package/lib/index.js +9 -20
- package/lib/index.js.map +1 -1
- package/lib/types/Provider.d.ts +14 -0
- package/lib/types/PubSub.d.ts +24 -0
- package/lib/types/PubSub.js +2 -12
- package/lib/types/PubSub.js.map +1 -1
- package/lib/types/index.d.ts +2 -0
- package/lib/types/index.js +2 -4
- package/lib/types/index.js.map +1 -1
- package/lib/utils/ConnectionStateMonitor.d.ts +41 -0
- package/lib/utils/ConnectionStateMonitor.js +16 -29
- package/lib/utils/ConnectionStateMonitor.js.map +1 -1
- package/lib/utils/ReachabilityMonitor/index.d.ts +3 -0
- package/lib/utils/ReachabilityMonitor/index.native.d.ts +3 -0
- package/lib/utils/ReachabilityMonitor/index.native.js +2 -4
- package/lib/utils/ReachabilityMonitor/index.native.js.map +1 -1
- package/lib/utils/ReconnectionMonitor.d.ts +29 -0
- package/lib/utils/ReconnectionMonitor.js +73 -0
- package/lib/utils/ReconnectionMonitor.js.map +1 -0
- package/lib-esm/.tsbuildinfo +3 -0
- package/lib-esm/Providers/AWSAppSyncProvider.js +1 -80
- package/lib-esm/Providers/AWSAppSyncProvider.js.map +1 -1
- package/lib-esm/Providers/AWSAppSyncRealTimeProvider/index.d.ts +8 -0
- package/lib-esm/Providers/AWSAppSyncRealTimeProvider/index.js +126 -168
- package/lib-esm/Providers/AWSAppSyncRealTimeProvider/index.js.map +1 -1
- package/lib-esm/Providers/AWSIotProvider.js +3 -61
- package/lib-esm/Providers/AWSIotProvider.js.map +1 -1
- package/lib-esm/Providers/MqttOverWSProvider.d.ts +2 -4
- package/lib-esm/Providers/MqttOverWSProvider.js +139 -175
- package/lib-esm/Providers/MqttOverWSProvider.js.map +1 -1
- package/lib-esm/Providers/PubSubProvider.js +1 -11
- package/lib-esm/Providers/PubSubProvider.js.map +1 -1
- package/lib-esm/Providers/constants.d.ts +8 -0
- package/lib-esm/Providers/constants.js +8 -0
- package/lib-esm/Providers/constants.js.map +1 -1
- package/lib-esm/Providers/index.d.ts +5 -5
- package/lib-esm/Providers/index.js +7 -17
- package/lib-esm/Providers/index.js.map +1 -1
- package/lib-esm/PubSub.js +3 -48
- package/lib-esm/PubSub.js.map +1 -1
- package/lib-esm/index.d.ts +2 -7
- package/lib-esm/index.js +4 -19
- package/lib-esm/index.js.map +1 -1
- package/lib-esm/types/Provider.d.ts +0 -4
- package/lib-esm/types/PubSub.js +2 -12
- package/lib-esm/types/PubSub.js.map +1 -1
- package/lib-esm/types/index.js.map +1 -1
- package/lib-esm/utils/ConnectionStateMonitor.d.ts +1 -0
- package/lib-esm/utils/ConnectionStateMonitor.js +13 -23
- package/lib-esm/utils/ConnectionStateMonitor.js.map +1 -1
- package/lib-esm/utils/ReconnectionMonitor.d.ts +29 -0
- package/lib-esm/utils/ReconnectionMonitor.js +71 -0
- package/lib-esm/utils/ReconnectionMonitor.js.map +1 -0
- package/package.json +14 -10
- package/src/Providers/AWSAppSyncProvider.ts +2 -12
- package/src/Providers/AWSAppSyncRealTimeProvider/index.ts +142 -89
- package/src/Providers/AWSIotProvider.ts +2 -12
- package/src/Providers/MqttOverWSProvider.ts +90 -79
- package/src/Providers/PubSubProvider.ts +2 -12
- package/src/Providers/constants.ts +10 -0
- package/src/Providers/index.ts +15 -17
- package/src/PubSub.ts +2 -12
- package/src/index.ts +15 -23
- package/src/types/Provider.ts +2 -17
- package/src/types/PubSub.ts +2 -12
- package/src/types/index.ts +2 -12
- package/src/utils/ConnectionStateMonitor.ts +16 -12
- package/src/utils/ReconnectionMonitor.ts +74 -0
- package/build.js +0 -5
- package/dist/aws-amplify-pubsub.js +0 -10314
- package/dist/aws-amplify-pubsub.js.map +0 -1
- package/dist/aws-amplify-pubsub.min.js +0 -11
- package/dist/aws-amplify-pubsub.min.js.map +0 -1
- package/index.js +0 -7
- package/webpack.config.dev.js +0 -6
package/src/Providers/index.ts
CHANGED
|
@@ -1,17 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
export * from './AWSIotProvider';
|
|
17
|
-
export * from './MqttOverWSProvider';
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
export { AbstractPubSubProvider } from './PubSubProvider';
|
|
4
|
+
export { AWSAppSyncProvider } from './AWSAppSyncProvider';
|
|
5
|
+
export {
|
|
6
|
+
AWSAppSyncRealTimeProvider,
|
|
7
|
+
AWSAppSyncRealTimeProviderOptions,
|
|
8
|
+
ObserverQuery,
|
|
9
|
+
} from './AWSAppSyncRealTimeProvider';
|
|
10
|
+
export { AWSIoTProvider, AWSIoTProviderOptions } from './AWSIotProvider';
|
|
11
|
+
export {
|
|
12
|
+
MqttProviderOptions,
|
|
13
|
+
MqttOverWSProvider,
|
|
14
|
+
mqttTopicMatch,
|
|
15
|
+
} from './MqttOverWSProvider';
|
package/src/PubSub.ts
CHANGED
|
@@ -1,15 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
*
|
|
4
|
-
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
|
|
5
|
-
* the License. A copy of the License is located at
|
|
6
|
-
*
|
|
7
|
-
* http://aws.amazon.com/apache2.0/
|
|
8
|
-
*
|
|
9
|
-
* or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
|
10
|
-
* CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
|
|
11
|
-
* and limitations under the License.
|
|
12
|
-
*/
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
13
3
|
// import '../Common/Polyfills';
|
|
14
4
|
import Observable from 'zen-observable-ts';
|
|
15
5
|
|
package/src/index.ts
CHANGED
|
@@ -1,26 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
*
|
|
4
|
-
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
|
|
5
|
-
* the License. A copy of the License is located at
|
|
6
|
-
*
|
|
7
|
-
* http://aws.amazon.com/apache2.0/
|
|
8
|
-
*
|
|
9
|
-
* or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
|
10
|
-
* CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
|
|
11
|
-
* and limitations under the License.
|
|
12
|
-
*/
|
|
13
|
-
import { PubSub } from './PubSub';
|
|
14
|
-
|
|
15
|
-
export * from './Providers';
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
16
3
|
|
|
4
|
+
export { PubSub } from './PubSub';
|
|
17
5
|
export { CONNECTION_STATE_CHANGE } from './Providers/constants';
|
|
18
|
-
|
|
19
6
|
export { ConnectionState, CONTROL_MSG } from './types';
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
7
|
+
export {
|
|
8
|
+
AWSAppSyncProvider,
|
|
9
|
+
AWSAppSyncRealTimeProvider,
|
|
10
|
+
AWSAppSyncRealTimeProviderOptions,
|
|
11
|
+
AWSIoTProvider,
|
|
12
|
+
AWSIoTProviderOptions,
|
|
13
|
+
AbstractPubSubProvider,
|
|
14
|
+
MqttOverWSProvider,
|
|
15
|
+
MqttProviderOptions,
|
|
16
|
+
ObserverQuery,
|
|
17
|
+
mqttTopicMatch,
|
|
18
|
+
} from './Providers';
|
package/src/types/Provider.ts
CHANGED
|
@@ -1,15 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
*
|
|
4
|
-
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
|
|
5
|
-
* the License. A copy of the License is located at
|
|
6
|
-
*
|
|
7
|
-
* http://aws.amazon.com/apache2.0/
|
|
8
|
-
*
|
|
9
|
-
* or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
|
10
|
-
* CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
|
|
11
|
-
* and limitations under the License.
|
|
12
|
-
*/
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
13
3
|
import Observable from 'zen-observable-ts';
|
|
14
4
|
|
|
15
5
|
export interface PubSubOptions {
|
|
@@ -20,11 +10,6 @@ export interface ProviderOptions {
|
|
|
20
10
|
[key: string]: any;
|
|
21
11
|
}
|
|
22
12
|
|
|
23
|
-
/**
|
|
24
|
-
* @deprecated Migrated to ProviderOptions
|
|
25
|
-
*/
|
|
26
|
-
export type ProvidertOptions = ProviderOptions;
|
|
27
|
-
|
|
28
13
|
export interface PubSubProvider {
|
|
29
14
|
// configure your provider
|
|
30
15
|
configure(config: object): object;
|
package/src/types/PubSub.ts
CHANGED
|
@@ -1,15 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
*
|
|
4
|
-
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
|
|
5
|
-
* the License. A copy of the License is located at
|
|
6
|
-
*
|
|
7
|
-
* http://aws.amazon.com/apache2.0/
|
|
8
|
-
*
|
|
9
|
-
* or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
|
10
|
-
* CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
|
|
11
|
-
* and limitations under the License.
|
|
12
|
-
*/
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
13
3
|
|
|
14
4
|
export interface SubscriptionObserver<T> {
|
|
15
5
|
closed: boolean;
|
package/src/types/index.ts
CHANGED
|
@@ -1,14 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
*
|
|
4
|
-
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
|
|
5
|
-
* the License. A copy of the License is located at
|
|
6
|
-
*
|
|
7
|
-
* http://aws.amazon.com/apache2.0/
|
|
8
|
-
*
|
|
9
|
-
* or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
|
10
|
-
* CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
|
|
11
|
-
* and limitations under the License.
|
|
12
|
-
*/
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
13
3
|
export * from './Provider';
|
|
14
4
|
export * from './PubSub';
|
|
@@ -1,15 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
*
|
|
4
|
-
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
|
|
5
|
-
* the License. A copy of the License is located at
|
|
6
|
-
*
|
|
7
|
-
* http://aws.amazon.com/apache2.0/
|
|
8
|
-
*
|
|
9
|
-
* or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
|
10
|
-
* CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
|
|
11
|
-
* and limitations under the License.
|
|
12
|
-
*/
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
13
3
|
|
|
14
4
|
import { Reachability } from '@aws-amplify/core';
|
|
15
5
|
import Observable, { ZenObservable } from 'zen-observable-ts';
|
|
@@ -63,6 +53,7 @@ export class ConnectionStateMonitor {
|
|
|
63
53
|
private _linkedConnectionStateObservable: Observable<LinkedConnectionStates>;
|
|
64
54
|
private _linkedConnectionStateObserver: ZenObservable.SubscriptionObserver<LinkedConnectionStates>;
|
|
65
55
|
private _networkMonitoringSubscription?: ZenObservable.Subscription;
|
|
56
|
+
private _initialNetworkStateSubscription?: ZenObservable.Subscription;
|
|
66
57
|
|
|
67
58
|
constructor() {
|
|
68
59
|
this._networkMonitoringSubscription = undefined;
|
|
@@ -73,6 +64,16 @@ export class ConnectionStateMonitor {
|
|
|
73
64
|
keepAliveState: 'healthy',
|
|
74
65
|
};
|
|
75
66
|
|
|
67
|
+
// Attempt to update the state with the current actual network state
|
|
68
|
+
this._initialNetworkStateSubscription = ReachabilityMonitor().subscribe(
|
|
69
|
+
({ online }) => {
|
|
70
|
+
this.record(
|
|
71
|
+
online ? CONNECTION_CHANGE.ONLINE : CONNECTION_CHANGE.OFFLINE
|
|
72
|
+
);
|
|
73
|
+
this._initialNetworkStateSubscription?.unsubscribe();
|
|
74
|
+
}
|
|
75
|
+
);
|
|
76
|
+
|
|
76
77
|
this._linkedConnectionStateObservable =
|
|
77
78
|
new Observable<LinkedConnectionStates>(connectionStateObserver => {
|
|
78
79
|
connectionStateObserver.next(this._linkedConnectionState);
|
|
@@ -84,6 +85,9 @@ export class ConnectionStateMonitor {
|
|
|
84
85
|
* Turn network state monitoring on if it isn't on already
|
|
85
86
|
*/
|
|
86
87
|
private enableNetworkMonitoring() {
|
|
88
|
+
// If no initial network state was discovered, stop trying
|
|
89
|
+
this._initialNetworkStateSubscription?.unsubscribe();
|
|
90
|
+
|
|
87
91
|
// Maintain the network state based on the reachability monitor
|
|
88
92
|
if (this._networkMonitoringSubscription === undefined) {
|
|
89
93
|
this._networkMonitoringSubscription = ReachabilityMonitor().subscribe(
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { Observer } from 'zen-observable-ts';
|
|
2
|
+
import { RECONNECT_DELAY, RECONNECT_INTERVAL } from '../Providers/constants';
|
|
3
|
+
|
|
4
|
+
export enum ReconnectEvent {
|
|
5
|
+
START_RECONNECT = 'START_RECONNECT',
|
|
6
|
+
HALT_RECONNECT = 'HALT_RECONNECT',
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Captures the reconnect event logic used to determine when to reconnect to PubSub providers.
|
|
11
|
+
* Reconnnect attempts are delayed by 5 seconds to let the interface settle.
|
|
12
|
+
* Attempting to reconnect only once creates unrecoverable states when the network state isn't
|
|
13
|
+
* supported by the browser, so this keeps retrying every minute until halted.
|
|
14
|
+
*/
|
|
15
|
+
export class ReconnectionMonitor {
|
|
16
|
+
private reconnectObservers: Observer<void>[] = [];
|
|
17
|
+
private reconnectIntervalId?: ReturnType<typeof setInterval>;
|
|
18
|
+
private reconnectSetTimeoutId?: ReturnType<typeof setTimeout>;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Add reconnect observer to the list of observers to alert on reconnect
|
|
22
|
+
*/
|
|
23
|
+
addObserver(reconnectObserver: Observer<void>) {
|
|
24
|
+
this.reconnectObservers.push(reconnectObserver);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Given a reconnect event, start the appropriate behavior
|
|
29
|
+
*/
|
|
30
|
+
record(event: ReconnectEvent) {
|
|
31
|
+
if (event === ReconnectEvent.START_RECONNECT) {
|
|
32
|
+
// If the reconnection hasn't been started
|
|
33
|
+
if (
|
|
34
|
+
this.reconnectSetTimeoutId === undefined &&
|
|
35
|
+
this.reconnectIntervalId === undefined
|
|
36
|
+
) {
|
|
37
|
+
this.reconnectSetTimeoutId = setTimeout(() => {
|
|
38
|
+
// Reconnect now
|
|
39
|
+
this._triggerReconnect();
|
|
40
|
+
// Retry reconnect every periodically until it works
|
|
41
|
+
this.reconnectIntervalId = setInterval(() => {
|
|
42
|
+
this._triggerReconnect();
|
|
43
|
+
}, RECONNECT_INTERVAL);
|
|
44
|
+
}, RECONNECT_DELAY);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (event === ReconnectEvent.HALT_RECONNECT) {
|
|
49
|
+
if (this.reconnectIntervalId) {
|
|
50
|
+
clearInterval(this.reconnectIntervalId);
|
|
51
|
+
this.reconnectIntervalId = undefined;
|
|
52
|
+
}
|
|
53
|
+
if (this.reconnectSetTimeoutId) {
|
|
54
|
+
clearTimeout(this.reconnectSetTimeoutId);
|
|
55
|
+
this.reconnectSetTimeoutId = undefined;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Complete all reconnect observers
|
|
62
|
+
*/
|
|
63
|
+
close() {
|
|
64
|
+
this.reconnectObservers.forEach(reconnectObserver => {
|
|
65
|
+
reconnectObserver.complete?.();
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
private _triggerReconnect() {
|
|
70
|
+
this.reconnectObservers.forEach(reconnectObserver => {
|
|
71
|
+
reconnectObserver.next?.();
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
}
|