0.2.5 • Published 12 months ago

mojo-plugin-mqtt-helper v0.2.5

Weekly downloads
-
License
MIT
Repository
github
Last release
12 months ago

npm.io npm.io npm.io Coverage Status npm

A mojo.js plugin to add an MQTT helper, wrapped over async-mqtt module.

API

The API is the same as async-mqtt client.

Example

import mojo from '@mojojs/core';
import mqttPlugin from 'mojo-plugin-mqtt-helper';

const app = mojo();
app.plugin(mqttPlugin);

app.get('/', async ctx => {
  const client = await ctx.mqttClient('mqtt://test.mosquitto.org');
  client.on('message', async (topic, message) => {
    await ctx.render({text: `Received message on topic ${topic}: ${message}`});
    await client.end();
  });
  await client.subscribe('mojojs/test/#');
  await client.publish('mojojs/test/hello/Channel', 'Hello world!');
});
app.start();

More examples

This distribution also contains an example implementing a simple websockets based chat room: chat.

Installation

All you need is Node.js 16.0.0 (or newer).

$ npm install mojo-plugin-mqtt-helper
0.2.5

12 months ago

0.2.4

2 years ago

0.2.3

2 years ago

0.2.2

2 years ago

0.2.1

2 years ago

0.2.0

2 years ago

0.1.0

2 years ago