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 = {
mode: 'live',
game_code: 'G120',
sdk: null, // Instance of external SenaGameSDK
// --- KHO DỮ LIỆU NỘI BỘ ---
list: [],
currentQuestion: null,
@@ -109,101 +113,101 @@ var tdv_sdk = {
// --- KHỞI TẠO & LOAD DỮ LIỆU ---
init: function (config) {
var self = this;
config = config || {};
var urlParams = new URLSearchParams(window.location.search);
var self = this;
config = config || {};
var urlParams = new URLSearchParams(window.location.search);
this.mode = config.mode || urlParams.get('mode') || 'live';
this.game_code = config.game_code || urlParams.get('game_code') || 'SQ_SENTENCE';
this.mode = config.mode || urlParams.get('mode') || 'live';
this.game_code = config.game_code || urlParams.get('game_code') || 'SQ_SENTENCE';
// Auto preview
if (window.self === window.parent && this.mode === 'live') {
console.log("⚠️ Standalone detected - Switching to PREVIEW");
this.mode = 'preview';
}
// Auto preview
if (window.self === window.parent && this.mode === 'live') {
console.log("⚠️ Standalone detected - Switching to PREVIEW");
this.mode = 'preview';
}
// Globals cho Construct 2 (GIỮ)
window.answerResult = -1;
window.gameState = 0;
// Globals cho Construct 2 (GIỮ)
window.answerResult = -1;
window.gameState = 0;
// BG
var bgParam = urlParams.get('bg');
if (bgParam) {
this.themeSettings.current_bg = bgParam.startsWith('bg') ? bgParam : "bg" + bgParam;
}
// BG
var bgParam = urlParams.get('bg');
if (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 =====
if (typeof SenaGameSDK === 'undefined') {
console.error("❌ SenaGameSDK not found! Fallback to local default data.");
setTimeout(function () {
self.load(self.defaultData);
}, 500);
return;
}
// ===== CHECK SDK =====
if (typeof SenaGameSDK === 'undefined') {
console.error("❌ SenaGameSDK not found! Fallback to local default data.");
setTimeout(function () {
self.load(self.defaultData);
}, 500);
return;
}
// ===== INIT SDK =====
this.sdk = new SenaGameSDK({
iframePath: './sdk/package/dist/sdk-iframe/index.html',
mode: this.mode,
gameCode: this.game_code,
debug: true,
// ===== INIT SDK =====
this.sdk = new SenaGameSDK({
iframePath: './sdk/package/dist/sdk-iframe/index.html',
mode: this.mode,
gameCode: this.game_code,
debug: true,
// SDK sẵn sàng → push data
onReady: function (sdk) {
console.log("✅ SDK Ready → pushing defaultData");
sdk.pushData({
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
// SDK sẵn sàng → push data
onReady: function (sdk) {
console.log("✅ SDK Ready → pushing defaultData");
sdk.pushData({
items: self.defaultData.data // QUAN TRỌNG: map đúng field
});
} 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
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);
}
});
// ===== TIMEOUT FALLBACK =====
setTimeout(function () {
if (!self.serverDataLoaded) {
console.warn("⚠️ SDK timeout → fallback defaultData");
self.load(self.defaultData);
}
}, 5000);
// ===== TIMEOUT FALLBACK =====
setTimeout(function () {
if (!self.serverDataLoaded) {
console.warn("⚠️ SDK timeout → fallback defaultData");
self.load(self.defaultData);
}
}, 5000);
},