How sankalppatra/sa-react-native-mqtt works
Project type and purpose
• This is a React Native “native module” library (sa-react-native-mqtt) plus an example React Native app (rnmqttexample) that demonstrates usage.
• Purpose: expose a native MQTT client (iOS via CocoaPods MQTTClient; Android via Java implementation) to React Native JS through the standard Bridge API.
File structure
• Top-level:
• android/ – native‐module implementation for Android (Java code under com.tuanpm.RCTMqtt)
• ios/ – native‐module implementation for iOS (Objective-C wrappers RCTMqtt.* + Podspec file)
• index.js & index.d.ts – JS entrypoint, declare and export createClient API
• rnmqttexample/ – standalone React Native example app demonstrating module usage
• package.json – declares dependency on this module, linking workflows
• Patterns:
• React Native Bridge → Native Module
• Example app structured as typical RN project (android/, ios/, App.js, Metro config)
• CocoaPods under example’s ios/Pods for MQTTClient library
Insights from README
• Exposes a promise-based JS API: createClient, on(event), connect/disconnect, publish/subscribe
• iOS: depends on CocoaPods “MQTTClient”
• Android: Gradle project under android/ folder
• External dependency: any MQTT broker (mqtt://… or mqtts://…)