Skip to content

Latest commit

 

History

History
204 lines (150 loc) · 5.43 KB

README.md

File metadata and controls

204 lines (150 loc) · 5.43 KB

Animo Logo

React Native Ble DIDComm SDK

Powered by   Animo Logo


Getting started  |  Usage  |  Development  |  Contributing  |  License


Getting Started

First, you need to add the dependency to your project:

TODO: this is not released yet

yarn add react-native-ble-didcomm-sdk

Android

add the following to your android/app/src/main/AndroidManifest.xml

+   <uses-permission android:name="android.permission.INTERNET" />
+   <uses-permission android:name="android.permission.BLUETOOTH"
+                    android:maxSdkVersion="30" />
+   <uses-permission android:name="android.permission.BLUETOOTH_ADMIN"
+                    android:maxSdkVersion="30" />
+   <uses-permission android:name="android.permission.BLUETOOTH_SCAN" />
+   <uses-permission android:name="android.permission.BLUETOOTH_ADVERTISE" />
+   <uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
+   <uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
+   <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
+   <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />

iOS

Run pod install in the ios/ directory

Usage

An example can be found here: example

Make sure the correct permissions are requested on android:

await PermissionsAndroid.requestMultiple([
  "android.permission.ACCESS_FINE_LOCATION",
  "android.permission.BLUETOOTH_CONNECT",
  "android.permission.BLUETOOTH_SCAN",
  "android.permission.BLUETOOTH_ADVERTISE",
  "android.permission.ACCESS_COARSE_LOCATION",
])

Setting up the listeners:

React.useEffect(() => {
  const onDiscoverPeripheralListener = bleDidcommSdkEmitter.addListener(
    "onDiscoverPeripheral",
    console.log
  )

  const onConnectedPeripheralListener = bleDidcommSdkEmitter.addListener(
    "onConnectedPeripheral",
    console.log
  )

  const onReceivedNotificationListener = bleDidcommSdkEmitter.addListener(
    "onReceivedNotification",
    console.log
  )

  const onReceivedWriteWithoutResponseListener = bleDidcommSdkEmitter.addListener(
    "onReceivedWriteWithoutResponse",
    console.log
  )

  return () => {
    onDiscoverPeripheralListener.remove()
    onConnectedPeripheralListener.remove()
    onReceivedNotificationListener.remove()
    onReceivedWriteWithoutResponseListener.remove()
  }
}, [])

Start advertising (peripheral):

import { startPeripheral, advertise } from "react-native-ble-didcomm-sdk"

await startPeripheral()
await advertise()

Start scanning (central):

import { startCentral, scan } from "react-native-ble-didcomm-sdk"

await startCentral()
await scan()

Connect (central):

import { connect } from "react-native-ble-didcomm-sdk"

// peripheralId can be retrieved from the `onDiscoverPeripheralListener`
// as shown above with the listeners

await connect(peripheralId)

Send message (central):

import { write } from "react-native-ble-didcomm-sdk"

await write("Hello World!")

Send indication / message (peripheral):

import { notify } from "react-native-ble-didcomm-sdk"

await notify("Hello World!")

Development

When developing new features, you can use the application inside the example/ folder.

To get started you can run the following commands from the root of the project:

yarn example

yarn example start

yarn example android

pod install --project-directory=example/ios
yarn example ios

Contributing

Is there something you'd like to fix or add? Great, we love community contributions! To get involved, please follow our contribution guidelines.

License

This project is licensed under the Apache 2.0 License.

Credits

The initial work for this library was funded and started by ID Crypt.