Aller au contenu
InstaPlay
Sections de la documentation du SDK

InstaPlay SDK

The InstaPlay SDK connects a game to the portal: a guest player gets cloud saves and a place on the leaderboards, the portal shows a loading screen with real progress and pauses the game when the tab is hidden. The SDK is under 15 KB gzipped, has no dependencies and also works outside the portal.

Setup

The script is served from the game's own origin — the path is the same on the portal, in the emulator and on the check stand:

<script src="/_ip/sdk/v1.js"></script>

Or use the npm package @instaplay/sdk (ESM, same code and types). TypeScript types without npm are at the stable address /_ip/sdk/v1.d.ts on the same origin. See Quick start.

What SDK v1 does

Section Methods
Lifecycle init, loading.progress, ready, gameplay.start, gameplay.stop, game.happyMoment, level.*
Player player.get — a guest or an account with a pseudonym and a nickname; player.getToken — a player token for your own server (1.1); player.login — the portal sign-in window from the game (1.4)
Saves saves.get, saves.getMany, saves.set, saves.remove, saves.clear, saves.onConflict, saves.flush
Leaderboards leaderboard.submit, leaderboard.get
Analytics analytics.event, analytics.flush
Ads ads.interstitial, ads.rewarded — with a signed reward for your server, ads.available (1.3)
Portal events on('pause'), resume, mute, unmute, visibility, localeChanged, playerChanging (1.1)

Also: local mode and emulator, errors and limits, game template, publishing to the portal, changelog.

Ads are shown by the portal; the game only asks for them in a pause or on the player's button press (ads). SDK v1 has no purchases yet: isSupported('shop') returns false; preliminary shapes — shop.purchase() and more — are a draft: upcoming features.

Principles

  • The game is isolated: the SDK talks to the portal only via postMessage with the exact portal origin. The game never sees cookies, tokens or the real player id — only a pseudonym.
  • Every call with a reply is a promise with a timeout (10 s; init — 5 s) and a clear error code.
  • If the portal does not answer, the game does not hang: init resolves with environment: 'disabled' and calls work as stubs.