Quiz API
In-class quiz management: teacher creates questions, students submit answers.
API Reference
getQuizStat()
Get quiz statistics (teacher side; call after stopping the quiz).
| Parameter | Type | Description |
|---|---|---|
| questionId | string | Question ID |
Returns: Promise<TResult<QuizStat>>
startQuiz()
Start a quiz (teacher side). All students receive TEvent.QUESTION_BEGIN and enter the answering state.
Status is reflected via state.quizStatus$ / state.currentQuizId$; students answer via submitAnswer().
| Parameter | Type | Description |
|---|---|---|
| param | StartQuizParam | Quiz parameters (question ID, type, option count, duration, etc.) |
Returns: Promise<TResult<void>>
Example:
ts
await classroom.startQuiz({
questionId: `q_${Date.now()}`, // 业务自定义题目 ID / business-defined ID
type: 1, // 题型(业务约定)/ question type (business-defined)
optionNumber: 4, // ABCD 四选项 / four options
duration: 60, // 60 秒答题 / 60s timer
});stopQuiz()
Stop a quiz (teacher side); after stopping, call getQuizStat() to view statistics.
| Parameter | Type | Description |
|---|---|---|
| questionId | string | Question ID to stop |
Returns: Promise<TResult<void>>
Example:
ts
await classroom.stopQuiz('q_001');
const stat = await classroom.getQuizStat('q_001');
if (stat.ok) renderQuizResult(stat.data);submitAnswer()
Submit an answer (student side).
| Parameter | Type | Description |
|---|---|---|
| questionId | string | Question ID (from TEvent.QUESTION_BEGIN payload) |
| answer | string | Answer content (choice: option ID(s); subjective: free text) |
Returns: Promise<TResult<void>>
Example:
ts
classroom.on(TEvent.QUESTION_BEGIN, async ({ questionId }) => {
const userChoice = await getUserAnswer();
await classroom.submitAnswer(questionId, userChoice); // 例如 'A'
});