Chuyển tới nội dung chính

Web SDK Initialization

Call VLPlaySDK.init() once when your application or game loads. [PLACEHOLDER] The init() method is asynchronous and returns a Promise. It sets up the SDK internals, restores any saved session from localStorage, and verifies connectivity with VLPlay servers. You should await this call before invoking any other SDK method.

[PLACEHOLDER] The SDK instance is a singleton — calling init() multiple times is safe and will no-op after the first successful initialization. Pass env: 'sandbox' during development to use the VLPlay sandbox environment without affecting production data.

Basic Initialization

import { VLPlaySDK } from '@vlplay/sdk';

async function initGame() {
await VLPlaySDK.init({
appId: 'YOUR_APP_ID',
clientSecret: 'YOUR_CLIENT_SECRET',
env: 'production', // 'production' | 'sandbox'
debug: false,
locale: 'en', // 'en' | 'vi' | 'zh-Hans'
});

console.log(`VLPlay SDK ${VLPlaySDK.version} ready`);
}

initGame().catch(console.error);

Configuration Options

OptionTypeDefaultDescription
appIdstringYour application ID (required)
clientSecretstringYour client secret (required)
env'production' | 'sandbox''production'Target environment
debugbooleanfalseEnable verbose console logging
localestring'en'UI locale for SDK dialogs
storageKeystring'vlplay_session'localStorage key for session

Verify Initialization

console.log('SDK version:', VLPlaySDK.version);
console.log('Is initialized:', VLPlaySDK.isInitialized);
console.log('Current user:', VLPlaySDK.auth.currentUser);

Next: Auth Flow