Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions spec/fetcher.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ describe('Fetcher', () => {
maxWrapperDepth: 4,
timeout: 120000,
wrapperAd: null,
wrapperChainId: 0,
});

expect(mockEmit).toHaveBeenNthCalledWith(2, 'VAST-resolved', {
Expand All @@ -80,6 +81,7 @@ describe('Fetcher', () => {
statusCode: 200,
previousUrl: null,
wrapperDepth: 0,
wrapperChainId: 0,
});
});
});
Expand Down Expand Up @@ -156,6 +158,7 @@ describe('Fetcher', () => {
maxWrapperDepth: 4,
timeout: 120000,
wrapperAd: null,
wrapperChainId: 0,
});

expect(mockEmit).toHaveBeenNthCalledWith(2, 'VAST-resolved', {
Expand All @@ -165,6 +168,7 @@ describe('Fetcher', () => {
statusCode: 500,
previousUrl: null,
wrapperDepth: 0,
wrapperChainId: 0,
});
});
});
Expand Down
11 changes: 9 additions & 2 deletions spec/vast_parser.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ describe('VASTParser', () => {
type: 'ERROR',
url: inlineInvalidVastUrl,
wrapperDepth: 0,
wrapperChainId: 0,
});
}
});
Expand All @@ -125,6 +126,7 @@ describe('VASTParser', () => {
type: 'ERROR',
url: null,
wrapperDepth: 0,
wrapperChainId: 0,
});
}
});
Expand Down Expand Up @@ -171,13 +173,15 @@ describe('VASTParser', () => {
url: inlineSampleVastUrl,
wrapperDepth: 0,
vastVersion: '4.3',
wrapperChainId: 0,
});
expect(VastParser.emit).toHaveBeenCalledWith('VAST-ad-parsed', {
adIndex: 1,
type: 'INLINE',
url: inlineSampleVastUrl,
wrapperDepth: 0,
vastVersion: '4.3',
wrapperChainId: 0,
});
});
});
Expand All @@ -198,6 +202,9 @@ describe('VASTParser', () => {
isRootVAST: true,
url: inlineSampleVastUrl,
wrapperDepth: 0,
allowMultipleAds: undefined,
followAdditionalWrappers: undefined,
wrapperChainId: 0,
});
});
});
Expand Down Expand Up @@ -590,8 +597,8 @@ describe('VASTParser', () => {
}).then(() => {
expect(VastParser.resolveWrappers).toHaveBeenCalledTimes(2);
expect(VastParser.resolveWrappers.mock.calls).toEqual([
['ad1', 1, inlineSampleVastUrl],
['ad2', 1, inlineSampleVastUrl],
['ad1', 1, inlineSampleVastUrl, 0],
['ad2', 1, inlineSampleVastUrl, 0],
]);
});
});
Expand Down
4 changes: 4 additions & 0 deletions src/fetcher/fetcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export class Fetcher {
* @param {(String | null)} params.previousUrl - Url of the previous VAST.
* @param {Object} params.wrapperAd - Previously parsed ad node (Wrapper) related to this fetching.
* @param {Number} params.maxWrapperDepth - The maximum number of Wrapper that can be fetch
* @param {Number} params.wrapperChainId - The id of the current wrapper chain.
* @param {Function} params.emitter - The function used to Emit event
* @emits VASTParser#VAST-resolving
* @emits VASTParser#VAST-resolved
Expand All @@ -78,6 +79,7 @@ export class Fetcher {
wrapperDepth = 0,
previousUrl = null,
wrapperAd = null,
wrapperChainId = 0,
}) {
const timeBeforeGet = Date.now();

Expand All @@ -93,6 +95,7 @@ export class Fetcher {
maxWrapperDepth,
timeout: this.fetchingOptions.timeout,
wrapperAd,
wrapperChainId,
});

const data = await this.urlHandler.get(url, this.fetchingOptions);
Expand All @@ -105,6 +108,7 @@ export class Fetcher {
error: data?.error || null,
duration: requestDuration,
statusCode: data?.statusCode || null,
wrapperChainId,
...data?.details,
});
updateEstimatedBitrate(data?.details?.byteLength, requestDuration);
Expand Down
19 changes: 16 additions & 3 deletions src/parser/vast_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ export class VASTParser extends EventEmitter {
wrapperDepth = 0,
allowMultipleAds,
followAdditionalWrappers,
wrapperChainId = 0,
}
) {
// check if is a valid VAST document
Expand All @@ -175,6 +176,7 @@ export class VASTParser extends EventEmitter {
type: 'ERROR',
url,
wrapperDepth,
wrapperChainId,
});
// VideoAdServingTemplate node is used for VAST 1.0
const isNonSupportedVast =
Expand Down Expand Up @@ -230,6 +232,7 @@ export class VASTParser extends EventEmitter {
wrapperDepth,
adIndex: ads.length - 1,
vastVersion,
wrapperChainId,
});
} else {
// VAST version of response not supported.
Expand Down Expand Up @@ -263,6 +266,7 @@ export class VASTParser extends EventEmitter {
isRootVAST = false,
followAdditionalWrappers,
allowMultipleAds,
wrapperChainId = 0,
} = {}
) {
let ads = [];
Expand All @@ -278,6 +282,7 @@ export class VASTParser extends EventEmitter {
wrapperDepth,
allowMultipleAds,
followAdditionalWrappers,
wrapperChainId,
});
} catch (e) {
return Promise.reject(e);
Expand Down Expand Up @@ -318,6 +323,7 @@ export class VASTParser extends EventEmitter {
wrapperDepth,
previousUrl,
url,
wrapperChainId,
});
}

Expand All @@ -328,17 +334,22 @@ export class VASTParser extends EventEmitter {
* @param {Object} options - An options Object containing resolving parameters
* @return {Promise}
*/
resolveAds(ads = [], { wrapperDepth, previousUrl, url }) {
resolveAds(ads = [], { wrapperDepth, previousUrl, url, wrapperChainId = 0 } = {}) {
const resolveWrappersPromises = [];
previousUrl = url;
ads.forEach((ad) => {
const resolveWrappersPromise = this.resolveWrappers(
ad,
wrapperDepth,
previousUrl
previousUrl,
wrapperChainId
);

resolveWrappersPromises.push(resolveWrappersPromise);

if (wrapperDepth === 0) {
wrapperChainId++;
}
});

return Promise.all(resolveWrappersPromises).then((unwrappedAds) => {
Expand All @@ -354,7 +365,7 @@ export class VASTParser extends EventEmitter {
* @param {String} previousUrl - The previous vast url.
* @return {Promise}
*/
resolveWrappers(adToUnWrap, wrapperDepth, previousUrl) {
resolveWrappers(adToUnWrap, wrapperDepth, previousUrl, wrapperChainId) {
// Copy ad from parameters to prevent altering given object outside of function scope
const ad = { ...adToUnWrap };
return new Promise((resolve) => {
Expand Down Expand Up @@ -401,6 +412,7 @@ export class VASTParser extends EventEmitter {
wrapperDepth,
previousUrl,
wrapperAd: ad,
wrapperChainId,
})
.then((xml) => {
return this.parse(xml, {
Expand All @@ -410,6 +422,7 @@ export class VASTParser extends EventEmitter {
wrapperDepth,
followAdditionalWrappers: ad.followAdditionalWrappers,
allowMultipleAds,
wrapperChainId,
}).then((unwrappedAds) => {
delete ad.nextWrapperURL;
if (unwrappedAds.length === 0) {
Expand Down
Loading