Skip to content

Commit

Permalink
obtains language code
Browse files Browse the repository at this point in the history
  • Loading branch information
karimMourra committed Feb 4, 2022
1 parent f614026 commit 4e4d5de
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 7 deletions.
26 changes: 23 additions & 3 deletions modules/jwplayerVideoProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) ],
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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;
}
}

Expand Down
1 change: 0 additions & 1 deletion modules/videoModule/constants/ortb.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@
const VIDEO_PREFIX = 'video/';
const APPLICATION_PREFIX = 'application/';


/**
* ORTB 2.5 section 3.2.7 - Video.mimes
* @enum OrtbVideoParams.mimes
Expand Down
1 change: 0 additions & 1 deletion modules/videoModule/coreVideo.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions modules/videoModule/index.js
Original file line number Diff line number Diff line change
@@ -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';

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ function getPlayerMock() {
on: function () {},
off: function () {},
remove: function () {},
getAudioTracks: function () {},
getCurrentAudioTrack: function () {},
getPlugin: function () {}
})();
}

Expand All @@ -52,6 +55,7 @@ function getUtilsMock() {
isOmidSupported: function () {},
getSkipParams: function () {},
getJwEvent: function () {},
getIsoLanguageCode: function () {}
};
}

Expand Down Expand Up @@ -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');
});
});
});

0 comments on commit 4e4d5de

Please sign in to comment.