1 |
|
2 |
|
3 | import Observable from 'zen-observable-ts';
|
4 | import { PubSubProvider, ProviderOptions } from '../types/Provider';
|
5 | import {
|
6 | CustomUserAgentDetails,
|
7 | ConsoleLogger as Logger,
|
8 | } from '@aws-amplify/core';
|
9 | import { PubSubContent } from '../types/PubSub';
|
10 |
|
11 | const logger = new Logger('AbstractPubSubProvider');
|
12 |
|
13 | export abstract class AbstractPubSubProvider<T extends ProviderOptions>
|
14 | implements PubSubProvider
|
15 | {
|
16 | private _config: T;
|
17 |
|
18 | constructor(options: T) {
|
19 | this._config = options;
|
20 | }
|
21 |
|
22 | configure(config: T): T {
|
23 | this._config = { ...config, ...this._config };
|
24 |
|
25 | logger.debug(`configure ${this.getProviderName()}`, this._config);
|
26 |
|
27 | return this.options;
|
28 | }
|
29 |
|
30 | getCategory() {
|
31 | return 'PubSub';
|
32 | }
|
33 |
|
34 | abstract getProviderName(): string;
|
35 |
|
36 | protected get options(): T {
|
37 | return { ...this._config };
|
38 | }
|
39 |
|
40 | public abstract newClient(clientOptions: T): Promise<any>;
|
41 |
|
42 | public abstract publish(
|
43 | topics: string[] | string,
|
44 | msg: PubSubContent,
|
45 | options?: T
|
46 | ): void;
|
47 |
|
48 | public abstract subscribe(
|
49 | topics: string[] | string,
|
50 | options?: T,
|
51 | customUserAgentDetails?: CustomUserAgentDetails
|
52 | ): Observable<PubSubContent>;
|
53 | }
|