This commit is contained in:
2026-10-23 03:02:55 +07:00
parent e2f8a3302e
commit 1ce8efeef5
21 changed files with 561 additions and 46 deletions
+17 -4
View File
@@ -1,3 +1,6 @@
import { parseTimerType } from './screen-plan.js'
import { timerLabels, validQR } from '../src/utils/presentation.js'
import type { TimerType } from '../src/types/screen.js'
import { fieldError, ResponseFieldError } from './request-error.js'
import type { Controller } from './controller.js'
import type { Intent, ScreenMode } from '../src/types/screen.js'
@@ -64,8 +67,10 @@ export interface RemoteState {
volume: number
sound: boolean
text: string
qrUrl: string
timer: {
label: string
timerType?: TimerType
durationMs: number
remainingMs: number
status: 'stopped' | 'running' | 'paused' | 'finished'
@@ -99,11 +104,15 @@ export function parseRemote(value: unknown): RemoteState {
'RESULTS',
'TIMER',
'TEXT',
'QR',
'TEAMS',
],
'state.mode',
) || 1
if (![1, 2, 4, 6, 7, 8].includes(mode))
if (![1, 2, 4, 6, 7, 8, 9, 10].includes(mode))
throw fieldError('state.mode', 'актуальный режим экрана', s.mode, 'Некорректный режим экрана')
const qrUrl = text(s.qrUrl ?? '', 'state.qrUrl')
if (mode === 9 && !validQR(qrUrl, text(s.text ?? ''))) throw new Error('Некорректные параметры QR-кода')
const duration = integer(s.timerDurationSeconds ?? 600, 1, 86400, 'state.timerDurationSeconds')
const remaining = integer(
s.timerRemainingSeconds ?? 0,
@@ -192,8 +201,10 @@ export function parseRemote(value: unknown): RemoteState {
volume: integer(s.volume ?? 0, 0, 100, 'state.volume'),
sound: s.soundEnabled === true,
text: text(s.text ?? '', 'state.text').slice(0, 10000),
qrUrl,
timer: {
label: text(s.timerLabel ?? 'Перерыв', 'state.timerLabel').slice(0, 200),
timerType: parseTimerType(s.timerType),
label: text(s.timerLabel ?? timerLabels[parseTimerType(s.timerType)], 'state.timerLabel').slice(0, 200),
durationMs: duration * 1000,
remainingMs: remaining * 1000,
status: (['stopped', 'stopped', 'running', 'paused', 'finished'] as const)[timerState]!,
@@ -237,11 +248,13 @@ function applyRemoteState(controller: Controller, previous: RemoteState, next: R
(next.command >= 8 && controller.state.scene.mode !== 7) ||
next.mode !== previous.mode ||
next.text !== previous.text ||
next.qrUrl !== previous.qrUrl ||
(next.mode === 7 &&
(next.timer.label !== previous.timer.label ||
(next.timer.timerType !== previous.timer.timerType || next.timer.label !== previous.timer.label ||
next.timer.durationMs !== previous.timer.durationMs))
) {
if (next.mode === 8 && next.text.trim()) send(controller, { action: 'text', text: next.text })
if (next.mode === 9) send(controller, { action: 'qr', qrUrl: next.qrUrl, text: next.text })
else if (next.mode === 8 && next.text.trim()) send(controller, { action: 'text', text: next.text })
else send(controller, { action: 'mode', mode: next.mode })
}
if (next.mode === 7) controller.synchronizeTimer(next.timer)