Skip to content

Commit

Permalink
feat(srgssr-middleware): filter incompatible resources
Browse files Browse the repository at this point in the history
Removes incompatible resources such as `HDS` and `RTMP`. This functionality
to remove incompatible resources was not originally intended. However,
some BUs, such as RTS and RSI, continue to return these resources.

When the backends of the various BUs stop providing this type of resource, it
will be possible to remove this function.

- add a function to filter `HDS` and `RTMP` resources
- call to resource filtering in `composeMainResources`
- test cases added
- indentation modified by side effect
  • Loading branch information
amtins committed Feb 2, 2024
1 parent a540671 commit c11d0a0
Show file tree
Hide file tree
Showing 3 changed files with 258 additions and 16 deletions.
17 changes: 16 additions & 1 deletion src/middleware/srgssr.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ class SrgSsr {
*/
static composeMainResources(mediaComposition) {
return SrgSsr.composeAkamaiResources(
SrgSsr.composeKeySystemsResources(mediaComposition.getMainResources())
SrgSsr.composeKeySystemsResources(
SrgSsr.filterIncompatibleResources(mediaComposition.getMainResources())
)
);
}

Expand Down Expand Up @@ -173,6 +175,19 @@ class SrgSsr {
});
}

/**
* Filter out incompatible resources such as `RTMP` and `HDS`.
*
* @param {Array.<Object>} resources Resources to filter
*
* @returns {Array.<Object>} The filtered resources
*/
static filterIncompatibleResources(resources = []) {
return resources.filter(
(resource) => !['RTMP', 'HDS'].includes(resource.streaming)
);
}

