fix: тема доски синхронизируется между учителем и учениками в реальном времени
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -22,6 +22,7 @@ const GUEST_EVENTS = new Set([
|
||||
'classroom_stroke_updated', 'classroom_page_added', 'classroom_page_changed',
|
||||
'classroom_template_changed', 'classroom_page_cleared', 'classroom_page_renamed',
|
||||
'classroom_page_duplicated', 'classroom_page_deleted', 'classroom_ended',
|
||||
'classroom_board_theme',
|
||||
]);
|
||||
|
||||
/* ── Helper: broadcast to all session participants ─────────────────────── */
|
||||
@@ -490,6 +491,21 @@ function updatePageTemplate(req, res) {
|
||||
res.json({ ok: true, template });
|
||||
}
|
||||
|
||||
/* PATCH /api/classroom/:id/board-theme — change board theme and broadcast to all */
|
||||
function updateBoardTheme(req, res) {
|
||||
const sessionId = Number(req.params.id);
|
||||
const VALID_THEMES = new Set(['chalkboard', 'blackboard', 'whiteboard', 'dark', 'grid', 'dots']);
|
||||
const { theme } = req.body;
|
||||
if (!theme || !VALID_THEMES.has(theme)) return res.status(400).json({ error: 'invalid theme' });
|
||||
const session = db.prepare(`SELECT * FROM classroom_sessions WHERE id=? AND status='active'`).get(sessionId);
|
||||
if (!session) return res.status(404).json({ error: 'Сессия не активна' });
|
||||
if (session.teacher_id !== req.user.id && req.user.role !== 'admin')
|
||||
return res.status(403).json({ error: 'Нет доступа' });
|
||||
db.prepare('UPDATE classroom_sessions SET board_theme=? WHERE id=?').run(theme, sessionId);
|
||||
emitToSession(sessionId, { type: 'classroom_board_theme', sessionId, theme });
|
||||
res.json({ ok: true, theme });
|
||||
}
|
||||
|
||||
/* POST /api/classroom/:id/hand — raise hand */
|
||||
function raiseHand(req, res) {
|
||||
const sessionId = Number(req.params.id);
|
||||
@@ -1521,6 +1537,7 @@ module.exports = {
|
||||
addPage,
|
||||
changePage,
|
||||
updatePageTemplate,
|
||||
updateBoardTheme,
|
||||
getPages,
|
||||
renamePage,
|
||||
duplicatePage,
|
||||
|
||||
Reference in New Issue
Block a user