# MQTT.js
**Repository Path**: open-rc/react-native-mqtt
## Basic Information
- **Project Name**: MQTT.js
- **Description**: No description available
- **Primary Language**: Unknown
- **License**: MIT
- **Default Branch**: react-native-mqtt
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 1
- **Created**: 2022-04-26
- **Last Updated**: 2024-05-28
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
[English](README.md)
这是一个支持 react-native 的极简 mqtt 协议库, , 与[MQTT](github.com/mqttjs/MQTT.js)保持同步, 支持[Emq](https://github.com/emqx/emqx)和[mosquitto](https://github.com/eclipse/mosquitto)
## 安装
```bash
npm i --save @openrc/react-native-mqtt
yarn add @openrc/react-native-mqtt
```
## 用法(websocket)
```js
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()
[了解更多](README.more.md)
## License
MIT