npm.io
3.0.8 • Published 4 years agoCLI

@openrc/react-native-mqtt

Licence
MIT
Version
3.0.8
Deps
17
Size
401 kB
Vulns
0
Weekly
0

简体中文    

A minimalist MQTT library that supports react-native, keeps MQTT in sync, and supports Emq and mosquitto

Installation

npm i --save @openrc/react-native-mqtt
yarn add @openrc/react-native-mqtt

Example(websocket)

import MQTT from '@openrc/react-native-mqtt';

const client = MQTT.connect('ws://car.openrc.top/mqtt', {
  port: 8083,
  protocol: 'ws',
  username: 'your username',
  password: 'your password',
  reconnectPeriod: 30 * 1000,
  qos: 2,
});

client.on('closed', function () {
  console.log('mqtt event closed');
});

client.on('error', function (msg) {
  console.log('mqtt event error', msg);
});

client.on('connect', function () {
  console.log('connected mqtt');
});

export default client;

API

Learn more

License

MIT

Keywords