Skip to content

Commit

Permalink
feat: adds ad log, fixes #698 (#704)
Browse files Browse the repository at this point in the history
* feat: adds ad log, fixes #698 (#704)
* test: remove broswerstack tests due to flakiness
  • Loading branch information
ypavlotsky committed Jul 25, 2018
1 parent d8cb13d commit 3b16758
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 22 deletions.
6 changes: 6 additions & 0 deletions examples/advanced/ads.js
Expand Up @@ -93,6 +93,12 @@ Ads.prototype.adsManagerLoadedCallback = function() {
events[index],
this.onAdEvent.bind(this));
}

this.player.on('adslog', this.onAdLog.bind(this));
};

Ads.prototype.onAdLog = function(data) {
this.log('Ad log: ' + data.data.AdError);
};

Ads.prototype.onAdEvent = function(event) {
Expand Down
8 changes: 8 additions & 0 deletions src/controller.js
Expand Up @@ -356,6 +356,14 @@ Controller.prototype.onAdPlayheadUpdated =
currentTime, remainingTime, duration, adPosition, totalAds);
};

/**
* Handles ad log messages.
* @param {google.ima.AdEvent} adEvent The AdEvent thrown by the IMA SDK.
*/
Controller.prototype.onAdLog = function(adEvent) {
this.playerWrapper.onAdLog(adEvent);
};


/**
* @return {Object} The current ad.
Expand Down
15 changes: 15 additions & 0 deletions src/player-wrapper.js
Expand Up @@ -461,6 +461,21 @@ PlayerWrapper.prototype.onAdError = function(adErrorEvent) {
}});
};

/**
* Handles ad log messages.
* @param {google.ima.AdEvent} adEvent The AdEvent thrown by the IMA SDK.
*/
PlayerWrapper.prototype.onAdLog = function(adEvent) {
const adData = adEvent.getAdData();
const errorMessage =
adData['adError'] !== undefined ?
adData['adError'].getMessage() : undefined;
this.vjsPlayer.trigger({type: 'adslog', data: {
AdError: errorMessage,
AdEvent: adEvent,
}});
};


/**
* Handles ad break starting.
Expand Down
11 changes: 11 additions & 0 deletions src/sdk-impl.js
Expand Up @@ -273,6 +273,9 @@ SdkImpl.prototype.onAdsManagerLoaded = function(adsManagerLoadedEvent) {
this.adsManager.addEventListener(
google.ima.AdEvent.Type.SKIPPED,
this.onAdComplete.bind(this));
this.adsManager.addEventListener(
google.ima.AdEvent.Type.LOG,
this.onAdLog.bind(this));

if (this.controller.getIsMobile()) {
// Show/hide controls on pause and resume (triggered by tap).
Expand Down Expand Up @@ -469,6 +472,14 @@ SdkImpl.prototype.onAdComplete = function() {
}
};

/**
* Handles ad log messages.
* @param {google.ima.AdEvent} adEvent The AdEvent thrown by the AdsManager.
*/
SdkImpl.prototype.onAdLog = function(adEvent) {
this.controller.onAdLog(adEvent);
};

/**
* Gets the current time and duration of the ad and calls the method to
* update the ad UI.
Expand Down
22 changes: 0 additions & 22 deletions test/webdriver/content/capabilities.js
Expand Up @@ -45,28 +45,6 @@ var browsers = [
'moz:firefoxOptions' : {args: ['-headless']}
}
},
{
name: 'browserstack-win10-chrome',
server: 'http://hub-cloud.browserstack.com/wd/hub',
capabilities: {
'browserName' : 'Chrome',
'browser_version' : '62.0',
'os' : 'Windows',
'os_version' : '10',
'resolution' : '1024x768',
}
},
{
name: 'browserstack-win10-firefox',
server: 'http://hub-cloud.browserstack.com/wd/hub',
capabilities: {
'browserName' : 'Firefox',
'browser_version' : '58.0',
'os' : 'Windows',
'os_version' : '10',
'resolution' : '1024x768',
}
},
];

for (let browser of browsers) {
Expand Down

0 comments on commit 3b16758

Please sign in to comment.