Skip to content

Commit

Permalink
feat: add support for #EXT-X-SERVER-CONTROL (#121)
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonocasey authored Jan 20, 2021
1 parent 4fd693a commit 7f82f53
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/parse-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,28 @@ export default class ParseStream extends Stream {
this.trigger('data', event);
return;
}
match = (/^#EXT-X-SERVER-CONTROL:(.*)$/).exec(newLine);
if (match && match[1]) {
event = {
type: 'tag',
tagType: 'server-control'
};
event.attributes = parseAttributes(match[1]);
['CAN-SKIP-UNTIL', 'PART-HOLD-BACK', 'HOLD-BACK'].forEach(function(key) {
if (event.attributes.hasOwnProperty(key)) {
event.attributes[key] = parseFloat(event.attributes[key]);
}
});

['CAN-SKIP-DATERANGES', 'CAN-BLOCK-RELOAD'].forEach(function(key) {
if (event.attributes.hasOwnProperty(key)) {
event.attributes[key] = (/YES/).test(event.attributes[key]);
}
});

this.trigger('data', event);
return;
}

match = (/^#EXT-X-PRELOAD-HINT:(.*)$/).exec(newLine);
if (match && match[1]) {
Expand Down
3 changes: 3 additions & 0 deletions src/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,9 @@ export default class Parser extends Stream {
this.manifest.parts = this.manifest.parts || [];
this.manifest.parts.push(entry.attributes);
},
'server-control'() {
this.manifest.serverControl = entry.attributes;
},
'preload-hint'() {
this.manifest.preloadHints = this.manifest.preloadHints || [];
this.manifest.preloadHints.push(entry.attributes);
Expand Down
7 changes: 7 additions & 0 deletions test/fixtures/m3u8/llhls.json
Original file line number Diff line number Diff line change
Expand Up @@ -187,5 +187,12 @@
"uri": "fileSequence272.mp4"
}
],
"serverControl": {
"CAN-SKIP-DATERANGES": true,
"CAN-BLOCK-RELOAD": true,
"CAN-SKIP-UNTIL": 12,
"PART-HOLD-BACK": 1,
"HOLD-BACK": 2
},
"targetDuration": 4
}
7 changes: 7 additions & 0 deletions test/fixtures/m3u8/llhlsDelta.json
Original file line number Diff line number Diff line change
Expand Up @@ -160,5 +160,12 @@
"bar"
]
},
"serverControl": {
"CAN-SKIP-DATERANGES": true,
"CAN-BLOCK-RELOAD": true,
"CAN-SKIP-UNTIL": 12,
"PART-HOLD-BACK": 1,
"HOLD-BACK": 2
},
"targetDuration": 4
}

0 comments on commit 7f82f53

Please sign in to comment.