Polyv Help Center

Help Center

Topic PK

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

Feature Overview

This module is used to handle logic related to topic PK.

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

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

Usage Flow

Listening to the "Topic Start" Event

After starting a topic in the Polyv backend, the topicSdk.events.TOPIC_START event is triggered. The event parameters include the topic PK ID and content. The integrator can listen to this event and display content accordingly.

topicSdk.on(topicSdk.events.TOPIC_START, function(msg) {
  console.log('话题开始:', msg);
});

Listening to the "Topic End" Event

When the topic is ended in the Polyv backend, the topicSdk.events.TOPIC_OVER event is triggered. Display the topic end content accordingly.

topicSdk.on(topicSdk.events.TOPIC_OVER, function(msg) {
  console.log('话题结束:', msg);
});

Listening to the "Topic Statistics" Event

After other viewers select a stance (for or against), the topicSdk.events.TOPIC_UPDATE_DATA event is triggered. The event parameters include the statistics of supporters and opponents.

topicSdk.on(topicSdk.events.TOPIC_UPDATE_DATA, function(data) {
  console.log('话题统计:', data);
});

Listening to the "Topic Deletion" Event

When the topic is deleted in the Polyv backend, the topicSdk.events.TOPIC_DELETE event is triggered. The integrator can use the ID to determine whether the currently displayed topic has been deleted.

topicSdk.on(topicSdk.events.TOPIC_DELETE, function(msg) {
  console.log('话题删除:', msg);
});

Listening to the "Topic Widget Entry Visibility" Event

When the topic toggle is switched in the Polyv backend, the topicSdk.events.TOPIC_CHANGE_ENTRANCE event is triggered. The integrator can determine whether the widget entry is currently hidden.

topicSdk.on(topicSdk.events.TOPIC_CHANGE_ENTRANCE, function(msg) {
    // 挂件入口
    // this.entranceVisible = msg.entranceEnable;
    console.log('挂件入口状态:', msg);
});

Note

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

联系客服,在线咨询