reactReact Native

React Native Functions

Connection Setup

initTerra

Initializes Terra for the given developer ID and optional reference ID.

tsxCopy codeexport function initTerra(devId: String, referenceId?: String): Promise<SuccessMessage>
  • devId: The developer ID used for initialization.

  • referenceId: An optional reference ID.

  • Returns: A Promise<SuccessMessage> indicating whether the initialization was successful.

initConnection

Initializes a connection using the provided authentication token.

tsxCopy codeexport function initConnection(token: String): Promise<SuccessMessage>
  • token: The authentication token generated by your backend.

  • Returns: A Promise<SuccessMessage> indicating whether the connection initialization was successful.

Disconnection

disconnect

Disconnects from the specified connection types.

  • connections: The connection types to disconnect from.

  • Returns: A Promise<SuccessMessage> indicating whether the disconnection was successful.

getUserId

Retrieves the user ID associated with the device.

  • Returns: A Promise<GetUserId> containing the user ID and success status.


Device Scanning

startDeviceScan

Starts a device scan for the specified connection types.

  • connections: The connection types (e.g., BLE, WATCH_OS) for which to scan.

  • useCache: Whether to use cached devices if available (default: false).

  • showWidgetIfCacheNotFound: Whether to show a widget if no cached devices are found (default: false).

  • Returns: A Promise<SuccessMessage> indicating whether the scan was successful.

startDeviceScanWithCallback

Starts a device scan with a callback specific to the platform (iOS or Android).

  • connections: The connection types to scan for.

  • Returns: A Promise<SuccessMessage> indicating whether the scan was successful.

connectDevice

Connects to a specific device by its ID.

  • device: The device to connect to, which includes an ID and name.

  • Returns: A Promise<SuccessMessage> indicating whether the connection was successful.


Data Streaming

startRealtime

Starts real-time data streaming for the specified connections and data types.

  • connections: The connection types from which to stream data.

  • dataTypes: The data types to stream (e.g., heart rate, steps).

  • token: An optional token for authentication (default: null).

  • Returns: A Promise<SuccessMessage> indicating whether real-time data streaming was successfully started.

stopRealtime

Stops real-time data streaming for the specified connections.

  • connections: The connection types to stop streaming from.

  • Returns: A Promise<SuccessMessage> indicating whether the real-time streaming was successfully stopped.


WatchOS Integration

connectWithWatchOS

Establishes a connection with WatchOS.

  • Returns: A Promise<SuccessMessage> indicating whether the connection to WatchOS was successful.


Types

SuccessMessage

Represents a success response from various operations.

  • success: A boolean indicating whether the operation was successful.

  • error: A nullable string containing error details, if any.

GetUserId

Represents the response from retrieving the user ID.

  • success: A boolean indicating whether the user ID was successfully retrieved.

  • userId: The user ID, or null if it was not found.

Update

Represents an update received from a device.

  • ts: The timestamp of the update.

  • val: The value associated with the update (e.g., heart rate).

  • type: The data type (e.g., heart rate, steps).

  • d: An array of values for complex data types (e.g., acceleration).

Device

Represents a device that can be connected to.

  • id: The ID of the device.

  • name: The name of the device.

  • type: The type of the device (e.g., BLE, WatchOS).


Enums

Connections

The Connections enum represents the different connection types available in the Terra SDK.

DataTypes

The DataTypes enum represents the different data types that can be streamed from a device.

Was this helpful?