Ads plugin fixes to allow multiple VAST requests
This commit is contained in:
		@ -172,17 +172,6 @@ class Ads {
 | 
				
			|||||||
        // We assume the adContainer is the video container of the plyr element that will house the ads
 | 
					        // We assume the adContainer is the video container of the plyr element that will house the ads
 | 
				
			||||||
        this.elements.displayContainer = new google.ima.AdDisplayContainer(this.elements.container, this.player.media);
 | 
					        this.elements.displayContainer = new google.ima.AdDisplayContainer(this.elements.container, this.player.media);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // Request video ads to be pre-loaded
 | 
					 | 
				
			||||||
        this.requestAds();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    /**
 | 
					 | 
				
			||||||
     * Request advertisements
 | 
					 | 
				
			||||||
     */
 | 
					 | 
				
			||||||
    requestAds() {
 | 
					 | 
				
			||||||
        const { container } = this.player.elements;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        try {
 | 
					 | 
				
			||||||
        // Create ads loader
 | 
					        // Create ads loader
 | 
				
			||||||
        this.loader = new google.ima.AdsLoader(this.elements.displayContainer);
 | 
					        this.loader = new google.ima.AdsLoader(this.elements.displayContainer);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -194,6 +183,17 @@ class Ads {
 | 
				
			|||||||
        );
 | 
					        );
 | 
				
			||||||
        this.loader.addEventListener(google.ima.AdErrorEvent.Type.AD_ERROR, error => this.onAdError(error), false);
 | 
					        this.loader.addEventListener(google.ima.AdErrorEvent.Type.AD_ERROR, error => this.onAdError(error), false);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // Request video ads to be pre-loaded
 | 
				
			||||||
 | 
					        this.requestAds();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * Request advertisements
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    requestAds() {
 | 
				
			||||||
 | 
					        const { container } = this.player.elements;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        try {
 | 
				
			||||||
            // Request video ads
 | 
					            // Request video ads
 | 
				
			||||||
            const request = new google.ima.AdsRequest();
 | 
					            const request = new google.ima.AdsRequest();
 | 
				
			||||||
            request.adTagUrl = this.tagUrl;
 | 
					            request.adTagUrl = this.tagUrl;
 | 
				
			||||||
@ -369,7 +369,14 @@ class Ads {
 | 
				
			|||||||
                // TODO: So there is still this thing where a video should only be allowed to start
 | 
					                // TODO: So there is still this thing where a video should only be allowed to start
 | 
				
			||||||
                // playing when the IMA SDK is ready or has failed
 | 
					                // playing when the IMA SDK is ready or has failed
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                if (player.ended){
 | 
				
			||||||
				    this.loadAds();
 | 
									    this.loadAds();
 | 
				
			||||||
 | 
								    }
 | 
				
			||||||
 | 
								    else
 | 
				
			||||||
 | 
								    {
 | 
				
			||||||
 | 
					                    // The SDK won't allow new ads to be called without receiving a contentComplete()
 | 
				
			||||||
 | 
									    this.loader.contentComplete();
 | 
				
			||||||
 | 
								    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                break;
 | 
					                break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -563,6 +570,8 @@ class Ads {
 | 
				
			|||||||
                    this.on('loaded', resolve);
 | 
					                    this.on('loaded', resolve);
 | 
				
			||||||
                    this.player.debug.log(this.manager);
 | 
					                    this.player.debug.log(this.manager);
 | 
				
			||||||
                });
 | 
					                });
 | 
				
			||||||
 | 
					                // Now that the manager has been destroyed set it to also be un-initialized
 | 
				
			||||||
 | 
					                this.initialized = false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                // Now request some new advertisements
 | 
					                // Now request some new advertisements
 | 
				
			||||||
                this.requestAds();
 | 
					                this.requestAds();
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user