Provider setup
BetaGamerProvider is the root wrapper for both React and React Native SDKs. It opens the Socket.IO connection, decodes the session token, and makes game state available to all child components via context.
npm install @beta-gamer/react
# React Native:
npm install @beta-gamer/react-native react-native-webviewProps
| Prop | Type | Required | Default | Description |
|---|---|---|---|---|
token | string | Yes | — | JWT session token from POST /v1/sessions. Never hardcode — fetch from your backend. |
serverUrl | string | No | "https://api.beta-gamer.com" | Base URL of the Beta Gamer API server. |
socketPath | string | No | "/socket.io" | Socket.IO path. Only change if self-hosting. |
connectSocket | boolean | No | true | Set false when using native board components (ChessBoard, CheckersBoard, Connect4Board, TictactoeBoard from @beta-gamer/react-native) — they open their own socket and the provider should not create a duplicate. |
theme | object | No | session defaults | Override theme tokens at runtime (see Theming). |
onError | function | No | — | Called with an Error when the socket fails to connect. |
Usage
import { BetaGamerProvider } from '@beta-gamer/react';
// sessionToken comes from your server — never expose your API key to the client
export default function GamePage({ sessionToken }: { sessionToken: string }) {
return (
<BetaGamerProvider
token={sessionToken}
serverUrl="https://api.beta-gamer.com"
onError={(err) => console.error('Socket error:', err)}
>
{/* game components go here */}
</BetaGamerProvider>
);
}💡 The provider connects to the correct Socket.IO namespace automatically based on the game type encoded in the session token. You don't need to specify the namespace manually.
Beta Gamer GaaS API — questions? support@beta-gamer.com