SDK Reference

API Documentation

Complete client-side JavaScript API reference for the Boofer SDK (v2.0.0). The SDK operates as a bridge between your HTML5 game and the native Boofer App WebView shell.

Overview

The Boofer SDK is lightweight, has zero dependencies, and doesn't store credentials or perform direct database calls. All operations are dispatched as secure messages to the Android/iOS native layer via postMessage.

To integrate, embed the script relatively in your document (required for final upload):

index.html (Relative)
<script src="boofer-sdk.js"></script>

Alternatively, use the official CDN for rapid prototyping and AI generation:

index.html (CDN)
<script src="https://booferapp.github.io/bgames/assets/sdk/boofer-sdk.js"></script>

Lifecycle & Init

Initialize communication with the parent shell immediately upon game startup.

Boofer.ready(timeoutMs?)

Returns a Promise<boolean> resolving when the native bridge channel is successfully injected. Standard timeout defaults to 6000ms.

await Boofer.ready(5000); // Wait up to 5s

Boofer.initGame(options?)

Starts the session. Resolves with player profiles, active session, and custom game configs from the developer console.

const config = await Boofer.initGame({
  gameId: 'super_runner',
  gameVersion: '1.0.0'
});

console.log("Welcome back,", config.player.displayName);

Player & Sessions

Retrieve rich player profile data, session diagnostics, and secure web tokens.

Boofer.getPlayerInfo(fresh?)

Retrieves the logged-in player profile. If fresh is set to true, it skips client caches and queries the live database.

const player = await Boofer.getPlayerInfo(true);
// { userId, displayName, avatarUrl, level, xp, highScore, badges[] }

Boofer.getSessionInfo()

Returns a synchronous snapshot of the active gaming session stats (playtime duration, current score).

const stats = Boofer.getSessionInfo();
console.log(`Playtime: ${stats.duration / 1000}s`);

Boofer.getSessionToken()

Fetches a signed payload verified with the Xaor Cryptographic Engine on server webhooks for secure server-side integrations.

const { token } = await Boofer.getSessionToken();
// Send token to your own server endpoint for verification

Scores & Overlays

Submit score telemetry and show native application leaderboards and share interfaces.

Boofer.saveScore(score, meta?)

Saves a player's score to the global leaderboards. Non-negative integers only.

await Boofer.saveScore(24800, { combo: 4, character: 'ninja' });

Boofer.gameOver(finalScore, meta?)

Signals the end of a match. Submits the score and opens the native post-match leaderboard display automatically.

await Boofer.gameOver(24800, { reason: 'fallen' });

Boofer.showLeaderboard()

Renders the native full-screen leaderboard interface over the webview page.

Boofer.showLeaderboard();

Boofer.shareScore(score, message?)

Opens the native mobile share sheet, allowing players to share their scores onto Whatsapp, Discord, or Twitter.

await Boofer.shareScore(24800, "I just reached Level 10!");

Telemetry & Haptics

Send custom events and trigger device vibration motor patterns.

Boofer.trackEvent(name, data?)

Publishes custom analytics events for the dashboard graph views.

await Boofer.trackEvent('purchase_attempt', { itemId: 'laser_gun', goldValue: 50 });

Boofer.triggerHaptic(type)

Vibrates the mobile device if supported. Types: 'light' | 'medium' | 'heavy' | 'success' | 'warning' | 'error'.

await Boofer.triggerHaptic('success');

Event Subscriptions

Subscribe to event streams dispatched from the host shell.

Boofer.onAppEvent(event, callback)

Listens to application state occurrences. Events: 'pause' | 'resume' | 'close'.

const unsubscribe = Boofer.onAppEvent('pause', () => {
  pauseGameLoop();
});