Bash.tv → GitHub → itch.io

Platform Adapter

One set of calls (gameplay start and stop, ads, sharing, the player’s name, saving) that works on Bash.tv, itch.io, CrazyGames, Poki or a plain website. Game code never touches a portal’s SDK directly, and a missing or failing SDK never breaks the game.

Files: platform-adapter.js (the component, no dependencies) and platform-adapter.test.mjs (7 tests). Copy platform-adapter.js into your game, for example to src/components/, and import it as an ES module.

Usage

import { createPlatform } from "./platform-adapter.js";
const platform = await createPlatform({ hooks: { mute: () => audio.mute("master", true), unmute: () => audio.mute("master", false), pause, resume } });
platform.loadingDone();
platform.gameplayStart();                              // level start, unpause, revive
platform.gameplayStop();                               // menus, level end, pause
await platform.midgameAd();                            // between levels; resolves straight away where there are no ads
if (await platform.rewardedAd()) player.extraLife();   // true only if the player watched it
await platform.share({ text: `I scored ${score}!` });
console.log(platform.name, platform.supports("ads"));

API

Detection: Bash.tv if window.bash exists; CrazyGames if window.CrazyGames.SDK exists; Poki if window.PokiSDK exists; itch.io if the page is on itch.zone or itch.io; else web.

Each portal’s SDK script still has to be added to the page as that portal’s docs say. Check the portal’s current docs before release; their rules change.

Engines

Engine Notes
Vanilla, Phaser, PixiJS, Three.js yes. Call the hooks from your engine’s pause and audio code.

Tests

Node tests with fake SDKs: detection order, gameplay events without repeats, ads with mute and pause hooks, rewarded results, ad errors and missing SDKs, failing SDK calls caught, share fallbacks, users, storage.

Run them with node --test toolkit/components/platform-adapter/ (Node 20 or newer, nothing to install).