From 1583e7653bb6a9bd14ab21d7ff2f4c8fc3e9e6ef Mon Sep 17 00:00:00 2001 From: Stephan Hesse Date: Thu, 26 Apr 2018 23:12:01 +0200 Subject: [PATCH] Disolve "helper" folder: all of these parts belong into other specific places --- src/config.js | 2 +- src/controller/abr-controller.js | 2 +- src/controller/audio-stream-controller.js | 6 ++--- src/controller/buffer-controller.js | 2 +- src/{helper => controller}/buffer-helper.js | 24 +++++++++++-------- .../fragment-tracker.js | 0 src/{helper => controller}/level-helper.js | 9 +++++-- src/controller/stream-controller.js | 6 ++--- src/demux/demuxer.js | 7 +++--- src/hls.js | 4 ++-- src/{helper => }/is-supported.js | 2 +- src/{helper => utils}/mediakeys-helper.js | 0 src/{helper => utils}/mediasource-helper.js | 0 .../{helper => controller}/buffer-helper.js | 3 ++- .../fragment-tracker.js | 6 ++--- 15 files changed, 42 insertions(+), 31 deletions(-) rename src/{helper => controller}/buffer-helper.js (88%) rename src/{helper => controller}/fragment-tracker.js (100%) rename src/{helper => controller}/level-helper.js (96%) rename src/{helper => }/is-supported.js (92%) rename src/{helper => utils}/mediakeys-helper.js (100%) rename src/{helper => utils}/mediasource-helper.js (100%) rename tests/unit/{helper => controller}/buffer-helper.js (98%) rename tests/unit/{helper => controller}/fragment-tracker.js (99%) diff --git a/src/config.js b/src/config.js index a406a1f5800..18ff6a27040 100644 --- a/src/config.js +++ b/src/config.js @@ -18,7 +18,7 @@ import SubtitleTrackController from './controller/subtitle-track-controller'; import SubtitleStreamController from './controller/subtitle-stream-controller'; import EMEController from './controller/eme-controller'; -import { requestMediaKeySystemAccess } from './helper/mediakeys-helper'; +import { requestMediaKeySystemAccess } from './utils/mediakeys-helper'; export var hlsDefaultConfig = { autoStartLoad: true, // used by stream-controller diff --git a/src/controller/abr-controller.js b/src/controller/abr-controller.js index 2ff23352a85..fcb33907429 100644 --- a/src/controller/abr-controller.js +++ b/src/controller/abr-controller.js @@ -6,7 +6,7 @@ import Event from '../events'; import EventHandler from '../event-handler'; -import BufferHelper from '../helper/buffer-helper'; +import { BufferHelper } from './buffer-helper'; import { ErrorDetails } from '../errors'; import { logger } from '../utils/logger'; import EwmaBandWidthEstimator from '../utils/ewma-bandwidth-estimator'; diff --git a/src/controller/audio-stream-controller.js b/src/controller/audio-stream-controller.js index 13dc9cca66d..1e88253ba9e 100644 --- a/src/controller/audio-stream-controller.js +++ b/src/controller/audio-stream-controller.js @@ -3,16 +3,16 @@ */ import BinarySearch from '../utils/binary-search'; -import BufferHelper from '../helper/buffer-helper'; +import { BufferHelper } from './buffer-helper'; import Demuxer from '../demux/demuxer'; import Event from '../events'; -import * as LevelHelper from '../helper/level-helper'; +import * as LevelHelper from './level-helper'; import TimeRanges from '../utils/time-ranges'; import { ErrorTypes, ErrorDetails } from '../errors'; import { logger } from '../utils/logger'; import { findFragWithCC } from '../utils/discontinuities'; import TaskLoop from '../task-loop'; -import { FragmentState } from '../helper/fragment-tracker'; +import { FragmentState } from './fragment-tracker'; import Fragment from '../loader/fragment'; const State = { diff --git a/src/controller/buffer-controller.js b/src/controller/buffer-controller.js index c2e906283c9..1ff1f1261a0 100644 --- a/src/controller/buffer-controller.js +++ b/src/controller/buffer-controller.js @@ -6,7 +6,7 @@ import Event from '../events'; import EventHandler from '../event-handler'; import { logger } from '../utils/logger'; import { ErrorTypes, ErrorDetails } from '../errors'; -import { getMediaSource } from '../helper/mediasource-helper'; +import { getMediaSource } from '../utils/mediasource-helper'; const MediaSource = getMediaSource(); diff --git a/src/helper/buffer-helper.js b/src/controller/buffer-helper.js similarity index 88% rename from src/helper/buffer-helper.js rename to src/controller/buffer-helper.js index 7a72b5e6081..35ee5f3e5ae 100644 --- a/src/helper/buffer-helper.js +++ b/src/controller/buffer-helper.js @@ -1,15 +1,21 @@ /** - * Buffer Helper utils, providing methods dealing buffer length retrieval + * @module BufferHelper + * + * Providing methods dealing with buffer length retrieval for example. + * + * In general, a helper around HTML5 MediaElement TimeRanges gathered from `buffered` property. + * + * Also @see https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/buffered */ -const BufferHelper = { +export class BufferHelper { /** * Return true if `media`'s buffered include `position` * @param {HTMLMediaElement|SourceBuffer} media * @param {number} position * @returns {boolean} */ - isBuffered: function (media, position) { + static isBuffered (media, position) { try { if (media) { let buffered = media.buffered; @@ -25,9 +31,9 @@ const BufferHelper = { // This SourceBuffer has been removed from the parent media source } return false; - }, + } - bufferInfo: function (media, pos, maxHoleDuration) { + static bufferInfo (media, pos, maxHoleDuration) { try { if (media) { let vbuffered = media.buffered, buffered = [], i; @@ -43,9 +49,9 @@ const BufferHelper = { // This SourceBuffer has been removed from the parent media source } return { len: 0, start: pos, end: pos, nextStart: undefined }; - }, + } - bufferedInfo: function (buffered, pos, maxHoleDuration) { + static bufferedInfo (buffered, pos, maxHoleDuration) { let buffered2 = [], // bufferStart and bufferEnd are buffer boundaries around current video position bufferLen, bufferStart, bufferEnd, bufferStartNext, i; @@ -99,6 +105,4 @@ const BufferHelper = { } return { len: bufferLen, start: bufferStart, end: bufferEnd, nextStart: bufferStartNext }; } -}; - -export default BufferHelper; +} diff --git a/src/helper/fragment-tracker.js b/src/controller/fragment-tracker.js similarity index 100% rename from src/helper/fragment-tracker.js rename to src/controller/fragment-tracker.js diff --git a/src/helper/level-helper.js b/src/controller/level-helper.js similarity index 96% rename from src/helper/level-helper.js rename to src/controller/level-helper.js index 9dcde116b2d..9e3f79d2bd6 100644 --- a/src/helper/level-helper.js +++ b/src/controller/level-helper.js @@ -1,6 +1,11 @@ /** - * Level Helper class, providing methods dealing with playlist sliding and drift -*/ + * @module LevelHelper + * + * Providing methods dealing with playlist sliding and drift + * + * TODO: Create an actual `Level` class/model that deals with all this logic in an object-oriented-manner. + * + * */ import { logger } from '../utils/logger'; diff --git a/src/controller/stream-controller.js b/src/controller/stream-controller.js index f209452c633..532055ffe9a 100644 --- a/src/controller/stream-controller.js +++ b/src/controller/stream-controller.js @@ -3,13 +3,13 @@ */ import BinarySearch from '../utils/binary-search'; -import BufferHelper from '../helper/buffer-helper'; +import { BufferHelper } from './buffer-helper'; import Demuxer from '../demux/demuxer'; import Event from '../events'; -import { FragmentState } from '../helper/fragment-tracker'; +import { FragmentState } from './fragment-tracker'; import Fragment from '../loader/fragment'; import PlaylistLoader from '../loader/playlist-loader'; -import * as LevelHelper from '../helper/level-helper'; +import * as LevelHelper from './level-helper'; import TimeRanges from '../utils/time-ranges'; import { ErrorTypes, ErrorDetails } from '../errors'; import { logger } from '../utils/logger'; diff --git a/src/demux/demuxer.js b/src/demux/demuxer.js index 51ae0b47d4d..8720849ab36 100644 --- a/src/demux/demuxer.js +++ b/src/demux/demuxer.js @@ -1,10 +1,11 @@ +import EventEmitter from 'events'; +import work from 'webworkify-webpack'; + import Event from '../events'; import DemuxerInline from '../demux/demuxer-inline'; import { logger } from '../utils/logger'; import { ErrorTypes, ErrorDetails } from '../errors'; -import EventEmitter from 'events'; -import work from 'webworkify-webpack'; -import { getMediaSource } from '../helper/mediasource-helper'; +import { getMediaSource } from '../utils/mediasource-helper'; const MediaSource = getMediaSource(); diff --git a/src/hls.js b/src/hls.js index 4c656620a57..5a7ddeed27e 100644 --- a/src/hls.js +++ b/src/hls.js @@ -9,14 +9,14 @@ import PlaylistLoader from './loader/playlist-loader'; import FragmentLoader from './loader/fragment-loader'; import KeyLoader from './loader/key-loader'; +import { FragmentTracker } from './controller/fragment-tracker'; import StreamController from './controller/stream-controller'; import LevelController from './controller/level-controller'; import ID3TrackController from './controller/id3-track-controller'; -import { isSupported } from './helper/is-supported'; +import { isSupported } from './is-supported'; import { logger, enableLogs } from './utils/logger'; import { hlsDefaultConfig } from './config'; -import { FragmentTracker } from './helper/fragment-tracker'; import HlsEvents from './events'; import EventEmitter from 'events'; diff --git a/src/helper/is-supported.js b/src/is-supported.js similarity index 92% rename from src/helper/is-supported.js rename to src/is-supported.js index c6258f86fb5..54a2fc6d3d3 100644 --- a/src/helper/is-supported.js +++ b/src/is-supported.js @@ -1,4 +1,4 @@ -import { getMediaSource } from './mediasource-helper'; +import { getMediaSource } from './utils/mediasource-helper'; export function isSupported () { const mediaSource = getMediaSource(); diff --git a/src/helper/mediakeys-helper.js b/src/utils/mediakeys-helper.js similarity index 100% rename from src/helper/mediakeys-helper.js rename to src/utils/mediakeys-helper.js diff --git a/src/helper/mediasource-helper.js b/src/utils/mediasource-helper.js similarity index 100% rename from src/helper/mediasource-helper.js rename to src/utils/mediasource-helper.js diff --git a/tests/unit/helper/buffer-helper.js b/tests/unit/controller/buffer-helper.js similarity index 98% rename from tests/unit/helper/buffer-helper.js rename to tests/unit/controller/buffer-helper.js index c9226f9ebae..852587bec74 100644 --- a/tests/unit/helper/buffer-helper.js +++ b/tests/unit/controller/buffer-helper.js @@ -1,5 +1,6 @@ const assert = require('assert'); -import BufferHelper from '../../../src/helper/buffer-helper'; + +import BufferHelper from '../../../src/controller/buffer-helper'; function createMockBuffer (buffered) { return { diff --git a/tests/unit/helper/fragment-tracker.js b/tests/unit/controller/fragment-tracker.js similarity index 99% rename from tests/unit/helper/fragment-tracker.js rename to tests/unit/controller/fragment-tracker.js index c37bce3d456..a4dc264b95d 100644 --- a/tests/unit/helper/fragment-tracker.js +++ b/tests/unit/controller/fragment-tracker.js @@ -1,10 +1,10 @@ -import Event from '../../../src/events'; - const assert = require('assert'); import Hls from '../../../src/hls'; -import { FragmentTracker, FragmentState } from '../../../src/helper/fragment-tracker'; +import Event from '../../../src/events'; +import { FragmentTracker, FragmentState } from '../../../src/controller/fragment-tracker'; import PlaylistLoader from '../../../src/loader/playlist-loader'; + const LevelType = PlaylistLoader.LevelType; function createMockBuffer (buffered) {