2021-06-30 18:29:00 +02:00
|
|
|
// Created by xander on 6/21/2021
|
|
|
|
import videojs from 'video.js';
|
2021-07-13 10:00:25 +02:00
|
|
|
import 'videojs-contrib-ads';
|
2021-06-30 18:29:00 +02:00
|
|
|
import 'videojs-ima';
|
|
|
|
const VERSION = '0.0.1';
|
|
|
|
|
2021-07-13 10:00:25 +02:00
|
|
|
/* Macro provided by aniview
|
|
|
|
* const macroUrl =
|
|
|
|
`https://vast.aniview.com/api/adserver61/vast/` +
|
|
|
|
`?AV_PUBLISHERID=60afcbc58cfdb065440d2426` +
|
|
|
|
`&AV_CHANNELID=60b354389c7adb506d0bd9a4` +
|
|
|
|
`&AV_URL=[URL_MACRO]` +
|
|
|
|
`&cb=[TIMESTAMP_MACRO]` +
|
|
|
|
`&AV_WIDTH=[WIDTH_MACRO]` +
|
|
|
|
`&AV_HEIGHT=[HEIGHT_MACRO]` +
|
|
|
|
`&AV_SCHAIN=[SCHAIN_MACRO]` +
|
|
|
|
`&AV_CCPA=[CCPA_MACRO]` +
|
|
|
|
`&AV_GDPR=[GDPR_MACRO]` +
|
|
|
|
`&AV_CONSENT=[CONSENT_MACRO]` +
|
|
|
|
`&skip=true` +
|
|
|
|
`&skiptimer=5` +
|
|
|
|
`&logo=false` +
|
|
|
|
`&usevslot=true` +
|
|
|
|
`&vastretry=3` +
|
|
|
|
`&hidecontrols=false`;
|
|
|
|
* */
|
|
|
|
|
|
|
|
// TEST PRE-ROLL WITH THIS TAG:
|
|
|
|
// https://pubads.g.doubleclick.net/gampad/ads?sz=640x480&iu=/124319096/external/ad_rule_samples&ciu_szs=300x250&ad_rule=1&impl=s&gdfp_req=1&env=vp&output=vmap&unviewed_position_start=1&cust_params=deployment%3Ddevsite%26sample_ar%3Dpreonly&cmsid=496&vid=short_onecue&correlator=
|
|
|
|
|
|
|
|
// Modified to work with IMA
|
2021-06-30 18:29:00 +02:00
|
|
|
const macroUrl =
|
2021-07-13 10:00:25 +02:00
|
|
|
`https://vast.aniview.com/api/adserver61/vast/` +
|
|
|
|
`?AV_PUBLISHERID=60afcbc58cfdb065440d2426` +
|
|
|
|
`&AV_CHANNELID=60b354389c7adb506d0bd9a4` +
|
|
|
|
`&AV_URL=[URL]` +
|
|
|
|
`&cb=[CACHEBUSTING]` +
|
|
|
|
`&AV_WIDTH=[WIDTH]` +
|
|
|
|
`&AV_HEIGHT=[HEIGHT]` +
|
|
|
|
// `&AV_SCHAIN=[SCHAIN_MACRO]` +
|
|
|
|
// `&AV_CCPA=[CCPA_MACRO]` +
|
|
|
|
// `&AV_GDPR=[GDPR_MACRO]` +
|
|
|
|
// `&AV_CONSENT=[CONSENT_MACRO]` +
|
|
|
|
`&skip=true` +
|
|
|
|
`&skiptimer=5` +
|
|
|
|
`&logo=true` +
|
|
|
|
`&usevslot=true` +
|
|
|
|
`&vastretry=5` +
|
|
|
|
`&hidecontrols=false`;
|
2021-06-30 18:29:00 +02:00
|
|
|
|
|
|
|
const defaults = {
|
|
|
|
adTagUrl: macroUrl,
|
|
|
|
debug: false,
|
|
|
|
};
|
|
|
|
|
|
|
|
const Component = videojs.getComponent('Component');
|
|
|
|
const registerPlugin = videojs.registerPlugin || videojs.plugin;
|
|
|
|
|
|
|
|
class AniviewPlugin extends Component {
|
|
|
|
constructor(player, options) {
|
|
|
|
super(player, options);
|
|
|
|
|
|
|
|
// Plugin started
|
2021-07-13 10:00:25 +02:00
|
|
|
if (options.debug) this.log(`Created aniview plugin.`);
|
2021-06-30 18:29:00 +02:00
|
|
|
|
|
|
|
// To help with debugging, we'll add a global vjs object with the video js player
|
|
|
|
window.aniview = player;
|
|
|
|
|
|
|
|
this.player = player;
|
|
|
|
|
|
|
|
// request ads whenever there's new video content
|
2021-07-13 10:00:25 +02:00
|
|
|
/* player.on('contentchanged', () => {
|
2021-06-30 18:29:00 +02:00
|
|
|
// in a real plugin, you might fetch your ad inventory here
|
|
|
|
player.trigger('adsready');
|
2021-07-13 10:00:25 +02:00
|
|
|
}); */
|
2021-06-30 18:29:00 +02:00
|
|
|
|
|
|
|
// Plugin event listeners
|
2021-07-13 10:00:25 +02:00
|
|
|
// player.on('readyforpreroll', (event) => this.onReadyForPreroll(event));
|
2021-06-30 18:29:00 +02:00
|
|
|
}
|
|
|
|
|
2021-07-13 10:00:25 +02:00
|
|
|
/* onReadyForPreroll(event) {
|
2021-06-30 18:29:00 +02:00
|
|
|
// send event when ad is playing to remove loading spinner
|
|
|
|
this.player.one('adplaying', () => {
|
|
|
|
this.player.trigger('ads-ad-started');
|
|
|
|
});
|
|
|
|
|
|
|
|
// resume content when all your linear ads have finished
|
|
|
|
this.player.one('adended', () => {
|
|
|
|
this.player.ads.endLinearAdMode();
|
|
|
|
});
|
2021-07-13 10:00:25 +02:00
|
|
|
} */
|
2021-06-30 18:29:00 +02:00
|
|
|
|
|
|
|
log(...args) {
|
|
|
|
if (this.options_.debug) {
|
|
|
|
console.log(`Aniview Debug:`, JSON.stringify(args));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-18 17:00:51 +02:00
|
|
|
videojs.registerComponent('aniview', AniviewPlugin);
|
2021-06-30 18:29:00 +02:00
|
|
|
|
|
|
|
const onPlayerReady = (player, options) => {
|
|
|
|
player.aniview = new AniviewPlugin(player, options);
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialize the plugin.
|
|
|
|
*
|
|
|
|
* @function plugin
|
|
|
|
* @param {Object} [options={}]
|
|
|
|
*/
|
|
|
|
const plugin = function (options) {
|
2021-07-13 10:00:25 +02:00
|
|
|
const google = window.google;
|
|
|
|
|
|
|
|
this.ima({
|
|
|
|
// $FlowFixMe
|
|
|
|
vpaidMode: google.ima.ImaSdkSettings.VpaidMode.INSECURE,
|
|
|
|
adTagUrl: macroUrl,
|
|
|
|
});
|
|
|
|
|
2021-06-30 18:29:00 +02:00
|
|
|
this.ready(() => {
|
|
|
|
onPlayerReady(this, videojs.mergeOptions(defaults, options));
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
plugin.VERSION = VERSION;
|
|
|
|
|
|
|
|
registerPlugin('aniview', plugin);
|
|
|
|
|
|
|
|
export default plugin;
|