Skip to main content
Every export of @opengamehq/sdk 0.1.0, read from the type declarations the package ships. For worked examples, read Connect the SDK, Add a leaderboard and Add multiplayer.

Pick an entry point

Each entry is its own module. The core leaves out the multiplayer transport, and multiplayer, bridge and global include it.

Handle a failed call

@opengamehq/sdk

The handshake and lifecycle, player identity, events, leaderboards and achievements. Preview sessions withhold profile details, isolate scores and rooms, and exclude events from public analytics. Achievements require a published game session. The injected /_og/sdk.js build exposes this client as OpenGame.og and starts the hosted handshake during script loading. Call init before tracking events and ready when the game is playable. The opengame.js build provides the core for games without a bundler.
Values: og, OpenGameClient
Functions: trustedParent
Types: Achievement, AchievementResult, AchievementUnlock, AvatarRecipe, Capability, DevPlayer, Environment, InitOptions, Leaderboard, LeaderboardPage, Player, Result, ScoreEntry, ScoreMeta, ScoreReceipt
Referenced: Achievements, Client, Listener, Session

og

See Client for its methods and fields.

OpenGameClient

See Client for its methods and fields.

Client

The class behind og and OpenGameClient. The SDK does not export it by name.

achievements

env

capabilities

player property

Current player, sign-in action and subscription. onChange calls the listener immediately, then on player changes, and returns an unsubscribe function. Subscribe while loading to receive identity from the injected handshake.

audio

fullscreen

onPause

Call directly from a click or key handler. The parent displays the destination; the player then chooses Open site or Keep playing in the parent’s own dialog.

leaderboard method

init

Initialize lifecycle listeners and event reporting, reusing any handshake the injected SDK started during loading. Resolves with the available environment, including when hosted services are unavailable. Outside OpenGame hosting, an unanswered handshake uses the local mock. The first call sets the options.

ready

Report that the game is playable, after assets and controls are ready. Starts initialization if needed. Repeated calls have no effect.

track

Record a custom event after calling init. During startup, valid events wait in a bounded queue for the first analytics session. Success means queued locally, not stored by the server. Batches go to the events API with the game’s session; in the local mock, validated events are printed with console.debug at flush.

dispose

trustedParent

A local parent is trusted only by a local game. A published game must never acquire a localhost exception just because a developer uses the same SDK.

Achievement

AchievementResult

AchievementUnlock

AvatarRecipe

look is the head and character the body and clothes, each a recipe string in OpenGame’s stored format. character is present only when look is.

Capability

DevPlayer

dev.player chooses the local mock’s identity, so a game can be checked as a guest, a signed-in player, or an account that has not claimed a handle yet. ?og-dev-player=guest|signed-in|no-handle on the page URL does the same. The signed-in player shares an avatar with a look and a character, as a hosted player who has turned on profile sharing does.

Environment

Current connection state and services available to this game. Check capabilities before using a service; previews can have fewer services.

InitOptions

Options for the first init call. manifest supplies local board and room settings; dev.player selects the local identity. Later calls reuse initialization.

Leaderboard

A board declared in opengame.json. Hosted requests use the current game session; the local mock stores scores in this browser. Preview scores stay in that preview.

LeaderboardPage

Player

The game’s player identity. id is scoped to this game. Profile sharing controls handle, ogNumber and avatar, independently of signedIn. Null fields are valid for guests, withheld profiles and unavailable sessions. Previews withhold profiles.

Result

ScoreEntry

ScoreMeta

What a score may carry beside its value. These keys and types are the policy the API and the SDK check every submission against: another key, or a value of another type, fails with invalid_meta before anything is sent.

ScoreReceipt

Referenced declarations in core

These declarations describe types used by this entry’s public signatures. They are not additional named exports from this entry. Achievements
Listener
Session

@opengamehq/sdk/multiplayer

