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
mqtt.connect()
mqtt.Client()
mqtt.Client#publish()
mqtt.Client#subscribe()
mqtt.Client#unsubscribe()
mqtt.Client#end()
mqtt.Client#removeOutgoingMessage()
mqtt.Client#reconnect()
mqtt.Client#handleMessage()
mqtt.Client#connected
mqtt.Client#reconnecting
mqtt.Client#getLastMessageId()
mqtt.Store()
mqtt.Store#put()
mqtt.Store#del()
mqtt.Store#createStream()
mqtt.Store#close()
License
MIT