UNPKG

2.42 kBTypeScriptView Raw
1import Observable from 'zen-observable-ts';
2import { AbstractPubSubProvider } from './PubSubProvider';
3import { PubSubContentObserver, PubSubContent } from '../types/PubSub';
4import { ProviderOptions } from '../types/Provider';
5export declare function mqttTopicMatch(filter: string, topic: string): boolean;
6export interface MqttProviderOptions extends ProviderOptions {
7 clientId?: string;
8 url?: string;
9 aws_pubsub_endpoint?: string;
10}
11interface PahoClient {
12 onMessageArrived: (params: {
13 destinationName: string;
14 payloadString: string;
15 }) => void;
16 onConnectionLost: (params: {
17 errorCode: number;
18 }) => void;
19 connect: (params: {
20 [k: string]: string | number | boolean | (() => void);
21 }) => void;
22 disconnect: () => void;
23 isConnected: () => boolean;
24 subscribe: (topic: string) => void;
25 unsubscribe: (topic: string) => void;
26 send(topic: string, message: string): any;
27}
28declare class ClientsQueue {
29 private promises;
30 get(clientId: string, clientFactory?: (input: string) => Promise<PahoClient | undefined>): Promise<PahoClient>;
31 get allClients(): string[];
32 remove(clientId: string): void;
33}
34export declare class MqttOverWSProvider extends AbstractPubSubProvider<MqttProviderOptions> {
35 private _clientsQueue;
36 private connectionState;
37 private readonly connectionStateMonitor;
38 private readonly reconnectionMonitor;
39 constructor(options?: MqttProviderOptions);
40 protected get clientId(): string;
41 protected get endpoint(): Promise<string | undefined>;
42 protected get clientsQueue(): ClientsQueue;
43 protected get isSSLEnabled(): boolean;
44 getProviderName(): string;
45 onDisconnect({ clientId, errorCode, ...args }: {
46 clientId?: string;
47 errorCode?: number;
48 }): void;
49 newClient({ url, clientId, }: MqttProviderOptions): Promise<PahoClient>;
50 protected connect(clientId: string, options?: MqttProviderOptions): Promise<PahoClient | undefined>;
51 protected disconnect(clientId: string): Promise<void>;
52 publish(topics: string[] | string, msg: PubSubContent): Promise<void>;
53 protected _topicObservers: Map<string, Set<PubSubContentObserver>>;
54 protected _clientIdObservers: Map<string, Set<PubSubContentObserver>>;
55 private _onMessage;
56 subscribe(topics: string[] | string, options?: MqttProviderOptions): Observable<PubSubContent>;
57}
58export {};