React Native
Streaming to Terra's Server
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);
};Endpoint for generation of a token for a user (producer) connection
Authorizations
x-api-keystringRequired
dev-idstringRequired
Query parameters
idstringOptional
The ID of the user to generate a token for
Header parameters
dev-idstringRequired
your developer ID
x-api-keystringRequired
your API key
Responses
200
Successful response
application/json
tokenstringOptionalExample:
OTYwNWFi5ZWQMTAxMjg0Y2Qw.gzrPzZcS3Gy8QDOxbiPRwu30PTB3VxW0eE403
Forbidden
text/plain
post
/auth/userLast updated
Was this helpful?