Skip to content

Commit

Permalink
fix(srgssr-middleware): add missing return statement for DRM check
Browse files Browse the repository at this point in the history
A return statement was missing from the condition that checks if a list of
resources contains DRM. This oversight caused all resources without DRM
protection to end up with an empty `keySystems` object.

- add return statement to the DRM check condition
- fix the comparison function in the unit test and improve the resource list for
better clarity
  • Loading branch information
amtins committed Sep 10, 2024
1 parent 72417f4 commit dd7b2fd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
6 changes: 4 additions & 2 deletions src/middleware/srgssr.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,12 +212,14 @@ class SrgSsr {
* @returns {Array.<import('./typedef').MainResourceWithKeySystems>}
*/
static composeKeySystemsResources(resources = []) {
if (!Drm.hasDrm(resources)) resources;
if (!Drm.hasDrm(resources)) return resources;

return resources.map((resource) => ({
const resourcesWithKeySystems = resources.map((resource) => ({
...resource,
...Drm.buildKeySystems(resource.drmList),
}));

return resourcesWithKeySystems;
}

/**
Expand Down
11 changes: 6 additions & 5 deletions test/middleware/srgssr.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -405,16 +405,17 @@ describe('SrgSsr', () => {
it('should not add the keySystems property if no resource has DRM', () => {
const resources = [
{
streaming: 'DASH',
},
{
streaming: 'HLS',
src: 'https://fake-url.com/resource.m3u8',
type: 'application/x-mpegURL',
}, {
src: 'https://fake-url.com/resource.mpd',
type: 'application/dash+xml',
}
];
const resourcesNoKeySystems =
SrgSsr.composeKeySystemsResources(resources);

expect(resourcesNoKeySystems).toMatchObject(resources);
expect(resourcesNoKeySystems).toEqual(resources);
});

it('should add the keySystems property if at least one resource has DRM', () => {
Expand Down

0 comments on commit dd7b2fd

Please sign in to comment.