Skip to content

Commit

Permalink
fix(FEC-11441): Default kava details are reported with wrong (unknown…
Browse files Browse the repository at this point in the history
…) player version (#478)

add the product version to the default kava impression and to the client tag param
extract `validateProviderConfig` from `validateConfig` to call it after getting the uiconf config
  • Loading branch information
yairans committed Aug 18, 2021
1 parent 820d9f4 commit d918029
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 19 deletions.
10 changes: 6 additions & 4 deletions src/common/utils/kaltura-params.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,13 @@ function getQueryStringParamDelimiter(url: string): string {

/**
* @param {string} url - url
* @param {string} productVersion - product version
* @return {string} - the url with the client tag appended in the query params
* @private
*/
function addClientTag(url: string): string {
function addClientTag(url: string, productVersion: ?string): string {
if (url.indexOf(CLIENT_TAG) === -1) {
url += getQueryStringParamDelimiter(url) + CLIENT_TAG + __VERSION__;
url += getQueryStringParamDelimiter(url) + CLIENT_TAG + (productVersion || __VERSION__);
}
return url;
}
Expand All @@ -158,20 +159,21 @@ function addKalturaParams(player: Player, playerConfig: PartialKPOptionsObject):
handleSessionId(player, playerConfig);
const sources = playerConfig.sources;
const sessionId = playerConfig.session && playerConfig.session.id;
const productVersion = player.config.productVersion;
Object.values(StreamType).forEach(key => {
// $FlowFixMe
if (sources[key]) {
sources[key].forEach(source => {
if (typeof source.url === 'string' && source.url.toLowerCase().indexOf(PLAY_MANIFEST) > -1 && !source.localSource) {
source.url = updateSessionIdInUrl(source.url, sessionId);
source.url = addReferrer(source.url);
source.url = addClientTag(source.url);
source.url = addClientTag(source.url, productVersion);
}
if (source.drmData && source.drmData.length) {
source.drmData.forEach(drmData => {
if (typeof drmData.licenseUrl === 'string' && [UDRM_DOMAIN, CUSTOM_DATA, SIGNATURE].every(t => drmData.licenseUrl.includes(t))) {
drmData.licenseUrl = updateSessionIdInUrl(drmData.licenseUrl, sessionId, DRM_SESSION_ID);
drmData.licenseUrl = addClientTag(drmData.licenseUrl);
drmData.licenseUrl = addClientTag(drmData.licenseUrl, productVersion);
drmData.licenseUrl = addReferrer(drmData.licenseUrl);
drmData.licenseUrl = addUIConfId(drmData.licenseUrl, playerConfig);
}
Expand Down
23 changes: 19 additions & 4 deletions src/common/utils/setup-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ function validateConfig(options: PartialKPOptionsObject): void {
throw new Error(ValidationErrorType.INITIAL_CONFIG_REQUIRED);
}
validateTargetId(options.targetId);
validateProviderConfig(options.provider);
}

/**
Expand All @@ -63,21 +62,36 @@ function validateTargetId(targetId: string): void {
}
}

/**
* @param {string} url - url
* @param {string} productVersion - product version
* @return {string} - the url with the product version appended in the query params
* @private
*/
function addProductVersion(url: string, productVersion: ?string): string {
if (productVersion) {
url += `&clientVer=${productVersion}`;
}
return url;
}

/**
* Validate the initial user input for the provider options.
* @private
* @param {ProviderOptionsObject} providerOptions - provider options.
* @param {KPOptionsObject} options - kaltura player options
* @returns {void}
*/
function validateProviderConfig(providerOptions: ProviderOptionsObject): void {
function validateProviderConfig(options: KPOptionsObject): void {
const {provider: providerOptions, productVersion}: {provider: ProviderOptionsObject, productVersion?: string} = options;
if (!providerOptions.partnerId || providerOptions.partnerId === KAVA_DEFAULT_PARTNER) {
//create source object as a 'hack' to be able to use utility functions on url
const source = {
url: KAVA_DEFAULT_IMPRESSION,
mimetype: ''
};
source.url = addProductVersion(source.url, productVersion);
source.url = addReferrer(source.url);
source.url = addClientTag(source.url);
source.url = addClientTag(source.url, productVersion);
source.url = updateSessionIdInUrl(source.url, Utils.Generator.guid() + ':' + Utils.Generator.guid());
navigator.sendBeacon && navigator.sendBeacon(source.url);
}
Expand Down Expand Up @@ -710,6 +724,7 @@ export {
setStorageTextStyle,
attachToFirstClick,
validateConfig,
validateProviderConfig,
setLogOptions,
maybeApplyStartTimeQueryParam,
createKalturaPlayerContainer,
Expand Down
4 changes: 3 additions & 1 deletion src/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import {
setStorageConfig,
setStorageTextStyle,
supportLegacyOptions,
validateConfig
validateConfig,
validateProviderConfig
} from './common/utils/setup-helpers';

/**
Expand All @@ -27,6 +28,7 @@ function setup(options: PartialKPOptionsObject | LegacyPartialKPOptionsObject):
options = supportLegacyOptions(options);
validateConfig(options);
const defaultOptions = getDefaultOptions(options);
validateProviderConfig(defaultOptions);
setLogOptions(defaultOptions);
maybeApplyStartTimeQueryParam(defaultOptions);
printSetupMessages();
Expand Down
24 changes: 17 additions & 7 deletions test/src/common/utils/kaltura-params.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,10 @@ describe('addKalturaParams', function () {
});

it('should add session id, referrer and client tag for PLAYMANIFEST source and session id, referrer, client tag and uiconfid to udrm license', function () {
let source1 = {url: 'a/b/c/PLAYMANIFEST/source', drmData: [{licenseUrl: 'udrm.kaltura.com?custom_data=someData&signature=Sig'}]};
let source1 = {
url: 'a/b/c/PLAYMANIFEST/source',
drmData: [{licenseUrl: 'udrm.kaltura.com?custom_data=someData&signature=Sig'}]
};
player.config = {provider: {uiConfId: 123}, sources: {progressive: [source1]}};
addKalturaParams(player, player.config);
source1.url.should.be.equal(
Expand All @@ -103,15 +106,21 @@ describe('addKalturaParams', function () {
});

it('should not add session id, referrer, client tag and uiconfid to other drm system', function () {
let source1 = {url: 'a/b/c/PLAYMANIFEST/source', drmData: [{licenseUrl: 'udrm.other.com?custom_data=someData&signature=Sig'}]};
let source1 = {
url: 'a/b/c/PLAYMANIFEST/source',
drmData: [{licenseUrl: 'udrm.other.com?custom_data=someData&signature=Sig'}]
};
player.config = {provider: {uiConfId: 123}, sources: {progressive: [source1]}};
addKalturaParams(player, player.config);

source1.drmData[0].licenseUrl.should.be.equal('udrm.other.com?custom_data=someData&signature=Sig');
});

it('should not add session id, referrer, client tag and uiconfid to other drm system', function () {
let source1 = {url: 'a/b/c/PLAYMANIFEST/source', drmData: [{licenseUrl: 'udrm.kaltura.com?custommm_data=someData&signature=Sig'}]};
let source1 = {
url: 'a/b/c/PLAYMANIFEST/source',
drmData: [{licenseUrl: 'udrm.kaltura.com?custommm_data=someData&signature=Sig'}]
};
player.config = {provider: {uiConfId: 123}, sources: {progressive: [source1]}};
addKalturaParams(player, player.config);

Expand Down Expand Up @@ -208,15 +217,16 @@ describe('addUIConfId', function () {
describe('addClientTag', function () {
it('should add client tag as first param', function () {
let source = {url: 'a/b/c/playmanifest/source'};
player.config = {session: {}};
source.url = addClientTag(source.url, player);
source.url.should.be.equal('a/b/c/playmanifest/source?clientTag=html5:v' + __VERSION__);
let productVersion = '7.37';
player.config = {session: {}, productVersion};
source.url = addClientTag(source.url, player.config.productVersion);
source.url.should.be.equal('a/b/c/playmanifest/source?clientTag=html5:v' + productVersion);
});

it('should add client tag as second param', function () {
let source = {url: 'a/b/c/playmanifest/source?a'};
player.config = {session: {}};
source.url = addClientTag(source.url, player);
source.url = addClientTag(source.url);
source.url.should.be.equal('a/b/c/playmanifest/source?a&clientTag=html5:v' + __VERSION__);
});
});
6 changes: 3 additions & 3 deletions test/src/common/utils/setup-helpers.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ describe('error handling', function () {
div.id = 'test-id';
document.body.appendChild(div);
(navigator.sendBeacon.getCall(0) === null).should.be.true;
SetupHelpers.validateConfig({targetId: div.id, provider: {}});
SetupHelpers.validateProviderConfig({targetId: div.id, provider: {}});
document.body.removeChild(div);
navigator.sendBeacon
.getCall(0)
Expand All @@ -63,12 +63,12 @@ describe('error handling', function () {
div.id = 'test-id';
document.body.appendChild(div);
(navigator.sendBeacon.getCall(0) === null).should.be.true;
SetupHelpers.validateConfig({targetId: div.id, provider: {partnerId: 2504201}});
SetupHelpers.validateProviderConfig({targetId: div.id, provider: {partnerId: 2504201}, productVersion: '7.37'});
document.body.removeChild(div);
navigator.sendBeacon
.getCall(0)
.args[0].should.include(
'https://analytics.kaltura.com/api_v3/index.php?service=analytics&action=trackEvent&apiVersion=3.3.0&format=1&eventType=1&partnerId=2504201&entryId=1_3bwzbc9o&&eventIndex=1&position=0&referrer'
'https://analytics.kaltura.com/api_v3/index.php?service=analytics&action=trackEvent&apiVersion=3.3.0&format=1&eventType=1&partnerId=2504201&entryId=1_3bwzbc9o&&eventIndex=1&position=0&clientVer=7.37&referrer'
);
done();
});
Expand Down

0 comments on commit d918029

Please sign in to comment.