@aws-amplify/pubsub 4.5.12-unstable.4 → 4.5.13

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 (102) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/build.js +5 -0
  3. package/dist/aws-amplify-pubsub.js +10278 -0
  4. package/dist/aws-amplify-pubsub.js.map +1 -0
  5. package/dist/aws-amplify-pubsub.min.js +11 -0
  6. package/dist/aws-amplify-pubsub.min.js.map +1 -0
  7. package/index.js +7 -0
  8. package/lib/Providers/AWSAppSyncProvider.js +102 -20
  9. package/lib/Providers/AWSAppSyncProvider.js.map +1 -1
  10. package/lib/Providers/AWSAppSyncRealTimeProvider/index.js +210 -158
  11. package/lib/Providers/AWSAppSyncRealTimeProvider/index.js.map +1 -1
  12. package/lib/Providers/AWSIotProvider.js +64 -6
  13. package/lib/Providers/AWSIotProvider.js.map +1 -1
  14. package/lib/Providers/MqttOverWSProvider.js +204 -158
  15. package/lib/Providers/MqttOverWSProvider.js.map +1 -1
  16. package/lib/Providers/PubSubProvider.js +13 -3
  17. package/lib/Providers/PubSubProvider.js.map +1 -1
  18. package/lib/Providers/constants.js +0 -8
  19. package/lib/Providers/constants.js.map +1 -1
  20. package/lib/Providers/index.js +20 -13
  21. package/lib/Providers/index.js.map +1 -1
  22. package/lib/PubSub.js +56 -8
  23. package/lib/PubSub.js.map +1 -1
  24. package/lib/index.js +20 -9
  25. package/lib/index.js.map +1 -1
  26. package/lib/types/PubSub.js +12 -2
  27. package/lib/types/PubSub.js.map +1 -1
  28. package/lib/types/index.js +4 -2
  29. package/lib/types/index.js.map +1 -1
  30. package/lib/utils/ConnectionStateMonitor.js +29 -16
  31. package/lib/utils/ConnectionStateMonitor.js.map +1 -1
  32. package/lib/utils/ReachabilityMonitor/index.native.js +4 -2
  33. package/lib/utils/ReachabilityMonitor/index.native.js.map +1 -1
  34. package/lib-esm/Providers/AWSAppSyncProvider.js +80 -1
  35. package/lib-esm/Providers/AWSAppSyncProvider.js.map +1 -1
  36. package/lib-esm/Providers/AWSAppSyncRealTimeProvider/index.d.ts +0 -8
  37. package/lib-esm/Providers/AWSAppSyncRealTimeProvider/index.js +168 -126
  38. package/lib-esm/Providers/AWSAppSyncRealTimeProvider/index.js.map +1 -1
  39. package/lib-esm/Providers/AWSIotProvider.js +61 -3
  40. package/lib-esm/Providers/AWSIotProvider.js.map +1 -1
  41. package/lib-esm/Providers/MqttOverWSProvider.d.ts +4 -2
  42. package/lib-esm/Providers/MqttOverWSProvider.js +175 -139
  43. package/lib-esm/Providers/MqttOverWSProvider.js.map +1 -1
  44. package/lib-esm/Providers/PubSubProvider.js +11 -1
  45. package/lib-esm/Providers/PubSubProvider.js.map +1 -1
  46. package/lib-esm/Providers/constants.d.ts +0 -8
  47. package/lib-esm/Providers/constants.js +0 -8
  48. package/lib-esm/Providers/constants.js.map +1 -1
  49. package/lib-esm/Providers/index.d.ts +5 -5
  50. package/lib-esm/Providers/index.js +17 -7
  51. package/lib-esm/Providers/index.js.map +1 -1
  52. package/lib-esm/PubSub.js +48 -3
  53. package/lib-esm/PubSub.js.map +1 -1
  54. package/lib-esm/index.d.ts +7 -2
  55. package/lib-esm/index.js +19 -4
  56. package/lib-esm/index.js.map +1 -1
  57. package/lib-esm/types/Provider.d.ts +4 -0
  58. package/lib-esm/types/PubSub.js +12 -2
  59. package/lib-esm/types/PubSub.js.map +1 -1
  60. package/lib-esm/types/index.js.map +1 -1
  61. package/lib-esm/utils/ConnectionStateMonitor.d.ts +0 -1
  62. package/lib-esm/utils/ConnectionStateMonitor.js +23 -13
  63. package/lib-esm/utils/ConnectionStateMonitor.js.map +1 -1
  64. package/package.json +10 -14
  65. package/src/Providers/AWSAppSyncProvider.ts +12 -2
  66. package/src/Providers/AWSAppSyncRealTimeProvider/index.ts +89 -142
  67. package/src/Providers/AWSIotProvider.ts +12 -2
  68. package/src/Providers/MqttOverWSProvider.ts +79 -90
  69. package/src/Providers/PubSubProvider.ts +12 -2
  70. package/src/Providers/constants.ts +0 -10
  71. package/src/Providers/index.ts +17 -15
  72. package/src/PubSub.ts +12 -2
  73. package/src/index.ts +23 -15
  74. package/src/types/Provider.ts +17 -2
  75. package/src/types/PubSub.ts +12 -2
  76. package/src/types/index.ts +12 -2
  77. package/src/utils/ConnectionStateMonitor.ts +12 -16
  78. package/webpack.config.dev.js +6 -0
  79. package/lib/.tsbuildinfo +0 -3
  80. package/lib/Providers/AWSAppSyncProvider.d.ts +0 -21
  81. package/lib/Providers/AWSAppSyncRealTimeProvider/index.d.ts +0 -75
  82. package/lib/Providers/AWSIotProvider.d.ts +0 -11
  83. package/lib/Providers/MqttOverWSProvider.d.ts +0 -41
  84. package/lib/Providers/PubSubProvider.d.ts +0 -13
  85. package/lib/Providers/constants.d.ts +0 -95
  86. package/lib/Providers/index.d.ts +0 -5
  87. package/lib/PubSub.d.ts +0 -51
  88. package/lib/index.d.ts +0 -4
  89. package/lib/types/Provider.d.ts +0 -14
  90. package/lib/types/PubSub.d.ts +0 -24
  91. package/lib/types/index.d.ts +0 -2
  92. package/lib/utils/ConnectionStateMonitor.d.ts +0 -41
  93. package/lib/utils/ReachabilityMonitor/index.d.ts +0 -3
  94. package/lib/utils/ReachabilityMonitor/index.native.d.ts +0 -3
  95. package/lib/utils/ReconnectionMonitor.d.ts +0 -29
  96. package/lib/utils/ReconnectionMonitor.js +0 -73
  97. package/lib/utils/ReconnectionMonitor.js.map +0 -1
  98. package/lib-esm/.tsbuildinfo +0 -3
  99. package/lib-esm/utils/ReconnectionMonitor.d.ts +0 -29
  100. package/lib-esm/utils/ReconnectionMonitor.js +0 -71
  101. package/lib-esm/utils/ReconnectionMonitor.js.map +0 -1
  102. package/src/utils/ReconnectionMonitor.ts +0 -74
