保利威文档中心

幫助中心

頻道資訊

更新時間:2026-07-17 15:16:39

本文件主要說明 频道模块(channel) 提供的頻道資訊取得相關的 API 文件,詳細內容請見下文:

一、頻道資訊

1.1 取得頻道基礎資訊

根據語言類型取得頻道基礎資訊(含英文設定),如:頻道名稱、頻道介紹、主持人名稱。

Api 方法: getChannelBasicInfo(type?: LanguageType): ChannelBasicInfo

參數說明:

  • type:語言類型,LanguageType 類型,選傳,預設 'zh_CN'

回傳值說明: 頻道基礎資訊,ChannelBasicInfo 類型,詳細類型說明如下

屬性名 說明 類型
title 頻道標題 string
publisher 頻道主持人 string
description 頻道描述 string

範例:

// 获取频道的基础信息
const cnBasicInfo = watchCore.channel.getChannelBasicInfo();
console.log('频道名称', cnBasicInfo.title);
console.log('频道介绍', cnBasicInfo.description);
console.log('主持人名称', cnBasicInfo.publisher);

// 获取频道的英文基础信息
const enBasicInfo = watchCore.channel.getChannelBasicInfo('en');
console.log('英文频道名称', enBasicInfo.title);

1.2 取得頻道場景

用於判斷頻道類型,例如是否為三分螢幕的頻道,是否為研討會的頻道

Api 方法: getChannelScene(): ChannelScene

回傳值說明: ChannelScene 類型

範例:

import { ChannelScene } from '@polyv/live-watch-sdk';
const scene = watchCore.channel.getChannelScene();
const isAloneChannel = scene === ChannelScene.Alone; // 普通直播频道
const isPptChannel = scene === ChannelScene.Ppt; // 三分屏频道
const isSeminarChannel = scene === ChannelScene.Seminar; // 研讨会频道

1.3 取得目前頻道的觀看頁位址

用於取得目前觀看頁的位址。

Api 方法: getChannelWatchUrl(): string

範例:

const watchUrl = watchCore.channel.getChannelWatchUrl();
console.log('当前观看页的打开地址', watchUrl);

1.4 產生觀看頁位址

Api 方法: generateWatchUrl(channelId: string): string

參數說明:

  • channelId:頻道號,string 類型,必傳

範例:

const watchUrl = watchCore.channel.generateWatchUrl('频道号');
location.href = watchUrl;

1.5 取得講師資訊

用於取得目前講師/主講的資訊。

Api 方法: getTeacherInfo(): TeacherInfoType

回傳值說明: TeacherInfoType 類型

範例:

const teacherInfo = watchCore.channel.getTeacherInfo();
console.log('讲师昵称', teacherInfo.nick);
console.log('讲师头像', teacherInfo.pic);
console.log('讲师头衔', teacherInfo.actor);

1.6 取得渠道 id

透過後台設定的渠道進入觀看頁後,在建立觀看頁 SDK 實例時傳入 promoteId 渠道號設定,可透過該方法取得目前觀眾的渠道 id,用作其他處理。

Api 方法: getPromoteId(): undefined | string

回傳值說明: undefined | string 類型

範例:

import { createWatchCore } from '@polyv/live-watch-sdk';
const watchCore = createWatchCore({
  channelId: '频道号',
  promoteId: '渠道号',
});

// 需要重新获取渠道号时
const promoteId = watchCore.channel.getPromoteId();

1.7 取得頻道協議設定

可以取得在不同語言下的協議設定,主要用於授權類業務

Api 方法: getChannelAgreementConfig(): Promise<ChannelAgreementConfig>

從 v0.10.0 版本開始支援

回傳值說明: Promise<ChannelAgreementConfig> 類型

範例:

const agreementConfig = await watchCore.channel.getChannelAgreementConfig();
console.log('当前语言的协议配置', agreementConfig["zh_CN"]);

1.8 取得頻道的直播場景

Api 方法: getNewScene(): ChannelNewScene

從 v2.13.0 版本開始支援

回傳值說明: ChannelNewScene 類型

1.9 重設頻道詳細資訊(謹慎使用)

Api 方法: resetChannelDetail(): void

從 v2.17.0 版本開始支援

二、直播狀態

2.1 頻道直播狀態

Enum 列舉: LiveStatus

常數 列舉成員 說明
'live' LiveStatus.Live 直播中
'waiting' LiveStatus.Waiting 等待中
'end' LiveStatus.End 已結束,無直播
'playback' LiveStatus.Playback 回放中
'stop' LiveStatus.Stop 直播暫停中
'unStart' LiveStatus.UnStart 未開始

