up
All checks were successful
Deploy to Production / deploy (push) Successful in 9s

This commit is contained in:
lubukhu
2026-01-24 13:59:24 +07:00
parent 4262ba6277
commit c68b74d8a2

View File

@@ -1,4 +1,8 @@
var tdv_sdk = { var tdv_sdk = {
mode: 'live',
game_code: 'G120',
sdk: null, // Instance of external SenaGameSDK
// --- KHO DỮ LIỆU NỘI BỘ --- // --- KHO DỮ LIỆU NỘI BỘ ---
list: [], list: [],
currentQuestion: null, currentQuestion: null,
@@ -109,101 +113,101 @@ var tdv_sdk = {
// --- KHỞI TẠO & LOAD DỮ LIỆU --- // --- KHỞI TẠO & LOAD DỮ LIỆU ---
init: function (config) { init: function (config) {
var self = this; var self = this;
config = config || {}; config = config || {};
var urlParams = new URLSearchParams(window.location.search); var urlParams = new URLSearchParams(window.location.search);
this.mode = config.mode || urlParams.get('mode') || 'live'; this.mode = config.mode || urlParams.get('mode') || 'live';
this.game_code = config.game_code || urlParams.get('game_code') || 'SQ_SENTENCE'; this.game_code = config.game_code || urlParams.get('game_code') || 'SQ_SENTENCE';
// Auto preview // Auto preview
if (window.self === window.parent && this.mode === 'live') { if (window.self === window.parent && this.mode === 'live') {
console.log("⚠️ Standalone detected - Switching to PREVIEW"); console.log("⚠️ Standalone detected - Switching to PREVIEW");
this.mode = 'preview'; this.mode = 'preview';
} }
// Globals cho Construct 2 (GIỮ) // Globals cho Construct 2 (GIỮ)
window.answerResult = -1; window.answerResult = -1;
window.gameState = 0; window.gameState = 0;
// BG // BG
var bgParam = urlParams.get('bg'); var bgParam = urlParams.get('bg');
if (bgParam) { if (bgParam) {
this.themeSettings.current_bg = bgParam.startsWith('bg') ? bgParam : "bg" + bgParam; this.themeSettings.current_bg = bgParam.startsWith('bg') ? bgParam : "bg" + bgParam;
} }
console.log(`🚀 TDV SDK Init | Mode: ${this.mode} | Code: ${this.game_code}`); console.log(`🚀 TDV SDK Init | Mode: ${this.mode} | Code: ${this.game_code}`);
// ===== CHECK SDK ===== // ===== CHECK SDK =====
if (typeof SenaGameSDK === 'undefined') { if (typeof SenaGameSDK === 'undefined') {
console.error("❌ SenaGameSDK not found! Fallback to local default data."); console.error("❌ SenaGameSDK not found! Fallback to local default data.");
setTimeout(function () { setTimeout(function () {
self.load(self.defaultData); self.load(self.defaultData);
}, 500); }, 500);
return; return;
} }
// ===== INIT SDK ===== // ===== INIT SDK =====
this.sdk = new SenaGameSDK({ this.sdk = new SenaGameSDK({
iframePath: './sdk/package/dist/sdk-iframe/index.html', iframePath: './sdk/package/dist/sdk-iframe/index.html',
mode: this.mode, mode: this.mode,
gameCode: this.game_code, gameCode: this.game_code,
debug: true, debug: true,
// SDK sẵn sàng → push data // SDK sẵn sàng → push data
onReady: function (sdk) { onReady: function (sdk) {
console.log("✅ SDK Ready → pushing defaultData"); console.log("✅ SDK Ready → pushing defaultData");
sdk.pushData({ sdk.pushData({
items: self.defaultData.data // QUAN TRỌNG: map đúng field items: self.defaultData.data // QUAN TRỌNG: map đúng field
});
},
// SDK trả data đã xử lý
onDataReady: function (data) {
var items = data && data.items ? data.items : [];
console.log("📥 SDK DataReady:", items.length);
if (items.length > 0) {
self.serverDataLoaded = true;
self.load({
data: items,
blank_count: data.blank_count || self.defaultData.blank_count
}); });
} else { },
console.warn("⚠️ SDK returned empty items");
// SDK trả data đã xử lý
onDataReady: function (data) {
var items = data && data.items ? data.items : [];
console.log("📥 SDK DataReady:", items.length);
if (items.length > 0) {
self.serverDataLoaded = true;
self.load({
data: items,
blank_count: data.blank_count || self.defaultData.blank_count
});
} else {
console.warn("⚠️ SDK returned empty items");
}
},
// Kết quả từng câu
onAnswerResult: function (result) {
console.log("📝 Answer Result:", result);
self.handleAnswerResult(result);
},
// Game complete
onGameComplete: function (result) {
console.log("🏁 Game Complete:", result);
self.onGameFinished(result);
},
onSessionStart: function (session) {
console.log("🎮 Session:", session);
self.gameID = session.gameId;
self.userId = session.userId;
},
onError: function (error) {
console.error("❌ SDK Error:", error);
} }
}, });
// Kết quả từng câu // ===== TIMEOUT FALLBACK =====
onAnswerResult: function (result) { setTimeout(function () {
console.log("📝 Answer Result:", result); if (!self.serverDataLoaded) {
self.handleAnswerResult(result); console.warn("⚠️ SDK timeout → fallback defaultData");
}, self.load(self.defaultData);
}
// Game complete }, 5000);
onGameComplete: function (result) {
console.log("🏁 Game Complete:", result);
self.onGameFinished(result);
},
onSessionStart: function (session) {
console.log("🎮 Session:", session);
self.gameID = session.gameId;
self.userId = session.userId;
},
onError: function (error) {
console.error("❌ SDK Error:", error);
}
});
// ===== TIMEOUT FALLBACK =====
setTimeout(function () {
if (!self.serverDataLoaded) {
console.warn("⚠️ SDK timeout → fallback defaultData");
self.load(self.defaultData);
}
}, 5000);
}, },