Channel Information
This document primarily describes the API documentation related to obtaining channel information provided by 频道模块(channel). Details are as follows:
1. Channel Information
1.1 Get Channel Basic Information
Get channel basic information (including English configuration) based on language type, such as: channel name, channel introduction, host name.
Api Method: getChannelBasicInfo(type?: LanguageType): ChannelBasicInfo
Parameter Description:
- type: Language type,
LanguageTypetype, optional, default'zh_CN'
Return Value Description: Channel basic information, ChannelBasicInfo type, detailed type description as follows
| Property Name | Description | Type |
|---|---|---|
title |
Channel Title | string |
publisher |
Channel Host | string |
description |
Channel Description | string |
Example:
// 获取频道的基础信息
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 Get Channel Scene
Used to determine the channel type, such as whether it is a three-screen channel or a seminar channel.
Api Method: getChannelScene(): ChannelScene
Return Value Description: ChannelScene type
Example:
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. Live Status
2.1 Channel Live Status
Enum Enumeration: LiveStatus
| Constant | Enum Member | Description |
|---|---|---|
'live' |
LiveStatus.Live |
Live |
'waiting' |
LiveStatus.Waiting |
Waiting |
'end' |
LiveStatus.End |
Ended, No Live |
'playback' |
LiveStatus.Playback |
Playing Back |
'stop' |
LiveStatus.Stop |
Live Paused |
'unStart' |
LiveStatus.UnStart |
Not Started |
2.2 Live Status Change Event
Description: When the host starts/ends a live broadcast, the channel's live status changes. Use this event to listen for live status changes.
Event Event: ChannelEvents.LiveStatusChange
Callback Parameters: Object object, detailed type description as follows
| Property Name | Description | Type |
|---|---|---|
liveStatus |
New Live Status | LiveStatus |
Example:
watchCore.channel.eventEmitter.on(ChannelEvents.LiveStatusChange, (data) => {
console.log('频道状态改变,新状态:', data.liveStatus);
});
2.3 Get Channel Live Status
Used to get the current live status of the channel. Listen for live status change events via ChannelEvents.LiveStatusChange.
Api Method: getLiveStatus(): LiveStatus
Return Value Description: LiveStatus type
Example:
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 Session ID Change Event
Description: Each time the host starts a new live broadcast, a new live session ID is generated. You can listen for live session ID changes through this event of the channel module.
Event Event: ChannelEvents.SessionIdChange
Callback Parameters: Object object, detailed type description as follows
| Property Name | Description | Type |
|---|---|---|
sessionId |
New Session ID | string |
Example:
watchCore.channel.eventEmitter.on(ChannelEvents.LiveStatusChange, (data) => {
console.log('频道状态改变,新状态:', data.liveStatus);
});
2.5 Get Channel Live Session ID
Get the latest session ID of the current channel via the getCurrentSessionId method.
Api Method: getCurrentSessionId(): string
Return Value Description: Latest session ID
Example:
const currentSessionId = watchCore.channel.getCurrentSessionId();
console.log('频道最新场次号', currentSessionId);
2.6 Stop Live Status Polling
Api Method: removeLiveStatusPolling(pollingId: string): void
Parameter Description:
- pollingId: Polling ID,
stringtype, required
2.7 Start Live Status Polling
Api Method: startLiveStatusPolling(pollingId?: string): string
Parameter Description:
- pollingId: Polling ID,
stringtype, optional, default...
Return Value Description: pollingId
3. Push Stream Information
3.1 Get Push Stream Information
Used to get the latest push stream information of the current channel, such as stream size, push stream type, etc.
Api Method: getPushInfo(): Promise<StreamPushInfo>
Return Value Description: Promise<StreamPushInfo> type, detailed type description as follows
| Property Name | Description | Type |
|---|---|---|
isNewGuide |
Whether it is a director console push | YN |
resolutionWidth |
Resolution Width | number |
resolutionHeight |
Resolution Height | number |
streamType |
Push Stream Type | StreamType |
Example:
const pushInfo = await watchCore.channel.getPushInfo();
console.log('流宽度', pushInfo.resolutionWidth);
console.log('流高度', pushInfo.resolutionHeight);
console.log('推流类型', pushInfo.streamType);
4. Page View Count
4.1 Get Channel Basic Information
Get channel basic information (including English configuration) based on language type, such as: channel name, channel introduction, host name.
Api Method: getChannelBasicInfo(type?: LanguageType): ChannelBasicInfo
Parameter Description:
- type: Language type,
LanguageTypetype, optional, default'zh_CN'
Return Value Description: Channel basic information, ChannelBasicInfo type, detailed type description as follows
| Property Name | Description | Type |
|---|---|---|
title |
Channel Title | string |
publisher |
Channel Host | string |
description |
Channel Description | string |
Example:
// 获取频道的基础信息
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 Get Channel Scene
Used to determine the channel type, such as whether it is a three-screen channel or a seminar channel.
Api Method: getChannelScene(): ChannelScene
Return Value Description: ChannelScene type
Example:
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 Get Channel ID
After entering the viewing page via a channel set in the backend, pass the promoteId channel number configuration when creating the viewing page SDK instance. This method can be used to get the current viewer's channel ID for other processing.
Api Method: getPromoteId(): undefined | string
Return Value Description: undefined | string type
Example:
import { createWatchCore } from '@polyv/live-watch-miniprogram-sdk';
const watchCore = createWatchCore({
channelId: '频道号',
promoteId: '渠道号',
});
// 需要重新获取渠道号时
const promoteId = watchCore.channel.getPromoteId();
4.4 Get Channel Live Session ID
Get the latest session ID of the current channel via the getCurrentSessionId method.
Api Method: getCurrentSessionId(): string
Return Value Description: Latest session ID
Example:
const currentSessionId = watchCore.channel.getCurrentSessionId();
console.log('频道最新场次号', currentSessionId);
4.5 Get Channel Live Status
Used to get the current live status of the channel. Listen for live status change events via ChannelEvents.LiveStatusChange.
Api Method: getLiveStatus(): LiveStatus
Return Value Description: LiveStatus type
Example:
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 Stop Live Status Polling
Api Method: removeLiveStatusPolling(pollingId: string): void
Parameter Description:
- pollingId: Polling ID,
stringtype, required
4.7 Start Live Status Polling
Api Method: startLiveStatusPolling(pollingId?: string): string
Parameter Description:
- pollingId: Polling ID,
stringtype, optional, default...
Return Value Description: pollingId
4.8 Get Viewing Page View Count
If you do not need the polling mechanism to update the view count, you can call the getPageViewCount method to re-obtain the view count when the viewer entered the page.
Api Method: getPageViewCount(): number
Example:
const pageViewCount = await watchCore.channel.getPageViewCount();
console.log('页面浏览次数', pageViewCount);
4.9 Start Viewing Page View Count Request Polling
Used to start polling for the viewing page view count API request, updating the page view count after the callback is triggered.
Api Method: startPageViewPolling(callback?: Function): void
Parameter Description:
- callback: Callback function, gets the view count from each poll,
Functiontype, optional
Example:
watchCore.channel.startPageViewPolling((pageViewCount: number) => {
console.log('页面浏览次数更新:', pageViewCount);
});
4.10 Stop Viewing Page View Count Request Polling
When the page or related components are destroyed, call stopPageViewPolling to stop the poller.
Api Method: stopPageViewPolling(): void
Example:
// vue 代码
export default {
// 组件销毁前停止定时器
beforeDestroy() {
watchCore.channel.stopPageViewPolling();
}
};
4.11 Get Push Stream Information
Used to get the latest push stream information of the current channel, such as stream size, push stream type, etc.
Api Method: getPushInfo(): Promise<StreamPushInfo>
Return Value Description: Promise<StreamPushInfo> type, detailed type description as follows
| Property Name | Description | Type |
|---|---|---|
isNewGuide |
Whether it is a director console push | YN |
resolutionWidth |
Resolution Width | number |
resolutionHeight |
Resolution Height | number |
streamType |
Push Stream Type | StreamType |
Example:
const pushInfo = await watchCore.channel.getPushInfo();
console.log('流宽度', pushInfo.resolutionWidth);
console.log('流高度', pushInfo.resolutionHeight);
console.log('推流类型', pushInfo.streamType);
4.12 Get Viewing Page Settings
Used to get the viewing page settings configured in the management backend.
Api Method: getWatchSetting(): ChannelWatchSetting
Return Value Description: Channel viewing page settings, ChannelWatchSetting type, detailed type description as follows
| Property Name | Description | Type |
|---|---|---|
watchEnabled |
Viewing Page Switch | boolean |
mobileWatchEnabled |
Mobile Viewing Page Switch | boolean |
splashEnabled |
Guide Page Switch | boolean |
Example:
const setting = watchCore.channel.getWatchSetting();
if (!setting.watchEnabled) { alert('当前观看页暂未开放'); }
if (isMobile && !setting.mobileWatchEnabled) { alert('暂不支持移动端观看'); }
4.13 Get Channel Layout Settings
Used to get the page layout related settings from the management backend.
Api Method: getLayoutSetting(): ChannelLayoutSetting
Return Value Description: Channel layout settings, ChannelLayoutSetting type, detailed type description as follows
| Property Name | Description | Type |
|---|---|---|
mainScreenLayoutMode |
Three-Screen Main Screen Layout Mode | MainScreenLayoutMode |
mobileSplashLayout |
Mobile Guide Page Layout | MobileSplashLayout |
mobileWatchLayout |
Mobile Viewing Page Layout | MobileWatchLayout |
Example:
const setting = watchCore.channel.getLayoutSetting();
console.log('三分屏主屏布局模式:', setting.mainScreenLayoutMode);
console.log('移动端引导页布局:', setting.mobileSplashLayout);
console.log('移动端观看页页布局:', setting.mobileWatchLayout);
4.14 Get Channel Skin Theme Settings
Used to get the skin theme settings from the management backend.
Api Method: getThemeSetting(): ChannelThemeSetting
Return Value Description: Channel skin theme settings, ChannelThemeSetting type, detailed type description as follows
| Property Name | Description | Type |
|---|---|---|
pageSkin |
Viewing Page Skin | ChannelWatchPageSkin |
browserFavIcon |
Browser Tab Icon | undefined | string |
channelCoverImg |
Channel Icon Image URL | string |
splashImg |
Guide Page Cover Image | undefined | string |
mobileSplashLargeImg |
Mobile Guide Page Large Image | undefined | string |
pcWatchBackgroundImage |
PC Viewing Page Background Image | undefined | string |
mobileChatBackgroundImage |
Mobile Chat Room Background Image | undefined | string |
mobileChatBackgroundImageAmbiguity |
Chat Room Background Blur, 0 ~ 100 | undefined | number |
portraitBackgroundImage |
Portrait Background Image | undefined | string |
portraitBackgroundImageAmbiguity |
Portrait Background Image Transparency, 0 ~ 100 | undefined | number |
Example:
const setting = watchCore.channel.getThemeSetting();
console.log('皮肤风格:', setting.pageSkin);
console.log('直播间图标:', setting.channelCoverImg);
4.15 Get Instructor Information
Used to get the current instructor/host information.
Api Method: getTeacherInfo(): TeacherInfoType
Return Value Description: TeacherInfoType type
Example:
const teacherInfo = watchCore.channel.getTeacherInfo();
console.log('讲师昵称', teacherInfo.nick);
console.log('讲师头像', teacherInfo.pic);
console.log('讲师头衔', teacherInfo.actor);
4.16 Get View Count Settings Information
Used to get the page view count information set in the management backend.
Api Method: getPageViewSetting(): PageViewSetting
Return Value Description: Page view count settings, PageViewSetting type, detailed type description as follows
| Property Name | Description | Type |
|---|---|---|
pvShowEnabled |
Page View Count Switch | boolean |
pageViewCount |
Page View Count | number |
mobilePvShowLocation |
Mobile Page View Count Position | PageViewShowLocation |
Example:
const setting = watchCore.channel.getPageViewSetting();
console.log('页面浏览次数开关', setting.pvShowEnabled);
console.log('页面浏览次数', setting.pageViewCount);
console.log('移动端浏览次数位置', setting.mobilePvShowLocation);
4.17 Get Live Countdown Settings
Used to get the channel start time and other settings configured in the backend.
Api Method: getCountdownSetting(): ChannelCountdownSetting
Return Value Description: Countdown settings, ChannelCountdownSetting type, detailed type description as follows
| Property Name | Description | Type |
|---|---|---|
liveStartTime |
Live Start Time, Unit: Timestamp | undefined | number |
countdownEnabled |
Countdown Switch | boolean |
playbackShowCountdownEnabled |
Whether to show the next countdown during playback | boolean |
Example:
const setting = watchCore.channel.getCountdownSetting();
console.log('开始时间:', setting.liveStartTime);
console.log('回放下是否显示倒计时:', setting.playbackShowCountdownEnabled);
4.18 Get Share Information
Used to get the share information of the current channel, including whether sharing is enabled, cover image, title.
Api Method: getShareInfo(): Promise<ShareInfo>
Return Value Description: Promise<ShareInfo> type, detailed type description as follows
| Property Name | Description | Type |
|---|---|---|
shareEnabled |
Whether sharing function is enabled | boolean |
shareImageUrl |
Share Cover | string |
shareTitle |
Resolution Height | string |
Example:
const shareInfo = await watchCore.channel.getShareInfo();
console.log('是否开启分享', shareInfo.shareEnabled);
console.log('分享的封面', shareInfo.shareImageUrl);
console.log('分享的标题', shareInfo.shareTitle);
5. Live Start Time
5.1 Get Live Countdown Settings
Used to get the channel start time and other settings configured in the backend.
Api Method: getCountdownSetting(): ChannelCountdownSetting
Return Value Description: Countdown settings, ChannelCountdownSetting type, detailed type description as follows
| Property Name | Description | Type |
|---|---|---|
liveStartTime |
Live Start Time, Unit: Timestamp | undefined | number |
countdownEnabled |
Countdown Switch | boolean |
playbackShowCountdownEnabled |
Whether to show the next countdown during playback | boolean |
Example:
const setting = watchCore.channel.getCountdownSetting();
console.log('开始时间:', setting.liveStartTime);
console.log('回放下是否显示倒计时:', setting.playbackShowCountdownEnabled);
