-
Notifications
You must be signed in to change notification settings - Fork 217
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
Modularization #458
Modularization #458
Changes from 34 commits
c61c0b3
b2f40c4
6a73db8
2acf7da
6ec4bce
4d360bc
7e6f9f7
06f729a
3d303d6
f6229fb
8ccc8d5
3c23daf
f169bc5
f5a5575
06be203
be2907f
2c665d2
41ae3a7
33c34ef
ae5f7ce
5f7ade1
a26ab51
fb4830c
9cd9f7b
5409cb6
33e0e79
1dbcc80
0ca5915
a129967
f49be0c
8a43120
a54fc76
7a1b823
4c31d60
2b2869f
ab8dba0
a8bd502
74b3e1c
b41edc3
531ad8a
24b2c68
b68037b
c8b4f2c
04c582f
56ecbcc
11e0876
83f5464
83fae5b
78eb751
554792c
fa2fe1e
5964765
4b7f2a6
03d2545
0d1786b
3822db7
63cdae9
f6bd002
d2e9bde
d62cde2
be09e55
a3a74d2
817a8ac
d65171d
412b1ef
3112014
e6b6354
af7bcc0
c594041
bf0e460
d470fd7
c359cad
904e794
49f2e8a
c51abd4
b3b6822
074067e
cf254d2
bbd2fc4
fefb556
89a6b39
cb49bb5
4d343b7
0ce2697
70dfd51
918c7d3
ba5bcd8
4bc57ca
1754223
1381daf
f3b596c
955ab7a
c5f03f0
8adf88f
feec407
fe7172c
c1c8b42
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -29,7 +29,7 @@ Then import the components you need. | |||||||||
|
||||||||||
### VASTClient | ||||||||||
|
||||||||||
If you need to fetch and parse VAST documents, you can use the **VASTClient**: | ||||||||||
If you need to fetch and parse VAST documents, you can use the `get` method from the **VASTClient**: | ||||||||||
|
||||||||||
```javascript | ||||||||||
import { VASTClient } from '@dailymotion/vast-client' | ||||||||||
|
@@ -47,9 +47,25 @@ vastClient.get('https://www.examplevast.com/vast.xml') | |||||||||
|
||||||||||
In addition to fetching and parsing a VAST resource, **VASTClient** provides options to filter a sequence of calls based on count and time of execution, together with the possibility to track URLs using **VASTTracker**. | ||||||||||
|
||||||||||
If you need to directly parse a VAST XML and also follow any wrappers chain, you can use the `parseVAST` method from the **VASTClient** : | ||||||||||
|
||||||||||
```javascript | ||||||||||
import { VASTClient } from '@dailymotion/vast-client' | ||||||||||
|
||||||||||
const vastClient = new VASTClient(); | ||||||||||
|
||||||||||
vastClient.parseVAST(vastXml) | ||||||||||
.then(parsedVAST => { | ||||||||||
// Do something with the parsed VAST response | ||||||||||
}) | ||||||||||
.catch(err => { | ||||||||||
// Deal with the error | ||||||||||
}); | ||||||||||
``` | ||||||||||
### VASTParser | ||||||||||
|
||||||||||
To directly parse a VAST XML you can use the **VASTParser**: | ||||||||||
The **VASTParser** will make no fetching, the final response will only contain the first VAST encountered. | ||||||||||
|
||||||||||
```Javascript | ||||||||||
import { VASTParser } from '@dailymotion/vast-client' | ||||||||||
|
@@ -110,18 +126,21 @@ const vastTracker = new VASTTracker(); | |||||||||
|
||||||||||
#### Browser script | ||||||||||
|
||||||||||
A pre-bundled version of VAST Client JS is available: [`vast-client-browser.min.js`](dist/vast-client-browser.min.js) [minified]. | ||||||||||
A pre-bundled version of VAST Client JS is available: [`vast-client.min.js`](dist/vast-client.min.js) [minified]. | ||||||||||
|
||||||||||
You can add the script directly to your page and access the library's components through the `VAST` object. | ||||||||||
If you want to use this file, download it place it your project at your prefered location. | ||||||||||
Then, make sure that your main file is in type module as below. | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
|
||||||||||
```html | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
<script src="vast-client-browser.min.js"></script> | ||||||||||
<script type="module" src="your-main-file.js"></script> | ||||||||||
``` | ||||||||||
|
||||||||||
```javascript | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
const vastClient = new VAST.VASTClient(); | ||||||||||
const vastParser = new VAST.VASTParser(); | ||||||||||
const vastTracker = new VAST.VASTTracker(); | ||||||||||
import {VASTClient, VASTParser, VASTTracker} from "vast-client.min.js" | ||||||||||
|
||||||||||
const vastClient = new VASTClient(); | ||||||||||
const vastParser = new VASTParser(); | ||||||||||
const vastTracker = new VASTTracker(); | ||||||||||
``` | ||||||||||
|
||||||||||
#### Node | ||||||||||
|
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -2,6 +2,8 @@ | |||||||||
|
||||||||||
The `VASTClient` class provides a client to manage the fetching and parsing of VAST documents. | ||||||||||
|
||||||||||
`VASTClient` provides a methods to fetch a VAST resource because of his ability to resolving the wrapper chain (recursive fetch and parse) by using the `VASTParser` parsing methods. | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
|
||||||||||
- [Constructor](#constructor) | ||||||||||
- [Properties](#properties) | ||||||||||
- [Methods](#methods) | ||||||||||
|
@@ -147,6 +149,62 @@ vastClient.get('http://example.dailymotion.com/vast.xml', options) | |||||||||
// Deal with the error | ||||||||||
}); | ||||||||||
``` | ||||||||||
### parseVAST(vastXml, options)<a name="parse"></a> | ||||||||||
|
||||||||||
Parses the given xml Object into a [VASTResponse](https://github.com/dailymotion/vast-client-js/blob/master/docs/api/class-reference.md#vastresponse). | ||||||||||
Returns a `Promise` which either resolves with the fully parsed `VASTResponse` or rejects with an `Error`. | ||||||||||
|
||||||||||
By using this method, you will be able to perform fetching in case you want to parse a VAST document and follow a wrappers chain. | ||||||||||
If you just need to parse an inline VAST or you want to parse the first VAST document encountered, you should use the **parseVAST** method from the **VASTParser**. | ||||||||||
|
||||||||||
#### Parameters | ||||||||||
|
||||||||||
- **`vastXml: Object`** - An object representing an xml document | ||||||||||
- **`options: Object`** - An optional Object of parameters to be used in the parsing process | ||||||||||
- `timeout: Number` - A custom timeout for the possible wrapper resolving requests (default `120000`) | ||||||||||
- `withCredentials: Boolean` - A boolean to enable the withCredentials options for the XHR URLHandler (default `false`) | ||||||||||
- `wrapperLimit: Number` - A number of Wrapper responses that can be received with no InLine response (default `10`) | ||||||||||
- `urlHandler: URLHandler` - Custom urlhandler to be used instead of the default ones [`urlhandlers`](../../src/urlhandlers) | ||||||||||
- `urlhandler: URLHandler` - Fulfills the same purpose as `urlHandler`, which is the preferred parameter to use | ||||||||||
- `allowMultipleAds: Boolean` - A boolean value that identifies whether multiple ads are allowed in the requested VAST response. This will override any value of allowMultipleAds attribute set in the VAST | ||||||||||
- `followAdditionalWrappers: Boolean` - A boolean value that identifies whether subsequent Wrappers after a requested VAST response is allowed. This will override any value of followAdditionalWrappers attribute set in the VAST | ||||||||||
- `requestDuration: Number` - The fetching time of the XML in ms. Provide it with byteLength to have a more accurate estimated bitrate. | ||||||||||
- `byteLength: Number`- The size of the request in bytes. Provide it with requestDuration to have a more accurate estimated bitrate. | ||||||||||
|
||||||||||
#### Events emitted | ||||||||||
|
||||||||||
- **`VAST-resolved`** | ||||||||||
- **`VAST-resolving`** | ||||||||||
- **`VAST-warning`** | ||||||||||
|
||||||||||
#### Example | ||||||||||
|
||||||||||
```Javascript | ||||||||||
const vastXml = (new window.DOMParser()).parseFromString(xmlStr, "text/xml"); | ||||||||||
|
||||||||||
vastParser.parseVAST(vastXml) | ||||||||||
.then(res => { | ||||||||||
// Do something with the parsed VAST response | ||||||||||
}) | ||||||||||
.catch(err => { | ||||||||||
// Deal with the error | ||||||||||
}); | ||||||||||
|
||||||||||
// Or with some options | ||||||||||
const options = { | ||||||||||
timeout: 5000, | ||||||||||
withCredentials: true, | ||||||||||
wrapperLimit: 7 | ||||||||||
} | ||||||||||
vastParser.parseVAST(vastXml, options) | ||||||||||
.then(res => { | ||||||||||
// Do something with the parsed VAST response | ||||||||||
}) | ||||||||||
.catch(err => { | ||||||||||
// Deal with the error | ||||||||||
}); | ||||||||||
``` | ||||||||||
|
||||||||||
|
||||||||||
#### How does resolveAll work | ||||||||||
|
||||||||||
|
@@ -304,3 +362,72 @@ const vastParser = vastClient.getParser(); | |||||||||
// Clear the url template filters used | ||||||||||
vastParser.clearUrlTemplateFilters(); | ||||||||||
``` | ||||||||||
|
||||||||||
### addURLTemplateFilter(filter) | ||||||||||
|
||||||||||
Adds a filter function to the array of filters which are called before fetching a VAST document. | ||||||||||
|
||||||||||
#### Parameters | ||||||||||
|
||||||||||
- **`filter: function`** - The filter function to be added at the end of the array | ||||||||||
|
||||||||||
#### Example | ||||||||||
|
||||||||||
```Javascript | ||||||||||
vastClient.addURLTemplateFilter( vastUrl => { | ||||||||||
return url.replace('[DOMAIN]', 'mywebsite.com') | ||||||||||
}); | ||||||||||
|
||||||||||
/* | ||||||||||
For a VASTAdTagURI defined as : | ||||||||||
<VASTAdTagURI>http://example.dailymotion.com/vast.php?domain=[DOMAIN]</VASTAdTagURI> | ||||||||||
HTTP request will be: | ||||||||||
http://example.dailymotion.com/vast.php?domain=mywebsite.com | ||||||||||
*/ | ||||||||||
``` | ||||||||||
|
||||||||||
### removeURLTemplateFilter() | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As it has been replaced with removeLastURLTemplateFilter you need to update it aswell |
||||||||||
|
||||||||||
Removes the last element of the url templates filters array. | ||||||||||
|
||||||||||
#### Example | ||||||||||
|
||||||||||
```Javascript | ||||||||||
const replaceDomain = () => { | ||||||||||
return url.replace('[DOMAIN]', 'mywebsite.com') | ||||||||||
}; | ||||||||||
|
||||||||||
vastClient.addURLTemplateFilter(replaceDomain); | ||||||||||
// ... | ||||||||||
vastClient.removeURLTemplateFilter(replaceDomain); | ||||||||||
// [DOMAIN] placeholder is no longer replaced | ||||||||||
``` | ||||||||||
### countURLTemplateFilters() | ||||||||||
|
||||||||||
Returns the number of filters of the url templates filters array. | ||||||||||
|
||||||||||
#### Example | ||||||||||
|
||||||||||
```Javascript | ||||||||||
vastClient.addURLTemplateFilter( vastUrl => { | ||||||||||
return url.replace('[DOMAIN]', 'mywebsite.com') | ||||||||||
}); | ||||||||||
|
||||||||||
vastClient.countUrlTemplateFilters(); | ||||||||||
// returns 1 | ||||||||||
``` | ||||||||||
|
||||||||||
### clearURLTemplateFilters() | ||||||||||
|
||||||||||
Removes all the filter functions from the url templates filters array. | ||||||||||
|
||||||||||
#### Example | ||||||||||
|
||||||||||
```Javascript | ||||||||||
vastClient.addURLTemplateFilter( vastUrl => { | ||||||||||
return url.replace('[DOMAIN]', 'mywebsite.com') | ||||||||||
}); | ||||||||||
|
||||||||||
vastClient.clearUrlTemplateFilters(); | ||||||||||
// [DOMAIN] placeholder is no longer replaced | ||||||||||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.