@aws-amplify/pubsub 5.0.12 → 5.0.13-push-notification-dryrun.43
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/Providers/AWSAppSyncRealTimeProvider/index.d.ts +9 -8
- package/lib/Providers/AWSAppSyncRealTimeProvider/index.js +19 -14
- package/lib/Providers/AWSAppSyncRealTimeProvider/index.js.map +1 -1
- package/lib/Providers/AWSIotProvider.d.ts +1 -1
- package/lib/Providers/AWSIotProvider.js +1 -1
- package/lib/Providers/AWSIotProvider.js.map +1 -1
- package/lib/Providers/MqttOverWSProvider.d.ts +29 -12
- package/lib/Providers/MqttOverWSProvider.js +9 -10
- package/lib/Providers/MqttOverWSProvider.js.map +1 -1
- package/lib/Providers/PubSubProvider.d.ts +8 -7
- package/lib/Providers/PubSubProvider.js +0 -2
- package/lib/Providers/PubSubProvider.js.map +1 -1
- package/lib/Providers/index.d.ts +0 -1
- package/lib/Providers/index.js +0 -2
- package/lib/Providers/index.js.map +1 -1
- package/lib/PubSub.d.ts +9 -3
- package/lib/PubSub.js +4 -2
- package/lib/PubSub.js.map +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.js +0 -1
- package/lib/index.js.map +1 -1
- package/lib/types/Provider.d.ts +7 -3
- package/lib/types/PubSub.d.ts +3 -0
- package/lib/types/PubSub.js +0 -2
- package/lib/types/PubSub.js.map +1 -1
- package/lib/types/index.d.ts +1 -1
- package/lib/types/index.js +3 -2
- package/lib/types/index.js.map +1 -1
- package/lib/utils/ConnectionStateMonitor.js.map +1 -1
- package/lib-esm/Providers/AWSAppSyncRealTimeProvider/index.d.ts +9 -8
- package/lib-esm/Providers/AWSAppSyncRealTimeProvider/index.js +20 -15
- package/lib-esm/Providers/AWSAppSyncRealTimeProvider/index.js.map +1 -1
- package/lib-esm/Providers/AWSIotProvider.d.ts +1 -1
- package/lib-esm/Providers/AWSIotProvider.js +1 -1
- package/lib-esm/Providers/AWSIotProvider.js.map +1 -1
- package/lib-esm/Providers/MqttOverWSProvider.d.ts +29 -12
- package/lib-esm/Providers/MqttOverWSProvider.js +10 -11
- package/lib-esm/Providers/MqttOverWSProvider.js.map +1 -1
- package/lib-esm/Providers/PubSubProvider.d.ts +8 -7
- package/lib-esm/Providers/PubSubProvider.js +0 -2
- package/lib-esm/Providers/PubSubProvider.js.map +1 -1
- package/lib-esm/Providers/index.d.ts +0 -1
- package/lib-esm/Providers/index.js +0 -1
- package/lib-esm/Providers/index.js.map +1 -1
- package/lib-esm/PubSub.d.ts +9 -3
- package/lib-esm/PubSub.js +4 -2
- package/lib-esm/PubSub.js.map +1 -1
- package/lib-esm/index.d.ts +1 -1
- package/lib-esm/index.js +1 -1
- package/lib-esm/index.js.map +1 -1
- package/lib-esm/types/Provider.d.ts +7 -3
- package/lib-esm/types/PubSub.d.ts +3 -0
- package/lib-esm/types/PubSub.js +0 -2
- package/lib-esm/types/PubSub.js.map +1 -1
- package/lib-esm/types/index.d.ts +1 -1
- package/lib-esm/types/index.js +1 -1
- package/lib-esm/types/index.js.map +1 -1
- package/lib-esm/utils/ConnectionStateMonitor.js.map +1 -1
- package/package.json +9 -9
- package/src/Providers/AWSAppSyncRealTimeProvider/index.ts +79 -29
- package/src/Providers/AWSIotProvider.ts +2 -2
- package/src/Providers/MqttOverWSProvider.ts +67 -31
- package/src/Providers/PubSubProvider.ts +13 -10
- package/src/Providers/index.ts +0 -1
- package/src/PubSub.ts +16 -8
- package/src/index.ts +0 -1
- package/src/types/Provider.ts +11 -3
- package/src/types/PubSub.ts +5 -0
- package/src/types/index.ts +1 -1
- package/src/utils/ConnectionStateMonitor.ts +0 -1
- package/CHANGELOG.md +0 -1269
- package/lib/Providers/AWSAppSyncProvider.d.ts +0 -21
- package/lib/Providers/AWSAppSyncProvider.js +0 -210
- package/lib/Providers/AWSAppSyncProvider.js.map +0 -1
- package/lib-esm/Providers/AWSAppSyncProvider.d.ts +0 -21
- package/lib-esm/Providers/AWSAppSyncProvider.js +0 -208
- package/lib-esm/Providers/AWSAppSyncProvider.js.map +0 -1
- package/src/Providers/AWSAppSyncProvider.ts +0 -194
|
@@ -5,7 +5,11 @@ import { v4 as uuid } from 'uuid';
|
|
|
5
5
|
import Observable, { ZenObservable } from 'zen-observable-ts';
|
|
6
6
|
|
|
7
7
|
import { AbstractPubSubProvider } from './PubSubProvider';
|
|
8
|
-
import {
|
|
8
|
+
import {
|
|
9
|
+
ConnectionState,
|
|
10
|
+
PubSubContentObserver,
|
|
11
|
+
PubSubContent,
|
|
12
|
+
} from '../types/PubSub';
|
|
9
13
|
import { ProviderOptions } from '../types/Provider';
|
|
10
14
|
import { ConsoleLogger as Logger, Hub } from '@aws-amplify/core';
|
|
11
15
|
import {
|
|
@@ -37,19 +41,39 @@ export function mqttTopicMatch(filter: string, topic: string) {
|
|
|
37
41
|
export interface MqttProviderOptions extends ProviderOptions {
|
|
38
42
|
clientId?: string;
|
|
39
43
|
url?: string;
|
|
44
|
+
aws_pubsub_endpoint?: string;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
interface PahoClient {
|
|
48
|
+
onMessageArrived: (params: {
|
|
49
|
+
destinationName: string;
|
|
50
|
+
payloadString: string;
|
|
51
|
+
}) => void;
|
|
52
|
+
onConnectionLost: (params: { errorCode: number }) => void;
|
|
53
|
+
connect: (params: {
|
|
54
|
+
[k: string]: string | number | boolean | (() => void);
|
|
55
|
+
}) => void;
|
|
56
|
+
disconnect: () => void;
|
|
57
|
+
isConnected: () => boolean;
|
|
58
|
+
subscribe: (topic: string) => void;
|
|
59
|
+
unsubscribe: (topic: string) => void;
|
|
60
|
+
send(topic: string, message: string);
|
|
40
61
|
}
|
|
41
62
|
|
|
42
63
|
class ClientsQueue {
|
|
43
|
-
private promises: Map<string, Promise<
|
|
64
|
+
private promises: Map<string, Promise<PahoClient | undefined>> = new Map();
|
|
44
65
|
|
|
45
|
-
async get(
|
|
66
|
+
async get(
|
|
67
|
+
clientId: string,
|
|
68
|
+
clientFactory?: (input: string) => Promise<PahoClient | undefined>
|
|
69
|
+
) {
|
|
46
70
|
const cachedPromise = this.promises.get(clientId);
|
|
47
71
|
if (cachedPromise) return cachedPromise;
|
|
48
72
|
|
|
49
73
|
if (clientFactory) {
|
|
50
74
|
const newPromise = clientFactory(clientId);
|
|
51
75
|
this.promises.set(clientId, newPromise);
|
|
52
|
-
newPromise.catch(
|
|
76
|
+
newPromise.catch(() => this.promises.delete(clientId));
|
|
53
77
|
return newPromise;
|
|
54
78
|
}
|
|
55
79
|
|
|
@@ -65,13 +89,17 @@ class ClientsQueue {
|
|
|
65
89
|
}
|
|
66
90
|
}
|
|
67
91
|
|
|
68
|
-
const dispatchPubSubEvent = (
|
|
92
|
+
const dispatchPubSubEvent = (
|
|
93
|
+
event: string,
|
|
94
|
+
data: Record<string, unknown>,
|
|
95
|
+
message: string
|
|
96
|
+
) => {
|
|
69
97
|
Hub.dispatch('pubsub', { event, data, message }, 'PubSub', AMPLIFY_SYMBOL);
|
|
70
98
|
};
|
|
71
99
|
|
|
72
100
|
const topicSymbol = typeof Symbol !== 'undefined' ? Symbol('topic') : '@@topic';
|
|
73
101
|
|
|
74
|
-
export class MqttOverWSProvider extends AbstractPubSubProvider {
|
|
102
|
+
export class MqttOverWSProvider extends AbstractPubSubProvider<MqttProviderOptions> {
|
|
75
103
|
private _clientsQueue = new ClientsQueue();
|
|
76
104
|
private connectionState: ConnectionState;
|
|
77
105
|
private readonly connectionStateMonitor = new ConnectionStateMonitor();
|
|
@@ -106,11 +134,11 @@ export class MqttOverWSProvider extends AbstractPubSubProvider {
|
|
|
106
134
|
}
|
|
107
135
|
|
|
108
136
|
protected get clientId() {
|
|
109
|
-
return this.options.clientId
|
|
137
|
+
return this.options.clientId!;
|
|
110
138
|
}
|
|
111
139
|
|
|
112
|
-
protected get endpoint() {
|
|
113
|
-
return this.options.aws_pubsub_endpoint;
|
|
140
|
+
protected get endpoint(): Promise<string | undefined> {
|
|
141
|
+
return Promise.resolve(this.options.aws_pubsub_endpoint);
|
|
114
142
|
}
|
|
115
143
|
|
|
116
144
|
protected get clientsQueue() {
|
|
@@ -118,12 +146,9 @@ export class MqttOverWSProvider extends AbstractPubSubProvider {
|
|
|
118
146
|
}
|
|
119
147
|
|
|
120
148
|
protected get isSSLEnabled() {
|
|
121
|
-
return !this.options
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
protected getTopicForValue(value: any) {
|
|
126
|
-
return typeof value === 'object' && value[topicSymbol];
|
|
149
|
+
return !this.options[
|
|
150
|
+
'aws_appsync_dangerously_connect_to_http_endpoint_for_testing'
|
|
151
|
+
];
|
|
127
152
|
}
|
|
128
153
|
|
|
129
154
|
getProviderName() {
|
|
@@ -152,12 +177,15 @@ export class MqttOverWSProvider extends AbstractPubSubProvider {
|
|
|
152
177
|
}
|
|
153
178
|
}
|
|
154
179
|
|
|
155
|
-
public async newClient({
|
|
180
|
+
public async newClient({
|
|
181
|
+
url,
|
|
182
|
+
clientId,
|
|
183
|
+
}: MqttProviderOptions): Promise<PahoClient> {
|
|
156
184
|
logger.debug('Creating new MQTT client', clientId);
|
|
157
185
|
|
|
158
186
|
this.connectionStateMonitor.record(CONNECTION_CHANGE.OPENING_CONNECTION);
|
|
159
187
|
// @ts-ignore
|
|
160
|
-
const client = new Paho.Client(url, clientId);
|
|
188
|
+
const client = new Paho.Client(url, clientId) as PahoClient;
|
|
161
189
|
|
|
162
190
|
client.onMessageArrived = ({
|
|
163
191
|
destinationName: topic,
|
|
@@ -183,7 +211,7 @@ export class MqttOverWSProvider extends AbstractPubSubProvider {
|
|
|
183
211
|
useSSL: this.isSSLEnabled,
|
|
184
212
|
mqttVersion: 3,
|
|
185
213
|
onSuccess: () => resolve(true),
|
|
186
|
-
onFailure:
|
|
214
|
+
onFailure: () => {
|
|
187
215
|
if (clientId) this._clientsQueue.remove(clientId);
|
|
188
216
|
this.connectionStateMonitor.record(CONNECTION_CHANGE.CLOSED);
|
|
189
217
|
resolve(false);
|
|
@@ -203,14 +231,17 @@ export class MqttOverWSProvider extends AbstractPubSubProvider {
|
|
|
203
231
|
protected async connect(
|
|
204
232
|
clientId: string,
|
|
205
233
|
options: MqttProviderOptions = {}
|
|
206
|
-
): Promise<
|
|
234
|
+
): Promise<PahoClient | undefined> {
|
|
207
235
|
return await this.clientsQueue.get(clientId, async clientId => {
|
|
208
236
|
const client = await this.newClient({ ...options, clientId });
|
|
209
237
|
|
|
210
238
|
if (client) {
|
|
211
239
|
// Once connected, subscribe to all topics registered observers
|
|
212
240
|
this._topicObservers.forEach(
|
|
213
|
-
(
|
|
241
|
+
(
|
|
242
|
+
_value: Set<ZenObservable.SubscriptionObserver<any>>,
|
|
243
|
+
key: string
|
|
244
|
+
) => {
|
|
214
245
|
client.subscribe(key);
|
|
215
246
|
}
|
|
216
247
|
);
|
|
@@ -229,7 +260,7 @@ export class MqttOverWSProvider extends AbstractPubSubProvider {
|
|
|
229
260
|
this.connectionStateMonitor.record(CONNECTION_CHANGE.CLOSED);
|
|
230
261
|
}
|
|
231
262
|
|
|
232
|
-
async publish(topics: string[] | string, msg:
|
|
263
|
+
async publish(topics: string[] | string, msg: PubSubContent) {
|
|
233
264
|
const targetTopics = ([] as string[]).concat(topics);
|
|
234
265
|
const message = JSON.stringify(msg);
|
|
235
266
|
|
|
@@ -247,23 +278,26 @@ export class MqttOverWSProvider extends AbstractPubSubProvider {
|
|
|
247
278
|
}
|
|
248
279
|
}
|
|
249
280
|
|
|
250
|
-
protected _topicObservers: Map<string, Set<
|
|
281
|
+
protected _topicObservers: Map<string, Set<PubSubContentObserver>> =
|
|
251
282
|
new Map();
|
|
252
283
|
|
|
253
|
-
protected _clientIdObservers: Map<string, Set<
|
|
284
|
+
protected _clientIdObservers: Map<string, Set<PubSubContentObserver>> =
|
|
254
285
|
new Map();
|
|
255
286
|
|
|
256
|
-
private _onMessage(topic: string, msg:
|
|
287
|
+
private _onMessage(topic: string, msg: string) {
|
|
257
288
|
try {
|
|
258
|
-
const matchedTopicObservers: Set<
|
|
289
|
+
const matchedTopicObservers: Set<
|
|
290
|
+
ZenObservable.SubscriptionObserver<any>
|
|
291
|
+
>[] = [];
|
|
259
292
|
this._topicObservers.forEach((observerForTopic, observerTopic) => {
|
|
260
293
|
if (mqttTopicMatch(observerTopic, topic)) {
|
|
261
294
|
matchedTopicObservers.push(observerForTopic);
|
|
262
295
|
}
|
|
263
296
|
});
|
|
264
|
-
const parsedMessage = JSON.parse(msg);
|
|
297
|
+
const parsedMessage: PubSubContent = JSON.parse(msg);
|
|
265
298
|
|
|
266
299
|
if (typeof parsedMessage === 'object') {
|
|
300
|
+
// @ts-ignore
|
|
267
301
|
parsedMessage[topicSymbol] = topic;
|
|
268
302
|
}
|
|
269
303
|
|
|
@@ -278,7 +312,7 @@ export class MqttOverWSProvider extends AbstractPubSubProvider {
|
|
|
278
312
|
subscribe(
|
|
279
313
|
topics: string[] | string,
|
|
280
314
|
options: MqttProviderOptions = {}
|
|
281
|
-
): Observable<
|
|
315
|
+
): Observable<PubSubContent> {
|
|
282
316
|
const targetTopics = ([] as string[]).concat(topics);
|
|
283
317
|
logger.debug('Subscribing to topic(s)', targetTopics.join(','));
|
|
284
318
|
let reconnectSubscription: ZenObservable.Subscription;
|
|
@@ -302,10 +336,12 @@ export class MqttOverWSProvider extends AbstractPubSubProvider {
|
|
|
302
336
|
// this._clientIdObservers is used to close observers when client gets disconnected
|
|
303
337
|
let observersForClientId = this._clientIdObservers.get(clientId);
|
|
304
338
|
if (!observersForClientId) {
|
|
305
|
-
observersForClientId = new Set();
|
|
339
|
+
observersForClientId = new Set<PubSubContentObserver>();
|
|
340
|
+
}
|
|
341
|
+
if (observersForClientId) {
|
|
342
|
+
observersForClientId.add(observer);
|
|
343
|
+
this._clientIdObservers.set(clientId, observersForClientId);
|
|
306
344
|
}
|
|
307
|
-
observersForClientId.add(observer);
|
|
308
|
-
this._clientIdObservers.set(clientId, observersForClientId);
|
|
309
345
|
|
|
310
346
|
(async () => {
|
|
311
347
|
const getClient = async () => {
|
|
@@ -352,7 +388,7 @@ export class MqttOverWSProvider extends AbstractPubSubProvider {
|
|
|
352
388
|
targetTopics.forEach(topic => {
|
|
353
389
|
const observersForTopic =
|
|
354
390
|
this._topicObservers.get(topic) ||
|
|
355
|
-
(new Set() as Set<SubscriptionObserver<any>>);
|
|
391
|
+
(new Set() as Set<ZenObservable.SubscriptionObserver<any>>);
|
|
356
392
|
|
|
357
393
|
observersForTopic.delete(observer);
|
|
358
394
|
|
|
@@ -3,17 +3,20 @@
|
|
|
3
3
|
import Observable from 'zen-observable-ts';
|
|
4
4
|
import { PubSubProvider, ProviderOptions } from '../types/Provider';
|
|
5
5
|
import { ConsoleLogger as Logger } from '@aws-amplify/core';
|
|
6
|
+
import { PubSubContent } from '../types/PubSub';
|
|
6
7
|
|
|
7
8
|
const logger = new Logger('AbstractPubSubProvider');
|
|
8
9
|
|
|
9
|
-
export abstract class AbstractPubSubProvider
|
|
10
|
-
|
|
10
|
+
export abstract class AbstractPubSubProvider<T extends ProviderOptions>
|
|
11
|
+
implements PubSubProvider
|
|
12
|
+
{
|
|
13
|
+
private _config: T;
|
|
11
14
|
|
|
12
|
-
constructor(options:
|
|
15
|
+
constructor(options: T) {
|
|
13
16
|
this._config = options;
|
|
14
17
|
}
|
|
15
18
|
|
|
16
|
-
configure(config:
|
|
19
|
+
configure(config: T): T {
|
|
17
20
|
this._config = { ...config, ...this._config };
|
|
18
21
|
|
|
19
22
|
logger.debug(`configure ${this.getProviderName()}`, this._config);
|
|
@@ -27,20 +30,20 @@ export abstract class AbstractPubSubProvider implements PubSubProvider {
|
|
|
27
30
|
|
|
28
31
|
abstract getProviderName(): string;
|
|
29
32
|
|
|
30
|
-
protected get options():
|
|
33
|
+
protected get options(): T {
|
|
31
34
|
return { ...this._config };
|
|
32
35
|
}
|
|
33
36
|
|
|
34
|
-
public abstract newClient(clientOptions:
|
|
37
|
+
public abstract newClient(clientOptions: T): Promise<any>;
|
|
35
38
|
|
|
36
39
|
public abstract publish(
|
|
37
40
|
topics: string[] | string,
|
|
38
|
-
msg:
|
|
39
|
-
options?:
|
|
41
|
+
msg: PubSubContent,
|
|
42
|
+
options?: T
|
|
40
43
|
): void;
|
|
41
44
|
|
|
42
45
|
public abstract subscribe(
|
|
43
46
|
topics: string[] | string,
|
|
44
|
-
options?:
|
|
45
|
-
): Observable<
|
|
47
|
+
options?: T
|
|
48
|
+
): Observable<PubSubContent>;
|
|
46
49
|
}
|
package/src/Providers/index.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
export { AbstractPubSubProvider } from './PubSubProvider';
|
|
4
|
-
export { AWSAppSyncProvider } from './AWSAppSyncProvider';
|
|
5
4
|
export {
|
|
6
5
|
AWSAppSyncRealTimeProvider,
|
|
7
6
|
AWSAppSyncRealTimeProviderOptions,
|
package/src/PubSub.ts
CHANGED
|
@@ -11,10 +11,16 @@ import {
|
|
|
11
11
|
} from '@aws-amplify/core';
|
|
12
12
|
import { PubSubProvider, PubSubOptions, ProviderOptions } from './types';
|
|
13
13
|
import { AWSAppSyncRealTimeProvider } from './Providers';
|
|
14
|
+
import { PubSubContent } from './types/PubSub';
|
|
14
15
|
|
|
15
16
|
const { isNode } = browserOrNode();
|
|
16
17
|
const logger = new Logger('PubSub');
|
|
17
18
|
|
|
19
|
+
type PubSubObservable = {
|
|
20
|
+
provider: PubSubProvider;
|
|
21
|
+
value: string | Record<string, unknown>;
|
|
22
|
+
};
|
|
23
|
+
|
|
18
24
|
export class PubSubClass {
|
|
19
25
|
private _options: PubSubOptions;
|
|
20
26
|
|
|
@@ -60,7 +66,9 @@ export class PubSubClass {
|
|
|
60
66
|
* @return {Object} - The current configuration
|
|
61
67
|
*/
|
|
62
68
|
configure(options: PubSubOptions) {
|
|
63
|
-
const opt
|
|
69
|
+
const opt: Record<string, unknown> = options
|
|
70
|
+
? options.PubSub || options
|
|
71
|
+
: {};
|
|
64
72
|
logger.debug('configure PubSub', { opt });
|
|
65
73
|
|
|
66
74
|
this._options = Object.assign({}, this._options, opt);
|
|
@@ -105,14 +113,14 @@ export class PubSubClass {
|
|
|
105
113
|
}
|
|
106
114
|
|
|
107
115
|
private getProviders(options: ProviderOptions = {}) {
|
|
108
|
-
const
|
|
116
|
+
const providerName = options.provider;
|
|
109
117
|
if (!providerName) {
|
|
110
118
|
return this._pluggables;
|
|
111
119
|
}
|
|
112
120
|
|
|
113
121
|
const provider = this.getProviderByName(providerName);
|
|
114
122
|
if (!provider) {
|
|
115
|
-
throw new Error(`Could not find provider named ${providerName}`);
|
|
123
|
+
throw new Error(`Could not find provider named ${String(providerName)}`);
|
|
116
124
|
}
|
|
117
125
|
|
|
118
126
|
return [provider];
|
|
@@ -120,7 +128,7 @@ export class PubSubClass {
|
|
|
120
128
|
|
|
121
129
|
async publish(
|
|
122
130
|
topics: string[] | string,
|
|
123
|
-
msg:
|
|
131
|
+
msg: PubSubContent,
|
|
124
132
|
options?: ProviderOptions
|
|
125
133
|
) {
|
|
126
134
|
return Promise.all(
|
|
@@ -133,7 +141,7 @@ export class PubSubClass {
|
|
|
133
141
|
subscribe(
|
|
134
142
|
topics: string[] | string,
|
|
135
143
|
options?: ProviderOptions
|
|
136
|
-
): Observable<
|
|
144
|
+
): Observable<PubSubObservable> {
|
|
137
145
|
if (isNode && this._options && this._options.ssr) {
|
|
138
146
|
throw new Error(
|
|
139
147
|
'Subscriptions are not supported for Server-Side Rendering (SSR)'
|
|
@@ -144,7 +152,7 @@ export class PubSubClass {
|
|
|
144
152
|
|
|
145
153
|
const providers = this.getProviders(options);
|
|
146
154
|
|
|
147
|
-
return new Observable(observer => {
|
|
155
|
+
return new Observable<PubSubObservable>(observer => {
|
|
148
156
|
const observables = providers.map(provider => ({
|
|
149
157
|
provider,
|
|
150
158
|
observable: provider.subscribe(topics, options),
|
|
@@ -153,8 +161,8 @@ export class PubSubClass {
|
|
|
153
161
|
const subscriptions = observables.map(({ provider, observable }) =>
|
|
154
162
|
observable.subscribe({
|
|
155
163
|
start: console.error,
|
|
156
|
-
next: value => observer.next({ provider, value }),
|
|
157
|
-
error: error => observer.error({ provider, error }),
|
|
164
|
+
next: (value: PubSubContent) => observer.next({ provider, value }),
|
|
165
|
+
error: (error: unknown) => observer.error({ provider, error }),
|
|
158
166
|
// complete: observer.complete, // TODO: when all completed, complete the outer one
|
|
159
167
|
})
|
|
160
168
|
);
|
package/src/index.ts
CHANGED
|
@@ -5,7 +5,6 @@ export { PubSub } from './PubSub';
|
|
|
5
5
|
export { CONNECTION_STATE_CHANGE } from './Providers/constants';
|
|
6
6
|
export { ConnectionState, CONTROL_MSG } from './types';
|
|
7
7
|
export {
|
|
8
|
-
AWSAppSyncProvider,
|
|
9
8
|
AWSAppSyncRealTimeProvider,
|
|
10
9
|
AWSAppSyncRealTimeProviderOptions,
|
|
11
10
|
AWSIoTProvider,
|
package/src/types/Provider.ts
CHANGED
|
@@ -1,18 +1,22 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
import Observable from 'zen-observable-ts';
|
|
4
|
+
import { PubSubContent } from './PubSub';
|
|
4
5
|
|
|
5
6
|
export interface PubSubOptions {
|
|
6
7
|
[key: string]: any;
|
|
8
|
+
ssr?: boolean;
|
|
9
|
+
PubSub?: {};
|
|
7
10
|
}
|
|
8
11
|
|
|
9
12
|
export interface ProviderOptions {
|
|
10
13
|
[key: string]: any;
|
|
14
|
+
provider?: string | symbol;
|
|
11
15
|
}
|
|
12
16
|
|
|
13
17
|
export interface PubSubProvider {
|
|
14
18
|
// configure your provider
|
|
15
|
-
configure(config:
|
|
19
|
+
configure(config: Record<string, unknown>): Record<string, unknown>;
|
|
16
20
|
|
|
17
21
|
// return 'Analytics';
|
|
18
22
|
getCategory(): string;
|
|
@@ -20,10 +24,14 @@ export interface PubSubProvider {
|
|
|
20
24
|
// return the name of you provider
|
|
21
25
|
getProviderName(): string;
|
|
22
26
|
|
|
23
|
-
publish(
|
|
27
|
+
publish(
|
|
28
|
+
topics: string[] | string,
|
|
29
|
+
msg: PubSubContent,
|
|
30
|
+
options?: ProviderOptions
|
|
31
|
+
): void;
|
|
24
32
|
|
|
25
33
|
subscribe(
|
|
26
34
|
topics: string[] | string,
|
|
27
35
|
options?: ProviderOptions
|
|
28
|
-
): Observable<
|
|
36
|
+
): Observable<PubSubContent>;
|
|
29
37
|
}
|
package/src/types/PubSub.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
import { ZenObservable } from 'zen-observable-ts';
|
|
3
4
|
|
|
4
5
|
export interface SubscriptionObserver<T> {
|
|
5
6
|
closed: boolean;
|
|
@@ -51,3 +52,7 @@ export enum ConnectionState {
|
|
|
51
52
|
*/
|
|
52
53
|
ConnectedPendingKeepAlive = 'ConnectedPendingKeepAlive',
|
|
53
54
|
}
|
|
55
|
+
|
|
56
|
+
export type PubSubContent = Record<string, unknown> | string;
|
|
57
|
+
export type PubSubContentObserver =
|
|
58
|
+
ZenObservable.SubscriptionObserver<PubSubContent>;
|
package/src/types/index.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import { Reachability } from '@aws-amplify/core';
|
|
5
4
|
import Observable, { ZenObservable } from 'zen-observable-ts';
|
|
6
5
|
import { ConnectionState } from '../types/PubSub';
|
|
7
6
|
import { ReachabilityMonitor } from './ReachabilityMonitor';
|