Skip to content

The Bridgefy Software Development Kit (SDK) is a state-of-the-art, plug-and-play package that will let people use your mobile app when they don’t have access to the Internet, by using Bluetooth mesh networks.

License

Notifications You must be signed in to change notification settings

bridgefy/bridgefy-react-native

Repository files navigation

Bridgefy React Native SDK

GitHub last commit GitHub issues

The Bridgefy Software Development Kit (SDK) is a state-of-the-art, plug-and-play package that will let people use your mobile app when they don’t have access to the Internet, by using Bluetooth mesh networks.

Integrate the Bridgefy SDK into your Android and iOS app to reach the 3.5 billion people that don’t always have access to an Internet connection, and watch engagement and revenue grow!

Website. https://bridgefy.me/sdk
Email. [email protected]
witter. https://twitter.com/bridgefy
Facebook. https://www.facebook.com/bridgefy

Operation mode

All the connections are handled seamlessly by the SDK to create a mesh network. The size of this network depends on the number of devices connected and the environment as a variable factor, allowing you to join nodes in the same network or nodes in different networks.

networking

Platform permissions

To utilize this SDK in a React Native application, you'll need to configure permissions for each individual platform (iOS and Android) first. You can read more about each platform's requirements below:

Installation

$ npm i bridgefy-react-native
# --- or ---
$ yarn install bridgefy-react-native

Usage

Initialization

The initialize method initializes the Bridgefy SDK with the given API key and propagation profile. We will configure event listeners later.

import { Bridgefy, BridgefyPropagationProfile } from 'bridgefy-react-native';

const bridgefy = new Bridgefy();

export default function App() {
    React.useEffect(() => {
        bridgefy
            .initialize({
                apiKey: 'your-api-key-here', // UUID - The license key registered on the Bridgefy developer site.
                verboseLogging: false, // The logging priority for SDK operations.
            })
            .catch((error) => {
                console.error(error);
            });
    });
}

Once initialized, you can call start and stop Bridgefy SDK operations as follows:

/**
 * Start Bridgefy SDK operations
 */
bridgefy.start(
  userId, // UUID? (optional) - The ID used to identify the user in the Bridgefy network.If null is passed, the SDK will assign an autogenerated ID.
  propagationProfile, // PropagationProfile (optional, default: PropagationProfile.Standard) - A profile that defines a series of properties and rules for the propagation of messages.
);

/**
 * Stop Bridgefy SDK operations
 */
bridgefy.stop()

Sending data

The following method is used to send data using a transmission mode. This method returns a UUID to identify the message that was sent. You'll need to serialize your data into a string before transmission so React Native can communicate the information to the native platform.

async function sendData() {
  const userId = await bridgefy.currentUserId();
  const lastMessageId = await bridgefy.send(
    'data', // String encoded data to send.
    {
      type: BridgefyTransmissionModeType.broadcast,
      uuid: userId,
    },
  );
}

Responding to SDK events

The SDK can report events to your app through an instance of React's NativeEventEmitter.

The following is an example subscription to a couple of events. Each message will contain information relevant to the event being transmitted.

React.useEffect(() => {
  const subscriptions: EmitterSubscription[] = [];
  const eventEmitter = new NativeEventEmitter(
    NativeModules.BridgefyReactNative
  );
  // When the Bridgefy SDK started successfully.
  subscriptions.push(
    eventEmitter.addListener(BridgefyEvents.bridgefyDidStart, (event) => {
      console.log(`Bridgefy started`, event);
    })
  );
  // When this device received data from another Bridgefy device.
  subscriptions.push(
    eventEmitter.addListener(
      BridgefyEvents.bridgefyDidReceiveData,
      (event) => {
        console.log(`Bridgefy received data`, event);
      }
    )
  );
  return () => {
    for (const sub of subscriptions) {
      sub.remove();
    }
  };
});

To see a full list of events, see the BridgefyEvents enum.

Additional Functionality

The Bridgefy class also provides various functionalities:

  • destroySession(): Destroy current session.
  • updateLicense(): Update license.
  • establishSecureConnection(userId: string): Promise<void>: Establish a secure connection with a specified user.
  • currentUserId(): Promise<string>: Get the current user ID.
  • connectedPeers(): Promise<string[]>: Get a list of connected peers.
  • licenseExpirationDate(): Promise<Date>: Get the license expiration date.
  • isInitialized(): Promise<boolean>: Check if the SDK is initialized.
  • isStarted(): Promise<boolean>: Check if the SDK is started.

Make sure to handle promises and error scenarios appropriately when using these methods.

Bridgefy Propagation Profiles

The BridgefyPropagationProfile enum defines the following propagation profiles available for use:

  • standard: Standard propagation profile.
  • highDensityNetwork: High-density network profile.
  • sparseNetwork: Sparse network profile.
  • longReach: Long-reach profile.
  • shortReach: Short-reach profile.

These profiles can be used when configuring the Bridgefy SDK operations within your React Native application.

Multi-Platform Support

Bridgefy's SDKs are designed to work seamlessly across different platforms, including iOS and Android. This means that users with different devices can communicate with each other as long as they have the Bridgefy-enabled applications installed.

Contact & Support

© 2023 Bridgefy Inc. All rights reserved

About

The Bridgefy Software Development Kit (SDK) is a state-of-the-art, plug-and-play package that will let people use your mobile app when they don’t have access to the Internet, by using Bluetooth mesh networks.

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published