/**
* Get mediaComposition from an URN.
*
Expand Down
202 changes: 202 additions & 0 deletions test/__mocks__/urn:rts:audio:3262320.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
{
"chapterUrn": "urn:rts:audio:3262320",
"episode": {
"id": "3262332",
"title": "La 1ère en direct",
"publishedDate": "2011-07-11T14:18:47+02:00",
"imageUrl": "https://www.rts.ch/2017/04/11/16/17/7069749.image/16x9"
},
"show": {
"id": "3262333",
"vendor": "RTS",
"transmission": "RADIO",
"urn": "urn:rts:show:radio:3262333",
"title": "La 1ère en direct",
"imageUrl": "https://www.rts.ch/2017/04/11/16/17/7069749.image/16x9",
"imageTitle": "srg_responsive-la1ere [RTS]",
"bannerImageUrl": "https://www.rts.ch/2017/04/11/16/17/7069749.image/3x1",
"primaryChannelId": "a9e7621504c6959e35c3ecbe7f6bed0446cdf8da",
"primaryChannelUrn": "urn:rts:channel:radio:a9e7621504c6959e35c3ecbe7f6bed0446cdf8da",
"allowIndexing": true
},
"channel": {
"id": "a9e7621504c6959e35c3ecbe7f6bed0446cdf8da",
"vendor": "RTS",
"urn": "urn:rts:channel:radio:a9e7621504c6959e35c3ecbe7f6bed0446cdf8da",
"title": "La 1ere",
"imageUrl": "https://www.rts.ch/2017/04/11/16/17/7069749.image/3x1",
"imageTitle": "srg_responsive-la1ere [RTS]",
"transmission": "RADIO"
},
"chapterList": [
{
"id": "3262320",
"mediaType": "AUDIO",
"vendor": "RTS",
"urn": "urn:rts:audio:3262320",
"title": "La 1ère en direct",
"imageUrl": "https://www.rts.ch/2017/04/11/16/17/7069749.image/16x9",
"imageTitle": "srg_responsive-la1ere [RTS]",
"imageCopyright": "RTS",
"type": "LIVESTREAM",
"date": "2011-07-11T14:18:47+02:00",
"duration": 0,
"playableAbroad": true,
"displayable": true,
"position": 0,
"noEmbed": false,
"analyticsMetadata": {
"media_segment": "Livestream",
"media_type": "Audio",
"media_segment_id": "3262320",
"media_episode_length": "0",
"media_segment_length": "0",
"media_number_of_segment_selected": "1",
"media_number_of_segments_total": "1",
"media_duration_category": "infinit.livestream",
"media_is_geoblocked": "false",
"media_is_web_only": "false",
"media_production_source": "produced.for.broadcasting",
"media_urn": "urn:rts:audio:3262320"
},
"eventData": "$b82c2b84ab0634d0$2d244397099a643e0279225ec27ff2f9f28639925a1b65df099a935c3377dc7a6414bfc8f3d3eb9463413ae9106c031987393aa9c60f931673e8a807a36d36668300b91bbd17dd2d22e3b5eb012c0eecb20f0f4aee692259e841b67d1e5b7af9dfeb3efce9f6e8b57b893b3cd9a67dd996a6c91aa2effa08a401dc12a1c7f0daafa2d1afc824728ab8954a09d47fedf9fa9494ce130d65c73234ed0152d12f6a5121fcbb3ab1b3e356bf2caabaa2d510c3a407ad22ce27338e18a2a27ca1396c1e47e1e5c19819d13f79df31aaec1b6b0156ba3bfa86995ea8e64215dd7d1a503cfa2c9a4b8d40bd3892fd67cc9642ea0746cc5b68f3d8bf0ea8be9e69efa50e14cfc891d058f0faf6b152ab787dcc059b8a36515e39e17914f0ce343bf2d7f8a63e24ceebffeae23a83abf8de72220df9d4a58dd8138447962159ddf822c45585c62216f732a6303cea1c0c7ee6f805",
"fullLengthMarkIn": 0,
"fullLengthMarkOut": 0,
"resourceList": [
{
"url": "rtmp://rtmp.streaming.swisstxt.ch/live/la-1ere.96.stream",
"quality": "HQ",
"protocol": "RTMP",
"encoding": "AAC",
"mimeType": "audio/mp4; codecs=\"mp4a.40.2\"",
"presentation": "DEFAULT",
"streaming": "RTMP",
"dvr": false,
"live": true,
"mediaContainer": "NONE",
"audioCodec": "AAC",
"videoCodec": "NONE",
"tokenType": "NONE",
"analyticsMetadata": {
"media_streaming_quality": "HQ",
"media_special_format": "DEFAULT",
"media_url": "rtmp://rtmp.streaming.swisstxt.ch/live/la-1ere.96.stream"
}
},
{
"url": "http://stream.srg-ssr.ch/m/la-1ere/mp3_128",
"quality": "HQ",
"protocol": "HTTP-MP3-STREAM",
"encoding": "MP3",
"mimeType": "audio/mpeg",
"presentation": "DEFAULT",
"streaming": "PROGRESSIVE",
"dvr": false,
"live": true,
"mediaContainer": "NONE",
"audioCodec": "MP3",
"videoCodec": "NONE",
"tokenType": "NONE",
"analyticsMetadata": {
"media_streaming_quality": "HQ",
"media_special_format": "DEFAULT",
"media_url": "http://stream.srg-ssr.ch/m/la-1ere/mp3_128"
}
},
{
"url": "https://lsaplus.swisstxt.ch/audio/la-1ere_96.stream/manifest.f4m",
"quality": "HD",
"protocol": "HDS-DVR",
"encoding": "H264",
"mimeType": "application/adobe-f4m",
"presentation": "DEFAULT",
"streaming": "HDS",
"dvr": true,
"live": true,
"mediaContainer": "NONE",
"audioCodec": "UNKNOWN",
"videoCodec": "NONE",
"tokenType": "NONE",
"analyticsMetadata": {
"media_streaming_quality": "HD",
"media_special_format": "DEFAULT",
"media_url": "https://lsaplus.swisstxt.ch/audio/la-1ere_96.stream/manifest.f4m"
}
},
{
"url": "https://lsaplus.swisstxt.ch/audio/la-1ere_96.stream/playlist.m3u8",
"quality": "HD",
"protocol": "HLS-DVR",
"encoding": "H264",
"mimeType": "application/x-mpegURL",
"presentation": "DEFAULT",
"streaming": "HLS",
"dvr": true,
"live": true,
"mediaContainer": "NONE",
"audioCodec": "UNKNOWN",
"videoCodec": "NONE",
"tokenType": "NONE",
"analyticsMetadata": {
"media_streaming_quality": "HD",
"media_special_format": "DEFAULT",
"media_url": "https://lsaplus.swisstxt.ch/audio/la-1ere_96.stream/playlist.m3u8"
}
}
]
}
],
"analyticsData": {
"srg_pr_id": "3262332",
"srg_plid": "3262333",
"ns_st_pl": "Livestream",
"ns_st_pr": "La 1ère en direct",
"ns_st_dt": "2011-07-11",
"ns_st_ddt": "2011-07-11",
"ns_st_tdt": "2011-07-11",
"ns_st_tm": "14:18:47",
"ns_st_tep": "*null",
"ns_st_li": "1",
"ns_st_stc": "0867",
"ns_st_st": "La 1ere",
"ns_st_tpr": "8272976",
"ns_st_en": "*null",
"ns_st_ge": "*null",
"ns_st_ia": "*null",
"ns_st_ce": "1",
"ns_st_cdm": "to",
"ns_st_cmt": "fc",
"srg_unit": "RTS",
"srg_c1": "live",
"srg_c2": "rts.ch_audio_la-1ere",
"srg_c3": "LA 1ÈRE",
"srg_aod_prid": "3262332"
},
"analyticsMetadata": {
"media_episode_id": "3262332",
"media_show_id": "8272976",
"media_show": "A l'abordage",
"media_episode": "La 1ère en direct",
"media_is_livestream": "true",
"media_full_length": "full",
"media_enterprise_units": "RTS",
"media_joker1": "live",
"media_joker2": "rts.ch_audio_la-1ere",
"media_joker3": "LA 1ÈRE",
"media_is_web_only": "false",
"media_production_source": "produced.for.broadcasting",
"media_thumbnail": "https://www.rts.ch/2017/04/11/16/17/7069749.image/16x9/scale/width/344",
"media_publication_date": "2011-07-11",
"media_publication_time": "14:18:47",
"media_publication_datetime": "2011-07-11T14:18:47+02:00",
"media_tv_date": "2011-07-11",
"media_tv_time": "14:18:47",
"media_tv_datetime": "2011-07-11T14:18:47+02:00",
"media_content_group": "La 1ère,rts.ch",
"media_channel_id": "a9e7621504c6959e35c3ecbe7f6bed0446cdf8da",
"media_channel_cs": "0867",
"media_channel_name": "La 1ere",
"media_since_publication_d": "3161",
"media_since_publication_h": "75866"
}
}
55 changes: 40 additions & 15 deletions test/middleware/srgssr.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import DataProvider from '../../src/dataProvider/services/DataProvider.js';
import Image from '../../src/utils/Image.js';
import MediaComposition from '../../src/dataProvider/model/MediaComposition.js';
import urnCredits from '../__mocks__/urn:rts:video:10313496-credits.json';
import urnRtsAudio from '../__mocks__/urn:rts:audio:3262320.json';
import Pillarbox from '../../src/pillarbox.js';
import AkamaiTokenService from '../../src/utils/AkamaiTokenService.js';

Expand Down Expand Up @@ -66,10 +67,7 @@ describe('SrgSsr', () => {

expect(SrgSsr.blockingReason(player, 'STARTDATE', {})).toBe(true);
expect(spyOnLocalize).toHaveBeenCalled();
expect(spyOnError).toHaveBeenCalledWith(
player,
expect.any(Object)
);
expect(spyOnError).toHaveBeenCalledWith(player, expect.any(Object));
expect(spyOnPlayerError.mock.calls[1]).toEqual(
expect.arrayContaining([
expect.objectContaining({ cause: { type: 'STARTDATE', src: {}}})
Expand Down Expand Up @@ -238,10 +236,7 @@ describe('SrgSsr', () => {
statusText: 'Not Found',
})
).toBe(true);
expect(spyOnError).toHaveBeenCalledWith(
player,
expect.any(Object)
);
expect(spyOnError).toHaveBeenCalledWith(player, expect.any(Object));
});
});

Expand Down Expand Up @@ -350,6 +345,37 @@ describe('SrgSsr', () => {
});
});

/**
*****************************************************************************
* filterIncompatibleResources ***********************************************
*****************************************************************************
*/

