@aws-amplify/pubsub 6.0.1-console-preview.f63250a.0 → 6.0.1-console-preview.b278dcb.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/iot/packages.json +7 -0
- package/lib/Providers/AWSIot.d.ts +10 -0
- package/lib/Providers/AWSIot.js +56 -0
- package/lib/Providers/{MqttOverWSProvider.d.ts → MqttOverWS.d.ts} +13 -15
- package/lib/Providers/{MqttOverWSProvider.js → MqttOverWS.js} +47 -45
- package/{lib-esm/Providers/PubSubProvider.d.ts → lib/Providers/PubSub.d.ts} +4 -7
- package/lib/Providers/PubSub.js +25 -0
- package/lib/Providers/constants.d.ts +1 -1
- package/lib/Providers/constants.js +3 -4
- package/lib/Providers/index.d.ts +3 -4
- package/lib/Providers/index.js +8 -10
- package/lib/clients/iot.d.ts +1 -0
- package/lib/clients/iot.js +7 -0
- package/lib/clients/mqtt.d.ts +1 -0
- package/lib/clients/mqtt.js +7 -0
- package/lib/index.d.ts +2 -2
- package/lib/index.js +7 -11
- package/lib/tsconfig.tsbuildinfo +1 -0
- package/lib/types/PubSub.d.ts +12 -3
- package/lib/types/PubSub.js +1 -1
- package/lib/types/index.d.ts +0 -1
- package/lib/types/index.js +5 -3
- package/lib/utils/ConnectionStateMonitor.d.ts +5 -5
- package/lib/utils/ConnectionStateMonitor.js +13 -12
- package/lib/utils/ReachabilityMonitor/index.d.ts +1 -3
- package/lib/utils/ReachabilityMonitor/index.js +4 -3
- package/lib/utils/ReachabilityMonitor/index.native.d.ts +1 -3
- package/lib/utils/ReachabilityMonitor/index.native.js +7 -6
- package/lib/utils/ReconnectionMonitor.d.ts +1 -1
- package/lib/utils/ReconnectionMonitor.js +1 -1
- package/lib-esm/Providers/AWSIot.d.ts +10 -0
- package/lib-esm/Providers/{AWSIotProvider.js → AWSIot.js} +23 -21
- package/lib-esm/Providers/{MqttOverWSProvider.d.ts → MqttOverWS.d.ts} +13 -15
- package/lib-esm/Providers/{MqttOverWSProvider.js → MqttOverWS.js} +41 -40
- package/{lib/Providers/PubSubProvider.d.ts → lib-esm/Providers/PubSub.d.ts} +4 -7
- package/lib-esm/Providers/PubSub.js +22 -0
- package/lib-esm/Providers/constants.d.ts +1 -1
- package/lib-esm/Providers/constants.js +1 -4
- package/lib-esm/Providers/index.d.ts +3 -4
- package/lib-esm/Providers/index.js +3 -5
- package/lib-esm/clients/iot.d.ts +1 -0
- package/{src/internals/index.ts → lib-esm/clients/iot.js} +1 -1
- package/lib-esm/clients/mqtt.d.ts +1 -0
- package/lib-esm/{internals/index.js → clients/mqtt.js} +1 -2
- package/lib-esm/index.d.ts +2 -2
- package/lib-esm/index.js +2 -3
- package/lib-esm/tsconfig.tsbuildinfo +1 -0
- package/lib-esm/types/PubSub.d.ts +12 -3
- package/lib-esm/types/PubSub.js +0 -1
- package/lib-esm/types/index.d.ts +0 -1
- package/lib-esm/types/index.js +2 -1
- package/lib-esm/utils/ConnectionStateMonitor.d.ts +5 -5
- package/lib-esm/utils/ConnectionStateMonitor.js +9 -9
- package/lib-esm/utils/ReachabilityMonitor/index.d.ts +1 -3
- package/lib-esm/utils/ReachabilityMonitor/index.js +1 -2
- package/lib-esm/utils/ReachabilityMonitor/index.native.d.ts +1 -3
- package/lib-esm/utils/ReachabilityMonitor/index.native.js +1 -2
- package/lib-esm/utils/ReconnectionMonitor.d.ts +1 -1
- package/lib-esm/utils/ReconnectionMonitor.js +0 -1
- package/mqtt/packages.json +7 -0
- package/package.json +55 -34
- package/src/Providers/{AWSIotProvider.ts → AWSIot.ts} +17 -15
- package/src/Providers/{MqttOverWSProvider.ts → MqttOverWS.ts} +30 -44
- package/src/Providers/{PubSubProvider.ts → PubSub.ts} +7 -17
- package/src/Providers/constants.ts +2 -6
- package/src/Providers/index.ts +3 -12
- package/src/clients/iot.ts +4 -0
- package/src/clients/mqtt.ts +7 -0
- package/src/index.ts +3 -12
- package/src/types/PubSub.ts +24 -5
- package/src/types/index.ts +0 -1
- package/src/utils/ConnectionStateMonitor.ts +17 -13
- package/src/utils/ReachabilityMonitor/index.native.ts +2 -1
- package/src/utils/ReachabilityMonitor/index.ts +1 -1
- package/src/utils/ReconnectionMonitor.ts +1 -1
- package/README.md +0 -3
- package/internals/package.json +0 -8
- package/lib/.tsbuildinfo +0 -3
- package/lib/Providers/AWSAppSyncRealTimeProvider/index.d.ts +0 -77
- package/lib/Providers/AWSAppSyncRealTimeProvider/index.js +0 -855
- package/lib/Providers/AWSAppSyncRealTimeProvider/index.js.map +0 -1
- package/lib/Providers/AWSIotProvider.d.ts +0 -11
- package/lib/Providers/AWSIotProvider.js +0 -53
- package/lib/Providers/AWSIotProvider.js.map +0 -1
- package/lib/Providers/MqttOverWSProvider.js.map +0 -1
- package/lib/Providers/PubSubProvider.js +0 -28
- package/lib/Providers/PubSubProvider.js.map +0 -1
- package/lib/Providers/constants.js.map +0 -1
- package/lib/Providers/index.js.map +0 -1
- package/lib/PubSub.d.ts +0 -13
- package/lib/PubSub.js +0 -22
- package/lib/PubSub.js.map +0 -1
- package/lib/index.js.map +0 -1
- package/lib/internals/InternalPubSub.d.ts +0 -50
- package/lib/internals/InternalPubSub.js +0 -136
- package/lib/internals/InternalPubSub.js.map +0 -1
- package/lib/internals/index.d.ts +0 -1
- package/lib/internals/index.js +0 -8
- package/lib/internals/index.js.map +0 -1
- package/lib/types/Provider.d.ts +0 -18
- package/lib/types/Provider.js +0 -3
- package/lib/types/Provider.js.map +0 -1
- package/lib/types/PubSub.js.map +0 -1
- package/lib/types/index.js.map +0 -1
- package/lib/utils/ConnectionStateMonitor.js.map +0 -1
- package/lib/utils/ReachabilityMonitor/index.js.map +0 -1
- package/lib/utils/ReachabilityMonitor/index.native.js.map +0 -1
- package/lib/utils/ReconnectionMonitor.js.map +0 -1
- package/lib/vendor/paho-mqtt.d.ts +0 -2
- package/lib/vendor/paho-mqtt.js.map +0 -1
- package/lib-esm/.tsbuildinfo +0 -3
- package/lib-esm/Providers/AWSAppSyncRealTimeProvider/index.d.ts +0 -77
- package/lib-esm/Providers/AWSAppSyncRealTimeProvider/index.js +0 -853
- package/lib-esm/Providers/AWSAppSyncRealTimeProvider/index.js.map +0 -1
- package/lib-esm/Providers/AWSIotProvider.d.ts +0 -11
- package/lib-esm/Providers/AWSIotProvider.js.map +0 -1
- package/lib-esm/Providers/MqttOverWSProvider.js.map +0 -1
- package/lib-esm/Providers/PubSubProvider.js +0 -26
- package/lib-esm/Providers/PubSubProvider.js.map +0 -1
- package/lib-esm/Providers/constants.js.map +0 -1
- package/lib-esm/Providers/index.js.map +0 -1
- package/lib-esm/PubSub.d.ts +0 -13
- package/lib-esm/PubSub.js +0 -20
- package/lib-esm/PubSub.js.map +0 -1
- package/lib-esm/index.js.map +0 -1
- package/lib-esm/internals/InternalPubSub.d.ts +0 -50
- package/lib-esm/internals/InternalPubSub.js +0 -134
- package/lib-esm/internals/InternalPubSub.js.map +0 -1
- package/lib-esm/internals/index.d.ts +0 -1
- package/lib-esm/internals/index.js.map +0 -1
- package/lib-esm/types/Provider.d.ts +0 -18
- package/lib-esm/types/Provider.js +0 -1
- package/lib-esm/types/Provider.js.map +0 -1
- package/lib-esm/types/PubSub.js.map +0 -1
- package/lib-esm/types/index.js.map +0 -1
- package/lib-esm/utils/ConnectionStateMonitor.js.map +0 -1
- package/lib-esm/utils/ReachabilityMonitor/index.js.map +0 -1
- package/lib-esm/utils/ReachabilityMonitor/index.native.js.map +0 -1
- package/lib-esm/utils/ReconnectionMonitor.js.map +0 -1
- package/lib-esm/vendor/paho-mqtt.d.ts +0 -2
- package/lib-esm/vendor/paho-mqtt.js.map +0 -1
- package/src/Providers/AWSAppSyncRealTimeProvider/index.ts +0 -1048
- package/src/PubSub.ts +0 -33
- package/src/internals/InternalPubSub.ts +0 -185
- package/src/types/Provider.ts +0 -37
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { MqttOverWS, MqttOptions } from './MqttOverWS';
|
|
2
|
+
export interface AWSIoTOptions extends MqttOptions {
|
|
3
|
+
region?: string;
|
|
4
|
+
endpoint?: string;
|
|
5
|
+
}
|
|
6
|
+
export declare class AWSIoT extends MqttOverWS {
|
|
7
|
+
constructor(options?: AWSIoTOptions);
|
|
8
|
+
protected get region(): string | undefined;
|
|
9
|
+
protected get endpoint(): Promise<string>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AWSIoT = void 0;
|
|
4
|
+
var tslib_1 = require("tslib");
|
|
5
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
6
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
7
|
+
var MqttOverWS_1 = require("./MqttOverWS");
|
|
8
|
+
var utils_1 = require("@aws-amplify/core/internals/utils");
|
|
9
|
+
var core_1 = require("@aws-amplify/core");
|
|
10
|
+
var SERVICE_NAME = 'iotdevicegateway';
|
|
11
|
+
var AWSIoT = /** @class */ (function (_super) {
|
|
12
|
+
tslib_1.__extends(AWSIoT, _super);
|
|
13
|
+
function AWSIoT(options) {
|
|
14
|
+
if (options === void 0) { options = {}; }
|
|
15
|
+
return _super.call(this, options) || this;
|
|
16
|
+
}
|
|
17
|
+
Object.defineProperty(AWSIoT.prototype, "region", {
|
|
18
|
+
get: function () {
|
|
19
|
+
var _a;
|
|
20
|
+
return (_a = this.options) === null || _a === void 0 ? void 0 : _a.region;
|
|
21
|
+
},
|
|
22
|
+
enumerable: false,
|
|
23
|
+
configurable: true
|
|
24
|
+
});
|
|
25
|
+
Object.defineProperty(AWSIoT.prototype, "endpoint", {
|
|
26
|
+
get: function () {
|
|
27
|
+
var _this = this;
|
|
28
|
+
return (function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
29
|
+
var endpoint, serviceInfo, session, _a, access_key, secret_key, session_token, result;
|
|
30
|
+
return tslib_1.__generator(this, function (_b) {
|
|
31
|
+
switch (_b.label) {
|
|
32
|
+
case 0:
|
|
33
|
+
endpoint = this.options.endpoint;
|
|
34
|
+
serviceInfo = {
|
|
35
|
+
service: SERVICE_NAME,
|
|
36
|
+
region: this.region,
|
|
37
|
+
};
|
|
38
|
+
return [4 /*yield*/, (0, core_1.fetchAuthSession)()];
|
|
39
|
+
case 1:
|
|
40
|
+
session = _b.sent();
|
|
41
|
+
if (!session.credentials) {
|
|
42
|
+
throw new Error('No auth session credentials');
|
|
43
|
+
}
|
|
44
|
+
_a = session.credentials, access_key = _a.accessKeyId, secret_key = _a.secretAccessKey, session_token = _a.sessionToken;
|
|
45
|
+
result = utils_1.Signer.signUrl(endpoint, { access_key: access_key, secret_key: secret_key, session_token: session_token }, serviceInfo);
|
|
46
|
+
return [2 /*return*/, result];
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
}); })();
|
|
50
|
+
},
|
|
51
|
+
enumerable: false,
|
|
52
|
+
configurable: true
|
|
53
|
+
});
|
|
54
|
+
return AWSIoT;
|
|
55
|
+
}(MqttOverWS_1.MqttOverWS));
|
|
56
|
+
exports.AWSIoT = AWSIoT;
|
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import Observable from '
|
|
2
|
-
import {
|
|
3
|
-
import { PubSubContentObserver, PubSubContent } from '../types/PubSub';
|
|
4
|
-
import { ProviderOptions } from '../types/Provider';
|
|
1
|
+
import { Observable } from 'rxjs';
|
|
2
|
+
import { AbstractPubSub } from './PubSub';
|
|
3
|
+
import { PubSubContentObserver, PubSubContent, PubSubOptions } from '../types/PubSub';
|
|
5
4
|
export declare function mqttTopicMatch(filter: string, topic: string): boolean;
|
|
6
|
-
export interface
|
|
5
|
+
export interface MqttOptions extends PubSubOptions {
|
|
7
6
|
clientId?: string;
|
|
8
7
|
url?: string;
|
|
9
|
-
|
|
8
|
+
endpoint?: string;
|
|
10
9
|
}
|
|
11
10
|
interface PahoClient {
|
|
12
11
|
onMessageArrived: (params: {
|
|
@@ -23,36 +22,35 @@ interface PahoClient {
|
|
|
23
22
|
isConnected: () => boolean;
|
|
24
23
|
subscribe: (topic: string) => void;
|
|
25
24
|
unsubscribe: (topic: string) => void;
|
|
26
|
-
send(topic: string, message: string):
|
|
25
|
+
send(topic: string, message: string): void;
|
|
27
26
|
}
|
|
28
27
|
declare class ClientsQueue {
|
|
29
28
|
private promises;
|
|
30
|
-
get(clientId: string, clientFactory?: (input: string) => Promise<PahoClient | undefined>): Promise<PahoClient>;
|
|
29
|
+
get(clientId: string, clientFactory?: (input: string) => Promise<PahoClient | undefined>): Promise<PahoClient | undefined>;
|
|
31
30
|
get allClients(): string[];
|
|
32
31
|
remove(clientId: string): void;
|
|
33
32
|
}
|
|
34
|
-
export declare class
|
|
33
|
+
export declare class MqttOverWS extends AbstractPubSub<MqttOptions> {
|
|
35
34
|
private _clientsQueue;
|
|
36
|
-
private connectionState
|
|
35
|
+
private connectionState?;
|
|
37
36
|
private readonly connectionStateMonitor;
|
|
38
37
|
private readonly reconnectionMonitor;
|
|
39
|
-
constructor(options?:
|
|
38
|
+
constructor(options?: MqttOptions);
|
|
40
39
|
protected get clientId(): string;
|
|
41
40
|
protected get endpoint(): Promise<string | undefined>;
|
|
42
41
|
protected get clientsQueue(): ClientsQueue;
|
|
43
42
|
protected get isSSLEnabled(): boolean;
|
|
44
|
-
getProviderName(): string;
|
|
45
43
|
onDisconnect({ clientId, errorCode, ...args }: {
|
|
46
44
|
clientId?: string;
|
|
47
45
|
errorCode?: number;
|
|
48
46
|
}): void;
|
|
49
|
-
newClient({ url, clientId
|
|
50
|
-
protected connect(clientId: string, options?:
|
|
47
|
+
newClient({ url, clientId }: MqttOptions): Promise<PahoClient>;
|
|
48
|
+
protected connect(clientId: string, options?: MqttOptions): Promise<PahoClient | undefined>;
|
|
51
49
|
protected disconnect(clientId: string): Promise<void>;
|
|
52
50
|
publish(topics: string[] | string, msg: PubSubContent): Promise<void>;
|
|
53
51
|
protected _topicObservers: Map<string, Set<PubSubContentObserver>>;
|
|
54
52
|
protected _clientIdObservers: Map<string, Set<PubSubContentObserver>>;
|
|
55
53
|
private _onMessage;
|
|
56
|
-
subscribe(topics: string[] | string, options?:
|
|
54
|
+
subscribe(topics: string[] | string, options?: MqttOptions): Observable<PubSubContent>;
|
|
57
55
|
}
|
|
58
56
|
export {};
|
|
@@ -1,18 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
var tslib_1 = require("tslib");
|
|
4
2
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
5
3
|
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.MqttOverWS = exports.mqttTopicMatch = void 0;
|
|
6
|
+
var tslib_1 = require("tslib");
|
|
7
|
+
// @ts-ignore
|
|
6
8
|
var Paho = tslib_1.__importStar(require("../vendor/paho-mqtt"));
|
|
7
|
-
var
|
|
8
|
-
var
|
|
9
|
-
var
|
|
10
|
-
var PubSub_1 = require("../types/PubSub");
|
|
9
|
+
var rxjs_1 = require("rxjs");
|
|
10
|
+
var PubSub_1 = require("./PubSub");
|
|
11
|
+
var PubSub_2 = require("../types/PubSub");
|
|
11
12
|
var core_1 = require("@aws-amplify/core");
|
|
13
|
+
var utils_1 = require("@aws-amplify/core/internals/utils");
|
|
12
14
|
var ConnectionStateMonitor_1 = require("../utils/ConnectionStateMonitor");
|
|
13
15
|
var ReconnectionMonitor_1 = require("../utils/ReconnectionMonitor");
|
|
14
16
|
var constants_1 = require("./constants");
|
|
15
|
-
var logger = new core_1.ConsoleLogger('
|
|
17
|
+
var logger = new core_1.ConsoleLogger('MqttOverWS');
|
|
16
18
|
function mqttTopicMatch(filter, topic) {
|
|
17
19
|
var filterArray = filter.split('/');
|
|
18
20
|
var length = filterArray.length;
|
|
@@ -54,7 +56,7 @@ var ClientsQueue = /** @class */ (function () {
|
|
|
54
56
|
get: function () {
|
|
55
57
|
return Array.from(this.promises.keys());
|
|
56
58
|
},
|
|
57
|
-
enumerable:
|
|
59
|
+
enumerable: false,
|
|
58
60
|
configurable: true
|
|
59
61
|
});
|
|
60
62
|
ClientsQueue.prototype.remove = function (clientId) {
|
|
@@ -62,15 +64,15 @@ var ClientsQueue = /** @class */ (function () {
|
|
|
62
64
|
};
|
|
63
65
|
return ClientsQueue;
|
|
64
66
|
}());
|
|
65
|
-
var dispatchPubSubEvent = function (
|
|
66
|
-
core_1.Hub.dispatch('pubsub',
|
|
67
|
+
var dispatchPubSubEvent = function (payload) {
|
|
68
|
+
core_1.Hub.dispatch('pubsub', payload, 'PubSub', constants_1.AMPLIFY_SYMBOL);
|
|
67
69
|
};
|
|
68
70
|
var topicSymbol = typeof Symbol !== 'undefined' ? Symbol('topic') : '@@topic';
|
|
69
|
-
var
|
|
70
|
-
tslib_1.__extends(
|
|
71
|
-
function
|
|
71
|
+
var MqttOverWS = /** @class */ (function (_super) {
|
|
72
|
+
tslib_1.__extends(MqttOverWS, _super);
|
|
73
|
+
function MqttOverWS(options) {
|
|
72
74
|
if (options === void 0) { options = {}; }
|
|
73
|
-
var _this = _super.call(this, tslib_1.__assign(tslib_1.__assign({}, options), { clientId: options.clientId ||
|
|
75
|
+
var _this = _super.call(this, tslib_1.__assign(tslib_1.__assign({}, options), { clientId: options.clientId || (0, utils_1.amplifyUuid)() })) || this;
|
|
74
76
|
_this._clientsQueue = new ClientsQueue();
|
|
75
77
|
_this.connectionStateMonitor = new ConnectionStateMonitor_1.ConnectionStateMonitor();
|
|
76
78
|
_this.reconnectionMonitor = new ReconnectionMonitor_1.ReconnectionMonitor();
|
|
@@ -78,54 +80,55 @@ var MqttOverWSProvider = /** @class */ (function (_super) {
|
|
|
78
80
|
_this._clientIdObservers = new Map();
|
|
79
81
|
// Monitor the connection health state and pass changes along to Hub
|
|
80
82
|
_this.connectionStateMonitor.connectionStateObservable.subscribe(function (connectionStateChange) {
|
|
81
|
-
dispatchPubSubEvent(
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
83
|
+
dispatchPubSubEvent({
|
|
84
|
+
event: constants_1.CONNECTION_STATE_CHANGE,
|
|
85
|
+
data: {
|
|
86
|
+
provider: _this,
|
|
87
|
+
connectionState: connectionStateChange,
|
|
88
|
+
},
|
|
89
|
+
message: "Connection state is ".concat(connectionStateChange),
|
|
90
|
+
});
|
|
85
91
|
_this.connectionState = connectionStateChange;
|
|
86
92
|
// Trigger reconnection when the connection is disrupted
|
|
87
|
-
if (connectionStateChange ===
|
|
93
|
+
if (connectionStateChange === PubSub_2.ConnectionState.ConnectionDisrupted) {
|
|
88
94
|
_this.reconnectionMonitor.record(ReconnectionMonitor_1.ReconnectEvent.START_RECONNECT);
|
|
89
95
|
}
|
|
90
|
-
else if (connectionStateChange !==
|
|
96
|
+
else if (connectionStateChange !== PubSub_2.ConnectionState.Connecting) {
|
|
91
97
|
// Trigger connected to halt reconnection attempts
|
|
92
98
|
_this.reconnectionMonitor.record(ReconnectionMonitor_1.ReconnectEvent.HALT_RECONNECT);
|
|
93
99
|
}
|
|
94
100
|
});
|
|
95
101
|
return _this;
|
|
96
102
|
}
|
|
97
|
-
Object.defineProperty(
|
|
103
|
+
Object.defineProperty(MqttOverWS.prototype, "clientId", {
|
|
98
104
|
get: function () {
|
|
99
105
|
return this.options.clientId;
|
|
100
106
|
},
|
|
101
|
-
enumerable:
|
|
107
|
+
enumerable: false,
|
|
102
108
|
configurable: true
|
|
103
109
|
});
|
|
104
|
-
Object.defineProperty(
|
|
110
|
+
Object.defineProperty(MqttOverWS.prototype, "endpoint", {
|
|
105
111
|
get: function () {
|
|
106
|
-
return Promise.resolve(this.options.
|
|
112
|
+
return Promise.resolve(this.options.endpoint);
|
|
107
113
|
},
|
|
108
|
-
enumerable:
|
|
114
|
+
enumerable: false,
|
|
109
115
|
configurable: true
|
|
110
116
|
});
|
|
111
|
-
Object.defineProperty(
|
|
117
|
+
Object.defineProperty(MqttOverWS.prototype, "clientsQueue", {
|
|
112
118
|
get: function () {
|
|
113
119
|
return this._clientsQueue;
|
|
114
120
|
},
|
|
115
|
-
enumerable:
|
|
121
|
+
enumerable: false,
|
|
116
122
|
configurable: true
|
|
117
123
|
});
|
|
118
|
-
Object.defineProperty(
|
|
124
|
+
Object.defineProperty(MqttOverWS.prototype, "isSSLEnabled", {
|
|
119
125
|
get: function () {
|
|
120
126
|
return !this.options['aws_appsync_dangerously_connect_to_http_endpoint_for_testing'];
|
|
121
127
|
},
|
|
122
|
-
enumerable:
|
|
128
|
+
enumerable: false,
|
|
123
129
|
configurable: true
|
|
124
130
|
});
|
|
125
|
-
|
|
126
|
-
return 'MqttOverWSProvider';
|
|
127
|
-
};
|
|
128
|
-
MqttOverWSProvider.prototype.onDisconnect = function (_a) {
|
|
131
|
+
MqttOverWS.prototype.onDisconnect = function (_a) {
|
|
129
132
|
var clientId = _a.clientId, errorCode = _a.errorCode, args = tslib_1.__rest(_a, ["clientId", "errorCode"]);
|
|
130
133
|
if (errorCode !== 0) {
|
|
131
134
|
logger.warn(clientId, JSON.stringify(tslib_1.__assign({ errorCode: errorCode }, args), null, 2));
|
|
@@ -139,7 +142,7 @@ var MqttOverWSProvider = /** @class */ (function (_super) {
|
|
|
139
142
|
this.disconnect(clientId);
|
|
140
143
|
}
|
|
141
144
|
};
|
|
142
|
-
|
|
145
|
+
MqttOverWS.prototype.newClient = function (_a) {
|
|
143
146
|
var url = _a.url, clientId = _a.clientId;
|
|
144
147
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
145
148
|
var client, connected;
|
|
@@ -182,7 +185,7 @@ var MqttOverWSProvider = /** @class */ (function (_super) {
|
|
|
182
185
|
});
|
|
183
186
|
});
|
|
184
187
|
};
|
|
185
|
-
|
|
188
|
+
MqttOverWS.prototype.connect = function (clientId, options) {
|
|
186
189
|
if (options === void 0) { options = {}; }
|
|
187
190
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
188
191
|
var _this = this;
|
|
@@ -210,7 +213,7 @@ var MqttOverWSProvider = /** @class */ (function (_super) {
|
|
|
210
213
|
});
|
|
211
214
|
});
|
|
212
215
|
};
|
|
213
|
-
|
|
216
|
+
MqttOverWS.prototype.disconnect = function (clientId) {
|
|
214
217
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
215
218
|
var client;
|
|
216
219
|
return tslib_1.__generator(this, function (_a) {
|
|
@@ -228,7 +231,7 @@ var MqttOverWSProvider = /** @class */ (function (_super) {
|
|
|
228
231
|
});
|
|
229
232
|
});
|
|
230
233
|
};
|
|
231
|
-
|
|
234
|
+
MqttOverWS.prototype.publish = function (topics, msg) {
|
|
232
235
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
233
236
|
var targetTopics, message, client;
|
|
234
237
|
return tslib_1.__generator(this, function (_a) {
|
|
@@ -251,7 +254,7 @@ var MqttOverWSProvider = /** @class */ (function (_super) {
|
|
|
251
254
|
});
|
|
252
255
|
});
|
|
253
256
|
};
|
|
254
|
-
|
|
257
|
+
MqttOverWS.prototype._onMessage = function (topic, msg) {
|
|
255
258
|
try {
|
|
256
259
|
var matchedTopicObservers_1 = [];
|
|
257
260
|
this._topicObservers.forEach(function (observerForTopic, observerTopic) {
|
|
@@ -272,13 +275,13 @@ var MqttOverWSProvider = /** @class */ (function (_super) {
|
|
|
272
275
|
logger.warn('Error handling message', error, msg);
|
|
273
276
|
}
|
|
274
277
|
};
|
|
275
|
-
|
|
278
|
+
MqttOverWS.prototype.subscribe = function (topics, options) {
|
|
276
279
|
var _this = this;
|
|
277
280
|
if (options === void 0) { options = {}; }
|
|
278
281
|
var targetTopics = [].concat(topics);
|
|
279
282
|
logger.debug('Subscribing to topic(s)', targetTopics.join(','));
|
|
280
283
|
var reconnectSubscription;
|
|
281
|
-
return new
|
|
284
|
+
return new rxjs_1.Observable(function (observer) {
|
|
282
285
|
targetTopics.forEach(function (topic) {
|
|
283
286
|
// this._topicObservers is used to notify the observers according to the topic received on the message
|
|
284
287
|
var observersForTopic = _this._topicObservers.get(topic);
|
|
@@ -344,7 +347,7 @@ var MqttOverWSProvider = /** @class */ (function (_super) {
|
|
|
344
347
|
// Establish the initial connection
|
|
345
348
|
_a.sent();
|
|
346
349
|
// Add an observable to the reconnection list to manage reconnection for this subscription
|
|
347
|
-
reconnectSubscription = new
|
|
350
|
+
reconnectSubscription = new rxjs_1.Observable(function (observer) {
|
|
348
351
|
_this.reconnectionMonitor.addObserver(observer);
|
|
349
352
|
}).subscribe(function () {
|
|
350
353
|
getClient();
|
|
@@ -390,7 +393,6 @@ var MqttOverWSProvider = /** @class */ (function (_super) {
|
|
|
390
393
|
}); };
|
|
391
394
|
});
|
|
392
395
|
};
|
|
393
|
-
return
|
|
394
|
-
}(
|
|
395
|
-
exports.
|
|
396
|
-
//# sourceMappingURL=MqttOverWSProvider.js.map
|
|
396
|
+
return MqttOverWS;
|
|
397
|
+
}(PubSub_1.AbstractPubSub));
|
|
398
|
+
exports.MqttOverWS = MqttOverWS;
|
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
import Observable from '
|
|
2
|
-
import {
|
|
3
|
-
import { CustomUserAgentDetails } from '@aws-amplify/core';
|
|
4
|
-
|
|
5
|
-
export declare abstract class AbstractPubSubProvider<T extends ProviderOptions> implements PubSubProvider {
|
|
1
|
+
import { Observable } from 'rxjs';
|
|
2
|
+
import { PubSubBase, PubSubOptions, PubSubContent } from '../types/PubSub';
|
|
3
|
+
import { CustomUserAgentDetails } from '@aws-amplify/core/internals/utils';
|
|
4
|
+
export declare abstract class AbstractPubSub<T extends PubSubOptions> implements PubSubBase {
|
|
6
5
|
private _config;
|
|
7
6
|
constructor(options: T);
|
|
8
7
|
configure(config: T): T;
|
|
9
|
-
getCategory(): string;
|
|
10
|
-
abstract getProviderName(): string;
|
|
11
8
|
protected get options(): T;
|
|
12
9
|
abstract newClient(clientOptions: T): Promise<any>;
|
|
13
10
|
abstract publish(topics: string[] | string, msg: PubSubContent, options?: T): void;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AbstractPubSub = void 0;
|
|
4
|
+
var tslib_1 = require("tslib");
|
|
5
|
+
var core_1 = require("@aws-amplify/core");
|
|
6
|
+
var logger = new core_1.ConsoleLogger('AbstractPubSubProvider');
|
|
7
|
+
var AbstractPubSub = /** @class */ (function () {
|
|
8
|
+
function AbstractPubSub(options) {
|
|
9
|
+
this._config = options;
|
|
10
|
+
}
|
|
11
|
+
AbstractPubSub.prototype.configure = function (config) {
|
|
12
|
+
this._config = tslib_1.__assign(tslib_1.__assign({}, config), this._config);
|
|
13
|
+
logger.debug("configure", this._config);
|
|
14
|
+
return this.options;
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(AbstractPubSub.prototype, "options", {
|
|
17
|
+
get: function () {
|
|
18
|
+
return tslib_1.__assign({}, this._config);
|
|
19
|
+
},
|
|
20
|
+
enumerable: false,
|
|
21
|
+
configurable: true
|
|
22
|
+
});
|
|
23
|
+
return AbstractPubSub;
|
|
24
|
+
}());
|
|
25
|
+
exports.AbstractPubSub = AbstractPubSub;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export { AMPLIFY_SYMBOL } from '@aws-amplify/core/internals/utils';
|
|
1
2
|
export declare const MAX_DELAY_MS = 5000;
|
|
2
3
|
export declare const NON_RETRYABLE_CODES: number[];
|
|
3
4
|
export declare const CONNECTION_STATE_CHANGE = "ConnectionStateChange";
|
|
@@ -63,7 +64,6 @@ export declare enum SOCKET_STATUS {
|
|
|
63
64
|
READY = 1,
|
|
64
65
|
CONNECTING = 2
|
|
65
66
|
}
|
|
66
|
-
export declare const AMPLIFY_SYMBOL: Symbol;
|
|
67
67
|
export declare const AWS_APPSYNC_REALTIME_HEADERS: {
|
|
68
68
|
accept: string;
|
|
69
69
|
'content-encoding': string;
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RECONNECT_INTERVAL = exports.RECONNECT_DELAY = exports.DEFAULT_KEEP_ALIVE_ALERT_TIMEOUT = exports.DEFAULT_KEEP_ALIVE_TIMEOUT = exports.START_ACK_TIMEOUT = exports.CONNECTION_INIT_TIMEOUT = exports.AWS_APPSYNC_REALTIME_HEADERS = exports.SOCKET_STATUS = exports.SUBSCRIPTION_STATUS = exports.MESSAGE_TYPES = exports.CONNECTION_STATE_CHANGE = exports.NON_RETRYABLE_CODES = exports.MAX_DELAY_MS = exports.AMPLIFY_SYMBOL = void 0;
|
|
3
4
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
4
5
|
// SPDX-License-Identifier: Apache-2.0
|
|
6
|
+
var utils_1 = require("@aws-amplify/core/internals/utils");
|
|
7
|
+
Object.defineProperty(exports, "AMPLIFY_SYMBOL", { enumerable: true, get: function () { return utils_1.AMPLIFY_SYMBOL; } });
|
|
5
8
|
exports.MAX_DELAY_MS = 5000;
|
|
6
9
|
exports.NON_RETRYABLE_CODES = [400, 401, 403];
|
|
7
10
|
exports.CONNECTION_STATE_CHANGE = 'ConnectionStateChange';
|
|
@@ -70,9 +73,6 @@ var SOCKET_STATUS;
|
|
|
70
73
|
SOCKET_STATUS[SOCKET_STATUS["READY"] = 1] = "READY";
|
|
71
74
|
SOCKET_STATUS[SOCKET_STATUS["CONNECTING"] = 2] = "CONNECTING";
|
|
72
75
|
})(SOCKET_STATUS = exports.SOCKET_STATUS || (exports.SOCKET_STATUS = {}));
|
|
73
|
-
exports.AMPLIFY_SYMBOL = (typeof Symbol !== 'undefined' && typeof Symbol.for === 'function'
|
|
74
|
-
? Symbol.for('amplify_default')
|
|
75
|
-
: '@@amplify_default');
|
|
76
76
|
exports.AWS_APPSYNC_REALTIME_HEADERS = {
|
|
77
77
|
accept: 'application/json, text/javascript',
|
|
78
78
|
'content-encoding': 'amz-1.0',
|
|
@@ -102,4 +102,3 @@ exports.RECONNECT_DELAY = 5 * 1000;
|
|
|
102
102
|
* Default interval time in milleseconds between when reconnect is re-attempted
|
|
103
103
|
*/
|
|
104
104
|
exports.RECONNECT_INTERVAL = 60 * 1000;
|
|
105
|
-
//# sourceMappingURL=constants.js.map
|
package/lib/Providers/index.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
4
|
-
export { MqttProviderOptions, MqttOverWSProvider, mqttTopicMatch, } from './MqttOverWSProvider';
|
|
1
|
+
export { AbstractPubSub } from './PubSub';
|
|
2
|
+
export { AWSIoT, AWSIoTOptions } from './AWSIot';
|
|
3
|
+
export { MqttOptions, MqttOverWS, mqttTopicMatch } from './MqttOverWS';
|
package/lib/Providers/index.js
CHANGED
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.mqttTopicMatch = exports.MqttOverWS = exports.AWSIoT = exports.AbstractPubSub = void 0;
|
|
3
4
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
4
5
|
// SPDX-License-Identifier: Apache-2.0
|
|
5
|
-
var
|
|
6
|
-
exports
|
|
7
|
-
var
|
|
8
|
-
exports
|
|
9
|
-
var
|
|
10
|
-
exports
|
|
11
|
-
|
|
12
|
-
exports.MqttOverWSProvider = MqttOverWSProvider_1.MqttOverWSProvider;
|
|
13
|
-
exports.mqttTopicMatch = MqttOverWSProvider_1.mqttTopicMatch;
|
|
14
|
-
//# sourceMappingURL=index.js.map
|
|
6
|
+
var PubSub_1 = require("./PubSub");
|
|
7
|
+
Object.defineProperty(exports, "AbstractPubSub", { enumerable: true, get: function () { return PubSub_1.AbstractPubSub; } });
|
|
8
|
+
var AWSIot_1 = require("./AWSIot");
|
|
9
|
+
Object.defineProperty(exports, "AWSIoT", { enumerable: true, get: function () { return AWSIot_1.AWSIoT; } });
|
|
10
|
+
var MqttOverWS_1 = require("./MqttOverWS");
|
|
11
|
+
Object.defineProperty(exports, "MqttOverWS", { enumerable: true, get: function () { return MqttOverWS_1.MqttOverWS; } });
|
|
12
|
+
Object.defineProperty(exports, "mqttTopicMatch", { enumerable: true, get: function () { return MqttOverWS_1.mqttTopicMatch; } });
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { AWSIoT as PubSub, AWSIoTOptions as PubSubOptions } from '../Providers';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.PubSub = void 0;
|
|
6
|
+
var Providers_1 = require("../Providers");
|
|
7
|
+
Object.defineProperty(exports, "PubSub", { enumerable: true, get: function () { return Providers_1.AWSIoT; } });
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { MqttOverWS as PubSub, MqttOptions as PubSubOptions, } from '../Providers';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.PubSub = void 0;
|
|
6
|
+
var Providers_1 = require("../Providers");
|
|
7
|
+
Object.defineProperty(exports, "PubSub", { enumerable: true, get: function () { return Providers_1.MqttOverWS; } });
|
package/lib/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { PubSub } from './PubSub';
|
|
2
1
|
export { CONNECTION_STATE_CHANGE } from './Providers/constants';
|
|
3
2
|
export { ConnectionState, CONTROL_MSG } from './types';
|
|
4
|
-
export {
|
|
3
|
+
export { mqttTopicMatch } from './Providers';
|
|
4
|
+
export { PubSub, PubSubOptions } from './clients/iot';
|
package/lib/index.js
CHANGED
|
@@ -2,17 +2,13 @@
|
|
|
2
2
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
3
|
// SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
-
|
|
6
|
-
exports.PubSub = PubSub_1.PubSub;
|
|
5
|
+
exports.PubSub = exports.mqttTopicMatch = exports.CONTROL_MSG = exports.ConnectionState = exports.CONNECTION_STATE_CHANGE = void 0;
|
|
7
6
|
var constants_1 = require("./Providers/constants");
|
|
8
|
-
exports
|
|
7
|
+
Object.defineProperty(exports, "CONNECTION_STATE_CHANGE", { enumerable: true, get: function () { return constants_1.CONNECTION_STATE_CHANGE; } });
|
|
9
8
|
var types_1 = require("./types");
|
|
10
|
-
exports
|
|
11
|
-
exports
|
|
9
|
+
Object.defineProperty(exports, "ConnectionState", { enumerable: true, get: function () { return types_1.ConnectionState; } });
|
|
10
|
+
Object.defineProperty(exports, "CONTROL_MSG", { enumerable: true, get: function () { return types_1.CONTROL_MSG; } });
|
|
12
11
|
var Providers_1 = require("./Providers");
|
|
13
|
-
exports
|
|
14
|
-
|
|
15
|
-
exports
|
|
16
|
-
exports.MqttOverWSProvider = Providers_1.MqttOverWSProvider;
|
|
17
|
-
exports.mqttTopicMatch = Providers_1.mqttTopicMatch;
|
|
18
|
-
//# sourceMappingURL=index.js.map
|
|
12
|
+
Object.defineProperty(exports, "mqttTopicMatch", { enumerable: true, get: function () { return Providers_1.mqttTopicMatch; } });
|
|
13
|
+
var iot_1 = require("./clients/iot");
|
|
14
|
+
Object.defineProperty(exports, "PubSub", { enumerable: true, get: function () { return iot_1.PubSub; } });
|