parseVastXml(
    vastXml,
    {
      isRootVAST = false,
      url = null,
      wrapperDepth = 0,
      allowMultipleAds,
      followAdditionalWrappers,
    }
  ) {
    // check if is a valid VAST document
    if (
      !vastXml ||
      !vastXml.documentElement ||
      vastXml.documentElement.nodeName !== 'VAST'
    ) {
      this.emit('VAST-ad-parsed', {
        type: 'ERROR',
        url,
        wrapperDepth,
      });
      throw new Error('Invalid VAST XMLDocument');
    }

    const ads = [];
    const childNodes = vastXml.documentElement.childNodes;

    /* Only parse the version of the Root VAST for now because we don't know yet how to
     * handle some cases like multiple wrappers in the same vast
     */
    const vastVersion = vastXml.documentElement.getAttribute('version');
    if (isRootVAST) {
      if (vastVersion) this.vastVersion = vastVersion;
    }

    // Fill the VASTResponse object with ads and errorURLTemplates
    for (const nodeKey in childNodes) {
      const node = childNodes[nodeKey];

      if (node.nodeName === 'Error') {
        const errorURLTemplate = parserUtils.parseNodeText(node);

        // Distinguish root VAST url templates from ad specific ones
        isRootVAST
          ? this.rootErrorURLTemplates.push(errorURLTemplate)
          : this.errorURLTemplates.push(errorURLTemplate);
      } else if (node.nodeName === 'Ad') {
        // allowMultipleAds was introduced in VAST 3
        // for retrocompatibility set it to true
        if (this.vastVersion && parseFloat(this.vastVersion) < 3) {
          allowMultipleAds = true;
        } else if (allowMultipleAds === false && ads.length > 1) {
          // if wrapper allowMultipleAds is set to false only the first stand-alone Ad
          // (with no sequence values) in the requested VAST response is allowed
          break;
        }

        const result = parseAd(node, this.emit.bind(this), {
          allowMultipleAds,
          followAdditionalWrappers,
        });

        if (result.ad) {
          ads.push(result.ad);

          this.emit('VAST-ad-parsed', {
            type: result.type,
            url,
            wrapperDepth,
            adIndex: ads.length - 1,
            vastVersion,
          });
        } else {
          // VAST version of response not supported.
          this.trackVastError(this.getErrorURLTemplates(), {
            ERRORCODE: 101,
          });
        }
      }
    }

    return ads;
  }
/**
   * Parses the given xml Object into an array of ads
   * Returns the array or throws an `Error` if an invalid VAST XML is provided
   * @param  {Object} vastXml - An object representing an xml document.
   * @param  {Object} options - An optional Object of parameters to be used in the parsing process.
   * @emits  VASTParser#VAST-warning
   * @emits VASTParser#VAST-ad-parsed
   * @return {Array}
   * @throws {Error} `vastXml` must be a valid VAST XMLDocument
   */
