forked from prebid/Prebid.js
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from jwplayer/feat/AD-1499
[AD-1499] Integrate Video Module with Ad Server
- Loading branch information
Showing
12 changed files
with
390 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { GAM_VENDOR } from './videoModule/constants/vendorCodes.js'; | ||
import { adServerDirectory } from './videoModule/vendorDirectory.js'; | ||
|
||
function GamAdServerProvider(dfpModule_) { | ||
const dfp = dfpModule_; | ||
|
||
function getAdTagUrl(adUnit, baseAdTag) { | ||
return dfp.buildVideoUrl({ adUnit: adUnit, url: baseAdTag }); | ||
} | ||
|
||
return { | ||
getAdTagUrl | ||
} | ||
} | ||
function gamSubmoduleFactory() { | ||
const dfp = $$PREBID_GLOBAL$$.adServers.dfp; | ||
const gamProvider = GamAdServerProvider(dfp); | ||
return gamProvider; | ||
} | ||
|
||
gamSubmoduleFactory.vendorCode = GAM_VENDOR; | ||
adServerDirectory[GAM_VENDOR] = gamSubmoduleFactory; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { adServerDirectory } from './vendorDirectory.js'; | ||
import { ParentModule, SubmoduleBuilder } from './shared/parentModule.js'; | ||
|
||
export function AdServerCore(parentModule_) { | ||
const parentModule = parentModule_; | ||
|
||
function registerAdServer(config) { | ||
const vendorCode = config.vendorCode; | ||
parentModule.registerSubmodule(vendorCode, vendorCode, config); | ||
} | ||
|
||
function getAdTagUrl(vendorCode, adUnit, baseAdTagUrl) { | ||
const submodule = parentModule.getSubmodule(vendorCode); | ||
return submodule && submodule.getAdTagUrl(adUnit, baseAdTagUrl); | ||
} | ||
|
||
return { | ||
registerAdServer, | ||
getAdTagUrl | ||
} | ||
} | ||
|
||
export function coreAdServerFactory() { | ||
const adServerSubmoduleBuilder = SubmoduleBuilder(adServerDirectory); | ||
const parentModule = ParentModule(adServerSubmoduleBuilder); | ||
const adServerCore = AdServerCore(parentModule); | ||
return adServerCore; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,6 @@ | ||
// Video Vendors | ||
export const JWPLAYER_VENDOR = 1; | ||
export const VIDEO_JS_VENDOR = 2; | ||
|
||
// Ad Server Vendors | ||
export const GAM_VENDOR = 'gam'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
|
||
/* | ||
Used by any module to manage the relationship with its submodules. | ||
*/ | ||
export function ParentModule(submoduleBuilder_) { | ||
const submoduleBuilder = submoduleBuilder_; | ||
const submodules = {}; | ||
|
||
/* | ||
id: identifies the submodule instance | ||
vendorCode: identifies the submodule type that must be built | ||
config: additional information necessary to instantiate the instance | ||
*/ | ||
function registerSubmodule(id, vendorCode, config) { | ||
if (submodules[id]) { | ||
return; | ||
} | ||
|
||
let submodule; | ||
try { | ||
submodule = submoduleBuilder.build(vendorCode, config); | ||
} catch (e) { | ||
throw e; | ||
} | ||
submodules[id] = submodule; | ||
} | ||
|
||
function getSubmodule(id) { | ||
return submodules[id]; | ||
} | ||
|
||
return { | ||
registerSubmodule, | ||
getSubmodule | ||
} | ||
} | ||
|
||
export function SubmoduleBuilder(submoduleDirectory_) { | ||
const submoduleDirectory = submoduleDirectory_; | ||
|
||
function build(vendorCode, config) { | ||
const submoduleFactory = submoduleDirectory[vendorCode]; | ||
if (!submoduleFactory) { | ||
throw new Error('Unrecognized submodule vendor code: ' + vendorCode); | ||
} | ||
|
||
const submodule = submoduleFactory(config); | ||
submodule && submodule.init && submodule.init(); | ||
return submodule; | ||
} | ||
|
||
return { | ||
build | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export const vendorDirectory = {}; | ||
export const videoVendorDirectory = {}; | ||
export const adServerDirectory = {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { expect } from 'chai'; | ||
import { AdServerCore } from 'modules/videoModule/adServer.js'; | ||
|
||
describe('Ad Server Core', function () { | ||
const parentModuleMock = { | ||
registerSubmodule: sinon.spy(), | ||
getSubmodule: sinon.spy() | ||
}; | ||
const testVendorCode = 'test'; | ||
const adServerCore = AdServerCore(parentModuleMock); | ||
adServerCore.registerAdServer({ vendorCode: testVendorCode }); | ||
|
||
describe('Register Ad Server', function () { | ||
it('should use the vendor code as an id as well as a vendor code', function () { | ||
expect(parentModuleMock.registerSubmodule.calledOnce).to.be.true; | ||
expect(parentModuleMock.registerSubmodule.args[0][0]).to.be.equal(testVendorCode); | ||
expect(parentModuleMock.registerSubmodule.args[0][1]).to.be.equal(testVendorCode); | ||
}); | ||
}); | ||
|
||
describe('Get Ad Tag Url', function () { | ||
it('should request the right submodule', function () { | ||
adServerCore.getAdTagUrl(testVendorCode); | ||
expect(parentModuleMock.getSubmodule.calledOnce).to.be.true; | ||
expect(parentModuleMock.getSubmodule.args[0][0]).to.be.equal(testVendorCode); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.