@aws-amplify/pubsub 6.0.1-api-v6-models.9351bcf.0 → 6.0.1-api-v6-models.891fe0d.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/lib/Providers/AWSIot.js +27 -49
- package/lib/Providers/MqttOverWS.d.ts +5 -3
- package/lib/Providers/MqttOverWS.js +196 -320
- package/lib/Providers/PubSub.d.ts +3 -4
- package/lib/Providers/PubSub.js +12 -18
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/types/PubSub.d.ts +11 -2
- package/lib/utils/ConnectionStateMonitor.js +51 -64
- package/lib/utils/ReachabilityMonitor/index.js +2 -2
- package/lib/utils/ReachabilityMonitor/index.native.js +4 -6
- package/lib/utils/ReconnectionMonitor.js +20 -24
- package/lib-esm/Providers/AWSIot.js +24 -47
- package/lib-esm/Providers/MqttOverWS.d.ts +5 -3
- package/lib-esm/Providers/MqttOverWS.js +186 -312
- package/lib-esm/Providers/PubSub.d.ts +3 -4
- package/lib-esm/Providers/PubSub.js +11 -18
- package/lib-esm/Providers/constants.js +10 -10
- package/lib-esm/tsconfig.tsbuildinfo +1 -1
- package/lib-esm/types/PubSub.d.ts +11 -2
- package/lib-esm/utils/ConnectionStateMonitor.js +49 -63
- package/lib-esm/utils/ReachabilityMonitor/index.js +1 -1
- package/lib-esm/utils/ReachabilityMonitor/index.native.js +1 -3
- package/lib-esm/utils/ReconnectionMonitor.js +19 -24
- package/package.json +6 -10
- package/src/Providers/MqttOverWS.ts +9 -7
- package/src/Providers/PubSub.ts +10 -13
- package/src/types/PubSub.ts +13 -9
|
@@ -3,10 +3,9 @@
|
|
|
3
3
|
// SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
5
|
exports.ConnectionStateMonitor = exports.CONNECTION_CHANGE = void 0;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
var ReachabilityMonitor_1 = require("./ReachabilityMonitor");
|
|
6
|
+
const rxjs_1 = require("rxjs");
|
|
7
|
+
const PubSub_1 = require("../types/PubSub");
|
|
8
|
+
const ReachabilityMonitor_1 = require("./ReachabilityMonitor");
|
|
10
9
|
exports.CONNECTION_CHANGE = {
|
|
11
10
|
KEEP_ALIVE_MISSED: { keepAliveState: 'unhealthy' },
|
|
12
11
|
KEEP_ALIVE: { keepAliveState: 'healthy' },
|
|
@@ -24,9 +23,8 @@ exports.CONNECTION_CHANGE = {
|
|
|
24
23
|
ONLINE: { networkState: 'connected' },
|
|
25
24
|
OFFLINE: { networkState: 'disconnected' },
|
|
26
25
|
};
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
var _this = this;
|
|
26
|
+
class ConnectionStateMonitor {
|
|
27
|
+
constructor() {
|
|
30
28
|
this._networkMonitoringSubscription = undefined;
|
|
31
29
|
this._linkedConnectionState = {
|
|
32
30
|
networkState: 'connected',
|
|
@@ -35,73 +33,61 @@ var ConnectionStateMonitor = /** @class */ (function () {
|
|
|
35
33
|
keepAliveState: 'healthy',
|
|
36
34
|
};
|
|
37
35
|
// Attempt to update the state with the current actual network state
|
|
38
|
-
this._initialNetworkStateSubscription = (0, ReachabilityMonitor_1.ReachabilityMonitor)().subscribe(
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
_this.record(online ? exports.CONNECTION_CHANGE.ONLINE : exports.CONNECTION_CHANGE.OFFLINE);
|
|
42
|
-
(_b = _this._initialNetworkStateSubscription) === null || _b === void 0 ? void 0 : _b.unsubscribe();
|
|
36
|
+
this._initialNetworkStateSubscription = (0, ReachabilityMonitor_1.ReachabilityMonitor)().subscribe(({ online }) => {
|
|
37
|
+
this.record(online ? exports.CONNECTION_CHANGE.ONLINE : exports.CONNECTION_CHANGE.OFFLINE);
|
|
38
|
+
this._initialNetworkStateSubscription?.unsubscribe();
|
|
43
39
|
});
|
|
44
40
|
this._linkedConnectionStateObservable =
|
|
45
|
-
new rxjs_1.Observable(
|
|
46
|
-
connectionStateObserver.next(
|
|
47
|
-
|
|
41
|
+
new rxjs_1.Observable(connectionStateObserver => {
|
|
42
|
+
connectionStateObserver.next(this._linkedConnectionState);
|
|
43
|
+
this._linkedConnectionStateObserver = connectionStateObserver;
|
|
48
44
|
});
|
|
49
45
|
}
|
|
50
46
|
/**
|
|
51
47
|
* Turn network state monitoring on if it isn't on already
|
|
52
48
|
*/
|
|
53
|
-
|
|
54
|
-
var _this = this;
|
|
55
|
-
var _a;
|
|
49
|
+
enableNetworkMonitoring() {
|
|
56
50
|
// If no initial network state was discovered, stop trying
|
|
57
|
-
|
|
51
|
+
this._initialNetworkStateSubscription?.unsubscribe();
|
|
58
52
|
// Maintain the network state based on the reachability monitor
|
|
59
53
|
if (this._networkMonitoringSubscription === undefined) {
|
|
60
|
-
this._networkMonitoringSubscription = (0, ReachabilityMonitor_1.ReachabilityMonitor)().subscribe(
|
|
61
|
-
|
|
62
|
-
_this.record(online ? exports.CONNECTION_CHANGE.ONLINE : exports.CONNECTION_CHANGE.OFFLINE);
|
|
54
|
+
this._networkMonitoringSubscription = (0, ReachabilityMonitor_1.ReachabilityMonitor)().subscribe(({ online }) => {
|
|
55
|
+
this.record(online ? exports.CONNECTION_CHANGE.ONLINE : exports.CONNECTION_CHANGE.OFFLINE);
|
|
63
56
|
});
|
|
64
57
|
}
|
|
65
|
-
}
|
|
58
|
+
}
|
|
66
59
|
/**
|
|
67
60
|
* Turn network state monitoring off if it isn't off already
|
|
68
61
|
*/
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
(_a = this._networkMonitoringSubscription) === null || _a === void 0 ? void 0 : _a.unsubscribe();
|
|
62
|
+
disableNetworkMonitoring() {
|
|
63
|
+
this._networkMonitoringSubscription?.unsubscribe();
|
|
72
64
|
this._networkMonitoringSubscription = undefined;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
return this.
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
}));
|
|
96
|
-
},
|
|
97
|
-
enumerable: false,
|
|
98
|
-
configurable: true
|
|
99
|
-
});
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Get the observable that allows us to monitor the connection state
|
|
68
|
+
*
|
|
69
|
+
* @returns {Observable<ConnectionState>} - The observable that emits ConnectionState updates
|
|
70
|
+
*/
|
|
71
|
+
get connectionStateObservable() {
|
|
72
|
+
let previous;
|
|
73
|
+
// The linked state aggregates state changes to any of the network, connection,
|
|
74
|
+
// intendedConnection and keepAliveHealth. Some states will change these independent
|
|
75
|
+
// states without changing the overall connection state.
|
|
76
|
+
// After translating from linked states to ConnectionState, then remove any duplicates
|
|
77
|
+
return this._linkedConnectionStateObservable
|
|
78
|
+
.pipe((0, rxjs_1.map)(value => {
|
|
79
|
+
return this.connectionStatesTranslator(value);
|
|
80
|
+
}))
|
|
81
|
+
.pipe((0, rxjs_1.filter)(current => {
|
|
82
|
+
const toInclude = current !== previous;
|
|
83
|
+
previous = current;
|
|
84
|
+
return toInclude;
|
|
85
|
+
}));
|
|
86
|
+
}
|
|
100
87
|
/*
|
|
101
88
|
* Updates local connection state and emits the full state to the observer.
|
|
102
89
|
*/
|
|
103
|
-
|
|
104
|
-
var _a;
|
|
90
|
+
record(statusUpdates) {
|
|
105
91
|
// Maintain the network monitor
|
|
106
92
|
if (statusUpdates.intendedConnectionState === 'connected') {
|
|
107
93
|
this.enableNetworkMonitoring();
|
|
@@ -110,15 +96,17 @@ var ConnectionStateMonitor = /** @class */ (function () {
|
|
|
110
96
|
this.disableNetworkMonitoring();
|
|
111
97
|
}
|
|
112
98
|
// Maintain the socket state
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
99
|
+
const newSocketStatus = {
|
|
100
|
+
...this._linkedConnectionState,
|
|
101
|
+
...statusUpdates,
|
|
102
|
+
};
|
|
103
|
+
this._linkedConnectionState = { ...newSocketStatus };
|
|
104
|
+
this._linkedConnectionStateObserver?.next(this._linkedConnectionState);
|
|
105
|
+
}
|
|
117
106
|
/*
|
|
118
107
|
* Translate the ConnectionState structure into a specific ConnectionState string literal union
|
|
119
108
|
*/
|
|
120
|
-
|
|
121
|
-
var connectionState = _a.connectionState, networkState = _a.networkState, intendedConnectionState = _a.intendedConnectionState, keepAliveState = _a.keepAliveState;
|
|
109
|
+
connectionStatesTranslator({ connectionState, networkState, intendedConnectionState, keepAliveState, }) {
|
|
122
110
|
if (connectionState === 'connected' && networkState === 'disconnected')
|
|
123
111
|
return PubSub_1.ConnectionState.ConnectedPendingNetwork;
|
|
124
112
|
if (connectionState === 'connected' &&
|
|
@@ -139,7 +127,6 @@ var ConnectionStateMonitor = /** @class */ (function () {
|
|
|
139
127
|
if (connectionState === 'disconnected')
|
|
140
128
|
return PubSub_1.ConnectionState.Disconnected;
|
|
141
129
|
return PubSub_1.ConnectionState.Connected;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
}());
|
|
130
|
+
}
|
|
131
|
+
}
|
|
145
132
|
exports.ConnectionStateMonitor = ConnectionStateMonitor;
|
|
@@ -3,6 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.ReachabilityMonitor = void 0;
|
|
4
4
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
5
5
|
// SPDX-License-Identifier: Apache-2.0
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
const utils_1 = require("@aws-amplify/core/internals/utils");
|
|
7
|
+
const ReachabilityMonitor = () => new utils_1.Reachability().networkMonitor();
|
|
8
8
|
exports.ReachabilityMonitor = ReachabilityMonitor;
|
|
@@ -3,10 +3,8 @@
|
|
|
3
3
|
// SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
5
|
exports.ReachabilityMonitor = void 0;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
return new utils_1.Reachability().networkMonitor(netinfo_1.default);
|
|
11
|
-
};
|
|
6
|
+
const tslib_1 = require("tslib");
|
|
7
|
+
const utils_1 = require("@aws-amplify/core/internals/utils");
|
|
8
|
+
const netinfo_1 = tslib_1.__importDefault(require("@react-native-community/netinfo"));
|
|
9
|
+
const ReachabilityMonitor = () => new utils_1.Reachability().networkMonitor(netinfo_1.default);
|
|
12
10
|
exports.ReachabilityMonitor = ReachabilityMonitor;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ReconnectionMonitor = exports.ReconnectEvent = void 0;
|
|
4
|
-
|
|
4
|
+
const constants_1 = require("../Providers/constants");
|
|
5
5
|
var ReconnectEvent;
|
|
6
6
|
(function (ReconnectEvent) {
|
|
7
7
|
ReconnectEvent["START_RECONNECT"] = "START_RECONNECT";
|
|
@@ -13,31 +13,30 @@ var ReconnectEvent;
|
|
|
13
13
|
* Attempting to reconnect only once creates unrecoverable states when the network state isn't
|
|
14
14
|
* supported by the browser, so this keeps retrying every minute until halted.
|
|
15
15
|
*/
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
class ReconnectionMonitor {
|
|
17
|
+
constructor() {
|
|
18
18
|
this.reconnectObservers = [];
|
|
19
19
|
}
|
|
20
20
|
/**
|
|
21
21
|
* Add reconnect observer to the list of observers to alert on reconnect
|
|
22
22
|
*/
|
|
23
|
-
|
|
23
|
+
addObserver(reconnectObserver) {
|
|
24
24
|
this.reconnectObservers.push(reconnectObserver);
|
|
25
|
-
}
|
|
25
|
+
}
|
|
26
26
|
/**
|
|
27
27
|
* Given a reconnect event, start the appropriate behavior
|
|
28
28
|
*/
|
|
29
|
-
|
|
30
|
-
var _this = this;
|
|
29
|
+
record(event) {
|
|
31
30
|
if (event === ReconnectEvent.START_RECONNECT) {
|
|
32
31
|
// If the reconnection hasn't been started
|
|
33
32
|
if (this.reconnectSetTimeoutId === undefined &&
|
|
34
33
|
this.reconnectIntervalId === undefined) {
|
|
35
|
-
this.reconnectSetTimeoutId = setTimeout(
|
|
34
|
+
this.reconnectSetTimeoutId = setTimeout(() => {
|
|
36
35
|
// Reconnect now
|
|
37
|
-
|
|
36
|
+
this._triggerReconnect();
|
|
38
37
|
// Retry reconnect every periodically until it works
|
|
39
|
-
|
|
40
|
-
|
|
38
|
+
this.reconnectIntervalId = setInterval(() => {
|
|
39
|
+
this._triggerReconnect();
|
|
41
40
|
}, constants_1.RECONNECT_INTERVAL);
|
|
42
41
|
}, constants_1.RECONNECT_DELAY);
|
|
43
42
|
}
|
|
@@ -52,22 +51,19 @@ var ReconnectionMonitor = /** @class */ (function () {
|
|
|
52
51
|
this.reconnectSetTimeoutId = undefined;
|
|
53
52
|
}
|
|
54
53
|
}
|
|
55
|
-
}
|
|
54
|
+
}
|
|
56
55
|
/**
|
|
57
56
|
* Complete all reconnect observers
|
|
58
57
|
*/
|
|
59
|
-
|
|
60
|
-
this.reconnectObservers.forEach(
|
|
61
|
-
|
|
62
|
-
(_a = reconnectObserver.complete) === null || _a === void 0 ? void 0 : _a.call(reconnectObserver);
|
|
58
|
+
close() {
|
|
59
|
+
this.reconnectObservers.forEach(reconnectObserver => {
|
|
60
|
+
reconnectObserver.complete?.();
|
|
63
61
|
});
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
this.reconnectObservers.forEach(
|
|
67
|
-
|
|
68
|
-
(_a = reconnectObserver.next) === null || _a === void 0 ? void 0 : _a.call(reconnectObserver);
|
|
62
|
+
}
|
|
63
|
+
_triggerReconnect() {
|
|
64
|
+
this.reconnectObservers.forEach(reconnectObserver => {
|
|
65
|
+
reconnectObserver.next?.();
|
|
69
66
|
});
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
}());
|
|
67
|
+
}
|
|
68
|
+
}
|
|
73
69
|
exports.ReconnectionMonitor = ReconnectionMonitor;
|
|
@@ -1,53 +1,30 @@
|
|
|
1
|
-
import { __awaiter, __extends, __generator } from "tslib";
|
|
2
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
4
3
|
import { MqttOverWS } from './MqttOverWS';
|
|
5
4
|
import { Signer } from '@aws-amplify/core/internals/utils';
|
|
6
5
|
import { fetchAuthSession } from '@aws-amplify/core';
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
if (options === void 0) { options = {}; }
|
|
12
|
-
return _super.call(this, options) || this;
|
|
6
|
+
const SERVICE_NAME = 'iotdevicegateway';
|
|
7
|
+
export class AWSIoT extends MqttOverWS {
|
|
8
|
+
constructor(options = {}) {
|
|
9
|
+
super(options);
|
|
13
10
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
};
|
|
35
|
-
return [4 /*yield*/, fetchAuthSession()];
|
|
36
|
-
case 1:
|
|
37
|
-
session = _b.sent();
|
|
38
|
-
if (!session.credentials) {
|
|
39
|
-
throw new Error('No auth session credentials');
|
|
40
|
-
}
|
|
41
|
-
_a = session.credentials, access_key = _a.accessKeyId, secret_key = _a.secretAccessKey, session_token = _a.sessionToken;
|
|
42
|
-
result = Signer.signUrl(endpoint, { access_key: access_key, secret_key: secret_key, session_token: session_token }, serviceInfo);
|
|
43
|
-
return [2 /*return*/, result];
|
|
44
|
-
}
|
|
45
|
-
});
|
|
46
|
-
}); })();
|
|
47
|
-
},
|
|
48
|
-
enumerable: false,
|
|
49
|
-
configurable: true
|
|
50
|
-
});
|
|
51
|
-
return AWSIoT;
|
|
52
|
-
}(MqttOverWS));
|
|
53
|
-
export { AWSIoT };
|
|
11
|
+
get region() {
|
|
12
|
+
return this.options?.region;
|
|
13
|
+
}
|
|
14
|
+
get endpoint() {
|
|
15
|
+
return (async () => {
|
|
16
|
+
const endpoint = this.options.endpoint;
|
|
17
|
+
const serviceInfo = {
|
|
18
|
+
service: SERVICE_NAME,
|
|
19
|
+
region: this.region,
|
|
20
|
+
};
|
|
21
|
+
const session = await fetchAuthSession();
|
|
22
|
+
if (!session.credentials) {
|
|
23
|
+
throw new Error('No auth session credentials');
|
|
24
|
+
}
|
|
25
|
+
const { accessKeyId: access_key, secretAccessKey: secret_key, sessionToken: session_token, } = session.credentials;
|
|
26
|
+
const result = Signer.signUrl(endpoint, { access_key, secret_key, session_token }, serviceInfo);
|
|
27
|
+
return result;
|
|
28
|
+
})();
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Observable } from 'rxjs';
|
|
2
2
|
import { AbstractPubSub } from './PubSub';
|
|
3
|
-
import { PubSubContentObserver, PubSubContent, PubSubOptions } from '../types/PubSub';
|
|
3
|
+
import { PubSubContentObserver, PubSubContent, PubSubOptions, PublishInput, SubscribeInput } from '../types/PubSub';
|
|
4
4
|
export declare function mqttTopicMatch(filter: string, topic: string): boolean;
|
|
5
5
|
export interface MqttOptions extends PubSubOptions {
|
|
6
6
|
clientId?: string;
|
|
@@ -47,10 +47,12 @@ export declare class MqttOverWS extends AbstractPubSub<MqttOptions> {
|
|
|
47
47
|
newClient({ url, clientId }: MqttOptions): Promise<PahoClient>;
|
|
48
48
|
protected connect(clientId: string, options?: MqttOptions): Promise<PahoClient | undefined>;
|
|
49
49
|
protected disconnect(clientId: string): Promise<void>;
|
|
50
|
-
publish(topics
|
|
50
|
+
publish({ topics, message }: PublishInput): Promise<void>;
|
|
51
51
|
protected _topicObservers: Map<string, Set<PubSubContentObserver>>;
|
|
52
52
|
protected _clientIdObservers: Map<string, Set<PubSubContentObserver>>;
|
|
53
53
|
private _onMessage;
|
|
54
|
-
subscribe(topics
|
|
54
|
+
subscribe({ topics, options, }: SubscribeInput & {
|
|
55
|
+
options?: MqttOptions;
|
|
56
|
+
}): Observable<PubSubContent>;
|
|
55
57
|
}
|
|
56
58
|
export {};
|