@@ -1,5 +1,15 @@
1
- // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
- // SPDX-License-Identifier: Apache-2.0
1
+ /*
2
+ * Copyright 2017-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5
+ * the License. A copy of the License is located at
6
+ *
7
+ * http://aws.amazon.com/apache2.0/
8
+ *
9
+ * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10
+ * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11
+ * and limitations under the License.
12
+ */
3
13
  import { MqttOverWSProvider, MqttProviderOptions } from './MqttOverWSProvider';
4
14
  import { Signer, Credentials } from '@aws-amplify/core';
5
15
 
@@ -1,21 +1,27 @@
1
- // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
- // SPDX-License-Identifier: Apache-2.0
1
+ /*
2
+ * Copyright 2017-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5
+ * the License. A copy of the License is located at
6
+ *
7
+ * http://aws.amazon.com/apache2.0/
8
+ *
9
+ * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10
+ * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11
+ * and limitations under the License.
12
+ */
3
13
  import * as Paho from 'paho-mqtt';
4
14
  import { v4 as uuid } from 'uuid';
5
- import Observable, { ZenObservable } from 'zen-observable-ts';
15
+ import Observable from 'zen-observable-ts';
6
16
 
7
17
  import { AbstractPubSubProvider } from './PubSubProvider';
8
- import { SubscriptionObserver, ConnectionState } from '../types/PubSub';
18
+ import { SubscriptionObserver } from '../types/PubSub';
9
19
  import { ProviderOptions } from '../types/Provider';
10
20
  import { ConsoleLogger as Logger, Hub } from '@aws-amplify/core';
