Class: Client
client.Client
Instant Game client. Handles platform specific initialization as well as other generic and useful features like sentry.io and analytics.
Constructors
constructor
• new Client(options?
): Client
Parameters
Name | Type |
---|---|
options |
ClientOptions |
Returns
Properties
ads
• Readonly
ads: AdApi
analytics
• Readonly
analytics: AnalyticsApi
bot
• Readonly
bot: BotApi
context
• Readonly
context: ContextApi
crosspromo
• Readonly
crosspromo: CrossPromoApi
devicePlatform
• Private
devicePlatform: DevicePlatform
iap
• Readonly
iap: IapApi
initCalled
• Private
initCalled: boolean
language
• Private
language: string
leaderboard
• Readonly
leaderboard: LeaderboardApi
loadCalled
• Private
loadCalled: boolean
player
• Readonly
player: PlayerApi
region
• Private
region: null
| string
server
• Readonly
server: ServerApi
share
• Readonly
share: ShareApi
startCalled
• Private
startCalled: boolean
tournament
• Readonly
tournament: TournamentApi
Methods
canCreateShortcut
▸ canCreateShortcut(): Promise
<boolean
>
Returns whether or not the user is eligible to have shortcut creation requested. Will
resolve with false
if unavailable on the platform or on FB if createShortcut
was
already called this session or the user is ineligible for shortcut creation.
Returns
Promise
<boolean
>
createShortcut
▸ createShortcut(): Promise
<boolean
>
Prompts the user to create a shortcut to the game. Eligibility should be checked with
canCreateShortcut. On FB platform this can only be called once per session. Resolves with
true
if the shortcut was created succesfully and with false
if the user cancelled the
operation.
Returns
Promise
<boolean
>
expand
▸ expand(autoForce?
): Promise
<boolean
>
Expands the game to a larger size of the screen, only supported for Zoom. Note that
expanding an already expanded app will have no effect unless you specify autoForce=true
.
Parameters
Name | Type | Description |
---|---|---|
autoForce? |
boolean |
If automatic forced expand should be used, it will force expand if the ratio between window.innerWidth and window.screen.width is less than 80% . |
Returns
Promise
<boolean
>
findDevicePlatform
▸ findDevicePlatform(): Promise
<DevicePlatform
>
Returns
Promise
<DevicePlatform
>
getDevicePlatform
▸ getDevicePlatform(): DevicePlatform
Get the device platform. Note that this is different from the compile target platform.
Compile target platforms include values like FB
and VK
, whereas the device platforms
include values like IOS
and ANDROID
.
Returns
DevicePlatform
getEntryPointData
▸ getEntryPointData(): any
Get the data object associated with the user’s entrypoint. Returns null
if no entrypoint
data is found.
Returns
any
getLocale
▸ getLocale(): Object
Get the users’s language and region settings. The language and region will always be in
lowercase. If the users locale is en_US
for example, this will be split to language en
and region us
.
Returns
Object
Name | Type |
---|---|
language |
string |
region |
null | string |
hapticFeedback
▸ hapticFeedback(): Promise
<boolean
>
Requests and performs haptic feedback on supported devices.
Returns
Promise
<boolean
>
true if haptic feedback requested successfully, false if not
init
▸ init(options?
): Promise
<void
>
Initialize the client. This will handle the platform specific initialization. After this it should be safe to use any of the provided APIs.
Parameters
Name | Type |
---|---|
options |
ClientInitOptions |
Returns
Promise
<void
>
initContext
▸ initContext(): Promise
<void
>
Initializes the context, use this method if you need to refresh the context data after entering a sub group for instance.
Returns
Promise
<void
>
load
▸ load(loadCallback
): Promise
<void
>
Load client resources. The actual resource loading should be done in the passed load
callback which in turn should call the provided onProgress
callback.
Parameters
Name | Type | Description |
---|---|---|
loadCallback |
LoadCallback |
Callback to handle the actual loading |
Returns
Promise
<void
>
log
▸ log(event
, parameters?
): void
Parameters
Name | Type |
---|---|
event |
string |
parameters? |
Object |
Returns
void
onPause
▸ onPause(callback
): void
Register a callback to be called when the game needs to be paused, ie. when the user task switches to another app.
Parameters
Name | Type | Description |
---|---|---|
callback |
() => void |
The callback to call |
Returns
void
postSessionScore
▸ postSessionScore(score
): Promise
<void
>
Post a session highscore to the platform. The score should be an integer number. This is only relevant to some platforms like Facebook. On platforms that do not support it the call will simply be ignored.
Parameters
Name | Type | Description |
---|---|---|
score |
number |
The session score |
Returns
Promise
<void
>
quit
▸ quit(): void
Quit the game and close the app.
Returns
void
start
▸ start(startCallback
): Promise
<void
>
Start the client. The callback should handle the initialization of the main update/render loop and render the first frame. Once the callback completes the platform specific splash screen is removed.
Parameters
Name | Type | Description |
---|---|---|
startCallback |
StartCallback |
Callback to handle the client start |
Returns
Promise
<void
>