Polyv Help Center

Help Center

Answer Card

Updated: 2024-04-22 19:18:32

Feature Overview

This module is primarily used to receive and process answer cards initiated by users such as instructors, teaching assistants, and administrators. It facilitates the integration party in implementing features like question display, audience answering, and result presentation.

Answer cards are divided into Quick Quiz and Normal Quiz.

  • Quick Quiz only supports single-choice/multiple-choice question formats.
  • Normal Quiz has more comprehensive features, including single-choice, multiple-choice, rating, and voting questions. It also supports a time-limited answering feature, requiring respondents to answer within a specified time.

Initialization and Destruction

Before instantiating and using this module, the SDK must be initialized and configured. For details, see the Reference Documentation.

Online File Import Method

// script 标签引入,根据版本号引入JS版本。
<script src="https://websdk.videocc.net/interactions-receive-sdk/0.24.0/lib/polyv-ir.umd.js"></script>

<script>
    const { AnswerCard } = window.PolyvIRSDK;
</script>
import { AnswerCard } from '@polyv/interactions-receive-sdk';

const answerCardSdk = new AnswerCard();
// ...
// 销毁 SDK 实例,清除逻辑
answerCardSdk.destroy();

Usage Flow

Listen for the "Answer Start" Event

When an initiator (e.g., instructor/assistant) starts an answer card, the SDK triggers the answerCardSdk.events.GET_TEST_QUESTION_CONTENT event. This event contains information about the answer card, including the card type, questions, options, and whether it is time-limited. This information can be displayed to users for answering.

answerCardSdk.on(answerCardSdk.events.GET_TEST_QUESTION_CONTENT, function(msg) {
  console.log('接收到答题开始事件', msg,'题目:', msg.name, '题目限时:', msg.duration);
});

When displaying answer card questions, different displays can be used based on the answer card type and question type:

  • The attributes under answerCardSdk.questionItemTypes represent the list of answer card types (Quick Quiz, Normal Quiz). Compare its attribute value with the value of msg.itemType to determine the current answer card type.
  • The attributes under answerCardSdk.questionTypes represent the specific question types (single-choice, multiple-choice, rating, or voting). Compare its attribute value with the value of msg.type to determine the specific question type.

For example:

function questionHandler(msg) {
  if (msg.itemType === answerCardSdk.questionItemTypes.QuickAnswerCard) {
    const questionType = {
      [answerCardSdk.questionTypes.CheckBox]: '多选题',
      [answerCardSdk.questionTypes.Radio]: '单选题',
    }[msg.type];
    console.log('本次答题卡为快速问答, 题目类型为: ' + questionType);
  } else if (msg.itemType === answerCardSdk.questionItemTypes.Normal) {
    const questionType = {
      [answerCardSdk.questionTypes.CheckBox]: '多选题',
      [answerCardSdk.questionTypes.Radio]: '单选题',
      [answerCardSdk.questionTypes.Score]: '评分题',
      [answerCardSdk.questionTypes.Vote]: '投票题',
    }[msg.type];
    console.log('本次答题卡为普通答题, 题目类型为: ' + questionType);
  }
}
answerCardSdk.on(answerCardSdk.events.GET_TEST_QUESTION_CONTENT, questionHandler);

For time-limited questions, use answerCardSdk.getServerTime() to obtain the current remaining time from the server and synchronize it when necessary.

const data = await answerCardSdk.getServerTime();
console.log('剩余时间', data.time);

Submit User Answers

If a quiz is currently in progress, use answerCardSdk.answerQuestion to submit the user's answers to the server. This is an asynchronous method. The parameter is an array of strings (uppercase) representing the user's selected options. Display different prompt messages based on the code field in the returned result. The statuses represented by the code values are described in the API documentation under the attributes of answerCardSdk.answerQuestionResCode.

const res = await answerCardSdk.answerQuestion(['A', 'B']);
if (res.code === answerCardSdk.answerQuestionResCode.SubmitSuccess) {
  console.log('提交成功');
}

Listen for the "Answer End" Event

When the initiator stops the quiz, or when the countdown for a time-limited question ends, answerCardSdk.events.STOP_TEST_QUESTION is triggered. At this point, the currently displayed question should be closed, or a prompt indicating that answering has ended should be shown.

answerCardSdk.on(answerCardSdk.events.STOP_TEST_QUESTION, function(msg) {
  console.log('答题结束', msg);
});

Listen for the "Answer Result" Event

After the instructor sends the results, the SDK triggers the answerCardSdk.events.GET_TEST_QUESTION_RESULT event. This event contains the question content, correct answers, and the number of respondents per option. Based on this information, it can be compared with the user's personal answers to display the user's quiz results.

answerCardSdk.on(answerCardSdk.events.GET_TEST_QUESTION_RESULT, function(msg) {
  console.log('答题结果', msg);
});

Use answerCardSdk.curSubmittedAnswer (string type) to obtain the user's submitted answer for the current question and compare it with the correct answer.

Note

If the answer card SDK is no longer needed, call the destroy method of the SDK instance to destroy it.

联系客服,在线咨询
在线咨询