@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.
Files changed (150) hide show
  1. package/iot/packages.json +7 -0
  2. package/lib/Providers/AWSIot.d.ts +10 -0
  3. package/lib/Providers/AWSIot.js +34 -0
  4. package/lib/Providers/{MqttOverWSProvider.d.ts → MqttOverWS.d.ts} +16 -16
  5. package/lib/Providers/MqttOverWS.js +274 -0
  6. package/lib/Providers/PubSub.d.ts +11 -0
  7. package/lib/Providers/PubSub.js +19 -0
  8. package/lib/Providers/constants.d.ts +1 -1
  9. package/lib/Providers/constants.js +3 -4
  10. package/lib/Providers/index.d.ts +3 -4
  11. package/lib/Providers/index.js +8 -10
  12. package/lib/clients/iot.d.ts +1 -0
  13. package/lib/clients/iot.js +7 -0
  14. package/lib/clients/mqtt.d.ts +1 -0
  15. package/lib/clients/mqtt.js +7 -0
  16. package/lib/index.d.ts +2 -2
  17. package/lib/index.js +7 -11
  18. package/lib/tsconfig.tsbuildinfo +1 -0
  19. package/lib/types/PubSub.d.ts +21 -3
  20. package/lib/types/PubSub.js +1 -1
  21. package/lib/types/index.d.ts +0 -1
  22. package/lib/types/index.js +5 -3
  23. package/lib/utils/ConnectionStateMonitor.d.ts +5 -5
  24. package/lib/utils/ConnectionStateMonitor.js +52 -64
  25. package/lib/utils/ReachabilityMonitor/index.d.ts +1 -3
  26. package/lib/utils/ReachabilityMonitor/index.js +4 -3
  27. package/lib/utils/ReachabilityMonitor/index.native.d.ts +1 -3
  28. package/lib/utils/ReachabilityMonitor/index.native.js +7 -8
  29. package/lib/utils/ReconnectionMonitor.d.ts +1 -1
  30. package/lib/utils/ReconnectionMonitor.js +21 -25
  31. package/lib-esm/Providers/AWSIot.d.ts +10 -0
  32. package/lib-esm/Providers/AWSIot.js +30 -0
  33. package/lib-esm/Providers/{MqttOverWSProvider.d.ts → MqttOverWS.d.ts} +16 -16
  34. package/lib-esm/Providers/MqttOverWS.js +268 -0
  35. package/lib-esm/Providers/PubSub.d.ts +11 -0
  36. package/lib-esm/Providers/PubSub.js +15 -0
  37. package/lib-esm/Providers/constants.d.ts +1 -1
  38. package/lib-esm/Providers/constants.js +11 -14
  39. package/lib-esm/Providers/index.d.ts +3 -4
  40. package/lib-esm/Providers/index.js +3 -5
  41. package/lib-esm/clients/iot.d.ts +1 -0
  42. package/{src/internals/index.ts → lib-esm/clients/iot.js} +1 -1
  43. package/lib-esm/clients/mqtt.d.ts +1 -0
  44. package/lib-esm/{internals/index.js → clients/mqtt.js} +1 -2
  45. package/lib-esm/index.d.ts +2 -2
  46. package/lib-esm/index.js +2 -3
  47. package/lib-esm/tsconfig.tsbuildinfo +1 -0
  48. package/lib-esm/types/PubSub.d.ts +21 -3
  49. package/lib-esm/types/PubSub.js +0 -1
  50. package/lib-esm/types/index.d.ts +0 -1
  51. package/lib-esm/types/index.js +2 -1
  52. package/lib-esm/utils/ConnectionStateMonitor.d.ts +5 -5
  53. package/lib-esm/utils/ConnectionStateMonitor.js +50 -64
  54. package/lib-esm/utils/ReachabilityMonitor/index.d.ts +1 -3
  55. package/lib-esm/utils/ReachabilityMonitor/index.js +2 -3
  56. package/lib-esm/utils/ReachabilityMonitor/index.native.d.ts +1 -3
  57. package/lib-esm/utils/ReachabilityMonitor/index.native.js +2 -5
  58. package/lib-esm/utils/ReconnectionMonitor.d.ts +1 -1
  59. package/lib-esm/utils/ReconnectionMonitor.js +19 -25
  60. package/mqtt/packages.json +7 -0
  61. package/package.json +146 -126
  62. package/src/Providers/{AWSIotProvider.ts → AWSIot.ts} +17 -15
  63. package/src/Providers/{MqttOverWSProvider.ts → MqttOverWS.ts} +38 -50
  64. package/src/Providers/PubSub.ts +40 -0
  65. package/src/Providers/constants.ts +2 -6
  66. package/src/Providers/index.ts +3 -12
  67. package/src/clients/iot.ts +4 -0
  68. package/src/clients/mqtt.ts +7 -0
  69. package/src/index.ts +3 -12
  70. package/src/types/PubSub.ts +28 -5
  71. package/src/types/index.ts +0 -1
  72. package/src/utils/ConnectionStateMonitor.ts +17 -13
  73. package/src/utils/ReachabilityMonitor/index.native.ts +2 -1
  74. package/src/utils/ReachabilityMonitor/index.ts +1 -1
  75. package/src/utils/ReconnectionMonitor.ts +1 -1
  76. package/internals/package.json +0 -8
  77. package/lib/.tsbuildinfo +0 -3
  78. package/lib/Providers/AWSAppSyncRealTimeProvider/index.d.ts +0 -77
  79. package/lib/Providers/AWSAppSyncRealTimeProvider/index.js +0 -856
  80. package/lib/Providers/AWSAppSyncRealTimeProvider/index.js.map +0 -1
  81. package/lib/Providers/AWSIotProvider.d.ts +0 -11
  82. package/lib/Providers/AWSIotProvider.js +0 -53
  83. package/lib/Providers/AWSIotProvider.js.map +0 -1
  84. package/lib/Providers/MqttOverWSProvider.js +0 -396
  85. package/lib/Providers/MqttOverWSProvider.js.map +0 -1
  86. package/lib/Providers/PubSubProvider.d.ts +0 -15
  87. package/lib/Providers/PubSubProvider.js +0 -28
  88. package/lib/Providers/PubSubProvider.js.map +0 -1
  89. package/lib/Providers/constants.js.map +0 -1
  90. package/lib/Providers/index.js.map +0 -1
  91. package/lib/PubSub.d.ts +0 -13
  92. package/lib/PubSub.js +0 -22
  93. package/lib/PubSub.js.map +0 -1
  94. package/lib/index.js.map +0 -1
  95. package/lib/internals/InternalPubSub.d.ts +0 -50
  96. package/lib/internals/InternalPubSub.js +0 -136
  97. package/lib/internals/InternalPubSub.js.map +0 -1
  98. package/lib/internals/index.d.ts +0 -1
  99. package/lib/internals/index.js +0 -8
  100. package/lib/internals/index.js.map +0 -1
  101. package/lib/types/Provider.d.ts +0 -18
  102. package/lib/types/Provider.js +0 -3
  103. package/lib/types/Provider.js.map +0 -1
  104. package/lib/types/PubSub.js.map +0 -1
  105. package/lib/types/index.js.map +0 -1
  106. package/lib/utils/ConnectionStateMonitor.js.map +0 -1
  107. package/lib/utils/ReachabilityMonitor/index.js.map +0 -1
  108. package/lib/utils/ReachabilityMonitor/index.native.js.map +0 -1
  109. package/lib/utils/ReconnectionMonitor.js.map +0 -1
  110. package/lib/vendor/paho-mqtt.d.ts +0 -2
  111. package/lib/vendor/paho-mqtt.js.map +0 -1
  112. package/lib-esm/.tsbuildinfo +0 -3
  113. package/lib-esm/Providers/AWSAppSyncRealTimeProvider/index.d.ts +0 -77
  114. package/lib-esm/Providers/AWSAppSyncRealTimeProvider/index.js +0 -854
  115. package/lib-esm/Providers/AWSAppSyncRealTimeProvider/index.js.map +0 -1
  116. package/lib-esm/Providers/AWSIotProvider.d.ts +0 -11
  117. package/lib-esm/Providers/AWSIotProvider.js +0 -51
  118. package/lib-esm/Providers/AWSIotProvider.js.map +0 -1
  119. package/lib-esm/Providers/MqttOverWSProvider.js +0 -393
  120. package/lib-esm/Providers/MqttOverWSProvider.js.map +0 -1
  121. package/lib-esm/Providers/PubSubProvider.d.ts +0 -15
  122. package/lib-esm/Providers/PubSubProvider.js +0 -26
  123. package/lib-esm/Providers/PubSubProvider.js.map +0 -1
  124. package/lib-esm/Providers/constants.js.map +0 -1
  125. package/lib-esm/Providers/index.js.map +0 -1
  126. package/lib-esm/PubSub.d.ts +0 -13
  127. package/lib-esm/PubSub.js +0 -20
  128. package/lib-esm/PubSub.js.map +0 -1
  129. package/lib-esm/index.js.map +0 -1
  130. package/lib-esm/internals/InternalPubSub.d.ts +0 -50
  131. package/lib-esm/internals/InternalPubSub.js +0 -134
  132. package/lib-esm/internals/InternalPubSub.js.map +0 -1
  133. package/lib-esm/internals/index.d.ts +0 -1
  134. package/lib-esm/internals/index.js.map +0 -1
  135. package/lib-esm/types/Provider.d.ts +0 -18
  136. package/lib-esm/types/Provider.js +0 -1
  137. package/lib-esm/types/Provider.js.map +0 -1
  138. package/lib-esm/types/PubSub.js.map +0 -1
  139. package/lib-esm/types/index.js.map +0 -1
  140. package/lib-esm/utils/ConnectionStateMonitor.js.map +0 -1
  141. package/lib-esm/utils/ReachabilityMonitor/index.js.map +0 -1
  142. package/lib-esm/utils/ReachabilityMonitor/index.native.js.map +0 -1
  143. package/lib-esm/utils/ReconnectionMonitor.js.map +0 -1
  144. package/lib-esm/vendor/paho-mqtt.d.ts +0 -2
  145. package/lib-esm/vendor/paho-mqtt.js.map +0 -1
  146. package/src/Providers/AWSAppSyncRealTimeProvider/index.ts +0 -1049
  147. package/src/Providers/PubSubProvider.ts +0 -53
  148. package/src/PubSub.ts +0 -33
  149. package/src/internals/InternalPubSub.ts +0 -185
  150. package/src/types/Provider.ts +0 -37
