From 4e4d5de1d494ca26f18b467bb7db7aa673f687e6 Mon Sep 17 00:00:00 2001 From: Karim Mourra Date: Fri, 4 Feb 2022 17:51:13 -0300 Subject: [PATCH] obtains language code --- modules/jwplayerVideoProvider.js | 26 ++++++++-- modules/videoModule/constants/ortb.js | 1 - modules/videoModule/coreVideo.js | 1 - modules/videoModule/index.js | 4 +- .../submodules/jwplayerVideoProvider_spec.js | 48 +++++++++++++++++++ 5 files changed, 73 insertions(+), 7 deletions(-) diff --git a/modules/jwplayerVideoProvider.js b/modules/jwplayerVideoProvider.js index f026a75593c..9485bd613a2 100644 --- a/modules/jwplayerVideoProvider.js +++ b/modules/jwplayerVideoProvider.js @@ -92,7 +92,7 @@ export function JWPlayerProvider(config, jwplayer_, adState_, timeState_, callba placement: utils.getPlacement(adConfig), // linearity is omitted because both forms are supported. // sequence - TODO not yet supported - // battr - not yet supported + battr: adConfig.battr, maxextended: -1, // extension is allowed, and there is no time limit imposed. boxingallowed: 1, playbackmethod: [ utils.getPlaybackMethod(config) ], @@ -136,7 +136,11 @@ export function JWPlayerProvider(config, jwplayer_, adState_, timeState_, callba livestream: Math.min(playbackMode, 1), embeddable: 1 }; - //language string Content language using ISO-639-1-alpha-2. + + const isoLanguageCode = utils.getIsoLanguageCode(player); + if (isoLanguageCode) { + content.language = isoLanguageCode; + } return { video, @@ -796,12 +800,28 @@ export const utils = { /** * Indicates if Omid is supported * - * @param {string=} adClient - The identifier of the ad plugin requesting the bid + * @param {string} adClient - The identifier of the ad plugin requesting the bid * @returns {boolean} - support of omid */ isOmidSupported: function(adClient) { const omidIsLoaded = window.OmidSessionClient !== undefined; return omidIsLoaded && adClient === 'vast'; + }, + + /** + * Gets ISO 639 language code of current audio track. + * @param {Object} player + * @returns {string|undefined} ISO 639 language code. + */ + getIsoLanguageCode: function(player) { + const audioTracks = player.getAudioTracks(); + if (!audioTracks || !audioTracks.length) { + return; + } + + const currentTrackIndex = Math.max(player.getCurrentAudioTrack() || 0, 0); // returns -1 when there are no alternative tracks. + const audioTrack = audioTracks[currentTrackIndex]; + return audioTrack && audioTrack.language; } } diff --git a/modules/videoModule/constants/ortb.js b/modules/videoModule/constants/ortb.js index 7c936aa25a9..98830a022a0 100644 --- a/modules/videoModule/constants/ortb.js +++ b/modules/videoModule/constants/ortb.js @@ -66,7 +66,6 @@ const VIDEO_PREFIX = 'video/'; const APPLICATION_PREFIX = 'application/'; - /** * ORTB 2.5 section 3.2.7 - Video.mimes * @enum OrtbVideoParams.mimes diff --git a/modules/videoModule/coreVideo.js b/modules/videoModule/coreVideo.js index 458c098534b..158eaf61208 100644 --- a/modules/videoModule/coreVideo.js +++ b/modules/videoModule/coreVideo.js @@ -36,7 +36,6 @@ import { ParentModule, SubmoduleBuilder } from './shared/parentModule.js'; * @param {Object} options - Optional params */ - /** * @function VideoProvider#onEvents * @param {[string]} events - List of event names for which the listener should be added diff --git a/modules/videoModule/index.js b/modules/videoModule/index.js index 1d2eac196dd..20bf0f867e5 100644 --- a/modules/videoModule/index.js +++ b/modules/videoModule/index.js @@ -1,10 +1,10 @@ import { config } from '../../src/config.js'; import events from '../../src/events.js'; -import {allVideoEvents, AUCTION_AD_LOAD_ATTEMPT } from './constants/events.js'; +import { allVideoEvents, AUCTION_AD_LOAD_ATTEMPT } from './constants/events.js'; import CONSTANTS from '../../src/constants.json'; import { videoCoreFactory } from './coreVideo.js'; import { coreAdServerFactory } from './adServer.js'; -import find from 'core-js-pure/features/array/find.js'; +import find from 'prebidjs-polyfill/find.js'; import { vastXmlEditorFactory } from './shared/vastXmlEditor.js'; /** diff --git a/test/spec/modules/videoModule/submodules/jwplayerVideoProvider_spec.js b/test/spec/modules/videoModule/submodules/jwplayerVideoProvider_spec.js index 16b143cf706..cd96f6fef37 100644 --- a/test/spec/modules/videoModule/submodules/jwplayerVideoProvider_spec.js +++ b/test/spec/modules/videoModule/submodules/jwplayerVideoProvider_spec.js @@ -31,6 +31,9 @@ function getPlayerMock() { on: function () {}, off: function () {}, remove: function () {}, + getAudioTracks: function () {}, + getCurrentAudioTrack: function () {}, + getPlugin: function () {} })(); } @@ -52,6 +55,7 @@ function getUtilsMock() { isOmidSupported: function () {}, getSkipParams: function () {}, getJwEvent: function () {}, + getIsoLanguageCode: function () {} }; } @@ -752,4 +756,48 @@ describe('utils', function () { expect(isOmidSupported()).to.be.false; }); }); + + describe('getIsoLanguageCode', function () { + const sampleAudioTracks = [{language: 'ht'}, {language: 'fr'}, {language: 'es'}, {language: 'pt'}]; + + it('should return undefined when audio tracks are unavailable', function () { + const player = getPlayerMock(); + let languageCode = utils.getIsoLanguageCode(player); + expect(languageCode).to.be.undefined; + player.getAudioTracks = () => []; + languageCode = utils.getIsoLanguageCode(player); + expect(languageCode).to.be.undefined; + }); + + it('should return the first audio track language code if the getCurrentAudioTrack returns undefined', function () { + const player = getPlayerMock(); + player.getAudioTracks = () => sampleAudioTracks; + let languageCode = utils.getIsoLanguageCode(player); + expect(languageCode).to.be.equal('ht'); + }); + + it('should return the first audio track language code if the getCurrentAudioTrack returns null', function () { + const player = getPlayerMock(); + player.getAudioTracks = () => sampleAudioTracks; + player.getCurrentAudioTrack = () => null; + let languageCode = utils.getIsoLanguageCode(player); + expect(languageCode).to.be.equal('ht'); + }); + + it('should return the first audio track language code if the getCurrentAudioTrack returns -1', function () { + const player = getPlayerMock(); + player.getAudioTracks = () => sampleAudioTracks; + player.getCurrentAudioTrack = () => -1; + const languageCode = utils.getIsoLanguageCode(player); + expect(languageCode).to.be.equal('ht'); + }); + + it('should return the right audio track language code', function () { + const player = getPlayerMock(); + player.getAudioTracks = () => sampleAudioTracks; + player.getCurrentAudioTrack = () => 2; + const languageCode = utils.getIsoLanguageCode(player); + expect(languageCode).to.be.equal('es'); + }); + }); });