link-game-sdk
Classes
- ConnectedPlayer
- ContextPlayer
- InterstitialAdInstance
- Leaderboard
- LeaderboardEntry
- LeaderboardPlayer
- RewardedVideoInstance
- SignedPlayerInfo
Interfaces
- AdUnit
- ContextChoosePayload
- ContextCreatePayload
- InitializationOptions
- Product
- Purchase
- PurchaseConfig
- SharePayload
LinkGame Functions
- getAdUnitsAsync
- getEntryPointAsync
- getEntryPointData
- getInterstitialAdAsync
- getLeaderboardAsync
- getLocale
- getPlatform
- getRewardedVideoAsync
- getTrafficSource
- initializeAsync
- onPause
- openDeeplinkAsync
- openUrlAsync
- setLoadingProgress
- shareAsync
- startGameAsync
- updateAsync
LinkGame.context Functions
LinkGame.payments Functions
LinkGame.player Functions
- flushDataAsync
- getConnectedPlayersAsync
- getDataAsync
- getID
- getName
- getPhoto
- getSignedPlayerInfoAsync
- hasPlayed
- setDataAsync
Type Aliases
GetAdUnitsResponse
Ƭ GetAdUnitsResponse: AdUnit
[]
Defined in
Platform
Ƭ Platform: "IOS"
| "ANDROID"
| "DESKTOP"
The underlying platform where Link app is running on.
Defined in
Signature
Ƭ Signature: string
A signature that can be verified on game's backend server. Server side validation can be done by following these steps:
- Split the signature into two parts delimited by the
.
character. - Decode the first part with base64url encoding, which should be a hash.
- Decode the second part with base64url encoding, which should be a string representation of an JSON object.
- Hash the second part string using HMAC SHA-256 and the app secret, check if it is identical to the hash from step 2.
- Optionally, developer can also validate the timestamp to see if the request is made recently.
Defined in
Variables
LinkGame
• Const
LinkGame: __module
= _LinkGame
Stands for the namespace containing all APIs of the Link Game SDK.
Defined in
context
• Const
context: __module
= _context
LinkGame.context
namespace contains context related APIs
Defined in
payments
• Const
payments: __module
= _payments
LinkGame.payments
namespace contains payment related APIs
Defined in
player
• Const
player: __module
= _player
LinkGame.player
namespace contains player related APIs
Defined in
LinkGame Functions
getAdUnitsAsync
▸ getAdUnitsAsync(): Promise
<AdUnit
[]>
Get a list of available ad units in current game
Experimental support: please note that this API is subject to breaking change.
Example
LinkGame.getAdUnitsAsync().then((adUnits) => {
console.log(adUnits)
});
Returns
Promise
<AdUnit
[]>
Defined in
getEntryPointAsync
▸ getEntryPointAsync(): Promise
<string
>
Get information about where the game is started.
Example
// Should be called after LinkGame.initializeAsync() resolves
LinkGame.getEntryPointAsync().then(entryPoint => {
console.log(entryPoint) // 'tab_banner'
})
Returns
Promise
<string
>
Defined in
getEntryPointData
▸ getEntryPointData(): EntryPointData
Get the entry point data bound to the entry point.
Example
// Should be called after LinkGame.initializeAsync() resolves
LinkGame.getEntryPointData() // { from: 'prequel-game' }
Returns
EntryPointData
Defined in
getInterstitialAdAsync
▸ getInterstitialAdAsync(placementId
): Promise
<InterstitialAdInstance
>
Get AdInstance of an interstitial ad placement.
Experimental support: please note that this API is subject to breaking change.
Example
LinkGame.getInterstitialAdAsync('DUMMY_PLACEMENT_ID')
.then(adInstance => {
// do something
})
Parameters
Name | Type |
---|---|
placementId | string |
Returns
Promise
<InterstitialAdInstance
>
Defined in
getLeaderboardAsync
▸ getLeaderboardAsync(name
): Promise
<Leaderboard
>
Get a leaderboard by its name
Example
LinkGame.getLeaderboardAsync('some_leaderboard')
.then(leaderboard => {
console.log(leaderboard.getName()) // 'some_leaderboard'
})
Parameters
Name | Type | Description |
---|---|---|
name | string | The name of the leaderboard |
Returns
Promise
<Leaderboard
>
Defined in
getLocale
▸ getLocale(): string
Get the current player's locale information.
Locale code will be based on navigator.language
in the WebView, format will be align with BCP47.
Example
LinkGame.getLocale() // 'ru-RU'
Returns
string
Defined in
getPlatform
▸ getPlatform(): Platform
Get information about from which platform the game is started, regarding OS or browser.
Example
console.log(LinkGame.getPlatform()) // 'ANDROID'
Returns
Defined in
getRewardedVideoAsync
▸ getRewardedVideoAsync(placementId
): Promise
<RewardedVideoInstance
>
Get AdInstance of a rewarded video ad placement.
Experimental support: please note that this API is subject to breaking change.
Example
LinkGame.getRewardedVideoAsync('DUMMY_PLACEMENT_ID')
.then(adInstance => {
// do something
})
Parameters
Name | Type |
---|---|
placementId | string |
Returns
Promise
<RewardedVideoInstance
>
Defined in
getTrafficSource
▸ getTrafficSource(): TrafficSource
Get traffic source info. This unveals the the URL parameters attached to the game's URL.
Experimental support: please note that this API is subject to breaking change.
Example
// Should be called after LinkGame.initializeAsync() resolves
const trafficSource = LinkGame.getTrafficSource()
console.log(trafficSource['utm_entrypoint']) // 'share'
Returns
TrafficSource
Defined in
initializeAsync
▸ initializeAsync(options?
): Promise
<void
>
Initialize the SDK for the game. In the background, SDK will try to setup environment and retrieve data for later use in the game. We recommend calling this API in the game ASAP to shorten the total loading wait time for players.
Example
LinkGame.initializeAsync().then(() => {
// Initialize player session with game backend
})
Parameters
Name | Type | Description |
---|---|---|
options | InitializationOptions | Extra options to alter the runtime behavior of the SDK. |
Returns
Promise
<void
>
Defined in
onPause
▸ onPause(fn
): void
Set a callback which will be invoked when the app is brought to background.
Example
LinkGame.onPause(() => {
pauseGameplay()
})
Parameters
Name | Type |
---|---|
fn | () => void |
Returns
void
Defined in
openDeeplinkAsync
▸ openDeeplinkAsync(category
, params
): Promise
<void
>
Open deeplink in Link
Experimental support: please note that this API is subject to breaking change.
Example
LinkGame.openDeeplinkAsync('news', '/weather?mode=gps').then(function(res) {
console.log(res);
}).catch(function(err) {
console.log(err)
});
Parameters
Name | Type |
---|---|
category | string |
params | string |
Returns
Promise
<void
>
Defined in
openUrlAsync
▸ openUrlAsync(url
): Promise
<void
>
Open event link in Link
Experimental support: please note that this API is subject to breaking change.
Example
LinkGame.openUrlAsync('https://service.link.link/').then(function(res) {
console.log(res);
}).catch(function(err) {
console.log(err)
});
Parameters
Name | Type |
---|---|
url | string |
Returns
Promise
<void
>
Defined in
setLoadingProgress
▸ setLoadingProgress(percentage?
): void
Updates the load progress of the game. The value will be shown at the loading screen.
Example
LinkGame.setLoadingProgress(50) // The game is halfway loaded
Parameters
Name | Type | Default value | Description |
---|---|---|---|
percentage | number | 0 | Represents percentage of loading progress. It should be between 0 and 100. |
Returns
void
Defined in
shareAsync
▸ shareAsync(payload
): Promise
<ShareResult
>
Share messages to the player's friends. This will display an interactive UI for the user to choose who to share. Additional parameters can be used to fine-tune the message to be shared.
Experimental support: please note that this API is subject to breaking change.
Example
LinkGame.shareAsync({
image: base64Picture,
text: {
default: 'Some text',
localizations: {
ja_JP: 'テキスト',
en_US: 'Some text',
}
}
caption: 'Some caption',
data: { someData: '...' },
}).then(function(shareResult) {
console.log(shareResult); // {sharedCount: 3}
});
Parameters
Name | Type | Description |
---|---|---|
payload | SharePayload | An object describes the message to be shared. |
Returns
Promise
<ShareResult
>
Defined in
startGameAsync
▸ startGameAsync(): Promise
<void
>
Starts the game. Calling this method will turn off the loading screen as soon as these requirements are met:
- LinkGame.setLoadingProgress() is called with a number > 99
- LinkGame.initializeAsync() is called and resolved
Example
LinkGame.startGameAsync().then(() => {
myAwesomeGame.start()
})
Returns
Promise
<void
>
Defined in
updateAsync
▸ updateAsync(payload
): Promise
<void
>
Post an update to the corresponding context. If the game is played in a messenger chat thread, this will send a message into the thread with specified image and text message and custom data payload.
Experimental support: please note that this API is subject to breaking change.
Example
LinkGame.updateAsync({
image: base64Picture,
text: {
default: 'Some text',
localizations: {
ja_JP: 'テキスト',
en_US: 'Some text',
}
}
caption: 'Some caption',
data: { someData: '...' },
})
Parameters
Name | Type | Description |
---|---|---|
payload | CustomUpdatePayload | An object describes the update message |
Returns
Promise
<void
>
Defined in
LinkGame.context Functions
chooseAsync
▸ chooseAsync(payload
): Promise
<void
>
Display a UI to interactively choose a friend and create a context and send an invitation right away. Additional parameters can be specified to fine-tune the invitation message.
Experimental support: please note that this API is subject to breaking change.
Example
LinkGame.context.chooseAsync({
image: base64Picture,
text: {
default: 'Some text',
localizations: {
ja_JP: 'テキスト',
en_US: 'Some text',
}
}
caption: 'Some caption',
data: { someData: '...' },
}).then(() => {
console.log(LinkGame.context.getID()); // 'SOMECONTEXT1234567'
});
Parameters
Name | Type | Description |
---|---|---|
payload | ContextChoosePayload | Additional parameters for the UI |
Returns
Promise
<void
>
Defined in
createAsync
▸ createAsync(playerId
, payload?
): Promise
<void
>
Create a context with an opponent player
Experimental support: please note that this API is subject to breaking change.
Example
LinkGame.context.createAsync('SOMEPLAYER123456', {
text: 'SENDER_NAME want to play with RECEIVER_NAME at GAME_NAME.',
caption: {
default: 'Some text',
localizations: {
ja_JP: 'テキスト',
en_US: 'Some text',
}
}
}).then(() => {
console.log(LinkGame.context.getID()); // 'SOMECONTEXT1234567'
});
Parameters
Name | Type | Description |
---|---|---|
playerId | string | Player ID of the opponent player |
payload | ContextCreatePayload | Additional parameters for main text and action button on the popup UI |
Returns
Promise
<void
>
Defined in
getID
▸ getID(): string
| null
Get ID of current context
Example
// In SOLO context
LinkGame.context.getID(); // null
// In THREAD context
LinkGame.context.getID(); // a 16 char alphanumeric string
Returns
string
| null
Defined in
getPlayersAsync
▸ getPlayersAsync(): Promise
<ContextPlayer
[]>
Get players in current context
Experimental support: please note that this API is subject to breaking change.
Example
LinkGame.context.getPlayersAsync().then(players => {
console.log(player.length); // 2
});
Returns
Promise
<ContextPlayer
[]>
Defined in
getType
▸ getType(): "SOLO"
| "THREAD"
Get type of current context
Example
// In SOLO context
LinkGame.context.getType(); // 'SOLO'
Returns
"SOLO"
| "THREAD"
Defined in
isSizeBetween
▸ isSizeBetween(minSize?
, maxSize?
): ContextSizeResponse
| null
Check if the count of players in current context is between given numbers
Experimental support: please note that this API is subject to breaking change.
Example
// In a THREAD context containing 2 players
const result = LinkGame.context.isSizeBetween(2, 3);
console.log(result.answer); // true
Parameters
Name | Type | Description |
---|---|---|
minSize? | number | The minimum boundry of the check |
maxSize? | number | The maximum boundry of the check |
Returns
ContextSizeResponse
| null
Defined in
switchAsync
▸ switchAsync(contextId
, payload?
): Promise
<void
>
Switch context by using a known context ID.
Experimental support: please note that this API is subject to breaking change.
Example
LinkGame.context.switchAsync('SOMECONTEXT1234567', {
text: 'SENDER_NAME want to play with RECEIVER_NAME at GAME_NAME.',
caption: {
default: 'Some text',
localizations: {
ja_JP: 'テキスト',
en_US: 'Some text',
}
}
}).then(() => {
console.log(LinkGame.context.getID()); // 'SOMECONTEXT1234567'
});
Parameters
Name | Type | Description |
---|---|---|
contextId | string | Context ID of the context |
payload | ContextCreatePayload | Additional parameters for main text and action button on the popup UI |
Returns
Promise
<void
>
Defined in
LinkGame.payments Functions
consumePurchaseAsync
▸ consumePurchaseAsync(purchaseToken
): Promise
<void
>
Consume a purchase. This will update the status of the corrsponding purchase, and allow the player to purchase the same product for another time.
Experimental support: please note that this API is subject to breaking change.
Example
LinkGame.payments.consumePurchaseAsync('somePurchaseToken').then(() => {
console.log('Purchase is consumed')
})
Parameters
Name | Type | Description |
---|---|---|
purchaseToken | string | A string of purchase token used for consumption |
Returns
Promise
<void
>
Defined in
getCatalogAsync
▸ getCatalogAsync(): Promise
<Product
[]>
Get the catalog for info on available products. There's chance in getting an empty list even though the device supports In-App Purchase. (e.g. Google Play doesn't support purchase in the user's region.)
Experimental support: please note that this API is subject to breaking change.
Example
LinkGame.payments.getCatalogAsync().then((catalog) => {
console.log(catalog)
})
Returns
Promise
<Product
[]>
Array of products with pricing information
Defined in
getPurchasesAsync
▸ getPurchasesAsync(): Promise
<Purchase
[]>
Get unconsumed purchases. Developers should validate the purchase signatures on server side before provisioning corresponding game item.
Experimental support: please note that this API is subject to breaking change.
Example
LinkGame.payments.getPurchasesAsync().then((purchases) => {
console.log(purchases)
})
Returns
Promise
<Purchase
[]>
purchases
Defined in
onReady
▸ onReady(callback
): void
Set a callback when payment features are ready. On unsupported device, the callback will never be invoked.
Experimental support: please note that this API is subject to breaking change.
Example
LinkGame.payments.onReady(function () {
console.log('Ready to receive payments requests')
})
Parameters
Name | Type |
---|---|
callback | () => any |
Returns
void
Defined in
purchaseAsync
▸ purchaseAsync(config
): Promise
<Purchase
>
Request an purchase on the specified product. This will invoke the native In-App Purchase screen and return the result.
Experimental support: please note that this API is subject to breaking change.
Example
LinkGame.payments.purchaseAsync({
productID: 'someProduct',
developerPayload: 'somePayload'
}).then((purchase) => {
console.log(purchase)
})
Parameters
Name | Type | Description |
---|---|---|
config | PurchaseConfig | An object containing purchase configuration information |
Returns
Promise
<Purchase
>
Purchase information
Defined in
LinkGame.player Functions
flushDataAsync
▸ flushDataAsync(): Promise
<void
>
Will flush any unsaved data to platform storage
Returns
Promise
<void
>
Defined in
getConnectedPlayersAsync
▸ getConnectedPlayersAsync(): Promise
<ConnectedPlayer
[]>
This returns an array containing the friends of the user who has played the current game before.
Experimental support: please note that this API is subject to breaking change.
Example
LinkGame.player.getConnectedPlayersAsync()
.then(players => {
console.log(players.map(player => {
return {
id: player.getID(),
name: player.getName(),
}
}))
// [{id: 'SOMEPLAYER123456', name: 'John'}, {id: 'SOMEPLAYER654321', name: 'Jack'}]
})
Returns
Promise
<ConnectedPlayer
[]>
Array of connected players
Defined in
getDataAsync
▸ getDataAsync(keys
): Promise
<PlayerData
>
Get game data from platform storage.
Example
LinkGame.player
.getDataAsync(['hp', 'items'])
.then(function(data) {
console.log(data['hp']) // 100
console.log(data['items']) // {potion: 3, gold: 20}
})
Parameters
Name | Type | Description |
---|---|---|
keys | string [] | An array of unique keys to retrieve data for. |
Returns
Promise
<PlayerData
>
Latest snapshot of game data
Defined in
getID
▸ getID(): string
| null
Get the player's ID.
Example
LinkGame.player.getID() // 'SOMEPLAYER123456'
Returns
string
| null
Player's ID
Defined in
getName
▸ getName(): string
| null
Get the player's name.
Example
LinkGame.player.getName() // 'John Smith'
Returns
string
| null
Player's name
Defined in
getPhoto
▸ getPhoto(): string
| null
Get the player's photo.
Example
const playerImage = new Image()
playerImage.crossOrigin = 'anonymous'
playerImage.src = LinkGame.player.getPhoto()
Returns
string
| null
URL of player photo
Defined in
getSignedPlayerInfoAsync
▸ getSignedPlayerInfoAsync(payload?
): Promise
<SignedPlayerInfo
>
Get a SignedPlayerInfo object with custom payload and a signature. This can be useful for game server to validate if the user's identity and its payload is really sent from the game or tampered. Please read more on SignedPlayerInfo for more information.
Example
LinkGame.player.getSignedPlayerInfoAsync('{"type":"GAIN_COINS","amount":100}')
.then(result => {
// Send to server for validation and further processing
sendToGameServer(
result.getPlayerID(),
result.getSignature(),
'{"type":"GAIN_COINS","amount":100}',
)
})
Parameters
Name | Type | Description |
---|---|---|
payload? | string | An arbitary string to be signed |
Returns
Promise
<SignedPlayerInfo
>
An object containing signed player info and custom payload
Defined in
hasPlayed
▸ hasPlayed(): boolean
Get info about if the player has played the game.
Example
LinkGame.player.hasPlayed() // true
Returns
boolean
Always true
Defined in
setDataAsync
▸ setDataAsync(data
): Promise
<void
>
Update game data to platform storage. The update will be merged into existing game data. Please be careful not to store a game data bigger than 1MB when stringified, which will cause the modification be rejected.
Example
LinkGame.player
.setDataAsync({
items: {
potion: 4,
gold: 20,
},
hp: 99,
})
.then(function() {
console.log('data is set')
})
Parameters
Name | Type | Description |
---|---|---|
data | Record <string , unknown > | An object containing a set of key-value pairs. The object must contain only serializable values. Nullable value will be treated as removal of the key-value pair. |
Returns
Promise
<void
>