UNPKG

@speechkit/speechkit-audio-player

Version:

A web player component that can play audio from https://speechkit.io

66 lines (55 loc) 2.43 kB
const stringToXML = sXml => { if (typeof window.DOMParser !== 'undefined') { return new window.DOMParser().parseFromString(sXml, 'text/xml'); } else if (typeof window.ActiveXObject !== 'undefined' && new window.ActiveXObject('Microsoft.XMLDOM')) { const xmlDoc = new window.ActiveXObject('Microsoft.XMLDOM'); xmlDoc.async = 'false'; xmlDoc.loadXML(sXml); return xmlDoc; } return false; } // Return array of all nodes in aXMLNodes that have sAttribute equal to sReqValue const getNodesWithAttrValue = (aXMLNodes, sAttribute, sReqValue) => { const aNodes = Array.apply(null, aXMLNodes); return aNodes.filter(node => node.nodeType !== 3) //filter out text nodes .filter(node => node.getAttribute(sAttribute) === sReqValue); //filter for node value } // Return array of textContent of all nodes in aXMLNodes that have sAttribute equal to sReqValue // Currently used for getting tracking urls const getContentOfNodesWithAttrValue = (aXMLNodes, sAttribute, sReqValue) => { const aNodes = getNodesWithAttrValue(aXMLNodes, sAttribute, sReqValue); return aNodes.map(node => node.textContent); } // Take array of XML Nodes & return array of the text content of each node // (used for getting error/impression urls) const getNodeValues = aXMLNodes => { const aNodes = Array.apply(null, aXMLNodes); return aNodes.filter(node => node.nodeType !== 3) // filter out text nodes .map(node => node.textContent); // then return textContent } // pass in xml node and event type string, return array of events const getVASTEventURLs = (xNode, sEventType) => { const xEvents = xNode.getElementsByTagName(sEventType), aEventNodes = Array.apply(null, xEvents), aEventUrls = getNodeValues(aEventNodes); return aEventUrls; } //store error/impression events from VAST XML const getCreative = xAd => { // Look for all creatives: const xCreatives = xAd.getElementsByTagName('Creative'), aCreatives = Array.apply(null, xCreatives); // now filter for those creatives that have a linear node const aFilteredCreatives = aCreatives.filter(node => node.getElementsByTagName('Linear').length) // take the first linear creative (can expand for adservers returning >1) const xCreative = aFilteredCreatives[0]; return xCreative; } export { stringToXML, getCreative, getVASTEventURLs, getNodesWithAttrValue, getContentOfNodesWithAttrValue, }