componentDidMount()

in web/reactplayer/src/Components/VideoJSPlayer.js [57:148]


  componentDidMount() {

    //initialize the QoS SDK
    var sdk = new SDK(this);
    this.sdk = sdk;
    var utils = new Utils();

    //initialize user
    sdk.getUser();

    // instantiate Video.js
    this.player = videojs(this.videoNode, this.props, function onPlayerReady() {
      // console.log('onPlayerReady', this);
    });

    //-----Capturing Events for SDK-----

    //fired when video is played
    this.player.on('play', function() {
      sdk.play(utils.getPlaylistType(this));
    });

    //Fired when the user agent begins looking for the media
    this.player.on('loadstart', sdk.loadStarted);

    //fired when the metadata,first frame info of the media is available
    this.player.on('loadeddata', function() {
      // console.log("In loadeddata :", this);
      let segmentInfo = utils.getSegmentInfo(this);
      sdk.loadeddata(this.duration(), utils.getPackageType(this), this.tech_.hls.playlists.media_.attributes, segmentInfo.cdn_request_id, segmentInfo.rtt);
    });

    //fired when the player is waiting for buffer to fill in
    this.player.on('waiting', function() {
      sdk.buffering(this.currentTime());
    });

    //fired once the player has estimated that it has enough media in the buffer to //start playback
    this.player.on('canplaythrough', function() {
      // console.log("In canplaythrough ",this);
      let segmentInfo = utils.getSegmentInfo(this);
      // console.log("Segment Info :",segmentInfo);
      sdk.bufferCompleted(segmentInfo.cdn_request_id, segmentInfo.rtt);
    });

    //fired every few milli seconds as play back position changes
    this.player.on('timeupdate', function() {
      var intPlayedTime = parseInt(this.currentTime(), 10);
      let everyFiveSec = intPlayedTime % 5 === 0 && intPlayedTime !== 0;

      //process it only every 5 seconds.
      if (everyFiveSec) {
        let segmentInfo = utils.getSegmentInfo(this);
        // console.log("In timeupdate ",this.tech_.hls.playlists.media_.segments);
        sdk.timeUpdate(this.currentTime(),this.duration(), segmentInfo.cdn_request_id,segmentInfo.rtt);
      }
    });

    this.player.on('seeking', sdk.seeking);
    this.player.on('seeked', function() {
      let segmentInfo = utils.getSegmentInfo(this);
      sdk.seeked(this.currentTime(),segmentInfo.cdn_request_id,segmentInfo.rtt);
    });

    //fired when there is a switch in bitrate
    this.player.on('mediachange', function(event) {
      console.log("In mediachange :", this);
      sdk.step(this.tech_.hls.playlists.media_.attributes, utils.getPackageType(this), this.currentTime());
    });

    //fired when video.js player encounters an 'error'
    this.player.on('error', function(err) {
      let segmentInfo = utils.getSegmentInfo(this);
      sdk.errorOccured(this.currentTime(), segmentInfo.cdn_request_id, err);
    });

    //fired when video is paused.
    this.player.on('pause', sdk.pause);

    //fired when playback has finished
    this.player.on('ended', function() {
      sdk.ended(this.currentTime(), this.duration());
    });

    //
    // this.player.on('playing',function(){
    //   // console.log("In playing ",this);
    // });
    // this.player.on('progress', function(event) {
    //   // console.log("In progress ",this);
    // });
  }