Skip to content

Commit 35245c9

Browse files
committed
Handle Certurl like laurl; centralize certUrls normalization/deduplication
1 parent 03bbc02 commit 35245c9

File tree

2 files changed

+55
-35
lines changed

2 files changed

+55
-35
lines changed

src/streaming/MediaPlayer.js

Lines changed: 3 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2020,44 +2020,15 @@ function MediaPlayer() {
20202020
* @instance
20212021
*/
20222022
function setProtectionData(value) {
2023-
protectionData = value;
2024-
2023+
const sanitizedValue = CertUrlUtils.sanitizeProtectionDataCertUrls(value);
2024+
protectionData = sanitizedValue;
2025+
20252026
// Propagate changes in case StreamController is already created
20262027
if (streamController) {
20272028
streamController.setProtectionData(protectionData);
20282029
}
20292030
}
20302031

2031-
/**
2032-
* Adds one or multiple certificate URLs (Certurl) for a given key system. These URLs
2033-
* override (i.e. take priority over) manifest-provided Certurl entries when acquiring
2034-
* the server certificate. They are tried before manifest entries and in the provided order.
2035-
* Input may be a single string, an object {url, certType}, or an array of those.
2036-
* @param {string} keySystemString EME key system identifier e.g. 'com.widevine.alpha'
2037-
* @param {string|object|Array<string|object>} certUrls One or many certificate URL descriptors
2038-
* @example
2039-
* // Single URL
2040-
* player.addCertUrls('com.widevine.alpha', 'https://example.com/wv_cert');
2041-
* // Multiple with certType labels
2042-
* player.addCertUrls('com.widevine.alpha', [
2043-
* { url: 'https://example.com/wv_cert_primary', certType: 'primary' },
2044-
* { url: 'https://backup.example.com/wv_cert_backup', certType: 'backup' }
2045-
* ]);
2046-
*/
2047-
function addCertUrls(keySystemString, certUrls) {
2048-
if (!keySystemString || !certUrls) { return; }
2049-
const normalized = CertUrlUtils.normalizeCertUrls(certUrls);
2050-
if (!normalized.length) { return; }
2051-
// Ensure protectionData structure
2052-
protectionData = protectionData || {};
2053-
const existing = protectionData[keySystemString] || {};
2054-
const existingList = Array.isArray(existing.certUrls) ? existing.certUrls : [];
2055-
// Merge and dedupe via shared utility (existing first order preserved)
2056-
const merged = existingList.concat(normalized);
2057-
existing.certUrls = CertUrlUtils.dedupeCertUrls(merged);
2058-
protectionData[keySystemString] = existing;
2059-
setProtectionData(protectionData);
2060-
}
20612032

20622033
/*
20632034
---------------------------------------------------------------------------
@@ -2955,7 +2926,6 @@ function MediaPlayer() {
29552926
setMute,
29562927
setPlaybackRate,
29572928
setProtectionData,
2958-
addCertUrls,
29592929
setRepresentationForTypeById,
29602930
setRepresentationForTypeByIndex,
29612931
setTextTrack,

src/streaming/utils/CertUrlUtils.js

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,37 @@
1+
/**
2+
* The copyright in this software is being made available under the BSD License,
3+
* included below. This software may be subject to other third party and contributor
4+
* rights, including patent rights, and no such rights are granted under this license.
5+
*
6+
* Copyright (c) 2013, Dash Industry Forum.
7+
* All rights reserved.
8+
*
9+
* Redistribution and use in source and binary forms, with or without modification,
10+
* are permitted provided that the following conditions are met:
11+
* * Redistributions of source code must retain the above copyright notice, this
12+
* list of conditions and the following disclaimer.
13+
* * Redistributions in binary form must reproduce the above copyright notice,
14+
* this list of conditions and the following disclaimer in the documentation and/or
15+
* other materials provided with the distribution.
16+
* * Neither the name of Dash Industry Forum nor the names of its
17+
* contributors may be used to endorse or promote products derived from this software
18+
* without specific prior written permission.
19+
*
20+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
21+
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23+
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
24+
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25+
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
26+
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
27+
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29+
* POSSIBILITY OF SUCH DAMAGE.
30+
*/
31+
132
/**
233
* Utility functions for DASH Certurl normalization.
3-
* Shared by ContentProtection parsing and MediaPlayer.addCertUrls API.
34+
* Shared by ContentProtection parsing and protData handling.
435
*
536
* A Certurl entry may appear as:
637
* - String: 'https://example.com/cert'
@@ -59,7 +90,26 @@ function dedupeCertUrls(list) {
5990
return result;
6091
}
6192

93+
/**
94+
* Iterates over a ProtectionDataSet object and normalizes & deduplicates any certUrls arrays in-place.
95+
* Returns the same object reference for convenience.
96+
* @param {Object} protData - keySystem -> config object
97+
* @returns {Object} protData
98+
*/
99+
function sanitizeProtectionDataCertUrls(protData) {
100+
if (protData && typeof protData === 'object') {
101+
Object.keys(protData).forEach(keySystem => {
102+
const entry = protData[keySystem];
103+
if (entry && Array.isArray(entry.certUrls)) {
104+
entry.certUrls = dedupeCertUrls(normalizeCertUrls(entry.certUrls));
105+
}
106+
});
107+
}
108+
return protData;
109+
}
110+
62111
export default {
63112
normalizeCertUrls,
64-
dedupeCertUrls
113+
dedupeCertUrls,
114+
sanitizeProtectionDataCertUrls
65115
};

0 commit comments

Comments
 (0)