resolveWrappers(ad, wrapperDepth, previousUrl) {
    return new Promise((resolve) => {
      // Going one level deeper in the wrapper chain
      wrapperDepth++;
      // We already have a resolved VAST ad, no need to resolve wrapper
      if (!ad.nextWrapperURL) {
        delete ad.nextWrapperURL;
        return resolve(ad);
      }

      if (
        wrapperDepth >= this.maxWrapperDepth ||
        this.parentURLs.indexOf(ad.nextWrapperURL) !== -1
      ) {
        // Wrapper limit reached, as defined by the video player.
        // Too many Wrapper responses have been received with no InLine response.
        ad.errorCode = 302;
        delete ad.nextWrapperURL;
        return resolve(ad);
      }

      // Get full URL
      ad.nextWrapperURL = parserUtils.resolveVastAdTagURI(
        ad.nextWrapperURL,
        previousUrl
      );

      this.URLTemplateFilters.forEach((filter) => {
        ad.nextWrapperURL = filter(ad.nextWrapperURL);
      });

      // If allowMultipleAds is set inside the parameter 'option' of public method
      // override the vast value by the one provided
      const allowMultipleAds =
        this.parsingOptions.allowMultipleAds ?? ad.allowMultipleAds;
      // sequence doesn't carry over in wrapper element
      const wrapperSequence = ad.sequence;
      this.fetchVAST(ad.nextWrapperURL, wrapperDepth, previousUrl)
        .then((xml) => {
          return this.parse(xml, {
            url: ad.nextWrapperURL,
            previousUrl,
            wrapperSequence,
            wrapperDepth,
            followAdditionalWrappers: ad.followAdditionalWrappers,
            allowMultipleAds,
          }).then((unwrappedAds) => {
            delete ad.nextWrapperURL;
            if (unwrappedAds.length === 0) {
              // No ads returned by the wrappedResponse, discard current <Ad><Wrapper> creatives
              ad.creatives = [];
              return resolve(ad);
            }

            unwrappedAds.forEach((unwrappedAd) => {
              if (unwrappedAd) {
                parserUtils.mergeWrapperAdData(unwrappedAd, ad);
              }
            });

            resolve(unwrappedAds);
          });
        })
        .catch((err) => {
          // Timeout of VAST URI provided in Wrapper element, or of VAST URI provided in a subsequent Wrapper element.
          // (URI was either unavailable or reached a timeout as defined by the video player.)
          ad.errorCode = 301;
          ad.errorMessage = err.message;

          resolve(ad);
        });
    });
  }
/**
   * Resolves the wrappers for the given ad in a recursive way.
   * Returns a Promise which resolves with the unwrapped ad or rejects with an error.
   * @param {Object} ad - An ad object to be unwrapped.
   * @param {Number} wrapperDepth - The reached depth in the wrapper resolving chain.
   * @param {String} previousUrl - The previous vast url.
   * @return {Promise}
   */
