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

Modularization #458

Merged
merged 97 commits into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
97 commits
Select commit Hold shift + click to select a range
c61c0b3
[tools] modification of the rollup configuration
Jun 23, 2023
b2f40c4
[parser] Removing fectchVAST and getAndParseVAST methods from the vas…
Jun 23, 2023
6a73db8
adding new Fetcher class including the fetchVAST method
Jun 23, 2023
2acf7da
[client] changing get method to use fetchVAST method from the Fetcher…
Jun 23, 2023
6ec4bce
adding supported browsers list, modification of the entry point, and …
Jun 23, 2023
4d360bc
[parser] removing unnecessary comments
Jun 23, 2023
7e6f9f7
[client] add parseVAST method to be able to perform fetching from a g…
Jul 20, 2023
06f729a
[test] tests for the modularization
Jul 26, 2023
3d303d6
[test] moving mocha tests to jest
Aug 17, 2023
f6229fb
removing mocha command from package.json
Aug 17, 2023
8ccc8d5
[tools] Removing mocha
Aug 25, 2023
3c23daf
Removing unnecessary comment
Aug 25, 2023
f169bc5
[parser] checking Inline first to prevent VASTAdTagURI to be in the f…
Aug 29, 2023
f5a5575
[client] rootURL should be set when the first VAST is fetch
Aug 29, 2023
06be203
[tools] updating rollup config since there is no need to have one bun…
Aug 30, 2023
be2907f
[docs] WIP/modifying documentations for modularization
Aug 31, 2023
2c665d2
[docs] WIP/ updating documentations
Aug 31, 2023
41ae3a7
[docs] removing unnecessary documentation
Aug 31, 2023
33c34ef
[docs] updating docs
Aug 31, 2023
ae5f7ce
[docs] updating documentations
Sep 1, 2023
5f7ade1
[docs] updating README
Sep 1, 2023
a26ab51
[docs] updating README
Sep 4, 2023
fb4830c
[docs] updating readme
Sep 4, 2023
9cd9f7b
[test] updating vast version in tests files
Sep 12, 2023
5409cb6
[test] updating tests
Sep 12, 2023
33e0e79
[client] updating get method
Sep 12, 2023
1dbcc80
[parser] updating fetchingCallback
Sep 12, 2023
0ca5915
[tools] adding new command including --watch
Sep 12, 2023
a129967
[tools] replacing functions by arrow functions
Sep 12, 2023
f49be0c
[docs] updating documentations
Sep 12, 2023
8a43120
updating fetchVAST method
Sep 12, 2023
a54fc76
[test] removing console.log
Sep 12, 2023
7a1b823
[tests] removing unnecessary files related to mocha
Sep 12, 2023
4c31d60
minor code update
Sep 13, 2023
2b2869f
modifying fetchVAST jsdoc
Oct 4, 2023
ab8dba0
[test] removing duplicate complete key
Oct 4, 2023
a8bd502
[test] removing unused variables
Oct 4, 2023
74b3e1c
[doc] updating documentation
Oct 4, 2023
b41edc3
[test] correcting typo error
Oct 4, 2023
531ad8a
[docs] updating documentations
Oct 6, 2023
24b2c68
fix typo and update formatting
Oct 6, 2023
b68037b
[client] Pass fetcher as argument of VASTParser
Nov 6, 2023
c8b4f2c
[parser] add fetcher in the constructor
Nov 6, 2023
04c582f
updated comments and variables names
Nov 6, 2023
56ecbcc
[test] update tests cases
Nov 6, 2023
11e0876
minor code update
Nov 7, 2023
83f5464
remove unnecessary file in dist folder
Nov 7, 2023
83fae5b
wip/upgrating urlhandler
Sep 8, 2023
78eb751
[tools] modifying rollup configuration for node
Sep 13, 2023
554792c
upgrade urlhandler from XMLHttpRequest to fetch
Sep 13, 2023
fa2fe1e
[test] updating tests for new fetching method
Sep 13, 2023
5964765
removing file related to node urlhandler and modifications for new ur…
Sep 18, 2023
4b7f2a6
[test] modifying tests for new urlHandler
Sep 18, 2023
03d2545
[tools] removing unused import
Sep 18, 2023
0d1786b
[test] correcting vast sample and test
Sep 19, 2023
3822db7
fixing error handling
Sep 25, 2023
63cdae9
[test] fixing failing test
Oct 4, 2023
f6bd002
[test] fix inconsistent test
Oct 5, 2023
d2e9bde
[parser] Improving code readability
Sep 22, 2023
d62cde2
[parser] fix unparsed VerificationParameters
Oct 5, 2023
be09e55
[client] refactor constructor default values
Oct 5, 2023
a3a74d2
[test] adding tests for new error logs
Oct 4, 2023
817a8ac
[tracker] adding error logs in public methods
Oct 4, 2023
d65171d
[util] filtering url to return arrays of valid and unvalid url
Oct 4, 2023
412b1ef
[parser] adding error logs in case Wrapper or InLine node is malformed
Oct 4, 2023
3112014
[test] adding blockedAdCategories node to a sample file
Oct 4, 2023
e6b6354
fix bug where wrapper where not parsed if creatives node was missing …
Jan 24, 2024
af7bcc0
correct typos errors
Jan 25, 2024
c594041
adding raw xml to the object returned by the urlhandler
Jan 25, 2024
bf0e460
[test] fix inconsistent test
Jan 26, 2024
d470fd7
[test] fix comments related to tests
Mar 18, 2024
c359cad
[parser] fix comments related to the vastparser
Mar 18, 2024
904e794
create folder for fetching related file
Mar 18, 2024
49f2e8a
[tracker] fix comments related to vasttracker
Mar 18, 2024
c51abd4
[utils] add two utils function to check browser environment and forma…
Mar 18, 2024
b3b6822
[client] fix import
Mar 18, 2024
074067e
[doc] add doc for new error tracking
Mar 18, 2024
cf254d2
[tool] fix rollup configuration to handle dynamic imports and fix get…
Mar 18, 2024
bbd2fc4
[parser] fix comments related to parseWrapper function
Mar 18, 2024
fefb556
fix comments
Mar 22, 2024
89a6b39
add a full example with a player using the vast-client
Apr 9, 2024
cb49bb5
adding package.json
Apr 9, 2024
4d343b7
update readme + VAST url
Apr 9, 2024
0ce2697
fix comments
Apr 12, 2024
70dfd51
removing safe operator for codesandbox compatibility
Apr 12, 2024
918c7d3
Update README.md
Rapha0511 Apr 12, 2024
ba5bcd8
Merge pull request #467 from dailymotion/adding-error-logs
ZacharieTFR Apr 25, 2024
4bc57ca
fix lint and comments
Apr 26, 2024
1754223
fix comments
Apr 26, 2024
1381daf
changing fetchVAST method to async
May 6, 2024
f3b596c
fix lint
May 6, 2024
955ab7a
correct html , add h1, title and alt text for the image
May 6, 2024
c5f03f0
fix typo
Rapha0511 May 6, 2024
8adf88f
play event refactorization
May 28, 2024
feec407
add package-lock and modify gitignore
May 28, 2024
fe7172c
Merge pull request #470 from dailymotion/adding-vast-client-use-case-…
Rapha0511 Jun 27, 2024
c1c8b42
fix lint in examples/utils.js
Jun 27, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@
node_modules/*
npm-debug.log
dist_old
examples/node_modules/*
examples/.parcel-cache/*
examples/dist/*
39 changes: 30 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ This library provides three components:
For the full API documentation go [here](#api).
For the full Class reference go [here](https://github.com/dailymotion/vast-client-js/blob/master/docs/api/class-reference.md)

Complies with the [VAST 4.2 specification](https://iabtechlab.com/wp-content/uploads/2019/06/VAST_4.2_final_june26.pdf) provided by the [Interactive Advertising Bureau (IAB)](https://www.iab.com/).
To explore a practical example of how the vast client can be implemented, please visit this [link](https://githubbox.com/dailymotion/vast-client-js/tree/master/examples).

Complies with the [VAST 4.3 specification](https://iabtechlab.com/wp-content/uploads/2022/09/VAST_4.3.pdf) provided by the [Interactive Advertising Bureau (IAB)](https://www.iab.com/).

## Get Started

Expand All @@ -29,7 +31,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'
Expand All @@ -47,9 +49,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'
Expand Down Expand Up @@ -110,18 +128,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.
To use it, either host it on your CDN or locally in your project. If you're using a script tag make sure to set the type property to module like below.

_your index.html_
```html
<script src="vast-client-browser.min.js"></script>
<script type="module" src="your-main-file.js"></script>
```

_main.js_
```javascript
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
Expand Down
6 changes: 4 additions & 2 deletions bundle_size.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
const fs = require('fs');
const path = require('path');

const newDistPath = './dist';
const oldDistPath = './dist_old';

const getFileSizes = (folderPath) => {
return fs.readdirSync(folderPath).reduce((res, fileName) => {
res[fileName] = fs.readFileSync(path.join(folderPath, fileName)).byteLength;
const stats = fs.statSync(`${folderPath}/${fileName}`);
if (stats.isFile()) {
res[fileName] = stats.size;
}
return res;
}, {});
};
Expand Down
1 change: 0 additions & 1 deletion dist/vast-client-browser.min.js

This file was deleted.

127 changes: 126 additions & 1 deletion docs/api/vast-client.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# VASTClient

The `VASTClient` class provides a client to manage the fetching and parsing of VAST documents.
The `VASTClient` class provides a client to manage the fetching and parsing of VAST documents. It provides methods for fetching VAST resources by resolving the wrapper chain (recursive fetching and parsing) by using the `VASTParser` parsing methods.

- [Constructor](#constructor)
- [Properties](#properties)
Expand Down Expand Up @@ -147,6 +147,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

Expand Down Expand Up @@ -304,3 +360,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
*/
```

### removeLastURLTemplateFilter()

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
```
Loading
Loading