Rooms by code through the OpenGame broker, with lobby controls, readiness, scheduled phases and connection statistics. Hosted rooms support optional host migration through a game-supplied checkpoint and restore adapter. This entry loads the PeerJS transport.
Values: binaryHeaderBytes, errorCatalogue, Lobby, multiplayer, Multiplayer, Room, RoomError
Functions: mountLobby
Types: AuthorityChange, BinaryPayload, Channel, ErrorEntry, HostOptions, JoinOptions, Json, LobbyOptions, LobbySelection, LobbyState, LobbyTheme, LobbyViewOptions, MigrationAdapter, PeerStats, PhaseOptions, RoomClock, RoomConfiguration, RoomData, RoomEvents, RoomMember, RoomPeer, RoomPhase, RoomReadiness, RoomStats, SendResult, Signalling
Referenced: Achievement, AchievementResult, Achievements, AchievementUnlock, AvatarRecipe, Capability, Client, ClientLobby, ClientRoom, ClientRoomError, DevPlayer, Environment, InitOptions, Leaderboard, LeaderboardPage, Listener, LobbyAllowlist, LobbyConfigurationPolicy, LobbyMember, MultiplayerClient, OpenGameClient, Player, Result, RoomConfig, ScoreEntry, ScoreMeta, ScoreReceipt, Session

binaryHeaderBytes

errorCatalogue

Lobby

See ClientLobby for its methods and fields.

multiplayer

See MultiplayerClient for its methods and fields.

Multiplayer class

See MultiplayerClient for its methods and fields.

Room

See ClientRoom for its methods and fields.

RoomError

See ClientRoomError for its methods and fields.

ClientLobby

The class behind Lobby. The SDK does not export it by name.

ClientRoomError

The class behind RoomError. The SDK does not export it by name.

code

hint

retryable

ClientRoom

The class behind Room. The SDK does not export it by name.

MultiplayerClient

The class behind multiplayer and Multiplayer. The SDK does not export it by name.

invite

The join code from the invite link this player arrived with, or null. Read it after og.init(); it clears once a room is hosted or joined.

createLobby

Headless controls for games that render their own lobby.

lobby method

Optional reference controls. Resolves with the room when its host starts.

host

join

joinInvite

Join the invite this player arrived with. Resolves to null when there is none, so await multiplayer.joinInvite() ?? await multiplayer.host() covers both.

mountLobby

Render the optional reference controls in the game’s chosen container. Replacement interfaces use the same Lobby methods and subscribe to the same state.

AuthorityChange

BinaryPayload

Channel

ErrorEntry

Error code, delivery type, retry advice and recovery text.

HostOptions

relayOnly hides this player’s network address from peers by using relay candidates. Players who choose direct connections can expose their own addresses. Relay connections use more bandwidth and may add latency.

JoinOptions

Json

LobbyOptions

LobbySelection

LobbyState

LobbyTheme

LobbyViewOptions

MigrationAdapter

Opt-in state format owned by the game. Every peer must supply the same schema and a restore function. A failed restore ends the match.

PeerStats

One peer, as this side measures it. rtt is smoothed (RFC 6298), minRtt the best sample, jitter the smoothed deviation, and loss covers the last few heartbeats.

PhaseOptions

RoomClock

Estimated host time: sample count, sync status and uncertainty in milliseconds. After sync, clock corrections are gradual and time never decreases.

RoomConfiguration

RoomData

RoomEvents

RoomMember

RoomPeer

Connection ID; stable member slot across reconnects; reusable zero-based seat for colours and spawn points.

RoomPhase

RoomReadiness

RoomStats

Maximum peer RTT and jitter, aggregate packet loss and relay status.

SendResult

Counts sent and dropped packets. A closed room sends nothing; an absent recipient counts as dropped.

Signalling

Broker status. Existing peer links work during reconnection; joining resumes after recovery.

Referenced declarations in multiplayer

These declarations describe types used by this entry’s public signatures. They are not additional named exports from this entry. LobbyMember
LobbyAllowlist
RoomConfig
LobbyConfigurationPolicy

@opengamehq/sdk/netcode

Helpers for a host-authoritative simulation, covering message tables, input history, quantisation and smoothing.
Values: booleanField
Functions: arrayField, cyclicLerp, defineMessages, extrapolateScalar, lagCompensationMs, nullable, numberField, objectSchema, oneOf, smoothCamera, stringField, symmetricQuantizer, tupleField
Classes: EventLedger, InputHistory, InputQueue
Types: Fields, GameMessage, InputCommand, LedgerEntry, Validator
Referenced: FieldSet, FieldValue, Json, MessageTable

booleanField

arrayField

An array of up to maxLength items, each checked by item.

