The embed
The Put the games on your page step on Integration shows the embed under Your page, with your game server’s origin, your element’s tag and your first game filled in:- With several game servers, a Game server select above the code chooses the one the code and the Content Security Policy use.
- Before your first game server is deployed, the code shows
https://rgs.your-casino.examplein its place, with the bannerYour game server is not deployed yet, so the code shows rgs.your-casino.example in its place.and Open game server. - Below the code, Content Security Policy, for pages that send one holds the directives for that game server. See Content Security Policy.
- Under it, the step lists the origins your game server serves pages on, with a link to Settings to add another. With no allowed origin, it shows
Add your page's origin to Allowed origins. Your game server refuses pages on any other origin.and Open settings.
A fuller example
This example from these docs adds what the dashboard’s embed leaves out: it reads the tag fromconfig, checks your endpoint’s answer, and shows errors in your page’s own words.
og-game; config.tag holds it, so the script finds the element.
The loader
https://<game server>/element/v1/loader.js is a JavaScript module, built for your casino on each request. It exports two names:
config: your casino’s element settings.config.tagis your element’s tag,config.gamesthe games you turned on,config.themeyour saved theme,config.logoyour logo as a PNG data URL, ornull, andconfig.modethe mode your game server runs,"sandbox"or"live".connect(element, options): connects one element to your game server.
<script type="module"> or with import(), in the browser only. In a framework that renders on the server, import it in code that runs on the client, after the element is in the page.
Your page’s origin must be in Allowed origins, under Players and sessions in Settings, or your game server refuses the loader with 403. If your pages send a Content-Security-Policy, add the directives in Content Security Policy.
The element
The loader adds the Provably fair button to every element and opens the dialog when a player presses it. Write the element with an end tag,
<og-game ...></og-game>: custom elements cannot close themselves.
The token function
connect() calls your token function whenever the element needs a session token, and expects the token’s text back:
- First with
{}, to read the player and currency from the token. - Then with
{ publicKey }, the player’s device key, which your endpoint puts in the token’scnf. A browser that cannot keep a device key never makes this call. - Again shortly before each token expires.
token_timeout, and an answer that is not a token fails with token_invalid; the element tries again with a growing delay. Session tokens shows the endpoint.
Show errors
The element shows no error text on the game itself. YouronError function receives every failure: a connect() call that could not start, and every bet your game server refused, as an Error whose message is the code. The same errors fire as og-error events on the element.
Show the codes your players act on, such as insufficient_funds, bet_limit, bets_disabled and round_active, in your own words, and log the rest. Errors lists every code. Two outcomes are not reported, because the stake comes back on its own: a bet refunded after a key rotation, and an abandoned bet.
When the game is ready
connect() resolves as soon as the element is bound, before the connection opens, to a connection object, or to undefined after it reported a failure to onError. The element fires og-ready once its scene is built. While the connection opens, the element shows Connecting: a BET pressed then goes out once the connection is ready, or is dropped after 4 seconds. The balance shows a placeholder until it is known.
Several games
Place one element per game, and callconnect() for each. Elements of the same player and currency share one connection to your game server.
To switch the game in an element, set its game attribute. The loader loads the new game and connects it again. Build your own picker from config.games:
Single-page apps
Callconnect() once per element, and keep what it returns. Before you remove the element from the page, call the connection’s disconnect(): the loader does not notice a removed element. The page’s connection to your game server closes once no element uses it.
Size
The element lays itself out by its own width, not the window’s: from 701 pixels wide it uses the desktop layout, and below that the compact layout. Set the heights with two tokens:Balance changes
When a player deposits or withdraws in your cashier, post a wallet event from your backend: your game server reads the balance again and updates every open tab. See Balance changes outside the games. In sandbox the game server keeps the test balances itself.Your logo
The games never draw your logo.config.logo holds the logo you uploaded on Appearance, so your page can show it next to the games: