Init session
Opens the Swarm WebSocket session and initializes the Casino and Content CMS clients in a single call. It runs once on mount, so it belongs at your application root, above anything that reads data.
Show as
Import from@softconstruct/betchain-core-client/hooks
Use it whenCall it once at your application root, before any other hook.
Signature
.ts
useInitSDK(params: {
apiUrl: string;
version: 1 | 2;
platform: 'desktop' | 'mobile';
source: number;
siteId: number;
language: string;
releaseDate: string;
socketUrl: string;
afec?: string | Promise<string>;
reCaptchaPlatform?: 'ios' | 'android';
xPoint?: XPointConfig;
onSessionSuccess: (data: RequestSessionMessage) => void;
onSessionError: ({ message }: { message: string }) => void;
onReconnectSuccess?: () => void;
onReconnectError?: ({ message }: { message: string }) => void;
}): voidOptions
Passed as the second argument, except for useInitSDK which takes a single config object.
| Name | Type | Required | Description |
|---|---|---|---|
apiUrl | string | Yes | CMS API host, used by the Casino and Content clients. |
version | 1 | 2 | Yes | CMS API version. |
platform | 'desktop' | 'mobile' | Yes | Platform passed to the Casino client. |
socketUrl | string | Yes | Swarm WebSocket endpoint. |
siteId | number | Yes | Partner site id. Also passed to both CMS clients as partner. |
source | number | Yes | Source id assigned to your integration. |
language | string | Yes | Session language code, for example eng. |
releaseDate | string | Yes | Release date sent with the session handshake. |
onSessionSuccess | (data: RequestSessionMessage) => void | Yes | Fires once the session is established. The payload carries session config. |
onSessionError | ({ message }) => void | Yes | Fires when the session cannot be established. |
afec | string | Promise<string> | No | Device fingerprint. A promise is awaited before the handshake. |
reCaptchaPlatform | 'ios' | 'android' | No | Declares the app as native. The session handshake carries it as captcha_platform, and the SDK stops handling reCAPTCHA, Turnstile and XPoint so the app can verify natively. |
xPoint | XPointConfig | No | XPoint geolocation configuration: clientKey, enableXPoint and onResolve. |
onReconnectSuccess | () => void | No | Fires after the socket reconnects. |
onReconnectError | ({ message }) => void | No | Fires when a reconnection attempt fails. |
Returns
| Name | Type | Required | Description |
|---|---|---|---|
void | — | No | The hook returns nothing. Read the session result from onSessionSuccess or onSessionError. |
Example
.ts
1import {2 useInitSDK3} from '@softconstruct/betchain-core-client/hooks';4 5useInitSDK({6 version: 2,7 source: 42,8 platform: 'desktop',9 siteId: 18749451,10 language: 'eng',11 releaseDate: '2024-01-01',12 apiUrl: 'https://cms-api.your-host.com',13 socketUrl: 'wss://eu-swarm-newm.betcoswarm.com',14 onSessionSuccess: (response) => {15 console.log('Session ready', response.data);16 },17 onSessionError: ({18 message19 }) => {20 console.error('Session failed', message);21 }22});Notes
Runs once, on mountThe hook is wrapped in a mount effect, so later prop changes are ignored. Mount it in a component that stays alive for the life of the app.
One call, three clientsInternally it calls initSwarmSession, initCMSContent and initCMSCasino, so you do not need to initialize the surfaces separately.
Was this page helpful?