Skip to content

Commit

Permalink
Create a shaka class to encapsulate ads.
Browse files Browse the repository at this point in the history
Change-Id: Ic9388679754d24cef7246107e1e3b951977ce27f
  • Loading branch information
ismena committed Oct 25, 2019
1 parent 6ab4e68 commit 110c0bb
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 1 deletion.
1 change: 1 addition & 0 deletions build/types/ads
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Ad Insertion Functionality

+../../lib/ads/ad_manager.js
+../../lib/ads/client_side_ad.js
+../../lib/ads/client_side_ad_manager.js
17 changes: 16 additions & 1 deletion externs/ima.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ google.ima.AdsManager = class {
*/
init(width, height, viewMode) {}

/**
* @return {number}
*/
getRemainingTime() {}

/** @override */
addEventListener() {}

Expand Down Expand Up @@ -106,7 +111,17 @@ google.ima.AdsManagerLoadedEvent.Type = {


/** @const */
google.ima.AdEvent = {};
google.ima.AdEvent = class extends Event {
/** @return {!google.ima.Ad } */
getAd() {}
};


/** @const */
google.ima.Ad = class {
/** @return {number} */
getDuration() {}
};


/**
Expand Down
41 changes: 41 additions & 0 deletions externs/shaka/ads.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/**
* @license
* Copyright 2016 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/


/**
* @externs
*/


/**
* Interface for Ad objects.
*
* @extends {shaka.util.IReleasable}
* @interface
* @exportDoc
*/
shaka.extern.IAd = class {
/**
* @return {number}
*/
getDuration() {}

/**
* @return {number}
*/
getRemainingTime() {}
};
62 changes: 62 additions & 0 deletions lib/ads/client_side_ad.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/**
* @license
* Copyright 2016 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/


goog.provide('shaka.ads.ClientSideAd');

/**
* @implements {shaka.extern.IAd}
* @export
*/
shaka.ads.ClientSideAd = class {
/**
* @param {!google.ima.Ad} imaAd
* @param {!google.ima.AdsManager} imaAdManager
*/
constructor(imaAd, imaAdManager) {
/** @private {google.ima.Ad} */
this.ad_ = imaAd;

/** @private {google.ima.AdsManager} */
this.manager_ = imaAdManager;
}

/**
* @override
* @export
*/
getDuration() {
return this.ad_.getDuration();
}

/**
* @override
* @export
*/
getRemainingTime() {
return this.manager_.getRemainingTime();
}

/**
* @override
* @export
*/
release() {
this.ad_ = null;
this.manager_ = null;
}
};

0 comments on commit 110c0bb

Please sign in to comment.