package/package.json CHANGED
@@ -1,128 +1,148 @@
1
1
  {
2
- "name": "@aws-amplify/pubsub",
3
- "version": "5.5.6-api-v6-models.b3abc9b.0+b3abc9b",
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": [
12
- "./lib/PubSub.js",
13
- "./lib-esm/PubSub.js"
14
- ],
15
- "publishConfig": {
16
- "access": "public"
17
- },
18
- "scripts": {
19
- "test": "npm run lint && jest -w 1 --coverage",
20
- "test:size": "size-limit",
21
- "build-with-test": "npm run clean && npm test && tsc && webpack",
22
- "build:cjs": "node ./build es5 && cp src/vendor/* lib/vendor && webpack && webpack --config ./webpack.config.dev.js",
23
- "build:esm": "node ./build es6 && cp src/vendor/* lib-esm/vendor",
24
- "build:cjs:watch": "node ./build es5 --watch",
25
- "build:esm:watch": "node ./build es6 --watch",
26
- "build": "npm run clean && npm run build:esm && npm run build:cjs",
27
- "clean": "npm run clean:size && rimraf lib-esm lib dist",
28
- "clean:size": "rimraf dual-publish-tmp tmp*",
29
- "format": "echo \"Not implemented\"",
30
- "lint": "tslint 'src/**/*.ts' && npm run ts-coverage",
31
- "ts-coverage": "typescript-coverage-report -p ./tsconfig.build.json -t 93.0 -i src/vendor/paho-mqtt.js"
32
- },
33
- "repository": {
34
- "type": "git",
35
- "url": "https://github.com/aws-amplify/amplify-js.git"
36
- },
37
- "author": "Amazon Web Services",
38
- "license": "Apache-2.0",
39
- "bugs": {
40
- "url": "https://github.com/aws/aws-amplify/issues"
41
- },
42
- "homepage": "https://aws-amplify.github.io/",
43
- "devDependencies": {
44
- "@types/zen-observable": "^0.8.0"
45
- },
46
- "files": [
47
- "lib",
48
- "lib-esm",
49
- "src",
50
- "internals"
51
- ],
52
- "dependencies": {
53
- "@aws-amplify/auth": "5.6.6-api-v6-models.b3abc9b.0+b3abc9b",
54
- "@aws-amplify/cache": "5.1.12-api-v6-models.b3abc9b.0+b3abc9b",
55
- "@aws-amplify/core": "5.8.6-api-v6-models.b3abc9b.0+b3abc9b",
56
- "buffer": "4.9.2",
57
- "graphql": "15.8.0",
58
- "tslib": "^1.8.0",
59
- "url": "0.11.0",
60
- "uuid": "^3.2.1",
61
- "zen-observable-ts": "0.8.19"
62
- },
63
- "size-limit": [
64
- {
65
- "name": "PubSub (IoT provider)",
66
- "path": "./lib-esm/index.js",
67
- "import": "{ Amplify, PubSub, AWSIoTProvider }",
68
- "limit": "81.39 kB"
69
- },
70
- {
71
- "name": "PubSub (Mqtt provider)",
72
- "path": "./lib-esm/index.js",
73
- "import": "{ Amplify, PubSub, MqttOverWSProvider }",
74
- "limit": "81.26 kB"
75
- }
76
- ],
77
- "jest": {
78
- "globals": {
79
- "ts-jest": {
80
- "diagnostics": false,
81
- "tsConfig": {
82
- "lib": [
83
- "es5",
84
- "es2015",
85
- "dom",
86
- "esnext.asynciterable",
87
- "es2017.object"
88
- ],
89
- "allowJs": true
90
- }
91
- },
92
- "testRegex": "(/__tests__/.*|\\.(test|spec))\\.(tsx?|jsx?)$",
93
- "testPathIgnorePatterns": [
94
- "__tests__/helpers.ts"
95
- ]
96
- },
97
- "transform": {
98
- "^.+\\.(js|jsx|ts|tsx)$": "ts-jest"
99
- },
100
- "testPathIgnorePatterns": [
101
- "__tests__/helpers.ts"
102
- ],
103
- "moduleFileExtensions": [
104
- "ts",
105
- "tsx",
106
- "js",
107
- "json",
108
- "jsx"
109
- ],
110
- "testEnvironment": "jsdom",
111
- "testURL": "http://localhost/",
112
- "coverageThreshold": {
113
- "global": {
114
- "branches": 0,
115
- "functions": 0,
116
- "lines": 0,
117
- "statements": 0
118
- }
119
- },
120
- "coveragePathIgnorePatterns": [
121
- "/node_modules/",
122
- "dist",
123
- "lib",
124
- "lib-esm"
125
- ]
126
- },
127
- "gitHead": "b3abc9b75f6f1353f4c2fbc10cd3369be498e9fc"
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 { MqttOverWSProvider, MqttProviderOptions } from './MqttOverWSProvider';
4
- import { Signer, Credentials } from '@aws-amplify/core';
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 AWSIoTProviderOptions extends MqttProviderOptions {
9
- aws_pubsub_region?: string;
10
- aws_pubsub_endpoint?: string;
8
+ export interface AWSIoTOptions extends MqttOptions {
9
+ region?: string;
10
+ endpoint?: string;
11
11
  }
12
12
 
13
- export class AWSIoTProvider extends MqttOverWSProvider {
14
- constructor(options: AWSIoTProviderOptions = {}) {
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['aws_pubsub_region'];
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.aws_pubsub_endpoint;
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
- } = await Credentials.get();
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 { v4 as uuid } from 'uuid';
5
- import Observable, { ZenObservable } from 'zen-observable-ts';
6
+ import { Observable, SubscriptionLike as Subscription, Observer } from 'rxjs';
6
7
 
7
- import { AbstractPubSubProvider } from './PubSubProvider';
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 { ProviderOptions } from '../types/Provider';
14
- import { ConsoleLogger as Logger, Hub } from '@aws-amplify/core';
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('MqttOverWSProvider');
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 MqttProviderOptions extends ProviderOptions {
45
+ export interface MqttOptions extends PubSubOptions {
42
46
  clientId?: string;
43
47
  url?: string;
44
- aws_pubsub_endpoint?: string;
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
- event: string,
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 MqttOverWSProvider extends AbstractPubSubProvider<MqttProviderOptions> {
102
+ export class MqttOverWS extends AbstractPubSub<MqttOptions> {
103
103
  private _clientsQueue = new ClientsQueue();
104
- private connectionState: ConnectionState;
104
+ private connectionState?: ConnectionState;
105
105
  private readonly connectionStateMonitor = new ConnectionStateMonitor();
106
106
  private readonly reconnectionMonitor = new ReconnectionMonitor();
107
107
 
108
- constructor(options: MqttProviderOptions = {}) {
109
- super({ ...options, clientId: options.clientId || uuid() });
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.aws_pubsub_endpoint);
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: MqttProviderOptions = {}
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: string[] | string, msg: PubSubContent) {
253
+ async publish({ topics, message }: PublishInput) {
264
254
  const targetTopics = ([] as string[]).concat(topics);
265
- const message = JSON.stringify(msg);
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, message));
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: string[] | string,
314
- options: MqttProviderOptions = {}
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: ZenObservable.Subscription;
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<ZenObservable.SubscriptionObserver<any>>);
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',
@@ -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 { AbstractPubSubProvider } from './PubSubProvider';
4
- export {
5
- AWSAppSyncRealTimeProvider,
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';
@@ -0,0 +1,4 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ export { AWSIoT as PubSub, AWSIoTOptions as PubSubOptions } from '../Providers';
@@ -0,0 +1,7 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ export {
5
+ MqttOverWS as PubSub,
6
+ MqttOptions as PubSubOptions,
7
+ } from '../Providers';