<commit_before>'use strict';

import EventBus from '../components/EventBus';

import {extendDefaults} from '../modules/common';
import {dankLog} from '../modules/dankLog';

let instance = null;

/**
 * VideoAd
 */
class VideoAd {
    /**
     * Constructor of VideoAd.
     * @param {Object} options
     * @return {*}
     */
    constructor(options) {
        // Make this a singleton.
        if (instance) {
            return instance;
        } else {
            instance = this;
        }

        const defaults = {
            debug: false,
            prefix: 'gdApi-',
            autoplay: true,
            responsive: true,
            width: 640,
            height: 360,
            locale: 'en',
        };

        if (options) {
            this.options = extendDefaults(defaults, options);
        } else {
            this.options = defaults;
        }

        this.adsLoader = null;
        this.adsManager = null;
        this.adDisplayContainer = null;
        this.eventBus = new EventBus();
        this.safetyTimer = null;
        this.requestAttempts = 0;
        this.containerTransitionSpeed = 200;
        this.preroll = true;
        this.tag = 'https://pubads.g.doubleclick.net/gampad/ads' +
            '?sz=640x480&iu=/124319096/external/single_ad_samples' +
            '&ciu_szs=300x250&impl=s&gdfp_req=1&env=vp&output=vast' +
            '&unviewed_position_start=1&cust_params=deployment%3Ddevsite' +
            '%26sample_ct%3Dlinear&correlator=';

        // Analytics variables
        this.gameId = 0;
        this.eventCategory = 'AD';

        this.adsLoaderPromise = new Promise((resolve) => {
            // Wait for adsLoader to be loaded.
            this.eventBus.subscribe('AD_SDK_LOADER_READY',
                (arg) => resolve());
            // But don't wait too long.
            setTimeout(() => {
                resolve();
            }, 3000);
        });
        this.adsManagerPromise = new Promise((resolve) => {
            // Wait for adsManager to be loaded.
            this.eventBus.subscribe('AD_SDK_MANAGER_READY',
                (arg) => resolve());
            // But don't wait too long.
            setTimeout(() => {
                resolve();
            }, 3000);
        });
    }

    /**
     * start
     * Start the VideoAd instance by first checking if we
     * have auto play capabilities. By calling start() we start the
     * creation of the adsLoader, needed to request ads. This is also
     * the time where we can change other options based on context as well.
     * @public
     */
    start() {
        // Start ticking our safety timer. If the whole advertisement
        // thing doesn't resolve without our set time, then screw this.
        this._startSafetyTimer(8000, 'start()');
        this.eventBus.subscribe('LOADED', () => {
            // Start our safety timer every time an ad is loaded.
            // It can happen that an ad loads and starts, but has an error
            // within itself, so we never get an error event from IMA.
            this._clearSafetyTimer('LOADED');
            this._startSafetyTimer(2000, 'LOADED');
            // Show the advertisement container.
            if (this.adContainer) {
                this.adContainer.style.display = 'block';
                setTimeout(() => {
                    this.adContainer.style.opacity = 1;
                }, 10);
            }
        });

        // If we have auto play then we clear the safetyTimer when the ad
        // has actually started playing. However, if we do not have auto play
        // then we need to wait for a user action, which can take an eternity.
        this.eventBus.subscribe('STARTED', () => {
            this._clearSafetyTimer('STARTED');
        });
        if (!this.options.autoplay ||
            (this.options.autoplay && !this.options.preroll)) {
            this.eventBus.subscribe('AD_SDK_MANAGER_READY', () => {
                this._clearSafetyTimer('AD_SDK_MANAGER_READY');
            });
        }

        // Enable a responsive advertisement.<commit_msg>Increased the safety timer timeout for LOADED to START ad event.<commit_after>'use strict';

import EventBus from '../components/EventBus';

import {extendDefaults} from '../modules/common';
import {dankLog} from '../modules/dankLog';

let instance = null;

/**
 * VideoAd
 */
class VideoAd {
    /**
     * Constructor of VideoAd.
     * @param {Object} options
     * @return {*}
     */
    constructor(options) {
        // Make this a singleton.
        if (instance) {
            return instance;
        } else {
            instance = this;
        }

        const defaults = {
            debug: false,
            prefix: 'gdApi-',
            autoplay: true,
            responsive: true,
            width: 640,
            height: 360,
            locale: 'en',
        };

        if (options) {
            this.options = extendDefaults(defaults, options);
        } else {
            this.options = defaults;
        }

        this.adsLoader = null;
        this.adsManager = null;
        this.adDisplayContainer = null;
        this.eventBus = new EventBus();
        this.safetyTimer = null;
        this.requestAttempts = 0;
        this.containerTransitionSpeed = 200;
        this.preroll = true;
        this.tag = 'https://pubads.g.doubleclick.net/gampad/ads' +
            '?sz=640x480&iu=/124319096/external/single_ad_samples' +
            '&ciu_szs=300x250&impl=s&gdfp_req=1&env=vp&output=vast' +
            '&unviewed_position_start=1&cust_params=deployment%3Ddevsite' +
            '%26sample_ct%3Dlinear&correlator=';

        // Analytics variables
        this.gameId = 0;
        this.eventCategory = 'AD';

        this.adsLoaderPromise = new Promise((resolve) => {
            // Wait for adsLoader to be loaded.
            this.eventBus.subscribe('AD_SDK_LOADER_READY',
                (arg) => resolve());
            // But don't wait too long.
            setTimeout(() => {
                resolve();
            }, 3000);
        });
        this.adsManagerPromise = new Promise((resolve) => {
            // Wait for adsManager to be loaded.
            this.eventBus.subscribe('AD_SDK_MANAGER_READY',
                (arg) => resolve());
            // But don't wait too long.
            setTimeout(() => {
                resolve();
            }, 3000);
        });
    }

    /**
     * start
     * Start the VideoAd instance by first checking if we
     * have auto play capabilities. By calling start() we start the
     * creation of the adsLoader, needed to request ads. This is also
     * the time where we can change other options based on context as well.
     * @public
     */
    start() {
        // Start ticking our safety timer. If the whole advertisement
        // thing doesn't resolve without our set time, then screw this.
        this._startSafetyTimer(8000, 'start()');
        this.eventBus.subscribe('LOADED', () => {
            // Start our safety timer every time an ad is loaded.
            // It can happen that an ad loads and starts, but has an error
            // within itself, so we never get an error event from IMA.
            this._clearSafetyTimer('LOADED');
            this._startSafetyTimer(4000, 'LOADED');
            // Show the advertisement container.
            if (this.adContainer) {
                this.adContainer.style.display = 'block';
                setTimeout(() => {
                    this.adContainer.style.opacity = 1;
                }, 10);
            }
        });

        // If we have auto play then we clear the safetyTimer when the ad
        // has actually started playing. However, if we do not have auto play
        // then we need to wait for a user action, which can take an eternity.
        this.eventBus.subscribe('STARTED', () => {
            this._clearSafetyTimer('STARTED');
        });
        if (!this.options.autoplay ||
            (this.options.autoplay && !this.options.preroll)) {
            this.eventBus.subscribe('AD_SDK_MANAGER_READY', () => {
                this._clearSafetyTimer('AD_SDK_MANAGER_READY');
            });
        }

        // Enable a responsive advertisement.
{'fraction_non_alphanumeric': 0.11265038279256288, 'fraction_numerical': 0.013853445133065986, 'mean_word_length': 1.7125906394199077, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 23, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '208669', 'n_tokens_mistral': 2371, 'n_tokens_neox': 2194, 'n_words': 609}