2.2 直播狀態改變事件

說明: 當主講開始/結束直播後,頻道的直播狀態都會改變,透過該事件監聽直播狀態改變

Event 事件: ChannelEvents.LiveStatusChange

回呼參數: Object 物件,詳細類型說明如下

屬性名 說明 類型
liveStatus 新的直播狀態 LiveStatus
newLiveStatus 新的直播狀態 LiveStatus
oldLiveStatus 舊的直播狀態 LiveStatus

範例:

watchCore.channel.eventEmitter.on(ChannelEvents.LiveStatusChange, (data) => {
  console.log('频道状态改变,新状态:', data.liveStatus);
});

2.3 取得頻道直播狀態

用於取得頻道目前的直播狀態,透過 ChannelEvents.LiveStatusChange 事件監聽直播狀態更改事件。

Api 方法: getLiveStatus(): LiveStatus

回傳值說明: LiveStatus 類型

範例:

import { LiveStatus } from '@polyv/live-watch-sdk';

watchCore.channel.eventEmitter.on(ChannelEvents.LiveStatusChange, () => {
  const liveStatus = watchCore.channel.getLiveStatus();
  console.log('是否正在直播', liveStatus === LiveStatus.Live);
});

2.4 場次號改變事件

說明: 主講開啟新的一次直播後,都會產生一個新的直播場次號,可以透過頻道模組的該事件監聽直播場次號改變。

Event 事件: ChannelEvents.SessionIdChange

回呼參數: Object 物件,詳細類型說明如下

屬性名 說明 類型
sessionId 新的場次號 string

範例:

watchCore.channel.eventEmitter.on(ChannelEvents.LiveStatusChange, (data) => {
  console.log('频道状态改变,新状态:', data.liveStatus);
});

2.5 取得頻道直播場次號

透過 getCurrentSessionId 方法取得目前頻道的最新場次號。

Api 方法: getCurrentSessionId(): string

回傳值說明: 最新場次號

範例:

const currentSessionId = watchCore.channel.getCurrentSessionId();
console.log('频道最新场次号', currentSessionId);

2.6 關閉直播狀態輪詢

需要和 watchCore.channel.startLiveStatusPolling 方法配合使用

Api 方法: removeLiveStatusPolling(pollingId: string): void

參數說明:

  • pollingId:輪詢 id,string 類型,必傳

範例:

const watchCore = getWatchCore();
const pollingId = watchCore.channel.startLiveStatusPolling();
watchCore.channel.removeLiveStatusPolling(pollingId);

2.7 開始直播狀態輪詢

會根據後端設定,在條件允許的情況下進行直播狀態輪詢

Api 方法: startLiveStatusPolling(pollingId?: string, options?: Object): string

參數說明:

  • pollingId:輪詢 id,string 類型,選傳,預設 ...

  • options:Object 類型,選傳,詳細類型說明如下

參數名 說明 類型 必須 預設值
timeout - number -
maxPollingCount - number -

回傳值說明: 輪詢識別位,可用作移除輪詢的參數

範例:

const watchCore = getWatchCore();
const pollingId = watchCore.channel.startLiveStatusPolling();
console.info('轮询标识位:', pollingId);

三、推流資訊

3.1 取得推流資訊

用於取得目前頻道的最新推流資訊,如流的尺寸、推流類型等。

Api 方法: getPushInfo(): Promise<StreamPushInfo>

回傳值說明: Promise<StreamPushInfo> 類型,詳細類型說明如下

屬性名 說明 類型
isNewGuide 是否導播台推流 YN
resolutionWidth 解析度寬度 number
resolutionHeight 解析度高度 number
streamType 推流類型 StreamType

範例:

const pushInfo = await watchCore.channel.getPushInfo();
console.log('流宽度', pushInfo.resolutionWidth);
console.log('流高度', pushInfo.resolutionHeight);
console.log('推流类型', pushInfo.streamType);

四、頁面瀏覽次數

4.1 取得觀看頁瀏覽次數

如果不需要輪詢機制來更新瀏覽次數,可呼叫 getPageViewCount 方法來重新取得觀眾進入頁面時的瀏覽次數。

Api 方法: getPageViewCount(): number

範例:

const pageViewCount = await watchCore.channel.getPageViewCount();
console.log('页面浏览次数', pageViewCount);

4.2 開啟觀看頁瀏覽次數請求輪詢

