# mqtt-lite

> use mqtt`s method without wait for connection ready

Latest version **1.1.0** (published 2017-12-08) · ISC license · 0 weekly downloads

## Install

```sh
npm install mqtt-lite
pnpm add mqtt-lite
yarn add mqtt-lite
bun add mqtt-lite
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.0 |
| Published | 2017-12-08 |
| First published | 2017-11-03 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | lin-123 |
| Maintainers | lin-123 |

## Links

- npm: https://www.npmjs.com/package/mqtt-lite
- Repository: https://github.com/lin-123/mqtt-lite
- Homepage: https://github.com/lin-123/mqtt-lite#readme
- Issues: https://github.com/lin-123/mqtt-lite/issues
- npm.io page: https://npm.io/package/mqtt-lite

## Dependencies (1)

- [mqtt](https://npm.io/package/mqtt.md) ^2.13.1

## Recent versions

- 1.1.0 (latest) — 2017-12-08
- 1.0.0 — 2017-11-03

## README

# mqtt-lite

## Introduction
- use mqtt`s method without wait for connection ready. support nodejs and browser.

#### API

- new MqttLite(connection, option)
``` javascript
/**
 * mqtt-lite
 * @param  {string} conn   [mqtt websocket url]
 * @param  {Object} option [mqtt connect opiton see:  https://github.com/mqttjs/MQTT.js#connect]
 * @param  {bool}   option.debug [lite option, if debug is true, mqtt-lite will print log to console]
 */
new MqttLite(connection, option)
```

- subscribe
```javascript
/**
 * @param {Sting} topic
 * @param {Function} msgHandler [callback when this topic revice message]
 */
subscribe(topic, [options], msgHandler)
```

- publish
```javascript
/**
 * @param {String} topic
 * @param {*} payload  [send message that can be number, string, boolean, object]
 */
publish(topic, payload, [options])
```

- error
```javascript
/**
 * @param {Function} msgHandler [callback when mqtt connection revcive error message]
 */
error(msgHandler)
```

- end
```javascript
/**
 * close socket connection
 */
end()
```

#### Usage
```javascript
import MqttLite from 'mqtt-lite'

// debug: true  打印mqtt-lite log
const mqtt = new MqttLite('ws://iot.eclipse.org:80/ws', {debug: true})

mqtt.subscribe('testx', (msg) => {
    console.log('recive message: ', msg)
    mqtt.end()
})

mqtt.publish('testx', 'hello world!')

mqtt.error((e) => {
  console.error(e)
})
```

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