Skip to content

Commit

Permalink
Clear intervals on reset (googleads#210)
Browse files Browse the repository at this point in the history
* clear timeouts and intervals when player is disposed/reset

* clear timeouts and intervals when player is disposed/reset

* Add missing intervals

* clear timeouts and intervals when player is disposed/reset

* fix parenthesis
  • Loading branch information
kjanoudi authored and shawnbuso committed Apr 27, 2016
1 parent 3a8cc33 commit 7e18a85
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/videojs.ima.js
Original file line number Diff line number Diff line change
Expand Up @@ -1157,7 +1157,27 @@
clearInterval(updateTimeIntervalHandle);
clearInterval(seekCheckIntervalHandle);
clearInterval(resizeCheckIntervalHandle);
player.one('play', player.ima.setUpPlayerIntervals_);
if(player.el()) {
player.one('play', player.ima.setUpPlayerIntervals_);
}
};

var playerDisposedListener = function(){
contentEndedListeners, contentAndAdsEndedListeners = [], [];
contentComplete = true;
player.off('ended', localContentEndedListener);
var intervalsToClear = [updateTimeIntervalHandle, seekCheckIntervalHandle,
adTrackingTimer, resizeCheckIntervalHandle];
for (var index in intervalsToClear) {
var interval = intervalsToClear[index];
if (interval) {
clearInterval(interval);
}
}
if (adsManager) {
adsManager.destroy();
adsManager = null;
}
};

settings = extend({}, ima_defaults, options || {});
Expand All @@ -1183,6 +1203,7 @@
player.one('play', player.ima.setUpPlayerIntervals_);

player.on('ended', localContentEndedListener);
player.on('dispose', playerDisposedListener);

var contrib_ads_defaults = {
debug: settings.debug,
Expand Down

0 comments on commit 7e18a85

Please sign in to comment.