@aws-amplify/pubsub 5.5.6-api-v6-models.b3abc9b.0 → 6.0.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 +34 -0
- package/lib/Providers/{MqttOverWSProvider.d.ts → MqttOverWS.d.ts} +16 -16
- package/lib/Providers/MqttOverWS.js +274 -0
- package/lib/Providers/PubSub.d.ts +11 -0
- package/lib/Providers/PubSub.js +19 -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 +21 -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 +52 -64
- 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 -8
- package/lib/utils/ReconnectionMonitor.d.ts +1 -1
- package/lib/utils/ReconnectionMonitor.js +21 -25
- package/lib-esm/Providers/AWSIot.d.ts +10 -0
- package/lib-esm/Providers/AWSIot.js +30 -0
- package/lib-esm/Providers/{MqttOverWSProvider.d.ts → MqttOverWS.d.ts} +16 -16
- package/lib-esm/Providers/MqttOverWS.js +268 -0
- package/lib-esm/Providers/PubSub.d.ts +11 -0
- package/lib-esm/Providers/PubSub.js +15 -0
- package/lib-esm/Providers/constants.d.ts +1 -1
- package/lib-esm/Providers/constants.js +11 -14
- 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 +21 -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 +50 -64
- package/lib-esm/utils/ReachabilityMonitor/index.d.ts +1 -3
- package/lib-esm/utils/ReachabilityMonitor/index.js +2 -3
- package/lib-esm/utils/ReachabilityMonitor/index.native.d.ts +1 -3
- package/lib-esm/utils/ReachabilityMonitor/index.native.js +2 -5
- package/lib-esm/utils/ReconnectionMonitor.d.ts +1 -1
- package/lib-esm/utils/ReconnectionMonitor.js +19 -25
- package/mqtt/packages.json +7 -0
- package/package.json +146 -126
- package/src/Providers/{AWSIotProvider.ts → AWSIot.ts} +17 -15
- package/src/Providers/{MqttOverWSProvider.ts → MqttOverWS.ts} +38 -50
- package/src/Providers/PubSub.ts +40 -0
- 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 +28 -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/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 -856
- 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 +0 -396
- package/lib/Providers/MqttOverWSProvider.js.map +0 -1
- package/lib/Providers/PubSubProvider.d.ts +0 -15
- 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 -854
- 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 +0 -51
- package/lib-esm/Providers/AWSIotProvider.js.map +0 -1
- package/lib-esm/Providers/MqttOverWSProvider.js +0 -393
- package/lib-esm/Providers/MqttOverWSProvider.js.map +0 -1
- package/lib-esm/Providers/PubSubProvider.d.ts +0 -15
- 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 -1049
- package/src/Providers/PubSubProvider.ts +0 -53
- package/src/PubSub.ts +0 -33
- package/src/internals/InternalPubSub.ts +0 -185
- package/src/types/Provider.ts +0 -37
package/package.json
CHANGED
|
@@ -1,128 +1,148 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
2
|
+
"name": "@aws-amplify/pubsub",
|
|
3
|
+
"version": "6.0.0",
|
|
4
|
+
"description": "Pubsub category of aws-amplify",
|
|
5
|
+
"main": "./lib/index.js",
|
|
6
|
+
"module": "./lib-esm/index.js",
|
|
7
|
+
"typings": "./lib-esm/index.d.ts",
|
|
8
|
+
"react-native": {
|
|
9
|
+
"./lib/index": "./lib-esm/index.js"
|
|
10
|
+
},
|
|
11
|
+
"sideEffects": false,
|
|
12
|
+
"publishConfig": {
|
|
13
|
+
"access": "public"
|
|
14
|
+
},
|
|
15
|
+
"scripts": {
|
|
16
|
+
"test": "npm run lint && jest -w 1 --coverage",
|
|
17
|
+
"test:size": "size-limit",
|
|
18
|
+
"build-with-test": "npm run clean && npm test && tsc && webpack",
|
|
19
|
+
"build:cjs": "rimraf lib && tsc -m commonjs --outDir lib && cp -R src/vendor lib/vendor && webpack && webpack --config ./webpack.config.dev.js",
|
|
20
|
+
"build:esm": "rimraf lib-esm && tsc -m esnext --outDir lib-esm && cp -R src/vendor lib-esm/vendor",
|
|
21
|
+
"build:cjs:watch": "rimraf lib && tsc -m commonjs --outDir lib --watch",
|
|
22
|
+
"build:esm:watch": "rimraf lib-esm && tsc -m esnext --outDir lib-esm --watch",
|
|
23
|
+
"build": "npm run clean && npm run build:esm && npm run build:cjs",
|
|
24
|
+
"clean": "npm run clean:size && rimraf lib-esm lib dist",
|
|
25
|
+
"clean:size": "rimraf dual-publish-tmp tmp*",
|
|
26
|
+
"format": "echo \"Not implemented\"",
|
|
27
|
+
"lint": "tslint 'src/**/*.ts' && npm run ts-coverage",
|
|
28
|
+
"ts-coverage": "typescript-coverage-report -p ./tsconfig.json -t 93.0 -i src/vendor/paho-mqtt.js"
|
|
29
|
+
},
|
|
30
|
+
"typesVersions": {
|
|
31
|
+
">=4.2": {
|
|
32
|
+
"iot": [
|
|
33
|
+
"./lib-esm/clients/iot.d.ts"
|
|
34
|
+
],
|
|
35
|
+
"mqtt": [
|
|
36
|
+
"./lib-esm/clients/mqtt.d.ts"
|
|
37
|
+
]
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
"exports": {
|
|
41
|
+
".": {
|
|
42
|
+
"types": "./lib-esm/index.d.ts",
|
|
43
|
+
"import": "./lib-esm/index.js",
|
|
44
|
+
"require": "./lib/index.js"
|
|
45
|
+
},
|
|
46
|
+
"./iot": {
|
|
47
|
+
"types": "./lib-esm/clients/iot.d.ts",
|
|
48
|
+
"import": "./lib-esm/clients/iot.js",
|
|
49
|
+
"require": "./lib/clients/iot.js"
|
|
50
|
+
},
|
|
51
|
+
"./mqtt": {
|
|
52
|
+
"types": "./lib-esm/clients/mqtt.d.ts",
|
|
53
|
+
"import": "./lib-esm/clients/mqtt.js",
|
|
54
|
+
"require": "./lib/clients/mqtt.js"
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
"repository": {
|
|
58
|
+
"type": "git",
|
|
59
|
+
"url": "https://github.com/aws-amplify/amplify-js.git"
|
|
60
|
+
},
|
|
61
|
+
"author": "Amazon Web Services",
|
|
62
|
+
"license": "Apache-2.0",
|
|
63
|
+
"bugs": {
|
|
64
|
+
"url": "https://github.com/aws/aws-amplify/issues"
|
|
65
|
+
},
|
|
66
|
+
"homepage": "https://aws-amplify.github.io/",
|
|
67
|
+
"files": [
|
|
68
|
+
"lib",
|
|
69
|
+
"lib-esm",
|
|
70
|
+
"src",
|
|
71
|
+
"iot",
|
|
72
|
+
"mqtt"
|
|
73
|
+
],
|
|
74
|
+
"dependencies": {
|
|
75
|
+
"@aws-amplify/auth": "6.0.0",
|
|
76
|
+
"buffer": "4.9.2",
|
|
77
|
+
"graphql": "15.8.0",
|
|
78
|
+
"rxjs": "^7.8.1",
|
|
79
|
+
"tslib": "^2.5.0",
|
|
80
|
+
"url": "0.11.0"
|
|
81
|
+
},
|
|
82
|
+
"peerDependencies": {
|
|
83
|
+
"@aws-amplify/core": "^6.0.0"
|
|
84
|
+
},
|
|
85
|
+
"devDependencies": {
|
|
86
|
+
"@aws-amplify/core": "6.0.0",
|
|
87
|
+
"typescript": "5.0.2"
|
|
88
|
+
},
|
|
89
|
+
"size-limit": [
|
|
90
|
+
{
|
|
91
|
+
"name": "PubSub (IoT provider)",
|
|
92
|
+
"path": "./lib-esm/index.js",
|
|
93
|
+
"import": "{ generateClient }",
|
|
94
|
+
"limit": "1.2 kB"
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
"name": "PubSub (Mqtt provider)",
|
|
98
|
+
"path": "./lib-esm/clients/mqtt.js",
|
|
99
|
+
"import": "{ generateClient }",
|
|
100
|
+
"limit": "1.07 kB"
|
|
101
|
+
}
|
|
102
|
+
],
|
|
103
|
+
"jest": {
|
|
104
|
+
"globals": {
|
|
105
|
+
"ts-jest": {
|
|
106
|
+
"diagnostics": false,
|
|
107
|
+
"tsConfig": {
|
|
108
|
+
"allowJs": true,
|
|
109
|
+
"noEmitOnError": false
|
|
110
|
+
}
|
|
111
|
+
},
|
|
112
|
+
"testRegex": "(/__tests__/.*|\\.(test|spec))\\.(tsx?|jsx?)$",
|
|
113
|
+
"testPathIgnorePatterns": [
|
|
114
|
+
"__tests__/helpers.ts"
|
|
115
|
+
]
|
|
116
|
+
},
|
|
117
|
+
"transform": {
|
|
118
|
+
"^.+\\.(js|jsx|ts|tsx)$": "ts-jest"
|
|
119
|
+
},
|
|
120
|
+
"testPathIgnorePatterns": [
|
|
121
|
+
"__tests__/helpers.ts"
|
|
122
|
+
],
|
|
123
|
+
"moduleFileExtensions": [
|
|
124
|
+
"ts",
|
|
125
|
+
"tsx",
|
|
126
|
+
"js",
|
|
127
|
+
"json",
|
|
128
|
+
"jsx"
|
|
129
|
+
],
|
|
130
|
+
"testEnvironment": "jsdom",
|
|
131
|
+
"testURL": "http://localhost/",
|
|
132
|
+
"coverageThreshold": {
|
|
133
|
+
"global": {
|
|
134
|
+
"branches": 0,
|
|
135
|
+
"functions": 0,
|
|
136
|
+
"lines": 0,
|
|
137
|
+
"statements": 0
|
|
138
|
+
}
|
|
139
|
+
},
|
|
140
|
+
"coveragePathIgnorePatterns": [
|
|
141
|
+
"node_modules",
|
|
142
|
+
"dist",
|
|
143
|
+
"lib",
|
|
144
|
+
"lib-esm"
|
|
145
|
+
]
|
|
146
|
+
},
|
|
147
|
+
"gitHead": "d505105326d7f6214f6bd1e06eb20be3a3651377"
|
|
128
148
|
}
|
|
@@ -1,41 +1,43 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
import {
|
|
4
|
-
import { Signer
|
|
5
|
-
|
|
3
|
+
import { MqttOverWS, MqttOptions } from './MqttOverWS';
|
|
4
|
+
import { Signer } from '@aws-amplify/core/internals/utils';
|
|
5
|
+
import { fetchAuthSession } from '@aws-amplify/core';
|
|
6
6
|
const SERVICE_NAME = 'iotdevicegateway';
|
|
7
7
|
|
|
8
|
-
export interface
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
export interface AWSIoTOptions extends MqttOptions {
|
|
9
|
+
region?: string;
|
|
10
|
+
endpoint?: string;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
export class
|
|
14
|
-
constructor(options:
|
|
13
|
+
export class AWSIoT extends MqttOverWS {
|
|
14
|
+
constructor(options: AWSIoTOptions = {}) {
|
|
15
15
|
super(options);
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
protected get region(): string | undefined {
|
|
19
|
-
return this.options
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
public getProviderName() {
|
|
23
|
-
return 'AWSIoTProvider';
|
|
19
|
+
return this.options?.region;
|
|
24
20
|
}
|
|
25
21
|
|
|
26
22
|
protected get endpoint() {
|
|
27
23
|
return (async () => {
|
|
28
|
-
const endpoint = this.options.
|
|
24
|
+
const endpoint = this.options.endpoint;
|
|
29
25
|
|
|
30
26
|
const serviceInfo = {
|
|
31
27
|
service: SERVICE_NAME,
|
|
32
28
|
region: this.region,
|
|
33
29
|
};
|
|
30
|
+
const session = await fetchAuthSession();
|
|
31
|
+
|
|
32
|
+
if (!session.credentials) {
|
|
33
|
+
throw new Error('No auth session credentials');
|
|
34
|
+
}
|
|
35
|
+
|
|
34
36
|
const {
|
|
35
37
|
accessKeyId: access_key,
|
|
36
38
|
secretAccessKey: secret_key,
|
|
37
39
|
sessionToken: session_token,
|
|
38
|
-
} =
|
|
40
|
+
} = session.credentials;
|
|
39
41
|
|
|
40
42
|
const result = Signer.signUrl(
|
|
41
43
|
endpoint,
|
|
@@ -1,17 +1,21 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
// @ts-ignore
|
|
3
5
|
import * as Paho from '../vendor/paho-mqtt';
|
|
4
|
-
import {
|
|
5
|
-
import Observable, { ZenObservable } from 'zen-observable-ts';
|
|
6
|
+
import { Observable, SubscriptionLike as Subscription, Observer } from 'rxjs';
|
|
6
7
|
|
|
7
|
-
import {
|
|
8
|
+
import { AbstractPubSub } from './PubSub';
|
|
8
9
|
import {
|
|
9
10
|
ConnectionState,
|
|
10
11
|
PubSubContentObserver,
|
|
11
12
|
PubSubContent,
|
|
13
|
+
PubSubOptions,
|
|
14
|
+
PublishInput,
|
|
15
|
+
SubscribeInput,
|
|
12
16
|
} from '../types/PubSub';
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
17
|
+
import { Hub, HubPayload, ConsoleLogger as Logger } from '@aws-amplify/core';
|
|
18
|
+
import { amplifyUuid } from '@aws-amplify/core/internals/utils';
|
|
15
19
|
import {
|
|
16
20
|
ConnectionStateMonitor,
|
|
17
21
|
CONNECTION_CHANGE,
|
|
@@ -22,7 +26,7 @@ import {
|
|
|
22
26
|
} from '../utils/ReconnectionMonitor';
|
|
23
27
|
import { AMPLIFY_SYMBOL, CONNECTION_STATE_CHANGE } from './constants';
|
|
24
28
|
|
|
25
|
-
const logger = new Logger('
|
|
29
|
+
const logger = new Logger('MqttOverWS');
|
|
26
30
|
|
|
27
31
|
export function mqttTopicMatch(filter: string, topic: string) {
|
|
28
32
|
const filterArray = filter.split('/');
|
|
@@ -38,10 +42,10 @@ export function mqttTopicMatch(filter: string, topic: string) {
|
|
|
38
42
|
return length === topicArray.length;
|
|
39
43
|
}
|
|
40
44
|
|
|
41
|
-
export interface
|
|
45
|
+
export interface MqttOptions extends PubSubOptions {
|
|
42
46
|
clientId?: string;
|
|
43
47
|
url?: string;
|
|
44
|
-
|
|
48
|
+
endpoint?: string;
|
|
45
49
|
}
|
|
46
50
|
|
|
47
51
|
interface PahoClient {
|
|
@@ -57,7 +61,7 @@ interface PahoClient {
|
|
|
57
61
|
isConnected: () => boolean;
|
|
58
62
|
subscribe: (topic: string) => void;
|
|
59
63
|
unsubscribe: (topic: string) => void;
|
|
60
|
-
send(topic: string, message: string);
|
|
64
|
+
send(topic: string, message: string): void;
|
|
61
65
|
}
|
|
62
66
|
|
|
63
67
|
class ClientsQueue {
|
|
@@ -89,36 +93,32 @@ class ClientsQueue {
|
|
|
89
93
|
}
|
|
90
94
|
}
|
|
91
95
|
|
|
92
|
-
const dispatchPubSubEvent = (
|
|
93
|
-
|
|
94
|
-
data: Record<string, unknown>,
|
|
95
|
-
message: string
|
|
96
|
-
) => {
|
|
97
|
-
Hub.dispatch('pubsub', { event, data, message }, 'PubSub', AMPLIFY_SYMBOL);
|
|
96
|
+
const dispatchPubSubEvent = (payload: HubPayload) => {
|
|
97
|
+
Hub.dispatch('pubsub', payload, 'PubSub', AMPLIFY_SYMBOL);
|
|
98
98
|
};
|
|
99
99
|
|
|
100
100
|
const topicSymbol = typeof Symbol !== 'undefined' ? Symbol('topic') : '@@topic';
|
|
101
101
|
|
|
102
|
-
export class
|
|
102
|
+
export class MqttOverWS extends AbstractPubSub<MqttOptions> {
|
|
103
103
|
private _clientsQueue = new ClientsQueue();
|
|
104
|
-
private connectionState
|
|
104
|
+
private connectionState?: ConnectionState;
|
|
105
105
|
private readonly connectionStateMonitor = new ConnectionStateMonitor();
|
|
106
106
|
private readonly reconnectionMonitor = new ReconnectionMonitor();
|
|
107
107
|
|
|
108
|
-
constructor(options:
|
|
109
|
-
super({ ...options, clientId: options.clientId ||
|
|
108
|
+
constructor(options: MqttOptions = {}) {
|
|
109
|
+
super({ ...options, clientId: options.clientId || amplifyUuid() });
|
|
110
110
|
|
|
111
111
|
// Monitor the connection health state and pass changes along to Hub
|
|
112
112
|
this.connectionStateMonitor.connectionStateObservable.subscribe(
|
|
113
113
|
connectionStateChange => {
|
|
114
|
-
dispatchPubSubEvent(
|
|
115
|
-
CONNECTION_STATE_CHANGE,
|
|
116
|
-
{
|
|
114
|
+
dispatchPubSubEvent({
|
|
115
|
+
event: CONNECTION_STATE_CHANGE,
|
|
116
|
+
data: {
|
|
117
117
|
provider: this,
|
|
118
118
|
connectionState: connectionStateChange,
|
|
119
119
|
},
|
|
120
|
-
`Connection state is ${connectionStateChange}
|
|
121
|
-
);
|
|
120
|
+
message: `Connection state is ${connectionStateChange}`,
|
|
121
|
+
});
|
|
122
122
|
|
|
123
123
|
this.connectionState = connectionStateChange;
|
|
124
124
|
|
|
@@ -138,7 +138,7 @@ export class MqttOverWSProvider extends AbstractPubSubProvider<MqttProviderOptio
|
|
|
138
138
|
}
|
|
139
139
|
|
|
140
140
|
protected get endpoint(): Promise<string | undefined> {
|
|
141
|
-
return Promise.resolve(this.options.
|
|
141
|
+
return Promise.resolve(this.options.endpoint);
|
|
142
142
|
}
|
|
143
143
|
|
|
144
144
|
protected get clientsQueue() {
|
|
@@ -151,10 +151,6 @@ export class MqttOverWSProvider extends AbstractPubSubProvider<MqttProviderOptio
|
|
|
151
151
|
];
|
|
152
152
|
}
|
|
153
153
|
|
|
154
|
-
getProviderName() {
|
|
155
|
-
return 'MqttOverWSProvider';
|
|
156
|
-
}
|
|
157
|
-
|
|
158
154
|
public onDisconnect({
|
|
159
155
|
clientId,
|
|
160
156
|
errorCode,
|
|
@@ -177,10 +173,7 @@ export class MqttOverWSProvider extends AbstractPubSubProvider<MqttProviderOptio
|
|
|
177
173
|
}
|
|
178
174
|
}
|
|
179
175
|
|
|
180
|
-
public async newClient({
|
|
181
|
-
url,
|
|
182
|
-
clientId,
|
|
183
|
-
}: MqttProviderOptions): Promise<PahoClient> {
|
|
176
|
+
public async newClient({ url, clientId }: MqttOptions): Promise<PahoClient> {
|
|
184
177
|
logger.debug('Creating new MQTT client', clientId);
|
|
185
178
|
|
|
186
179
|
this.connectionStateMonitor.record(CONNECTION_CHANGE.OPENING_CONNECTION);
|
|
@@ -230,7 +223,7 @@ export class MqttOverWSProvider extends AbstractPubSubProvider<MqttProviderOptio
|
|
|
230
223
|
|
|
231
224
|
protected async connect(
|
|
232
225
|
clientId: string,
|
|
233
|
-
options:
|
|
226
|
+
options: MqttOptions = {}
|
|
234
227
|
): Promise<PahoClient | undefined> {
|
|
235
228
|
return await this.clientsQueue.get(clientId, async clientId => {
|
|
236
229
|
const client = await this.newClient({ ...options, clientId });
|
|
@@ -238,10 +231,7 @@ export class MqttOverWSProvider extends AbstractPubSubProvider<MqttProviderOptio
|
|
|
238
231
|
if (client) {
|
|
239
232
|
// Once connected, subscribe to all topics registered observers
|
|
240
233
|
this._topicObservers.forEach(
|
|
241
|
-
(
|
|
242
|
-
_value: Set<ZenObservable.SubscriptionObserver<any>>,
|
|
243
|
-
key: string
|
|
244
|
-
) => {
|
|
234
|
+
(_value: Set<PubSubContentObserver>, key: string) => {
|
|
245
235
|
client.subscribe(key);
|
|
246
236
|
}
|
|
247
237
|
);
|
|
@@ -260,15 +250,15 @@ export class MqttOverWSProvider extends AbstractPubSubProvider<MqttProviderOptio
|
|
|
260
250
|
this.connectionStateMonitor.record(CONNECTION_CHANGE.CLOSED);
|
|
261
251
|
}
|
|
262
252
|
|
|
263
|
-
async publish(topics
|
|
253
|
+
async publish({ topics, message }: PublishInput) {
|
|
264
254
|
const targetTopics = ([] as string[]).concat(topics);
|
|
265
|
-
const
|
|
255
|
+
const msg = JSON.stringify(message);
|
|
266
256
|
|
|
267
257
|
const client = await this.clientsQueue.get(this.clientId);
|
|
268
258
|
|
|
269
259
|
if (client) {
|
|
270
260
|
logger.debug('Publishing to topic(s)', targetTopics.join(','), message);
|
|
271
|
-
targetTopics.forEach(topic => client.send(topic,
|
|
261
|
+
targetTopics.forEach(topic => client.send(topic, msg));
|
|
272
262
|
} else {
|
|
273
263
|
logger.debug(
|
|
274
264
|
'Publishing to topic(s) failed',
|
|
@@ -286,9 +276,7 @@ export class MqttOverWSProvider extends AbstractPubSubProvider<MqttProviderOptio
|
|
|
286
276
|
|
|
287
277
|
private _onMessage(topic: string, msg: string) {
|
|
288
278
|
try {
|
|
289
|
-
const matchedTopicObservers: Set<
|
|
290
|
-
ZenObservable.SubscriptionObserver<any>
|
|
291
|
-
>[] = [];
|
|
279
|
+
const matchedTopicObservers: Set<PubSubContentObserver>[] = [];
|
|
292
280
|
this._topicObservers.forEach((observerForTopic, observerTopic) => {
|
|
293
281
|
if (mqttTopicMatch(observerTopic, topic)) {
|
|
294
282
|
matchedTopicObservers.push(observerForTopic);
|
|
@@ -309,13 +297,13 @@ export class MqttOverWSProvider extends AbstractPubSubProvider<MqttProviderOptio
|
|
|
309
297
|
}
|
|
310
298
|
}
|
|
311
299
|
|
|
312
|
-
subscribe(
|
|
313
|
-
topics
|
|
314
|
-
options
|
|
315
|
-
): Observable<PubSubContent> {
|
|
300
|
+
subscribe({
|
|
301
|
+
topics,
|
|
302
|
+
options = {},
|
|
303
|
+
}: SubscribeInput & { options?: MqttOptions }): Observable<PubSubContent> {
|
|
316
304
|
const targetTopics = ([] as string[]).concat(topics);
|
|
317
305
|
logger.debug('Subscribing to topic(s)', targetTopics.join(','));
|
|
318
|
-
let reconnectSubscription:
|
|
306
|
+
let reconnectSubscription: Subscription;
|
|
319
307
|
|
|
320
308
|
return new Observable(observer => {
|
|
321
309
|
targetTopics.forEach(topic => {
|
|
@@ -388,7 +376,7 @@ export class MqttOverWSProvider extends AbstractPubSubProvider<MqttProviderOptio
|
|
|
388
376
|
targetTopics.forEach(topic => {
|
|
389
377
|
const observersForTopic =
|
|
390
378
|
this._topicObservers.get(topic) ||
|
|
391
|
-
(new Set() as Set<
|
|
379
|
+
(new Set() as Set<Observer<any>>);
|
|
392
380
|
|
|
393
381
|
observersForTopic.delete(observer);
|
|
394
382
|
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
import { Observable } from 'rxjs';
|
|
4
|
+
import {
|
|
5
|
+
PubSubBase,
|
|
6
|
+
PubSubOptions,
|
|
7
|
+
PubSubContent,
|
|
8
|
+
PublishInput,
|
|
9
|
+
SubscribeInput,
|
|
10
|
+
} from '../types/PubSub';
|
|
11
|
+
import { ConsoleLogger as Logger } from '@aws-amplify/core';
|
|
12
|
+
const logger = new Logger('AbstractPubSubProvider');
|
|
13
|
+
|
|
14
|
+
export abstract class AbstractPubSub<T extends PubSubOptions>
|
|
15
|
+
implements PubSubBase
|
|
16
|
+
{
|
|
17
|
+
private _config: T;
|
|
18
|
+
|
|
19
|
+
constructor(options: T) {
|
|
20
|
+
this._config = options;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
configure(config: T): T {
|
|
24
|
+
this._config = { ...config, ...this._config };
|
|
25
|
+
|
|
26
|
+
logger.debug(`configure`, this._config);
|
|
27
|
+
|
|
28
|
+
return this.options;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
protected get options(): T {
|
|
32
|
+
return { ...this._config };
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
public abstract newClient(clientOptions: T): Promise<any>;
|
|
36
|
+
|
|
37
|
+
public abstract publish(input: PublishInput): void;
|
|
38
|
+
|
|
39
|
+
public abstract subscribe(input: SubscribeInput): Observable<PubSubContent>;
|
|
40
|
+
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
export { AMPLIFY_SYMBOL } from '@aws-amplify/core/internals/utils';
|
|
4
|
+
|
|
3
5
|
export const MAX_DELAY_MS = 5000;
|
|
4
6
|
|
|
5
7
|
export const NON_RETRYABLE_CODES = [400, 401, 403];
|
|
@@ -71,12 +73,6 @@ export enum SOCKET_STATUS {
|
|
|
71
73
|
CONNECTING,
|
|
72
74
|
}
|
|
73
75
|
|
|
74
|
-
export const AMPLIFY_SYMBOL = (
|
|
75
|
-
typeof Symbol !== 'undefined' && typeof Symbol.for === 'function'
|
|
76
|
-
? Symbol.for('amplify_default')
|
|
77
|
-
: '@@amplify_default'
|
|
78
|
-
) as Symbol;
|
|
79
|
-
|
|
80
76
|
export const AWS_APPSYNC_REALTIME_HEADERS = {
|
|
81
77
|
accept: 'application/json, text/javascript',
|
|
82
78
|
'content-encoding': 'amz-1.0',
|
package/src/Providers/index.ts
CHANGED
|
@@ -1,14 +1,5 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
export {
|
|
4
|
-
export {
|
|
5
|
-
|
|
6
|
-
AWSAppSyncRealTimeProviderOptions,
|
|
7
|
-
ObserverQuery,
|
|
8
|
-
} from './AWSAppSyncRealTimeProvider';
|
|
9
|
-
export { AWSIoTProvider, AWSIoTProviderOptions } from './AWSIotProvider';
|
|
10
|
-
export {
|
|
11
|
-
MqttProviderOptions,
|
|
12
|
-
MqttOverWSProvider,
|
|
13
|
-
mqttTopicMatch,
|
|
14
|
-
} from './MqttOverWSProvider';
|
|
3
|
+
export { AbstractPubSub } from './PubSub';
|
|
4
|
+
export { AWSIoT, AWSIoTOptions } from './AWSIot';
|
|
5
|
+
export { MqttOptions, MqttOverWS, mqttTopicMatch } from './MqttOverWS';
|