Menu

Game client

Game client

Show the game in your web site and in your iOS and Android apps. Listen for what happens in it.

Web

The same game link works in every app. Only the way messages pass differs. Every message is a JSON text, for example {"type":"player.exit"}. None carries money, a player id or a balance.

Your web siteGame → pagePage → game
Game inside your page: an iframewindow.parent.postMessage(text, page address)iframe.contentWindow.postMessage(text, "https://play.nartifacts.com")
Full page: the browser tabNone. Exit opens exitUrl.None
Web · iframeExample
Game → page:  window.parent.postMessage(text, page address)
Page → game:  iframe.contentWindow.postMessage(text, "https://play.nartifacts.com")

{"type":"player.exit"}

iOS

PartHow
Shows the game inWKWebView
Game → your appA message handler named nartifacts, added with WKUserContentController.add(_:name:)
Your app → gamecallAsyncJavaScript or evaluateJavaScript running nartifactsGame.receive(text)

Android

PartHow
Shows the game inWebView
Game → your appWebViewCompat.addWebMessageListener named nartifacts, allowed only for https://play.nartifacts.com. The game calls nartifacts.postMessage(text).
Your app → gameevaluateJavascript running nartifactsGame.receive(text)

Unity

PartHow
Shows the game inUnity has no web view of its own. Application.OpenURL opens the browser.
Game → your appNone. Exit opens exitUrl, the app’s own link back.
Your app → gameNone

React Native

PartHow
Shows the game inreact-native-webview
Game → your apponMessage. The game calls window.ReactNativeWebView.postMessage(text).
Your app → gameinjectJavaScript running nartifactsGame.receive(text)

Flutter

PartHow
Shows the game inwebview_flutter
Game → your appaddJavaScriptChannel named nartifacts. The game calls nartifacts.postMessage(text).
Your app → gamerunJavaScript running nartifactsGame.receive(text)

Events

These are the client messages between the game and your app.

DirectionMessageWhat it means
Game → appgame.loadedThe game is on screen: either ready to play, or showing its own error with a retry button. Show your own loading screen until then.
Game → appgame.failedThe game can’t be played. reason says why (below).
Game → appbalance.changedThe balance changed. Fetch it again, and show the new one in your header.
Game → appplayer.exitThe player pressed exit. Close the game. We already closed the session as exit.
App → gamebalance.refreshThe player added money while the game stayed open. The game asks for the new balance.

game.failed reasons

reasonMeaningWhat to do
link_usedThe link was already opened.Start a new session.
link_expiredThe link was opened after 2 minutes.Start a new session.
session_closedThe session was closed on purpose (logout, self-exclusion).Go back to the lobby. Do not start again by itself.

What your app must do

CaseWhat your app does
player.exitClose the game. The session is already closed.
Neither game.loaded nor game.failed comes within 15 secondsShow your own error with “Try again”. “Try again” starts a new session.
The player leaves the game another way (back button, a lobby tab)Close the game. Your server calls session.close. Otherwise the session stays active until it closes as idle after 30 minutes.
The web view’s process is killedDo not reload the old link. Your server starts a new session, and the app opens the new link. An open Mines round moves to the new session.
game.failed with link_used or link_expiredYour server starts a new session, and the app opens the new link.
game.failed with session_closedGo back to the lobby.
The app goes to the background during a roundNothing. A spin ends on our server. A Mines round stays open and waits for the player.