Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 58 additions & 14 deletions public/classroom_poc.html
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,11 @@ <h1 class="text-3xl font-extrabold bg-gradient-to-r from-teal-400 to-emerald-300
</header>

<!-- Main Content -->
<div class="flex-1 flex overflow-hidden">
<div class="flex-1 flex flex-col lg:flex-row overflow-hidden min-h-0">

<!-- Classroom Canvas -->
<div class="flex-1 flex flex-col p-3 gap-3 min-w-0">
<div id="classroomCanvas" class="flex-1 relative rounded-xl overflow-hidden border border-gray-800 shadow-2xl" style="min-height:400px;">
<div class="flex-1 flex flex-col p-3 gap-3 min-w-0 min-h-0">
<div id="classroomCanvas" class="flex-1 min-h-[280px] lg:min-h-[400px] relative rounded-xl overflow-hidden border border-gray-800 shadow-2xl">
<!-- Walls -->
<div class="absolute inset-0" style="background: linear-gradient(180deg, #E6E2D7 0%, #E6E2D7 38%, #C7B299 38%, #C7B299 100%);"></div>
<!-- Wainscoting line -->
Expand Down Expand Up @@ -149,7 +149,7 @@ <h1 class="text-3xl font-extrabold bg-gradient-to-r from-teal-400 to-emerald-300
</div>
</div>
<!-- Controls bar -->
<div class="flex items-center gap-4 px-3 py-2 bg-gray-900/60 rounded-lg border border-gray-800 text-xs text-gray-400 shrink-0">
<div class="flex flex-wrap items-center gap-3 px-3 py-2 bg-gray-900/60 rounded-lg border border-gray-800 text-xs text-gray-400 shrink-0">
<div class="flex items-center gap-1.5">
<kbd class="px-1.5 py-0.5 bg-gray-800 rounded text-[10px] font-mono border border-gray-700">↑</kbd>
<kbd class="px-1.5 py-0.5 bg-gray-800 rounded text-[10px] font-mono border border-gray-700">↓</kbd>
Expand All @@ -161,12 +161,12 @@ <h1 class="text-3xl font-extrabold bg-gradient-to-r from-teal-400 to-emerald-300
<kbd class="px-1.5 py-0.5 bg-gray-800 rounded text-[10px] font-mono border border-gray-700">E</kbd>
<span>Sit/Stand</span>
</div>
<div class="ml-auto text-gray-500">Virtual Classroom</div>
<div class="w-full sm:w-auto sm:ml-auto text-gray-500">Virtual Classroom</div>
</div>
</div>

<!-- Chat Sidebar -->
<div id="chatPanel" class="w-80 shrink-0 bg-gray-900/70 border-l border-gray-800 flex flex-col">
<div id="chatPanel" class="w-full lg:w-80 h-64 lg:h-auto shrink-0 bg-gray-900/70 border-t lg:border-t-0 lg:border-l border-gray-800 flex flex-col">
<div class="px-4 py-3 border-b border-gray-800 flex items-center gap-2">
<i data-lucide="message-circle" class="w-4 h-4 text-teal-400"></i>
<h2 class="text-sm font-semibold text-gray-200">Room Chat</h2>
Expand Down Expand Up @@ -293,6 +293,21 @@ <h2 class="text-sm font-semibold flex items-center gap-2">

const STORAGE_PARTICIPANT_KEY = 'classroom_participant_id';
const STORAGE_AUTH_USER_KEY = 'edu_user';
const searchParams = new URLSearchParams(window.location.search);

function sanitizeRoomId(value) {
return String(value || '')
.trim()
.replace(/[^a-zA-Z0-9_-]/g, '')
.slice(0, 64);
}

function sanitizeDisplayName(value) {
return String(value || '')
.replace(/[\u0000-\u001F\u007F]/g, '')
.trim()
.slice(0, 48);
}

