Files
shaka-player/lib/ads/server_side_ad.js
T
Joey Parrish f539147d48 fix: Correct license headers in compiled output
This fixes all the license headers in the main library, which corrects
the appearance of the main license in the compiled output.

It seems that the `!` in the header forces the compiler to keep it in
the output.  I believe older compiler releases did this purely based
on `@license`.

Issue #2638

Change-Id: I7f0e918caad10c9af689c9d07672b7fe9be7b2f3
2020-06-09 16:05:09 -07:00

204 lines
2.9 KiB
JavaScript

/*! @license
* Shaka Player
* Copyright 2016 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
goog.provide('shaka.ads.ServerSideAd');
/**
* @implements {shaka.extern.IAd}
* @export
*/
shaka.ads.ServerSideAd = class {
/**
* @param {google.ima.dai.api.Ad} imaAd
* @param {HTMLMediaElement} video
*/
constructor(imaAd, video) {
/** @private {google.ima.dai.api.Ad} */
this.ad_ = imaAd;
/** @private {?google.ima.dai.api.AdProgressData} */
this.adProgressData_ = null;
/** @private {HTMLMediaElement} */
this.video_ = video;
}
/**
* @param {google.ima.dai.api.AdProgressData} data
*/
setProgressData(data) {
this.adProgressData_ = data;
}
/**
* @override
* @export
*/
getDuration() {
if (!this.adProgressData_) {
// Unknown yet
return -1;
}
return this.adProgressData_.duration;
}
/**
* @override
* @export
*/
getRemainingTime() {
if (!this.adProgressData_) {
// Unknown yet
return -1;
}
return this.adProgressData_.duration - this.adProgressData_.currentTime;
}
/**
* @override
* @export
*/
isPaused() {
return this.video_.paused;
}
/**
* @override
* @export
*/
isSkippable() {
return this.ad_.isSkippable();
}
/**
* @override
* @export
*/
getTimeUntilSkippable() {
const skipOffset = this.ad_.getSkipTimeOffset();
const canSkipIn = this.getRemainingTime() - skipOffset;
return Math.max(canSkipIn, 0);
}
/**
* @override
* @export
*/
canSkipNow() {
return this.getTimeUntilSkippable() == 0;
}
/**
* @override
* @export
*/
skip() {
this.video_.currentTime += this.getRemainingTime();
}
/**
* @override
* @export
*/
pause() {
return this.video_.pause();
}
/**
* @override
* @export
*/
play() {
return this.video_.play();
}
/**
* @override
* @export
*/
getVolume() {
return this.video_.volume;
}
/**
* @override
* @export
*/
setVolume(volume) {
this.video_.volume = volume;
}
/**
* @override
* @export
*/
isMuted() {
return this.video_.muted;
}
/**
* @override
* @export
*/
resize(width, height) {
// Nothing
}
/**
* @override
* @export
*/
setMuted(muted) {
this.video_.muted = muted;
}
/**
* @override
* @export
*/
getSequenceLength() {
const podInfo = this.ad_.getAdPodInfo();
if (podInfo == null) {
// No pod, just one ad.
return 1;
}
return podInfo.getTotalAds();
}
/**
* @override
* @export
*/
getPositionInSequence() {
const podInfo = this.ad_.getAdPodInfo();
if (podInfo == null) {
// No pod, just one ad.
return 1;
}
return podInfo.getAdPosition();
}
/**
* @override
* @export
*/
release() {
this.ad_ = null;
this.adProgressData_ = null;
this.video_ = null;
}
};