From 8cc333458e75ed58d7599b009120ef6f6c5bc25c Mon Sep 17 00:00:00 2001 From: Constanza Dibueno Date: Tue, 21 Oct 2025 15:11:02 -0300 Subject: [PATCH 01/16] remove response mode WIP --- src/streaming/constants/Constants.js | 8 ++ src/streaming/controllers/CmcdController.js | 133 ++++++++---------- .../streaming.controllers.CmcdController.js | 25 ++-- 3 files changed, 80 insertions(+), 86 deletions(-) diff --git a/src/streaming/constants/Constants.js b/src/streaming/constants/Constants.js index 935269530c..ac7a5cf1ec 100644 --- a/src/streaming/constants/Constants.js +++ b/src/streaming/constants/Constants.js @@ -34,6 +34,7 @@ import { CmcdEventType } from '@svta/common-media-library/cmcd/CmcdEventType'; import { CMCD_DEFAULT_TIME_INTERVAL } from '@svta/common-media-library/cmcd/CMCD_DEFAULT_TIME_INTERVAL'; import { CMCD_PARAM } from '@svta/common-media-library/cmcd/CMCD_PARAM'; import { CMCD_QUERY } from '@svta/common-media-library/cmcd/CMCD_QUERY'; +import { CMCD_KEYS } from '@svta/common-media-library/cmcd/CMCD_KEYS'; /** * Constants declaration @@ -247,6 +248,13 @@ export default { */ CMCD_REPORTING_MODE: CmcdReportingMode, + /** + * @constant {string} CMCD_KEYS specifies all the available keys for CMCD. + * @memberof Constants# + * @static + */ + CMCD_KEYS: CMCD_KEYS, + /** * @constant {string} CMCD_REPORTING_EVENTS specifies all the available events for CMCD event mode. * @memberof Constants# diff --git a/src/streaming/controllers/CmcdController.js b/src/streaming/controllers/CmcdController.js index 29af4495ce..5ecafa9b9b 100644 --- a/src/streaming/controllers/CmcdController.js +++ b/src/streaming/controllers/CmcdController.js @@ -152,8 +152,7 @@ function CmcdController() { function _initializeEventModeTimeInterval() { const targets = settings.get().streaming.cmcd.targets; - const eventModeTargets = targets.filter((target) => target.cmcdMode === Constants.CMCD_REPORTING_MODE.EVENT); - eventModeTargets.forEach(({ timeInterval, events }) => { + targets.forEach(({ timeInterval, events }) => { if (!events || !events.includes(Constants.CMCD_REPORTING_EVENTS.TIME_INTERVAL)) { return; } @@ -176,9 +175,9 @@ function CmcdController() { _onEventChange(Constants.CMCD_REPORTING_EVENTS.PLAY_STATE); } - function _onEventChange(state){ + function _onEventChange(state, response){ cmcdModel.onEventChange(state); - triggerCmcdEventMode(state); + triggerCmcdEventMode(state, response); } function _onPeriodSwitchComplete() { @@ -228,47 +227,50 @@ function CmcdController() { } } - function triggerCmcdEventMode(event){ + function triggerCmcdEventMode(event, response){ const targets = settings.get().streaming.cmcd.targets; - const eventModeTargets = targets.filter((target) => target.cmcdMode === Constants.CMCD_REPORTING_MODE.EVENT); - if (eventModeTargets.length === 0) { + if (targets.length === 0) { return; } - const cmcdData = cmcdModel.triggerCmcdEventMode(event); + let cmcdData = cmcdModel.triggerCmcdEventMode(event); + + if (event == 'rr') { + cmcdData = {...cmcdData, ...response.request.cmcd} + cmcdData = _addCmcdResponseReceivedData(response, cmcdData); + } - eventModeTargets.forEach(targetSettings => { - if (targetSettings.enabled) { + targets.forEach(targetSettings => { + if (!isCmcdEnabled(targetSettings)){ + return; + } - if (targetSettings.events?.length === 0) { - logger.warn('CMCD Event Mode is enabled, but the "events" setting is empty. No event-specific CMCD data will be sent.'); - } + if (targetSettings.events?.length === 0) { + logger.warn('CMCD Event Mode is enabled, but the "events" setting is empty. No event-specific CMCD data will be sent.'); + } - let events = targetSettings.events ? targetSettings.events : Object.values(Constants.CMCD_REPORTING_EVENTS); + let events = targetSettings.events ? targetSettings.events : Object.values(Constants.CMCD_REPORTING_EVENTS); - if (!events.includes(event)) { - return; - } + if (!events.includes(event)) { + return; + } - let httpRequest = new CmcdReportRequest(); + let httpRequest = new CmcdReportRequest(); - httpRequest.url = targetSettings.url; - httpRequest.type = HTTPRequest.CMCD_EVENT; - httpRequest.method = HTTPRequest.GET; + httpRequest.url = targetSettings.url; + httpRequest.type = HTTPRequest.CMCD_EVENT; + httpRequest.method = HTTPRequest.GET; - const sequenceNumber = _getNextSequenceNumber(targetSettings); - let cmcd = {...cmcdData, sn: sequenceNumber} - httpRequest.cmcd = cmcd; + const sequenceNumber = _getNextSequenceNumber(targetSettings); + let cmcd = {...cmcdData, sn: sequenceNumber} + httpRequest.cmcd = cmcd; - if (isCmcdEnabled(targetSettings)) { - _updateRequestWithCmcd(httpRequest, cmcd, targetSettings) - if ((targetSettings.batchSize || targetSettings.batchTimer) && httpRequest.body){ - cmcdBatchController.addReport(targetSettings, httpRequest.body) - } else { - _sendCmcdDataReport(httpRequest); - } - } + _updateRequestWithCmcd(httpRequest, cmcd, targetSettings) + if ((targetSettings.batchSize || targetSettings.batchTimer) && httpRequest.body){ + cmcdBatchController.addReport(targetSettings, httpRequest.body) + } else { + _sendCmcdDataReport(httpRequest); } }); } @@ -299,8 +301,8 @@ function CmcdController() { if (isIncludedFilters) { const cmcdParameters = cmcdModel.getCmcdParametersFromManifest(); const cmcdModeSetting = targetSettings ? targetSettings.mode : settings.get().streaming.cmcd.mode; - const cmcdMode = cmcdParameters.mode ? cmcdParameters.mode : cmcdModeSetting; - switch (cmcdMode) { + const mode = cmcdParameters.mode ? cmcdParameters.mode : cmcdModeSetting; + switch (mode) { case Constants.CMCD_MODE_QUERY: request.url = Utils.removeQueryParameterFromUrl(request.url, Constants.CMCD_QUERY_KEY); const additionalQueryParameter = _getAdditionalQueryParameter(request, cmcdData, targetSettings); @@ -475,11 +477,16 @@ function CmcdController() { function _createCmcdEncodeOptions(targetSettings) { const cmcdParametersFromManifest = cmcdModel.getCmcdParametersFromManifest(); - const enabledKeys = targetSettings ? + let enabledKeys = targetSettings ? targetSettings.enabledKeys : (cmcdParametersFromManifest.version ? cmcdParametersFromManifest.keys : settings.get().streaming.cmcd.enabledKeys); + // if (enabledKeys?.length === 0){ + // enabledKeys = Constants.CMCD_KEYS + // } + return { + // reportingMode: targetSettings ? Constants.CMCD_REPORTING_MODE.EVENT : Constants.CMCD_REPORTING_MODE.REQUEST, reportingMode: targetSettings?.cmcdMode, version: settings.get().streaming.cmcd.version ?? Constants.CMCD_DEFAULT_VERSION, filter: enabledKeys ? (key) => enabledKeys.includes(key) : undefined, @@ -558,86 +565,56 @@ function CmcdController() { } function getCmcdResponseInterceptors(){ - return [_cmcdResponseModeInterceptor]; + return [_cmcdResponseReceivedInterceptor]; } - function _cmcdResponseModeInterceptor(response){ - const requestType = response.request.customData.request.type; - - let cmcdData = { - ...response.request.cmcd, - }; - - cmcdData = _addCmcdResponseModeData(response, cmcdData); - const targets = settings.get().streaming.cmcd.targets; - const responseModeTargets = targets.filter((target) => target.cmcdMode === Constants.CMCD_REPORTING_MODE.RESPONSE); - responseModeTargets.forEach(targetSettings => { - if (targetSettings.enabled && cmcdModel.isIncludedInRequestFilter(requestType, targetSettings.includeOnRequests)){ - let httpRequest = new CmcdReportRequest(); - httpRequest.url = targetSettings.url; - httpRequest.type = HTTPRequest.CMCD_RESPONSE; - httpRequest.method = HTTPRequest.GET; - - const sequenceNumber = _getNextSequenceNumber(targetSettings); - let cmcd = {...cmcdData, sn: sequenceNumber} - httpRequest.cmcd = cmcd; - - if (isCmcdEnabled(targetSettings)) { - _updateRequestWithCmcd(httpRequest, cmcd, targetSettings) - if ((targetSettings.batchSize || targetSettings.batchTimer) && httpRequest.body){ - cmcdBatchController.addReport(targetSettings, httpRequest.body) - } else { - _sendCmcdDataReport(httpRequest); - } - } - } - }); - + function _cmcdResponseReceivedInterceptor(response){ + _onEventChange('rr', response) return response; } - function _addCmcdResponseModeData(response, cmcdData){ - const responseModeData = {}; + function _addCmcdResponseReceivedData(response, cmcdData){ + const responseData = {}; const request = response.request.customData.request; const requestType = request.type; if (requestType === HTTPRequest.MEDIA_SEGMENT_TYPE){ - responseModeData.rc = response.status; + responseData.rc = response.status; } if (request.startDate && request.firstByteDate){ - responseModeData.ttfb = request.firstByteDate - request.startDate; + responseData.ttfb = request.firstByteDate - request.startDate; } if (request.endDate && request.startDate){ - responseModeData.ttlb = request.endDate - request.startDate + responseData.ttlb = request.endDate - request.startDate } if (request.url) { - responseModeData.url = request.url.split('?')[0] + responseData.url = request.url.split('?')[0] } if (response.headers){ try { const cmsdStaticHeader = response.headers['cmsd-static']; if (cmsdStaticHeader) { - responseModeData.cmsds = btoa(cmsdStaticHeader); + responseData.cmsds = btoa(cmsdStaticHeader); } const cmsdDynamicHeader = response.headers['cmsd-dynamic']; if (cmsdDynamicHeader) { - responseModeData.cmsdd = btoa(cmsdDynamicHeader); + responseData.cmsdd = btoa(cmsdDynamicHeader); } } catch (e) { logger.warn('Failed to base64 encode CMSD headers, ignoring.', e); } } - return {...cmcdData, ...responseModeData}; + return {...cmcdData, ...responseData}; } function _getTargetKey(target) { - return `${target.url}_${target.cmcdMode}_${target.mode}`; + return `${target.url}_${target.mode}`; } function _getNextSequenceNumber(target) { diff --git a/test/unit/test/streaming/streaming.controllers.CmcdController.js b/test/unit/test/streaming/streaming.controllers.CmcdController.js index 166436440d..51360b3208 100644 --- a/test/unit/test/streaming/streaming.controllers.CmcdController.js +++ b/test/unit/test/streaming/streaming.controllers.CmcdController.js @@ -2202,7 +2202,8 @@ describe('CmcdController', function () { cmcdMode: 'response', mode: 'query', includeOnRequests: ['segment'], - enabledKeys: ['rc', 'ttfb', 'ttlb', 'url', 'sid'] + enabledKeys: ['rc', 'ttfb', 'ttlb', 'url', 'sid', 'e'], + events: ['rr'] }] } } @@ -2253,7 +2254,8 @@ describe('CmcdController', function () { cmcdMode: 'response', mode: 'query', includeOnRequests: ['segment'], - enabledKeys: ['cmsdd', 'cmsds'] + enabledKeys: ['cmsdd', 'cmsds', 'e'], + events: ['rr'] }] } } @@ -2303,7 +2305,8 @@ describe('CmcdController', function () { cmcdMode: 'response', mode: 'query', enabledKeys: [], - includeOnRequests: ['mpd'] + includeOnRequests: ['mpd'], + events: ['rr'] }] } } @@ -2338,7 +2341,8 @@ describe('CmcdController', function () { enabled: false, cmcdMode: 'response', mode: 'query', - includeOnRequests: ['segment'] + includeOnRequests: ['segment'], + events: ['rr'] }] } } @@ -2373,7 +2377,8 @@ describe('CmcdController', function () { enabled: true, cmcdMode: 'response', mode: 'query', - includeOnRequests: ['segment'] + includeOnRequests: ['segment'], + events: ['rr'] }] } } @@ -2409,7 +2414,8 @@ describe('CmcdController', function () { cmcdMode: 'response', mode: 'header', includeOnRequests: ['segment'], - enabledKeys: ['rc', 'sid'] + enabledKeys: ['rc', 'sid', 'e'], + events: ['rr'] }] } } @@ -2455,6 +2461,7 @@ describe('CmcdController', function () { cmcdMode: 'response', mode: 'query', includeOnRequests: ['segment'], + events: ['rr'] }] } } @@ -2506,7 +2513,8 @@ describe('CmcdController', function () { cmcdMode: 'response', mode: 'query', includeOnRequests: ['segment'], - enabledKeys: ['rc', 'e'] + enabledKeys: ['rc', 'e', 'd'], + events: ['rr'] }] } } @@ -2553,7 +2561,8 @@ describe('CmcdController', function () { enabled: true, cmcdMode: 'response', mode: 'query', - includeOnRequests: ['segment'] + includeOnRequests: ['segment'], + events: ['rr'] }] } } From dc457624dbd9a53c15d704f4aa79f0d0814459d4 Mon Sep 17 00:00:00 2001 From: Constanza Dibueno Date: Tue, 21 Oct 2025 15:55:48 -0300 Subject: [PATCH 02/16] cml rr updates integration --- src/streaming/controllers/CmcdController.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/streaming/controllers/CmcdController.js b/src/streaming/controllers/CmcdController.js index 5ecafa9b9b..69d68317a4 100644 --- a/src/streaming/controllers/CmcdController.js +++ b/src/streaming/controllers/CmcdController.js @@ -235,9 +235,8 @@ function CmcdController() { } let cmcdData = cmcdModel.triggerCmcdEventMode(event); - if (event == 'rr') { - cmcdData = {...cmcdData, ...response.request.cmcd} + cmcdData = {...cmcdData, ...response.request.cmcd} cmcdData = _addCmcdResponseReceivedData(response, cmcdData); } @@ -486,8 +485,7 @@ function CmcdController() { // } return { - // reportingMode: targetSettings ? Constants.CMCD_REPORTING_MODE.EVENT : Constants.CMCD_REPORTING_MODE.REQUEST, - reportingMode: targetSettings?.cmcdMode, + reportingMode: targetSettings ? Constants.CMCD_REPORTING_MODE.EVENT : Constants.CMCD_REPORTING_MODE.REQUEST, version: settings.get().streaming.cmcd.version ?? Constants.CMCD_DEFAULT_VERSION, filter: enabledKeys ? (key) => enabledKeys.includes(key) : undefined, } From 694dc83bcaf5acd9ce34c5fac13fb159a134854d Mon Sep 17 00:00:00 2001 From: Constanza Dibueno Date: Tue, 21 Oct 2025 15:56:05 -0300 Subject: [PATCH 03/16] cml rr updates integration --- .../streaming.controllers.CmcdController.js | 20 ++++++------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/test/unit/test/streaming/streaming.controllers.CmcdController.js b/test/unit/test/streaming/streaming.controllers.CmcdController.js index 51360b3208..0abc9ddfb7 100644 --- a/test/unit/test/streaming/streaming.controllers.CmcdController.js +++ b/test/unit/test/streaming/streaming.controllers.CmcdController.js @@ -2199,10 +2199,9 @@ describe('CmcdController', function () { targets: [{ url: 'https://cmcd.response.collector/api', enabled: true, - cmcdMode: 'response', mode: 'query', includeOnRequests: ['segment'], - enabledKeys: ['rc', 'ttfb', 'ttlb', 'url', 'sid', 'e'], + enabledKeys: ['rc', 'ttfb', 'ttlb', 'url', 'sid'], events: ['rr'] }] } @@ -2251,10 +2250,9 @@ describe('CmcdController', function () { targets: [{ url: 'https://cmcd.response.collector/api', enabled: true, - cmcdMode: 'response', mode: 'query', includeOnRequests: ['segment'], - enabledKeys: ['cmsdd', 'cmsds', 'e'], + enabledKeys: ['cmsdd', 'cmsds'], events: ['rr'] }] } @@ -2294,7 +2292,7 @@ describe('CmcdController', function () { expect(metrics).to.have.property('cmsdd', btoa(cmsdDynamicHeaderValue)); }); - it('should not send a report if enabled keys is empty', () => { + it.only('should not send a report if enabled keys is empty', () => { settings.update({ streaming: { cmcd: { @@ -2302,7 +2300,6 @@ describe('CmcdController', function () { targets: [{ url: 'https://cmcd.response.collector/api', enabled: true, - cmcdMode: 'response', mode: 'query', enabledKeys: [], includeOnRequests: ['mpd'], @@ -2339,7 +2336,6 @@ describe('CmcdController', function () { targets: [{ url: 'https://cmcd.response.collector/api', enabled: false, - cmcdMode: 'response', mode: 'query', includeOnRequests: ['segment'], events: ['rr'] @@ -2375,7 +2371,6 @@ describe('CmcdController', function () { targets: [{ url: 'https://cmcd.response.collector/api', enabled: true, - cmcdMode: 'response', mode: 'query', includeOnRequests: ['segment'], events: ['rr'] @@ -2411,10 +2406,9 @@ describe('CmcdController', function () { targets: [{ url: 'https://cmcd.response.collector/api', enabled: true, - cmcdMode: 'response', mode: 'header', includeOnRequests: ['segment'], - enabledKeys: ['rc', 'sid', 'e'], + enabledKeys: ['rc', 'sid'], events: ['rr'] }] } @@ -2458,7 +2452,6 @@ describe('CmcdController', function () { targets: [{ url: 'https://cmcd.response.collector/api', enabled: true, - cmcdMode: 'response', mode: 'query', includeOnRequests: ['segment'], events: ['rr'] @@ -2510,7 +2503,6 @@ describe('CmcdController', function () { targets: [{ url: 'https://cmcd.response.collector/api', enabled: true, - cmcdMode: 'response', mode: 'query', includeOnRequests: ['segment'], enabledKeys: ['rc', 'e', 'd'], @@ -2548,7 +2540,8 @@ describe('CmcdController', function () { const cmcdString = url.searchParams.get('CMCD'); const metrics = decodeCmcd(cmcdString); expect(metrics).to.have.property('rc'); - expect(metrics).to.not.have.property('e'); + expect(metrics).to.have.property('e'); + expect(metrics).to.not.have.property('d'); }); it('should increment the sn key for each response report', () => { @@ -2559,7 +2552,6 @@ describe('CmcdController', function () { targets: [{ url: 'https://cmcd.response.collector/api', enabled: true, - cmcdMode: 'response', mode: 'query', includeOnRequests: ['segment'], events: ['rr'] From 98f31b4704af8c05930863ff1f10d19d0fda77de Mon Sep 17 00:00:00 2001 From: Constanza Dibueno Date: Tue, 21 Oct 2025 15:56:35 -0300 Subject: [PATCH 04/16] remove only --- .../unit/test/streaming/streaming.controllers.CmcdController.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unit/test/streaming/streaming.controllers.CmcdController.js b/test/unit/test/streaming/streaming.controllers.CmcdController.js index 0abc9ddfb7..d36b007df7 100644 --- a/test/unit/test/streaming/streaming.controllers.CmcdController.js +++ b/test/unit/test/streaming/streaming.controllers.CmcdController.js @@ -2292,7 +2292,7 @@ describe('CmcdController', function () { expect(metrics).to.have.property('cmsdd', btoa(cmsdDynamicHeaderValue)); }); - it.only('should not send a report if enabled keys is empty', () => { + it('should not send a report if enabled keys is empty', () => { settings.update({ streaming: { cmcd: { From 4b8b79c5e0e9d2bf73a65de70a68782af1153e31 Mon Sep 17 00:00:00 2001 From: Constanza Dibueno Date: Tue, 21 Oct 2025 16:03:09 -0300 Subject: [PATCH 05/16] update empty enabledKeys unit test case --- .../streaming.controllers.CmcdController.js | 77 ++++++++++--------- 1 file changed, 41 insertions(+), 36 deletions(-) diff --git a/test/unit/test/streaming/streaming.controllers.CmcdController.js b/test/unit/test/streaming/streaming.controllers.CmcdController.js index d36b007df7..f083fa006e 100644 --- a/test/unit/test/streaming/streaming.controllers.CmcdController.js +++ b/test/unit/test/streaming/streaming.controllers.CmcdController.js @@ -1909,6 +1909,47 @@ describe('CmcdController', function () { const metrics2 = decodeCmcd(cmcdString2); expect(metrics2).to.have.property('sn', 2); }); + + it('should send mandatory keys if enabled keys is empty', () => { + settings.update({ + streaming: { + cmcd: { + version: 2, + targets: [{ + url: 'https://cmcd.response.collector/api', + enabled: true, + mode: 'query', + enabledKeys: [], + includeOnRequests: ['mpd'], + }] + } + } + }); + + const mockResponse = { + status: 200, + request: { + customData: { + request: { + type: HTTPRequest.MEDIA_SEGMENT_TYPE, + url: 'http://test.url/video.m4s' + } + }, + cmcd: { sid: 'session-id' } + } + }; + + const interceptor = cmcdController.getCmcdResponseInterceptors()[0]; + interceptor(mockResponse); + + expect(urlLoaderMock.load.called).to.be.true; + const requestSent = urlLoaderMock.load.firstCall.args[0].request; + const url = new URL(requestSent.url); + const cmcdString = url.searchParams.get('CMCD'); + const metrics = decodeCmcd(cmcdString); + expect(metrics).to.have.property('ts'); + expect(metrics).to.have.property('v'); + }); }); describe('Event Mode player state events', () => { @@ -2292,42 +2333,6 @@ describe('CmcdController', function () { expect(metrics).to.have.property('cmsdd', btoa(cmsdDynamicHeaderValue)); }); - it('should not send a report if enabled keys is empty', () => { - settings.update({ - streaming: { - cmcd: { - version: 2, - targets: [{ - url: 'https://cmcd.response.collector/api', - enabled: true, - mode: 'query', - enabledKeys: [], - includeOnRequests: ['mpd'], - events: ['rr'] - }] - } - } - }); - - const mockResponse = { - status: 200, - request: { - customData: { - request: { - type: HTTPRequest.MEDIA_SEGMENT_TYPE, - url: 'http://test.url/video.m4s' - } - }, - cmcd: { sid: 'session-id' } - } - }; - - const interceptor = cmcdController.getCmcdResponseInterceptors()[0]; - interceptor(mockResponse); - - expect(urlLoaderMock.load.called).to.be.false; - }); - it('should not send a report if the target is disabled', () => { settings.update({ streaming: { From 5d1003e5ef2b98991f9b10574d5916a509eef67c Mon Sep 17 00:00:00 2001 From: Constanza Dibueno Date: Tue, 21 Oct 2025 16:07:04 -0300 Subject: [PATCH 06/16] let cml handle empty key array --- src/streaming/controllers/CmcdController.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/streaming/controllers/CmcdController.js b/src/streaming/controllers/CmcdController.js index 69d68317a4..b2ba51ede4 100644 --- a/src/streaming/controllers/CmcdController.js +++ b/src/streaming/controllers/CmcdController.js @@ -480,10 +480,6 @@ function CmcdController() { targetSettings.enabledKeys : (cmcdParametersFromManifest.version ? cmcdParametersFromManifest.keys : settings.get().streaming.cmcd.enabledKeys); - // if (enabledKeys?.length === 0){ - // enabledKeys = Constants.CMCD_KEYS - // } - return { reportingMode: targetSettings ? Constants.CMCD_REPORTING_MODE.EVENT : Constants.CMCD_REPORTING_MODE.REQUEST, version: settings.get().streaming.cmcd.version ?? Constants.CMCD_DEFAULT_VERSION, From 79290f1e9a7a5f5a445bbde5b926c25ed4ba05e9 Mon Sep 17 00:00:00 2001 From: Constanza Dibueno Date: Tue, 21 Oct 2025 16:07:51 -0300 Subject: [PATCH 07/16] change let for const --- src/streaming/controllers/CmcdController.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/streaming/controllers/CmcdController.js b/src/streaming/controllers/CmcdController.js index b2ba51ede4..37369a5e31 100644 --- a/src/streaming/controllers/CmcdController.js +++ b/src/streaming/controllers/CmcdController.js @@ -476,7 +476,7 @@ function CmcdController() { function _createCmcdEncodeOptions(targetSettings) { const cmcdParametersFromManifest = cmcdModel.getCmcdParametersFromManifest(); - let enabledKeys = targetSettings ? + const enabledKeys = targetSettings ? targetSettings.enabledKeys : (cmcdParametersFromManifest.version ? cmcdParametersFromManifest.keys : settings.get().streaming.cmcd.enabledKeys); From 9ee003a7235197970901c16e87e749bb95a76d15 Mon Sep 17 00:00:00 2001 From: Constanza Dibueno Date: Tue, 21 Oct 2025 16:10:33 -0300 Subject: [PATCH 08/16] response received constant --- src/streaming/controllers/CmcdController.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/streaming/controllers/CmcdController.js b/src/streaming/controllers/CmcdController.js index 37369a5e31..3795135952 100644 --- a/src/streaming/controllers/CmcdController.js +++ b/src/streaming/controllers/CmcdController.js @@ -235,7 +235,7 @@ function CmcdController() { } let cmcdData = cmcdModel.triggerCmcdEventMode(event); - if (event == 'rr') { + if (event == Constants.CMCD_REPORTING_EVENTS.RESPONSE_RECEIVED) { cmcdData = {...cmcdData, ...response.request.cmcd} cmcdData = _addCmcdResponseReceivedData(response, cmcdData); } @@ -563,7 +563,7 @@ function CmcdController() { } function _cmcdResponseReceivedInterceptor(response){ - _onEventChange('rr', response) + _onEventChange(Constants.CMCD_REPORTING_EVENTS.RESPONSE_RECEIVED, response) return response; } From b0be8f0a058633513cee6ee6f1f612c8a09b2562 Mon Sep 17 00:00:00 2001 From: Constanza Dibueno Date: Tue, 21 Oct 2025 16:28:22 -0300 Subject: [PATCH 09/16] remove HTTPRequest.CMCD_RESPONSE --- src/streaming/controllers/CmcdBatchController.js | 7 +------ src/streaming/controllers/CmcdController.js | 2 +- src/streaming/vo/metrics/HTTPRequest.js | 1 - .../streaming.controllers.CmcdBatchController.js | 8 ++++---- 4 files changed, 6 insertions(+), 12 deletions(-) diff --git a/src/streaming/controllers/CmcdBatchController.js b/src/streaming/controllers/CmcdBatchController.js index a2cb4f4a02..13e729665a 100644 --- a/src/streaming/controllers/CmcdBatchController.js +++ b/src/streaming/controllers/CmcdBatchController.js @@ -99,12 +99,7 @@ function CmcdBatchController() { httpRequest.method = HTTPRequest.POST; httpRequest.body = cmcdData; httpRequest.headers = Constants.CMCD_CONTENT_TYPE_HEADER - - if (target.cmcdMode === Constants.CMCD_REPORTING_MODE.EVENT) { - httpRequest.type = HTTPRequest.CMCD_EVENT; - } else if (target.cmcdMode === Constants.CMCD_REPORTING_MODE.RESPONSE) { - httpRequest.type = HTTPRequest.CMCD_RESPONSE; - } + httpRequest.type = HTTPRequest.CMCD_EVENT; _sendBatchReport(httpRequest) .then((response) => { diff --git a/src/streaming/controllers/CmcdController.js b/src/streaming/controllers/CmcdController.js index 3795135952..05d59949d6 100644 --- a/src/streaming/controllers/CmcdController.js +++ b/src/streaming/controllers/CmcdController.js @@ -312,7 +312,7 @@ function CmcdController() { request.headers = Object.assign(request.headers, getHeaderParameters(request, cmcdData, targetSettings)); break; case Constants.CMCD_MODE_BODY: - if (request.type === HTTPRequest.CMCD_RESPONSE || request.type === HTTPRequest.CMCD_EVENT) { + if (request.type === HTTPRequest.CMCD_EVENT) { request.body = getJsonParameters(request, cmcdData, targetSettings); request.method = HTTPRequest.POST; request.headers = request.headers || {}; diff --git a/src/streaming/vo/metrics/HTTPRequest.js b/src/streaming/vo/metrics/HTTPRequest.js index 94bd8afe63..17bb754f95 100644 --- a/src/streaming/vo/metrics/HTTPRequest.js +++ b/src/streaming/vo/metrics/HTTPRequest.js @@ -180,7 +180,6 @@ HTTPRequest.MSS_FRAGMENT_INFO_SEGMENT_TYPE = 'FragmentInfoSegment'; HTTPRequest.DVB_REPORTING_TYPE = 'DVBReporting'; HTTPRequest.LICENSE = 'license'; HTTPRequest.CONTENT_STEERING_TYPE = 'ContentSteering'; -HTTPRequest.CMCD_RESPONSE = 'CmcdResponse'; HTTPRequest.CMCD_EVENT = 'CmcdEvent'; HTTPRequest.OTHER_TYPE = 'other'; diff --git a/test/unit/test/streaming/streaming.controllers.CmcdBatchController.js b/test/unit/test/streaming/streaming.controllers.CmcdBatchController.js index f9f869b950..d27854c8c0 100644 --- a/test/unit/test/streaming/streaming.controllers.CmcdBatchController.js +++ b/test/unit/test/streaming/streaming.controllers.CmcdBatchController.js @@ -48,7 +48,7 @@ describe('CmcdBatchController', function () { const target = { url: 'http://test.com/report', batchSize: 2, - cmcdMode: Constants.CMCD_REPORTING_MODE.RESPONSE + cmcdMode: Constants.CMCD_REPORTING_MODE.EVENT }; const cmcdData1 = 'ot%3Dm%2Csid%3D%session1'; const cmcdData2 = 'ot%3Da%2Csid%3D%session2'; @@ -62,7 +62,7 @@ describe('CmcdBatchController', function () { expect(request.url).to.equal(target.url); expect(request.method).to.equal(HTTPRequest.POST); expect(request.body).to.equal(cmcdData1 + '\n' + cmcdData2); - expect(request.type).to.equal(HTTPRequest.CMCD_RESPONSE); + expect(request.type).to.equal(HTTPRequest.CMCD_EVENT); }); }); @@ -178,7 +178,7 @@ describe('CmcdBatchController', function () { const target1 = { url: 'http://test.com/report', batchSize: 2, - cmcdMode: Constants.CMCD_REPORTING_MODE.RESPONSE + cmcdMode: Constants.CMCD_REPORTING_MODE.EVENT }; const target2 = { @@ -207,7 +207,7 @@ describe('CmcdBatchController', function () { expect(urlLoaderMock.load.calledTwice).to.be.true; const secondRequest = urlLoaderMock.load.getCall(1).args[0].request; - expect(secondRequest.type).to.equal(HTTPRequest.CMCD_RESPONSE); + expect(secondRequest.type).to.equal(HTTPRequest.CMCD_EVENT); expect(secondRequest.body).to.equal(cmcdData1 + '\n' + cmcdData3); }); }); From 0750f13ad0af515c2a4dc45d761e369f77272212 Mon Sep 17 00:00:00 2001 From: Constanza Dibueno Date: Tue, 21 Oct 2025 16:28:46 -0300 Subject: [PATCH 10/16] change default enabledKeys value --- src/core/Settings.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/Settings.js b/src/core/Settings.js index 6a2a4c63d3..278b76de16 100644 --- a/src/core/Settings.js +++ b/src/core/Settings.js @@ -1410,7 +1410,7 @@ function Settings() { rtp: null, rtpSafetyFactor: 5, mode: Constants.CMCD_MODE_QUERY, - enabledKeys: null, + enabledKeys: Constants.CMCD_KEYS, includeInRequests: ['segment', 'mpd'], version: 1, targets: [] From b5a26c7f7a265edbcfdff5ecee5d23ecb231cd00 Mon Sep 17 00:00:00 2001 From: Constanza Dibueno Date: Wed, 22 Oct 2025 12:08:00 -0300 Subject: [PATCH 11/16] prevent request loop on response received --- src/streaming/controllers/CmcdController.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/streaming/controllers/CmcdController.js b/src/streaming/controllers/CmcdController.js index 05d59949d6..ae5dae8e95 100644 --- a/src/streaming/controllers/CmcdController.js +++ b/src/streaming/controllers/CmcdController.js @@ -245,6 +245,11 @@ function CmcdController() { return; } + const requestType = response?.request.customData.request.type; + if (requestType && !cmcdModel.isIncludedInRequestFilter(requestType, targetSettings.includeOnRequests)){ + return; + } + if (targetSettings.events?.length === 0) { logger.warn('CMCD Event Mode is enabled, but the "events" setting is empty. No event-specific CMCD data will be sent.'); } From c2548f54b7c63363ab3cf052c8114c5c08951083 Mon Sep 17 00:00:00 2001 From: Constanza Dibueno Date: Wed, 22 Oct 2025 12:08:31 -0300 Subject: [PATCH 12/16] update unit test --- .../test/streaming/streaming.controllers.CmcdController.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/unit/test/streaming/streaming.controllers.CmcdController.js b/test/unit/test/streaming/streaming.controllers.CmcdController.js index f083fa006e..6b5bee851e 100644 --- a/test/unit/test/streaming/streaming.controllers.CmcdController.js +++ b/test/unit/test/streaming/streaming.controllers.CmcdController.js @@ -1916,11 +1916,10 @@ describe('CmcdController', function () { cmcd: { version: 2, targets: [{ - url: 'https://cmcd.response.collector/api', + url: 'https://cmcd.event.collector/api', enabled: true, mode: 'query', enabledKeys: [], - includeOnRequests: ['mpd'], }] } } From 6628f0bad115602de930bf967656a5f412d48f15 Mon Sep 17 00:00:00 2001 From: Constanza Dibueno Date: Wed, 22 Oct 2025 13:33:25 -0300 Subject: [PATCH 13/16] update cmcdv2 sample page --- samples/advanced/cmcd-v2.html | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/samples/advanced/cmcd-v2.html b/samples/advanced/cmcd-v2.html index a3797c5fa1..9334f51143 100644 --- a/samples/advanced/cmcd-v2.html +++ b/samples/advanced/cmcd-v2.html @@ -55,16 +55,15 @@ enabledKeys: ['br', 'd', 'ot', 'tb' , 'bl', 'dl', 'mtp', 'nor', 'nrr', 'su' , 'bs', 'rtp' , 'cid', 'pr', 'sf', 'sid', 'st', 'v', 'msd'], targets: [ { - cmcdMode: 'response', enabled: true, - url: 'http://localhost:3001/cmcd/response-mode', - enabledKeys: ['ot', 'rc', 'msd'], - includeOnRequests: ['mpd', 'segment'], + url: 'http://localhost:3001/cmcd/response-received', + enabledKeys: ['url', 'rc', 'msd'], + includeOnRequests: ['mpd', 'segment'], //ESTO LO NECESITO? + events: ['rr'], mode: CMCD_MODE_QUERY, }, { enabled: true, - cmcdMode: 'event', url: 'http://localhost:3002/cmcd/event-mode', timeInterval: 10, enabledKeys: ['e', 'msd', 'sta'], @@ -73,21 +72,18 @@ }, { enabled: true, - cmcdMode: 'event', url: 'http://localhost:3003/cmcd/event-mode', timeInterval: 6, mode: CMCD_MODE_HEADER, }, { enabled: true, - cmcdMode: 'response', - url: 'http://localhost:3004/cmcd/response-body-mode', + url: 'http://localhost:3004/cmcd/event-body-mode', mode: CMCD_MODE_BODY, batchSize: 3, }, { enabled: true, - cmcdMode: 'event', url: 'http://localhost:3005/cmcd/event-body-mode', mode: CMCD_MODE_BODY, batchTimer: 3, From 1136e146025c2046be10e1012faf804d96789e49 Mon Sep 17 00:00:00 2001 From: Constanza Dibueno Date: Wed, 22 Oct 2025 13:51:57 -0300 Subject: [PATCH 14/16] remove comment --- samples/advanced/cmcd-v2.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/advanced/cmcd-v2.html b/samples/advanced/cmcd-v2.html index 9334f51143..5a9cf1f03f 100644 --- a/samples/advanced/cmcd-v2.html +++ b/samples/advanced/cmcd-v2.html @@ -58,7 +58,7 @@ enabled: true, url: 'http://localhost:3001/cmcd/response-received', enabledKeys: ['url', 'rc', 'msd'], - includeOnRequests: ['mpd', 'segment'], //ESTO LO NECESITO? + includeOnRequests: ['mpd', 'segment'], events: ['rr'], mode: CMCD_MODE_QUERY, }, From 8c457520e03b07cb00bdf1be711b867945bafc1d Mon Sep 17 00:00:00 2001 From: Constanza Dibueno Date: Wed, 22 Oct 2025 13:59:34 -0300 Subject: [PATCH 15/16] update cmcd v2 network interceptors sample page --- samples/advanced/cmcd-v2-network-interceptors.html | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/samples/advanced/cmcd-v2-network-interceptors.html b/samples/advanced/cmcd-v2-network-interceptors.html index 93acf29972..40869a2b9c 100644 --- a/samples/advanced/cmcd-v2-network-interceptors.html +++ b/samples/advanced/cmcd-v2-network-interceptors.html @@ -80,12 +80,11 @@ includeInRequests: ['segment', 'mpd'], targets: [ { - cmcdMode: 'response', enabled: true, - url: 'http://localhost:3003/response-mode', - enabledKeys: ['ot', 'rc', 'msd'], + url: 'http://localhost:3003/report', + enabledKeys: ['e', 'rc', 'url'], mode: CMCD_MODE_QUERY, - includeOnRequests: ['mpd', 'segment'], + events: ['rr'] }, ] } @@ -97,7 +96,7 @@ /* Callback before report */ player.addRequestInterceptor((request) => { - if (request.customData.request.type == 'CmcdResponse' && request.url.includes('http://localhost:3003/response-mode')) { + if (request.customData.request.type == 'CmcdEvent' && request.url.includes('rr') && request.url.includes('http://localhost:3003/report')) { let customKey = 'synchronization-leader-sid'; let customKeyValue = '123' let { cmcd } = request; @@ -115,7 +114,7 @@ /* Callback after server response */ player.addResponseInterceptor((response) => { request = response.request.customData.request; - if (request.type == 'CmcdResponse' && request.url.includes('http://localhost:3003/response-mode')) { + if (request.type == 'CmcdEvent' && request.url.includes('rr') && request.url.includes('http://localhost:3003/report')) { console.log(request.cmcd); } return Promise.resolve(response); @@ -123,7 +122,7 @@ const originalOpen = XMLHttpRequest.prototype.open; XMLHttpRequest.prototype.open = function(method, url, ...rest) { - if (url.includes('response-mode')) { + if (url.includes('report')) { const queryString = decodeURIComponent(url.split('CMCD=')[1]); const data = getKeysForQueryMode(queryString); var keys = Object.keys(data); From d24e2e1dbfa288910da8606a7e84f6bb8a47efc0 Mon Sep 17 00:00:00 2001 From: Constanza Dibueno Date: Wed, 22 Oct 2025 14:21:58 -0300 Subject: [PATCH 16/16] add equal operator --- src/streaming/controllers/CmcdController.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/streaming/controllers/CmcdController.js b/src/streaming/controllers/CmcdController.js index ae5dae8e95..d2c57ed82c 100644 --- a/src/streaming/controllers/CmcdController.js +++ b/src/streaming/controllers/CmcdController.js @@ -235,7 +235,7 @@ function CmcdController() { } let cmcdData = cmcdModel.triggerCmcdEventMode(event); - if (event == Constants.CMCD_REPORTING_EVENTS.RESPONSE_RECEIVED) { + if (event === Constants.CMCD_REPORTING_EVENTS.RESPONSE_RECEIVED) { cmcdData = {...cmcdData, ...response.request.cmcd} cmcdData = _addCmcdResponseReceivedData(response, cmcdData); }