<commit_before>import videojs from 'video.js';
import OGVCompat from 'OGVCompat';
import OGVLoader from 'OGVLoader';
import OGVPlayer from 'OGVPlayer';
const Tech = videojs.getComponent('Tech');

/**
 * Ogvjs Media Controller - Wrapper for Ogvjs Media API
 *
 * @param {Object=} options Object of option names and values
 * @param {Function=} ready Ready callback function
 * @extends Tech
 * @class Ogvjs
 */
class Ogvjs extends Tech {

  constructor(options, ready) {
    super(options, ready);

    this.triggerReady();
  }

  /**
   * Dispose of Ogvjs media element
   *
   * @method dispose
   */
  dispose() {
    // Ogvjs.disposeMediaElement(this.el_);
    super.dispose();
  }

  /**
   * Create the component's DOM element
   *
   * @return {Element}
   * @method createEl
   */
  createEl() {
    let options = this.options_;

    if (options.base) {
      // set the base, get this from options
      OGVLoader.base = '/ogv.js';
    }

    let el = new OGVPlayer(options);

    // simulate timeupdate events, needed for subtitles
    // @todo switch this to native timeupdate event when available upstream
    this.lastTime = 0;
    el.addEventListener('framecallback', this.onFrameUpdate.bind(this));
    el.src = this.options_.source.src;
    el.className += ' vjs-tech';

    return el;
  }

  onFrameUpdate(event) {
    let timeupdateInterval = 0.25;
    let now = this.el_ ? this.el_.currentTime : this.lastTime;

    // Don't spam time updates on every frame
    if (Math.abs(now - this.lastTime) >= timeupdateInterval) {
      this.lastTime = now;
      this.trigger('timeupdate');
      this.trigger('durationchange');
    }
  }

  // If we're loading the playback object after it has started loading
  // or playing the video (often with autoplay on) then the loadstart event
  // has already fired and we need to fire it manually because many things
  // rely on it.
  handleLateInit_(el) {
    if (el.networkState === 0 || el.networkState === 3) {
      // The video element hasn't started loading the source yet
      // or didn't find a source
      return;
    }

    if (el.readyState === 0) {
      // NetworkState is set synchronously BUT loadstart is fired at the
      // end of the current stack, usually before setInterval(fn, 0).
      // So at this point we know loadstart may have already fired or is
      // about to fire, and either way the player hasn't seen it yet.
      // We don't want to fire loadstart prematurely here and cause a
      // double loadstart so we'll wait and see if it happens between now
      // and the next loop, and fire it if not.
      // HOWEVER, we also want to make sure it fires before loadedmetadata
      // which could also happen between now and the next loop, so we'll
      // watch for that also.
      let loadstartFired = false;
      let setLoadstartFired = function() {
        loadstartFired = true;
      };
      let triggerLoadstart = function() {
        // We did miss the original loadstart. Make sure the player
        // sees loadstart before loadedmetadata
        if (!loadstartFired) {
          this.trigger('loadstart');
        }
      };

      this.on('loadstart', setLoadstartFired);
      this.on('loadedmetadata', triggerLoadstart);
      this.ready(function() {
        this.off('loadstart', setLoadstartFired);
        this.off('loadedmetadata', triggerLoadstart);

        if (!loadstartFired) {
          // We did miss the original native loadstart. Fire it now.
          this.trigger('loadstart');
        }
      });

      return;
    }

    // From here on we know that loadstart already fired and we missed it.
    // The other readyState events aren't as much of a problem if we double
    // them, so not going to go to as much trouble as loadstart to prevent
    // that unless we find reason to.
    let eventsToTrigger = ['loadstart'];

    // loadedmetadata: newly equal to HAVE_METADATA (1) or greater
    eventsToTrigger.push('loadedmetadata');

    // loadeddata: newly increased to HAVE_CURRENT_DATA (2) or greater
    if (el.readyState >= 2) {
      eventsToTrigger.push('loadeddata');
    }

    // canplay: newly increased to HAVE_FUTURE_DATA (3) or greater
    if (el.readyState >= 3) {
      eventsToTrigger.push('canplay');
    }

    // canplaythrough: newly equal to HAVE_ENOUGH_DATA (4)
    if (el.readyState >= 4) {
      eventsToTrigger.push('canplaythrough');
    }

    // We still need to give the player time to add event listeners
    this.ready(function() {
      eventsToTrigger.forEach(function(type) {
        this.trigger(type);
      }, this);
    });
  }

  /**<commit_msg>Remove handleLateInit<commit_after>import videojs from 'video.js';
import OGVCompat from 'OGVCompat';
import OGVLoader from 'OGVLoader';
import OGVPlayer from 'OGVPlayer';
const Tech = videojs.getComponent('Tech');

/**
 * Ogvjs Media Controller - Wrapper for Ogvjs Media API
 *
 * @param {Object=} options Object of option names and values
 * @param {Function=} ready Ready callback function
 * @extends Tech
 * @class Ogvjs
 */
class Ogvjs extends Tech {

  constructor(options, ready) {
    super(options, ready);

    this.triggerReady();
  }

  /**
   * Dispose of Ogvjs media element
   *
   * @method dispose
   */
  dispose() {
    // Ogvjs.disposeMediaElement(this.el_);
    super.dispose();
  }

  /**
   * Create the component's DOM element
   *
   * @return {Element}
   * @method createEl
   */
  createEl() {
    let options = this.options_;

    if (options.base) {
      // set the base, get this from options
      OGVLoader.base = '/ogv.js';
    }

    let el = new OGVPlayer(options);

    // simulate timeupdate events, needed for subtitles
    // @todo switch this to native timeupdate event when available upstream
    this.lastTime = 0;
    el.addEventListener('framecallback', this.onFrameUpdate.bind(this));
    el.src = this.options_.source.src;
    el.className += ' vjs-tech';

    return el;
  }

  onFrameUpdate(event) {
    let timeupdateInterval = 0.25;
    let now = this.el_ ? this.el_.currentTime : this.lastTime;

    // Don't spam time updates on every frame
    if (Math.abs(now - this.lastTime) >= timeupdateInterval) {
      this.lastTime = now;
      this.trigger('timeupdate');
      this.trigger('durationchange');
    }
  }

  /**
{'fraction_non_alphanumeric': 0.10786338363780779, 'fraction_numerical': 0.0030182684670373313, 'mean_word_length': 2.66046511627907, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 8, 'https://': 0, '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': '2074385', 'n_tokens_mistral': 1916, 'n_tokens_neox': 1826, 'n_words': 612}