/
v3.0.11Get access

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;
}): void

Options

Passed as the second argument, except for useInitSDK which takes a single config object.

NameTypeRequiredDescription
apiUrlstringYesCMS API host, used by the Casino and Content clients.
version1 | 2YesCMS API version.
platform'desktop' | 'mobile'YesPlatform passed to the Casino client.
socketUrlstringYesSwarm WebSocket endpoint.
siteIdnumberYesPartner site id. Also passed to both CMS clients as partner.
sourcenumberYesSource id assigned to your integration.
languagestringYesSession language code, for example eng.
releaseDatestringYesRelease date sent with the session handshake.
onSessionSuccess(data: RequestSessionMessage) => voidYesFires once the session is established. The payload carries session config.
onSessionError({ message }) => voidYesFires when the session cannot be established.
afecstring | Promise<string>NoDevice fingerprint. A promise is awaited before the handshake.
reCaptchaPlatform'ios' | 'android'NoDeclares 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.
xPointXPointConfigNoXPoint geolocation configuration: clientKey, enableXPoint and onResolve.
onReconnectSuccess() => voidNoFires after the socket reconnects.
onReconnectError({ message }) => voidNoFires when a reconnection attempt fails.

Returns

NameTypeRequiredDescription
void—NoThe 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?