From 229b771dc5fc9d3c6a985f7c52dad38cc9f756c1 Mon Sep 17 00:00:00 2001 From: Kiro705 Date: Thu, 3 Oct 2019 15:28:03 -0400 Subject: [PATCH] feat: adds IMA events --- README.md | 23 +++++++++++++++++++++++ src/sdk-impl.js | 12 +++++++++++- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 5d89453f..427849a1 100644 --- a/README.md +++ b/README.md @@ -176,6 +176,29 @@ the previous snippet. A summary of all settings follows:
(5) [google.ima.ImaSdkSettings.VpaidMode](//developers.google.com/interactive-media-ads/docs/sdks/html5/v3/apis#ima.ImaSdkSettings.VpaidMode) +## IMA Plugin Ad Events +The IMA Plugin will fire events that can be listened for. Ad lifecycle events can be listened for by following our [Advanced Example](https://github.com/googleads/videojs-ima/blob/master/examples/advanced/ads.js) + +Other events are emited from the videojs player. Please see the below example to set up listeners for these events. + +```javascript +this.player = videojs('content_video'); + +this.player.on('ads-manager', function(response){ + var adsManager = response.adsManager; + // Your code in response to the `ads-manager` event. +}) +``` + +Below are the events added by the videojs-ima plugin to the videojs player. + +| Event | Event String | Payload | +|-------|--------------|---------| +| Ad Started | 'ads-ad-started' | none | +| Ads Manager | 'ads-manager' | [google.ima.AdsManager](https://developers.google.com/interactive-media-ads/docs/sdks/html5/v3/apis#ima.AdsManager) | +| Ads Loader | 'ads-loader' | [google.ima.AdsLoader](https://developers.google.com/interactive-media-ads/docs/sdks/html5/v3/apis#ima.AdsLoader) | +| Ads Request | 'ads-request' | [google.ima.AdsRequest](https://developers.google.com/interactive-media-ads/docs/sdks/html5/v3/apis#ima.AdsRequest) | + ## Disable automatic ad break playback In some circumstances you may want to prevent the SDK from playing ad breaks until you're ready for them. In this scenario, you can disable automatic diff --git a/src/sdk-impl.js b/src/sdk-impl.js index 0438ebab..ce2964c2 100644 --- a/src/sdk-impl.js +++ b/src/sdk-impl.js @@ -183,6 +183,11 @@ SdkImpl.prototype.initAdObjects = function() { google.ima.AdErrorEvent.Type.AD_ERROR, this.onAdsLoaderError.bind(this), false); + + this.controller.playerWrapper.vjsPlayer.trigger({ + type: 'ads-loader', + adsLoader: this.adsLoader, + }); }; /** @@ -224,7 +229,7 @@ SdkImpl.prototype.requestAds = function() { } this.adsLoader.requestAds(adsRequest); - this.controller.triggerPlayerEvent('ads-request', adsRequest); + this.controller.playerWrapper.vjsPlayer.trigger({ type: 'ads-request', AdsRequest: adsRequest }); }; @@ -284,6 +289,11 @@ SdkImpl.prototype.onAdsManagerLoaded = function(adsManagerLoadedEvent) { this.onAdResumed.bind(this)); } + this.controller.playerWrapper.vjsPlayer.trigger({ + type: 'ads-manager', + adsManager: this.adsManager, + }); + if (!this.autoPlayAdBreaks) { this.initAdsManager(); }