Terra Docs
Dashboard
  • Docs
  • API Reference
  • Changelog
  • Health & Fitness API
    • REST API Endpoints
    • Supported integrations
    • Event Types
    • Data models
    • Samples
    • Core concepts
    • Destinations
    • Mobile SDK
      • iOS (Swift)
      • Android (Kotlin)
      • React Native
      • Flutter
  • Streaming API
    • REST API Endpoints
    • Supported Integrations
    • Core Concepts
    • Websocket Reference
    • Mobile SDK
      • iOS (Swift)
      • Android (Kotlin)
      • Flutter
      • React Native
  • Teams API - Beta
    • Supported Integrations
    • Core Concepts
    • API Endpoints
    • Event types
Powered by GitBook
On this page
  • React Native Functions
  • Connection Setup
  • Device Scanning
  • Data Streaming
  • WatchOS Integration
  • Types

Was this helpful?

  1. Streaming API
  2. Mobile SDK

React 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.

tsxCopy codeexport function disconnect(connections: Connections): Promise<SuccessMessage>
  • 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.

tsxCopy codeexport function getUserId(): Promise<GetUserId>
  • Returns: A Promise<GetUserId> containing the user ID and success status.


Device Scanning

startDeviceScan

Starts a device scan for the specified connection types.

tsxCopy codeexport function startDeviceScan(
  connections: Connections,
  useCache: Boolean = false,
  showWidgetIfCacheNotFound: Boolean = false
): Promise<SuccessMessage>
  • 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).

tsxCopy codeexport function startDeviceScanWithCallback(connections: Connections): Promise<SuccessMessage>
  • 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.

tsxCopy codeexport function connectDevice(device: Device): Promise<SuccessMessage>
  • 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.

tsxCopy codeexport function startRealtime(
  connections: Connections,
  dataTypes: Array<DataTypes>,
  token: String | null = null
): Promise<SuccessMessage>
  • 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.

tsxCopy codeexport function stopRealtime(connections: Connections): Promise<SuccessMessage>
  • 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.

tsxCopy codeexport function connectWithWatchOS(): Promise<SuccessMessage>
  • Returns: A Promise<SuccessMessage> indicating whether the connection to WatchOS was successful.


Types

SuccessMessage

Represents a success response from various operations.

tsxCopy codeexport type SuccessMessage = {
  success: Boolean;
  error: String | null;
};
  • 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.

tsxCopy codeexport type GetUserId = {
  success: Boolean;
  userId: String | null;
};
  • 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.

tsxCopy codeexport type Update = {
  ts: String | null;
  val: number | null;
  type: String | null;
  d: Array<number> | null;
};
  • 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.

tsxCopy codeexport type Device = {
  id: String | null;
  name: String | null;
  type: String;
};
  • 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.

tsxCopy codeexport enum Connections {
  ANT = 'ANT',
  BLE = 'BLE',
  WEAR_OS = 'WEAR_OS',
  WATCH_OS = 'WATCH_OS',
  ANDROID = 'ANDROID',
  ALL_DEVICES = 'ALL_DEVICES',
  APPLE = 'APPLE',
}

DataTypes

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

tsxCopy codeexport enum DataTypes {
  HEART_RATE = 'HEART_RATE',
  ECG = 'ECG',
  STEPS = 'STEPS',
  HRV = 'HRV',
  CALORIES = 'CALORIES',
  LOCATION = 'LOCATION',
  DISTANCE = 'DISTANCE',
  ACTIVITY = 'ACTIVITY',
  ACCELERATION = 'ACCELERATION',
  GYROSCOPE = 'GYROSCOPE',
  FLOORS_CLIMBED = 'FLOORS_CLIMBED',
  STEPS_CADENCE = 'STEPS_CADENCE',
  SPEED = 'SPEED',
  POWER = 'POWER',
  BIKE_CADENCE = 'BIKE_CADENCE',
  MET = 'MET',
  RR_INTERVAL = 'RR_INTERVAL',
}

PreviousFlutterNextSupported Integrations

Was this helpful?