radiantmediaplayer / rmp-vast

A client-side JavaScript solution to load, parse and display VAST 2, 3 & 4 resources with HTML5 video
https://www.radiantmediaplayer.com/rmp-vast/app/
Other
95 stars 37 forks source link
ads advertisement html5 javascript outstream-video-ads vast vast-player video

rmp-vast

A client-side JavaScript solution to load, parse, ping and display VAST resources (advertising).

It aims at implementing the IAB VAST specification for web-based environments - e.g. browser, WebView (Ionic, Flutter, Cordova, Electron ...) & smart TV - where both HTML5 video and JavaScript are available. We support VAST 3 and VAST 4 up to VAST 4.3. VAST 2 support has been deprecated with rmp-vast 15 and we no longer test for VAST 2 tags.

rmp-vast comes as a compiled library (./dist/ folder) but it can also be imported as a ES2015 module.

rmp-vast makes use of vast-client-js for fetching and parsing VAST XML resources.

rmp-vast is used and maintained by Radiant Media Player.

Documentation sections

Quick start guide

First download latest rmp-vast package from the release tab.

You must use rmp-vast in a well-formed HTML document. This means a web-page with a valid HTML5 DOCTYPE and other elements that are commonly available in today's web.

<script src="https://github.com/radiantmediaplayer/rmp-vast/raw/master/dist/rmp-vast.min.js">
<div class="rmp-container" id="vast-player">
  <div class="rmp-content">
    <video
      class="rmp-video"
      src="https://www.rmp-streaming.com/media/big-buck-bunny-360p.mp4"
      playsinline
      muted
      controls
    ></video>
  </div>
</div>

Do NOT rename CSS classes or alter this HTML layout. The HTML5 video tag used for content must use the src property on the HTML5 video (e.g. do not use <source> tag).

// our VAST tag to be displayed
const adTag =
  "https://www.radiantmediaplayer.com/vast/tags/inline-linear-1.xml";
const id = "vast-player";
const params = {
  ajaxTimeout: 5000,
  maxNumRedirects: 10,
};
// create RmpVast instance
const rmpVast = new RmpVast(id, params);
// call loadAds - this will start the ad loading process, display the ad and resume content automatically
// in this case we use autoplay
rmpVast.loadAds(adTag);

// or if autoplay is not wanted the call to loadAds must be the result
// of a user interaction (click, touchend ...)
// playButton.addEventListener('click', function() {
//   rmpVast.loadAds(adTag);
// });

A complete implementation example is provided in app/index.html. You should look at app/js/app.js. This example can be found live at https://www.radiantmediaplayer.com/rmp-vast/app/.

Alternatively, you may also create a RmpVast instance while passing a reference to the player container. This can come in handy for some web frameworks. Note that the element must be an instanceof HTMLElement.

// We already have a reference to the player container (e.g. element with "rmp-container" class)
const element = this.element;
// create RmpVast instance
const rmpVast = new RmpVast(element, params);

Back to documentation sections

Supported VAST features

We support VAST standard up to VAST 4.3, this includes:

Currently unsupported features

Back to documentation sections

Supported environments

rmp-vast compiled library (./dist/rmp-vast.min.js)

Browsers

Desktop means Windows 7+, macOS 10.11+, Linux (latest LTS Ubuntu).

WebViews (Ionic, Flutter, Cordova, WebView created from native code)

With the announcement of Apple in december 2019, to remove support for UIWebView API by end 2020, we only support WKWebView API for iOS apps built with Ionic, Flutter, Cordova or WebView created from native code. See this blog post to help you update to WKWebView API.

For Flutter apps we support using rmp-vast with webview_flutter plugin. See a guide for adding WebView to your Flutter app here.

Smart TV & OTT (Native web, Cordova or WebView created from native code)

Back to documentation sections

CORS requirements

rmp-vast uses JavaScript XMLHttpRequests to load VAST tags. Hence proper CORS configuration is required on your ad-server in order for rmp-vast to be able to retrieve VAST tags. Refer to this Google documentation for more information.

Back to documentation sections

Video ads from Google Ads network and rmp-vast

When serving ads from Google Ads network (DFP, ADX, AdSense for Video) we recommend using Google IMA HTML5 SDK. Radiant Media Player supports Google IMA HTML5 SDK and is a certified Google's video technology partner. rmp-vast can display VAST ads from Google Ads network as well - though all features from Google Ads network may not be available.

Back to documentation sections

Debugging

rmp-vast compiled library (./dist/rmp-vast.min.js) does not print any log to the console. If you want those logs for debugging purposes please use ./dist/rmp-vast.js instead

Back to documentation sections

Parameters, API events and methods

