Skip to content

Commit f764c82

Browse files
author
Olivier Poitrey
committed
Initial Revision
0 parents  commit f764c82

21 files changed

+713
-0
lines changed

.travis

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
nguage: node_js
2+
node_js:
3+
- 0.8

LICENSE

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Copyright (c) 2013 Olivier Poitrey <[email protected]>
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is furnished
8+
to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in all
11+
copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+
THE SOFTWARE.
20+

README.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# VAST Javascript Client
2+
3+
## Usage
4+
5+
``` javascript
6+
DMVASTClient.get(VASTURL, function(response)
7+
{
8+
if (response)
9+
{
10+
for (var adIdx = 0, adLen = VASTResponse.ads.length; adIdx < adLen; adIdx++)
11+
{
12+
var ad = VASTResponse.ads[adIdx];
13+
for (var creaIdx = 0, creaLen = ad.creatives.length; creaIdx < creaLen; creaIdx++)
14+
{
15+
var linearCreative = ad.creatives[creaIdx];
16+
if (linearCreative.type != "linear") continue;
17+
18+
for (var mfIdx = 0, mfLen = linearCreative.mediaFiles.length; mfIdx < mfLen; mfIdx++)
19+
{
20+
var mediaFile = linearCreative.mediaFiles[mfIdx];
21+
if (mediaFile.mimeType != "video/mp4") continue;
22+
23+
player.vastTracker = new DMVASTTracker(ad, linearCreative);
24+
player.vastTracker.on('clickthrough', function(url)
25+
{
26+
document.location.href = url;
27+
});
28+
player.on('canplay', function() {self.vastTracker.load();});
29+
player.on('timeupdate', function() {self.vastTracker.setProgress(self.currentTime);});
30+
player.on('play', function() {self.vastTracker.setPaused(false);});
31+
player.on('pause', function() {self.vastTracker.setPaused(true);});
32+
33+
player.video.href = mediaFile.fileURL;
34+
// put player in ad mode
35+
break;
36+
}
37+
38+
if (player.vastTracker)
39+
{
40+
break;
41+
}
42+
}
43+
44+
if (player.vastTracker)
45+
{
46+
break;
47+
}
48+
else
49+
{
50+
// Inform ad server we can't find suitable media file for this ad
51+
DMVASTUtil.track(ad.errorURLTemplates, {ERRORCODE: 403});
52+
}
53+
}
54+
}
55+
56+
if (!self.vastTracker)
57+
{
58+
// No pre-roll, start video
59+
}
60+
61+
});
62+
```

package.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"name": "vast-client-js",
3+
"author": "Olivier Poitrey <[email protected]>",
4+
"version": "0.0.1",
5+
"description": "Javascript VAST Client",
6+
"keywords": ["vast", "ad", "advertising", "iab", "in-stream", "video"],
7+
"repository": {"type": "git", "url": "https://github.com/rs/vast-client-js"},
8+
"licenses": [{"type": "MIT", "url": "https://github.com/rs/vast-client-js/raw/master/LICENSE"}],
9+
"engines": {"node": "~0.8.19"},
10+
"scripts":
11+
{
12+
"test": "mocha --compilers coffee:coffee-script --reporter spec test/*.coffee",
13+
"bundle": "browserify -c 'coffee -scb' src/client.coffee src/tracker.coffee -o vast-client.js"
14+
},
15+
"devDependencies":
16+
{
17+
"mocha": "*",
18+
"should": "*",
19+
"xmldom": "*"
20+
},
21+
"dependencies":
22+
{
23+
"coffee-script": "~1.2.0",
24+
"browserify": "*"
25+
}
26+
}

src/ad.coffee

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
class VASTAd
2+
constructor: ->
3+
@errorURLTemplates = []
4+
@impressionURLTemplates = []
5+
@creatives = []
6+
7+
module.exports = VASTAd

src/client.coffee

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
VASTParser = require './parser.coffee'
2+
3+
class VASTClient
4+
@totalCalls: 0 # TODO: make this persistent across requests
5+
@cappingFreeLunch: 0
6+
@cappingMinimumTimeInterval: 0
7+
@timeout: 0
8+
9+
@get: (url, cb) ->
10+
# TODO handle timeout
11+
@totalCalls++
12+
13+
if @cappingFreeLunch >= @totalCalls
14+
cb(null)
15+
return
16+
17+
if new Date().getTime() - @lastSuccessfulAd < @cappingMinimumTimeInterval
18+
cb(null)
19+
return
20+
21+
VASTParser.get url, (response) ->
22+
@lastSuccessfulAd = new Date().getTime() # TODO: make this persistent across requests
23+
cb(response)
24+
25+
module.export = VASTClient
26+
27+
if window?
28+
window.DMVASTClient = VASTClient

src/creative.coffee

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
class VASTCreative
2+
constructor: ->
3+
@trackingEvents = []
4+
5+
class VASTCreativeLinear extends VASTCreative
6+
constructor: ->
7+
super
8+
@type = "linear"
9+
@duration = 0
10+
@skipDelay = -1
11+
@mediaFiles = []
12+
@videoClickThroughURLTemplate = null
13+
@videoClickTrackingURLTemplate = null
14+
15+
class VASTCreativeNonLinear extends VASTCreative
16+
17+
18+
class VASTCreativeCompanion extends VASTCreative
19+
20+
module.exports =
21+
VASTCreativeLinear: VASTCreativeLinear
22+
VASTCreativeNonLinear: VASTCreativeNonLinear
23+
VASTCreativeCompanion: VASTCreativeCompanion

src/mediafile.coffee

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class VASTMediaFile
2+
constructor: ->
3+
@fileURL = null
4+
@deliveryType = "progressive"
5+
@mimeType = null
6+
@codec = null
7+
@bitrate = 0
8+
@minBitrate = 0
9+
@maxBitrate = 0
10+
@width = 0
11+
@height = 0
12+
13+
module.exports = VASTMediaFile

0 commit comments

Comments
 (0)