diff --git a/integrationExamples/videoModule/jwplayer/bidsBackHandlerOverride.html b/integrationExamples/videoModule/jwplayer/bidsBackHandlerOverride.html index 66eaff26090..7a7b71eba82 100644 --- a/integrationExamples/videoModule/jwplayer/bidsBackHandlerOverride.html +++ b/integrationExamples/videoModule/jwplayer/bidsBackHandlerOverride.html @@ -119,7 +119,9 @@ }); bid.vastUrl = videoUrl; - pbjs.videoModule.renderBid('player', bid); + pbjs.renderAd(null, bid.adId); + // Alternatively you can use: + // pbjs.videoModule.renderBid('player', bid); }); } }); diff --git a/libraries/creativeRender/direct.js b/libraries/creativeRender/direct.js index 0b4fb2f0a75..9a92da6e7a7 100644 --- a/libraries/creativeRender/direct.js +++ b/libraries/creativeRender/direct.js @@ -35,12 +35,13 @@ export function renderAdDirect(doc, adId, options) { } else { bid = auctionManager.findBidByAdId(adId); - if (FEATURES.VIDEO) { + if (FEATURES.VIDEO && bid.mediaType === 'video') { // TODO: could the video module implement this as a custom renderer, rather than a special case in here? const adUnit = bid && auctionManager.index.getAdUnit(bid); const videoModule = getGlobal().videoModule; - if (adUnit?.video && videoModule) { - videoModule.renderBid(adUnit.video.divId, bid); + const divId = adUnit && adUnit.video && adUnit.video.divId; + if (divId && videoModule) { + videoModule.renderBid(divId, bid); return; } } diff --git a/test/spec/unit/pbjs_api_spec.js b/test/spec/unit/pbjs_api_spec.js index 39123d4aa41..b18a7292581 100644 --- a/test/spec/unit/pbjs_api_spec.js +++ b/test/spec/unit/pbjs_api_spec.js @@ -1206,6 +1206,8 @@ describe('Unit: Prebid Module', function () { var spyAddWinningBid; var inIframe = true; var triggerPixelStub; + let indexStub; + let auctionManagerInstance; function pushBidResponseToAuction(obj) { adResponse = Object.assign({ @@ -1251,6 +1253,10 @@ describe('Unit: Prebid Module', function () { inIframe = true; sinon.stub(utils, 'inIframe').callsFake(() => inIframe); triggerPixelStub = sinon.stub(utils.internal, 'triggerPixel'); + + indexStub = sinon.stub(auctionManager, 'index'); + auctionManagerInstance = newAuctionManager(); + indexStub.get(() => auctionManagerInstance.index); }); afterEach(function () { @@ -1261,6 +1267,7 @@ describe('Unit: Prebid Module', function () { utils.inIframe.restore(); triggerPixelStub.restore(); spyAddWinningBid.restore(); + indexStub.restore(); }); it('should require doc and id params', function () { @@ -1469,6 +1476,25 @@ describe('Unit: Prebid Module', function () { $$PREBID_GLOBAL$$.offEvent(CONSTANTS.EVENTS.STALE_RENDER, onStaleEvent); configObj.setConfig({'auctionOptions': {}}); }); + + if (FEATURES.VIDEO) { + it('should render in the Video Module when mediaType is video and the AdUnit includes a video config', function () { + const adUnit = { + video: { + divId: 'playerDivId' + } + }; + sinon.stub(auctionManager.index, 'getAdUnit').callsFake(() => adUnit); + pushBidResponseToAuction({ + mediaType: 'video' + }); + const renderBidSpy = sinon.spy($$PREBID_GLOBAL$$.videoModule, 'renderBid'); + $$PREBID_GLOBAL$$.renderAd(null, bidId); + assert.ok(renderBidSpy.calledOnce, 'videoModule.renderBid should be called when adUnit is configured for Video Module'); + const args = renderBidSpy.getCall(0).args; + assert.ok(args[0] === 'playerDivId', 'divId from adUnit must be passed as an argument'); + }); + } }); describe('requestBids', function () {