Polyv Help Center

Help Center

Lottery

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

Feature Overview

This module is primarily used to handle lottery-related logic. It can listen to events such as the start and end of a lottery and submit audience winning information. The integrator can customize their own UI interface based on these event flows.

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 { Lottery } = window.PolyvIRSDK;
</script>
import { Lottery } from '@polyv/interactions-receive-sdk';

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

Usage Flow

Listen to the "Lottery Start" Event

When an initiator, such as an instructor or teaching assistant, starts a round of lottery, the lotterySdk.events.LotteryStart event is triggered. At this point, the integrator can display prompts or animations indicating that the lottery is in progress, allowing users to perceive that the lottery has begun.

lotterySdk.on(lotterySdk.events.LotteryStart, function() {
  // 处理开始抽奖
  alert('抽奖开始');
});

Listen to the "Lottery in Progress" Event

When a lottery is initiated, some audience members may not have entered the corresponding live room and thus miss the immediate event.
The integrator needs to listen to the lotterySdk.events.OnLottery event so that late-arriving audience members can also be informed of the ongoing lottery and display the corresponding status.

lotterySdk.on(lotterySdk.events.OnLottery, function() {
  // 处理开始抽奖
  alert('抽奖进行中');
});

Listen to the "Lottery End" Event

When the initiator ends a round of lottery, the lotterySdk.events.LotteryEnd event is triggered. This event also contains personal winning information, redemption codes, prize claim details, etc., for that round. The integrator can listen to this event and display the corresponding winning results and prize claim information form.

lotterySdk.on(lotterySdk.events.LotteryEnd, function(msg) {
  alert(`抽奖 id: ${msg.lotteryId}`, `是否中奖: ${msg.isWinner}`, `奖品名称:${msg.prize}`, `领奖信息:${msg.collectInfo}`);
});

Display Lottery Results

In the "Lottery End" event, the lottery results for that round can already be obtained. Additionally, the lottery SDK provides some methods to retrieve more information.

  1. Paginate to get the list of winners
const data = await lotterySdk.getWinnersList({
  pageNumber: 1,
  // 抽奖 id 可以在“抽奖结束”事件 LotteryEnd 的参数中获取
  lotteryId: 'lotteryId',
})
// 当前页码,总页数,中奖者列表
const { pageNumber, totalPages, contents } = data;
  1. Get all winning records for an individual in a specific round
// 中奖记录列表。可传参数 { channelId, sessioId, userId },若不传则按照初始化配置参数去获取数据
const data = await lotterySdk.getLotteryRecord();

Note: This method can be called immediately after the page and lottery module initialization is complete, making it easier to obtain the user's winning status in the current round.

Submit Winner Information

Based on the information obtained from the "Lottery End" event or the winning record interface, display the prize claim information form. After the user fills it out, the following interface can be used to submit the information to the system backend.

await lotterySdk.submitInfo({
  sessionId: 'sessionId',
  lotteryId: 'lotteryId',
  winnerCode: 'winnerCode',
  receiveInfo: [{ field: '', value: '' }],
});

Note

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

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