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 ...@@ -55,7 +55,7 @@ $extraJs = ['/public/js/ludo-constants.js', '/public/js/ludo-ui.js', '/public/js
</div> </div>
<script> <script>
(function() { document.addEventListener('DOMContentLoaded', function() {
var params = new URLSearchParams(window.location.search); var params = new URLSearchParams(window.location.search);
var action = params.get('action'); var action = params.get('action');
var code = params.get('code'); var code = params.get('code');
...@@ -70,6 +70,8 @@ $extraJs = ['/public/js/ludo-constants.js', '/public/js/ludo-ui.js', '/public/js ...@@ -70,6 +70,8 @@ $extraJs = ['/public/js/ludo-constants.js', '/public/js/ludo-ui.js', '/public/js
var token = session.access_token; var token = session.access_token;
var userId = session.user ? session.user.id : null; var userId = session.user ? session.user.id : null;
LudoLive.setAuth(token, userId);
if (matchId) { if (matchId) {
startLiveGame(matchId); startLiveGame(matchId);
return; return;
...@@ -96,10 +98,6 @@ $extraJs = ['/public/js/ludo-constants.js', '/public/js/ludo-ui.js', '/public/js ...@@ -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) { function initLiveConnection(id) {
LudoLive.init({ LudoLive.init({
matchId: id, matchId: id,
...@@ -187,7 +185,7 @@ $extraJs = ['/public/js/ludo-constants.js', '/public/js/ludo-ui.js', '/public/js ...@@ -187,7 +185,7 @@ $extraJs = ['/public/js/ludo-constants.js', '/public/js/ludo-ui.js', '/public/js
App.toast('تم نسخ الكود', 'success'); App.toast('تم نسخ الكود', 'success');
} }
}; };
})(); });
</script> </script>
<?php require __DIR__ . '/../includes/footer.php'; ?> <?php require __DIR__ . '/../includes/footer.php'; ?>
...@@ -30,7 +30,7 @@ $extraCss = ['/public/css/ludo.css']; ...@@ -30,7 +30,7 @@ $extraCss = ['/public/css/ludo.css'];
</style> </style>
<script> <script>
(function() { document.addEventListener('DOMContentLoaded', function() {
var session = App.getSession ? App.getSession() : null; var session = App.getSession ? App.getSession() : null;
if (!session || !session.access_token) { if (!session || !session.access_token) {
window.location.href = '/login'; window.location.href = '/login';
...@@ -87,7 +87,7 @@ $extraCss = ['/public/css/ludo.css']; ...@@ -87,7 +87,7 @@ $extraCss = ['/public/css/ludo.css'];
xhr.onload = function() { window.location.href = '/ludo'; }; xhr.onload = function() { window.location.href = '/ludo'; };
xhr.send(JSON.stringify({ action: 'matchmake', sub_action: 'leave' })); xhr.send(JSON.stringify({ action: 'matchmake', sub_action: 'leave' }));
}; };
})(); });
</script> </script>
<?php require __DIR__ . '/../includes/footer.php'; ?> <?php require __DIR__ . '/../includes/footer.php'; ?>
...@@ -338,8 +338,14 @@ var LudoLive = (function() { ...@@ -338,8 +338,14 @@ var LudoLive = (function() {
}, callback); }, callback);
} }
function setAuth(token, userId) {
state.token = token;
state.userId = userId;
}
return { return {
init: init, init: init,
setAuth: setAuth,
bindUI: bindUI, bindUI: bindUI,
fetchState: fetchState, fetchState: fetchState,
leave: leave, 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