Source code for rmp-vast is available for review in ./src/ folder. Code comments should be available at key points to better understand rmp-vast inner workings.

Parameters when creating a rmp-vast instance

Once rmp-vast is loaded on your page you can create a new rmp-vast instance as follows:

new RmpVast(id: String, params: Object)

Back to documentation sections

Starting the rmp-vast player

It is important for the rmp-vast instance to be properly initialized to avoid playback issues.

Playing video ads in HTML5 video is a non-trivial process that requires the overlaying of multiple video tags. On mobile devices a user interaction is required to properly initialized a video tag and various restrictions are set by OSes to limit manipulation of a video tag with JavaScript.

To sum up: use the rmp-vast API loadAds() method to start playback. On mobile devices this should be the result of a direct user interaction. You can also use muted autoplay to start playback. Refer to the autoplay section.

If you do not want to call loadAds() method directly - call initialize() method (as a result of a user interaction) then call loadAds() later on when you wish to load a VAST tag.

Back to documentation sections

API events

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:

const rmpVast = new RmpVast(id, params);
rmpVast.on("adstarted", callbackA);
rmpVast.loadAds(adTag);

You can register multiple events for the same callback, example:

const rmpVast = new RmpVast(id, params);
rmpVast.on("adloaded adstarted", callbackA);
rmpVast.loadAds(adTag);

You can access the name of the event being fired:

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:

rmpVast.off("adstarted", callbackA);

You can unregister multiple events for the same callback as well:

rmpVast.off("adloaded adstarted adclick", callbackA);

You can also register an event where the callback is only executed once:

const rmpVast = new RmpVast(id, params);
rmpVast.one("adstarted", callbackA);
rmpVast.loadAds(adTag);

Available events are:

The adinitialplayrequestfailed event tells if the ad (or content in case of non-linear creatives) player was able to play on first attempt. Typically this event will fire when autoplay is requested but blocked by an interference engine (macOS Safari 11+, Chrome 66+, browser extensions ...). If the initial play request was a success, the adinitialplayrequestsucceeded event will fire.

VPAID (DEPRECATED) related events:

Back to documentation sections

API methods

Once a rmp-vast instance is created you can query the API methods to interact with the player. Example:

const rmpVast = new RmpVast(id);
...
rmpVast.pause();
...
rmpVast.volume = 0.5;

For linear ads rmp-vast exposes 2 players: a content player (for the actual content) and a ad player (for the loaded ad).

API methods

API methods getter|setter

The following getter|setter should be queried after the adstarted event has fired:

Additional AdPod-related methods

Additional VPAID-related methods

The following methods should be queried after the aderror event has fired:

The following methods provide context information for the rmp-vast instance:

Back to documentation sections

Companion ads support

We support StaticResource, IFrameResource and HTMLResource in Companion tags.

We also support AltText, CompanionClickThrough, CompanionClickTracking, TrackingEvents tags in Companion tags.

We support "required" attribute for CompanionAds tag as well as "adSlotId" attribute for Companion tag.

We also support CompanionAds in wrappers/redirects (The CompanionAds nearer to the final linear creative will be selected).

See ./test/spec/companionSpec/ for examples of implementation.

The following methods must be queried when the adstarted event fires.

{
  adSlotId: "RMPSLOTID-1",
  altText: "Radiant Media Player logo",
  companionClickThroughUrl: "https://www.radiantmediaplayer.com",
  companionClickTrackingUrl: "https://www.radiantmediaplayer.com/vast/tags/ping.gif?creativeType=companion&type=companionClickTracking",
  height: 250,
  imageUrl: "https://www.radiantmediaplayer.com/vast/mp4s/companion.jpg",
  trackingEventsUri: [
    "https://www.radiantmediaplayer.com/vast/tags/ping.gif?creativeType=companion&type=creativeView",
    "https://www.radiantmediaplayer.com/vast/tags/ping.gif?creativeType=companion&type=creativeViewTwo"
  ],
  width: 300
}

Not all fields may be available, so check availability before usage.

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
  const list = rmpVast.getCompanionAdsList(900, 750);
  if (list && list.length === 3) {
    const img = rmpVast.getCompanionAd(2);
    if (img) {
      // we get our companion ad image and we can append it to DOM now
      // VAST trackers will be called automatically when needed
      const companionId = document.getElementById("companionId");
      companionId.appendChild(img);
    }
  }
});

Back to documentation sections

AdVerifications OM Web SDK

rmp-vast supports AdVerifications through the IAB OM Web SDK. Our implementation is based on IAB GitHub Open-Measurement-JSClients and sports OM Web SDK version 1.4.12

Feedback is welcome. Please see ./test/spec/omWebSpec/ for implementation examples.