describe('filterIncompatibleResources', () => {
it('should filter incompatible resources', async () => {
const resources = urnRtsAudio.chapterList[0].resourceList;
const filteredResources = SrgSsr.filterIncompatibleResources(resources);

expect(filteredResources).toHaveLength(2);
});

it('should return an empty array if no source is compatible', async () => {
const incompatibleResources = [
{ streaming: 'HDS' },
{ streaming: 'RTMP' }
];
const filteredResources = SrgSsr.filterIncompatibleResources(
incompatibleResources
);

expect(filteredResources).toHaveLength(0);
});

it('should return an empty array the resource is undefined', async () => {
expect(SrgSsr.filterIncompatibleResources()).toHaveLength(0);
});
});

/**
*****************************************************************************
* updatePoster **************************************************************
Expand Down Expand Up @@ -584,9 +610,11 @@ describe('SrgSsr', () => {
});

it('Should return undefined and generate an error the URN doest not exist', async () => {
const spyOnDataProvider = jest.spyOn(SrgSsr, 'dataProvider').mockReturnValue({
baseUrl: 'http://mock.url.ch',
});
const spyOnDataProvider = jest
.spyOn(SrgSsr, 'dataProvider')
.mockReturnValue({
baseUrl: 'http://mock.url.ch',
});
const spyOnError = jest.spyOn(SrgSsr, 'error');
const spyOnDataProviderError = jest.spyOn(SrgSsr, 'dataProviderError');

Expand All @@ -603,10 +631,7 @@ describe('SrgSsr', () => {

expect(result).toBeUndefined();
expect(spyOnDataProviderError.mock.results[0].value).toBe(true);
expect(spyOnError).toHaveBeenCalledWith(
player,
expect.any(Object)
);
expect(spyOnError).toHaveBeenCalledWith(player, expect.any(Object));

spyOnDataProvider.mockReset();
});
Expand Down

0 comments on commit c11d0a0

Please sign in to comment.