UNPKG

sparkplug-client

Version:

A client module for MQTT communication using the Sparkplug specification from Cirrus Link Solutions

93 lines 3.83 kB
/// <reference types="node" /> /** * Copyright (c) 2016-2017 Cirrus Link Solutions * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * Cirrus Link Solutions */ import * as mqtt from 'mqtt'; import type { IClientOptions } from 'mqtt'; import events from 'events'; import type { UPayload } from 'sparkplug-payload/lib/sparkplugbpayload'; export declare type ISparkplugClientOptions = { serverUrl: string; username: string; password: string; groupId: string; edgeNode: string; clientId: string; publishDeath?: boolean; version?: string; keepalive?: number; mqttOptions?: Omit<IClientOptions, 'clientId' | 'clean' | 'keepalive' | 'reschedulePings' | 'connectTimeout' | 'username' | 'password' | 'will'>; }; export declare type PayloadOptions = { algorithm?: 'GZIP' | 'DEFLATE'; /** @default false */ compress?: boolean; }; interface SparkplugClient extends events.EventEmitter { /** MQTT client event */ on(event: 'connect' | 'close' | 'reconnect' | 'offline', listener: () => void): this; /** MQTT client event */ on(event: 'error', listener: (error: Error) => void): this; /** emitted when birth messages are ready to be sent*/ on(event: 'birth', listener: () => void): this; /** emitted when a node command is received */ on(event: 'ncmd', listener: (payload: UPayload) => void): this; /** emitted when a device command is received */ on(event: 'dcmd', listener: (device: string, payload: UPayload) => void): this; /** emitted when a payload is received with a version unsupported by this client */ on(event: 'message', listener: (topic: string, payload: UPayload) => void): this; emit(event: 'connect' | 'close' | 'reconnect' | 'offline' | 'birth'): boolean; emit(event: 'error', error: Error): boolean; emit(event: 'ncmd', payload: UPayload): boolean; emit(event: 'dcmd', device: string, payload: UPayload): boolean; emit(event: 'message', topic: string, payload: UPayload): boolean; } export { UPayload }; declare class SparkplugClient extends events.EventEmitter { private readonly type_int32; private readonly type_boolean; private readonly type_string; private readonly versionB; private serverUrl; private groupId; private edgeNode; private publishDeath; private version; private mqttOptions; private bdSeq; private seq; private client; private connecting; private connected; constructor(config: ISparkplugClientOptions); private incrementSeqNum; private encodePayload; private decodePayload; private addSeqNumber; private getDeathPayload; private publishNDeath; private messageAlert; private compressPayload; private decompressPayload; private maybeCompressPayload; private maybeDecompressPayload; subscribeTopic(topic: string, options?: mqtt.IClientSubscribeOptions, callback?: mqtt.ClientSubscribeCallback): void; unsubscribeTopic(topic: string, options?: any, callback?: mqtt.PacketCallback): void; publishNodeBirth(payload: UPayload, options?: PayloadOptions): void; publishNodeData(payload: UPayload, options?: PayloadOptions): void; publishDeviceData(deviceId: string, payload: UPayload, options?: PayloadOptions): void; publishDeviceBirth(deviceId: string, payload: UPayload, options?: PayloadOptions): void; publishDeviceDeath(deviceId: string, payload: UPayload): void; stop(): void; private init; } export declare function newClient(config: ISparkplugClientOptions): SparkplugClient; //# sourceMappingURL=index.d.ts.map