Back to documentation sections

SIMID support

As SIMID is a new format in the industry, feedback is welcome - open a PR/issue for bugs and improvements

SIMID replaces VPAID for interactive creatives. We only support linear SIMID creatives for the moment. See test/simidSpec/ for an implementation example. This feature is enabled by default but can be turned off with enableSimid: false setting.

VPAID support

--- DEPRECATED with rmp-vast 7 ---

Current VPAID support limitations:

Back to documentation sections

HLS creatives support

We support linear creatives in HLS format on all supported devices for rmp-vast. This is made possible thanks to the hls.js project. Make sure to add ./externals/hls/hls.min.js to your page and enable this feature with useHlsJS: true setting. See ./test/spec/inlineLinearSpec/hls-creative.html for an example.

Back to documentation sections

Macros

rmp-vast supports most VAST 4.3 macros automatically. There are however macros that need to be set explicitly or that are not currently supported by rmp-vast. You can pass values for those macros with the macros setting (they will be replaced by rmp-vast for ping URLs). Example:

const id = "vast-player";
const macrosMap = new Map();
macrosMap.set("CLIENTUA", encodeURIComponent("MyPlayer/1.0 rmp-vast/15.0.0"));
macrosMap.set("PLAYBACKMETHODS", 2);
const params = {
  showControlsForAdPlayer: true,
  macros: macrosMap,
};
const rmpVast = new RmpVast(id, params);
rmpVast.loadAds("your-ad-tag-url");

Macros that need to be set explicitly if you want to support them: CONTENTCAT, GPPSECTIONID, GPPSTRING, PLAYBACKMETHODS, STOREID, STOREURL, BREAKMAXADLENGTH, BREAKMAXADS, BREAKMAXDURATION, BREAKMINADLENGTH, PLACEMENTTYPE, TRANSACTIONID, CLIENTUA, DEVICEIP, IFA, IFATYPE, LATLONG, SERVERUA, APPBUNDLE, EXTENSIONS, OMIDPARTNER, VERIFICATIONVENDORS, CONTENTID, CONTENTURI, INVENTORYSTATE.

Autoplay support

This is done by simply calling loadAds method on page load (after HTML5 content video player is in DOM and rmp-vast library is loaded and instantiated). In many environments, only muted autoplay is available (iOS, Android, Desktop Chrome 66+ and Desktop Safari 11+), so add the muted attribute on the HTML5 content video player.

Back to documentation sections

Fullscreen management

rmp-vast supports fullscreen for the global player (e.g. content + ad players) but there is an extra layer to add to your application. See the ./app/js/app.js file around line 25 for an example of implementation.

Back to documentation sections

Pre, mid and post rolls

rmp-vast can handle pre/mid/post rolls ad breaks through the loadAds API method. See ./test/spec/apiSpec/pre-mid-post-roll.html for an example.

Back to documentation sections

Outstream ads

rmp-vast supports displaying outstream ads when parameter outstream is set to true. For an implementation example see ./test/spec/outstreamSpec/Simple.html.

Back to documentation sections

TypeScript support

Make sure to include ./types folder in your TypeScript configuration file and you can start using rmp-vast in a TypeScript environment. Note: the resulting .d.ts files are generated from JavaScript using JSDoc syntax.

Contributing

Contributions are welcome. Please review general code structure and stick to existing patterns. Provide test where appropriate (see ./test folder). Tests are written with Jasmine and automated with selenium web driver and are validated in latest webdriver for Chrome and Firefox for Windows 11. Additionally we test on latest Chrome for Android and latest macOS and iOS Safari.

To develop rmp-vast do install it (you need to have node.js installed globally):

git clone https://github.com/radiantmediaplayer/rmp-vast.git

npm install

Make changes to code and then run:

npm run dev

When your changes are ready for commit, build rmp-vast:

npm run build

Before committing for a pull request - run test:

npm run test:patch

Make sure the ctrf-chrome.json file in report/v${version} has all test passed - test manually for false negative. Also note we test on Safari for macOS and Chrome for Android. Some more advanced tests require manual verification and are located in test/spec/manualSpec/ and should be run in latest Chrome for Windows|macOS|Linux.

Back to documentation sections

License

rmp-vast is released under MIT.

Back to documentation sections

Radiant Media Player

If you like rmp-vast you can check out Radiant Media Player - A Modern Go-everywhere HTML5 Video Player - Create web, mobile & OTT video apps in a snap.

Radiant Media Player is a commercial HTML5 media player, not covered by rmp-vast MIT license.

You may request a free trial for Radiant Media Player at: https://www.radiantmediaplayer.com/free-trial.html.

Back to documentation sections