Session State & Types
Session State
The player uses SessionState to track the learner’s progress through a lesson. This includes:
- Current position in the lesson
- History of visited steps with variable snapshots
- Widget states for each step (for resume/review)
SessionState Structure
interface SessionState {
version: 1;
lessonId: string;
currentHistoryIndex: number;
stepHistory: StepVisit[];
progress: LessonProgress;
currentVariables: Record<string, string | number | boolean>;
createdAt: string;
updatedAt: string;
}
interface StepVisit {
visitId: string;
stepId: string;
sectionIndex: number;
stepIndex: number;
variableSnapshot: Record<string, string | number | boolean>;
widgetStates: Record<string, unknown>;
itemStates: ItemState[];
visitedAt: string;
}CompletionResult
Sent via onComplete when the lesson finishes:
interface CompletionResult {
/** Final variable values at lesson completion */
finalVariables: Record<string, unknown>;
/** Final progress state */
progress: LessonProgress;
/** Total score achieved (if items had scores) */
score?: number;
/** Maximum possible score */
maxScore?: number;
/** All items from the lesson */
items?: ItemData[];
/** Full session state for review mode */
sessionState: SessionState;
}TypeScript Types
Import types from the package:
import type {
TeachariumPlayerProps,
TeachariumLessonExport,
SessionState,
CompletionResult,
LessonProgress,
PlayerConfig,
MediaResolverConfig,
} from "@teacharium/player";