custom-media: import spec and fix a minor missed validation

This commit is contained in:
Calvin Montgomery 2017-08-08 20:46:10 -07:00
parent 04c9d48779
commit 92f0a956b9
3 changed files with 181 additions and 2 deletions

View file

@ -29,6 +29,10 @@ const SOURCE_CONTENT_TYPES = new Set([
'video/webm'
]);
const LIVE_ONLY_CONTENT_TYPES = new Set([
'application/x-mpegURL'
]);
export function lookup(url, opts) {
if (!opts) opts = {};
if (!opts.hasOwnProperty('timeout')) opts.timeout = 10000;
@ -158,11 +162,11 @@ export function validate(data) {
validateURL(data.thumbnail);
}
validateSources(data.sources);
validateSources(data.sources, data);
validateTextTracks(data.textTracks);
}
function validateSources(sources) {
function validateSources(sources, data) {
if (!Array.isArray(sources))
throw new ValidationError('sources must be a list');
if (sources.length === 0)
@ -178,6 +182,11 @@ function validateSources(sources) {
`unacceptable source contentType "${source.contentType}"`
);
if (LIVE_ONLY_CONTENT_TYPES.has(source.contentType) && !data.live)
throw new ValidationError(
`contentType "${source.contentType}" requires live: true`
);
if (!SOURCE_QUALITIES.has(source.quality))
throw new ValidationError(`unacceptable source quality "${source.quality}"`);