-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
PatchHelper.js
128 lines (117 loc) · 3.43 KB
/
PatchHelper.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
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
import DashConstants from '../../../src/dash/constants/DashConstants.js';
function staticSElements() {
return [[0, 10], [10, 5], [15, 10]].map(([t, d]) => {
return {
__children: [],
d: d,
t: t
};
});
}
function staticSegmentTimeline() {
let sElements = staticSElements();
return {
S: sElements,
__children: sElements.map((element) => {
return {
S: element
};
})
};
}
function staticSegmentTemplate() {
let timeline = staticSegmentTimeline();
return {
SegmentTimeline: timeline,
__children: [{
SegmentTimeline: timeline
}]
};
}
function staticAdaptationSet(id) {
let template = staticSegmentTemplate();
return {
SegmentTemplate: template,
__children: [{
SegmentTemplate: template
}],
id: id
};
}
function staticBaseUrl(url, serviceLocation) {
if (!serviceLocation) {
return url;
}
return {
__children: [
{
'#text': url
}
],
serviceLocation: serviceLocation,
__text: url
}
}
function staticPeriod(id) {
let baseUrl = staticBaseUrl(`period-${id}/`);
let adaptationSets = [staticAdaptationSet(10), staticAdaptationSet(20)];
return {
BaseURL: [baseUrl],
AdaptationSet: adaptationSets,
__children: [
{ BaseURL: baseUrl },
{ AdaptationSet: adaptationSets[0] },
{ AdaptationSet: adaptationSets[1] }
],
id: id
}
}
class PatchHelper {
generatePatch(mpdId, operations = []) {
return {
[DashConstants.ORIGINAL_MPD_ID]: mpdId,
[DashConstants.PUBLISH_TIME]: new Date().toISOString(),
[DashConstants.ORIGINAL_PUBLISH_TIME]: new Date().toISOString(),
// only the ordered child array is simulated
__children: operations.map((operation) => {
if (operation.action === 'add') {
// add is special because it has extra possible attributes
return {
tagName: operation.action,
sel: operation.selector,
__children: operation.children,
__text: operation.text,
pos: operation.position,
type: operation.type
}
} else {
return {
tagName: operation.action,
sel: operation.selector,
__children: operation.children,
__text: operation.text
};
}
})
};
}
getStaticBaseMPD() {
// we will generate a simple base manifest example, it will not be a fully valid manifest
// but it will match the object structure of X2JS
let baseUrl = staticBaseUrl('http://example.com/base', 'a');
let utcTiming = 'timetime';
let period = staticPeriod('foo');
return {
UTCTiming: [utcTiming],
BaseURL: [baseUrl],
Period: [period],
__children: [
{ UTCTiming: utcTiming },
{ BaseURL: baseUrl },
{ Period: period }
],
id: 'foobar'
}
}
}
export default PatchHelper;