用於開啟觀看頁瀏覽次數介面請求的輪詢,在觸發回呼後更新頁面的瀏覽次數。

從 v1.2.0 開始在方法呼叫後立即回呼一次

Api 方法: startPageViewPolling(callback?: Function): void

參數說明:

  • callback:回呼函式,取得每次輪詢的瀏覽次數,Function 類型,選傳

範例:

watchCore.channel.startPageViewPolling((pageViewCount: number) => {
  console.log('页面浏览次数更新:', pageViewCount);
});

4.3 取得最新的觀看頁瀏覽次數

Api 方法: getLatestPageView(): Promise<number>

從 v1.2.0 版本開始支援

回傳值說明: Promise<number> 類型

4.4 停止觀看頁瀏覽次數請求輪詢

當頁面銷毀或相關元件銷毀時,呼叫 stopPageViewPolling 停止輪詢器。

Api 方法: stopPageViewPolling(): void

範例:

// vue 代码
export default {
  // 组件销毁前停止定时器
  beforeDestroy() {
    watchCore.channel.stopPageViewPolling();
  }
};

4.5 取得瀏覽次數設定資訊

用於取得管理後台設定的頁面瀏覽次數資訊。

Api 方法: getPageViewSetting(): PageViewSetting

回傳值說明: 頁面瀏覽次數設定,PageViewSetting 類型,詳細類型說明如下

屬性名 說明 類型
pvShowEnabled 頁面瀏覽次數開關 boolean
pageViewCount 頁面瀏覽次數 number
mobilePvShowLocation 行動端頁面瀏覽次數位置 PageViewShowLocation

範例:

const setting = watchCore.channel.getPageViewSetting();
console.log('页面浏览次数开关', setting.pvShowEnabled);
console.log('页面浏览次数', setting.pageViewCount);
console.log('移动端浏览次数位置', setting.mobilePvShowLocation);

五、直播開始時間

5.1 取得直播倒數計時設定

用於取得後台設定的頻道開始時間等設定資訊。

Api 方法: getCountdownSetting(): ChannelCountdownSetting

回傳值說明: 倒數計時設定,ChannelCountdownSetting 類型,詳細類型說明如下

屬性名 說明 類型
liveStartTime 直播開始時間,單位:時間戳 undefined | number
countdownEnabled 倒數計時開關 boolean
playbackShowCountdownEnabled 回放時是否顯示下一場倒數計時 boolean

範例:

const setting = watchCore.channel.getCountdownSetting();
console.log('开始时间:', setting.liveStartTime);
console.log('回放下是否显示倒计时:', setting.playbackShowCountdownEnabled);

六、觀看時長

6.1 取得觀看時長設定

Api 方法: getWatchDurationSetting(): ChannelWatchDurationSetting

從 v0.8.0 版本開始支援

回傳值說明: ChannelWatchDurationSetting 類型,詳細類型說明如下

屬性名 說明 類型
watchDurationEnabled 觀看時長開關 boolean
watchDurationType 觀看時長類型 string

6.2 結束觀看時長統計輪詢

Api 方法: stopWatchDurationStatsPolling(): void

從 v0.8.0 版本開始支援

6.3 開始觀看時長統計輪詢

Api 方法: startWatchDurationStatsPolling(): void

從 v0.8.0 版本開始支援

七、系列直播(直播新場次)

7.1 取得直播新場次開關

Api 方法: getTargetSessionEnabled(): boolean

從 v2.4.0 版本開始支援

7.2 取得頻道場次列表

Api 方法: getChannelSessionList(params?: GetChannelSessionListParams): Promise<PageContent<ChannelSessionDataItem>>

參數說明:

  • params:GetChannelSessionListParams 類型,選傳,詳細類型說明如下
參數名 說明 類型 必須 預設值
pageNumber - number -
pageSize - number -
status - string -
order - string -
chapterId 章節id(可選,傳入時僅回傳該章節下的場次) number -

回傳值說明: Promise<PageContent<ChannelSessionDataItem>> 類型

7.3 取得頻道場次章節列表

Api 方法: getChannelSessionChapterList(): Promise<ChannelSessionChapter[]>

從 v2.18.0 版本開始支援

回傳值說明: Promise<ChannelSessionChapter[]> 類型

八、主講資訊

8.1 取得主講資訊

Api 方法: getAnchorInfo(): Promise<undefined | ChannelAnchorInfo>

從 v2.13.0 版本開始支援

回傳值說明: Promise<undefined | ChannelAnchorInfo> 類型

联系客服,在线咨询