@gcorevideo/player 2.24.0 → 2.24.1
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/dist/core.js +1 -1
- package/dist/index.css +1312 -1312
- package/dist/index.js +40 -55
- package/dist/player.d.ts +46 -1
- package/docs/api/player.cmcdconfig._constructor_.md +50 -0
- package/docs/api/player.cmcdconfig.bindevents.md +19 -0
- package/docs/api/player.cmcdconfig.exportids.md +21 -0
- package/docs/api/player.cmcdconfig.md +191 -0
- package/docs/api/player.cmcdconfig.name.md +15 -0
- package/docs/api/player.cmcdconfig.supportedversion.md +14 -0
- package/docs/api/player.cmcdconfig.version.md +14 -0
- package/docs/api/player.cmcdconfigpluginsettings.md +18 -0
- package/docs/api/player.md +22 -0
- package/lib/plugins/cmcd-config/CmcdConfig.d.ts +8 -8
- package/lib/plugins/cmcd-config/CmcdConfig.d.ts.map +1 -1
- package/lib/plugins/cmcd-config/CmcdConfig.js +43 -47
- package/lib/plugins/cmcd-config/utils.d.ts +0 -1
- package/lib/plugins/cmcd-config/utils.d.ts.map +1 -1
- package/lib/plugins/cmcd-config/utils.js +0 -9
- package/lib/testUtils.d.ts +1 -0
- package/lib/testUtils.d.ts.map +1 -1
- package/lib/testUtils.js +1 -0
- package/package.json +1 -1
- package/src/plugins/cmcd-config/CmcdConfig.ts +57 -57
- package/src/plugins/cmcd-config/__tests__/CmcdConfig.test.ts +96 -84
- package/src/plugins/cmcd-config/utils.ts +0 -10
- package/src/testUtils.ts +1 -0
- package/temp/player.api.json +243 -0
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import { CorePlugin, Events
|
|
2
|
-
import {
|
|
1
|
+
import { $, CorePlugin, Events } from '@clappr/core';
|
|
2
|
+
// import { trace } from '@gcorevideo/utils'
|
|
3
|
+
import { generateSessionId } from './utils';
|
|
4
|
+
import { CLAPPR_VERSION } from '../../build.js';
|
|
3
5
|
const CMCD_KEYS = [
|
|
4
6
|
'br',
|
|
5
7
|
'd',
|
|
@@ -20,6 +22,7 @@ const CMCD_KEYS = [
|
|
|
20
22
|
'st',
|
|
21
23
|
'v',
|
|
22
24
|
];
|
|
25
|
+
// const T = 'plugins.cmcd'
|
|
23
26
|
/**
|
|
24
27
|
* A `PLUGIN` that configures CMCD for playback
|
|
25
28
|
* @beta
|
|
@@ -36,56 +39,62 @@ export class CmcdConfig extends CorePlugin {
|
|
|
36
39
|
get name() {
|
|
37
40
|
return 'cmcd';
|
|
38
41
|
}
|
|
42
|
+
get version() {
|
|
43
|
+
return '0.1.0';
|
|
44
|
+
}
|
|
45
|
+
get supportedVersion() {
|
|
46
|
+
return CLAPPR_VERSION;
|
|
47
|
+
}
|
|
39
48
|
constructor(core) {
|
|
40
49
|
super(core);
|
|
41
50
|
this.sid = this.options.cmcd?.sessionId ?? generateSessionId();
|
|
51
|
+
this.cid = this.options.cmcd?.contentId ?? this.generateContentId();
|
|
42
52
|
}
|
|
43
53
|
/**
|
|
44
54
|
* @inheritdocs
|
|
45
55
|
*/
|
|
46
56
|
bindEvents() {
|
|
47
|
-
this.listenTo(this.core, Events.
|
|
57
|
+
this.listenTo(this.core, Events.CORE_CONTAINERS_CREATED, () => this.updateSettings(this.core.containers[0]));
|
|
48
58
|
}
|
|
49
|
-
|
|
59
|
+
exportIds() {
|
|
50
60
|
return {
|
|
51
61
|
sid: this.sid,
|
|
52
|
-
cid:
|
|
62
|
+
cid: this.cid,
|
|
53
63
|
};
|
|
54
64
|
}
|
|
55
|
-
updateSettings() {
|
|
56
|
-
switch (
|
|
65
|
+
async updateSettings(container) {
|
|
66
|
+
switch (container.playback.name) {
|
|
57
67
|
case 'dash':
|
|
58
|
-
|
|
68
|
+
$.extend(true, container.playback.options, {
|
|
69
|
+
dash: {
|
|
70
|
+
cmcd: {
|
|
71
|
+
enabled: true,
|
|
72
|
+
enabledKeys: CMCD_KEYS,
|
|
73
|
+
sid: this.sid,
|
|
74
|
+
cid: this.cid,
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
});
|
|
59
78
|
break;
|
|
60
79
|
case 'hls':
|
|
61
|
-
|
|
80
|
+
$.extend(true, container.playback.options, {
|
|
81
|
+
playback: {
|
|
82
|
+
hlsjsConfig: {
|
|
83
|
+
cmcd: {
|
|
84
|
+
includeKeys: CMCD_KEYS,
|
|
85
|
+
sessionId: this.sid,
|
|
86
|
+
contentId: this.cid,
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
});
|
|
62
91
|
break;
|
|
63
92
|
}
|
|
64
93
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
const options = this.core.activePlayback.options;
|
|
68
|
-
this.core.activePlayback.options = {
|
|
69
|
-
...options,
|
|
70
|
-
dash: {
|
|
71
|
-
...(options.dash ?? {}),
|
|
72
|
-
cmcd: {
|
|
73
|
-
enabled: true,
|
|
74
|
-
enabledKeys: CMCD_KEYS,
|
|
75
|
-
sid,
|
|
76
|
-
cid,
|
|
77
|
-
},
|
|
78
|
-
},
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
async updateHlsjsSettings() {
|
|
82
|
-
const { cid, sid } = await this.getIds();
|
|
83
|
-
const options = this.core.activePlayback.options;
|
|
84
|
-
this.core.activePlayback.options = {
|
|
85
|
-
...options,
|
|
94
|
+
updateHlsjsSettings(options, { cid, sid }) {
|
|
95
|
+
$.extend(true, options, {
|
|
86
96
|
playback: {
|
|
87
97
|
hlsjsConfig: {
|
|
88
|
-
...(options.playback?.hlsjsConfig ?? {}),
|
|
89
98
|
cmcd: {
|
|
90
99
|
includeKeys: CMCD_KEYS,
|
|
91
100
|
sessionId: sid,
|
|
@@ -93,22 +102,9 @@ export class CmcdConfig extends CorePlugin {
|
|
|
93
102
|
},
|
|
94
103
|
},
|
|
95
104
|
},
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
|
-
async ensureContentId() {
|
|
99
|
-
if (!this.cid) {
|
|
100
|
-
this.cid = await this.evalContentId();
|
|
101
|
-
}
|
|
102
|
-
return this.cid;
|
|
105
|
+
});
|
|
103
106
|
}
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
return generateContentId(this.core.activePlayback.options.src);
|
|
107
|
-
}
|
|
108
|
-
const contentId = this.core.activeContainer.options.cmcd.contentId;
|
|
109
|
-
if (typeof contentId === 'string') {
|
|
110
|
-
return contentId;
|
|
111
|
-
}
|
|
112
|
-
return Promise.resolve(contentId(this.core.activePlayback.options.src));
|
|
107
|
+
generateContentId() {
|
|
108
|
+
return new URL(this.core.options.source ?? this.core.options.sources[0].source).pathname.slice(0, 64);
|
|
113
109
|
}
|
|
114
110
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/plugins/cmcd-config/utils.ts"],"names":[],"mappings":"AAAA,wBAAgB,iBAAiB,IAAI,MAAM,CAE1C
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/plugins/cmcd-config/utils.ts"],"names":[],"mappings":"AAAA,wBAAgB,iBAAiB,IAAI,MAAM,CAE1C"}
|
|
@@ -1,12 +1,3 @@
|
|
|
1
1
|
export function generateSessionId() {
|
|
2
2
|
return window.crypto.randomUUID();
|
|
3
3
|
}
|
|
4
|
-
export function generateContentId(sourceUrl) {
|
|
5
|
-
return window.crypto.subtle.digest('SHA-1', new TextEncoder().encode(sourceUrl))
|
|
6
|
-
.then(buffer => {
|
|
7
|
-
const hex = Array.from(new Uint8Array(buffer))
|
|
8
|
-
.map(b => b.toString(16).padStart(2, '0'))
|
|
9
|
-
.join('');
|
|
10
|
-
return hex;
|
|
11
|
-
});
|
|
12
|
-
}
|
package/lib/testUtils.d.ts
CHANGED
package/lib/testUtils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"testUtils.d.ts","sourceRoot":"","sources":["../src/testUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAK,YAAY,EAAE,MAAM,cAAc,CAAA;AAC9C,OAAO,MAAM,MAAM,eAAe,CAAA;AAGlC,wBAAgB,cAAc,CAC5B,OAAO,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM,EACrC,SAAS,GAAE,GAAkC
|
|
1
|
+
{"version":3,"file":"testUtils.d.ts","sourceRoot":"","sources":["../src/testUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAK,YAAY,EAAE,MAAM,cAAc,CAAA;AAC9C,OAAO,MAAM,MAAM,eAAe,CAAA;AAGlC,wBAAgB,cAAc,CAC5B,OAAO,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM,EACrC,SAAS,GAAE,GAAkC;;;;;;;;;;;;;;;;;EAsB9C;AAED,wBAAgB,gBAAgB;;;EAK/B;AAED,wBAAgB,mBAAmB;;;;;;EAKlC;AAED,wBAAgB,kBAAkB,CAAC,IAAI,SAAS,EAAE,OAAO,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAoCtF;AAED,wBAAgB,mBAAmB,CACjC,OAAO,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM,EACrC,QAAQ,GAAE,GAAgD;;;;;;;;;;;;;;;;;;;;;;;;EA6B3D;AAED,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,GAAG,gBAiB/C;AAED,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,GAAG,OAe7C"}
|
package/lib/testUtils.js
CHANGED
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Core,
|
|
3
|
-
CorePlugin,
|
|
4
|
-
Events,
|
|
5
|
-
} from '@clappr/core'
|
|
1
|
+
import { $, Container, Core, CorePlugin, Events } from '@clappr/core'
|
|
6
2
|
|
|
7
|
-
import {
|
|
3
|
+
// import { trace } from '@gcorevideo/utils'
|
|
4
|
+
|
|
5
|
+
import { generateSessionId } from './utils'
|
|
6
|
+
import { CLAPPR_VERSION } from '../../build.js'
|
|
7
|
+
import { CoreOptions } from 'src/internal.types'
|
|
8
8
|
|
|
9
9
|
const CMCD_KEYS = [
|
|
10
10
|
'br',
|
|
@@ -36,12 +36,14 @@ export type CmcdConfigPluginSettings = {
|
|
|
36
36
|
*/
|
|
37
37
|
sessionId: string
|
|
38
38
|
/**
|
|
39
|
-
* Content ID,
|
|
40
|
-
* If ommitted,
|
|
39
|
+
* Content ID,
|
|
40
|
+
* If ommitted, the pathname part of the first source URL will be used
|
|
41
41
|
*/
|
|
42
|
-
contentId?: string
|
|
42
|
+
contentId?: string
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
+
// const T = 'plugins.cmcd'
|
|
46
|
+
|
|
45
47
|
/**
|
|
46
48
|
* A `PLUGIN` that configures CMCD for playback
|
|
47
49
|
* @beta
|
|
@@ -61,63 +63,73 @@ export class CmcdConfig extends CorePlugin {
|
|
|
61
63
|
return 'cmcd'
|
|
62
64
|
}
|
|
63
65
|
|
|
66
|
+
get version() {
|
|
67
|
+
return '0.1.0'
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
get supportedVersion() {
|
|
71
|
+
return CLAPPR_VERSION
|
|
72
|
+
}
|
|
73
|
+
|
|
64
74
|
constructor(core: Core) {
|
|
65
75
|
super(core)
|
|
66
76
|
this.sid = this.options.cmcd?.sessionId ?? generateSessionId()
|
|
77
|
+
this.cid = this.options.cmcd?.contentId ?? this.generateContentId()
|
|
67
78
|
}
|
|
68
79
|
|
|
69
80
|
/**
|
|
70
81
|
* @inheritdocs
|
|
71
82
|
*/
|
|
72
83
|
override bindEvents() {
|
|
73
|
-
this.listenTo(this.core, Events.
|
|
74
|
-
this.updateSettings(),
|
|
84
|
+
this.listenTo(this.core, Events.CORE_CONTAINERS_CREATED, () =>
|
|
85
|
+
this.updateSettings(this.core.containers[0]),
|
|
75
86
|
)
|
|
76
87
|
}
|
|
77
88
|
|
|
78
|
-
|
|
89
|
+
exportIds(): { sid: string; cid: string } {
|
|
79
90
|
return {
|
|
80
91
|
sid: this.sid,
|
|
81
|
-
cid:
|
|
92
|
+
cid: this.cid,
|
|
82
93
|
}
|
|
83
94
|
}
|
|
84
95
|
|
|
85
|
-
private updateSettings() {
|
|
86
|
-
switch (
|
|
96
|
+
private async updateSettings(container: Container) {
|
|
97
|
+
switch (container.playback.name) {
|
|
87
98
|
case 'dash':
|
|
88
|
-
|
|
99
|
+
$.extend(true, container.playback.options, {
|
|
100
|
+
dash: {
|
|
101
|
+
cmcd: {
|
|
102
|
+
enabled: true,
|
|
103
|
+
enabledKeys: CMCD_KEYS,
|
|
104
|
+
sid: this.sid,
|
|
105
|
+
cid: this.cid,
|
|
106
|
+
},
|
|
107
|
+
},
|
|
108
|
+
})
|
|
89
109
|
break
|
|
90
110
|
case 'hls':
|
|
91
|
-
|
|
111
|
+
$.extend(true, container.playback.options, {
|
|
112
|
+
playback: {
|
|
113
|
+
hlsjsConfig: {
|
|
114
|
+
cmcd: {
|
|
115
|
+
includeKeys: CMCD_KEYS,
|
|
116
|
+
sessionId: this.sid,
|
|
117
|
+
contentId: this.cid,
|
|
118
|
+
},
|
|
119
|
+
},
|
|
120
|
+
},
|
|
121
|
+
})
|
|
92
122
|
break
|
|
93
123
|
}
|
|
94
124
|
}
|
|
95
125
|
|
|
96
|
-
private
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
dash: {
|
|
102
|
-
...(options.dash ?? {}),
|
|
103
|
-
cmcd: {
|
|
104
|
-
enabled: true,
|
|
105
|
-
enabledKeys: CMCD_KEYS,
|
|
106
|
-
sid,
|
|
107
|
-
cid,
|
|
108
|
-
},
|
|
109
|
-
},
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
private async updateHlsjsSettings() {
|
|
114
|
-
const { cid, sid } = await this.getIds()
|
|
115
|
-
const options = this.core.activePlayback.options
|
|
116
|
-
this.core.activePlayback.options = {
|
|
117
|
-
...options,
|
|
126
|
+
private updateHlsjsSettings(
|
|
127
|
+
options: CoreOptions,
|
|
128
|
+
{ cid, sid }: { cid: string; sid: string },
|
|
129
|
+
) {
|
|
130
|
+
$.extend(true, options, {
|
|
118
131
|
playback: {
|
|
119
132
|
hlsjsConfig: {
|
|
120
|
-
...(options.playback?.hlsjsConfig ?? {}),
|
|
121
133
|
cmcd: {
|
|
122
134
|
includeKeys: CMCD_KEYS,
|
|
123
135
|
sessionId: sid,
|
|
@@ -125,24 +137,12 @@ export class CmcdConfig extends CorePlugin {
|
|
|
125
137
|
},
|
|
126
138
|
},
|
|
127
139
|
},
|
|
128
|
-
}
|
|
140
|
+
})
|
|
129
141
|
}
|
|
130
142
|
|
|
131
|
-
private
|
|
132
|
-
|
|
133
|
-
this.
|
|
134
|
-
|
|
135
|
-
return this.cid
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
private async evalContentId(): Promise<string> {
|
|
139
|
-
if (!this.core.activeContainer.options.cmcd?.contentId) {
|
|
140
|
-
return generateContentId(this.core.activePlayback.options.src)
|
|
141
|
-
}
|
|
142
|
-
const contentId = this.core.activeContainer.options.cmcd.contentId
|
|
143
|
-
if (typeof contentId === 'string') {
|
|
144
|
-
return contentId
|
|
145
|
-
}
|
|
146
|
-
return Promise.resolve(contentId(this.core.activePlayback.options.src))
|
|
143
|
+
private generateContentId() {
|
|
144
|
+
return new URL(
|
|
145
|
+
this.core.options.source ?? this.core.options.sources[0].source,
|
|
146
|
+
).pathname.slice(0, 64)
|
|
147
147
|
}
|
|
148
148
|
}
|
|
@@ -3,13 +3,9 @@ import { beforeEach, describe, expect, it, vi } from 'vitest'
|
|
|
3
3
|
import { CmcdConfig } from '../CmcdConfig'
|
|
4
4
|
import { createMockCore } from '../../../testUtils'
|
|
5
5
|
import { Events } from '@clappr/core'
|
|
6
|
-
import { generateContentId } from '../utils'
|
|
7
|
-
|
|
8
|
-
import { createHash } from 'node:crypto'
|
|
9
6
|
|
|
10
7
|
vi.mock('../utils', () => ({
|
|
11
8
|
generateSessionId: vi.fn().mockReturnValue('123'),
|
|
12
|
-
generateContentId: vi.fn().mockResolvedValue('deadbeef'),
|
|
13
9
|
}))
|
|
14
10
|
|
|
15
11
|
const CMCD_KEYS = [
|
|
@@ -38,69 +34,78 @@ describe('CmcdConfig', () => {
|
|
|
38
34
|
let plugin: CmcdConfig
|
|
39
35
|
describe('basically', () => {
|
|
40
36
|
beforeEach(() => {
|
|
41
|
-
core = createMockCore({
|
|
37
|
+
core = createMockCore({
|
|
38
|
+
sources: [
|
|
39
|
+
{
|
|
40
|
+
source: 'https://zulu.com/123.mpd',
|
|
41
|
+
mimeType: 'application/dash+xml',
|
|
42
|
+
},
|
|
43
|
+
],
|
|
44
|
+
})
|
|
42
45
|
})
|
|
43
|
-
describe('when
|
|
46
|
+
describe('when container is created', () => {
|
|
44
47
|
describe('dash.js', () => {
|
|
45
48
|
beforeEach(async () => {
|
|
46
|
-
core.
|
|
47
|
-
core.activeContainer.playback.options.src = 'https://123.mpd'
|
|
49
|
+
core.containers[0].playback.name = 'dash'
|
|
48
50
|
plugin = new CmcdConfig(core)
|
|
49
|
-
core.trigger(Events.
|
|
50
|
-
await new Promise(resolve => setTimeout(resolve, 0))
|
|
51
|
+
core.trigger(Events.CORE_CONTAINERS_CREATED)
|
|
52
|
+
await new Promise((resolve) => setTimeout(resolve, 0))
|
|
51
53
|
})
|
|
52
54
|
it('should update DASH.js CMCD settings', () => {
|
|
53
|
-
expect(core.
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
55
|
+
expect(core.containers[0].playback.options).toEqual(
|
|
56
|
+
expect.objectContaining({
|
|
57
|
+
dash: expect.objectContaining({
|
|
58
|
+
cmcd: expect.objectContaining({
|
|
59
|
+
enabled: true,
|
|
60
|
+
enabledKeys: CMCD_KEYS,
|
|
61
|
+
}),
|
|
62
|
+
}),
|
|
63
|
+
}),
|
|
64
|
+
)
|
|
61
65
|
})
|
|
62
66
|
it('should generate unique session ID', () => {
|
|
63
|
-
expect(core.
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
67
|
+
expect(core.containers[0].playback.options).toEqual(
|
|
68
|
+
expect.objectContaining({
|
|
69
|
+
dash: expect.objectContaining({
|
|
70
|
+
cmcd: expect.objectContaining({
|
|
71
|
+
sid: '123',
|
|
72
|
+
}),
|
|
73
|
+
}),
|
|
74
|
+
}),
|
|
75
|
+
)
|
|
70
76
|
})
|
|
71
77
|
it('should compute content ID from source URL', () => {
|
|
72
|
-
expect(
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
78
|
+
expect(core.containers[0].playback.options).toEqual(
|
|
79
|
+
expect.objectContaining({
|
|
80
|
+
dash: expect.objectContaining({
|
|
81
|
+
cmcd: expect.objectContaining({
|
|
82
|
+
cid: '/123.mpd',
|
|
83
|
+
}),
|
|
84
|
+
}),
|
|
85
|
+
}),
|
|
86
|
+
)
|
|
80
87
|
})
|
|
81
88
|
})
|
|
82
89
|
describe('hls.js', () => {
|
|
83
90
|
beforeEach(async () => {
|
|
84
|
-
core.
|
|
85
|
-
core.activeContainer.playback.options.src = 'https://123.m3u8'
|
|
91
|
+
core.containers[0].playback.name = 'hls'
|
|
86
92
|
plugin = new CmcdConfig(core)
|
|
87
|
-
|
|
88
|
-
core.trigger(Events.CORE_ACTIVE_CONTAINER_CHANGED)
|
|
89
|
-
await new Promise(resolve => setTimeout(resolve, 0))
|
|
93
|
+
core.trigger(Events.CORE_CONTAINERS_CREATED)
|
|
90
94
|
})
|
|
91
95
|
it('should update HLS.js CMCD settings', () => {
|
|
92
|
-
expect(core.
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
96
|
+
expect(core.containers[0].playback.options).toEqual(
|
|
97
|
+
expect.objectContaining({
|
|
98
|
+
playback: expect.objectContaining({
|
|
99
|
+
hlsjsConfig: expect.objectContaining({
|
|
100
|
+
cmcd: expect.objectContaining({
|
|
101
|
+
includeKeys: CMCD_KEYS,
|
|
102
|
+
contentId: '/123.mpd',
|
|
103
|
+
sessionId: '123',
|
|
104
|
+
}),
|
|
105
|
+
}),
|
|
106
|
+
}),
|
|
107
|
+
}),
|
|
108
|
+
)
|
|
104
109
|
})
|
|
105
110
|
})
|
|
106
111
|
})
|
|
@@ -109,54 +114,61 @@ describe('CmcdConfig', () => {
|
|
|
109
114
|
beforeEach(async () => {
|
|
110
115
|
core = createMockCore({
|
|
111
116
|
cmcd: {
|
|
112
|
-
contentId:
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
h.end()
|
|
122
|
-
}),
|
|
123
|
-
}
|
|
117
|
+
contentId:
|
|
118
|
+
'e287ea99b57c09b7a185aaaf36e075f2c0b346ce90aeced72976b1732678a8c6',
|
|
119
|
+
},
|
|
120
|
+
sources: [
|
|
121
|
+
{
|
|
122
|
+
source: 'https://zulu.com/123.mpd',
|
|
123
|
+
mimeType: 'application/dash+xml',
|
|
124
|
+
},
|
|
125
|
+
],
|
|
124
126
|
})
|
|
125
|
-
core.
|
|
126
|
-
core.
|
|
127
|
+
core.containers[0].playback.name = 'dash'
|
|
128
|
+
core.containers[0].playback.options.src = 'https://123.mpd'
|
|
127
129
|
plugin = new CmcdConfig(core)
|
|
128
|
-
core.trigger(Events.
|
|
129
|
-
await new Promise(resolve => setTimeout(resolve, 0))
|
|
130
|
+
core.trigger(Events.CORE_CONTAINERS_CREATED)
|
|
131
|
+
await new Promise((resolve) => setTimeout(resolve, 0))
|
|
130
132
|
})
|
|
131
133
|
it('should use custom content ID', () => {
|
|
132
|
-
expect(core.
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
134
|
+
expect(core.containers[0].playback.options).toEqual(
|
|
135
|
+
expect.objectContaining({
|
|
136
|
+
dash: expect.objectContaining({
|
|
137
|
+
cmcd: expect.objectContaining({
|
|
138
|
+
cid: 'e287ea99b57c09b7a185aaaf36e075f2c0b346ce90aeced72976b1732678a8c6',
|
|
139
|
+
}),
|
|
140
|
+
}),
|
|
141
|
+
}),
|
|
142
|
+
)
|
|
139
143
|
})
|
|
140
144
|
})
|
|
141
145
|
describe('custom session ID', () => {
|
|
142
146
|
beforeEach(async () => {
|
|
143
147
|
core = createMockCore({
|
|
144
148
|
cmcd: { sessionId: '456' },
|
|
149
|
+
sources: [
|
|
150
|
+
{
|
|
151
|
+
source: 'https://zulu.com/123.mpd',
|
|
152
|
+
mimeType: 'application/dash+xml',
|
|
153
|
+
},
|
|
154
|
+
],
|
|
145
155
|
})
|
|
146
|
-
core.
|
|
147
|
-
core.
|
|
156
|
+
core.containers[0].playback.name = 'dash'
|
|
157
|
+
core.containers[0].playback.options.src = 'https://123.mpd'
|
|
148
158
|
plugin = new CmcdConfig(core)
|
|
149
|
-
core.trigger(Events.
|
|
150
|
-
await new Promise(resolve => setTimeout(resolve, 0))
|
|
159
|
+
core.trigger(Events.CORE_CONTAINERS_CREATED)
|
|
160
|
+
await new Promise((resolve) => setTimeout(resolve, 0))
|
|
151
161
|
})
|
|
152
162
|
it('should use custom session ID', () => {
|
|
153
|
-
expect(core.
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
163
|
+
expect(core.containers[0].playback.options).toEqual(
|
|
164
|
+
expect.objectContaining({
|
|
165
|
+
dash: expect.objectContaining({
|
|
166
|
+
cmcd: expect.objectContaining({
|
|
167
|
+
sid: '456',
|
|
168
|
+
}),
|
|
169
|
+
}),
|
|
170
|
+
}),
|
|
171
|
+
)
|
|
160
172
|
})
|
|
161
173
|
})
|
|
162
174
|
})
|
|
@@ -1,13 +1,3 @@
|
|
|
1
1
|
export function generateSessionId(): string {
|
|
2
2
|
return window.crypto.randomUUID()
|
|
3
3
|
}
|
|
4
|
-
|
|
5
|
-
export function generateContentId(sourceUrl: string): Promise<string> {
|
|
6
|
-
return window.crypto.subtle.digest('SHA-1', new TextEncoder().encode(sourceUrl))
|
|
7
|
-
.then(buffer => {
|
|
8
|
-
const hex = Array.from(new Uint8Array(buffer))
|
|
9
|
-
.map(b => b.toString(16).padStart(2, '0'))
|
|
10
|
-
.join('')
|
|
11
|
-
return hex
|
|
12
|
-
})
|
|
13
|
-
}
|