Skip to content

Commit

Permalink
Put stats API on source handler
Browse files Browse the repository at this point in the history
  • Loading branch information
jforbes committed Dec 12, 2017
1 parent c0297d6 commit f87f8fe
Showing 1 changed file with 31 additions and 36 deletions.
67 changes: 31 additions & 36 deletions src/videojs-http-streaming.js
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,37 @@ class HlsHandler extends Component {
}
super.dispose();
}

getPlaybackStats() {
const getTimeRanges = (player, type) => {
const timeRangesList = [];
const timeRanges = player[type]();

for (let i = 0; i < timeRanges.length; i++) {
timeRangesList.push({
start: timeRanges.start(i),
end: timeRanges.end(i)
});
}

return timeRangesList;
};

return {
videoPlaybackQuality: this.tech_.getVideoPlaybackQuality(),
playerDimensions: this.tech_.currentDimensions(),
vhsStats: this.stats,
duration: this.tech_.duration(),
buffered: getTimeRanges(this.tech_, 'buffered'),
seekable: getTimeRanges(this.tech_, 'seekable'),
currentTime: this.tech_.currentTime(),
timestamp: Date.now(),
currentSource: this.tech_.currentSource_,
master: this.playlists.master,
currentTech: this.tech_.name_,
history: videojs.log.history().filter(([_, type]) => type === '[VHS]')
};
}
}

/**
Expand Down Expand Up @@ -600,46 +631,10 @@ if (!videojs.use) {
videojs.m3u8 = m3u8;
videojs.options.hls = videojs.options.hls || {};

const getTimeRanges = (player, type) => {
const timeRangesList = [];
const timeRanges = player[type]();

for (let i = 0; i < timeRanges.length; i++) {
timeRangesList.push({
start: timeRanges.start(i),
end: timeRanges.end(i)
});
}

return timeRangesList;
};

const getPlaybackStats = function() {
const player = this;

return {
videoPlaybackQuality: player.getVideoPlaybackQuality(),
playerDimensions: player.currentDimensions(),
hlsStats: player.tech_.hls.stats,
duration: player.duration(),
buffered: getTimeRanges(player, 'buffered'),
seekable: getTimeRanges(player, 'seekable'),
currentTime: player.currentTime(),
timestamp: Date.now(),
currentSource: player.currentSource(),
master: player.tech_.hls.masterPlaylistController_.masterPlaylistLoader_.master,
currentTech: player.tech_.name_,
// TODO: filter by VHS logging only
history: videojs.log.history()
};
};

if (videojs.registerPlugin) {
videojs.registerPlugin('reloadSourceOnError', reloadSourceOnError);
videojs.registerPlugin('getPlaybackStats', getPlaybackStats);
} else {
videojs.plugin('reloadSourceOnError', reloadSourceOnError);
videojs.plugin('getPlaybackStats', getPlaybackStats);
}

module.exports = {
Expand Down

0 comments on commit f87f8fe

Please sign in to comment.