Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions src/playlist-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -1317,17 +1317,21 @@ export default class PlaylistLoader extends EventTarget {
* @return a Set of 32 digit hex strings that represent the unique keyIds for that playlist.
*/
getKeyIdSet(playlist) {
if (playlist.contentProtection) {
const keyIds = new Set();
const keyIds = new Set();

for (const keysystem in playlist.contentProtection) {
if (!playlist || !playlist.contentProtection) {
return keyIds;
}

for (const keysystem in playlist.contentProtection) {
if (playlist.contentProtection[keysystem] &&
playlist.contentProtection[keysystem].attributes &&
playlist.contentProtection[keysystem].attributes.keyId) {
const keyId = playlist.contentProtection[keysystem].attributes.keyId;

if (keyId) {
keyIds.add(keyId.toLowerCase());
}
keyIds.add(keyId.toLowerCase());
}
return keyIds;
}
return keyIds;
}
}
33 changes: 33 additions & 0 deletions test/playlist-loader.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,39 @@ QUnit.module('Playlist Loader', function(hooks) {
assert.ok(keyIdSet.has(keyId.toLowerCase()), 'keyId is expected hex string');
});

QUnit.test('does not error if keyId or keysystem.attributes is missing', function(assert) {
assert.expect(6);
const loader = new PlaylistLoader('variant.m3u8', this.fakeVhs);
const playlists = [
{
contentProtection: {
'fake.keysystem': {}
}
},
{
contentProtection: {
'fake.keysystem': {
attributes: {}
}
}
}
];

let errorHappened = false;

for (const playlist of playlists) {
let keyIdSet;

try {
keyIdSet = loader.getKeyIdSet(playlist);
} catch (e) {
errorHappened = true;
}
assert.notOk(errorHappened, 'no error was thrown');
assert.notOk(keyIdSet.size, 'keyIdSet is empty');
}
});

QUnit.test('updateSegments copies over properties', function(assert) {
assert.deepEqual(
[
Expand Down
Loading