0.8.1 • Published 1 year ago

react-native-native-mqtt-fork v0.8.1

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

React Native - Native MQTT

This is an MQTT client library for React Native. It utilizes native MQTT client libraries and exposes them via a unified Javascript interface. There are a few other React Native MQTT libraries, but they did not seem to work as expected, or did not support more advanced TLS configurations.

NOTE: This is currently tested only on React Native 0.60 and above using the automatic linking functionality.

This library uses the following native MQTT client libraries:

It supports most of the features supported by these libraries. Tradeoffs have been made to keep the interface unified, so some features are not exposed if not supported in both libraries.

This fork instead original 100% working with mqtt TLS connection with AWS on Android and IOS!

Getting started

$ npm i --save github:FrozenPyrozen/rn-native-mqtt

-- or --

$ yarn add github:FrozenPyrozen/rn-native-mqtt

Installation

If you are not on React Native 0.60+ and not using auto-linking, you may need to run the usual link command as below:

$ react-native link react-native-native-mqtt

This module has only been tested on 0.60+, so at this point you are a bit on your own, but should be standard stuff.

Additional Installation Steps

There are still some manual tasks that need to be done to wire this package up for both iOS and Android. Please perform the steps below to get everything working.

Android

  • Set your minSdkVersion in the android/build.gradle file to 21 or higher.

iOS

We need to add a bridging header file to your Xcode project because this module was written in Swift.

  • Open your project's ios folder in Xcode.
  • Add a new Swift file to the project. Name it whatever you want. Add a bridging header file when it prompts you to add one automatically.

Now you need to run a pod install for your project.

  • Navigate to the ios folder in your project and run pod install.

Usage

This is a quick example written in Typescript.

import * as Mqtt from 'react-native-native-mqtt';

const client = new Mqtt.Client('[SCHEME]://[URL]:[PORT]');

// Promisifyed connect
await client.connect({
	clientId: 'CLIENT_ID',
	tls: {
          caDer: 'ca certificate in Buffer, in my case Amazon root certificate, which I get from BA endpoint',
          cert: 'cert in Buffer, in my case from BA endpoint',
          key: 'key in Buffer, in my case from BA endpoint',
        },
        enableSsl: true,
});

client.on(Mqtt.Event.Message, (topic: string, message: Buffer) => {
	console.log('Mqtt Message:', topic, message.toString());
});

client.on(Mqtt.Event.Connect, () => {
	console.log('MQTT Connect');
	client.subscribe(['#'], [0]);
});

client.on(Mqtt.Event.Error, (error: string) => {
	console.log('MQTT Error:', error);
});

client.on(Mqtt.Event.Disconnect, (cause: string) => {
	console.log('MQTT Disconnect:', cause);
});
0.8.1

1 year ago

0.8.0

1 year ago

0.7.9

1 year ago

0.7.8

1 year ago

0.7.7

1 year ago

0.7.6

1 year ago

0.7.5

1 year ago

0.7.4

1 year ago

0.7.3

1 year ago

0.7.2

1 year ago

0.7.1

1 year ago

0.7.0

1 year ago

0.6.9

1 year ago

0.6.8

1 year ago

0.6.7

1 year ago

0.6.6

1 year ago

0.6.5

1 year ago

0.6.4

1 year ago

0.6.3

1 year ago

0.6.2

1 year ago

0.6.1

1 year ago

0.6.0

1 year ago

0.5.9

1 year ago

0.5.8

1 year ago

0.5.7

1 year ago

0.5.6

1 year ago

0.5.5

1 year ago

0.5.4

1 year ago

0.5.3

1 year ago

0.5.2

1 year ago

0.5.1

1 year ago

0.5.0

1 year ago

0.4.9

1 year ago

0.4.8

1 year ago

0.4.7

1 year ago

0.4.6

1 year ago

0.4.5

1 year ago

0.4.4

1 year ago

0.4.3

1 year ago

0.4.2

1 year ago

0.4.1

1 year ago

0.4.0

1 year ago

0.3.9

1 year ago

0.3.8

1 year ago

0.3.7

1 year ago

0.3.6

1 year ago

0.3.5

1 year ago

0.3.4

1 year ago

0.3.3

1 year ago

0.3.2

1 year ago

0.3.1

1 year ago

0.3.0

1 year ago

0.2.9

1 year ago

0.2.8

1 year ago

0.2.7

1 year ago

0.2.6

1 year ago

0.2.5

1 year ago

0.2.4

1 year ago

0.2.3

1 year ago

0.2.2

1 year ago

0.2.1

1 year ago

0.2.0

1 year ago

0.1.9

1 year ago

0.1.8

1 year ago

0.1.7

1 year ago

0.1.6

1 year ago

0.1.5

1 year ago

0.1.4

1 year ago

0.1.2

1 year ago

0.1.1

1 year ago

0.1.0

1 year ago

0.0.9

1 year ago

0.0.8

1 year ago

0.0.7

1 year ago

0.0.6

1 year ago

0.0.5

1 year ago

0.0.4

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago