UNPKG

react-mqtt-hooks

Version:
42 lines (33 loc) 1.4 kB
import * as react_jsx_runtime from 'react/jsx-runtime'; import { IClientOptions, MqttClient } from 'mqtt'; import { Buffer } from 'node:buffer'; type MqttConnectorProps = { children: React.ReactNode; url: string; options?: IClientOptions; customParser?: (message: Buffer) => any; }; declare function MqttConnector({ children, url, options, customParser }: MqttConnectorProps): react_jsx_runtime.JSX.Element; type MqttClientType = MqttClient | null; declare function useMqttClient(): MqttClientType; declare function useTopic<T = any>(topic: string | null): T | undefined; declare function useTopics(topics: string[]): Record<string, any>; declare class MqttCache { private static instance; private cache; private mqttClient; private customParser; private activeSubscriptions; static getInstance(): MqttCache; setClient(client: MqttClient | null): void; setCustomParser(parser: ((message: Buffer) => any) | undefined): void; private setupMessageListener; private resubscribeToActiveTopics; private notifySubscribers; getData<T>(topic: string): T | undefined; private setData; subscribe(topic: string, callback: Function, subscriberId: string): number; unsubscribe(topic: string, subscriberId: string): boolean; } declare const _cache: MqttCache; export { MqttConnector, _cache, useMqttClient, useTopic, useTopics };