Skip to content

Commit

Permalink
enables mdule hook
Browse files Browse the repository at this point in the history
  • Loading branch information
karimJWP authored and karimJWP committed Jul 8, 2020
1 parent 0003a3d commit 18f83cc
Showing 1 changed file with 27 additions and 11 deletions.
38 changes: 27 additions & 11 deletions modules/jwplayerTargeting.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
import { config } from '../src/config.js';
import { ajaxBuilder } from '../src/ajax.js';
import { logError } from '../src/utils.js';
import { logError, isPlainObject } from '../src/utils.js';
import { getGlobal } from '../src/prebidGlobal.js';
import { module } from '../src/hook.js';

const segCache = {};
let pendingRequests = 0;
let requestCount = 0;
let requestTimeout;
let resumeBidRequest;

function setup () {
config.getConfig('jwpTargeting', (config) => {
// fetch media ids
const targeting = config.jwpTargeting;
if (!targeting) {
return;
}
const mediaIDs = targeting.mediaIDs;
pendingRequests = mediaIDs.length;
console.log('karim config');
const mediaIDs = config.jwpTargeting.mediaIDs;
requestCount = mediaIDs.length;
mediaIDs.forEach(mediaID => {
console.log(mediaID);
fetchTargetingForMediaId(mediaID);
Expand All @@ -25,7 +23,7 @@ function setup () {

getGlobal().requestBids.before(function(nextFn, reqBidsConfigObj) {
console.error('karim before requestBids', reqBidsConfigObj);
if (pendingRequests <= 0) {
if (requestCount <= 0) {
console.log('karim no pending reqs');
nextFn.apply(this, [reqBidsConfigObj]);
return;
Expand Down Expand Up @@ -127,8 +125,8 @@ function fetchTargetingForMediaId(mediaId) {
}

function onRequestCompleted() {
pendingRequests--;
if (pendingRequests > 0) {
requestCount--;
if (requestCount > 0) {
return;
}

Expand All @@ -144,3 +142,21 @@ function onRequestCompleted() {
}

setup();

const sharedMethods = {
'getTargetingForBid': getTargetingForBid
}
Object.freeze(sharedMethods);

module('jwplayer', function shareJWPlayerUtilities(...args) {
if (!isPlainObject(args[0])) {
logError('JW Player module requires plain object to share methods with submodule');
return;
}
function addMethods(object, func) {
for (let name in func) {
object[name] = func[name];
}
}
addMethods(args[0], sharedMethods);
});

0 comments on commit 18f83cc

Please sign in to comment.