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
Obtain basic channel 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-sdk';
const scene = watchCore.channel.getChannelScene();
const isAloneChannel = scene === ChannelScene.Alone; // 普通直播频道
const isPptChannel = scene === ChannelScene.Ppt; // 三分屏频道
const isSeminarChannel = scene === ChannelScene.Seminar; // 研讨会频道
1.3 Get Current Channel Watch Page URL
Used to get the URL of the current watch page.
Api Method: getChannelWatchUrl(): string
Example:
const watchUrl = watchCore.channel.getChannelWatchUrl();
console.log('当前观看页的打开地址', watchUrl);
1.4 Generate Watch Page URL
Api Method: generateWatchUrl(channelId: string): string
Parameter Description:
- channelId: Channel ID,
stringtype, required
Example:
const watchUrl = watchCore.channel.generateWatchUrl('频道号');
location.href = watchUrl;
1.5 Get Teacher Information
Used to get the current teacher/presenter's 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);
1.6 Get Channel ID
After entering the watch page via a channel set in the backend, when creating the watch page SDK instance, pass the promoteId channel number configuration. 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-sdk';
const watchCore = createWatchCore({
channelId: '频道号',
promoteId: '渠道号',
});
// 需要重新获取渠道号时
const promoteId = watchCore.channel.getPromoteId();
1.7 Get Channel Agreement Configuration
Can obtain agreement configurations in different languages, mainly used for authorization-related services.
Api Method: getChannelAgreementConfig(): Promise<ChannelAgreementConfig>
Supported from version v0.10.0
Return Value Description: Promise<ChannelAgreementConfig> type
Example:
const agreementConfig = await watchCore.channel.getChannelAgreementConfig();
console.log('当前语言的协议配置', agreementConfig["zh_CN"]);
1.8 Get Channel Live Scene
Api Method: getNewScene(): ChannelNewScene
Supported from version v2.13.0
Return Value Description: ChannelNewScene type
1.9 Reset Channel Details (Use with Caution)
Api Method: resetChannelDetail(): void
Supported from version v2.17.0
2. Live Status
2.1 Channel Live Status
Enum: LiveStatus
| Constant | Enum Member | Description |
|---|---|---|
'live' |
LiveStatus.Live |
Live |
'waiting' |
LiveStatus.Waiting |
Waiting |
'end' |
LiveStatus.End |
Ended, no live stream |
'playback' |
LiveStatus.Playback |
Playback |
'stop' |
LiveStatus.Stop |
Live Paused |
'unStart' |
LiveStatus.UnStart |
Not Started |
2.2 Live Status Change Event
Description: When the presenter starts/ends a live stream, the channel's live status changes. Use this event to listen for live status changes.
Event: ChannelEvents.LiveStatusChange
Callback Parameters: Object object, detailed type description as follows
| Property Name | Description | Type |
|---|---|---|
liveStatus |
New live status | LiveStatus |
newLiveStatus |
New live status | LiveStatus |
oldLiveStatus |
Old 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-sdk';
watchCore.channel.eventEmitter.on(ChannelEvents.LiveStatusChange, () => {
const liveStatus = watchCore.channel.getLiveStatus();
console.log('是否正在直播', liveStatus === LiveStatus.Live);
});
2.4 Session ID Change Event
Description: When the presenter starts a new live stream, a new live session ID is generated. Listen for live session ID changes via this event of the channel module.
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
Must be used in conjunction with the watchCore.channel.startLiveStatusPolling method.
Api Method: removeLiveStatusPolling(pollingId: string): void
Parameter Description:
- pollingId: Polling ID,
stringtype, required
Example:
const watchCore = getWatchCore();
const pollingId = watchCore.channel.startLiveStatusPolling();
watchCore.channel.removeLiveStatusPolling(pollingId);
2.7 Start Live Status Polling
Performs live status polling based on backend configuration when conditions permit.
Api Method: startLiveStatusPolling(pollingId?: string, options?: Object): string
Parameter Description:
pollingId: Polling ID,
stringtype, optional, default...options:
Objecttype, optional, detailed type description as follows
| Parameter Name | Description | Type | Required | Default Value |
|---|---|---|---|---|
timeout |
- | number |
Yes | - |
maxPollingCount |
- | number |
Yes | - |
Return Value Description: Polling identifier, can be used as a parameter to remove polling
Example:
const watchCore = getWatchCore();
const pollingId = watchCore.channel.startLiveStatusPolling();
console.info('轮询标识位:', pollingId);
3. Push Stream Information
3.1 Get Push Stream Information
Used to get the latest push stream information for the current channel, such as stream dimensions, push 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 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 Watch Page View Count
If polling is not needed to update the view count, call the getPageViewCount method to re-obtain the view count when the viewer enters the page.
Api Method: getPageViewCount(): number
Example:
const pageViewCount = await watchCore.channel.getPageViewCount();
console.log('页面浏览次数', pageViewCount);
4.2 Start Watch Page View Count Polling
Used to start polling for the watch page view count API request, updating the page view count after the callback is triggered.
From v1.2.0, the callback is triggered once immediately after the method is called.
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.3 Get Latest Watch Page View Count
Api Method: getLatestPageView(): Promise<number>
Supported from version v1.2.0
Return Value Description: Promise<number> type
4.4 Stop Watch Page View Count 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.5 Get Page View Settings
Used to get the page view count settings configured 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 toggle | 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);
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 toggle | boolean |
playbackShowCountdownEnabled |
Whether to show next countdown during playback | boolean |
Example:
const setting = watchCore.channel.getCountdownSetting();
console.log('开始时间:', setting.liveStartTime);
console.log('回放下是否显示倒计时:', setting.playbackShowCountdownEnabled);
6. Watch Duration
6.1 Get Watch Duration Settings
Api Method: getWatchDurationSetting(): ChannelWatchDurationSetting
Supported from version v0.8.0
Return Value Description: ChannelWatchDurationSetting type, detailed type description as follows
| Property Name | Description | Type |
|---|---|---|
watchDurationEnabled |
Watch duration toggle | boolean |
watchDurationType |
Watch duration type | string |
6.2 Stop Watch Duration Statistics Polling
Api Method: stopWatchDurationStatsPolling(): void
Supported from version v0.8.0
6.3 Start Watch Duration Statistics Polling
Api Method: startWatchDurationStatsPolling(): void
Supported from version v0.8.0
7. Series Live (New Live Session)
7.1 Get New Live Session Toggle
Api Method: getTargetSessionEnabled(): boolean
Supported from version v2.4.0
7.2 Get Channel Session List
Api Method: getChannelSessionList(params?: GetChannelSessionListParams): Promise<PageContent<ChannelSessionDataItem>>
Parameter Description:
- params:
GetChannelSessionListParamstype, optional, detailed type description as follows
| Parameter Name | Description | Type | Required | Default Value |
|---|---|---|---|---|
pageNumber |
- | number |
No | - |
pageSize |
- | number |
No | - |
status |
- | string |
No | - |
order |
- | string |
No | - |
chapterId |
Chapter ID (optional, when provided, only returns sessions under that chapter) | number |
No | - |
Return Value Description: Promise<PageContent<ChannelSessionDataItem>> type
7.3 Get Channel Session Chapter List
Api Method: getChannelSessionChapterList(): Promise<ChannelSessionChapter[]>
Supported from version v2.18.0
Return Value Description: Promise<ChannelSessionChapter[]> type
8. Presenter Information
8.1 Get Presenter Information
Api Method: getAnchorInfo(): Promise<undefined | ChannelAnchorInfo>
Supported from version v2.13.0
Return Value Description: Promise<undefined | ChannelAnchorInfo> type
8.2 Get Presenter's Associated Channel List
Api Method: getAnchorChannelList(options?: GetAnchorChannelListParams): Promise<PageContent<AnchorChannelItem>>
Supported from version v2.13.0
Parameter Description:
- options:
GetAnchorChannelListParamstype, optional, default{}, detailed type description as follows
| Parameter Name | Description | Type | Required | Default Value |
|---|---|---|---|---|
pageNumber |
- | number |
No | - |
pageSize |
- | number |
No | - |
Return Value Description: Promise<PageContent<AnchorChannelItem>> type
