@polyv/wx-live-player-core 3.0.0-dev.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,34 @@
1
+ /**
2
+ * @file 清晰度控制模块
3
+ */
4
+ import { ModuleBase } from '../module-base';
5
+ import { LevelItem } from '../../types';
6
+ export declare class LevelControl extends ModuleBase {
7
+ private readonly definitionMap;
8
+ /**
9
+ * 获取清晰度配置
10
+ */
11
+ getLevelSetting(): LevelItem[];
12
+ /**
13
+ * 设置初始线路
14
+ */
15
+ setInitDefaultLevel(): void;
16
+ /**
17
+ * 根据线路获取默认清晰度索引
18
+ * @param lineIndex
19
+ * @returns
20
+ */
21
+ getDefaultLevelIndexByLineIndex(lineIndex: number): number;
22
+ /**
23
+ * 切换清晰度
24
+ * @param level
25
+ * @returns
26
+ * */
27
+ changeLevel(level: number): void;
28
+ /**
29
+ * 根据清晰度获取源
30
+ * @param src
31
+ * @returns
32
+ */
33
+ getSrcFromLevel(src: string): string;
34
+ }
@@ -0,0 +1,27 @@
1
+ /**
2
+ * @file 线路控制模块
3
+ */
4
+ import { ModuleBase } from '../module-base';
5
+ import { LineItem } from '../../types';
6
+ export declare class LineControl extends ModuleBase {
7
+ /**
8
+ * 获取线路配置
9
+ */
10
+ getLineSetting(): LineItem[];
11
+ /**
12
+ * 设置初始线路
13
+ */
14
+ setInitDefaultLine(): void;
15
+ /**
16
+ * 切换线路
17
+ * @param line
18
+ * @returns
19
+ */
20
+ changeLine(line: number): void;
21
+ /**
22
+ * 根据线路获取源
23
+ * @param src
24
+ * @returns
25
+ */
26
+ getSrcFromLine(src: string): string;
27
+ }
@@ -0,0 +1,14 @@
1
+ /**
2
+ * 直播模块
3
+ */
4
+ import { ModuleBase } from '../module-base';
5
+ export declare class Live extends ModuleBase {
6
+ /**
7
+ * 获取最新直播播放链接
8
+ */
9
+ getLiveSrc(): string;
10
+ /**
11
+ * 获取最新播放地址
12
+ */
13
+ resetLatestPlayUrl(): Promise<void>;
14
+ }
@@ -0,0 +1,7 @@
1
+ import PlayerCore from '../core';
2
+ export declare class ModuleBase {
3
+ private __playerCore;
4
+ constructor(__playerCore: PlayerCore);
5
+ getPlayerCore(): PlayerCore;
6
+ destroy(): void;
7
+ }
@@ -0,0 +1,20 @@
1
+ import { ModuleBase } from '../module-base';
2
+ export declare class Monitor extends ModuleBase {
3
+ /**
4
+ * 轮询定时器
5
+ */
6
+ private __timer;
7
+ /**
8
+ * 开始监控
9
+ */
10
+ start(): void;
11
+ /**
12
+ * 检查是否开始监控
13
+ */
14
+ private isStartCheck;
15
+ private __getPullTime;
16
+ /**
17
+ * 停止监控
18
+ */
19
+ private __stopTimer;
20
+ }
@@ -0,0 +1,16 @@
1
+ /**
2
+ * 回放模块
3
+ */
4
+ import { ModuleBase } from '../module-base';
5
+ import { PlayType } from '../../types';
6
+ export declare class Playback extends ModuleBase {
7
+ /**
8
+ * 获取最新回放配置
9
+ */
10
+ getPlaybackSetting(): {
11
+ playType: PlayType;
12
+ src: string;
13
+ duration: number | undefined;
14
+ sessionId: string;
15
+ } | undefined;
16
+ }
@@ -0,0 +1,40 @@
1
+ /**
2
+ * @file 无延迟控制模块
3
+ */
4
+ /// <reference types="miniprogram-api-typings" />
5
+ import { ModuleBase } from '../module-base';
6
+ import { PlayCoreType } from '../../types';
7
+ export declare class QuickControl extends ModuleBase {
8
+ /**
9
+ * 频道是否可以使用无延迟播放
10
+ * @returns
11
+ */
12
+ canUseQuick(): boolean;
13
+ /**
14
+ * 设备是否支持无延迟播放
15
+ * @returns
16
+ */
17
+ canQuickSupport(): boolean;
18
+ /**
19
+ * 获取无延迟播放地址
20
+ */
21
+ getSrcFromQuick(src: string): string;
22
+ /**
23
+ * 获取延迟内核配置
24
+ */
25
+ getPlayCoreSetting(): {
26
+ type: PlayCoreType;
27
+ core: number;
28
+ enabled: boolean;
29
+ }[];
30
+ /**
31
+ * 设置初始延迟内核
32
+ */
33
+ setInitDefaultPlayCore(): void;
34
+ /**
35
+ * 切换延迟内核
36
+ * @param playCore 延迟内核索引 0 代表普通延迟 1 代表无延迟
37
+ */
38
+ changePlayCore(playCore: number): void;
39
+ setLivePlayerStateChange(e: WechatMiniprogram.LivePlayerStateChange): void;
40
+ }
@@ -0,0 +1,21 @@
1
+ /**
2
+ * @file restrict.json 模块
3
+ */
4
+ import { ModuleBase } from '../module-base';
5
+ export declare class RestrictJson extends ModuleBase {
6
+ /**
7
+ * 获取限制信息的配置
8
+ * @returns
9
+ */
10
+ private __getRestrictJson;
11
+ /**
12
+ * 获取限制信息的配置备用接口
13
+ * @returns
14
+ */
15
+ private __getBackupRestrictJson;
16
+ /**
17
+ * 检查是否可以观看
18
+ * @returns
19
+ */
20
+ checkCanWatch(): Promise<void>;
21
+ }
@@ -0,0 +1,35 @@
1
+ /**
2
+ * 用户状态
3
+ */
4
+ type RestrictUserStatus = 'NORMAL' | '';
5
+ /**
6
+ * 限制信息配置接口返回内容
7
+ */
8
+ export interface IRestrictJsonResponse {
9
+ /**
10
+ * 用户状态
11
+ */
12
+ userStatus: RestrictUserStatus;
13
+ /**
14
+ * 是否可以观看
15
+ */
16
+ canWatch: boolean;
17
+ /**
18
+ * 错误码
19
+ */
20
+ errorCode: string;
21
+ }
22
+ /**
23
+ * 限制信息配置接口请求参数
24
+ */
25
+ export interface IRestrictJsonRequest {
26
+ /**
27
+ * 用户ID
28
+ */
29
+ uid: string;
30
+ /**
31
+ * 频道ID
32
+ */
33
+ cid: string;
34
+ }
35
+ export {};
@@ -0,0 +1,68 @@
1
+ /**
2
+ * @file 统计模块
3
+ */
4
+ import { ModuleBase } from '../module-base';
5
+ import PlayerCore from '../../core';
6
+ import { PlayerStatisticsSetting } from '../../types';
7
+ export declare class Statistics extends ModuleBase {
8
+ /**
9
+ * 开始时间戳
10
+ */
11
+ private __startTimeStamps;
12
+ /**
13
+ * 轮询定时器
14
+ */
15
+ private __pollingInterval;
16
+ /**
17
+ * 播放唯一标识 PID
18
+ */
19
+ pid: string;
20
+ /**
21
+ * 轮询间隔时间
22
+ */
23
+ private __pollingIntervalTime;
24
+ /**
25
+ * 播放时长
26
+ */
27
+ playDuration: number;
28
+ /**
29
+ * 播放时长计算定时器
30
+ */
31
+ private __playDurationCountInterval;
32
+ /**
33
+ * 停留时长开始时间戳
34
+ */
35
+ private __stayDurationStartTimeStamps;
36
+ /**
37
+ * 统计数据
38
+ */
39
+ private __updatingStatistics;
40
+ constructor(playerCore: PlayerCore);
41
+ /**
42
+ * 初始化
43
+ */
44
+ private __init;
45
+ startPolling(): void;
46
+ stopPolling(): void;
47
+ startCountPd(): void;
48
+ stopCountPd(): void;
49
+ /**
50
+ * 发送统计日志
51
+ */
52
+ sendStatistics(): Promise<void>;
53
+ /**
54
+ * 设置统计数据
55
+ * @param statics 统计数据
56
+ */
57
+ setStatics(statics: PlayerStatisticsSetting): void;
58
+ /**
59
+ * 改变统计基础参数
60
+ */
61
+ changeStatisticsBaseParams(): void;
62
+ /**
63
+ * 获取播放唯一标识 PID, 需要注意PID变更pd需要同时重置为0
64
+ * @returns
65
+ */
66
+ private __getPid;
67
+ destroy(): void;
68
+ }
@@ -0,0 +1 @@
1
+ export { ApiStatus } from './type';
@@ -0,0 +1,41 @@
1
+ /**
2
+ * @file 流状态模块
3
+ */
4
+ import { ModuleBase } from '../module-base';
5
+ import PlayerCore from '../../core';
6
+ export declare class Status extends ModuleBase {
7
+ /**
8
+ * 开始时间戳
9
+ */
10
+ private __startTimeStamps;
11
+ /**
12
+ * 轮询定时器
13
+ */
14
+ private __pollingInterval;
15
+ constructor(playerCore: PlayerCore);
16
+ /**
17
+ * 初始化
18
+ */
19
+ private __init;
20
+ /**
21
+ * 获取轮询间隔时间
22
+ * @returns
23
+ */
24
+ private __getPollingIntervalTime;
25
+ /**
26
+ * 获取流名
27
+ * @returns
28
+ */
29
+ private __getStreamName;
30
+ /**
31
+ * 获取频道ID
32
+ * @returns
33
+ */
34
+ private __getCid;
35
+ startPolling(): void;
36
+ /**
37
+ * 停止轮询
38
+ */
39
+ stopPolling(): void;
40
+ destroy(): void;
41
+ }
@@ -0,0 +1,47 @@
1
+ /**
2
+ * 播放器状态
3
+ */
4
+ export declare enum ApiStatus {
5
+ /**
6
+ * 直播进行中
7
+ */
8
+ LIVE = "live",
9
+ /**
10
+ * 直播结束
11
+ */
12
+ END = "end",
13
+ /**
14
+ * 中途暂停
15
+ */
16
+ STOP = "stop"
17
+ }
18
+ /**
19
+ * 获取API状态接口响应参数
20
+ */
21
+ export interface IGetApiStatusResponse {
22
+ /**
23
+ * 状态
24
+ */
25
+ status: ApiStatus;
26
+ /**
27
+ * 场次ID
28
+ */
29
+ sessionId: string;
30
+ }
31
+ /**
32
+ * 获取API状态接口请求参数
33
+ */
34
+ export interface IGetApiStatusRequest {
35
+ /**
36
+ * 频道ID
37
+ */
38
+ channelId: string;
39
+ /**
40
+ * 流名
41
+ */
42
+ stream: string;
43
+ /**
44
+ * 随机数
45
+ */
46
+ ran: number;
47
+ }
@@ -0,0 +1,14 @@
1
+ /**
2
+ * 暖场模块
3
+ */
4
+ import { ModuleBase } from '../module-base';
5
+ import { PlayType } from '../../types';
6
+ export declare class Warm extends ModuleBase {
7
+ /**
8
+ * 获取暖场配置
9
+ */
10
+ getWarmSetting(): {
11
+ playType: PlayType;
12
+ src: string;
13
+ } | undefined;
14
+ }
package/package.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "name": "@polyv/wx-live-player-core",
3
+ "version": "3.0.0-dev.12",
4
+ "main": "polyv-live-player.js",
5
+ "types": "polyv-live-player.d.ts"
6
+ }
package/player.d.ts ADDED
@@ -0,0 +1,139 @@
1
+ /// <reference types="miniprogram-api-typings" />
2
+ import { PlayerConfig, PlayType, PlayerStatisticsSetting } from './types';
3
+ import { PlayerEventMap } from './events-type';
4
+ export declare class PolyvLive {
5
+ /**
6
+ * 播放内核
7
+ */
8
+ private __playerCore;
9
+ /**
10
+ * 是否已经初始化
11
+ */
12
+ private __inited;
13
+ constructor(config: PlayerConfig);
14
+ /**
15
+ * 播放器初始化
16
+ * @description 初始化播放器, 包括鉴权, 解析当前状态等操作
17
+ */
18
+ setUp(): Promise<void>;
19
+ /**
20
+ * 获取播放类型
21
+ * @returns 播放类型
22
+ * @description 可以通过 `getPlayType` 主动获取当前的播放类型
23
+ *
24
+ * @example
25
+ * ```ts
26
+ * const playType = player.getPlayType();
27
+ *
28
+ * if (playType === PlayType.WAIT_START) {
29
+ * console.log('当前暂无直播, 显示暂未直播盖图');
30
+ * }}
31
+ * ```
32
+ */
33
+ getPlayType(): PlayType;
34
+ /**
35
+ * 刷新当前播放流
36
+ * @description 一般用于直播过程中, 出现卡顿等情况, 主动刷新当前播放流
37
+ * @example
38
+ * ```ts
39
+ * <button bind:tap="refresh"></button>
40
+ *
41
+ * player.on(PlayerEventsType.UPDATE_MEDIA_INFO, (mediaInfo: MediaInfo) => {
42
+ * const { playType, src } = mediaInfo;
43
+ * this.setData({ src });
44
+ * });
45
+ *
46
+ * // 调用刷新流接口,触发`UPDATE_MEDIA_INFO`事件更新视频播放地址
47
+ * function refresh() {
48
+ * player.refresh();
49
+ * }
50
+ * ```
51
+ */
52
+ refresh(): void;
53
+ /**
54
+ * 设置统计参数
55
+ * @description 播放中途如设置昵称, 可以通过`setStatics`更新统计参数。一般param1用于设置用户唯一Id,param2用于设置用户昵称等信息
56
+ * @param statics 统计参数
57
+ * @example
58
+ * ```ts
59
+ * player.setStatics({
60
+ * param2: '昵称',
61
+ * });
62
+ * ```
63
+ */
64
+ setStatics(statics: PlayerStatisticsSetting): void;
65
+ /**
66
+ * 开始统计播放时长
67
+ * @description 连麦结束,需要调用`startCountPd`开始统计播放时长
68
+ * @ignore
69
+ */
70
+ startCountPd(): void;
71
+ /**
72
+ * 暂停统计播放时长
73
+ * @description 连麦中途,CDN播放器会暂停统计播放时长,需要调用`stopCountPd`暂停统计播放时长
74
+ * @ignore
75
+ */
76
+ stopCountPd(): void;
77
+ /**
78
+ * 切换线路
79
+ * @description 切换线路, 切换线路后, 会触发`UPDATE_MEDIA_INFO`事件
80
+ * @param line 线路索引 0 代表线路1
81
+ * @example
82
+ * ```ts
83
+ * <button bind:tap="changeLine"></button>
84
+ *
85
+ * player.on(PlayerEventsType.UPDATE_MEDIA_INFO, (mediaInfo: MediaInfo) => {
86
+ * const { playType, src } = mediaInfo;
87
+ * this.setData({ src });
88
+ * });
89
+ *
90
+ * // 调用切换线路接口,触发`UPDATE_MEDIA_INFO`事件更新视频播放地址
91
+ * function changeLine() {
92
+ * player.changeLine(0);
93
+ * }
94
+ * ```
95
+ */
96
+ changeLine(line: number): void;
97
+ /**
98
+ * 切换清晰度
99
+ * @description 切换清晰度, 切换清晰度后, 会触发`UPDATE_MEDIA_INFO`事件
100
+ * @param level 清晰度索引 0 代表流畅
101
+ * @example
102
+ * ```ts
103
+ * <button bind:tap="changeLevel"></button>
104
+ *
105
+ * player.on(PlayerEventsType.UPDATE_MEDIA_INFO, (mediaInfo: MediaInfo) => {
106
+ * const { playType, src } = mediaInfo;
107
+ * this.setData({ src });
108
+ * });
109
+ *
110
+ * // 调用切换清晰度接口,触发`UPDATE_MEDIA_INFO`事件更新视频播放地址
111
+ * function changeLevel() {
112
+ * player.changeLevel();
113
+ * }
114
+ * ```
115
+ */
116
+ changeLevel(level: number): void;
117
+ /**
118
+ * 切换延迟内核
119
+ * @description 切换延迟内核, 切换延迟内核后, 会触发`UPDATE_MEDIA_INFO`事件
120
+ * @param playCore 延迟内核索引 0 代表普通延迟 1 代表无延迟
121
+ */
122
+ changePlayCore(playCore: number): void;
123
+ /**
124
+ * 监测播放组件状态回调
125
+ */
126
+ setLivePlayerStateChange(e: WechatMiniprogram.LivePlayerStateChange): void;
127
+ /**
128
+ * 事件监听
129
+ */
130
+ on<K extends keyof PlayerEventMap>(event: K, listener: PlayerEventMap[K]): void;
131
+ /**
132
+ * 取消事件监听
133
+ */
134
+ off<K extends keyof PlayerEventMap>(event: K, listener: PlayerEventMap[K]): void;
135
+ /**
136
+ * 销毁播放实例
137
+ */
138
+ destroy(): void;
139
+ }