Skip to content

[POC] - Support dependencies in modules #27

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 13 commits into from
8 changes: 8 additions & 0 deletions gulpHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ const through = require('through2');
const _ = require('lodash');
const gutil = require('gulp-util');
const submodules = require('./modules/.submodules.json');
const dependencies = require('./modules/.dependencies.json');
const dependencyEntries = require('./modules/.dependencyEntries.json');

const MODULE_PATH = './modules';
const BUILD_PATH = './build/dist';
Expand Down Expand Up @@ -70,6 +72,12 @@ module.exports = {

return modules;
},
getDependencies(moduleName) {
return dependencies[moduleName];
},
getDependencyEntry(dependencyName) {
return dependencyEntries[dependencyName];
},
getModules: _.memoize(function(externalModules) {
externalModules = externalModules || [];
var internalModules;
Expand Down
8 changes: 8 additions & 0 deletions modules/.dependencies.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
Copy link

@dgirardi dgirardi May 16, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer if there was only one configuration file for this, to make it harder for them to get out of sync, my vote would be for something like

"libraries": {
  "video": {
    "files": [...],
    "dependants": [
       "jwPlayerVideoProvider",
        ....
    }
  }
},

IMO it could be put in the same ".submodules.json" file we already have with some refactoring / renaming.

"jwplayerVideoProvider": [
"video-module"
],
"testVideoProvider": [
"video-module"
]
}
6 changes: 6 additions & 0 deletions modules/.dependencyEntries.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"video-module": {
"import": ["./modules/videoModule/index.js", "./modules/videoModule/constants/ortb.js", "./modules/videoModule/constants/enums.js"],
"dependOn": "prebid-core"
}
}
3 changes: 0 additions & 3 deletions modules/.submodules.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,5 @@
"fpdModule": [
"enrichmentFpdModule",
"validationFpdModule"
],
"videoModule": [
"jwplayerVideoProvider"
]
}
43 changes: 21 additions & 22 deletions modules/jwplayerVideoProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ import {
PROTOCOLS, API_FRAMEWORKS, VIDEO_MIME_TYPE, PLAYBACK_METHODS, PLACEMENT, VPAID_MIME_TYPE
} from './videoModule/constants/ortb.js';
import { PLAYBACK_MODE } from './videoModule/constants/enums.js';
import {
SETUP_COMPLETE, SETUP_FAILED, DESTROYED, AD_REQUEST, AD_BREAK_START, AD_LOADED, AD_STARTED, AD_IMPRESSION, AD_PLAY,
AD_TIME, AD_PAUSE, AD_CLICK, AD_SKIPPED, AD_ERROR, AD_COMPLETE, AD_BREAK_END, PLAYLIST, PLAYBACK_REQUEST,
AUTOSTART_BLOCKED, PLAY_ATTEMPT_FAILED, CONTENT_LOADED, PLAY, PAUSE, BUFFER, TIME, SEEK_START, SEEK_END, MUTE, VOLUME,
RENDITION_UPDATE, ERROR, COMPLETE, PLAYLIST_COMPLETE, FULLSCREEN, PLAYER_RESIZE, VIEWABLE, CAST
} from './videoModule/constants/events.js';
import stateFactory from './videoModule/shared/state.js';
import { JWPLAYER_VENDOR } from './videoModule/constants/vendorCodes.js';
import { submodule } from '../src/hook.js';
Expand Down Expand Up @@ -30,13 +36,6 @@ export function JWPlayerProvider(config, jwplayer_, adState_, timeState_, callba
let minimumSupportedPlayerVersion = '8.20.1';
let setupCompleteCallback = null;
let setupFailedCallback = null;
const prebidVideoEvents = sharedUtils.videoEvents;
const {
SETUP_COMPLETE, SETUP_FAILED, DESTROYED, AD_REQUEST, AD_BREAK_START, AD_LOADED, AD_STARTED, AD_IMPRESSION, AD_PLAY,
AD_TIME, AD_PAUSE, AD_CLICK, AD_SKIPPED, AD_ERROR, AD_COMPLETE, AD_BREAK_END, PLAYLIST, PLAYBACK_REQUEST,
AUTOSTART_BLOCKED, PLAY_ATTEMPT_FAILED, CONTENT_LOADED, PLAY, PAUSE, BUFFER, TIME, SEEK_START, SEEK_END, MUTE, VOLUME,
RENDITION_UPDATE, ERROR, COMPLETE, PLAYLIST_COMPLETE, FULLSCREEN, PLAYER_RESIZE, VIEWABLE, CAST
} = prebidVideoEvents;
const MEDIA_TYPES = [
VIDEO_MIME_TYPE.MP4,
VIDEO_MIME_TYPE.OGG,
Expand Down Expand Up @@ -194,7 +193,7 @@ export function JWPlayerProvider(config, jwplayer_, adState_, timeState_, callba

function offEvents(events, callback) {
events.forEach(event => {
const jwEvent = utils.getJwEvent(event, prebidVideoEvents);
const jwEvent = utils.getJwEvent(event);
if (!callback) {
player.off(jwEvent);
return;
Expand Down Expand Up @@ -720,42 +719,42 @@ export const utils = {
return jwConfig;
},

getJwEvent: function(eventName, prebidVideoEvents) {
getJwEvent: function(eventName) {
switch (eventName) {
case prebidVideoEvents.SETUP_COMPLETE:
case SETUP_COMPLETE:
return 'ready';

case prebidVideoEvents.SETUP_FAILED:
case SETUP_FAILED:
return 'setupError';

case prebidVideoEvents.DESTROYED:
case DESTROYED:
return 'remove';

case prebidVideoEvents.AD_STARTED:
return prebidVideoEvents.AD_IMPRESSION;
case AD_STARTED:
return AD_IMPRESSION;

case prebidVideoEvents.AD_IMPRESSION:
case AD_IMPRESSION:
return 'adViewableImpression';

case prebidVideoEvents.PLAYBACK_REQUEST:
case PLAYBACK_REQUEST:
return 'playAttempt';

case prebidVideoEvents.AUTOSTART_BLOCKED:
case AUTOSTART_BLOCKED:
return 'autostartNotAllowed';

case prebidVideoEvents.CONTENT_LOADED:
case CONTENT_LOADED:
return 'playlistItem';

case prebidVideoEvents.SEEK_START:
case SEEK_START:
return 'seek';

case prebidVideoEvents.SEEK_END:
case SEEK_END:
return 'seeked';

case prebidVideoEvents.RENDITION_UPDATE:
case RENDITION_UPDATE:
return 'visualQuality';

case prebidVideoEvents.PLAYER_RESIZE:
case PLAYER_RESIZE:
return 'resize';

default:
Expand Down
26 changes: 26 additions & 0 deletions modules/testVideoProvider.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import {
PROTOCOLS, API_FRAMEWORKS, VIDEO_MIME_TYPE, PLAYBACK_METHODS, PLACEMENT, VPAID_MIME_TYPE
} from './videoModule/constants/ortb.js';
import { PLAYBACK_MODE } from './videoModule/constants/enums.js';
import {
SETUP_COMPLETE, SETUP_FAILED, DESTROYED, AD_REQUEST, AD_BREAK_START, AD_LOADED, AD_STARTED, AD_IMPRESSION, AD_PLAY,
AD_TIME, AD_PAUSE, AD_CLICK, AD_SKIPPED, AD_ERROR, AD_COMPLETE, AD_BREAK_END, PLAYLIST, PLAYBACK_REQUEST,
AUTOSTART_BLOCKED, PLAY_ATTEMPT_FAILED, CONTENT_LOADED, PLAY, PAUSE, BUFFER, TIME, SEEK_START, SEEK_END, MUTE, VOLUME,
RENDITION_UPDATE, ERROR, COMPLETE, PLAYLIST_COMPLETE, FULLSCREEN, PLAYER_RESIZE, VIEWABLE, CAST
} from './videoModule/constants/events.js';
import stateFactory from './videoModule/shared/state.js';
import { VIDEO_JS_VENDOR } from './videoModule/constants/vendorCodes.js';
import { submodule } from '../src/hook.js';
import {registerBidder} from '../src/adapters/bidderFactory.js';

export function testProvider() {
const state = stateFactory();
state.updateState(PROTOCOLS, API_FRAMEWORKS, VIDEO_MIME_TYPE, PLAYBACK_METHODS, PLACEMENT, VPAID_MIME_TYPE, SETUP_COMPLETE, SETUP_FAILED, DESTROYED, AD_REQUEST, AD_BREAK_START, AD_LOADED, AD_STARTED, AD_IMPRESSION, AD_PLAY,
AD_TIME, AD_PAUSE, AD_CLICK, AD_SKIPPED, AD_ERROR, AD_COMPLETE, AD_BREAK_END, PLAYLIST, PLAYBACK_REQUEST,
AUTOSTART_BLOCKED, PLAY_ATTEMPT_FAILED, CONTENT_LOADED, PLAY, PAUSE, BUFFER, TIME, SEEK_START, SEEK_END, MUTE, VOLUME,
RENDITION_UPDATE, ERROR, COMPLETE, PLAYLIST_COMPLETE, FULLSCREEN, PLAYER_RESIZE, VIEWABLE, CAST, registerBidder, PLAYBACK_MODE);
}

testProvider.code = VIDEO_JS_VENDOR;

submodule('videoModule', testProvider);
20 changes: 20 additions & 0 deletions webpack.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,31 @@ module.exports = {
}
};
const selectedModules = new Set(helpers.getArgModules());

function setDependency(dependencyName) {
if (entry[dependencyName]) {
return;
}

const dependencyEntry = helpers.getDependencyEntry(dependencyName);
if (!dependencyEntry) {
return;
}

entry[dependencyName] = dependencyEntry;
}

Object.entries(helpers.getModules()).forEach(([fn, mod]) => {
if (selectedModules.size === 0 || selectedModules.has(mod)) {
entry[mod] = {
import: fn,
dependOn: 'prebid-core'
};

const extraDependencies = helpers.getDependencies(mod);
if (extraDependencies) {
extraDependencies.forEach(dependency => setDependency(dependency));
entry[mod].dependOn = ['prebid-core'].concat(extraDependencies);
}
}
});
Expand Down