123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266 |
- /* global $, events, eventLeftMargin, canvasBufferTimeRangeUpdate, canvasBufferWindowUpdate, canvasBitrateEventUpdate,
- canvasVideoEventUpdate, canvasLoadEventUpdate */
- /* eslint no-var: 0 */
- var windowDuration = 20000;
- var windowSliding = true;
- var windowStart = 0;
- var windowEnd = 10000;
- var windowFocus;
- var metricsDisplayed = false;
- var timeRangeMouseDown = false;
- $('#windowStart').val(windowStart);
- $('#windowEnd').val(windowEnd);
- function showMetrics() {
- metricsDisplayed = true;
- var width = window.innerWidth - 30;
- $('#bufferWindow_c')[0].width =
- $('#bitrateTimerange_c')[0].width =
- $('#bufferTimerange_c')[0].width =
- $('#videoEvent_c')[0].width =
- $('#metricsButton')[0].width =
- $('#loadEvent_c')[0].width =
- width;
- $('#bufferWindow_c').show();
- $('#bitrateTimerange_c').show();
- $('#bufferTimerange_c').show();
- $('#videoEvent_c').show();
- $('#metricsButton').show();
- $('#loadEvent_c').show();
- }
- function hideMetrics() {
- metricsDisplayed = false;
- $('#bufferWindow_c').hide();
- $('#bitrateTimerange_c').hide();
- $('#bufferTimerange_c').hide();
- $('#videoEvent_c').hide();
- $('#metricsButton').hide();
- $('#loadEvent_c').hide();
- }
- function timeRangeSetSliding(duration) {
- windowDuration = duration;
- windowSliding = true;
- refreshCanvas();
- }
- function timeRangeCanvasonMouseDown(evt) {
- var canvas = evt.currentTarget;
- var bRect = canvas.getBoundingClientRect();
- var mouseX = Math.round(
- (evt.clientX - bRect.left) * (canvas.width / bRect.width)
- );
- windowStart = Math.max(
- 0,
- Math.round(
- ((mouseX - eventLeftMargin) * getWindowTimeRange().now) /
- (canvas.width - eventLeftMargin)
- )
- );
- windowEnd = windowStart + 500;
- timeRangeMouseDown = true;
- windowSliding = false;
- // console.log('windowStart/windowEnd:' + '/' + windowStart + '/' + windowEnd);
- $('#windowStart').val(windowStart);
- $('#windowEnd').val(windowEnd);
- refreshCanvas();
- }
- function timeRangeCanvasonMouseMove(evt) {
- if (timeRangeMouseDown) {
- var canvas = evt.currentTarget;
- var bRect = canvas.getBoundingClientRect();
- var mouseX = Math.round(
- (evt.clientX - bRect.left) * (canvas.width / bRect.width)
- );
- var pos = Math.max(
- 0,
- Math.round(
- ((mouseX - eventLeftMargin) * getWindowTimeRange().now) /
- (canvas.width - eventLeftMargin)
- )
- );
- if (pos < windowStart) {
- windowStart = pos;
- } else {
- windowEnd = pos;
- }
- if (windowStart === windowEnd) {
- // to avoid division by zero ...
- windowEnd += 50;
- }
- // console.log('windowStart/windowEnd:' + '/' + windowStart + '/' + windowEnd);
- $('#windowStart').val(windowStart);
- $('#windowEnd').val(windowEnd);
- refreshCanvas();
- }
- }
- function timeRangeCanvasonMouseUp(evt) {
- timeRangeMouseDown = false;
- }
- function timeRangeCanvasonMouseOut(evt) {
- timeRangeMouseDown = false;
- }
- function windowCanvasonMouseMove(evt) {
- var canvas = evt.currentTarget;
- var bRect = canvas.getBoundingClientRect();
- var mouseX = Math.round(
- (evt.clientX - bRect.left) * (canvas.width / bRect.width)
- );
- var timeRange = getWindowTimeRange();
- windowFocus =
- timeRange.min +
- Math.max(
- 0,
- Math.round(
- ((mouseX - eventLeftMargin) * (timeRange.max - timeRange.min)) /
- (canvas.width - eventLeftMargin)
- )
- );
- // console.log(windowFocus);
- refreshCanvas();
- }
- function refreshCanvas() {
- if (metricsDisplayed) {
- try {
- var windowTime = getWindowTimeRange();
- canvasBufferTimeRangeUpdate(
- $('#bufferTimerange_c')[0],
- 0,
- windowTime.now,
- windowTime.min,
- windowTime.max,
- events.buffer
- );
- if (windowTime.min !== 0 || windowTime.max !== windowTime.now) {
- $('#bufferWindow_c').show();
- canvasBufferWindowUpdate(
- $('#bufferWindow_c')[0],
- windowTime.min,
- windowTime.max,
- windowTime.focus,
- events.buffer
- );
- } else {
- $('#bufferWindow_c').hide();
- }
- canvasBitrateEventUpdate(
- $('#bitrateTimerange_c')[0],
- 0,
- windowTime.now,
- windowTime.min,
- windowTime.max,
- events.level,
- events.bitrate
- );
- canvasVideoEventUpdate(
- $('#videoEvent_c')[0],
- windowTime.min,
- windowTime.max,
- events.video
- );
- canvasLoadEventUpdate(
- $('#loadEvent_c')[0],
- windowTime.min,
- windowTime.max,
- events.load
- );
- } catch (err) {
- console.log('refreshCanvas error:' + err.message);
- }
- }
- }
- function getWindowTimeRange() {
- var tnow;
- var minTime;
- var maxTime;
- if (events.buffer.length) {
- tnow = events.buffer[events.buffer.length - 1].time;
- } else {
- tnow = 0;
- }
- if (windowSliding) {
- // let's show the requested window
- if (windowDuration) {
- minTime = Math.max(0, tnow - windowDuration);
- maxTime = Math.min(minTime + windowDuration, tnow);
- } else {
- minTime = 0;
- maxTime = tnow;
- }
- } else {
- minTime = windowStart;
- maxTime = windowEnd;
- }
- if (
- windowFocus === undefined ||
- windowFocus < minTime ||
- windowFocus > maxTime
- ) {
- windowFocus = minTime;
- }
- return { min: minTime, max: maxTime, now: tnow, focus: windowFocus };
- }
- function timeRangeZoomIn() {
- if (windowSliding) {
- windowDuration /= 2;
- } else {
- var duration = windowEnd - windowStart;
- windowStart += duration / 4;
- windowEnd -= duration / 4;
- if (windowStart === windowEnd) {
- windowEnd += 50;
- }
- }
- $('#windowStart').val(windowStart);
- $('#windowEnd').val(windowEnd);
- refreshCanvas();
- }
- function timeRangeZoomOut() {
- if (windowSliding) {
- windowDuration *= 2;
- } else {
- var duration = windowEnd - windowStart;
- windowStart -= duration / 2;
- windowEnd += duration / 2;
- windowStart = Math.max(0, windowStart);
- windowEnd = Math.min(
- events.buffer[events.buffer.length - 1].time,
- windowEnd
- );
- }
- $('#windowStart').val(windowStart);
- $('#windowEnd').val(windowEnd);
- refreshCanvas();
- }
- function timeRangeSlideLeft() {
- var duration = windowEnd - windowStart;
- windowStart -= duration / 4;
- windowEnd -= duration / 4;
- windowStart = Math.max(0, windowStart);
- windowEnd = Math.min(events.buffer[events.buffer.length - 1].time, windowEnd);
- $('#windowStart').val(windowStart);
- $('#windowEnd').val(windowEnd);
- refreshCanvas();
- }
- function timeRangeSlideRight() {
- var duration = windowEnd - windowStart;
- windowStart += duration / 4;
- windowEnd += duration / 4;
- windowStart = Math.max(0, windowStart);
- windowEnd = Math.min(events.buffer[events.buffer.length - 1].time, windowEnd);
- $('#windowStart').val(windowStart);
- $('#windowEnd').val(windowEnd);
- refreshCanvas();
- }
|