react-native-tplsdk
v1.0.1
Published
React Native wrapper for TPL Game SDK - authentication, login, and user management
Maintainers
Readme
react-native-tplsdk
React Native wrapper for TPL Game SDK - authentication, login, and user management.
Installation
yarn add react-native-tplsdk
# or
npm install react-native-tplsdkiOS
cd ios && pod installAndroid
The SDK AAR is bundled with this package. No additional setup needed.
Configuration
Place a tpl-service.json file in your app:
- Android:
android/app/src/main/assets/tpl-service.json - iOS: Add to your app bundle
{
"game_code": "your_game_code",
"secret_key": "your_secret_key"
}Android: Register the package
In your MainApplication.kt (or .java):
import com.tplsdk.TPLGameSDKPackage
override fun getPackages(): List<ReactPackage> =
PackageList(this).packages.apply {
add(TPLGameSDKPackage())
}Usage
import TPLGameSDK from 'react-native-tplsdk';
// Initialize SDK (call once on app start)
await TPLGameSDK.initialize();
// Show login dialog
const result = await TPLGameSDK.showLogin();
console.log(result.userId, result.userName, result.accessToken);
// Show register dialog
const result = await TPLGameSDK.showRegister();
// Check login status
const loggedIn = await TPLGameSDK.isUserLoggedIn();
// Get user info
const userInfo = await TPLGameSDK.getUserInfo();
// Get access token
const token = await TPLGameSDK.getAccessToken();
// Logout
await TPLGameSDK.logout();
// Configuration
TPLGameSDK.setKeepLoginSession(true);
TPLGameSDK.setShowPlayNowButton(false);API
| Method | Returns | Description |
|--------|---------|-------------|
| initialize() | Promise<boolean> | Initialize SDK. Call before other methods. |
| showLogin() | Promise<TPLLoginResult> | Show login dialog |
| showRegister() | Promise<TPLLoginResult> | Show registration dialog |
| logout() | Promise<boolean> | Logout current user |
| isUserLoggedIn() | Promise<boolean> | Check login status |
| getAccessToken() | Promise<string> | Get current access token |
| getUserInfo() | Promise<TPLUserInfo> | Get current user info |
| setKeepLoginSession(keep) | void | Persist login session |
| setShowPlayNowButton(show) | void | Show/hide guest play button |
Types
interface TPLLoginResult {
userId: string;
userName: string;
accessToken: string;
expiresAt?: number;
}
interface TPLUserInfo {
userId: number;
userName: string;
accessToken: string;
isGuest: boolean;
}License
MIT
