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
- TypeScript / ESM
- UMD / CDN
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);
window.addEventListener('load', async () => {
await VLPlaySDK.init({
appId: 'YOUR_APP_ID',
clientSecret: 'YOUR_CLIENT_SECRET',
});
console.log('VLPlay SDK ready');
});
Configuration Options
| Option | Type | Default | Description |
|---|---|---|---|
appId | string | — | Your application ID (required) |
clientSecret | string | — | Your client secret (required) |
env | 'production' | 'sandbox' | 'production' | Target environment |
debug | boolean | false | Enable verbose console logging |
locale | string | 'en' | UI locale for SDK dialogs |
storageKey | string | '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