Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrapper limit handling #157

Merged
merged 2 commits into from
Jan 30, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/api.md
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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