cyclicLerp

defineMessages

extrapolateScalar

lagCompensationMs

Calculate the rewind window from full RTT, snapshot age, interpolation and jitter. Returns null until RTT and jitter are measured; use no rewind then.

nullable

Accept a value or null. Object schemas require the field and reject extra fields.

numberField

objectSchema

The same exact-key validator can be used by a producer and its host.

oneOf

One of a fixed set of literals: a weapon, an emote, a team.

smoothCamera

Use only for presentation. Apply authoritative positions to simulation immediately, then smooth the camera independently with this function.

stringField

A string of at most maxChars code units, optionally matching pattern in full.

symmetricQuantizer

tupleField

An array of exactly these positions:

EventLedger

InputHistory

InputQueue

Create one queue per player. Discarding the oldest excess inputs bounds latency when a faster client produces more commands than the host uses.

Fields

GameMessage

InputCommand

LedgerEntry

Validator

Referenced declarations in netcode

These declarations describe types used by this entry’s public signatures. They are not additional named exports from this entry. FieldSet
FieldValue
MessageTable

@opengamehq/sdk/avatar

Turns og.player.avatar into a head and an outfit with named parts and colors, for a game that draws the player’s OG with custom art. Draw the player’s OG covers each point of view.
Functions: readAvatar, watchAvatar
Types: Avatar, AvatarColor, AvatarHead, AvatarOutfit
Referenced: AvatarRecipe

readAvatar

Names the parts of og.player.avatar. Returns null when there is no look to draw: a guest, a player who has not turned on “Show my OG in games”, a private preview, or a malformed recipe. Use your game’s default character then.

watchAvatar

Calls listener with the player’s OG now, and again only when the look or the outfit changes: a guest signing in, a player switching accounts, or signing out (null). A session refresh with the same recipe does not call it, so a game can rebuild the model here and not on every onChange. A listener that throws is reported with console.error. Returns the unsubscribe function.

Avatar

The player’s OG. outfit is null when the player shared no outfit or it is in a version this SDK cannot read: draw your default body under their head.

AvatarColor

A color in the recipe. followsHead is true for avatar and match, which take the head’s color, and hex is then the head’s unshaded swatch: OpenGame draws match as the head and avatar darker by garment, with bottoms at roughly half the head’s brightness and shoes close to it, so darken it to match. hex is null for a color this SDK build does not know.

AvatarHead

The head, from look. color is the current id, so an old ink becomes black. hex is the color’s swatch. finish is true for a patterned, metallic, glowing or translucent color such as plaid, gold, neon pink or glass, which the swatch only approximates; mono (“Auto”) is black on a light page and white on a dark one, and its swatch is the black. accessory is null when there is none. identity picks a face set and is male unless the player chose otherwise: do not read it as gender, pronouns or a voice.

AvatarOutfit

The body and clothes, from character. shirt is "none" when the torso is the head’s color. accessories is empty when none are worn.

@opengamehq/sdk/bridge

JSON and byte calls for native engine adapters over the existing SDK client. Exports the shared bridge, its types and the createBridge factory; importing this module does not install the browser global.
Values: bridge
Functions: createBridge
Types: BridgeEvent, BridgeHandler, BridgeOperation, OpenGameBridge
Referenced: Achievement, AchievementResult, Achievements, AchievementUnlock, AuthorityChange, AvatarRecipe, BinaryPayload, Capability, Channel, Client, ClientLobby, ClientRoom, ClientRoomError, DevPlayer, Environment, HostOptions, InitOptions, JoinOptions, Json, Leaderboard, LeaderboardPage, Listener, Lobby, LobbyAllowlist, LobbyConfigurationPolicy, LobbyMember, LobbyOptions, LobbySelection, LobbyState, LobbyTheme, LobbyViewOptions, MigrationAdapter, Multiplayer, MultiplayerClient, OpenGameClient, PeerStats, PhaseOptions, Player, Result, Room, RoomClock, RoomConfig, RoomConfiguration, RoomData, RoomError, RoomEvents, RoomMember, RoomPeer, RoomPhase, RoomReadiness, RoomService, RoomStats, ScoreEntry, ScoreMeta, ScoreReceipt, SendResult, Session, Signalling

bridge

See OpenGameBridge for its methods and fields.

