Polyv Help Center

Help Center

Quick Answer Feature

Updated: 2021-12-28 13:02:24

Feature Overview

  • This feature is only supported for instructors and does not support real-time synchronized operations across multiple roles.
  • Supports setting a countdown time. The audience must answer before the countdown ends.
  • Supports early termination.
  • Allows querying the quick answer leaderboard.

Code Example

Note: Global initialization settings must be completed before starting the following steps. Please refer to the documentation.

Example Code

const app = new RushAnswer();
// 抢答状态。
const appData = {
  // 抢答题 id
  rushAnswerId: '',
  // 剩余时间。单位:秒。
  overTime: 0,
  // 提交人数。
  answerNum: 0,
};
// 定时器。
let timer = 0;
// 清理定时器。
function clearTimer() {
  if (!timer) return;
  clearTimeout(timer);
  timer = 0;
}
// 判断倒计时是否结束,未结束情况下每秒获取最新抢答状态。
async function updateStatus() {
  clearTimer();
  // 获取当前抢答状态
  const { ongoingStatus, overTime, answerNum, rushAnswerId } = await app.getStatus();
  // 是否正在进行抢答
  if (ongoingStatus) {
    appData = Object.assign(appData, { overTime, answerNum, rushAnswerId });
    timer = setTimeout(updateStatus, 1000);
  } else {
    appData = Object.assign(appData, { overTime: 0 });
  }
}

// 开始抢答。
const startResult = await app.start(30);

// 获取抢答状态。
updateStatus();

// 结束抢答。
app.stop(appData.rushAnswerId);
// 获取已回答的观众列表。
const result = await app.getAnswerList(appData.rushAnswerId);

Flowchart

img_1.png

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