Skip to content

Commit

Permalink
Check for available representations in DVBFonts.js to avoid accessing… (
Browse files Browse the repository at this point in the history
#4366)

* Check for available representations in DVBFonts.js to avoid accessing the path attribute on a non-existing object

* Remove unnecessary semicolon
  • Loading branch information
dsilhavy committed Jan 23, 2024
1 parent 7453930 commit 28d540b
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions src/streaming/text/DVBFonts.js
Expand Up @@ -72,13 +72,15 @@ function DVBFonts(config) {
// If there is a baseurl in the manifest resolve against a representation inside the current adaptation set
if (baseURLController.resolve()) {
const reps = adapter.getVoRepresentations(track);
asBaseUrl = baseURLController.resolve(reps[0].path).url
if (reps && reps.length > 0) {
asBaseUrl = baseURLController.resolve(reps[0].path).url
}
}

const essentialTags = track.essentialPropertiesAsArray.filter(tag =>
const essentialTags = track.essentialPropertiesAsArray.filter(tag =>
(tag.schemeIdUri && tag.schemeIdUri === Constants.FONT_DOWNLOAD_DVB_SCHEME)
);
const supplementalTags = track.supplementalPropertiesAsArray.filter(tag =>
const supplementalTags = track.supplementalPropertiesAsArray.filter(tag =>
(tag.schemeIdUri && tag.schemeIdUri === Constants.FONT_DOWNLOAD_DVB_SCHEME)
);

Expand All @@ -103,16 +105,16 @@ function DVBFonts(config) {
status: FONT_DOWNLOAD_STATUS.UNLOADED,
fontFace: new FontFace(
attrs.dvbFontFamily,
`url(${resolvedUrl})`,
`url(${resolvedUrl})`,
{ display: 'swap' }
)
});
}
});
}

/**
* Clean up dvb font downloads
/**
* Clean up dvb font downloads
* @private
*/
function _cleanUpDvbCustomFonts() {
Expand All @@ -123,23 +125,23 @@ function DVBFonts(config) {
}

/**
* Check the attributes of a supplemental or essential property descriptor to establish if
* Check the attributes of a supplemental or essential property descriptor to establish if
* it has the mandatory values for a dvb font download
* @param {object} attrs - property descriptor attributes
* @returns {boolean} true if mandatory attributes present
* @private
*/
function _hasMandatoryDvbFontAttributes(attrs) {
return !!((attrs.value && attrs.value === '1') &&
(attrs.dvbUrl && attrs.dvbUrl.length > 0) &&
(attrs.dvbFontFamily && attrs.dvbFontFamily.length > 0) &&
(attrs.dvbMimeType && (attrs.dvbMimeType === Constants.OFF_MIMETYPE || attrs.dvbMimeType === Constants.WOFF_MIMETYPE)));
(attrs.dvbUrl && attrs.dvbUrl.length > 0) &&
(attrs.dvbFontFamily && attrs.dvbFontFamily.length > 0) &&
(attrs.dvbMimeType && (attrs.dvbMimeType === Constants.OFF_MIMETYPE || attrs.dvbMimeType === Constants.WOFF_MIMETYPE)));
}

/**
* Resolves a given font download URL.
* @param {string} fontUrl - URL as in the 'dvb:url' property
* @param {string} baseUrl - BaseURL for Adaptation Set
* @param {string} baseUrl - BaseURL for Adaptation Set
* @returns {string} resolved URL
* @private
*/
Expand All @@ -153,7 +155,7 @@ function DVBFonts(config) {
return urlUtils.resolve(fontUrl);
}
} else {
return fontUrl;
return fontUrl;
}
}

Expand All @@ -166,7 +168,7 @@ function DVBFonts(config) {
*/
function _updateFontStatus(index, newStatus) {
const font = dvbFontList[index];
dvbFontList[index] = {...font, status: newStatus};
dvbFontList[index] = { ...font, status: newStatus };
}

/**
Expand All @@ -179,7 +181,7 @@ function DVBFonts(config) {
for (let i = 0; i < tracks.length; i++) {
let track = tracks[i];
_addFontFromTrack(track, streamId);
};
}
}
}

Expand Down Expand Up @@ -222,7 +224,7 @@ function DVBFonts(config) {
* @returns {array} filtered DVBFontList
*/
function getFontsForTrackId(trackId) {
return dvbFontList.filter(font =>
return dvbFontList.filter(font =>
(font.trackId && font.trackId === trackId)
);
}
Expand Down

0 comments on commit 28d540b

Please sign in to comment.