Front End
Integration
To get the game up and running you will need to insert this snippet on the page where you want the game platform to be loaded:
class="scout-games-wrapper">
<view-port></view-port>
</div>
<script
src="https://customer-scripts.assets.scoutgg-stg.net/customer-client/application.js"
data-white-label="customer"
data-environment="staging"
>
</script>
<div
class="scout-games-wrapper">
<view-port></view-port>
</div>
<script
src="https://customer-scripts.assets.scoutgg.net/customer-client/application.js"
data-white-label="customer"
data-environment="production"
>
</script>
<div
data-lang="ua"
.
Configuration options
Config Parameter | Data parameter(script tag) | Options | Default | Comment |
---|---|---|---|---|
environment | data-environment | staging, production | production | Which environment to load |
currency | data-currency | Any ISO 4217 supported code | EUR | |
whiteLabel | data-white-label | customer | none | Is required. Will be provided to you by your key account manager. |
token | data-token | none | none | Token should be generated when a user is logged in and passed to this parameter. If a token is present the platform will assume a user is logged in. |
basePath | data-base-path | none | / | Should be the base path to the game. For instance /sports/fantasy/. Base path should always have a trailing slash. |
root | data-root | Any URL | https://fantasy-game.api.scoutgg-stg.net | URL to game server. |
ws | data-ws | Any URL | https://fantasy-game.ws.scoutgg-stg.net | URL to web socket server. |
assetHost | data-asset-host | Any URL | https://fantasy.assets.scoutgg.net | URL to assets(icons etc). |
lang | data-lang |
|
en - English |
Scout Widgets API
The Widgets API is a way to change configuration parameters after the script has bootstrapped. After boostrapping window.ftWidgets
will be available. ftWidgets contains a few helper functions, including the config scheme.
// Accessible in the browser after Scout Gaming
// platform has bootstraped
{
"page": Function, // Access to the Scout UI Router
"renderSite": Function, // Trigger a repaint of all visible components
"config": Object, // Access all configuration parameters
"models": Object // Access to all models used
}
You can change the configuration options on the fly. Example:
// Guard the API (check that its bootstrapped)
if(window.ftWidgets) {
window.ftWidgets.config.lang = 'ru'
window.ftWidgets.renderSite() // Re-render elements
}
Authentication
Authentication is done by passing a JWT Token to the token config parameter. A secret to sign the JWT token will be provided to you by your key account manager. For more information on JWT you can see jwt.io. Generating the token must happen server side to not expose the secret in the frontend. The token should include the following payload:
id: String, // The unique identifier of your user
username: String, // A username that is displayed in the game
exp: Number, // Expiry of the token. Unix timestamp (seconds).
iat: Number, // Issued at. Timestamp of when the token was generated.
}
{
Node.js Express example of generating token.
const jwt = require('jsonwebtoken')
const moment = require('moment')
const config = require('../config')
const db = require('../services/database-connection')
module.exports = async function getToken(req, res, next) {
const user = await db.query(`SELECT * FROM users WHERE id = ${req.user.id}`)
const payload = {
id: user.id,
username: user.username,
exp: +moment().add(1, 'hour').format('X'), // Unix timestamp
iat: +moment().format('X'), // Unix timestamp
}
const token = jwt.sign(payload, config.secret)
res.send(token)
}