createBridge

BridgeEvent

BridgeHandler

BridgeOperation

Operations accepted by request. Achievement calls use the same published-game session as og.achievements; native adapters receive their results as JSON.

OpenGameBridge

Native callers copy strings and byte views across their FFI. No engine owns a session or a transport: all validation and network work remains in the core.

Referenced declarations in bridge

These declarations describe types used by this entry’s public signatures. They are not additional named exports from this entry. RoomService

@opengamehq/sdk/global

Side-effect entry that installs the complete OpenGame browser global and starts the handshake in hosted frames. Its declarations export the OpenGameGlobal type and declare globalThis.OpenGame and window.OpenGame; there are no named runtime exports. Use the injected client when it is already present. Same-major SDK bundles reuse the installed core.
Types: OpenGameGlobal
Referenced: Achievement, AchievementResult, Achievements, AchievementUnlock, AuthorityChange, AvatarRecipe, BinaryPayload, BridgeHandler, BridgeOperation, Capability, Channel, Client, ClientLobby, ClientRoom, ClientRoomError, DevPlayer, Environment, errorCatalogue, ErrorEntry, HostOptions, InitOptions, JoinOptions, Json, Leaderboard, LeaderboardPage, Listener, Lobby, LobbyAllowlist, LobbyConfigurationPolicy, LobbyMember, LobbyOptions, LobbySelection, LobbyState, LobbyTheme, LobbyViewOptions, MigrationAdapter, mountLobby, multiplayer, Multiplayer, MultiplayerClient, netcode, OpenGameBridge, OpenGameClient, PeerStats, PhaseOptions, Player, Result, Room, RoomClock, RoomConfig, RoomConfiguration, RoomData, RoomError, RoomEvents, RoomMember, RoomPeer, RoomPhase, RoomReadiness, RoomStats, ScoreEntry, ScoreMeta, ScoreReceipt, SendResult, Session, Signalling, trustedParent

OpenGameGlobal

Referenced declarations in global

These declarations describe types used by this entry’s public signatures. They are not additional named exports from this entry. netcode The @opengamehq/sdk/netcode entry, imported whole as a namespace. Its exports are listed in that section above.

Browser global declarations

@opengamehq/sdk/og-platform

Compatibility module for games using js/og-platform.js. Copy dist/og-platform.js into the build to replace that file. It reuses the installed same-major core, including the injected SDK. New code can use its og export or the core package.
Values: og, OG_API, OG_DIRECT_ONLY_NOTICE, OG_ENABLED, OG_PARENT_ORIGINS, OG_RTC
Functions: ogAuthHeaders, ogAwaitSession, ogEvent, ogHostLabel, ogHostPeerId, ogIceServers, ogInviteBase, ogIsActive, ogIsEmbedded, ogIsFullscreen, ogIsHostMuted, ogJoinCode, ogLobbySession, ogLobbyTicket, ogManageMedia, ogOnActivity, ogOnFullscreenChange, ogOnHostMute, ogPageUrl, ogPeerOptions, ogReady, ogSessionToken, ogUrl
Referenced: Achievement, AchievementResult, Achievements, AchievementUnlock, AvatarRecipe, Capability, Client, DevPlayer, Environment, InitOptions, Leaderboard, LeaderboardPage, Listener, Player, Result, ScoreEntry, ScoreMeta, ScoreReceipt, Session

og in og-platform

See Client for its methods and fields.

OG_API

OG_DIRECT_ONLY_NOTICE

OG_ENABLED

OG_PARENT_ORIGINS

Compatibility list of parent origins. The SDK validates trust using the current game origin and the message source.

OG_RTC

ogAuthHeaders

ogAwaitSession

ogEvent

ogHostLabel

ogHostPeerId

ogIceServers

ogInviteBase

Parent page address for invite links. Empty until an embedded game receives the page address.

ogIsActive

ogIsEmbedded

ogIsFullscreen

ogIsHostMuted

ogJoinCode

ogLobbySession

ogLobbyTicket

Legacy PeerJS ticket request. New games use @opengamehq/sdk/multiplayer for verified player identity.

ogManageMedia

ogOnActivity

ogOnFullscreenChange

ogOnHostMute

ogPageUrl

ogPeerOptions

ogReady

ogSessionToken

ogUrl