playkit-sdk 1.2.8-beta.3 → 1.2.8-beta.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/playkit-sdk.cjs.js +30 -17
- package/dist/playkit-sdk.cjs.js.map +1 -1
- package/dist/playkit-sdk.d.ts +25 -2
- package/dist/playkit-sdk.esm.js +30 -17
- package/dist/playkit-sdk.esm.js.map +1 -1
- package/dist/playkit-sdk.umd.js +30 -17
- package/dist/playkit-sdk.umd.js.map +1 -1
- package/package.json +1 -1
package/dist/playkit-sdk.cjs.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* playkit-sdk v1.2.8-beta.
|
|
2
|
+
* playkit-sdk v1.2.8-beta.5
|
|
3
3
|
* PlayKit SDK for JavaScript
|
|
4
4
|
* @license SEE LICENSE IN LICENSE
|
|
5
5
|
*/
|
|
@@ -3447,19 +3447,11 @@ class PlayerClient extends EventEmitter {
|
|
|
3447
3447
|
* Get player information
|
|
3448
3448
|
*/
|
|
3449
3449
|
async getPlayerInfo() {
|
|
3450
|
-
var _a, _b;
|
|
3450
|
+
var _a, _b, _c;
|
|
3451
3451
|
const token = this.authManager.getToken();
|
|
3452
3452
|
if (!token) {
|
|
3453
3453
|
throw new PlayKitError('Not authenticated', 'NOT_AUTHENTICATED');
|
|
3454
3454
|
}
|
|
3455
|
-
// If using developer token, return mock player info
|
|
3456
|
-
const authState = this.authManager.getAuthState();
|
|
3457
|
-
if (authState.tokenType === 'developer') {
|
|
3458
|
-
return {
|
|
3459
|
-
userId: 'developer',
|
|
3460
|
-
credits: 999999,
|
|
3461
|
-
};
|
|
3462
|
-
}
|
|
3463
3455
|
try {
|
|
3464
3456
|
// Build headers with X-Game-Id to support Global Developer Token
|
|
3465
3457
|
const headers = {
|
|
@@ -3489,13 +3481,14 @@ class PlayerClient extends EventEmitter {
|
|
|
3489
3481
|
const data = await response.json();
|
|
3490
3482
|
this.playerInfo = {
|
|
3491
3483
|
userId: data.userId,
|
|
3484
|
+
balance: (_a = data.balance) !== null && _a !== void 0 ? _a : 0,
|
|
3492
3485
|
credits: data.credits,
|
|
3493
|
-
nickname: (
|
|
3486
|
+
nickname: (_b = data.nickname) !== null && _b !== void 0 ? _b : null,
|
|
3494
3487
|
dailyRefresh: data.dailyRefresh,
|
|
3495
3488
|
};
|
|
3496
3489
|
this.emit('player_info_updated', this.playerInfo);
|
|
3497
3490
|
// Emit daily refresh event if credits were refreshed
|
|
3498
|
-
if ((
|
|
3491
|
+
if ((_c = data.dailyRefresh) === null || _c === void 0 ? void 0 : _c.refreshed) {
|
|
3499
3492
|
this.emit('daily_credits_refreshed', data.dailyRefresh);
|
|
3500
3493
|
// Show toast notification if enabled
|
|
3501
3494
|
if (this.rechargeConfig.showDailyRefreshToast !== false) {
|
|
@@ -3611,7 +3604,7 @@ class PlayerClient extends EventEmitter {
|
|
|
3611
3604
|
this.logger.warn('RechargeManager not initialized. Cannot show modal.');
|
|
3612
3605
|
return;
|
|
3613
3606
|
}
|
|
3614
|
-
const balance = (_a = this.playerInfo) === null || _a === void 0 ? void 0 : _a.
|
|
3607
|
+
const balance = (_a = this.playerInfo) === null || _a === void 0 ? void 0 : _a.balance;
|
|
3615
3608
|
await this.rechargeManager.showInsufficientBalanceModal({
|
|
3616
3609
|
currentBalance: balance,
|
|
3617
3610
|
message: customMessage,
|
|
@@ -3644,9 +3637,9 @@ class PlayerClient extends EventEmitter {
|
|
|
3644
3637
|
this.balanceCheckInterval = setInterval(async () => {
|
|
3645
3638
|
var _a, _b;
|
|
3646
3639
|
try {
|
|
3647
|
-
const oldBalance = (_a = this.playerInfo) === null || _a === void 0 ? void 0 : _a.
|
|
3640
|
+
const oldBalance = (_a = this.playerInfo) === null || _a === void 0 ? void 0 : _a.balance;
|
|
3648
3641
|
await this.refreshPlayerInfo();
|
|
3649
|
-
const newBalance = (_b = this.playerInfo) === null || _b === void 0 ? void 0 : _b.
|
|
3642
|
+
const newBalance = (_b = this.playerInfo) === null || _b === void 0 ? void 0 : _b.balance;
|
|
3650
3643
|
// Emit balance_updated event
|
|
3651
3644
|
if (newBalance !== undefined) {
|
|
3652
3645
|
this.emit('balance_updated', newBalance);
|
|
@@ -6152,6 +6145,7 @@ class PlayKitSDK extends EventEmitter {
|
|
|
6152
6145
|
this.playerClient.on('balance_updated', (credits) => this.emit('balance_updated', credits));
|
|
6153
6146
|
this.playerClient.on('player_info_updated', (info) => this.emit('player_info_updated', info));
|
|
6154
6147
|
this.playerClient.on('daily_credits_refreshed', (result) => this.emit('daily_credits_refreshed', result));
|
|
6148
|
+
this.playerClient.on('nickname_changed', (nickname) => this.emit('nickname_changed', nickname));
|
|
6155
6149
|
}
|
|
6156
6150
|
/**
|
|
6157
6151
|
* Initialize the SDK
|
|
@@ -6433,14 +6427,33 @@ class PlayKitSDK extends EventEmitter {
|
|
|
6433
6427
|
getCachedBalance() {
|
|
6434
6428
|
var _a;
|
|
6435
6429
|
const playerInfo = this.playerClient.getCachedPlayerInfo();
|
|
6436
|
-
return (_a = playerInfo === null || playerInfo === void 0 ? void 0 : playerInfo.
|
|
6430
|
+
return (_a = playerInfo === null || playerInfo === void 0 ? void 0 : playerInfo.balance) !== null && _a !== void 0 ? _a : null;
|
|
6437
6431
|
}
|
|
6438
6432
|
/**
|
|
6439
6433
|
* Refresh and get player's current balance
|
|
6440
6434
|
*/
|
|
6441
6435
|
async refreshBalance() {
|
|
6442
6436
|
const playerInfo = await this.playerClient.refreshPlayerInfo();
|
|
6443
|
-
return playerInfo.
|
|
6437
|
+
return playerInfo.balance;
|
|
6438
|
+
}
|
|
6439
|
+
// ============================================================
|
|
6440
|
+
// Player Profile Methods
|
|
6441
|
+
// ============================================================
|
|
6442
|
+
/**
|
|
6443
|
+
* Get player's nickname (cached)
|
|
6444
|
+
* @returns Nickname or null if not set
|
|
6445
|
+
*/
|
|
6446
|
+
getNickname() {
|
|
6447
|
+
return this.playerClient.getNickname();
|
|
6448
|
+
}
|
|
6449
|
+
/**
|
|
6450
|
+
* Set player's nickname for the current game
|
|
6451
|
+
* @param nickname - 1-16 characters (letters, numbers, Chinese, underscores, spaces)
|
|
6452
|
+
* @returns SetNicknameResponse with success status and gameId
|
|
6453
|
+
* @throws PlayKitError if validation fails or token type is invalid
|
|
6454
|
+
*/
|
|
6455
|
+
async setNickname(nickname) {
|
|
6456
|
+
return await this.playerClient.setNickname(nickname);
|
|
6444
6457
|
}
|
|
6445
6458
|
// ============================================================
|
|
6446
6459
|
// Headless Device Auth Methods (for terminal/CLI environments)
|