Skip to content

Commit 321e76c

Browse files
authored
(dash/HLS): update DRM configure (#151)
1 parent 69ebbca commit 321e76c

File tree

12 files changed

+616
-341
lines changed

12 files changed

+616
-341
lines changed

examples/standalone/main.ts

Lines changed: 48 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,16 @@ const player = Player.make<Ctx>('#player', {
143143
// source: DANMAKU //SUPER_DANMAKU
144144
}),
145145
new Playlist({
146-
initialIndex: 3,
146+
initialIndex: 0,
147147
sources: [
148+
{
149+
title: 'DASH DRM',
150+
id: 'dash-drm'
151+
},
152+
{
153+
title: 'Hls DRM',
154+
id: 'hls-drm'
155+
},
148156
{
149157
title: 'hls - muti quality & subtitle & audio',
150158
src: 'https://storage.googleapis.com/shaka-demo-assets/angel-one-hls/hls.m3u8'
@@ -197,12 +205,6 @@ const player = Player.make<Ctx>('#player', {
197205
],
198206
highlights: highlight
199207
},
200-
{
201-
title: 'BROKEN SOURCE & POSTER',
202-
src: '//',
203-
poster: '//',
204-
duration: '00:00'
205-
},
206208
{
207209
title: "Disney's Oceans - MP4",
208210
src: 'https://vjs.zencdn.net/v/oceans.mp4',
@@ -232,7 +234,45 @@ const player = Player.make<Ctx>('#player', {
232234
// 'magnet:?xt=urn:btih:08ada5a7a6183aae1e09d831df6748d566095a10&dn=Sintel&tr=udp%3A%2F%2Fexplodie.org%3A6969&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A6969&tr=udp%3A%2F%2Ftracker.empire-js.us%3A1337&tr=udp%3A%2F%2Ftracker.leechers-paradise.org%3A6969&tr=udp%3A%2F%2Ftracker.opentrackr.org%3A1337&tr=wss%3A%2F%2Ftracker.btorrent.xyz&tr=wss%3A%2F%2Ftracker.fastcast.nz&tr=wss%3A%2F%2Ftracker.openwebtorrent.com&ws=https%3A%2F%2Fwebtorrent.io%2Ftorrents%2F&xs=https%3A%2F%2Fwebtorrent.io%2Ftorrents%2Fsintel.torrent',
233235
poster: 'https://api.imlazy.ink/img?webtorrent'
234236
}
235-
]
237+
],
238+
customFetcher(player, source) {
239+
if (source.id === 'dash-drm') {
240+
;(player.context.dash as ReturnType<typeof dash>).options.drm = {
241+
'com.widevine.alpha': {
242+
serverURL: 'https://drm-widevine-licensing.axtest.net/AcquireLicense',
243+
httpRequestHeaders: {
244+
'X-AxDRM-Message':
245+
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2ZXJzaW9uIjoxLCJjb21fa2V5X2lkIjoiYjMzNjRlYjUtNTFmNi00YWUzLThjOTgtMzNjZWQ1ZTMxYzc4IiwibWVzc2FnZSI6eyJ0eXBlIjoiZW50aXRsZW1lbnRfbWVzc2FnZSIsImtleXMiOlt7ImlkIjoiOWViNDA1MGQtZTQ0Yi00ODAyLTkzMmUtMjdkNzUwODNlMjY2IiwiZW5jcnlwdGVkX2tleSI6ImxLM09qSExZVzI0Y3Iya3RSNzRmbnc9PSJ9XX19.4lWwW46k-oWcah8oN18LPj5OLS5ZU-_AQv7fe0JhNjA'
246+
},
247+
priority: 0
248+
}
249+
}
250+
return {
251+
...source,
252+
src: 'https://media.axprod.net/TestVectors/v7-MultiDRM-SingleKey/Manifest_1080p.mpd'
253+
}
254+
} else if (source.id == 'hls-drm') {
255+
;(player.context.hls as ReturnType<typeof hls>).options.config = {
256+
...player.context.hls.options.config,
257+
emeEnabled: true,
258+
drmSystems: {
259+
'com.widevine.alpha': {
260+
licenseUrl: 'https://widevine-proxy.appspot.com/proxy'
261+
}
262+
},
263+
licenseXhrSetup(xhr) {
264+
xhr.setRequestHeader('content-type', 'application/octet-stream')
265+
xhr.setRequestHeader('Authorization', 'Bearer token') // or other headers
266+
}
267+
}
268+
269+
return {} //TODO
270+
} else {
271+
;(player.context.dash as ReturnType<typeof dash>).options.drm = null
272+
;(player.context.hls as ReturnType<typeof hls>).options.config.emeEnabled = false
273+
}
274+
return source
275+
}
236276
// m3uList: {
237277
// sourceFormat(info) {
238278
// const chunk = info.title.substring(3).split(' ')
@@ -257,8 +297,6 @@ function stopLoad() {
257297
player.$video.src = URL.createObjectURL(new Blob([u8.buffer]))
258298
}
259299

260-
let src: string = player.context.playlist.options.sources[initialIndex].src
261-
262300
render(
263301
html`
264302
<div>

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
"lint": "prettier -w ./packages/*/**/*.ts"
3333
},
3434
"devDependencies": {
35-
"@babel/core": "^7.26.8",
35+
"@babel/core": "^7.26.9",
3636
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
3737
"@babel/plugin-transform-destructuring": "^7.25.9",
3838
"@babel/plugin-transform-logical-assignment-operators": "^7.25.9",
@@ -41,7 +41,7 @@
4141
"@babel/plugin-transform-parameters": "^7.25.9",
4242
"@babel/plugin-transform-spread": "^7.25.9",
4343
"@babel/plugin-transform-template-literals": "^7.26.8",
44-
"@changesets/cli": "^2.27.12",
44+
"@changesets/cli": "^2.28.0",
4545
"@rollup/plugin-babel": "^6.0.4",
4646
"@types/node": "^20.17.19",
4747
"@vitejs/plugin-react": "^4.3.4",

packages/dash/README.md

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,20 +33,23 @@ npm i @oplayer/core @oplayer/dash dashjs
3333

3434
## DRM
3535

36-
```js
37-
var protData = {
38-
'com.widevine.alpha': {
39-
serverURL: 'https://drm-widevine-licensing.axtest.net/AcquireLicense',
40-
httpRequestHeaders: {
41-
'X-AxDRM-Message':
42-
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2ZXJzaW9uIjoxLCJjb21fa2V5X2lkIjoiYjMzNjRlYjUtNTFmNi00YWUzLThjOTgtMzNjZWQ1ZTMxYzc4IiwibWVzc2FnZSI6eyJ0eXBlIjoiZW50aXRsZW1lbnRfbWVzc2FnZSIsImtleXMiOlt7ImlkIjoiOWViNDA1MGQtZTQ0Yi00ODAyLTkzMmUtMjdkNzUwODNlMjY2IiwiZW5jcnlwdGVkX2tleSI6ImxLM09qSExZVzI0Y3Iya3RSNzRmbnc9PSJ9XX19.4lWwW46k-oWcah8oN18LPj5OLS5ZU-_AQv7fe0JhNjA'
43-
},
44-
priority: 0
36+
```ts
37+
// https://media.axprod.net/TestVectors/v7-MultiDRM-SingleKey/Manifest_1080p.mpd
38+
ODash({
39+
drm: {
40+
'com.widevine.alpha': {
41+
serverURL: 'https://drm-widevine-licensing.axtest.net/AcquireLicense',
42+
httpRequestHeaders: {
43+
'X-AxDRM-Message':
44+
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2ZXJzaW9uIjoxLCJjb21fa2V5X2lkIjoiYjMzNjRlYjUtNTFmNi00YWUzLThjOTgtMzNjZWQ1ZTMxYzc4IiwibWVzc2FnZSI6eyJ0eXBlIjoiZW50aXRsZW1lbnRfbWVzc2FnZSIsImtleXMiOlt7ImlkIjoiOWViNDA1MGQtZTQ0Yi00ODAyLTkzMmUtMjdkNzUwODNlMjY2IiwiZW5jcnlwdGVkX2tleSI6ImxLM09qSExZVzI0Y3Iya3RSNzRmbnc9PSJ9XX19.4lWwW46k-oWcah8oN18LPj5OLS5ZU-_AQv7fe0JhNjA'
45+
},
46+
priority: 0
47+
}
4548
}
46-
}
47-
48-
player.changeSource({ src: 'https://media.axprod.net/TestVectors/v7-MultiDRM-SingleKey/Manifest_1080p.mpd' })
49-
player.once('loaderchange', () => {
50-
player.context.dash.instance.setProtectionData(protData)
5149
})
50+
51+
// update drm
52+
player.context.dash.options.drm = {
53+
// ...
54+
}
5255
```

packages/dash/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@oplayer/dash",
3-
"version": "1.2.27-beta.0",
3+
"version": "1.2.27-beta.1",
44
"description": "Dash plugin for oplayer",
55
"type": "module",
66
"main": "./dist/index.es.js",

packages/dash/src/index.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type {
33
BitrateInfo,
44
MediaPlayerClass,
55
MediaPlayerSettingClass,
6+
ProtectionDataSet,
67
QualityChangeRenderedEvent
78
} from 'dashjs'
89

@@ -36,6 +37,8 @@ export interface DashPluginOptions {
3637
*/
3738
config?: MediaPlayerSettingClass
3839

40+
drm?: ProtectionDataSet
41+
3942
// qualityLabelBuilder?: (instance: MediaPlayerClass) => {
4043
// name: string
4144
// default: boolean
@@ -83,7 +86,7 @@ class DashPlugin implements PlayerPlugin {
8386

8487
instance?: MediaPlayerClass
8588

86-
options: RequiredPartial<DashPluginOptions, 'config' | 'library'> = {
89+
options: RequiredPartial<DashPluginOptions, 'config' | 'library' | 'drm'> = {
8790
textControl: true,
8891
audioControl: true,
8992
qualityControl: true,
@@ -119,9 +122,10 @@ class DashPlugin implements PlayerPlugin {
119122
this.instance = DashPlugin.library.MediaPlayer().create()
120123

121124
const { player, instance } = this
122-
const { config } = this.options
125+
const { drm, config } = this.options
123126

124127
if (config) instance.updateSettings(config)
128+
if (drm) instance.setProtectionData(drm)
125129
instance.initialize($video, source.src, $video.autoplay)
126130

127131
instance.on(DashPlugin.library.MediaPlayer.events.ERROR, function (event: any) {
@@ -325,6 +329,6 @@ const removeSetting = (player: Player) => {
325329
)
326330
}
327331

328-
export default function create(options?: DashPluginOptions): PlayerPlugin {
332+
export default function create(options?: DashPluginOptions) {
329333
return new DashPlugin(options)
330334
}

packages/docs/tsconfig.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@
1616
"incremental": true,
1717
"paths": {
1818
"@/*": ["./src/*"]
19-
}
19+
},
20+
"plugins": [{ "name": "next" }]
2021
},
21-
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
22+
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
2223
"exclude": ["node_modules"]
2324
}

packages/hls/README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,28 @@ OHls({
8080
}
8181
})
8282
```
83+
84+
## DRM
85+
86+
```ts
87+
OHls({
88+
forceHLS: true, // use hls.js not native
89+
config: {
90+
emeEnabled: true,
91+
drmSystems: {
92+
'com.widevine.alpha': {
93+
licenseUrl: 'https://widevine-proxy.appspot.com/proxy'
94+
}
95+
},
96+
licenseXhrSetup(xhr) {
97+
xhr.setRequestHeader('content-type', 'application/octet-stream')
98+
xhr.setRequestHeader('Authorization', 'Bearer token') // or other headers
99+
}
100+
}
101+
})
102+
103+
// update
104+
player.context.hls.options.config = {
105+
//...
106+
}
107+
```

packages/hls/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@oplayer/hls",
3-
"version": "1.2.27",
3+
"version": "1.2.28-beta.1",
44
"description": "Hls plugin for oplayer",
55
"type": "module",
66
"main": "./dist/index.es.js",

packages/hls/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ class HlsPlugin implements PlayerPlugin {
195195
}
196196
}
197197

198-
export default function create(options?: HlsPluginOptions): PlayerPlugin {
198+
export default function create(options?: HlsPluginOptions) {
199199
return new HlsPlugin(options)
200200
}
201201

packages/plugins/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@oplayer/plugins",
3-
"version": "1.0.15-beta.2",
3+
"version": "1.0.15-beta.3",
44
"author": "shiyiya",
55
"description": "oplayer's plugin",
66
"homepage": "https://github.com/shiyiya/oplayer",

0 commit comments

Comments
 (0)