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