# @openrc/react-native-mqtt

> A library for the MQTT protocol

Latest version **3.0.8** (published 2022-05-21) · MIT license · 0 weekly downloads

## Install

```sh
npm install @openrc/react-native-mqtt
pnpm add @openrc/react-native-mqtt
yarn add @openrc/react-native-mqtt
bun add @openrc/react-native-mqtt
```

Provides the commands `mqtt`, `mqtt_pub`, `mqtt_sub`.

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.0.8 |
| Published | 2022-05-21 |
| First published | 2022-04-27 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=10.0.0 |
| Dependencies | 17 |
| Unpacked size | 401.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | openrc |
| Keywords | mqtt, publish/subscribe, publish, subscribe, react, react-native |

## Links

- npm: https://www.npmjs.com/package/@openrc/react-native-mqtt
- Repository: https://gitee.com/open-rc/react-native-mqtt/tree/react-native-mqtt/
- Homepage: https://github.com/mqttjs/MQTT.js
- npm.io page: https://npm.io/package/@openrc/react-native-mqtt

## Dependencies (17)

- [ws](https://npm.io/package/ws.md) ^7.0.0
- [url](https://npm.io/package/url.md) ^0.11.0
- [pump](https://npm.io/package/pump.md) ^3.0.0
- [util](https://npm.io/package/util.md) ^0.12.0
- [xtend](https://npm.io/package/xtend.md) ^4.0.1
- [buffer](https://npm.io/package/buffer.md) ^5.2.1
- [events](https://npm.io/package/events.md) ^3.0.0
- [stream](https://npm.io/package/stream.md) ^0.0.2
- [commist](https://npm.io/package/commist.md) ^1.0.0
- [es6-map](https://npm.io/package/es6-map.md) ^0.1.5
- [help-me](https://npm.io/package/help-me.md) ^1.0.1
- [inherits](https://npm.io/package/inherits.md) ^2.0.3
- [minimist](https://npm.io/package/minimist.md) ^1.2.0
- [reinterval](https://npm.io/package/reinterval.md) ^1.1.0
- [safe-buffer](https://npm.io/package/safe-buffer.md) ^5.1.2
- [concat-stream](https://npm.io/package/concat-stream.md) ^1.6.2
- [end-of-stream](https://npm.io/package/end-of-stream.md) ^1.4.1

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 3.0.8 (latest) — 2022-05-21
- 3.0.7 — 2022-04-27
- 3.0.6 — 2022-04-27
- 3.0.5 — 2022-04-27
- 3.0.4 — 2022-04-27
- 1.3.0 — 2022-04-27
- 1.2.1 — 2022-04-27
- 1.2.0 — 2022-04-27
- 1.0.3 — 2022-04-27
- 1.0.2 — 2022-04-27
- 1.0.1 — 2022-04-27
- 1.0.0 — 2022-04-27

## README

[简体中文](README.cn.md)&nbsp;&nbsp;&nbsp;&nbsp;

A minimalist MQTT library that supports react-native, keeps [MQTT](github.com/mqttjs/MQTT.js) in sync, and supports [Emq](https://github.com/emqx/emqx) and [mosquitto](https://github.com/eclipse/mosquitto)

## Installation

```bash
npm i --save @openrc/react-native-mqtt
yarn add @openrc/react-native-mqtt
```

## Example（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;
```

<a name="api"></a>

## API

- <a href="#connect"><code>mqtt.<b>connect()</b></code></a>
- <a href="#client"><code>mqtt.<b>Client()</b></code></a>
- <a href="#publish"><code>mqtt.Client#<b>publish()</b></code></a>
- <a href="#subscribe"><code>mqtt.Client#<b>subscribe()</b></code></a>
- <a href="#unsubscribe"><code>mqtt.Client#<b>unsubscribe()</b></code></a>
- <a href="#end"><code>mqtt.Client#<b>end()</b></code></a>
- <a href="#removeOutgoingMessage"><code>mqtt.Client#<b>removeOutgoingMessage()</b></code></a>
- <a href="#reconnect"><code>mqtt.Client#<b>reconnect()</b></code></a>
- <a href="#handleMessage"><code>mqtt.Client#<b>handleMessage()</b></code></a>
- <a href="#connected"><code>mqtt.Client#<b>connected</b></code></a>
- <a href="#reconnecting"><code>mqtt.Client#<b>reconnecting</b></code></a>
- <a href="#getLastMessageId"><code>mqtt.Client#<b>getLastMessageId()</b></code></a>
- <a href="#store"><code>mqtt.<b>Store()</b></code></a>
- <a href="#put"><code>mqtt.Store#<b>put()</b></code></a>
- <a href="#del"><code>mqtt.Store#<b>del()</b></code></a>
- <a href="#createStream"><code>mqtt.Store#<b>createStream()</b></code></a>
- <a href="#close"><code>mqtt.Store#<b>close()</b></code></a>

[Learn more](README.more.md)

## License

MIT

---
_Source: https://npm.io/package/@openrc/react-native-mqtt · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
