-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from voxmedia/ba-vast-wrapper-support
Vast Wrapper Support
- Loading branch information
Showing
25 changed files
with
623 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
## v1.1 (March 3, 2019) | ||
|
||
- Preparing for open sourcing, adding documentation | ||
- Adds Wrapper/VASTAdTagURI support, `async` in more loading paths | ||
- Moves XML Node Value parsing to it's own library | ||
|
||
## v1.0 | ||
|
||
- Basic Vast support | ||
- Applications for `<video>` element and `videojs` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
export default class NodeValue { | ||
/** | ||
* Returns the first TEXT or CDATA value from an XML element. | ||
* | ||
* @param {DOM Element} el An elemenet with a single CDATA or TEXT entity | ||
*/ | ||
static fromElement(el) { | ||
const matchedItem = Array.from(el.childNodes).find(n => { | ||
return (n.nodeType == Node.TEXT_NODE || n.nodeType == Node.CDATA_SECTION_NODE) && !!n.nodeValue.trim(); | ||
}); | ||
return matchedItem ? matchedItem.nodeValue.trim() : null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
export class VastNetworkError extends Error {} | ||
|
||
export default class Remote { | ||
/** | ||
* Fetches a remote XML Vast url. It has no knowledge of XML or the Vast structure | ||
* | ||
* @async | ||
* @param {String} url - Where to download the XML | ||
* @param {Integer} timeout - time in milleseconds to wait until for remote load | ||
* @param {Function} onBandwidthUpdate - Callback when there is a new bandwidth estimate available, | ||
* will be be passed a number representing KB/s | ||
* @returns {Promise<String>} XML Response from the url | ||
*/ | ||
static async loadUrl({ url, timeout = 10000, onBandwidthUpdate = () => {} }) { | ||
return new Promise((resolve, reject) => { | ||
this.vastUrl = url; | ||
const request = new XMLHttpRequest(); | ||
request.timeout = timeout; | ||
let startTime; | ||
|
||
request.addEventListener('load', async e => { | ||
const downloadTime = new Date().getTime() - startTime; | ||
const downloadSize = request.responseText.length; | ||
const bandwidthEstimateInKbs = (downloadSize * 8) / (downloadTime / 1000) / 1024; | ||
onBandwidthUpdate(bandwidthEstimateInKbs); | ||
resolve(request.response); | ||
}); | ||
|
||
request.addEventListener('error', e => { | ||
reject(new VastNetworkError(`Network Error: Request status: ${request.status}, ${request.responseText}`)); | ||
}); | ||
|
||
request.addEventListener('abort', e => { | ||
reject(new VastNetworkError('Network Aborted')); | ||
}); | ||
|
||
request.addEventListener('timeout', e => { | ||
reject(new VastNetworkError(`Network Timeout: Request did not complete in ${timeout}ms`)); | ||
}); | ||
|
||
startTime = new Date().getTime(); | ||
request.open('GET', this.vastUrl); | ||
request.send(); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.