@xsolla/launcher-sdk
v2.2.0
Published
SDK for integrating Launcher v3 by embedding web content (tab, web games)
Downloads
295
Readme
Launcher web SDK
SDK for integrating Launcher v3 by embedding web content (tab, web games)
Installation
npm i @xsolla/launcher-sdk
Usage
import { SDK } from '@xsolla/launcher-sdk';
const sdk = new SDK();
sdk.activate();
sdk.getAccessToken();
Classes
SDK
SDK module for communication with Launcher v3
Extends
EventHandler
Constructors
new SDK(targetWindow)
new SDK(
targetWindow
?):SDK
Parameters
• targetWindow?: null
| Window
= window.top
window object that refers to launcher
Returns
Overrides
EventHandler.constructor
Example
const sdk = new SDK();
Methods
activate()
activate():
void
Initialize communication between web content and Launcher
Returns
void
Overrides
EventHandler.activate
Example
const sdk = new SDK();
'...add listeners'
sdk.activate();
'...do stuff'
allowLogout()
allowLogout(
allow
):void
Sets whether the user is allowed to log out from the launcher.
Parameters
• allow: boolean
If set to true, the user can log out; if set to false, the logout option is disabled.
Returns
void
Example
const sdk = new SDK();
sdk.activate();
sdk.allowLogout(true);
authContinue()
authContinue():
void
Informs the launcher that authentication has been successfully completed, prompting the launcher to continue its initialization process.
Returns
void
Example
const sdk = new SDK();
sdk.activate();
sdk.onAccessTokenRefresh((access_token) => {
if (access_token) {
console.log('New access token received:', access_token);
sdk.authContinue();
} else {
console.log('No access token received. Authentication did not continue.');
}
});
authViaPlatform()
authViaPlatform():
void
Initiates the user authorization process via the current distribution platform, such as Steam or Epic Games Store.
Returns
void
Example
const sdk = new SDK();
sdk.activate();
sdk.authViaPlatform();
authViaXsolla()
authViaXsolla():
void
Initiates the user authorization process via Xsolla Login.
Returns
void
Example
const sdk = new SDK();
sdk.activate();
sdk.authViaXsolla();
closeApp()
closeApp():
void
Closes the launcher.
Returns
void
Example
const sdk = new SDK();
sdk.activate();
sdk.closeApp();
deactivate()
deactivate():
void
Deactivate communication between web content and Launcher when it is no longer needed
Returns
void
Overrides
EventHandler.deactivate
Example
const sdk = new SDK();
sdk.activate();
'...do stuff'
sdk.deactivate();
'...here new events will not be received'
getAccessToken()
getAccessToken():
Promise
<any
>
Requests Launcher for fresh access token
Returns
Promise
<any
>
Example
const sdk = new SDK();
sdk.activate();
const access_token = await sdk.getAccessToken();
console.log('Access token received:', access_token);
getDistributionPlatform()
getDistributionPlatform():
Promise
<DistributionPlatform
>
Requests the distribution platform that initiated the launcher.
Returns
Promise
<DistributionPlatform
>
Example
const sdk = new SDK();
sdk.activate();
const platform = await sdk.getDistributionPlatform();
console.log('Active distribution platform:', platform);
getLoginWidgetSettings()
getLoginWidgetSettings():
Promise
<XsollaLoginSettings
>
Requests the distribution platform that initiated the launcher.
Returns
Promise
<XsollaLoginSettings
>
Example
const sdk = new SDK();
sdk.activate();
const settings = await sdk.getLoginWidgetSettings();
console.log('Active distribution platform:', settings);
getPersistentData()
getPersistentData(
plugin_id
):Promise
<Record
<string
,unknown
>>
Gets persistent data from the launcher.
Parameters
• plugin_id: "login-page"
Returns
Promise
<Record
<string
, unknown
>>
Example
const sdk = new SDK();
sdk.activate();
const getPersistentData = await sdk.getPersistentData('login-page');
console.log('Persistent data from launcher:', getPersistentData);
isAccessTokenValid()
isAccessTokenValid(
access_token
):Promise
<boolean
>
Checks if the access token is valid.
Parameters
• access_token: string
Returns
Promise
<boolean
>
Example
const sdk = new SDK();
sdk.activate();
const access_token = await sdk.getAccessToken();
const isTokenValid = await sdk.isAccessTokenValid(access_token);
console.log('Is access token valid:', isTokenValid);
isFirstStart()
isFirstStart():
Promise
<boolean
>
Checks if the launcher has been started for the first time.
Returns
Promise
<boolean
>
Example
const sdk = new SDK();
sdk.activate();
const isFirstStart = await sdk.isFirstStart();
console.log('Is it the first launcher start:', isFirstStart);
onAccessTokenRefresh()
onAccessTokenRefresh(
handler
):void
Listens to channel, when a fresh access token received from launcher handler
would be called with handler(access_token)
Note: sdk.getAccessToken() will not trigger this event;
Parameters
• handler: AccessTokenRefreshHandler
callback function that will be called when fresh access token received
Returns
void
Example
const sdk = new SDK();
sdk.onAccessTokenRefresh((access_token) => {
console.log('Access token received:', access_token);
});
sdk.activate();
onAuthStatus()
onAuthStatus(
handler
):void
Listens to channel, when an authorization process changes its state (loading, error) handler
would be called with handler(status)
Parameters
• handler: AuthStatusHandler
callback function that will be called when authorization process changes its state
Returns
void
Example
const sdk = new SDK();
sdk.onAuthStatus((status) => {
console.log('Auth status:', status);
});
sdk.activate();
onUserLang()
onUserLang(
handler
):void
Listens to channel, when a user changes language of launcher handler
would be called with handler(language)
Note: The first call is the initial one, with the current launcher language
Parameters
• handler: UserLangHandler
callback function that will be called when user changes language
Returns
void
Example
const sdk = new SDK();
sdk.onUserLang((language) => {
console.log('Launcher language:', language);
});
sdk.activate();
patchPersistentData()
patchPersistentData(
plugin_id
,plugin_data
):void
Sends JSON data to the launcher to update (PATCH) persistent data.
Parameters
• plugin_id: "login-page"
ID of the plugin that wants to patch the persistent data.
• plugin_data: Record
<string
, unknown
>
JSON data to be patched by the launcher.
Returns
void
Example
const sdk = new SDK();
sdk.activate();
sdk.patchPersistentData('login-page', { is_auto_auth: true });
putPersistentData()
putPersistentData(
plugin_id
,plugin_data
):void
Sends JSON data to the launcher to rewrite (PUT) current persistent data.
Parameters
• plugin_id: "login-page"
ID of the plugin that wants to rewrite the existing persistent data.
• plugin_data: Record
<string
, unknown
>
JSON data to be rewritten by the launcher.
Returns
void
Example
const sdk = new SDK();
sdk.activate();
sdk.putPersistentData('login-page', {});
resetAuth()
resetAuth():
void
Resets the authentication process.
Returns
void
Example
const sdk = new SDK();
sdk.activate();
sdk.resetAuth();
Type Aliases
AccessTokenRefreshHandler()
AccessTokenRefreshHandler: (
access_token
) =>void
Parameters
• access_token: string
| null
Returns
void
AuthStatus
AuthStatus:
object
Type declaration
error
error:
string
|null
isError
isError:
boolean
isLoading
isLoading:
boolean
AuthStatusHandler()
AuthStatusHandler: (
status
) =>void
Parameters
• status: AuthStatus
Returns
void
DistributionPlatform
DistributionPlatform:
"Xsolla"
|"Steam"
|"Epic Games Store"
UserLang
UserLang:
"ar"
|"bg"
|"cn"
|"cs"
|"de"
|"en"
|"es"
|"fr"
|"he"
|"it"
|"ja"
|"ko"
|"pl"
|"pt"
|"ro"
|"ru"
|"th"
|"tr"
|"tw"
|"vi"
UserLangHandler()
UserLangHandler: (
language
) =>void
Parameters
• language: UserLang
Returns
void
XsollaLoginSettings
XsollaLoginSettings:
XsollaLoginSettingsClassic
|XsollaLoginSettingsOAuth
Represents the settings for Xsolla login.
For a detailed description of each field, see Xsolla Login SDK Documentation.
XsollaLoginSettingsClassic
XsollaLoginSettingsClassic:
object
Settings for classic Xsolla login
Type declaration
callbackUrl
callbackUrl:
string
The callback URL after login
preferredLocale
preferredLocale:
string
The preferred locale for the login
projectId
projectId:
string
The ID of the project
url
url:
string
URL of the Xsolla Login
XsollaLoginSettingsOAuth
XsollaLoginSettingsOAuth:
object
Settings for OAuth Xsolla login
Type declaration
clientId
clientId:
string
The client ID for OAuth
preferredLocale
preferredLocale:
string
The preferred locale for the login
projectId
projectId:
string
The ID of the project
redirectUri
redirectUri:
string
The redirect URI for OAuth
responseType
responseType:
string
The response type for OAuth
scope
scope:
string
The scope for OAuth
state
state:
string
The state for OAuth
url
url:
string
URL of the Xsolla Login