function generateOpaqueId() {
if (window.crypto?.randomUUID) {
Expand Down Expand Up @@ -331,6 +346,19 @@ <h2 class="text-sm font-semibold flex items-center gap-2">
return getStoredUserParticipantId() || getStoredAnonParticipantId();
}

function getPreferredDisplayName() {
const queryName = sanitizeDisplayName(searchParams.get('name') || '');
if (queryName) return queryName;
try {
const user = JSON.parse(localStorage.getItem(STORAGE_AUTH_USER_KEY) || 'null');
if (user?.name) return sanitizeDisplayName(user.name);
if (user?.username) return sanitizeDisplayName(user.username);
} catch (_) {
// Ignore malformed user payload.
}
return '';
}

// Desk rendering
const DESK_ROWS = 3;
const DESK_COLS = 5;
Expand Down Expand Up @@ -385,13 +413,15 @@ <h2 class="text-sm font-semibold flex items-center gap-2">
function refreshIcons() { try { lucide.createIcons(); } catch(_) {} }

// Join / Leave
btnJoin.addEventListener('click', async () => {
function joinClassroom() {
intentionalDisconnect = false;
reconnectAttempts = 0;
isSeated = false;
currentSeat = null;
roomId = lobbyRoomId.value.trim() || 'demo-room';
myDisplayName = lobbyDisplayName.value.trim() || `User-${Math.random().toString(36).slice(2,6)}`;
roomId = sanitizeRoomId(lobbyRoomId.value) || 'demo-room';
myDisplayName = sanitizeDisplayName(lobbyDisplayName.value) || `User-${Math.random().toString(36).slice(2,6)}`;
lobbyRoomId.value = roomId;
lobbyDisplayName.value = myDisplayName;
myParticipantId = resolveParticipantId();

topRoomId.textContent = roomId;
Expand All @@ -406,9 +436,11 @@ <h2 class="text-sm font-semibold flex items-center gap-2">
connectWS();
startGameLoop();
refreshIcons();
});
}

btnJoin.addEventListener('click', joinClassroom);

lobbyDisplayName.addEventListener('keydown', (e) => { if (e.key === 'Enter') btnJoin.click(); });
lobbyDisplayName.addEventListener('keydown', (e) => { if (e.key === 'Enter') joinClassroom(); });
lobbyRoomId.addEventListener('keydown', (e) => { if (e.key === 'Enter') lobbyDisplayName.focus(); });

btnLeave.addEventListener('click', () => {
Expand Down Expand Up @@ -848,11 +880,23 @@ <h2 class="text-sm font-semibold flex items-center gap-2">
return div.innerHTML;
}

// Init Lucide icons and auto-focus
// Init Lucide icons and entry behavior
refreshIcons();
lobbyDisplayName.focus();
const preferredName = getPreferredDisplayName();
if (preferredName) lobbyDisplayName.value = preferredName;

const initialRoom = sanitizeRoomId(searchParams.get('room') || '');
if (initialRoom) lobbyRoomId.value = initialRoom;

const shouldAutoJoin = searchParams.get('autojoin') === '1';
if (shouldAutoJoin && btnJoin) {
if (!lobbyRoomId.value) lobbyRoomId.value = 'lobby';
joinClassroom();
} else {
lobbyDisplayName.focus();
}
})();
</script>

</body>
</html>
</html>
8 changes: 4 additions & 4 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,9 @@ <h2 class="text-2xl font-bold mb-2">Global Virtual Classroom</h2>
</div>
<span>21 learners inside</span>
</div>
<button class="w-full bg-white text-teal-700 font-bold px-6 py-3 rounded-xl hover:bg-teal-50 transition-all shadow-lg flex items-center justify-center gap-2">
<i class="fas fa-door-open"></i> Sign in to Join
</button>
<a href="/classroom_poc.html?autojoin=1&room=lobby" class="w-full bg-white text-teal-700 font-bold px-6 py-3 rounded-xl hover:bg-teal-50 transition-all shadow-lg flex items-center justify-center gap-2">
<i class="fas fa-door-open"></i> Join Lobby Classroom
</a>
</div>
</div>
</div>
Expand Down Expand Up @@ -653,4 +653,4 @@ <h2 class="text-xl font-semibold flex items-center mb-4">

<script src="/js/layout.js" defer></script>
</body>
</html>
</html>
Loading