Other engines (postMessage)
The SDK is a thin layer over plain postMessage calls between the game’s frame and the screen that embeds it. An
engine that cannot load fabi-play.js (Unity, Godot, others) can speak them directly. The messages always carry
ns: 'fabi-play', so they are not confused with those of other scripts.
What the game sends
Section titled “What the game sends”To window.parent:
window.parent.postMessage({ ns: 'fabi-play', type: 'ready' }, '*')window.parent.postMessage({ ns: 'fabi-play', type: 'score', player: 1, score: 40 }, '*')window.parent.postMessage({ ns: 'fabi-play', type: 'break', reason: 'level' }, '*')window.parent.postMessage({ ns: 'fabi-play', type: 'end', scores: [{ player: 1, score: 120, stars: 3 }] }, '*')type |
Fields | Meaning |
|---|---|---|
ready |
Assets loaded: the screen hides its loader. Within 10 seconds of the page loading | |
score |
player, score |
A player’s score so far, shown by the screen |
break |
reason: 'level' or 'gameover' |
The game stopped by itself: Fabi Play may show an ad (see Pause, breaks and audio). Any other reason is answered at once, with no break |
end |
scores: [{ player, score, stars }], stars 0 to 3 |
The game is over: the screen shows the results and takes over |
stats |
renderFps, and optionally fps, renderer, tier |
Debug, only when init had stats: true (below) |
Anything else is dropped.
What the game receives
Section titled “What the game receives”window.addEventListener('message', (e) => { if (e.source !== window.parent || e.data?.ns !== 'fabi-play') return switch (e.data.type) { case 'init': /* v, ageRange, players, locale, mode, muted, backdrop, view, device, stats */ break case 'backdrop': /* e.data.backdrop: 'video' or 'none'; e.data.view (any backdrop) */ break case 'gesture': /* e.data.player, e.data.gesture: 'jump', 'lane-left', ... */ break case 'frame': /* e.data.t, e.data.players: id, body, hands, shape, lane, avatar */ break case 'pause': case 'resume': break case 'break-start': /* mute and freeze */ break case 'break-done': /* e.data.shown; resume */ break }})type |
Fields |
|---|---|
init |
v (the protocol version, 1), ageRange, players (ids), locale, mode ('tv' or 'solo'), muted, backdrop, view (optional), device (optional), stats (optional) |
backdrop |
backdrop, view (optional): see Mirror mode |
frame |
t (ms), players: one player frame per player seen |
gesture |
t, player, gesture |
pause, resume |
|
break-start |
|
break-done |
shown: whether an ad was shown |
To draw on the children, map a body point p to the screen with the view: (view.x + p.x·view.w, view.y + p.y·view.h) in fractions of the viewport; without a view, the point as it is. See
Mirror mode.
The device hint and stats
Section titled “The device hint and stats”When init has device, it is a hint for your quality settings: device.tier ('high', 'medium' or
'low'), a starting tier, and device.hz, the display’s refresh rate. Either may be missing. Start from it instead
of measuring the device, and still lower your quality if frames are slow (see
The device hint).
When init has stats: true (only the simulator sends it), you may send, about once a second:
window.parent.postMessage({ ns: 'fabi-play', type: 'stats', renderFps: 60, fps: 60, renderer: 'webgl2', tier: 'medium' }, '*')renderFps (how often you drew the players, per second) is required; fps (your frame rate), renderer (a short
lowercase name, up to 16 letters, digits or dashes) and tier are optional. The simulator shows them in its status
line. Don’t send it on a TV.
From Unity, use a small .jslib plugin that listens for these messages and calls SendMessage on a GameObject.