Polyv Help Center

Help Center

Questionnaire

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

Overview

This module is used to handle questionnaire operations for users such as instructors, teaching assistants, and administrators. It can listen to events like "Start Questionnaire" and "Questionnaire Results", as well as perform answer submission operations on the viewer side.

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 src="https://websdk.videocc.net/interactions-receive-sdk/0.24.0/lib/polyv-ir.umd.js"></script>

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

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

Usage Flow

Listening to the "Start Questionnaire" Event

When this event is received, it indicates that the instructor has initiated a questionnaire. The message parameters contain the detailed content of the questionnaire. The integrator can use the data fields to display the complete questionnaire to the viewers.

questionnaireSdk.on(questionnaireSdk.events.START_QUESTIONNAIRE, (msg) => {
  console.log('收到问卷消息', msg);
});

Submitting User Answers

After the viewer answers the questions, pass the answers as a string array into the answerQuestion method to submit the answers to the server. This method is asynchronous and returns a specific processing result status code. The possible statuses include successful submission, questionnaire ended, and answer already submitted. Based on this status code, you can prompt the user whether the submission was successful. All status enumerations can be accessed via questionnaireSdk.answerQuestionResCode.

/**
   * 提交问卷
   * @param answers 提交问卷答案, 字符串数组如:
     [
        {"questionId":"bab16ae6ce", "answer": "A"},
        {"questionId":"4a9f9e3139", "answer": "AB"}
     ]
   * @param questionnaireId 问卷Id
   * @returns 状态码
*/
// 单选题答案格式 [{"questionId":"bab16ae6ce", "answer": "A"}]
// 多选题答案格式 [{"questionId":"4a9f9e3139", "answer": "AB"}]
// 判断题答案格式 [{"questionId":"4a9f9e3139", "answer": "A"}]
// 问答题答案格式 [{"questionId":"4a9f9e3139", "answer": "你好"}]
// 评星题(五星)答案格式 [{"questionId":"4a9f9e3139", "answer": "A"}] A 一颗星, B 两颗星, C 三颗星,D 四颗星, E 五颗星
// 评分题(10分)答案格式 [{"questionId":"4a9f9e3139", "answer": "A"}] A 一分, B 两分... 以此类推 J 10分
const res = await questionnaireSdk.answerQuestion(answers: string[], questionnaireId: string);{"questionId":"4a9f9e3139", "answer": "AB"}]);
if (res.code === questionnaireSdk.answerQuestionResCode.SubmitSuccess) {
  console.log('提交成功');
}

Listening to the "End Questionnaire" Event

When this event is received, the questionnaire has ended, and viewers can no longer submit answers. The questionnaire should be hidden.

questionnaireSdk.on(questionnaireSdk.events.STOP_QUESTIONNAIRE, (msg) => {
    console.log('收到问卷结束消息', msg);
});

Listening to the "Questionnaire Results" Event and "Questionnaire Statistics" Event

If the current questionnaire includes scored questions with correct answers, and some users have submitted their answers, the instructor can use the "Send Results" function after the questionnaire ends, allowing viewers to view the questionnaire answers and their own responses.
To display the questionnaire response status on the viewer side, listen to these two events — SEND_QUESTIONNAIRE_RESULT and QUESTIONNAIRE_ACHIEVEMENT.
Note: The trigger order of these two events is not fixed. If the interface content depends on both events, ensure that data from both events is received and recorded before proceeding with subsequent processing.

  • Questionnaire Results Event
    This event contains detailed information such as the questionnaire title, question list, and correct answers. It can be used to display the questionnaire again. For specific fields, refer to typedoc.
questionnaireSdk.on(questionnaireSdk.events.SEND_QUESTIONNAIRE_RESULT, (msg) => {
  console.log('收到问卷结果事件:', msg);
});
  • Questionnaire Statistics Event
    This event contains the current viewer's question statistics and personal response status for this questionnaire. It can be used to display the specific response status. For specific fields, refer to typedoc.
questionnaireSdk.on(questionnaireSdk.events.QUESTIONNAIRE_ACHIEVEMENT, (msg) => {
  console.log('收到问卷统计事件:', msg);
});

Note

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

联系客服,在线咨询