頻道資訊
本文件主要說明 频道模块(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-miniprogram-sdk';
const scene = watchCore.channel.getChannelScene();
const isAloneChannel = scene === ChannelScene.Alone; // 普通直播频道
const isPptChannel = scene === ChannelScene.Ppt; // 三分屏频道
const isSeminarChannel = scene === ChannelScene.Seminar; // 研讨会频道
二、直播狀態
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 |
範例:
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-miniprogram-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 關閉直播狀態輪詢
Api 方法: removeLiveStatusPolling(pollingId: string): void
參數說明:
- pollingId:輪詢 id,
string類型,必傳
2.7 開始直播狀態輪詢
Api 方法: startLiveStatusPolling(pollingId?: string): string
參數說明:
- pollingId:輪詢 id,
string類型,選傳,預設...
回傳值說明: 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 取得頻道基礎資訊
根據語言類型取得頻道基礎資訊(含英文設定),如:頻道名稱、頻道介紹、主持人名稱。
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);
4.2 取得頻道場景
用於判斷頻道類型,如是否為三分屏的頻道,是否為研討會的頻道
Api 方法: getChannelScene(): ChannelScene
回傳值說明: ChannelScene 類型
範例:
import { ChannelScene } from '@polyv/live-watch-miniprogram-sdk';
const scene = watchCore.channel.getChannelScene();
const isAloneChannel = scene === ChannelScene.Alone; // 普通直播频道
const isPptChannel = scene === ChannelScene.Ppt; // 三分屏频道
const isSeminarChannel = scene === ChannelScene.Seminar; // 研讨会频道
4.3 取得渠道 id
透過後台設定的渠道進入觀看頁後,在建立觀看頁 SDK 實例時傳入 promoteId 渠道號設定,可透過該方法取得當前觀眾的渠道 id,用作其他處理。
Api 方法: getPromoteId(): undefined | string
回傳值說明: undefined | string 類型
範例:
import { createWatchCore } from '@polyv/live-watch-miniprogram-sdk';
const watchCore = createWatchCore({
channelId: '频道号',
promoteId: '渠道号',
});
// 需要重新获取渠道号时
const promoteId = watchCore.channel.getPromoteId();
4.4 取得頻道直播場次號
透過 getCurrentSessionId 方法取得當前頻道的最新場次號。
Api 方法: getCurrentSessionId(): string
回傳值說明: 最新場次號
範例:
const currentSessionId = watchCore.channel.getCurrentSessionId();
console.log('频道最新场次号', currentSessionId);
4.5 取得頻道直播狀態
用於取得頻道當前的直播狀態,透過 ChannelEvents.LiveStatusChange 事件監聽直播狀態更改事件。
Api 方法: getLiveStatus(): LiveStatus
回傳值說明: LiveStatus 類型
範例:
import { LiveStatus } from '@polyv/live-watch-miniprogram-sdk';
watchCore.channel.eventEmitter.on(ChannelEvents.LiveStatusChange, () => {
const liveStatus = watchCore.channel.getLiveStatus();
console.log('是否正在直播', liveStatus === LiveStatus.Live);
});
4.6 關閉直播狀態輪詢
Api 方法: removeLiveStatusPolling(pollingId: string): void
參數說明:
- pollingId:輪詢 id,
string類型,必傳
4.7 開始直播狀態輪詢
Api 方法: startLiveStatusPolling(pollingId?: string): string
參數說明:
- pollingId:輪詢 id,
string類型,選傳,預設...
回傳值說明: pollingId
4.8 取得觀看頁瀏覽次數
如果不需要輪詢機制來更新瀏覽次數,可呼叫 getPageViewCount 方法來重新取得觀眾進入頁面時的瀏覽次數。
Api 方法: getPageViewCount(): number
範例:
const pageViewCount = await watchCore.channel.getPageViewCount();
console.log('页面浏览次数', pageViewCount);
4.9 開啟觀看頁瀏覽次數請求輪詢
用於開啟觀看頁瀏覽次數介面請求的輪詢,在觸發回呼後更新頁面的瀏覽次數。
Api 方法: startPageViewPolling(callback?: Function): void
參數說明:
- callback:回呼函式,取得每次輪詢的瀏覽次數,
Function類型,選傳
範例:
watchCore.channel.startPageViewPolling((pageViewCount: number) => {
console.log('页面浏览次数更新:', pageViewCount);
});
4.10 停止觀看頁瀏覽次數請求輪詢
當頁面銷毀或相關元件銷毀時,呼叫 stopPageViewPolling 停止輪詢器。
Api 方法: stopPageViewPolling(): void
範例:
// vue 代码
export default {
// 组件销毁前停止定时器
beforeDestroy() {
watchCore.channel.stopPageViewPolling();
}
};
4.11 取得推流資訊
用於取得當前頻道的最新推流資訊,如流的尺寸、推流類型等。
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.12 取得觀看頁設定
用於取得管理後台設定的觀看頁設定資訊。
Api 方法: getWatchSetting(): ChannelWatchSetting
回傳值說明: 頻道觀看頁設定,ChannelWatchSetting 類型,詳細類型說明如下
| 屬性名 | 說明 | 類型 |
|---|---|---|
watchEnabled |
觀看頁開關 | boolean |
mobileWatchEnabled |
行動端觀看頁開關 | boolean |
splashEnabled |
引導頁開關 | boolean |
範例:
const setting = watchCore.channel.getWatchSetting();
if (!setting.watchEnabled) { alert('当前观看页暂未开放'); }
if (isMobile && !setting.mobileWatchEnabled) { alert('暂不支持移动端观看'); }
4.13 取得頻道佈局設定
用於取得管理後台的頁面佈局相關設定。
Api 方法: getLayoutSetting(): ChannelLayoutSetting
回傳值說明: 頻道佈局設定,ChannelLayoutSetting 類型,詳細類型說明如下
| 屬性名 | 說明 | 類型 |
|---|---|---|
mainScreenLayoutMode |
三分屏主螢幕佈局模式 | MainScreenLayoutMode |
mobileSplashLayout |
行動端引導頁佈局 | MobileSplashLayout |
mobileWatchLayout |
行動端觀看頁佈局 | MobileWatchLayout |
範例:
const setting = watchCore.channel.getLayoutSetting();
console.log('三分屏主屏布局模式:', setting.mainScreenLayoutMode);
console.log('移动端引导页布局:', setting.mobileSplashLayout);
console.log('移动端观看页页布局:', setting.mobileWatchLayout);
4.14 取得頻道皮膚主題設定
用於取得管理後台的皮膚主題設定。
Api 方法: getThemeSetting(): ChannelThemeSetting
回傳值說明: 頻道皮膚主題設定,ChannelThemeSetting 類型,詳細類型說明如下
| 屬性名 | 說明 | 類型 |
|---|---|---|
pageSkin |
觀看頁皮膚 | ChannelWatchPageSkin |
browserFavIcon |
瀏覽器標籤頁圖示 | undefined | string |
channelCoverImg |
頻道圖示圖片位址 | string |
splashImg |
引導頁封面圖 | undefined | string |
mobileSplashLargeImg |
行動端引導頁大圖 | undefined | string |
pcWatchBackgroundImage |
PC 端觀看頁背景圖 | undefined | string |
mobileChatBackgroundImage |
行動端聊天室背景圖 | undefined | string |
mobileChatBackgroundImageAmbiguity |
聊天室背景圖模糊,0 ~ 100 | undefined | number |
portraitBackgroundImage |
直式背景圖 | undefined | string |
portraitBackgroundImageAmbiguity |
直式背景圖透明度,0 ~ 100 | undefined | number |
範例:
const setting = watchCore.channel.getThemeSetting();
console.log('皮肤风格:', setting.pageSkin);
console.log('直播间图标:', setting.channelCoverImg);
4.15 取得講師資訊
用於取得當前講師/主播的資訊。
Api 方法: getTeacherInfo(): TeacherInfoType
回傳值說明: TeacherInfoType 類型
範例:
const teacherInfo = watchCore.channel.getTeacherInfo();
console.log('讲师昵称', teacherInfo.nick);
console.log('讲师头像', teacherInfo.pic);
console.log('讲师头衔', teacherInfo.actor);
4.16 取得瀏覽次數設定資訊
用於取得管理後台設定的頁面瀏覽次數資訊。
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);
4.17 取得直播倒數計時設定
用於取得後台設定的頻道開始時間等設定資訊。
Api 方法: getCountdownSetting(): ChannelCountdownSetting
回傳值說明: 倒數計時設定,ChannelCountdownSetting 類型,詳細類型說明如下
| 屬性名 | 說明 | 類型 |
|---|---|---|
liveStartTime |
直播開始時間,單位:時間戳 | undefined | number |
countdownEnabled |
倒數計時開關 | boolean |
playbackShowCountdownEnabled |
回放時是否顯示下一場倒數計時 | boolean |
範例:
