Skip to content

Commit

Permalink
Wrapper limit handling (#157)
Browse files Browse the repository at this point in the history
* Added wrapperLimit to options
* Fixed error forwarding inside wrappers
  • Loading branch information
itsikal authored and briganti committed Jan 30, 2017
1 parent c5eaeb4 commit 6941173
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
1 change: 1 addition & 0 deletions docs/api.md
Expand Up @@ -52,6 +52,7 @@ Fetch a URL and parse the response into a valid VAST object.
* `String` *response* – A VAST XML document. When *response* is provided, no Ajax request is made and thus the *url* parameter is ignored.
* `Object` *urlhandler* – A URL handler module, used to fetch the VAST document instead of the [default ones](https://github.com/dailymotion/vast-client-js/tree/master/src/urlhandlers).
* `Boolean` *withCredentials* – A boolean to enable the *withCredentials* options for the XHR and FLASH URLHandlers.
* `Number` *wrapperLimit* – A number of available *Wrapper* responses that can be received with no InLine response.

* `Function` *done* – Method to be called once the VAST document is parsed. The VAST JS object is passed as the 1st parameter. If null, an error is provided as a 2nd parameter.

Expand Down
10 changes: 5 additions & 5 deletions src/parser.coffee
Expand Up @@ -76,7 +76,7 @@ class VASTParser
# VAST version of response not supported.
@track(response.errorURLTemplates, ERRORCODE: 101)

complete = (errorAlreadyRaised = false) =>
complete = (error = null, errorAlreadyRaised = false) =>
return unless response
noCreatives = true
for ad in response.ads
Expand All @@ -91,19 +91,19 @@ class VASTParser
@track(response.errorURLTemplates, ERRORCODE: 303) unless errorAlreadyRaised
if response.ads.length == 0
response = null
cb(null, response)
cb(error, response)

loopIndex = response.ads.length
while loopIndex--
ad = response.ads[loopIndex]
continue unless ad.nextWrapperURL?
do (ad) =>
if parentURLs.length >= 10 or ad.nextWrapperURL in parentURLs
if parentURLs.length > (if options.wrapperLimit != null then options.wrapperLimit else 9) or ad.nextWrapperURL in parentURLs
# Wrapper limit reached, as defined by the video player.
# Too many Wrapper responses have been received with no InLine response.
@track(ad.errorURLTemplates, ERRORCODE: 302)
response.ads.splice(response.ads.indexOf(ad), 1)
complete()
complete(new Error("Wrapper limit reached, as defined by the video player"))
return

if ad.nextWrapperURL.indexOf('//') == 0
Expand Down Expand Up @@ -162,7 +162,7 @@ class VASTParser
response.ads.splice ++index, 0, wrappedAd

delete ad.nextWrapperURL
complete errorAlreadyRaised
complete err, errorAlreadyRaised

complete()

Expand Down

0 comments on commit 6941173

Please sign in to comment.