Polyv Help Center

Help Center

Watch Page Core

Updated: 2024-10-10 17:27:10

This document primarily provides the API descriptions for the core methods offered by the Watch Page Mini Program SDK.

In terms of design pattern, the Watch Page Core instance follows a singleton design. Therefore, the SDK provides separate methods for creating and destroying the instance.

1. Creating a Watch Page Core Instance

API Method: createWatchCore(appConfig: AppConfig): PolyvWatchCore

Parameter Description:

  • appConfig: Configuration options, type AppConfig, required. Detailed type description is as follows:
Parameter Description Type Required Default
channelId Channel ID string Yes -
domainInfo Custom Domain Partial<DomainInfo> No -
userInfo Viewer Information UserInfo No -
vid Playback VID string No -
playbackOrigin Playback Type PlaybackOrigin No -

Example Code:

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

2. Destroying a Watch Page Core Instance

API Method: destroyWatchCore(): void

Note: Generally, it is not recommended for developers to actively call this method. It is suggested that the instance be automatically destroyed and reclaimed by the browser when the browser tab is closed.

Example Code:

import { destroyWatchCore } from '@polyv/live-watch-miniprogram-sdk';
destroyWatchCore()

3. Core Methods

3.1 Setting the Authorization Token

API Method: setXAuthToken(xAuthToken: string): void

Parameter Description:

  • xAuthToken: Authorization token, type string, required.

3.2 Installing the Watch Page Core

The Watch Page Core method is used to install the Watch Page Core and load channel information. Upon successful installation, it triggers a Promise callback and the PolyvWatchCoreEvents.WatchCoreSetuped event.

API Method: setup(): Promise<SetupResult>

Return Value Description: Type Promise<SetupResult>

Example:

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

const watchCore = createWatchCore({
  channelId: '频道号'
});
watchCore.setup();

3.3 Connecting to the Chat Room

The Watch Page Core method is used to connect to the chat room before entering the live streaming watch page. Upon successful connection, it triggers a Promise callback and the PolyvWatchCoreEvents.WatchCoreConnected event.

API Method: connect(): Promise<void>

Example:

await watchCore.connect();
console.log('连接成功,显示直播观看页');
联系客服,在线咨询
在线咨询