All documentation
Getting Started

Expo and React Native Snippet

A simple Expo / React Native-style snippet showing how a mobile app would connect using a short-lived token.

JavaScript

Overview

Expo and React Native apps should use short-lived client tokens returned by your backend.

Setup

1. Authenticate the user in your own backend 2. Ask your backend for a PulseGrid client token 3. Connect from the app using the token

Code example

Expo and React Native Snippet
const clientToken = "TOKEN_FROM_YOUR_BACKEND";
const projectId = "your-project-id";
const channelSlug = "demo-channel";

const socket = new WebSocket(
  `wss://www.altrancconnect.com/ws/channels/${projectId}/${channelSlug}/?token=${encodeURIComponent(clientToken)}`
);

socket.onopen = () => {
  console.log("Connected");
};

socket.onmessage = (event) => {
  const payload = JSON.parse(event.data);
  console.log(payload);
};

function sendMessage(text) {
  socket.send(JSON.stringify({
    event: "message",
    data: { text },
    meta: { source: "expo_client" },
  }));
}

Notes

Expo or React Native apps should never hold the PulseGrid secret key directly. Use wss:// for production connections to AltraNC Connect.