Skip to main content

link-game-sdk

Classes

Interfaces

LinkGame Functions

LinkGame.context Functions

LinkGame.payments Functions

LinkGame.player Functions

Type Aliases

GetAdUnitsResponse

Ƭ GetAdUnitsResponse: AdUnit[]

Defined in

types/bridge.ts:150


Platform

Ƭ Platform: "IOS" | "ANDROID" | "DESKTOP"

The underlying platform where Link app is running on.

Defined in

types/platform.ts:4


Signature

Ƭ Signature: string

A signature that can be verified on game's backend server. Server side validation can be done by following these steps:

  1. Split the signature into two parts delimited by the . character.
  2. Decode the first part with base64url encoding, which should be a hash.
  3. Decode the second part with base64url encoding, which should be a string representation of an JSON object.
  4. Hash the second part string using HMAC SHA-256 and the app secret, check if it is identical to the hash from step 2.
  5. Optionally, developer can also validate the timestamp to see if the request is made recently.

Defined in

types/signature.ts:11

Variables

LinkGame

Const LinkGame: __module = _LinkGame

Stands for the namespace containing all APIs of the Link Game SDK.

Defined in

index.ts:13


context

Const context: __module = _context

LinkGame.context namespace contains context related APIs

Defined in

sdk/index.ts:46


payments

Const payments: __module = _payments

LinkGame.payments namespace contains payment related APIs

Defined in

sdk/index.ts:56


player

Const player: __module = _player

LinkGame.player namespace contains player related APIs

Defined in

sdk/index.ts:51

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

sdk/index.ts:599


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

sdk/index.ts:502


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

sdk/index.ts:255


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

NameType
placementIdstring

Returns

Promise<InterstitialAdInstance>

Defined in

sdk/index.ts:390


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

NameTypeDescription
namestringThe name of the leaderboard

Returns

Promise<Leaderboard>

Defined in

sdk/index.ts:343


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

sdk/index.ts:242


getPlatform

getPlatform(): Platform

Get information about from which platform the game is started, regarding OS or browser.

Example

console.log(LinkGame.getPlatform()) // 'ANDROID'

Returns

Platform

Defined in

sdk/index.ts:515


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

NameType
placementIdstring

Returns

Promise<RewardedVideoInstance>

Defined in

sdk/index.ts:416


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

sdk/index.ts:487


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

NameTypeDescription
optionsInitializationOptionsExtra options to alter the runtime behavior of the SDK.

Returns

Promise<void>

Defined in

sdk/index.ts:73


onPause

onPause(fn): void

Set a callback which will be invoked when the app is brought to background.

Example

LinkGame.onPause(() => {
pauseGameplay()
})

Parameters

NameType
fn() => void

Returns

void

Defined in

sdk/index.ts:270


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

NameType
categorystring
paramsstring

Returns

Promise<void>

Defined in

sdk/index.ts:618


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

NameType
urlstring

Returns

Promise<void>

Defined in

sdk/index.ts:637


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

NameTypeDefault valueDescription
percentagenumber0Represents percentage of loading progress. It should be between 0 and 100.

Returns

void

Defined in

sdk/index.ts:125


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

NameTypeDescription
payloadSharePayloadAn object describes the message to be shared.

Returns

Promise<ShareResult>

Defined in

sdk/index.ts:216


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

sdk/index.ts:143


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

NameTypeDescription
payloadCustomUpdatePayloadAn object describes the update message

Returns

Promise<void>

Defined in

sdk/index.ts:170


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

NameTypeDescription
payloadContextChoosePayloadAdditional parameters for the UI

Returns

Promise<void>

Defined in

sdk/context.ts:228


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

NameTypeDescription
playerIdstringPlayer ID of the opponent player
payloadContextCreatePayloadAdditional parameters for main text and action button on the popup UI

Returns

Promise<void>

Defined in

sdk/context.ts:114


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

sdk/context.ts:29


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

sdk/context.ts:255


getType

getType(): "SOLO" | "THREAD"

Get type of current context

Example

// In SOLO context
LinkGame.context.getType(); // 'SOLO'

Returns

"SOLO" | "THREAD"

Defined in

sdk/context.ts:42


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

NameTypeDescription
minSize?numberThe minimum boundry of the check
maxSize?numberThe maximum boundry of the check

Returns

ContextSizeResponse | null

Defined in

sdk/context.ts:60


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

NameTypeDescription
contextIdstringContext ID of the context
payloadContextCreatePayloadAdditional parameters for main text and action button on the popup UI

Returns

Promise<void>

Defined in

sdk/context.ts:170


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

NameTypeDescription
purchaseTokenstringA string of purchase token used for consumption

Returns

Promise<void>

Defined in

sdk/payments.ts:125


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

sdk/payments.ts:43


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

sdk/payments.ts:104


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

NameType
callback() => any

Returns

void

Defined in

sdk/payments.ts:24


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

NameTypeDescription
configPurchaseConfigAn object containing purchase configuration information

Returns

Promise<Purchase>

Purchase information

Defined in

sdk/payments.ts:65


LinkGame.player Functions

flushDataAsync

flushDataAsync(): Promise<void>

Will flush any unsaved data to platform storage

Returns

Promise<void>

Defined in

sdk/player.ts:88


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

sdk/player.ts:203


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

NameTypeDescription
keysstring[]An array of unique keys to retrieve data for.

Returns

Promise<PlayerData>

Latest snapshot of game data

Defined in

sdk/player.ts:35


getID

getID(): string | null

Get the player's ID.

Example

LinkGame.player.getID() // 'SOMEPLAYER123456'

Returns

string | null

Player's ID

Defined in

sdk/player.ts:101


getName

getName(): string | null

Get the player's name.

Example

LinkGame.player.getName() // 'John Smith'

Returns

string | null

Player's name

Defined in

sdk/player.ts:114


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

sdk/player.ts:129


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

NameTypeDescription
payload?stringAn arbitary string to be signed

Returns

Promise<SignedPlayerInfo>

An object containing signed player info and custom payload

Defined in

sdk/player.ts:166


hasPlayed

hasPlayed(): boolean

Get info about if the player has played the game.

Example

LinkGame.player.hasPlayed() // true  

Returns

boolean

Always true

Defined in

sdk/player.ts:142


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

NameTypeDescription
dataRecord<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>

Defined in

sdk/player.ts:76