Home react-native-awesome-mqtt
Post
Cancel

react-native-awesome-mqtt

react-native-awesome-mqtt

MQTT Client for React Native

The story

This is a port of repo sp-react-native-mqtt for Typescript.

I rewrite the original repo into Typescript, with some adjustments to be compatible with my project.

Thank to the author and his work.

Installation

1
yarn add react-native-awesome-mqtt rxjs

Usage

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import AwesomeMqtt from "react-native-awesome-mqtt";
import type {Subscription} from 'rxjs';

AwesomeMqtt.createClient({
  uri: 'tcp://localhost:1883',
  username: 'user',
  password: 'pass',
  tls: false,
  clientId: 'react-native-awesome-mqtt',
})
  .then((client: AwesomeMqtt) => {
    client.on('connect', (event: AwesomeMqtt.NativeEvent) => {
      const subscription: Subscription = client.message.subscribe((message: AwesomeMqtt.NativeEvent) => {

      });
    });
    client.on('error', (event: AwesomeMqtt.NativeEvent) => {

    });
    client.on('closed', (event: AwesomeMqtt.NativeEvent) => {

    });
  });

License

MIT

This post is licensed under CC BY 4.0 by the author.