Skip to content

init

init(options): Promise<InitResult>. Call it once, before anything else. A second call returns the same promise. It never rejects: a portal script that fails to load falls back to mock, and result.host says so.

Initialise

import { sdk } from '@filudi/game-sdk';
const result = await sdk.init({ gameId: 'gloop', version: '1.4.0' });
console.log(result.host); // 'filudi' | 'crazygames' | 'poki' | 'playgama' | 'mock'
console.log(result.player.nickname); // 'Guest-Fox'
if (result.features.leaderboard) showBoardButton();

InitOptions

await sdk.init({
gameId: 'gloop', // slug, same as in the console
version: '1.4.0', // bundle version, sent with events
debug: false, // console logging, same as ?filudi_debug=1
crazygames: { leaderboardKey: import.meta.env.VITE_CG_LEADERBOARD_KEY ?? '' },
});

gameId is the slug of the game in the console. On filudi.com the frame is opened for one game; when the handshake names another slug than the one you passed, the SDK logs an error and uses the slug of the frame, because the API would refuse the other one. version is the version string you upload; events carry it, so pass the release version from your build.

The SDK ignores options for a host the game does not run on.

InitResult

const { host, player, locale, features, policy } = await sdk.init({ gameId: 'gloop' });
// features.saves: 'remote' on filudi.com and portals with storage, 'local' elsewhere
// features.leaderboard, features.rewarded, features.interstitial, features.account: booleans
// policy.personalizedAds: false on kids sites or without consent
// policy.ageBand: 'all' | 'kids' | 'teen' | 'adult'

In this order: options.host; ?filudi_host=<name> on the page URL; a portal global or hostname (CrazyGames.SDK or *.crazygames.com; PokiSDK or *.poki.com or *.poki-gdn.com; Playgama’s bridge); the filudi handshake when the SDK runs inside an iframe (skipped on portal domains and at top level); localhost, 127.0.0.1 or any unknown host gives mock.

On mock, two behaviours share the name. With options.mock or ?filudi_host=mock, the ESM build loads the configurable mock. Without them, and always in the IIFE, the SDK runs standalone: ads unavailable, saves in localStorage, no leaderboard.

MockConfig

await sdk.init({
gameId: 'gloop',
mock: { host: 'filudi', ads: 'no-fill', latencyMs: 300, player: { nickname: 'Guest-Fox' } },
});

Async and void methods called while init() is pending wait for it. sdk.player.get(), sdk.ads.available(), sdk.i18n.locale() and sdk.device() throw until it resolves. Every on() works at any time and returns an unsubscribe function. Calling anything before init() was called at all throws.

init() has none: it resolves on every host. When a portal script fails, takes longer than timeoutMs or reports a disabled environment, the result says host: 'mock' and every other module answers as on the mock.