react-native-mqtt-v3
TypeScript icon, indicating that this package has built-in type declarations

0.3.0 • Public • Published

react-native-mqtt-v3

Native MQTT v3.1.1 for React Native

This is an MQTT v3.1.1 client library for React Native. It utilizes native MQTT client libraries and exposes them via a unified Javascript interface.

This library uses the following native MQTT client libraries:

Installation

npm install react-native-mqtt-v3

or

yarn add react-native-mqtt-v3

Usage

import { createMqttClient } from 'react-native-mqtt-v3';

// ...

const mqttClient = await createMqttClient({
  clientId: 'rnmqttv31883',
  host: 'test.mosquitto.org',
  port: 1883,
});

await mqttClient.connect();
await mqttClient.subscribe('cnhongwei/#');
await mqttClient.publish(
  'cnhongwei/test',
  new Buffer('Hello ' + new Date().toISOString()).toString(
    'base64'
  )
);
await  mqttClient.unsubscribe('cnhongwei/#');
await mqttClient.disconnect();
await mqttClient.close();

// ...

mqttClient.onDisconnect((message) => {})
mqttClient.onMessage(({ topic, base64Message }) => {});

License

MIT


Made with create-react-native-library

Dependencies (0)

    Dev Dependencies (21)

    Package Sidebar

    Install

    npm i react-native-mqtt-v3

    Weekly Downloads

    4

    Version

    0.3.0

    License

    MIT

    Unpacked Size

    260 kB

    Total Files

    39

    Last publish

    Collaborators

    • cnhongwei