11
21
  import {
12
22
  ConnectionStateMonitor,
13
23
  CONNECTION_CHANGE,
14
24
  } from '../utils/ConnectionStateMonitor';
15
- import {
16
- ReconnectEvent,
17
- ReconnectionMonitor,
18
- } from '../utils/ReconnectionMonitor';
19
25
  import { AMPLIFY_SYMBOL, CONNECTION_STATE_CHANGE } from './constants';
20
26
 
21
27
  const logger = new Logger('MqttOverWSProvider');
@@ -39,20 +45,27 @@ export interface MqttProviderOptions extends ProviderOptions {
39
45
  url?: string;
40
46
  }
41
47
 
48
+ /**
49
+ * @deprecated Migrated to MqttProviderOptions
50
+ */
51
+ export type MqttProvidertOptions = MqttProviderOptions;
52
+
42
53
  class ClientsQueue {
43
54
  private promises: Map<string, Promise<any>> = new Map();
44
55
 
45
56
  async get(clientId: string, clientFactory?: (input: string) => Promise<any>) {
46
57
  const cachedPromise = this.promises.get(clientId);
47
- if (cachedPromise) return cachedPromise;
58
+ if (cachedPromise) {
59
+ return cachedPromise;
60
+ }
48
61
 
49
62
  if (clientFactory) {
50
63
  const newPromise = clientFactory(clientId);
64
+
51
65
  this.promises.set(clientId, newPromise);
52
- newPromise.catch(v => this.promises.delete(clientId));
66
+
53
67
  return newPromise;
54
68
  }
55
-
56
69
  return undefined;
57
70
  }
58
71
 
@@ -73,9 +86,7 @@ const topicSymbol = typeof Symbol !== 'undefined' ? Symbol('topic') : '@@topic';
73
86
 
74
87
  export class MqttOverWSProvider extends AbstractPubSubProvider {
75
88
  private _clientsQueue = new ClientsQueue();
76
- private connectionState: ConnectionState;
77
89
  private readonly connectionStateMonitor = new ConnectionStateMonitor();
78
- private readonly reconnectionMonitor = new ReconnectionMonitor();
79
90
 
80
91
  constructor(options: MqttProviderOptions = {}) {
81
92
  super({ ...options, clientId: options.clientId || uuid() });
@@ -91,16 +102,6 @@ export class MqttOverWSProvider extends AbstractPubSubProvider {
91
102
  },
92
103
  `Connection state is ${connectionStateChange}`
93
104
  );
94
-
95
- this.connectionState = connectionStateChange;
96
-
97
- // Trigger reconnection when the connection is disrupted
98
- if (connectionStateChange === ConnectionState.ConnectionDisrupted) {
99
- this.reconnectionMonitor.record(ReconnectEvent.START_RECONNECT);
100
- } else if (connectionStateChange !== ConnectionState.Connecting) {
101
- // Trigger connected to halt reconnection attempts
102
- this.reconnectionMonitor.record(ReconnectEvent.HALT_RECONNECT);
103
- }
104
105
  }
105
106
  );
106
107
  }
