@flayerlabs/gamemode-client
v0.2.0
Published
Browser and mock-room client for Flaunch Game Modes
Downloads
321
Readme
@flayerlabs/gamemode-client
Use the SDK room while building offline or connecting a browser to a live Game Mode gate.
Requirements
Install the package with Node.js 20 or later:
pnpm add @flayerlabs/gamemode-client @flayerlabs/gamemode-specThe package runs in the browser. It has no React dependency.
Build against the offline room
Pass your real rules and config to createMockRoom. This example uses the number game created by
the Game Mode CLI:
import { createMockRoom } from '@flayerlabs/gamemode-client'
import { rules, type Action, type Config } from './game/rules.js'
const config: Config = {
rounds: 3,
ceiling: 10,
points: 500,
roundMs: 10_000,
}
const room = createMockRoom(rules, { config })
const unsubscribe = room.subscribe(({ publicView, playerView }) => {
console.log({ publicView, playerView })
})
await room.send({ guess: 7 } satisfies Action)The mock drives the same rules module as a live gate. It replaces only the network, wallet, chain
and real spending. Call unsubscribe(), then room.dispose() when the game closes.
Join from an embedded game
An embedded game first receives its context and restricted host services from the trusted parent:
import { connectEmbeddedGame, joinRoom } from '@flayerlabs/gamemode-client'
const embedded = await connectEmbeddedGame({
parentOrigin: 'https://flaunch.gg',
})
const room = await joinRoom({
gateUrl: embedded.context.gateUrl,
roundId: embedded.context.roundId,
launch: embedded.context.launch,
host: embedded.host,
platform: embedded.platform,
})Creator code sends game actions and reads room state. It cannot send a wallet transaction or create
Flaunch calldata. The trusted parent uses serveEmbeddedGame to provide the permitted wallet,
market and identity operations to one known iframe.
Call room.dispose() and embedded.dispose() when the iframe closes.
Connect a game with its own server
Use joinEconomy() when your existing server owns gameplay and scoring:
import { connectEmbeddedGame, joinEconomy } from '@flayerlabs/gamemode-client'
const embedded = await connectEmbeddedGame({
parentOrigin: 'https://flaunch.gg',
})
const gameMode = await joinEconomy({
gateUrl: embedded.context.gateUrl,
roundId: embedded.context.roundId,
launch: embedded.context.launch,
host: embedded.host,
platform: embedded.platform,
})
const stop = gameMode.economy.subscribe(renderAllowance)joinEconomy() signs the player into the SDK gate and provides launch and spending capabilities.
It does not send gameplay to your server or let the browser add points. Your game server must
authenticate its players and use the gate's internal award route.
The SDK does not give its gate session token to your game server. Keep your existing player and wallet authentication.
Call stop(), gameMode.dispose() and embedded.dispose() when the iframe closes.
Use room capabilities
Room provides:
subscribefor public and player-specific game viewssendfor proposed game actionsnowfor the server-corrected clocklaunchfor fixed launch detailseconomyfor earned, held, spent and available allowancemarketandidentityfor data supplied by the trusted parentpresenceandsocialfor connected-player counts and cosmetic reactions
EconomyRoom provides the same launch, connection, economy, market, identity, presence and social
capabilities. It leaves out gameplay views and send().
Use replayMarket
to build market presentation without a live chain.
Integrate the trusted parent
Read the trusted platform integration guide
before implementing serveEmbeddedGame, Host or a production joinRoom call.
The quiz example shows a live room with a stand-in wallet.
The generated game source shows the offline room.
