# React Native

Once you've started receiving data from a [device](/reference/streaming-api/core-concepts.md#device) into your app, you can start sending this data to Terra's websocket server.

{% hint style="info" %}

#### Prerequisite

Before following the steps below, make sure you've followed the guide to [stream data from a wearable device to your app](/streaming-api/connect-wearable-to-sdk/react-native.md)
{% endhint %}

## Streaming to Terra's Server

You'll have previously set up a local stream using `startRealtime` without a token. To also send data to Terra's server, pass a **streaming token** as the third argument:

```tsx
import { getUserId, startRealtime, Connections, DataTypes } from 'react-native-terra-rt-react';

const startServerStreaming = async () => {
  // 1. Get the Terra user ID
  const { userId } = await getUserId();
  if (!userId) return;

  // 2. Get a streaming token from your backend
  const tokenResponse = await fetch('YOUR_BACKEND_URL/streaming-token', {
    method: 'POST',
    body: JSON.stringify({ userId }),
  });
  const { token } = await tokenResponse.json();

  // 3. Start streaming with the token — data goes to BOTH your app and Terra's server
  const dataTypes = [DataTypes.HEART_RATE, DataTypes.STEPS];
  await startRealtime(Connections.BLE, dataTypes, token);
};
```

The `token` parameter is the only difference from local-only streaming. When provided, the SDK opens a websocket connection to Terra and relays data in real time.

Listen for websocket connection status via the `ConnectionUpdate` event:

```tsx
import { NativeEventEmitter, NativeModules } from 'react-native';

const connectionEmitter = new NativeEventEmitter(NativeModules.ConnectionHandler);
connectionEmitter.addListener('ConnectionUpdate', (connected: boolean) => {
  console.log('Websocket connected:', connected);
});
```

Your backend should generate the streaming token by calling:

{% openapi src="<https://raw.githubusercontent.com/tryterra/openapi/refs/heads/master/rt.yml>" path="/auth/user" method="post" %}
<https://raw.githubusercontent.com/tryterra/openapi/refs/heads/master/rt.yml>
{% endopenapi %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.tryterra.co/streaming-api/your-app-greater-than-terra/react-native.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
