npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-native-native-mqtt-forkk

v0.0.1

Published

An MQTT client or React Native that actually works with a simple Javascript interface

Downloads

4

Readme

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:

  • iOS - https://github.com/emqx/CocoaMQTT
  • Android - https://github.com/eclipse/paho.mqtt.java

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);
});