ckplayer-plus 1.1.10 → 1.1.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.
- package/README.md +179 -176
- package/dist/ckplayer.js +77 -33
- package/dist/ckplayer.min.js +2 -2
- package/dist/flv.js/LICENSE +201 -201
- package/dist/flv.js/flv.min.js +9 -9
- package/dist/hls.js/LICENSE +28 -28
- package/dist/hls.js/hls.min.js +1 -1
- package/dist/index.cjs +68 -25
- package/dist/index.js +69 -27
- package/dist/mpegts.js/LICENSE +201 -201
- package/dist/mpegts.js/mpegts.min.js +8 -8
- package/dist/react.cjs +71 -25
- package/dist/react.js +72 -27
- package/dist/vue.cjs +71 -25
- package/dist/vue.js +72 -27
- package/package.json +6 -2
- package/types/vue.d.ts +1 -1
package/README.md
CHANGED
|
@@ -1,176 +1,179 @@
|
|
|
1
|
-
# ckplayer-plus
|
|
2
|
-
|
|
3
|
-
基于 [ckplayer](https://www.ckplayer.com) X3 的工程化封装:支持 **npm / ESM**,并提供 **Vue 2.7+/3** 与 **React** 组件。
|
|
4
|
-
|
|
5
|
-
> **免责声明**:本包为社区/工程化封装,**非 ckplayer 官方包**。播放内核来自 ckplayer(MIT)。完整能力与参数请同时参考 [官方手册](https://www.ckplayer.com/manual/)。npm 上的官方包名为 [`ckplayer`](https://www.npmjs.com/package/ckplayer),请勿混淆。
|
|
6
|
-
|
|
7
|
-
## 安装(只需这一步)
|
|
8
|
-
|
|
9
|
-
```bash
|
|
10
|
-
npm i ckplayer-plus
|
|
11
|
-
```
|
|
12
|
-
|
|
13
|
-
**不必再单独安装** `hls.js` / `flv.js` / `mpegts.js`。
|
|
14
|
-
包内已附带对应脚本;播放时会按视频地址**自动选择插件并按需加载**。
|
|
15
|
-
|
|
16
|
-
## 自动识别规则(默认开启)
|
|
17
|
-
|
|
18
|
-
| 地址特征 | 行为 |
|
|
19
|
-
|----------|------|
|
|
20
|
-
| `.mp4` 等浏览器可直接播的格式 | 原生 `<video>`,不加载流媒体脚本 |
|
|
21
|
-
| `.m3u8` | 自动使用 `hls.js`(Safari 若原生支持则仍走原生) |
|
|
22
|
-
| `.flv` | 自动使用 `flv.js` |
|
|
23
|
-
| `.ts` / `.m2ts` / `.mts` | 自动使用 `mpegts.js` |
|
|
24
|
-
|
|
25
|
-
关闭自动识别:`autoPlug: false`,并自行传 `plug`。
|
|
26
|
-
|
|
27
|
-
## 引入样式(必做)
|
|
28
|
-
|
|
29
|
-
```js
|
|
30
|
-
import 'ckplayer-plus/style.css'
|
|
31
|
-
```
|
|
32
|
-
|
|
33
|
-
## 最简用法(mp4 / m3u8 都这样写)
|
|
34
|
-
|
|
35
|
-
```js
|
|
36
|
-
import ckplayer from 'ckplayer-plus'
|
|
37
|
-
import 'ckplayer-plus/style.css'
|
|
38
|
-
|
|
39
|
-
const player = new ckplayer({
|
|
40
|
-
container: '#player',
|
|
41
|
-
video: url // 可以是 mp4 或 m3u8,无需再写 plug
|
|
42
|
-
})
|
|
43
|
-
```
|
|
44
|
-
|
|
45
|
-
Vue:
|
|
46
|
-
|
|
47
|
-
```vue
|
|
48
|
-
<CkPlayer :video="url" height="400px" />
|
|
49
|
-
```
|
|
50
|
-
|
|
51
|
-
React:
|
|
52
|
-
|
|
53
|
-
```jsx
|
|
54
|
-
<CkPlayer video={url} height="400px" />
|
|
55
|
-
```
|
|
56
|
-
|
|
57
|
-
## 配置说明(哪些要写、哪些不用写)
|
|
58
|
-
|
|
59
|
-
### 常用且推荐
|
|
60
|
-
|
|
61
|
-
| 配置 | 是否必须 | 默认 | 说明 |
|
|
62
|
-
|------|----------|------|------|
|
|
63
|
-
| `container` | 核心 API 必须;组件不用 | — | 播放器挂载节点。Vue/React 组件内部自动创建,**不要传** |
|
|
64
|
-
| `video` | 必须 | — | 视频地址或清晰度数组 |
|
|
65
|
-
| `poster` | 可选 | `''` | 封面图 |
|
|
66
|
-
| `autoplay` | 可选 | `false` | 自动播放。**课程/断点续播请保持 `false`**:有 `seek` 时组件会强制关闭自动播,只定位进度,需用户点击播放 |
|
|
67
|
-
| `volume` | 可选 | `0.8` | 音量 0–1 |
|
|
68
|
-
| `live` | 可选 | `false` | 直播相关 |
|
|
69
|
-
| `width` / `height` | 组件可选 | `100%` / `400px` | 仅 Vue/React 组件样式 |
|
|
70
|
-
|
|
71
|
-
### 一般不用写(已内置默认行为)
|
|
72
|
-
|
|
73
|
-
| 配置 | 默认 | 说明 |
|
|
74
|
-
|------|------|------|
|
|
75
|
-
| `autoPlug` | `true` | 按地址自动选插件;通常保持默认即可 |
|
|
76
|
-
| `plug` | 自动 | 仅在要强制指定或 `autoPlug: false` 时填写:`hls.js` / `flv.js` / `mpegts.js` |
|
|
77
|
-
| `preferBuiltinPlug` | `true` | 优先加载本包内置脚本,避免复用页面上其它全局 `Hls` |
|
|
78
|
-
| `cdnFallback` | `true` | `getPath` 失败时回退 jsDelivr;内网无外网请设 `false` 并配 `pluginPath
|
|
79
|
-
| `pluginPath` | 自动 | 插件脚本根路径。默认:`window.ckplayerBasePath` →
|
|
80
|
-
| `seek` | `0` | 续播秒数。HLS 对齐分片起点缓冲后再定位;**只 seek 不自动 play**,避免 Network 出现 canceled `.ts` |
|
|
81
|
-
| `loaded` | — | **只支持函数**;字符串形式已禁用(防 XSS) |
|
|
82
|
-
|
|
83
|
-
### 进阶(按需)
|
|
84
|
-
|
|
85
|
-
| 配置 | 说明 |
|
|
86
|
-
|------|------|
|
|
87
|
-
| `timeScheduleAdjust` | `5` 时只能在已看进度内拖动;续播请同时传数字 `seek` |
|
|
88
|
-
| `crossOrigin` | 跨域视频 / 截图等场景 |
|
|
89
|
-
| `cookie` | 进度记忆;组件默认使用实例唯一名,避免多实例冲突 |
|
|
90
|
-
| `language` | 语言包名,如 `en`、`zh.hk`(需能加载到 `language/*.js`) |
|
|
91
|
-
| `loop` / `controls` 等 | 与官方 ckplayer 一致,见[手册](https://www.ckplayer.com/manual/) |
|
|
92
|
-
| `window.ckplayerBasePath` | 全局指定插件根目录(以 `/` 结尾),优先于 CDN |
|
|
93
|
-
| `window.ckplayerPlusCdn` | 自定义 CDN 根地址(覆盖默认 jsDelivr) |
|
|
94
|
-
|
|
95
|
-
### 插件加载优先级
|
|
96
|
-
|
|
97
|
-
1. `preferBuiltinPlug: false` 且页面已有全局 `Hls` / `flvjs` / `mpegts` → 直接复用
|
|
98
|
-
2. 否则加载本包脚本:`pluginPath` 或可信的 `window.ckplayerBasePath`(仅 dist / npm
|
|
99
|
-
3. 传统 `<script src=".../ckplayer.min.js">`
|
|
100
|
-
4. `cdnFallback !== false` 时回退:`https://cdn.jsdelivr.net/npm/ckplayer-plus@x.y.z/dist/`;若本地路径 404 会再自动重试一次 CDN
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
>
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
<
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
},
|
|
123
|
-
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
<
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
|
163
|
-
|
|
164
|
-
|
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
1
|
+
# ckplayer-plus
|
|
2
|
+
|
|
3
|
+
基于 [ckplayer](https://www.ckplayer.com) X3 的工程化封装:支持 **npm / ESM**,并提供 **Vue 2.7+/3** 与 **React** 组件。
|
|
4
|
+
|
|
5
|
+
> **免责声明**:本包为社区/工程化封装,**非 ckplayer 官方包**。播放内核来自 ckplayer(MIT)。完整能力与参数请同时参考 [官方手册](https://www.ckplayer.com/manual/)。npm 上的官方包名为 [`ckplayer`](https://www.npmjs.com/package/ckplayer),请勿混淆。
|
|
6
|
+
|
|
7
|
+
## 安装(只需这一步)
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm i ckplayer-plus
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
**不必再单独安装** `hls.js` / `flv.js` / `mpegts.js`。
|
|
14
|
+
包内已附带对应脚本;播放时会按视频地址**自动选择插件并按需加载**。
|
|
15
|
+
|
|
16
|
+
## 自动识别规则(默认开启)
|
|
17
|
+
|
|
18
|
+
| 地址特征 | 行为 |
|
|
19
|
+
|----------|------|
|
|
20
|
+
| `.mp4` 等浏览器可直接播的格式 | 原生 `<video>`,不加载流媒体脚本 |
|
|
21
|
+
| `.m3u8` | 自动使用 `hls.js`(Safari 若原生支持则仍走原生) |
|
|
22
|
+
| `.flv` | 自动使用 `flv.js` |
|
|
23
|
+
| `.ts` / `.m2ts` / `.mts` | 自动使用 `mpegts.js` |
|
|
24
|
+
|
|
25
|
+
关闭自动识别:`autoPlug: false`,并自行传 `plug`。
|
|
26
|
+
|
|
27
|
+
## 引入样式(必做)
|
|
28
|
+
|
|
29
|
+
```js
|
|
30
|
+
import 'ckplayer-plus/style.css'
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## 最简用法(mp4 / m3u8 都这样写)
|
|
34
|
+
|
|
35
|
+
```js
|
|
36
|
+
import ckplayer from 'ckplayer-plus'
|
|
37
|
+
import 'ckplayer-plus/style.css'
|
|
38
|
+
|
|
39
|
+
const player = new ckplayer({
|
|
40
|
+
container: '#player',
|
|
41
|
+
video: url // 可以是 mp4 或 m3u8,无需再写 plug
|
|
42
|
+
})
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Vue:
|
|
46
|
+
|
|
47
|
+
```vue
|
|
48
|
+
<CkPlayer :video="url" height="400px" />
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
React:
|
|
52
|
+
|
|
53
|
+
```jsx
|
|
54
|
+
<CkPlayer video={url} height="400px" />
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## 配置说明(哪些要写、哪些不用写)
|
|
58
|
+
|
|
59
|
+
### 常用且推荐
|
|
60
|
+
|
|
61
|
+
| 配置 | 是否必须 | 默认 | 说明 |
|
|
62
|
+
|------|----------|------|------|
|
|
63
|
+
| `container` | 核心 API 必须;组件不用 | — | 播放器挂载节点。Vue/React 组件内部自动创建,**不要传** |
|
|
64
|
+
| `video` | 必须 | — | 视频地址或清晰度数组 |
|
|
65
|
+
| `poster` | 可选 | `''` | 封面图 |
|
|
66
|
+
| `autoplay` | 可选 | `false` | 自动播放。**课程/断点续播请保持 `false`**:有 `seek` 时组件会强制关闭自动播,只定位进度,需用户点击播放 |
|
|
67
|
+
| `volume` | 可选 | `0.8` | 音量 0–1 |
|
|
68
|
+
| `live` | 可选 | `false` | 直播相关 |
|
|
69
|
+
| `width` / `height` | 组件可选 | `100%` / `400px` | 仅 Vue/React 组件样式 |
|
|
70
|
+
|
|
71
|
+
### 一般不用写(已内置默认行为)
|
|
72
|
+
|
|
73
|
+
| 配置 | 默认 | 说明 |
|
|
74
|
+
|------|------|------|
|
|
75
|
+
| `autoPlug` | `true` | 按地址自动选插件;通常保持默认即可 |
|
|
76
|
+
| `plug` | 自动 | 仅在要强制指定或 `autoPlug: false` 时填写:`hls.js` / `flv.js` / `mpegts.js` |
|
|
77
|
+
| `preferBuiltinPlug` | `true` | 优先加载本包内置脚本,避免复用页面上其它全局 `Hls` |
|
|
78
|
+
| `cdnFallback` | `true` | `getPath` 失败时回退 jsDelivr;内网无外网请设 `false` 并配 `pluginPath`(或确保能访问 `/node_modules/ckplayer-plus/dist/`) |
|
|
79
|
+
| `pluginPath` | 自动 | 插件脚本根路径。默认:`window.ckplayerBasePath` → 可信 script/`dist` → jsDelivr CDN → `/node_modules/ckplayer-plus/dist/`。**勿设成 `/src/`**;也勿依赖当前页相对路径 |
|
|
80
|
+
| `seek` | `0` | 续播秒数。HLS 对齐分片起点缓冲后再定位;**只 seek 不自动 play**,避免 Network 出现 canceled `.ts` |
|
|
81
|
+
| `loaded` | — | **只支持函数**;字符串形式已禁用(防 XSS) |
|
|
82
|
+
|
|
83
|
+
### 进阶(按需)
|
|
84
|
+
|
|
85
|
+
| 配置 | 说明 |
|
|
86
|
+
|------|------|
|
|
87
|
+
| `timeScheduleAdjust` | `5` 时只能在已看进度内拖动;续播请同时传数字 `seek` |
|
|
88
|
+
| `crossOrigin` | 跨域视频 / 截图等场景 |
|
|
89
|
+
| `cookie` | 进度记忆;组件默认使用实例唯一名,避免多实例冲突 |
|
|
90
|
+
| `language` | 语言包名,如 `en`、`zh.hk`(需能加载到 `language/*.js`) |
|
|
91
|
+
| `loop` / `controls` 等 | 与官方 ckplayer 一致,见[手册](https://www.ckplayer.com/manual/) |
|
|
92
|
+
| `window.ckplayerBasePath` | 全局指定插件根目录(以 `/` 结尾),优先于 CDN |
|
|
93
|
+
| `window.ckplayerPlusCdn` | 自定义 CDN 根地址(覆盖默认 jsDelivr) |
|
|
94
|
+
|
|
95
|
+
### 插件加载优先级
|
|
96
|
+
|
|
97
|
+
1. `preferBuiltinPlug: false` 且页面已有全局 `Hls` / `flvjs` / `mpegts` → 直接复用
|
|
98
|
+
2. 否则加载本包脚本:`pluginPath` 或可信的 `window.ckplayerBasePath`(仅 dist / npm 包路径会自动设置;`/src`、`assets`、`.vite/deps`、chunk 目录会忽略)
|
|
99
|
+
3. 传统 `<script src=".../ckplayer.min.js">` 同级目录推导(**不会**再用页面最后一个无关 script,避免 Vite 指到 `/src/main.js`)
|
|
100
|
+
4. `cdnFallback !== false` 时回退:`https://cdn.jsdelivr.net/npm/ckplayer-plus@x.y.z/dist/`;若本地路径 404 会再自动重试一次 CDN
|
|
101
|
+
5. 仍无可靠根时:站点根相对 `/node_modules/ckplayer-plus/dist/`(Vite 开发态常用;**不是**当前路由目录下的相对路径)
|
|
102
|
+
|
|
103
|
+
> **Vue 2.7 / Vue 3 / React(Vite/Webpack)**:直接 `import { CkPlayer } from 'ckplayer-plus/vue'`(或 `/react`)即可。默认会走 jsDelivr CDN;内网请把 `dist/hls.js` 等拷到静态目录并设 `pluginPath`,同时 `cdnFallback: false`。
|
|
104
|
+
> **不要**指望 `hls.js/hls.min.js` 这种相对路径——在 `/student/course` 一类 SPA 路由下会错误请求 `/student/hls.js/...`。
|
|
105
|
+
> 本地调试本仓库 demo:先 `npm run build`,再用静态服务打开 `examples/demo.html`(`dist/` 被 gitignore,不重建会跑到旧逻辑)。
|
|
106
|
+
> 样式请使用 `import 'ckplayer-plus/style.css'`,保证 `./images/` 图标能被打包工具解析。
|
|
107
|
+
|
|
108
|
+
## Vue 2.7 / Vue 3
|
|
109
|
+
|
|
110
|
+
支持 **Vue 2.7+** 与 **Vue 3**(需从 `vue` 解析 `h`,与 peerDependencies 一致)。
|
|
111
|
+
|
|
112
|
+
```vue
|
|
113
|
+
<template>
|
|
114
|
+
<CkPlayer :video="url" :seek="16" poster="/poster.png" height="400px" @play="onPlay" />
|
|
115
|
+
</template>
|
|
116
|
+
|
|
117
|
+
<script>
|
|
118
|
+
import { CkPlayer } from 'ckplayer-plus/vue'
|
|
119
|
+
import 'ckplayer-plus/style.css'
|
|
120
|
+
|
|
121
|
+
export default {
|
|
122
|
+
components: { CkPlayer },
|
|
123
|
+
data() {
|
|
124
|
+
return { url: 'https://example.com/a.m3u8' } // 或 .mp4
|
|
125
|
+
},
|
|
126
|
+
methods: { onPlay() {} }
|
|
127
|
+
}
|
|
128
|
+
</script>
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
断点续播:`seek` 用 `:seek` 或 `options.seek` 在创建时传入;**不要**在 `@ready` 里再 `player.seek(16)`,否则会重复加载 HLS、取消 `.ts` 分片导致卡住。有 `seek` 时不会自动播放,定位完成后点中央播放按钮即可。切集/切换清晰度同样不强制自动播。
|
|
132
|
+
|
|
133
|
+
SSR(Nuxt 等)请用 `<ClientOnly>`,仅在浏览器初始化。
|
|
134
|
+
|
|
135
|
+
## React
|
|
136
|
+
|
|
137
|
+
```jsx
|
|
138
|
+
import { CkPlayer } from 'ckplayer-plus/react'
|
|
139
|
+
import 'ckplayer-plus/style.css'
|
|
140
|
+
|
|
141
|
+
<CkPlayer video={url} height="400px" onPlay={() => {}} />
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
Next.js 使用 Client Component 或 `dynamic(..., { ssr: false })`。
|
|
145
|
+
|
|
146
|
+
## 脚本标签
|
|
147
|
+
|
|
148
|
+
```html
|
|
149
|
+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/ckplayer-plus/dist/ckplayer.css" />
|
|
150
|
+
<script src="https://cdn.jsdelivr.net/npm/ckplayer-plus/dist/ckplayer.min.js"></script>
|
|
151
|
+
<div id="player" style="width:800px;height:450px;"></div>
|
|
152
|
+
<script>
|
|
153
|
+
new ckplayer({
|
|
154
|
+
container: '#player',
|
|
155
|
+
video: 'https://example.com/video.mp4'
|
|
156
|
+
})
|
|
157
|
+
</script>
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
## 重要说明
|
|
161
|
+
|
|
162
|
+
| 主题 | 说明 |
|
|
163
|
+
|------|------|
|
|
164
|
+
| SSR | 依赖 `document`,必须客户端初始化 |
|
|
165
|
+
| 移动端自动播 | 常需 `volume: 0` 或用户手势 |
|
|
166
|
+
| dash.js | 未实现 |
|
|
167
|
+
| 体积 | 主包含流媒体 min 脚本以便「只装一个包」;运行时仍按需加载 |
|
|
168
|
+
|
|
169
|
+
## 开发与发布
|
|
170
|
+
|
|
171
|
+
```bash
|
|
172
|
+
npm install
|
|
173
|
+
npm run build
|
|
174
|
+
npm publish --access public
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
## License
|
|
178
|
+
|
|
179
|
+
MIT。内置的 hls.js / flv.js / mpegts.js 遵循各自许可证(多为 Apache-2.0)。
|
package/dist/ckplayer.js
CHANGED
|
@@ -141,7 +141,9 @@
|
|
|
141
141
|
cdnFallback:true// getPath 失败时是否回退到 jsDelivr(内网可设 false,并配置 pluginPath)
|
|
142
142
|
};
|
|
143
143
|
// 打包时替换为真实版本;用于 bundler 下 getPath 失效时的 CDN 回退
|
|
144
|
-
var ckplayerPlusDefaultCdn='https://cdn.jsdelivr.net/npm/ckplayer-plus@1.1.
|
|
144
|
+
var ckplayerPlusDefaultCdn='https://cdn.jsdelivr.net/npm/ckplayer-plus@1.1.12/dist/';
|
|
145
|
+
// 构建脚本会把下一行改为 true;勿用版本号字符串做 CDN 可用性判断(默认 CDN URL 本身含版本)
|
|
146
|
+
var ckplayerPlusCdnReady=true; // BUILD_CDN_READY
|
|
145
147
|
function ckplayerEmbed(videoObj){
|
|
146
148
|
/*
|
|
147
149
|
* rightMenu
|
|
@@ -411,22 +413,14 @@
|
|
|
411
413
|
return embed(obj);
|
|
412
414
|
}
|
|
413
415
|
},
|
|
414
|
-
/*
|
|
415
|
-
* isUnreliablePluginBase
|
|
416
|
-
* 功能:识别 bundler chunk 目录(不含 hls.js 等插件),避免短路 CDN 回退
|
|
417
|
-
*/
|
|
418
|
-
isUnreliablePluginBase=function(base){
|
|
419
|
-
if(!base || valType(base)!='string'){
|
|
420
|
-
return true;
|
|
421
|
-
}
|
|
422
|
-
return /\/(?:assets|\.vite\/deps|_next\/static|chunks?)\/?$/i.test(base);
|
|
423
|
-
},
|
|
424
416
|
/*
|
|
425
417
|
* resolveAssetPath
|
|
426
418
|
* 功能:解析插件/语言包路径
|
|
427
|
-
* 优先级:pluginPath > window.ckplayerBasePath > script 推导 > 本包 CDN
|
|
419
|
+
* 优先级:pluginPath > window.ckplayerBasePath > script 推导 > 本包 CDN > /node_modules/.../dist/
|
|
420
|
+
* 禁止返回「hls.js/xxx」这类文档相对路径(会在 SPA 子路由下变成 /student/hls.js/... 404)
|
|
428
421
|
*/
|
|
429
422
|
resolveAssetPath=function (folder,file){
|
|
423
|
+
var asset=folder+'/'+file;
|
|
430
424
|
var base='';
|
|
431
425
|
if(vars && vars['pluginPath']){
|
|
432
426
|
base=vars['pluginPath'];
|
|
@@ -441,22 +435,31 @@
|
|
|
441
435
|
if(base.slice(-1)!=='/'){
|
|
442
436
|
base+='/';
|
|
443
437
|
}
|
|
444
|
-
return base+
|
|
438
|
+
return base+asset;
|
|
445
439
|
}
|
|
446
|
-
var
|
|
447
|
-
|
|
440
|
+
var scriptBase=getPath();
|
|
441
|
+
var fromScript=scriptBase ? (getPath(folder)+file) : '';
|
|
442
|
+
if(fromScript && fromScript.indexOf(folder+'/')>-1 && fromScript.indexOf('undefined')===-1 && !isUnreliablePluginBase(scriptBase)){
|
|
448
443
|
return fromScript;
|
|
449
444
|
}
|
|
450
445
|
var allowCdn=!vars || vars['cdnFallback']!==false;
|
|
451
446
|
var cdn=(typeof window!=='undefined' && window.ckplayerPlusCdn) ? window.ckplayerPlusCdn : ckplayerPlusDefaultCdn;
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
447
|
+
// 仅用构建注入的就绪标记;禁止 indexOf(版本号)/indexOf(占位符)(会与 CDN URL 自撞)
|
|
448
|
+
if(allowCdn && ckplayerPlusCdnReady && cdn){
|
|
449
|
+
if(cdn.slice(-1)!=='/'){
|
|
450
|
+
cdn+='/';
|
|
451
|
+
}
|
|
452
|
+
return cdn+asset;
|
|
455
453
|
}
|
|
456
|
-
|
|
457
|
-
|
|
454
|
+
// Vite/Webpack 开发态:站点根相对路径,不受 /student/course 等 SPA 路由影响
|
|
455
|
+
var npmDist=guessNpmDistBase();
|
|
456
|
+
if(npmDist){
|
|
457
|
+
return npmDist+asset;
|
|
458
458
|
}
|
|
459
|
-
|
|
459
|
+
if(typeof console!=='undefined' && console.warn){
|
|
460
|
+
console.warn('[ckplayer-plus] cannot resolve plugin path for '+asset+'. Set pluginPath / window.ckplayerBasePath, or keep cdnFallback:true.');
|
|
461
|
+
}
|
|
462
|
+
return '';
|
|
460
463
|
},
|
|
461
464
|
/*
|
|
462
465
|
* guessPlug
|
|
@@ -7468,6 +7471,12 @@
|
|
|
7468
7471
|
if(!isUndefined(callback)){
|
|
7469
7472
|
fn=callback;
|
|
7470
7473
|
}
|
|
7474
|
+
if(!file){
|
|
7475
|
+
if(typeof console!=='undefined' && console.warn){
|
|
7476
|
+
console.warn('[ckplayer-plus] loadJs skipped: empty plugin path');
|
|
7477
|
+
}
|
|
7478
|
+
return;
|
|
7479
|
+
}
|
|
7471
7480
|
if(checkJs(file)){
|
|
7472
7481
|
fn();
|
|
7473
7482
|
return;
|
|
@@ -7514,8 +7523,8 @@
|
|
|
7514
7523
|
// bundler 下错误 base 路径 404 时,回退 jsDelivr 再试一次
|
|
7515
7524
|
if(!isRetry && (!vars || vars['cdnFallback']!==false)){
|
|
7516
7525
|
var cdn=(typeof window!=='undefined' && window.ckplayerPlusCdn) ? window.ckplayerPlusCdn : ckplayerPlusDefaultCdn;
|
|
7517
|
-
var m=String(file).match(
|
|
7518
|
-
if(cdn &&
|
|
7526
|
+
var m=String(file).match(/(?:^|\/)(hls\.js|flv\.js|mpegts\.js|language)\/([^/?#]+)(?:[?#].*)?$/i);
|
|
7527
|
+
if(cdn && ckplayerPlusCdnReady && m){
|
|
7519
7528
|
if(cdn.slice(-1)!=='/'){
|
|
7520
7529
|
cdn+='/';
|
|
7521
7530
|
}
|
|
@@ -7810,18 +7819,46 @@
|
|
|
7810
7819
|
}
|
|
7811
7820
|
|
|
7812
7821
|
}
|
|
7822
|
+
/*
|
|
7823
|
+
* guessNpmDistBase
|
|
7824
|
+
* 功能:Vite/Webpack 开发态下用站点根相对路径访问 npm 包内 dist(含 hls.js/)
|
|
7825
|
+
* 必须以 / 开头,绝不能用文档相对路径(否则 /student/course 会解析成 /student/hls.js/...)
|
|
7826
|
+
*/
|
|
7827
|
+
function guessNpmDistBase() {
|
|
7828
|
+
return '/node_modules/ckplayer-plus/dist/';
|
|
7829
|
+
}
|
|
7830
|
+
/*
|
|
7831
|
+
* isUnreliablePluginBase
|
|
7832
|
+
* 功能:识别不会托管 hls.js/flv.js 的目录,避免 Vite/Webpack 下请求 /src/hls.js 等 404
|
|
7833
|
+
*/
|
|
7834
|
+
function isUnreliablePluginBase(base) {
|
|
7835
|
+
if (!base || typeof base !== 'string') {
|
|
7836
|
+
return true;
|
|
7837
|
+
}
|
|
7838
|
+
var b = base.replace(/\\/g, '/');
|
|
7839
|
+
// bundler 产物 / 依赖预构建目录
|
|
7840
|
+
if (/\/(?:assets|\.vite\/deps|_next\/static|chunks?|static\/js|webpack|@fs|@id|@vite)\/?$/i.test(b)) {
|
|
7841
|
+
return true;
|
|
7842
|
+
}
|
|
7843
|
+
// 应用源码根(Vite 常见:…/src/main.js → 误推 …/src/hls.js/…)
|
|
7844
|
+
if (/\/(?:src|app|pages|views|components)\/?$/i.test(b)) {
|
|
7845
|
+
return true;
|
|
7846
|
+
}
|
|
7847
|
+
// 仅站点根路径,不含插件文件
|
|
7848
|
+
if (/^https?:\/\/[^/?#]+\/?$/i.test(b)) {
|
|
7849
|
+
return true;
|
|
7850
|
+
}
|
|
7851
|
+
return false;
|
|
7852
|
+
}
|
|
7813
7853
|
/*
|
|
7814
7854
|
* getPath
|
|
7815
7855
|
* 功能:获取该js文件所在路径
|
|
7856
|
+
* 仅信任 ckplayer 脚本或可信的 ckplayerBasePath;勿回退到页面最后一个 script(Vite 常为 /src/main.js)
|
|
7816
7857
|
*/
|
|
7817
7858
|
function getPath(siz) {
|
|
7818
7859
|
if (typeof window !== 'undefined' && window.ckplayerBasePath) {
|
|
7819
7860
|
var base = window.ckplayerBasePath;
|
|
7820
|
-
|
|
7821
|
-
if (/\/(?:assets|\.vite\/deps|_next\/static|chunks?)\/?$/i.test(base)) {
|
|
7822
|
-
base = '';
|
|
7823
|
-
}
|
|
7824
|
-
if (base) {
|
|
7861
|
+
if (!isUnreliablePluginBase(base)) {
|
|
7825
7862
|
if (base.slice(-1) !== '/') {
|
|
7826
7863
|
base += '/';
|
|
7827
7864
|
}
|
|
@@ -7831,13 +7868,17 @@
|
|
|
7831
7868
|
return base;
|
|
7832
7869
|
}
|
|
7833
7870
|
}
|
|
7834
|
-
var scriptList = document.scripts || []
|
|
7835
|
-
|
|
7871
|
+
var scriptList = document.scripts || [];
|
|
7872
|
+
var thisPath = '';
|
|
7836
7873
|
for (var i = 0; i < scriptList.length; i++) {
|
|
7837
7874
|
var scriptName = scriptList[i].getAttribute('name') || scriptList[i].getAttribute('data-name');
|
|
7838
|
-
var
|
|
7839
|
-
if (
|
|
7840
|
-
|
|
7875
|
+
var srcFull = scriptList[i].src || '';
|
|
7876
|
+
if (!srcFull) {
|
|
7877
|
+
continue;
|
|
7878
|
+
}
|
|
7879
|
+
var src = srcFull.slice(srcFull.lastIndexOf('/') + 1, srcFull.lastIndexOf('.'));
|
|
7880
|
+
if ((scriptName && (scriptName == 'ckplayer' || scriptName == 'ckplayer.min' || scriptName == 'ckplayer-plus')) || (src == 'ckplayer' || src == 'ckplayer.min' || src.indexOf('ckplayer') === 0)) {
|
|
7881
|
+
thisPath = srcFull;
|
|
7841
7882
|
break;
|
|
7842
7883
|
}
|
|
7843
7884
|
}
|
|
@@ -7847,6 +7888,9 @@
|
|
|
7847
7888
|
} else if (thisPath && thisPath.lastIndexOf('/') > -1) {
|
|
7848
7889
|
path = thisPath.substring(0, thisPath.lastIndexOf('/') + 1);
|
|
7849
7890
|
}
|
|
7891
|
+
if (!path || isUnreliablePluginBase(path)) {
|
|
7892
|
+
return '';
|
|
7893
|
+
}
|
|
7850
7894
|
if (!isUndefined(siz)) {
|
|
7851
7895
|
path += siz + '/';
|
|
7852
7896
|
}
|