@@ -141,6 +142,7 @@ export class MqttOverWSProvider extends AbstractPubSubProvider {
141
142
  if (errorCode !== 0) {
142
143
  logger.warn(clientId, JSON.stringify({ errorCode, ...args }, null, 2));
143
144
 
145
+ const topicsToDelete: string[] = [];
144
146
  if (!clientId) {
145
147
  return;
146
148
  }
@@ -148,7 +150,24 @@ export class MqttOverWSProvider extends AbstractPubSubProvider {
148
150
  if (!clientIdObservers) {
149
151
  return;
150
152
  }
151
- this.disconnect(clientId);
153
+ clientIdObservers.forEach(observer => {
154
+ observer.error('Disconnected, error code: ' + errorCode);
155
+ // removing observers for disconnected clientId
156
+ this._topicObservers.forEach((observerForTopic, observerTopic) => {
157
+ observerForTopic.delete(observer);
158
+ if (observerForTopic.size === 0) {
159
+ topicsToDelete.push(observerTopic);
160
+ }
161
+ });
162
+ });
163
+
164
+ // forgiving any trace of clientId
165
+ this._clientIdObservers.delete(clientId);
166
+
167
+ // Removing topics that are not listen by an observer
168
+ topicsToDelete.forEach(topic => {
169
+ this._topicObservers.delete(topic);
170
+ });
152
171
  }
153
172
  }
154
173
 
@@ -158,7 +177,7 @@ export class MqttOverWSProvider extends AbstractPubSubProvider {
158
177
  this.connectionStateMonitor.record(CONNECTION_CHANGE.OPENING_CONNECTION);
159
178
  // @ts-ignore
160
179
  const client = new Paho.Client(url, clientId);
161
-
180
+ // client.trace = (args) => logger.debug(clientId, JSON.stringify(args, null, 2));
162
181
  client.onMessageArrived = ({
163
182
  destinationName: topic,
164
183
  payloadString: msg,
@@ -178,24 +197,23 @@ export class MqttOverWSProvider extends AbstractPubSubProvider {
178
197
  this.connectionStateMonitor.record(CONNECTION_CHANGE.CLOSED);
179
198
  };
180
199
 
181
- const connected = await new Promise((resolve, reject) => {
200
+ await new Promise((resolve, reject) => {
182
201
  client.connect({
183
202
  useSSL: this.isSSLEnabled,
184
203
  mqttVersion: 3,
185
- onSuccess: () => resolve(true),
186
- onFailure: x => {
187
- if (clientId) this._clientsQueue.remove(clientId);
188
- this.connectionStateMonitor.record(CONNECTION_CHANGE.CLOSED);
189
- resolve(false);
204
+ onSuccess: () => resolve(client),
205
+ onFailure: () => {
206
+ reject();
207
+ this.connectionStateMonitor.record(
208
+ CONNECTION_CHANGE.CONNECTION_FAILED
209
+ );
190
210
  },
191
211
  });
192
212
  });
193
213
 
194
- if (connected) {
195
- this.connectionStateMonitor.record(
196
- CONNECTION_CHANGE.CONNECTION_ESTABLISHED
197
- );
198
- }
214
+ this.connectionStateMonitor.record(
215
+ CONNECTION_CHANGE.CONNECTION_ESTABLISHED
216
+ );
199
217
 
200
218
  return client;
201
219
  }
@@ -204,19 +222,9 @@ export class MqttOverWSProvider extends AbstractPubSubProvider {
204
222
  clientId: string,
205
223
  options: MqttProviderOptions = {}
206
224
  ): Promise<any> {
207
- return await this.clientsQueue.get(clientId, async clientId => {
208
- const client = await this.newClient({ ...options, clientId });
209
-
210
- if (client) {
211
- // Once connected, subscribe to all topics registered observers
212
- this._topicObservers.forEach(
213
- (_value: Set<SubscriptionObserver<any>>, key: string) => {
214
- client.subscribe(key);
215
- }
216
- );
217
- }
218
- return client;
219
- });
225
+ return await this.clientsQueue.get(clientId, clientId =>
226
+ this.newClient({ ...options, clientId })
227
+ );
220
228
  }
221
229
 
222
230
  protected async disconnect(clientId: string): Promise<void> {
@@ -224,27 +232,21 @@ export class MqttOverWSProvider extends AbstractPubSubProvider {
224
232
 
225
233
  if (client && client.isConnected()) {
226
234
  client.disconnect();
235
+ this.connectionStateMonitor.record(CONNECTION_CHANGE.CLOSED);
227
236
  }
228
237
  this.clientsQueue.remove(clientId);
229
- this.connectionStateMonitor.record(CONNECTION_CHANGE.CLOSED);
230
238
  }
231
239
 
232
240
  async publish(topics: string[] | string, msg: any) {
233
241
  const targetTopics = ([] as string[]).concat(topics);
234
242
  const message = JSON.stringify(msg);
235
243
 
236
- const client = await this.clientsQueue.get(this.clientId);
237
-
238
- if (client) {
239
- logger.debug('Publishing to topic(s)', targetTopics.join(','), message);
240
- targetTopics.forEach(topic => client.send(topic, message));
241
- } else {
242
- logger.debug(
243
- 'Publishing to topic(s) failed',
244
- targetTopics.join(','),
245
- message
246
- );
247
- }
244
+ const url = await this.endpoint;
245
+
246
+ const client = await this.connect(this.clientId, { url });
247
+
248
+ logger.debug('Publishing to topic(s)', targetTopics.join(','), message);
249
+ targetTopics.forEach(topic => client.send(topic, message));
248
250
  }
249
251
 
250
252
  protected _topicObservers: Map<string, Set<SubscriptionObserver<any>>> =
@@ -281,7 +283,6 @@ export class MqttOverWSProvider extends AbstractPubSubProvider {
281
283
  ): Observable<any> {
282
284
  const targetTopics = ([] as string[]).concat(topics);
283
285
  logger.debug('Subscribing to topic(s)', targetTopics.join(','));
284
- let reconnectSubscription: ZenObservable.Subscription;
285
286
 
286
287
  return new Observable(observer => {
287
288
  targetTopics.forEach(topic => {
@@ -297,6 +298,8 @@ export class MqttOverWSProvider extends AbstractPubSubProvider {
297
298
  observersForTopic.add(observer);
298
299
  });
299
300
 
301
+ // @ts-ignore
302
+ let client: Paho.Client;
300
303
  const { clientId = this.clientId } = options;
301
304
 
302
305
  // this._clientIdObservers is used to close observers when client gets disconnected
@@ -308,44 +311,30 @@ export class MqttOverWSProvider extends AbstractPubSubProvider {
308
311
  this._clientIdObservers.set(clientId, observersForClientId);
309
312
 
310
313
  (async () => {
311
- const getClient = async () => {
312
- try {
313
- const { url = await this.endpoint } = options;
314
- const client = await this.connect(clientId, { url });
315
- if (client !== undefined) {
316
- targetTopics.forEach(topic => {
317
- client.subscribe(topic);
318
- });
319
- }
320
- } catch (e) {
321
- logger.debug('Error forming connection', e);
322
- }
323
- };
314
+ const { url = await this.endpoint } = options;
324
315
 
325
- // Establish the initial connection
326
- await getClient();
327
-
328
- // Add an observable to the reconnection list to manage reconnection for this subscription
329
- reconnectSubscription = new Observable(observer => {
330
- this.reconnectionMonitor.addObserver(observer);
331
- }).subscribe(() => {
332
- getClient();
333
- });
316
+ try {
317
+ client = await this.connect(clientId, { url });
318
+ targetTopics.forEach(topic => {
319
+ client.subscribe(topic);
320
+ });
321
+ } catch (e) {
322
+ observer.error(e);
323
+ }
334
324
  })();
335
325
 
336
- return async () => {
337
- const client = await this.clientsQueue.get(clientId);
338
-
339
- reconnectSubscription?.unsubscribe();
326
+ return () => {
327
+ logger.debug('Unsubscribing from topic(s)', targetTopics.join(','));
340
328
 
341
329
  if (client) {
342
330
  this._clientIdObservers.get(clientId)?.delete(observer);
343
331
  // No more observers per client => client not needed anymore
344
332
  if (this._clientIdObservers.get(clientId)?.size === 0) {
345
- this.disconnect(clientId);
346
333
  this.connectionStateMonitor.record(
347
334
  CONNECTION_CHANGE.CLOSING_CONNECTION
348
335
  );
336
+
337
+ this.disconnect(clientId);
349
338
  this._clientIdObservers.delete(clientId);
350
339
  }
351
340
 
@@ -1,5 +1,15 @@
1
- // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
- // SPDX-License-Identifier: Apache-2.0
1
+ /*
2
+ * Copyright 2017-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5
+ * the License. A copy of the License is located at
6
+ *
7
+ * http://aws.amazon.com/apache2.0/
8
+ *
9
+ * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10
+ * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11
+ * and limitations under the License.
12
+ */
3
13
  import Observable from 'zen-observable-ts';
4
14
  import { PubSubProvider, ProviderOptions } from '../types/Provider';
5
15
  import { ConsoleLogger as Logger } from '@aws-amplify/core';
@@ -100,13 +100,3 @@ export const DEFAULT_KEEP_ALIVE_TIMEOUT = 5 * 60 * 1000;
100
100
  * Default Time in milleseconds to alert for missed GQL_CONNECTION_KEEP_ALIVE message
101
101
  */
102
102
  export const DEFAULT_KEEP_ALIVE_ALERT_TIMEOUT = 65 * 1000;
103
-
104
- /**
105
- * Default delay time in milleseconds between when reconnect is triggered vs when it is attempted
106
- */
107
- export const RECONNECT_DELAY = 5 * 1000;
108
-
109
- /**
110
- * Default interval time in milleseconds between when reconnect is re-attempted
111
- */
112
- export const RECONNECT_INTERVAL = 60 * 1000;
@@ -1,15 +1,17 @@
1
- // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
- // SPDX-License-Identifier: Apache-2.0
3
- export { AbstractPubSubProvider } from './PubSubProvider';
4
- export { AWSAppSyncProvider } from './AWSAppSyncProvider';
5
- export {
6
- AWSAppSyncRealTimeProvider,
7
- AWSAppSyncRealTimeProviderOptions,
8
- ObserverQuery,
9
- } from './AWSAppSyncRealTimeProvider';
10
- export { AWSIoTProvider, AWSIoTProviderOptions } from './AWSIotProvider';
11
- export {
12
- MqttProviderOptions,
13
- MqttOverWSProvider,
14
- mqttTopicMatch,
15
- } from './MqttOverWSProvider';
1
+ /*
2
+ * Copyright 2017-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5
+ * the License. A copy of the License is located at
6
+ *
7
+ * http://aws.amazon.com/apache2.0/
8
+ *
9
+ * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10
+ * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11
+ * and limitations under the License.
12
+ */
13
+ export * from './PubSubProvider';
14
+ export * from './AWSAppSyncProvider';
15
+ export * from './AWSAppSyncRealTimeProvider';
16
+ export * from './AWSIotProvider';
17
+ export * from './MqttOverWSProvider';
package/src/PubSub.ts CHANGED
@@ -1,5 +1,15 @@
1
- // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
- // SPDX-License-Identifier: Apache-2.0
1
+ /*
2
+ * Copyright 2017-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5
+ * the License. A copy of the License is located at
6
+ *
7
+ * http://aws.amazon.com/apache2.0/
8
+ *
9
+ * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10
+ * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11
+ * and limitations under the License.
12
+ */
3
13
  // import '../Common/Polyfills';
4
14
  import Observable from 'zen-observable-ts';
5
15
 
package/src/index.ts CHANGED
@@ -1,18 +1,26 @@
1
- // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
- // SPDX-License-Identifier: Apache-2.0
1
+ /*
2
+ * Copyright 2017-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5
+ * the License. A copy of the License is located at
6
+ *
7
+ * http://aws.amazon.com/apache2.0/
8
+ *
9
+ * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10
+ * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11
+ * and limitations under the License.
12
+ */
13
+ import { PubSub } from './PubSub';
14
+
15
+ export * from './Providers';
3
16
 
4
- export { PubSub } from './PubSub';
5
17
  export { CONNECTION_STATE_CHANGE } from './Providers/constants';
18
+
6
19
  export { ConnectionState, CONTROL_MSG } from './types';
7
- export {
8
- AWSAppSyncProvider,
9
- AWSAppSyncRealTimeProvider,
10
- AWSAppSyncRealTimeProviderOptions,
11
- AWSIoTProvider,
12
- AWSIoTProviderOptions,
13
- AbstractPubSubProvider,
14
- MqttOverWSProvider,
15
- MqttProviderOptions,
16
- ObserverQuery,
17
- mqttTopicMatch,
18
- } from './Providers';
20
+
21
+ export { PubSub };
22
+
23
+ /**
24
+ * @deprecated use named import
25
+ */
26
+ export default PubSub;
@@ -1,5 +1,15 @@
1
- // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
- // SPDX-License-Identifier: Apache-2.0
1
+ /*
2
+ * Copyright 2017-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5
+ * the License. A copy of the License is located at
6
+ *
7
+ * http://aws.amazon.com/apache2.0/
8
+ *
9
+ * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10
+ * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11
+ * and limitations under the License.
12
+ */
3
13
  import Observable from 'zen-observable-ts';
4
14
 
5
15
  export interface PubSubOptions {
@@ -10,6 +20,11 @@ export interface ProviderOptions {
10
20
  [key: string]: any;
11
21
  }
12
22
 
23
+ /**
24
+ * @deprecated Migrated to ProviderOptions
25
+ */
26
+ export type ProvidertOptions = ProviderOptions;
27
+
13
28
  export interface PubSubProvider {
14
29
  // configure your provider
15
30
  configure(config: object): object;
@@ -1,5 +1,15 @@
1
- // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
- // SPDX-License-Identifier: Apache-2.0
1
+ /*
2
+ * Copyright 2017-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5
+ * the License. A copy of the License is located at
6
+ *
7
+ * http://aws.amazon.com/apache2.0/
8
+ *
9
+ * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10
+ * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11
+ * and limitations under the License.
12
+ */
3
13
 
4
14
  export interface SubscriptionObserver<T> {
5
15
  closed: boolean;
@@ -1,4 +1,14 @@
1
- // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
- // SPDX-License-Identifier: Apache-2.0
1
+ /*
2
+ * Copyright 2017-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5
+ * the License. A copy of the License is located at
6
+ *
7
+ * http://aws.amazon.com/apache2.0/
8
+ *
9
+ * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10
+ * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11
+ * and limitations under the License.
12
+ */
3
13
  export * from './Provider';
4
14
  export * from './PubSub';
@@ -1,5 +1,15 @@
1
- // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
- // SPDX-License-Identifier: Apache-2.0
1
+ /*
2
+ * Copyright 2017-2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5
+ * the License. A copy of the License is located at
6
+ *
7
+ * http://aws.amazon.com/apache2.0/
8
+ *
9
+ * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10
+ * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11
+ * and limitations under the License.
12
+ */
3
13
 
4
14
  import { Reachability } from '@aws-amplify/core';
5
15
  import Observable, { ZenObservable } from 'zen-observable-ts';
@@ -53,7 +63,6 @@ export class ConnectionStateMonitor {
53
63
  private _linkedConnectionStateObservable: Observable<LinkedConnectionStates>;
54
64
  private _linkedConnectionStateObserver: ZenObservable.SubscriptionObserver<LinkedConnectionStates>;
55
65
  private _networkMonitoringSubscription?: ZenObservable.Subscription;
56
- private _initialNetworkStateSubscription?: ZenObservable.Subscription;
57
66
 
58
67
  constructor() {
59
68
  this._networkMonitoringSubscription = undefined;
@@ -64,16 +73,6 @@ export class ConnectionStateMonitor {
64
73
  keepAliveState: 'healthy',
65
74
  };
66
75
 
67
- // Attempt to update the state with the current actual network state
68
- this._initialNetworkStateSubscription = ReachabilityMonitor().subscribe(
69
- ({ online }) => {
70
- this.record(
71
- online ? CONNECTION_CHANGE.ONLINE : CONNECTION_CHANGE.OFFLINE
72
- );
73
- this._initialNetworkStateSubscription?.unsubscribe();
74
- }
75
- );
76
-
77
76
  this._linkedConnectionStateObservable =
78
77
  new Observable<LinkedConnectionStates>(connectionStateObserver => {
79
78
  connectionStateObserver.next(this._linkedConnectionState);
@@ -85,9 +84,6 @@ export class ConnectionStateMonitor {
85
84
  * Turn network state monitoring on if it isn't on already
86
85
  */
87
86
  private enableNetworkMonitoring() {
88
- // If no initial network state was discovered, stop trying
89
- this._initialNetworkStateSubscription?.unsubscribe();
90
-
91
87
  // Maintain the network state based on the reachability monitor
92
88
  if (this._networkMonitoringSubscription === undefined) {
93
89
  this._networkMonitoringSubscription = ReachabilityMonitor().subscribe(
@@ -0,0 +1,6 @@
1
+ var config = require('./webpack.config.js');
2
+
3
+ var entry = {
4
+ 'aws-amplify-pubsub': './lib-esm/index.js',
5
+ };
6
+ module.exports = Object.assign(config, { entry, mode: 'development' });
package/lib/.tsbuildinfo DELETED
@@ -1,3 +0,0 @@
1
- {
2
- "version": "3.8.3"
3
- }
@@ -1,21 +0,0 @@
1
- import Observable from 'zen-observable-ts';
2
- import { MqttOverWSProvider } from './MqttOverWSProvider';
3
- /**
4
- * @deprecated Unused, all usecases have migrated to AWSAppSyncRealtimeProvider
5
- */
6
- export declare class AWSAppSyncProvider extends MqttOverWSProvider {
7
- protected get endpoint(): void;
8
- getProviderName(): string;
9
- publish(topics: string[] | string, msg: any, options?: any): Promise<void>;
10
- private _cleanUp;
11
- private _cleanUpForTopic;
12
- onDisconnect({ clientId, errorCode, ...args }: {
13
- [x: string]: any;
14
- clientId: any;
15
- errorCode: any;
16
- }): void;
17
- private _topicClient;
18
- private _topicAlias;
19
- protected disconnect(clientId: string): Promise<void>;
20
- subscribe(topics: string[] | string, options?: any): Observable<any>;
21
- }