How to use aws-iot-device-sdk with react-native
Asked Answered
P

1

6

I have tested aws-iot-device-sdk as shown on the image below. On my console I get topics from aws IoT. aws-iot-device-sdk

My question is when I try to integrate it into my react native application. below is my package.json for my react-native application enter image description here

When i reference the aws-iot-device-sdk and configure the setting in my react-native application I get error associated with the aws-iot-device-ssdk. Is this sdk compatible with react native? If so how do I configure the setting to push notification to my react native from an Aws IoT device?

Pignut answered 21/4, 2017 at 8:27 Comment(4)
have you had any luck with this?Forevermore
Any updates on working with react native and aws-iot-device-sdk?Pasturage
github.com/aws/aws-iot-device-sdk-js/issues/86Showthrough
2021 now, any updates?Hinze
Y
2

To use aws-iot-device-sdk in React-Native, you need to follow Viotti's suggestion above (https://github.com/aws/aws-iot-device-sdk-js/issues/86#issuecomment-371159865) but with some new additions including adding 'url' and 'events' to the nodeify step. The problem we all face is that React-Native uses JavaScriptCore which is not the same as NodeJS and it is not the same as any specific browser JS engine either, though it is used in Safari. In order to use aws-sdk and aws-iot-device-sdk you need to include libraries that replace several important NodeJS libraries. rn-nodeify is an NPM package that makes this somewhat easy to do. The key step in the walk through on GitHub is here: npx rn-nodeify --install "fs,util,path,tls,stream,buffer,global,process,events,url" --hack

This will install libraries that replace what is missing when not in nodejs, and create a shim.js file that you need to copy to your project's files and import. Within that Shim file you'll need to also make further modifications. buffer should already be installed, but the require or import statement must read `import { Buffer } from 'buffer/'; with the trailing slash, to separate it from the nodejs version for confused transpilers.

Other libraries I have needed for this include react-native-crypto, which can be used to replace NodeJS's crypto. Edit rn-nodeify's shim file to allow crypto. In order to make use of WSS on AWS in React-Native I've also used react-native-wss which helps handle certs in WSS.

Yi answered 12/11, 2021 at 0:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.