Skip to content

Commit

Permalink
feat: adds IMA events
Browse files Browse the repository at this point in the history
  • Loading branch information
Kiro705 committed Oct 3, 2019
1 parent 317cdaa commit 229b771
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
23 changes: 23 additions & 0 deletions README.md
Expand Up @@ -176,6 +176,29 @@ the previous snippet. A summary of all settings follows:
<br />
(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
Expand Down
12 changes: 11 additions & 1 deletion src/sdk-impl.js
Expand Up @@ -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,
});
};

/**
Expand Down Expand Up @@ -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 });
};


Expand Down Expand Up @@ -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();
}
Expand Down

0 comments on commit 229b771

Please sign in to comment.