KOHAMI Docs
ReferenceEvents Catalog

Quiz — question

Auto-généré par scripts/gen-events-catalog.ts depuis le schéma Zod canonique dans packages/shared/src/events/widget-data-events.ts. Ne pas éditer ce fichier à la main — modifier la source puis relancer bun run gen:events.

Topic

quiz:question
  • Famille : Games
  • Bloc d'origine : BLOC-06
  • Discriminant : kind: "quiz:question"

Description

Question de quiz cognitif à choix multiple (2 à 4 réponses, exactement 1 correcte). L'id sert de pilote pour reset de l'UI.

Schéma JSON

{
  "$ref": "#/definitions/quiz-question",
  "definitions": {
    "quiz-question": {
      "type": "object",
      "properties": {
        "kind": {
          "type": "string",
          "const": "quiz:question"
        },
        "question": {
          "type": "object",
          "properties": {
            "id": {
              "type": "string",
              "minLength": 1,
              "maxLength": 64
            },
            "prompt": {
              "type": "string",
              "minLength": 1,
              "maxLength": 512
            },
            "answers": {
              "type": "array",
              "items": {
                "type": "object",
                "properties": {
                  "id": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 64
                  },
                  "text": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 256
                  },
                  "isCorrect": {
                    "type": "boolean"
                  }
                },
                "required": [
                  "id",
                  "text",
                  "isCorrect"
                ],
                "additionalProperties": false
              },
              "minItems": 2,
              "maxItems": 4
            }
          },
          "required": [
            "id",
            "prompt",
            "answers"
          ],
          "additionalProperties": false
        }
      },
      "required": [
        "kind",
        "question"
      ],
      "additionalProperties": false
    }
  },
  "$schema": "http://json-schema.org/draft-07/schema#"
}

Import TypeScript

import {
  QuizQuestionEventSchema,
  type QuizQuestionEvent,
} from "@kohami/shared";

Parsing côté tablette

import { QuizQuestionEventSchema } from "@kohami/shared";

room.on(RoomEvent.DataReceived, (payload, _participant, _kind, topic) => {
  if (topic !== "quiz:question") return;
  const raw = new TextDecoder().decode(payload);
  const event = QuizQuestionEventSchema.parse(JSON.parse(raw));
  // ... handle event
});