/
v3.0.11Get access

initSwarmSession

initSwarmSession opens the WebSocket connection to Swarm and establishes the session that every other SDK (subscription/getonce) method depends on. Call it once, at application start — it stores the configuration, opens the socket to socketUrl, sends the request_session command, and reports the result through onSessionSuccess / onSessionError.

Request parameters:

Name
DescriptionTypeValuesDefault
source
The source identifier for the sessionnumber--
language
The language code for the sessionarraySupported Languages-
siteId
The site identifiernumber--
socketUrl
WebSocket URL for the connectionstring--
onSessionError
onSessionError is a required callback for initSwarmSession / useInitSDK. The SDK calls it whenever the session cannot be created or the transport carrying it fails — a duplicate initialization, an unresolvable afec token, or a WebSocket error.function--
onSessionSuccess
onSessionSuccess is a required callback passed to initSwarmSession / useInitSDK. The SDK calls it when Swarm answers the request_session command — the moment the session becomes usable. It receives the raw session payload, whose main use is ip / host; the reCAPTCHA and Turnstile fields in it are stored and acted on by the SDK itself.function--
afec
User Hashstring--
xPoint
Enables XPoint fraud-prevention validation for protected commands e.g. login, register). Runs before the request is sent to the server. Has no effect when isNativeApp is true.object-
└─ clientKey
Client Keystring--
└─ enableXPoint
Flag to enable Xpointbooleantrue / false-
└─ onResolve
Callback argument 'data' is '' when the user is allowed, or the X_POINT sentinel when blocked. Use this callback to apply the result to the pending request in your UI.function--
releaseDate
Consumer application release datestring--
onReconnectError
onReconnectError is an optional callback you pass to initSwarmSession / useInitSDK. It calls, when the SDK's automatic reconnection fails.function--
onReconnectSuccess
onReconnectSuccess is optional method and called after the WebSocket successfully reconnects and a new session is established.function--
reCaptchaPlatform
To handle reCAPTCHA in a native application, we need to inform the backend which platform the session is being opened for. This parameter helps us handle this scenario. You can specify the platform (Android or iOS) for which the session is being opened. If this parameter is not provided, the session opening process will proceed in the standard mode.string"ios" / "android"-
isCashDesk
Opens a cash desk session for betshop cashier clients (cash desk / POS apps). Set it to true only in those apps, never in a player-facing site or app. The SDK then sends is_cashdesk: true in the request_session command; when the flag is omitted or false nothing is sent and the session behaves as before. Why it exists: Swarm blocks an IP address that sends many requests failing reCAPTCHA, and every request_session from a blocked IP is then refused with code 21 (Operation not allowed). Betshop tills share one public IP, so one block would stop the whole shop from selling or paying out. With isCashDesk: true the session is created even if the IP is currently blocked. The trade-off: the session is restricted for its whole lifetime, and Swarm refuses player-account commands in it with code 42 (msg 'Not allowed in cashdesk session', data is the refused command name). The SDK reports this as the not_allowed_in_cashdesk_session error. Refused groups: - Login: login, restore_login, social network login, RFID / NemID / iDIN / MetaMask login, getSocialNetworkFrontUrl and the like. - Registration: registerUser, registerUserBySocialInfo, user verification. - Password: forgot / reset / change / create password and wrong-login-attempt resets. - 2FA and verification codes: two-factor setup and codes, phone and email verification, SMS codes. - Money and account: deposit, withdraw, transfers, wallets, bank accounts, updateUser, self-exclusion and deposit / login limits. Still allowed: cashier commands (betshop_*, terminal_*, cash_desk_deposit, cashdesk_other_expense, cashdesk_other_income, create_bet_from_betshop, get_bet_shops, get_cashdesk_report), data subscriptions (get / unsubscribe) and logout. Sportsbook data and bet placement through betshop_* work as usual.booleantrue / false-

Call example:

initSwarmSession({
  source: 42,
  version: 1,
  language: 'eng',
  siteId: 18749451,
  apiUrl: 'sms-url',
  platform: 'desktop',
  socketUrl: 'wss://eu-swarm-newm.betcoswarm.com',
  onSessionError: (data) => { console.log(data) },
  onSessionSuccess: (data) => { console.log(data) }
})

Response examples:

{
  sid: '05***',
  turnstileEnabled: true
}

Response parameters:

NameDescriptionTypeValues
sid
Assigned Session ID to use for subsequent requestsstring-
turnstileEnabled
Whether Turnstile enabled or notbooleantrue / false
recaptchaEnabled
Is reCAPTCHA validation is active for the current sessionbooleantrue / false
recaptchaActions
The command names that should be validated by captcha before issuingarrayRestriction Actions
turnstileActions
The command names that should be validated by turnstile-cloudflare before issuingarrayRestriction Actions
recaptchaEnterprise
This parameter contains information about the reCAPTCHA configuration. If the configuration for all required platforms is correct, this parameter will be true, otherwise, it will be false.booleantrue / false