Integration

How a game runs in your app

Each game is one HTML package with everything inside. Your app opens it in a WebView, tells it where to sit and what currency to show, and listens for its events. Your client panel holds the settings and gives your app an API.

1. Open the game with its placement

The launch URL from the API already carries your panel's settings. You can also set them yourself:

ParameterValuesWhat it does
moderoom, gameVoice room: the game sits in the lower part of the screen. Game: full screen.
safeHeight75%, 633px, or design units such as 968The room-mode height. The game lays its whole UI out inside it.
currencycoins, diamonds, beans, pointsCurrency name and icons everywhere in the game.
sound, music1, 0Starting state of sound effects and music.
balancewhole numberBalance to show at start. Display only; your server stays in charge.
qualitylowLighter rendering for slow phones.

Apps already built for BAISHUN games can keep their logic: game_mode 2 is the voice room, 3 is full screen, safe_height is in the same design units, and walletUpdate() is answered too.

2. Load it in your WebView

Android (Kotlin)

webView.settings.javaScriptEnabled = true
webView.settings.domStorageEnabled = true
webView.settings.mediaPlaybackRequiresUserGesture = false
webView.setBackgroundColor(Color.TRANSPARENT)  // voice room: your UI shows above the game

webView.addJavascriptInterface(object {
    @JavascriptInterface
    fun postMessage(json: String) { /* ready, balance, spinResult, topUpRequest */ }
}, "AVGameHost")

webView.loadUrl(game.launchUrl)  // from GET /api/v1/games

// later, from your app
webView.evaluateJavascript("window.AVGame && AVGame.setBalance(50000)", null)

iOS (Swift)

let config = WKWebViewConfiguration()
config.mediaTypesRequiringUserActionForPlayback = []
config.userContentController.add(handler, name: "avgame")  // events arrive as dictionaries

let webView = WKWebView(frame: .zero, configuration: config)
webView.isOpaque = false
webView.backgroundColor = .clear
webView.load(URLRequest(url: URL(string: launchUrl)!))

webView.evaluateJavaScript("window.AVGame && AVGame.setBalance(50000)")

React Native

<WebView
  ref={web}
  source={{ uri: launchUrl }}
  style={{ backgroundColor: "transparent" }}
  mediaPlaybackRequiresUserAction={false}
  onMessage={e => handle(JSON.parse(e.nativeEvent.data))}
/>

web.current.injectJavaScript("window.AVGame && AVGame.setBalance(50000); true;")

Web

<iframe src="LAUNCH_URL" allow="autoplay" style="border:0;width:100%;height:100%"></iframe>
<script>
  addEventListener("message", e => {
    if (e.data && e.data.source === "avgame") console.log(e.data.type, e.data)
  })
</script>

3. Talk to the game

Your app callsEffect
AVGame.setBalance(n)Shows the balance from your server
AVGame.setCurrency(key)Switches currency name and icons
AVGame.setSound(on)Follows your app's mute switch
AVGame.setMusic(on)Music on or off
AVGame.setMode(m)Moves between room and full screen
AVGame.setSafeHeight(v)Re-lays out when your room UI changes height
AVGame.getState()Balance, bet, level, currency, mode
The game sendsWhen
readyLoaded, with version and currency
balanceThe balance changed
spinResultA round finished: bet, win, balance
topUpRequestThe player tapped + or ran out: open your store
closeThe player closed the game
errorSomething failed

4. Get your games from the API

Your client panel shows your key. GET /api/v1/games lists the games your app has switched on, and GET /api/v1/games/{game_id} returns one. A wrong key answers code 1003; a game you have no licence for answers code 1012.

curl https://games.appverselabs.com/api/v1/games \
  -H "Authorization: Bearer avk_your_key"

{
  "code": 0,
  "msg": "success",
  "app_id": "av_3f9c2a1b7d",
  "data": [
    {
      "game_id": "lucky777",
      "name": "Lucky 777",
      "game_version": "0.8.0",
      "preview_url": "https://games.appverselabs.com/uploads/games/lucky777-cover.webp",
      "download_url": "https://games.appverselabs.com/hosted/…/package.zip",
      "launch_url": "https://games.appverselabs.com/hosted/…/index.html?mode=room&safeHeight=75%25&currency=diamonds&sound=1&music=1",
      "game_mode": [2, 3],
      "default_mode": 2,
      "game_orientation": 1,
      "safe_height": 968,
      "safe_height_percent": 75,
      "currency": "diamonds",
      "sound": true,
      "music": true,
      "enabled": true
    }
  ]
}

Ready to try it in your app?