Commit fa7328ff authored by Mahmoud Aglan's avatar Mahmoud Aglan

fix: wrap live/matchmaking pages in DOMContentLoaded, add setAuth

Scripts load after inline code in footer pattern; ensure all
LudoLive/App references are inside DOMContentLoaded callbacks.
Co-Authored-By: 's avatarClaude Opus 4.6 <noreply@anthropic.com>
parent 59d32ebf
......@@ -55,7 +55,7 @@ $extraJs = ['/public/js/ludo-constants.js', '/public/js/ludo-ui.js', '/public/js
</div>
<script>
(function() {
document.addEventListener('DOMContentLoaded', function() {
var params = new URLSearchParams(window.location.search);
var action = params.get('action');
var code = params.get('code');
......@@ -70,6 +70,8 @@ $extraJs = ['/public/js/ludo-constants.js', '/public/js/ludo-ui.js', '/public/js
var token = session.access_token;
var userId = session.user ? session.user.id : null;
LudoLive.setAuth(token, userId);
if (matchId) {
startLiveGame(matchId);
return;
......@@ -96,10 +98,6 @@ $extraJs = ['/public/js/ludo-constants.js', '/public/js/ludo-ui.js', '/public/js
});
}
// Expose token/userId for LudoLive
window.__ludoToken = token;
window.__ludoUserId = userId;
function initLiveConnection(id) {
LudoLive.init({
matchId: id,
......@@ -187,7 +185,7 @@ $extraJs = ['/public/js/ludo-constants.js', '/public/js/ludo-ui.js', '/public/js
App.toast('تم نسخ الكود', 'success');
}
};
})();
});
</script>
<?php require __DIR__ . '/../includes/footer.php'; ?>
......@@ -30,7 +30,7 @@ $extraCss = ['/public/css/ludo.css'];
</style>
<script>
(function() {
document.addEventListener('DOMContentLoaded', function() {
var session = App.getSession ? App.getSession() : null;
if (!session || !session.access_token) {
window.location.href = '/login';
......@@ -87,7 +87,7 @@ $extraCss = ['/public/css/ludo.css'];
xhr.onload = function() { window.location.href = '/ludo'; };
xhr.send(JSON.stringify({ action: 'matchmake', sub_action: 'leave' }));
};
})();
});
</script>
<?php require __DIR__ . '/../includes/footer.php'; ?>
......@@ -338,8 +338,14 @@ var LudoLive = (function() {
}, callback);
}
function setAuth(token, userId) {
state.token = token;
state.userId = userId;
}
return {
init: init,
setAuth: setAuth,
bindUI: bindUI,
fetchState: fetchState,
leave: leave,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment