Skip to content

Commit

Permalink
10.0.0
Browse files Browse the repository at this point in the history
- replaced the old event system for rmp-vast API (addEventListener/removeEventListener on player container with DOM events) with a new custom one that includes on, off and one methods to register/unregister events on rmp-vast instance (breaking change)
- fixes an issue with retrieval of companion ads in certain formats
- ran test and updates dependencies
  • Loading branch information
radiantmediaplayer committed Feb 27, 2023
1 parent 8262505 commit ef68371
Show file tree
Hide file tree
Showing 73 changed files with 1,910 additions and 955 deletions.
52 changes: 43 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -266,17 +266,51 @@ If you do not want to call `loadAds()` method directly - call `initialize()` met
### API events
rmp-vast will fire VAST-related events on the player container as they occur. It will also ping VAST trackers when needed but this section refers to events emitted by rmp-vast and that can be hooked to with JavaScript.
rmp-vast will fire VAST-related events on the rmp-vast instance as they occur. Events are registered with the `on` method applied to the rmp-vast instance (`rmpVast` as shown above). They are unregistered with the `off` method. Example:
Events are registered and unregistered with the addEventListener and removeEventListener JavaScript methods set on the player container. Example:
```javascript
const rmpVast = new RmpVast(id, params);
rmpVast.on('adloaded', callbackA);
rmpVast.loadAds(adTag);
```
You can register multiple events for the same callback, example:
```javascript
const id = 'rmp';
const container = document.getElementById(id);
...
container.addEventListener('adloaded', function() {
console.log('adloaded event');
});
const rmpVast = new RmpVast(id, params);
rmpVast.on('adloaded adstarted', callbackA);
rmpVast.loadAds(adTag);
```
You can access the name of the event being fired:
```javascript
function callbackA (event) {
console.log(event.type); // name of the event being fired
}
const rmpVast = new RmpVast(id, params);
rmpVast.on('adloaded adstarted adclick', callbackA);
rmpVast.loadAds(adTag);
```
You can unregister an event with the off method:
```javascript
rmpVast.off('adloaded', callbackA);
```
You can unregister multiple events for the same callback as well:
```javascript
rmpVast.off('adloaded adstarted adclick', callbackA);
```
You can also register an event where the callback is only executed once:
```javascript
const rmpVast = new RmpVast(id, params);
rmpVast.one('adloaded', callbackA);
rmpVast.loadAds(adTag);
```
Available events are:
Expand Down Expand Up @@ -444,7 +478,7 @@ Not all fields may be available, so check availability before usage.
- `getCompanionAd(index: Number)`: return `HTMLElement|null` representing the companion ad. It takes a `Number` index parameter which represents the index of the wanted companion ad in the Array returned from `getCompanionAdsList` method. This method automates the required pinging for companion ads. Usage example:
```javascript
container.addEventListener("adstarted", function () {
rmpVast.on("adstarted", function () {
// we need to call getCompanionAdsList BEFORE calling getCompanionAd so that
// rmp-vast can first create a collection of available companion ads based on getCompanionAdsList
// input parameters
Expand Down
11 changes: 2 additions & 9 deletions app/dev.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,10 @@
//var ADTAG = 'https://raw.githubusercontent.com/InteractiveAdvertisingBureau/VAST_Samples/master/VAST%204.2%20Samples/Inline_Linear_Tag-test.xml';
//ADTAG = 'https://www.radiantmediaplayer.com/vast/tags/vpaid-3-js-linear.xml';
//ADTAG = 'https://pubads.g.doubleclick.net/gampad/ads?iu=/21775744923/external/single_ad_samples&sz=640x480&cust_params=sample_ct%3Dlinearvpaid2js&ciu_szs=300x250%2C728x90&gdfp_req=1&output=vast&unviewed_position_start=1&env=vp&impl=s&correlator=' + Date.now();
ADTAG = 'https://www.radiantmediaplayer.com/vast/tags/inline-linear-all-kind-trackers.xml';
ADTAG = 'https://www.radiantmediaplayer.com/vast/tags/inline-linear-companion-html.xml';
/*ADTAG = 'https://pubads.g.doubleclick.net/gampad/ads?sz=640x480&iu=/124319096/external/single_ad_samples&ciu_szs=300x250&impl=s&gdfp_req=1&env=vp&output=vast&unviewed_position_start=1&cust_params=deployment%3Ddevsite%26sample_ct%3Dlinear&correlator=' + Date.now();
ADTAG = 'https://playertest.longtailvideo.com/vast-30s-ad.xml';*/
var rmpVast = new RmpVast(id, { showControlsForVastPlayer: true, forceUseContentPlayerForAds: true });
var rmpVast = new RmpVast(id, { showControlsForVastPlayer: true });
rmpVast.loadAds(ADTAG);
/*container.addEventListener('adstarted', function () {
setInterval(() => {
console.log(rmpVast.getAdDuration());
console.log(rmpVast.getAdCurrentTime());
console.log(rmpVast.getAdRemainingTime());
}, 1000);
});*/
</script>
</body>
4 changes: 2 additions & 2 deletions app/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -333,11 +333,11 @@ const _wireUI = function () {
}
};
for (let j = 0, lenJ = events.length; j < lenJ; j++) {
container.addEventListener(events[j], _logEvent);
rmpVast.on(events[j], _logEvent);
}

// companion ad
container.addEventListener('adstarted', function () {
rmpVast.on('adstarted', function () {
const companionId = document.getElementById('companion-ad');
companionId.innerHTML = '';
const list = rmpVast.getCompanionAdsList();
Expand Down
Loading

0 comments on commit ef68371

Please sign in to comment.