Utilities

SDK-level helpers and read-only state — platform context, platform name, version, capability list.

These are the bits of the SDK that aren’t game→platform RPC. Use them to inspect the runtime (which platform are we on, can we even talk to a host) or to read constants the SDK exposes for typing and validation.

Three top-level imports, two SDK getters. No side effects, no wire traffic — every call here is local and synchronous.

hasPlatformContext#

Top-level import. Synchronous boolean — returns whether the SDK can reach a GAMEE host from the current document. Call it at boot to decide whether to start the SDK handshake or render a “open this game from GAMEE” fallback.

import { hasPlatformContext, createSdk } from '@gamee/sdk';

if (!hasPlatformContext()) {
  showStandaloneNotice();
  return; // do not construct the SDK, do not call init()
}

const sdk = createSdk();
await sdk.init({ capabilities: [/* … */] });

Returns true when any of:

  • the document is inside an iframe (browser embed — docs emulator, platform web)
  • window.webkit.messageHandlers.callbackHandler exists (iOS WKWebView)
  • window._toDevice is a function (Android WebView)

Returns false only when the bundle is opened standalone in a top-level browser with no native host — i.e. the developer or a player loaded the HTML file directly. Never call init() in that case — it has nothing to talk to and will reject with BRIDGE_TIMEOUT after 30 s.

Pure and side-effect-free: it only reads from window. Safe to call before or after createSdk(), as many times as you want — it never touches the SDK or the bridge.

Don’t roll your own. Avoid checking window.parent, window.webkit, or window._toDevice directly. iOS and Android native webviews load games as the top-level document, so any window.parent !== window check will silently fail on real devices.

sdk.platform#

Getter property on the SDK instance. Returns the platform the bridge is talking to:

type Platform = 'web' | 'mobile_web' | 'ios' | 'android';

console.log(gamee.platform); // → 'ios' inside the iOS app, 'web' otherwise

Stable for the lifetime of the SDK instance — pick a bridge once at construction and the value never changes. Use it for diagnostics, asset selection (“load the touch-control sprite on mobile_web”), or analytics context. Do not branch core game logic on it; the platform exposes the canonical signal via initResponse fields like gameContext and environment.

When you inject a custom bridge (createSdk({ bridge: myBridge })), sdk.platform returns bridge.platform. That’s how the emulator and MockBridge (Testing) tell the game what to pretend to be.

sdk.version#

Getter property on the SDK instance. Returns the SDK version string that was sent on the wire with init. Identical to the top-level SDK_VERSION export — the SDK getter exists so games that already have a gamee instance don’t have to do a second import.

console.log(gamee.version); // → "3.0.0"

Useful for diagnostics, bug reports, and analytics (“which SDK version is this game shipping with?”).

SDK_VERSION#

Top-level import. The same version string sdk.version returns, but available before the SDK is constructed:

import { SDK_VERSION } from '@gamee/sdk';
console.log('SDK', SDK_VERSION);

Comes from @gamee/sdk/package.json at build time. Reach for this when you want to log/report the SDK version before calling createSdk() (e.g. in a top-level error boundary).

ALL_CAPABILITIES#

Top-level import. Readonly array of every capability the SDK knows about — useful for tests, dev tools, and TypeScript narrowing.

import { ALL_CAPABILITIES, type Capability } from '@gamee/sdk';
// → ['saveState', 'rewardedAds', 'logEvents', 'missions', 'gems', 'platformExtraLife']

const everyCapability = [...ALL_CAPABILITIES] as Capability[];
await gamee.init({ capabilities: everyCapability });

See Capabilities for what each one unlocks.

At a glance#

SymbolKindReturnsNotes
hasPlatformContext()top-level fnbooleanCall before createSdk(). false = render fallback.
sdk.platforminstance getterPlatformStable for the SDK’s lifetime.
sdk.versioninstance getterstringSame as SDK_VERSION, accessed via the SDK instance.
SDK_VERSIONtop-level constantstringAvailable pre-init.
ALL_CAPABILITIEStop-level constantreadonly Capability[]All capabilities the SDK knows.