Parses the given xml Object into an array of ads
Returns the array or throws an `Error` if an invalid VAST XML is provided
@param  {Object} vastXml - An object representing an xml document.
@param  {Object} options - An optional Object of parameters to be used in the parsing process.
@emits  VASTParser#VAST-warning
@emits VASTParser#VAST-ad-parsed
@return {Array}
@throws {Error} `vastXml` must be a valid VAST XMLDocument
Parses the given xml Object into an array of ads Returns the array or throws an ` Error ` if an invalid VAST XML is provided @param { Object } vastXml - An object representing an xml document . @param { Object } options - An optional Object of parameters to be used in the parsing process . @emits VASTParser#VAST - warning @emits VASTParser#VAST - ad - parsed @return { Array } @throws { Error } ` vastXml ` must be a valid VAST XMLDocument
parseVastXml(
    vastXml,
    {
      isRootVAST = false,
      url = null,
      wrapperDepth = 0,
      allowMultipleAds,
      followAdditionalWrappers,
    }
  ) {
    if (
      !vastXml ||
      !vastXml.documentElement ||
      vastXml.documentElement.nodeName !== 'VAST'
    ) {
      this.emit('VAST-ad-parsed', {
        type: 'ERROR',
        url,
        wrapperDepth,
      });
      throw new Error('Invalid VAST XMLDocument');
    }
    const ads = [];
    const childNodes = vastXml.documentElement.childNodes;
    const vastVersion = vastXml.documentElement.getAttribute('version');
    if (isRootVAST) {
      if (vastVersion) this.vastVersion = vastVersion;
    }
    for (const nodeKey in childNodes) {
      const node = childNodes[nodeKey];
      if (node.nodeName === 'Error') {
        const errorURLTemplate = parserUtils.parseNodeText(node);
        isRootVAST
          ? this.rootErrorURLTemplates.push(errorURLTemplate)
          : this.errorURLTemplates.push(errorURLTemplate);
      } else if (node.nodeName === 'Ad') {
        if (this.vastVersion && parseFloat(this.vastVersion) < 3) {
          allowMultipleAds = true;
        } else if (allowMultipleAds === false && ads.length > 1) {
          break;
        }
        const result = parseAd(node, this.emit.bind(this), {
          allowMultipleAds,
          followAdditionalWrappers,
        });
        if (result.ad) {
          ads.push(result.ad);
          this.emit('VAST-ad-parsed', {
            type: result.type,
            url,
            wrapperDepth,
            adIndex: ads.length - 1,
            vastVersion,
          });
        } else {
          this.trackVastError(this.getErrorURLTemplates(), {
            ERRORCODE: 101,
          });
        }
      }
    }
    return ads;
  }
parseVastXml ( vastXml , { isRootVAST = false , url = null , wrapperDepth = 0 , allowMultipleAds , followAdditionalWrappers , } ) { if ( ! vastXml || ! vastXml . documentElement || vastXml . documentElement . nodeName !== 'VAST' ) { this . emit ( 'VAST-ad-parsed' , { type : 'ERROR' , url , wrapperDepth , } ) ; throw new Error ( 'Invalid VAST XMLDocument' ) ; } const ads = [ ] ; const childNodes = vastXml . documentElement . childNodes ; const vastVersion = vastXml . documentElement . getAttribute ( 'version' ) ; if ( isRootVAST ) { if ( vastVersion ) this . vastVersion = vastVersion ; } for ( const nodeKey in childNodes ) { const node = childNodes [ nodeKey ] ; if ( node . nodeName === 'Error' ) { const errorURLTemplate = parserUtils . parseNodeText ( node ) ; isRootVAST ? this . rootErrorURLTemplates . push ( errorURLTemplate ) : this . errorURLTemplates . push ( errorURLTemplate ) ; } else if ( node . nodeName === 'Ad' ) { if ( this . vastVersion && parseFloat ( this . vastVersion ) < 3 ) { allowMultipleAds = true ; } else if ( allowMultipleAds === false && ads . length > 1 ) { break ; } const result = parseAd ( node , this . emit . bind ( this ) , { allowMultipleAds , followAdditionalWrappers , } ) ; if ( result . ad ) { ads . push ( result . ad ) ; this . emit ( 'VAST-ad-parsed' , { type : result . type , url , wrapperDepth , adIndex : ads . length - 1 , vastVersion , } ) ; } else { this . trackVastError ( this . getErrorURLTemplates ( ) , { ERRORCODE : 101 , } ) ; } } } return ads ; }
Parses the given xml Object into an array of ads
 Returns the array or throws an `Error` if an invalid VAST XML is provided
 @param  {Object} vastXml - An object representing an xml document.
Parses the given xml Object into an array of ads Returns the array or throws an ` Error ` if an invalid VAST XML is provided @param { Object } vastXml - An object representing an xml document .
// check if is a valid VAST document /* Only parse the version of the Root VAST for now because we don't know yet how to
     * handle some cases like multiple wrappers in the same vast
     */ // Fill the VASTResponse object with ads and errorURLTemplates // Distinguish root VAST url templates from ad specific ones // allowMultipleAds was introduced in VAST 3 // for retrocompatibility set it to true // if wrapper allowMultipleAds is set to false only the first stand-alone Ad // (with no sequence values) in the requested VAST response is allowed // VAST version of response not supported.