@abraham_0101/platzimediaplayer
Version:
41 lines (40 loc) • 1.76 kB
JavaScript
"use strict";
exports.__esModule = true;
var ads_1 = require("./ads");
var AdsPlugin = /** @class */ (function () {
function AdsPlugin() {
this.ads = ads_1["default"].getInstance();
this.adContainer = document.createElement('div');
this.handleTimeUpdate = this.handleTimeUpdate.bind(this);
}
AdsPlugin.prototype.run = function (player) {
this.player = player;
this.player.container.appendChild(this.adContainer);
this.media = this.player.media;
this.media.addEventListener('timeupdate', this.handleTimeUpdate);
};
AdsPlugin.prototype.handleTimeUpdate = function () {
var currentTime = Math.floor(this.media.currentTime);
if (currentTime % 30 === 0) {
this.renderAd();
}
};
AdsPlugin.prototype.renderAd = function () {
var _this = this;
if (this.currentAd) {
return;
}
var ad = this.ads.getAd();
this.currentAd = ad;
this.adContainer.innerHTML = "\n <div class=\"ads\">\n <a class=\"adsLink\"href=\"" + this.currentAd.url + "\"target=\"_blank\">\n <img class=\"adsImg\"src=\"" + this.currentAd.imageUrl + "\" />\n <div class=\"ads__info\">\n <h5class=\"ads__title\">" + this.currentAd.title + "</h5>\n <p class=\"ads__body\">" + this.currentAd.body + "</p>\n </div>\n </a>\n </div>\n ";
/* setTimeout(()=>{
this.this.currentAd = null
},10000) */
setTimeout(function () {
_this.currentAd = null;
_this.adContainer.innerHTML = '';
}, 10000);
};
return AdsPlugin;
}());
exports["default"] = AdsPlugin;