Resolves the wrappers for the given ad in a recursive way.
Returns a Promise which resolves with the unwrapped ad or rejects with an error.
@param {Object} ad - An ad object to be unwrapped.
@param {Number} wrapperDepth - The reached depth in the wrapper resolving chain.
@param {String} previousUrl - The previous vast url.
@return {Promise}
Resolves the wrappers for the given ad in a recursive way . Returns a Promise which resolves with the unwrapped ad or rejects with an error . @param { Object } ad - An ad object to be unwrapped . @param { Number } wrapperDepth - The reached depth in the wrapper resolving chain . @param { String } previousUrl - The previous vast url . @return { Promise }
resolveWrappers(ad, wrapperDepth, previousUrl) {
    return new Promise((resolve) => {
      wrapperDepth++;
      if (!ad.nextWrapperURL) {
        delete ad.nextWrapperURL;
        return resolve(ad);
      }
      if (
        wrapperDepth >= this.maxWrapperDepth ||
        this.parentURLs.indexOf(ad.nextWrapperURL) !== -1
      ) {
        ad.errorCode = 302;
        delete ad.nextWrapperURL;
        return resolve(ad);
      }
      ad.nextWrapperURL = parserUtils.resolveVastAdTagURI(
        ad.nextWrapperURL,
        previousUrl
      );
      this.URLTemplateFilters.forEach((filter) => {
        ad.nextWrapperURL = filter(ad.nextWrapperURL);
      });
      const allowMultipleAds =
        this.parsingOptions.allowMultipleAds ?? ad.allowMultipleAds;
      const wrapperSequence = ad.sequence;
      this.fetchVAST(ad.nextWrapperURL, wrapperDepth, previousUrl)
        .then((xml) => {
          return this.parse(xml, {
            url: ad.nextWrapperURL,
            previousUrl,
            wrapperSequence,
            wrapperDepth,
            followAdditionalWrappers: ad.followAdditionalWrappers,
            allowMultipleAds,
          }).then((unwrappedAds) => {
            delete ad.nextWrapperURL;
            if (unwrappedAds.length === 0) {
              ad.creatives = [];
              return resolve(ad);
            }
            unwrappedAds.forEach((unwrappedAd) => {
              if (unwrappedAd) {
                parserUtils.mergeWrapperAdData(unwrappedAd, ad);
              }
            });
            resolve(unwrappedAds);
          });
        })
        .catch((err) => {
          ad.errorCode = 301;
          ad.errorMessage = err.message;
          resolve(ad);
        });
    });
  }
resolveWrappers ( ad , wrapperDepth , previousUrl ) { return new Promise ( ( resolve ) => { wrapperDepth ++ ; if ( ! ad . nextWrapperURL ) { delete ad . nextWrapperURL ; return resolve ( ad ) ; } if ( wrapperDepth >= this . maxWrapperDepth || this . parentURLs . indexOf ( ad . nextWrapperURL ) !== - 1 ) { ad . errorCode = 302 ; delete ad . nextWrapperURL ; return resolve ( ad ) ; } ad . nextWrapperURL = parserUtils . resolveVastAdTagURI ( ad . nextWrapperURL , previousUrl ) ; this . URLTemplateFilters . forEach ( ( filter ) => { ad . nextWrapperURL = filter ( ad . nextWrapperURL ) ; } ) ; const allowMultipleAds = this . parsingOptions . allowMultipleAds ?? ad . allowMultipleAds ; const wrapperSequence = ad . sequence ; this . fetchVAST ( ad . nextWrapperURL , wrapperDepth , previousUrl ) . then ( ( xml ) => { return this . parse ( xml , { url : ad . nextWrapperURL , previousUrl , wrapperSequence , wrapperDepth , followAdditionalWrappers : ad . followAdditionalWrappers , allowMultipleAds , } ) . then ( ( unwrappedAds ) => { delete ad . nextWrapperURL ; if ( unwrappedAds . length === 0 ) { ad . creatives = [ ] ; return resolve ( ad ) ; } unwrappedAds . forEach ( ( unwrappedAd ) => { if ( unwrappedAd ) { parserUtils . mergeWrapperAdData ( unwrappedAd , ad ) ; } } ) ; resolve ( unwrappedAds ) ; } ) ; } ) . catch ( ( err ) => { ad . errorCode = 301 ; ad . errorMessage = err . message ; resolve ( ad ) ; } ) ; } ) ; }
Resolves the wrappers for the given ad in a recursive way.
Resolves the wrappers for the given ad in a recursive way .
// Going one level deeper in the wrapper chain // We already have a resolved VAST ad, no need to resolve wrapper // Wrapper limit reached, as defined by the video player. // Too many Wrapper responses have been received with no InLine response. // Get full URL // If allowMultipleAds is set inside the parameter 'option' of public method // override the vast value by the one provided // sequence doesn't carry over in wrapper element // No ads returned by the wrappedResponse, discard current <Ad><Wrapper> creatives // Timeout of VAST URI provided in Wrapper element, or of VAST URI provided in a subsequent Wrapper element. // (URI was either unavailable or reached a timeout as defined by the video player.)