Launching a game and embedding it
After this page you can start a session, show the game on your page, and react to what the game tells your page.
#Start a session
Call POST /v1/sessions from your server, never from the browser, because it needs your secret.
{
"mode": "real",
"player_id": "player-1001",
"game_id": "doink",
"currency": "SC",
"language": "en",
"device": "mobile",
"country": "US",
"us_state": "TX",
"lobby_url": "https://casino.example.com/lobby",
"cashier_url": "https://casino.example.com/cashier",
"operator_session_id": "op-session-77"
}player_idis your own opaque id. Do not send names, emails or other personal data.currencyis one of your configured currency codes. A session uses one currency and cannot switch.us_stateis required whencountryisUS.operator_session_idis optional. Reelbit echoes it on every wallet call for this session.mode: "demo"needs noplayer_idand makes no wallet calls. The player plays with pretend coins.
The answer has a launch_url. It opens once, and expires 60 seconds after it is issued if it is not opened. So create the session when the player taps the game, not in advance.
#Session lifetime
A session ends after 30 minutes without activity, or 24 hours after it started, whichever comes first. An expired session cannot start a round. Wallet calls already owed for it, such as a credit, are still delivered.
#Embed the game
<iframe
src="LAUNCH_URL"
allow="autoplay; fullscreen"
style="border:0;width:100%;height:100%"
title="DOINK!"></iframe>Games are served with a Content-Security-Policy: frame-ancestors header that lists only the origins configured for your operator account. Send support the exact origins (scheme, host and port) of every page that embeds a game, for each environment. A page whose origin is not on the list shows a blank frame.
You can also open the launch_url as a full page on mobile. The game's exit button goes to your lobby_url.
#Page messages
The game and your page talk with window.postMessage. Every message is an object with a type starting reelbit: and version: 1. Amounts are whole numbers in your minor units, with the currency code.
Reelbit sends messages only to the origins configured for your account, and accepts messages only from the page that embeds the game, on one of those origins. Check event.origin on your side too.
Messages from the game:
| Type | When | Fields |
|---|---|---|
reelbit:loaded | The game has loaded. | |
reelbit:ready | The game can be played. | balance, currency |
reelbit:round_started | A round has started. | amount, currency, mode |
reelbit:round_ended | A round has finished. | balance, currency |
reelbit:balance_too_low | The player's balance is too low to play. | |
reelbit:open_cashier | The player chose the cashier from the "balance too low" message. | |
reelbit:exit | The player chose to leave from the "balance too low" message. |
Messages to the game:
| Type | What happens |
|---|---|
reelbit:refresh_balance | The game reloads to show the new balance, for example after a deposit. If a round is in play, it waits until the round ends. |
reelbit:pause | No new round can start until you send reelbit:resume. A round in play finishes. |
reelbit:resume | Play can continue. |
reelbit:stop_autoplay | Autoplay stops: the next round the player did not start themselves is not played, and no money moves. |
const GAMES_ORIGIN = 'https://games.sandbox.reelbit.io';
const frame = document.querySelector('iframe');
window.addEventListener('message', (event) => {
if (event.origin !== GAMES_ORIGIN) return;
const msg = event.data;
if (msg?.type === 'reelbit:round_ended') showBalance(msg.balance, msg.currency);
if (msg?.type === 'reelbit:open_cashier') openCashier();
if (msg?.type === 'reelbit:exit') location.href = '/lobby';
});
// After a deposit:
frame.contentWindow.postMessage({ type: 'reelbit:refresh_balance' }, GAMES_ORIGIN);
Docs