From f3f76d343b19dedde6cf0a81f1fcf9caf1f55785 Mon Sep 17 00:00:00 2001 From: Rob Walch Date: Fri, 4 Oct 2024 17:01:02 -0700 Subject: [PATCH] Add import/order eslint rules and run `npm run lint:fix` --- .eslintrc.js | 27 +++++ src/config.ts | 26 ++--- src/controller/abr-controller.ts | 24 ++-- src/controller/audio-stream-controller.ts | 42 +++---- src/controller/audio-track-controller.ts | 16 +-- src/controller/base-playlist-controller.ts | 12 +- src/controller/base-stream-controller.ts | 56 ++++----- src/controller/buffer-controller.ts | 34 +++--- src/controller/cap-level-controller.ts | 12 +- src/controller/cmcd-controller.ts | 20 ++-- src/controller/content-steering-controller.ts | 15 ++- src/controller/eme-controller.ts | 27 ++--- src/controller/error-controller.ts | 13 ++- src/controller/fps-controller.ts | 4 +- src/controller/fragment-tracker.ts | 16 +-- src/controller/gap-controller.ts | 12 +- src/controller/id3-track-controller.ts | 22 ++-- src/controller/interstitial-player.ts | 6 +- src/controller/interstitials-controller.ts | 30 ++--- src/controller/interstitials-schedule.ts | 6 +- src/controller/latency-controller.ts | 6 +- src/controller/level-controller.ts | 30 ++--- src/controller/stream-controller.ts | 28 +++-- src/controller/subtitle-stream-controller.ts | 29 ++--- src/controller/subtitle-track-controller.ts | 24 ++-- src/controller/timeline-controller.ts | 49 ++++---- src/crypt/decrypter.ts | 4 +- src/demux/audio/aacdemuxer.ts | 6 +- src/demux/audio/ac3-demuxer.ts | 2 +- src/demux/audio/adts.ts | 6 +- src/demux/audio/base-audio-demuxer.ts | 18 +-- src/demux/audio/mp3demuxer.ts | 6 +- src/demux/mp4demuxer.ts | 22 ++-- src/demux/sample-aes.ts | 10 +- src/demux/transmuxer-interface.ts | 17 ++- src/demux/transmuxer-worker.ts | 6 +- src/demux/transmuxer.ts | 20 ++-- src/demux/tsdemuxer.ts | 28 ++--- src/demux/video/avc-video-parser.ts | 8 +- src/demux/video/base-video-parser.ts | 6 +- src/demux/video/hevc-video-parser.ts | 10 +- src/events.ts | 108 +++++++++--------- src/exports-named.ts | 8 +- src/hls.ts | 68 ++++++----- src/is-supported.ts | 2 +- src/loader/fragment-loader.ts | 6 +- src/loader/fragment.ts | 4 +- src/loader/interstitial-asset-list.ts | 9 +- src/loader/interstitial-event.ts | 4 +- src/loader/key-loader.ts | 26 ++--- src/loader/level-details.ts | 4 +- src/loader/level-key.ts | 4 +- src/loader/m3u8-parser.ts | 13 ++- src/loader/playlist-loader.ts | 28 ++--- src/remux/mp4-generator.ts | 2 +- src/remux/mp4-remuxer.ts | 34 +++--- src/remux/passthrough-remuxer.ts | 31 +++-- src/types/events.ts | 50 ++++---- src/types/fragment-tracker.ts | 2 +- src/types/loader.ts | 2 +- src/types/media-playlist.ts | 4 +- src/types/remuxer.ts | 4 +- src/types/track.ts | 2 +- src/types/transmuxer.ts | 4 +- src/utils/attr-list.ts | 4 +- src/utils/cea-608-parser.ts | 2 +- src/utils/cues.ts | 4 +- src/utils/discontinuities.ts | 3 +- src/utils/error-helper.ts | 2 +- src/utils/fetch-loader.ts | 14 +-- src/utils/imsc1-ttml-parser.ts | 10 +- src/utils/mediacapabilities-helper.ts | 2 +- src/utils/mediakeys-helper.ts | 2 +- src/utils/mp4-tools.ts | 8 +- src/utils/output-filter.ts | 2 +- src/utils/variable-substitution.ts | 2 +- src/utils/webvtt-parser.ts | 8 +- src/utils/xhr-loader.ts | 13 ++- tests/mocks/hls.mock.ts | 7 +- tests/mocks/loader.mock.ts | 2 +- tests/unit/controller/abr-controller.ts | 23 ++-- .../controller/audio-stream-controller.ts | 27 +++-- .../unit/controller/audio-track-controller.ts | 25 ++-- .../unit/controller/base-stream-controller.ts | 11 +- .../buffer-controller-operations.ts | 23 ++-- tests/unit/controller/buffer-controller.ts | 25 ++-- .../unit/controller/buffer-operation-queue.ts | 7 +- tests/unit/controller/cmcd-controller.ts | 7 +- .../controller/content-steering-controller.ts | 26 ++--- tests/unit/controller/eme-controller.ts | 16 ++- tests/unit/controller/error-controller.ts | 13 +-- tests/unit/controller/fragment-tracker.ts | 15 ++- .../controller/interstitials-controller.ts | 13 +-- tests/unit/controller/latency-controller.ts | 11 +- tests/unit/controller/level-controller.ts | 26 ++--- tests/unit/controller/level-helper.ts | 17 +-- tests/unit/controller/stream-controller.ts | 29 +++-- .../controller/subtitle-track-controller.ts | 21 ++-- tests/unit/demuxer/base-audio-demuxer.ts | 2 +- tests/unit/demuxer/transmuxer.ts | 17 +-- tests/unit/hls.ts | 11 +- tests/unit/loader/date-range.ts | 3 +- tests/unit/loader/fragment-loader.ts | 15 ++- tests/unit/loader/fragment.ts | 5 +- tests/unit/loader/playlist-loader.ts | 11 +- tests/unit/utils/discontinuities.ts | 20 ++-- tests/unit/utils/utf8.ts | 2 +- tests/unit/utils/vttparser.ts | 2 +- 108 files changed, 833 insertions(+), 849 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index a29341f16fd..81e9d40eda7 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -86,6 +86,30 @@ module.exports = { 'no-unused-vars': 0, 'no-undef': 0, 'no-use-before-define': 'off', + 'import/order': [ + 'warn', + { + alphabetize: { + order: 'asc', + }, + groups: [ + 'builtin', + 'external', + 'internal', + ['sibling', 'index'], + 'parent', + 'type', + ], + 'newlines-between': 'never', + }, + ], + 'sort-imports': [ + 'error', + { + ignoreCase: true, + ignoreDeclarationSort: true, + }, + ], '@typescript-eslint/no-unused-vars': [ 'warn', { @@ -100,6 +124,9 @@ module.exports = { objectLiteralTypeAssertions: 'never', }, ], + '@typescript-eslint/consistent-type-imports': 'error', + '@typescript-eslint/no-import-type-side-effects': 'error', + '@typescript-eslint/no-restricted-imports': 'error', }, }, ], diff --git a/src/config.ts b/src/config.ts index 9a7881d8e9d..71580fea286 100644 --- a/src/config.ts +++ b/src/config.ts @@ -1,28 +1,23 @@ import AbrController from './controller/abr-controller'; import AudioStreamController from './controller/audio-stream-controller'; import AudioTrackController from './controller/audio-track-controller'; -import { SubtitleStreamController } from './controller/subtitle-stream-controller'; -import SubtitleTrackController from './controller/subtitle-track-controller'; import BufferController from './controller/buffer-controller'; -import { TimelineController } from './controller/timeline-controller'; import CapLevelController from './controller/cap-level-controller'; -import FPSController from './controller/fps-controller'; -import EMEController, { - MediaKeySessionContext, -} from './controller/eme-controller'; import CMCDController from './controller/cmcd-controller'; import ContentSteeringController from './controller/content-steering-controller'; -import InterstitialsController from './controller/interstitials-controller'; +import EMEController from './controller/eme-controller'; import ErrorController from './controller/error-controller'; -import XhrLoader from './utils/xhr-loader'; -import FetchLoader, { fetchSupported } from './utils/fetch-loader'; +import FPSController from './controller/fps-controller'; +import InterstitialsController from './controller/interstitials-controller'; +import { SubtitleStreamController } from './controller/subtitle-stream-controller'; +import SubtitleTrackController from './controller/subtitle-track-controller'; +import { TimelineController } from './controller/timeline-controller'; import Cues from './utils/cues'; +import FetchLoader, { fetchSupported } from './utils/fetch-loader'; import { requestMediaKeySystemAccess } from './utils/mediakeys-helper'; - +import XhrLoader from './utils/xhr-loader'; +import type { MediaKeySessionContext } from './controller/eme-controller'; import type Hls from './hls'; -import type { CuesInterface } from './utils/cues'; -import type { ILogger } from './utils/logger'; -import type { MediaKeyFunc, KeySystems } from './utils/mediakeys-helper'; import type { FragmentLoaderContext, Loader, @@ -35,6 +30,9 @@ import type { SubtitleSelectionOption, VideoSelectionOption, } from './types/media-playlist'; +import type { CuesInterface } from './utils/cues'; +import type { ILogger } from './utils/logger'; +import type { KeySystems, MediaKeyFunc } from './utils/mediakeys-helper'; export type ABRControllerConfig = { abrEwmaFastLive: number; diff --git a/src/controller/abr-controller.ts b/src/controller/abr-controller.ts index 9c9b3b64345..59000e55911 100644 --- a/src/controller/abr-controller.ts +++ b/src/controller/abr-controller.ts @@ -1,35 +1,35 @@ -import EwmaBandWidthEstimator from '../utils/ewma-bandwidth-estimator'; -import { Events } from '../events'; import { ErrorDetails } from '../errors'; +import { Events } from '../events'; import { PlaylistLevelType } from '../types/loader'; +import EwmaBandWidthEstimator from '../utils/ewma-bandwidth-estimator'; import { Logger } from '../utils/logger'; import { - SUPPORTED_INFO_DEFAULT, getMediaDecodingInfoPromise, requiresMediaCapabilitiesDecodingInfo, + SUPPORTED_INFO_DEFAULT, } from '../utils/mediacapabilities-helper'; import { + type AudioTracksByGroup, + type CodecSetTier, getAudioTracksByGroup, getCodecTiers, getStartCodecTier, - type AudioTracksByGroup, - type CodecSetTier, } from '../utils/rendition-helper'; +import type Hls from '../hls'; import type { Fragment } from '../loader/fragment'; import type { Part } from '../loader/fragment'; -import type { Level, VideoRange } from '../types/level'; -import type { LoaderStats } from '../types/loader'; -import type Hls from '../hls'; +import type { AbrComponentAPI } from '../types/component-api'; import type { - FragLoadingData, - FragLoadedData, + ErrorData, FragBufferedData, + FragLoadedData, + FragLoadingData, LevelLoadedData, LevelSwitchingData, ManifestLoadingData, - ErrorData, } from '../types/events'; -import type { AbrComponentAPI } from '../types/component-api'; +import type { Level, VideoRange } from '../types/level'; +import type { LoaderStats } from '../types/loader'; class AbrController extends Logger implements AbrComponentAPI { protected hls: Hls; diff --git a/src/controller/audio-stream-controller.ts b/src/controller/audio-stream-controller.ts index 53f454f01d4..696e5a401f2 100644 --- a/src/controller/audio-stream-controller.ts +++ b/src/controller/audio-stream-controller.ts @@ -1,48 +1,44 @@ import BaseStreamController, { State } from './base-stream-controller'; -import { Events } from '../events'; +import { findFragWithCC, findNearestWithCC } from './fragment-finders'; import { FragmentState } from './fragment-tracker'; -import { Level } from '../types/level'; -import { PlaylistContextType, PlaylistLevelType } from '../types/loader'; -import { - Fragment, - ElementaryStreamTypes, - Part, - MediaFragment, -} from '../loader/fragment'; import ChunkCache from '../demux/chunk-cache'; import TransmuxerInterface from '../demux/transmuxer-interface'; +import { ErrorDetails } from '../errors'; +import { Events } from '../events'; +import { ElementaryStreamTypes } from '../loader/fragment'; +import { Level } from '../types/level'; +import { PlaylistContextType, PlaylistLevelType } from '../types/loader'; import { ChunkMetadata } from '../types/transmuxer'; -import { findFragWithCC, findNearestWithCC } from './fragment-finders'; import { alignMediaPlaylistByPDT } from '../utils/discontinuities'; import { mediaAttributesIdentical } from '../utils/media-option-attributes'; -import { ErrorDetails } from '../errors'; -import type { NetworkComponentAPI } from '../types/component-api'; import type Hls from '../hls'; import type { FragmentTracker } from './fragment-tracker'; +import type { Fragment, MediaFragment, Part } from '../loader/fragment'; import type KeyLoader from '../loader/key-loader'; -import type { TransmuxerResult } from '../types/transmuxer'; import type { LevelDetails } from '../loader/level-details'; -import type { TrackSet } from '../types/track'; +import type { NetworkComponentAPI } from '../types/component-api'; import type { - BufferCreatedData, AudioTracksUpdatedData, AudioTrackSwitchingData, - LevelLoadedData, - TrackLoadedData, BufferAppendingData, + BufferCodecsData, + BufferCreatedData, BufferFlushedData, - InitPTSFoundData, + BufferFlushingData, + ErrorData, + FragBufferedData, FragLoadedData, + FragLoadingData, FragParsingMetadataData, FragParsingUserdataData, - FragBufferedData, - ErrorData, - BufferFlushingData, - BufferCodecsData, - FragLoadingData, + InitPTSFoundData, + LevelLoadedData, MediaDetachingData, + TrackLoadedData, } from '../types/events'; import type { MediaPlaylist } from '../types/media-playlist'; +import type { TrackSet } from '../types/track'; +import type { TransmuxerResult } from '../types/transmuxer'; const TICK_INTERVAL = 100; // how often to tick in ms diff --git a/src/controller/audio-track-controller.ts b/src/controller/audio-track-controller.ts index 15ceeef2993..079ef312c3c 100644 --- a/src/controller/audio-track-controller.ts +++ b/src/controller/audio-track-controller.ts @@ -1,6 +1,6 @@ import BasePlaylistController from './base-playlist-controller'; +import { ErrorDetails, ErrorTypes } from '../errors'; import { Events } from '../events'; -import { ErrorTypes, ErrorDetails } from '../errors'; import { PlaylistContextType } from '../types/loader'; import { mediaAttributesIdentical } from '../utils/media-option-attributes'; import { @@ -11,18 +11,18 @@ import { } from '../utils/rendition-helper'; import type Hls from '../hls'; import type { - AudioSelectionOption, - MediaPlaylist, -} from '../types/media-playlist'; -import type { HlsUrlParameters } from '../types/level'; -import type { - ManifestParsedData, + AudioTrackLoadedData, AudioTracksUpdatedData, ErrorData, LevelLoadingData, - AudioTrackLoadedData, LevelSwitchingData, + ManifestParsedData, } from '../types/events'; +import type { HlsUrlParameters } from '../types/level'; +import type { + AudioSelectionOption, + MediaPlaylist, +} from '../types/media-playlist'; class AudioTrackController extends BasePlaylistController { private tracks: MediaPlaylist[] = []; diff --git a/src/controller/base-playlist-controller.ts b/src/controller/base-playlist-controller.ts index 4dc34ab207d..7f7f34eb0ae 100644 --- a/src/controller/base-playlist-controller.ts +++ b/src/controller/base-playlist-controller.ts @@ -1,23 +1,23 @@ -import type Hls from '../hls'; -import type { NetworkComponentAPI } from '../types/component-api'; +import { NetworkErrorAction } from './error-controller'; import { getSkipValue, HlsSkip, HlsUrlParameters, type Level, } from '../types/level'; -import { computeReloadInterval, mergeDetails } from '../utils/level-helper'; -import type { ErrorData } from '../types/events'; import { getRetryDelay, isTimeoutError } from '../utils/error-helper'; -import { NetworkErrorAction } from './error-controller'; +import { computeReloadInterval, mergeDetails } from '../utils/level-helper'; import { Logger } from '../utils/logger'; +import type Hls from '../hls'; import type { LevelDetails } from '../loader/level-details'; -import type { MediaPlaylist } from '../types/media-playlist'; +import type { NetworkComponentAPI } from '../types/component-api'; +import type { ErrorData } from '../types/events'; import type { AudioTrackLoadedData, LevelLoadedData, TrackLoadedData, } from '../types/events'; +import type { MediaPlaylist } from '../types/media-playlist'; export default class BasePlaylistController extends Logger diff --git a/src/controller/base-stream-controller.ts b/src/controller/base-stream-controller.ts index 37cda1cb33f..0fbb4aad5d0 100644 --- a/src/controller/base-stream-controller.ts +++ b/src/controller/base-stream-controller.ts @@ -1,57 +1,59 @@ -import TaskLoop from '../task-loop'; +import { NetworkErrorAction } from './error-controller'; +import { + findFragmentByPDT, + findFragmentByPTS, + findFragWithCC, +} from './fragment-finders'; import { FragmentState } from './fragment-tracker'; -import { Bufferable, BufferHelper, BufferInfo } from '../utils/buffer-helper'; -import { Events } from '../events'; +import Decrypter from '../crypt/decrypter'; import { ErrorDetails, ErrorTypes } from '../errors'; +import { Events } from '../events'; +import FragmentLoader from '../loader/fragment-loader'; +import TaskLoop from '../task-loop'; +import { PlaylistLevelType } from '../types/loader'; import { ChunkMetadata } from '../types/transmuxer'; -import { appendUint8Array } from '../utils/mp4-tools'; +import { BufferHelper } from '../utils/buffer-helper'; import { alignStream } from '../utils/discontinuities'; import { - isFullSegmentEncryption, getAesModeFromFullSegmentMethod, + isFullSegmentEncryption, } from '../utils/encryption-methods-util'; -import { - findFragmentByPDT, - findFragmentByPTS, - findFragWithCC, -} from './fragment-finders'; +import { getRetryDelay } from '../utils/error-helper'; import { findPart, getFragmentWithSN, getPartWith, updateFragPTSDTS, } from '../utils/level-helper'; -import TransmuxerInterface from '../demux/transmuxer-interface'; -import { Fragment, MediaFragment, Part } from '../loader/fragment'; -import FragmentLoader, { +import { appendUint8Array } from '../utils/mp4-tools'; +import TimeRanges from '../utils/time-ranges'; +import type { FragmentTracker } from './fragment-tracker'; +import type { HlsConfig } from '../config'; +import type TransmuxerInterface from '../demux/transmuxer-interface'; +import type Hls from '../hls'; +import type { Fragment, MediaFragment, Part } from '../loader/fragment'; +import type { FragmentLoadProgressCallback, LoadError, } from '../loader/fragment-loader'; -import KeyLoader from '../loader/key-loader'; -import Decrypter from '../crypt/decrypter'; -import TimeRanges from '../utils/time-ranges'; -import { PlaylistLevelType } from '../types/loader'; -import { getRetryDelay } from '../utils/error-helper'; -import { NetworkErrorAction } from './error-controller'; +import type KeyLoader from '../loader/key-loader'; import type { LevelDetails } from '../loader/level-details'; +import type { SourceBufferName } from '../types/buffer'; +import type { NetworkComponentAPI } from '../types/component-api'; import type { BufferAppendingData, + BufferFlushingData, ErrorData, FragLoadedData, - PartsLoadedData, KeyLoadedData, - MediaAttachedData, - BufferFlushingData, ManifestLoadedData, + MediaAttachedData, MediaDetachingData, + PartsLoadedData, } from '../types/events'; -import type { FragmentTracker } from './fragment-tracker'; import type { Level } from '../types/level'; import type { RemuxedTrack } from '../types/remuxer'; -import type Hls from '../hls'; -import type { HlsConfig } from '../config'; -import type { NetworkComponentAPI } from '../types/component-api'; -import type { SourceBufferName } from '../types/buffer'; +import type { Bufferable, BufferInfo } from '../utils/buffer-helper'; import type { RationalTimestamp } from '../utils/timescale-conversion'; type ResolveFragLoaded = (FragLoadedEndData) => void; diff --git a/src/controller/buffer-controller.ts b/src/controller/buffer-controller.ts index c014008aac7..8b8b2b8d6f1 100755 --- a/src/controller/buffer-controller.ts +++ b/src/controller/buffer-controller.ts @@ -1,21 +1,25 @@ -import { Events } from '../events'; -import { Logger } from '../utils/logger'; +import BufferOperationQueue from './buffer-operation-queue'; +import { createDoNothingErrorAction } from './error-controller'; import { ErrorDetails, ErrorTypes } from '../errors'; +import { Events } from '../events'; +import { ElementaryStreamTypes } from '../loader/fragment'; +import { PlaylistLevelType } from '../types/loader'; import { BufferHelper } from '../utils/buffer-helper'; import { getCodecCompatibleName, pickMostCompleteCodecName, } from '../utils/codecs'; +import { Logger } from '../utils/logger'; import { getMediaSource, isCompatibleTrackChange, isManagedMediaSource, } from '../utils/mediasource-helper'; -import { ElementaryStreamTypes } from '../loader/fragment'; -import { PlaylistLevelType } from '../types/loader'; -import BufferOperationQueue from './buffer-operation-queue'; -import { createDoNothingErrorAction } from './error-controller'; +import type Hls from '../hls'; +import type { FragmentTracker } from './fragment-tracker'; +import type { HlsConfig } from '../config'; import type { MediaFragment, Part } from '../loader/fragment'; +import type { LevelDetails } from '../loader/level-details'; import type { AttachMediaSourceData, BaseTrack, @@ -27,29 +31,25 @@ import type { MediaOverrides, ParsedTrack, SourceBufferName, + SourceBuffersTuple, SourceBufferTrack, SourceBufferTrackSet, - SourceBuffersTuple, } from '../types/buffer'; +import type { ComponentAPI } from '../types/component-api'; import type { - LevelUpdatedData, BufferAppendingData, - MediaAttachingData, - ManifestParsedData, BufferCodecsData, BufferEOSData, BufferFlushingData, - FragParsedData, - FragChangedData, ErrorData, + FragChangedData, + FragParsedData, + LevelUpdatedData, + ManifestParsedData, + MediaAttachingData, MediaDetachingData, } from '../types/events'; -import type { ComponentAPI } from '../types/component-api'; import type { ChunkMetadata } from '../types/transmuxer'; -import type Hls from '../hls'; -import type { FragmentTracker } from './fragment-tracker'; -import type { LevelDetails } from '../loader/level-details'; -import type { HlsConfig } from '../config'; interface BufferedChangeEvent extends Event { readonly addedRanges?: TimeRanges; diff --git a/src/controller/cap-level-controller.ts b/src/controller/cap-level-controller.ts index b39ec026ed3..9301e228dc9 100644 --- a/src/controller/cap-level-controller.ts +++ b/src/controller/cap-level-controller.ts @@ -3,17 +3,17 @@ */ import { Events } from '../events'; -import type { Level } from '../types/level'; +import type StreamController from './stream-controller'; +import type Hls from '../hls'; +import type { ComponentAPI } from '../types/component-api'; import type { - ManifestParsedData, BufferCodecsData, - MediaAttachingData, FPSDropLevelCappingData, LevelsUpdatedData, + ManifestParsedData, + MediaAttachingData, } from '../types/events'; -import StreamController from './stream-controller'; -import type { ComponentAPI } from '../types/component-api'; -import type Hls from '../hls'; +import type { Level } from '../types/level'; type RestrictedLevel = { width: number; height: number; bitrate: number }; class CapLevelController implements ComponentAPI { diff --git a/src/controller/cmcd-controller.ts b/src/controller/cmcd-controller.ts index bc5cf12a7d3..91a15c57814 100644 --- a/src/controller/cmcd-controller.ts +++ b/src/controller/cmcd-controller.ts @@ -1,15 +1,18 @@ -import { Events } from '../events'; -import type Hls from '../hls'; -import { Cmcd } from '@svta/common-media-library/cmcd/Cmcd'; import { CmcdObjectType } from '@svta/common-media-library/cmcd/CmcdObjectType'; import { CmcdStreamingFormat } from '@svta/common-media-library/cmcd/CmcdStreamingFormat'; import { appendCmcdHeaders } from '@svta/common-media-library/cmcd/appendCmcdHeaders'; import { appendCmcdQuery } from '@svta/common-media-library/cmcd/appendCmcdQuery'; -import type { CmcdEncodeOptions } from '@svta/common-media-library/cmcd/CmcdEncodeOptions'; +import { Events } from '../events'; import { BufferHelper } from '../utils/buffer-helper'; +import type { + FragmentLoaderConstructor, + HlsConfig, + PlaylistLoaderConstructor, +} from '../config'; +import type Hls from '../hls'; +import type { Fragment, Part } from '../loader/fragment'; import type { ExtendedSourceBuffer } from '../types/buffer'; import type { ComponentAPI } from '../types/component-api'; -import type { Fragment, Part } from '../loader/fragment'; import type { BufferCreatedData, MediaAttachedData } from '../types/events'; import type { FragmentLoaderContext, @@ -19,11 +22,8 @@ import type { LoaderContext, PlaylistLoaderContext, } from '../types/loader'; -import type { - FragmentLoaderConstructor, - HlsConfig, - PlaylistLoaderConstructor, -} from '../config'; +import type { Cmcd } from '@svta/common-media-library/cmcd/Cmcd'; +import type { CmcdEncodeOptions } from '@svta/common-media-library/cmcd/CmcdEncodeOptions'; /** * Controller to deal with Common Media Client Data (CMCD) diff --git a/src/controller/content-steering-controller.ts b/src/controller/content-steering-controller.ts index 2801cba8afc..9d150a9e767 100644 --- a/src/controller/content-steering-controller.ts +++ b/src/controller/content-steering-controller.ts @@ -1,28 +1,27 @@ +import { ErrorActionFlags, NetworkErrorAction } from './error-controller'; import { Events } from '../events'; import { Level } from '../types/level'; -import { reassignFragmentLevelIndexes } from '../utils/level-helper'; -import { AttrList } from '../utils/attr-list'; -import { ErrorActionFlags, NetworkErrorAction } from './error-controller'; -import { Logger } from '../utils/logger'; import { - PlaylistContextType, type Loader, type LoaderCallbacks, type LoaderConfiguration, type LoaderContext, type LoaderResponse, type LoaderStats, + PlaylistContextType, } from '../types/loader'; +import { AttrList } from '../utils/attr-list'; +import { reassignFragmentLevelIndexes } from '../utils/level-helper'; +import { Logger } from '../utils/logger'; +import type { RetryConfig } from '../config'; import type Hls from '../hls'; import type { NetworkComponentAPI } from '../types/component-api'; import type { - SteeringManifestLoadedData, ErrorData, ManifestLoadedData, ManifestParsedData, + SteeringManifestLoadedData, } from '../types/events'; -import type { RetryConfig } from '../config'; - import type { MediaAttributes, MediaPlaylist } from '../types/media-playlist'; export type SteeringManifest = { diff --git a/src/controller/eme-controller.ts b/src/controller/eme-controller.ts index 5fd9eea11b3..ecdfc9e1660 100644 --- a/src/controller/eme-controller.ts +++ b/src/controller/eme-controller.ts @@ -3,24 +3,22 @@ * * DRM support for Hls.js */ +import { EventEmitter } from 'eventemitter3'; +import { ErrorDetails, ErrorTypes } from '../errors'; import { Events } from '../events'; -import { ErrorTypes, ErrorDetails } from '../errors'; +import { LevelKey } from '../loader/level-key'; +import Hex from '../utils/hex'; import { Logger } from '../utils/logger'; import { getKeySystemsForConfig, getSupportedMediaKeySystemConfigurations, - keySystemDomainToKeySystemFormat as keySystemToKeySystemFormat, - KeySystemFormats, keySystemFormatToKeySystemDomain, keySystemIdToKeySystemDomain, KeySystems, - requestMediaKeySystemAccess, + keySystemDomainToKeySystemFormat as keySystemToKeySystemFormat, parsePlayReadyWRM, + requestMediaKeySystemAccess, } from '../utils/mediakeys-helper'; -import { strToUtf8array } from '../utils/utf8-utils'; -import { base64Decode } from '../utils/numeric-encoding-utils'; -import { DecryptData, LevelKey } from '../loader/level-key'; -import Hex from '../utils/hex'; import { bin2str, parseMultiPssh, @@ -28,23 +26,26 @@ import { type PsshData, type PsshInvalidResult, } from '../utils/mp4-tools'; -import { EventEmitter } from 'eventemitter3'; +import { base64Decode } from '../utils/numeric-encoding-utils'; +import { strToUtf8array } from '../utils/utf8-utils'; +import type { EMEControllerConfig, HlsConfig, LoadPolicy } from '../config'; import type Hls from '../hls'; +import type { Fragment } from '../loader/fragment'; +import type { DecryptData } from '../loader/level-key'; import type { ComponentAPI } from '../types/component-api'; import type { - MediaAttachedData, - KeyLoadedData, ErrorData, + KeyLoadedData, ManifestLoadedData, + MediaAttachedData, } from '../types/events'; -import type { EMEControllerConfig, HlsConfig, LoadPolicy } from '../config'; -import type { Fragment } from '../loader/fragment'; import type { Loader, LoaderCallbacks, LoaderConfiguration, LoaderContext, } from '../types/loader'; +import type { KeySystemFormats } from '../utils/mediakeys-helper'; interface KeySystemAccessPromises { keySystemAccess: Promise; mediaKeys?: Promise; diff --git a/src/controller/error-controller.ts b/src/controller/error-controller.ts index aca730efba2..2745894325e 100644 --- a/src/controller/error-controller.ts +++ b/src/controller/error-controller.ts @@ -1,20 +1,21 @@ -import { Events } from '../events'; +import { findFragmentByPTS } from './fragment-finders'; import { ErrorDetails, ErrorTypes } from '../errors'; +import { Events } from '../events'; +import { HdcpLevels } from '../types/level'; import { PlaylistContextType, PlaylistLevelType } from '../types/loader'; import { getRetryConfig, isTimeoutError, shouldRetry, } from '../utils/error-helper'; -import { findFragmentByPTS } from './fragment-finders'; -import { HdcpLevel, HdcpLevels } from '../types/level'; import { Logger } from '../utils/logger'; -import type Hls from '../hls'; import type { RetryConfig } from '../config'; -import type { NetworkComponentAPI } from '../types/component-api'; -import type { ErrorData } from '../types/events'; +import type Hls from '../hls'; import type { Fragment, MediaFragment } from '../loader/fragment'; import type { LevelDetails } from '../loader/level-details'; +import type { NetworkComponentAPI } from '../types/component-api'; +import type { ErrorData } from '../types/events'; +import type { HdcpLevel } from '../types/level'; export const enum NetworkErrorAction { DoNothing = 0, diff --git a/src/controller/fps-controller.ts b/src/controller/fps-controller.ts index ffa2fadf165..ef9f38668c0 100644 --- a/src/controller/fps-controller.ts +++ b/src/controller/fps-controller.ts @@ -1,8 +1,8 @@ import { Events } from '../events'; -import type { ComponentAPI } from '../types/component-api'; +import type StreamController from './stream-controller'; import type Hls from '../hls'; +import type { ComponentAPI } from '../types/component-api'; import type { MediaAttachingData } from '../types/events'; -import StreamController from './stream-controller'; class FPSController implements ComponentAPI { private hls: Hls; diff --git a/src/controller/fragment-tracker.ts b/src/controller/fragment-tracker.ts index 690c7c605e1..7f324a04525 100644 --- a/src/controller/fragment-tracker.ts +++ b/src/controller/fragment-tracker.ts @@ -1,19 +1,19 @@ import { Events } from '../events'; -import { Fragment, MediaFragment, Part } from '../loader/fragment'; -import { PlaylistLevelType } from '../types/loader'; +import type Hls from '../hls'; +import type { Fragment, MediaFragment, Part } from '../loader/fragment'; import type { SourceBufferName } from '../types/buffer'; -import type { - FragmentBufferedRange, - FragmentEntity, - FragmentTimeRange, -} from '../types/fragment-tracker'; import type { ComponentAPI } from '../types/component-api'; import type { BufferAppendedData, FragBufferedData, FragLoadedData, } from '../types/events'; -import type Hls from '../hls'; +import type { + FragmentBufferedRange, + FragmentEntity, + FragmentTimeRange, +} from '../types/fragment-tracker'; +import type { PlaylistLevelType } from '../types/loader'; export const enum FragmentState { NOT_LOADED = 'NOT_LOADED', diff --git a/src/controller/gap-controller.ts b/src/controller/gap-controller.ts index c8c6fecb9e1..43e5160094f 100644 --- a/src/controller/gap-controller.ts +++ b/src/controller/gap-controller.ts @@ -1,15 +1,15 @@ import { State } from './base-stream-controller'; -import { BufferHelper } from '../utils/buffer-helper'; -import { ErrorTypes, ErrorDetails } from '../errors'; -import { PlaylistLevelType } from '../types/loader'; +import { ErrorDetails, ErrorTypes } from '../errors'; import { Events } from '../events'; +import { PlaylistLevelType } from '../types/loader'; +import { BufferHelper } from '../utils/buffer-helper'; import { Logger } from '../utils/logger'; -import type Hls from '../hls'; -import type { BufferInfo } from '../utils/buffer-helper'; import type { HlsConfig } from '../config'; -import type { Fragment } from '../loader/fragment'; +import type Hls from '../hls'; import type { FragmentTracker } from './fragment-tracker'; +import type { Fragment } from '../loader/fragment'; import type { LevelDetails } from '../loader/level-details'; +import type { BufferInfo } from '../utils/buffer-helper'; export const STALL_MINIMUM_DURATION_MS = 250; export const MAX_START_GAP_JUMP = 2.0; diff --git a/src/controller/id3-track-controller.ts b/src/controller/id3-track-controller.ts index c73fe2c82d8..0c14155b227 100644 --- a/src/controller/id3-track-controller.ts +++ b/src/controller/id3-track-controller.ts @@ -1,16 +1,20 @@ +import { getId3Frames } from '@svta/common-media-library/id3/getId3Frames'; +import { isId3TimestampFrame } from '@svta/common-media-library/id3/isId3TimestampFrame'; import { Events } from '../events'; import { - sendAddTrackEvent, - clearCurrentCues, - removeCuesInRange, -} from '../utils/texttrack-utils'; -import { - DateRange, isDateRangeCueAttribute, isSCTE35Attribute, } from '../loader/date-range'; -import { LevelDetails } from '../loader/level-details'; import { MetadataSchema } from '../types/demuxer'; +import { + clearCurrentCues, + removeCuesInRange, + sendAddTrackEvent, +} from '../utils/texttrack-utils'; +import type Hls from '../hls'; +import type { DateRange } from '../loader/date-range'; +import type { LevelDetails } from '../loader/level-details'; +import type { ComponentAPI } from '../types/component-api'; import type { BufferFlushingData, FragParsingMetadataData, @@ -19,10 +23,6 @@ import type { MediaAttachingData, MediaDetachingData, } from '../types/events'; -import type { ComponentAPI } from '../types/component-api'; -import type Hls from '../hls'; -import { getId3Frames } from '@svta/common-media-library/id3/getId3Frames'; -import { isId3TimestampFrame } from '@svta/common-media-library/id3/isId3TimestampFrame'; declare global { interface Window { diff --git a/src/controller/interstitial-player.ts b/src/controller/interstitial-player.ts index e231b5e9c0a..fbac412f044 100644 --- a/src/controller/interstitial-player.ts +++ b/src/controller/interstitial-player.ts @@ -1,5 +1,4 @@ -import type Hls from '../hls'; -import type { HlsConfig } from '../config'; +import { Events, type HlsListeners } from '../events'; import { eventAssetToString, getInterstitialUrl, @@ -8,8 +7,9 @@ import { type InterstitialEvent, type InterstitialId, } from '../loader/interstitial-event'; -import { Events, type HlsListeners } from '../events'; import { BufferHelper } from '../utils/buffer-helper'; +import type { HlsConfig } from '../config'; +import type Hls from '../hls'; import type { BufferCodecsData, MediaAttachingData } from '../types/events'; export class HlsAssetPlayer { diff --git a/src/controller/interstitials-controller.ts b/src/controller/interstitials-controller.ts index 302af792e48..61b6bcdd745 100644 --- a/src/controller/interstitials-controller.ts +++ b/src/controller/interstitials-controller.ts @@ -1,50 +1,50 @@ import { createDoNothingErrorAction } from './error-controller'; +import { HlsAssetPlayer } from './interstitial-player'; import { - InterstitialsSchedule, - type TimelineType, type InterstitialScheduleEventItem, type InterstitialScheduleItem, type InterstitialSchedulePrimaryItem, + InterstitialsSchedule, segmentToString, + type TimelineType, } from './interstitials-schedule'; import { ErrorDetails, ErrorTypes } from '../errors'; import { Events } from '../events'; -import type Hls from '../hls'; +import { AssetListLoader } from '../loader/interstitial-asset-list'; import { + ALIGNED_END_THRESHOLD_SECONDS, + eventAssetToString, generateAssetIdentifier, - type InterstitialAssetItem, type InterstitialAssetId, + type InterstitialAssetItem, type InterstitialEvent, type InterstitialEventWithAssetList, TimelineOccupancy, - eventAssetToString, - ALIGNED_END_THRESHOLD_SECONDS, } from '../loader/interstitial-event'; -import { AssetListLoader } from '../loader/interstitial-asset-list'; -import { LevelDetails } from '../loader/level-details'; -import { HlsAssetPlayer } from './interstitial-player'; import { BufferHelper } from '../utils/buffer-helper'; import { hash } from '../utils/hash'; import { Logger } from '../utils/logger'; import { isCompatibleTrackChange } from '../utils/mediasource-helper'; import { getBasicSelectionOption } from '../utils/rendition-helper'; import type { HlsConfig } from '../config'; +import type Hls from '../hls'; +import type { LevelDetails } from '../loader/level-details'; import type { SourceBufferName } from '../types/buffer'; import type { NetworkComponentAPI } from '../types/component-api'; import type { + AssetListLoadedData, + AudioTrackSwitchingData, + AudioTrackUpdatedData, BufferAppendedData, + BufferCodecsData, + BufferFlushedData, ErrorData, - AssetListLoadedData, LevelUpdatedData, MediaAttachedData, MediaAttachingData, MediaDetachingData, - BufferCodecsData, - AudioTrackUpdatedData, - SubtitleTrackUpdatedData, - BufferFlushedData, SubtitleTrackSwitchData, - AudioTrackSwitchingData, + SubtitleTrackUpdatedData, } from '../types/events'; import type { MediaPlaylist, MediaSelection } from '../types/media-playlist'; diff --git a/src/controller/interstitials-schedule.ts b/src/controller/interstitials-schedule.ts index 436d634e9de..860db703fdc 100644 --- a/src/controller/interstitials-schedule.ts +++ b/src/controller/interstitials-schedule.ts @@ -1,14 +1,14 @@ import { findFragmentByPTS } from './fragment-finders'; import { - type BaseData, - type InterstitialId, ALIGNED_END_THRESHOLD_SECONDS, + type BaseData, InterstitialEvent, + type InterstitialId, TimelineOccupancy, } from '../loader/interstitial-event'; +import { logger } from '../utils/logger'; import type { DateRange } from '../loader/date-range'; import type { MediaSelection } from '../types/media-playlist'; -import { logger } from '../utils/logger'; const ABUTTING_THRESHOLD_SECONDS = 0.033; diff --git a/src/controller/latency-controller.ts b/src/controller/latency-controller.ts index 4769a943c0b..bf4953b5cb8 100644 --- a/src/controller/latency-controller.ts +++ b/src/controller/latency-controller.ts @@ -1,13 +1,13 @@ import { ErrorDetails } from '../errors'; import { Events } from '../events'; +import type { HlsConfig } from '../config'; +import type Hls from '../hls'; +import type { ComponentAPI } from '../types/component-api'; import type { ErrorData, LevelUpdatedData, MediaAttachingData, } from '../types/events'; -import type { ComponentAPI } from '../types/component-api'; -import type Hls from '../hls'; -import type { HlsConfig } from '../config'; export default class LatencyController implements ComponentAPI { private hls: Hls; diff --git a/src/controller/level-controller.ts b/src/controller/level-controller.ts index b74187412d3..08dc12a1429 100644 --- a/src/controller/level-controller.ts +++ b/src/controller/level-controller.ts @@ -1,16 +1,8 @@ -import type { - ManifestLoadedData, - ManifestParsedData, - LevelLoadedData, - ErrorData, - LevelSwitchingData, - LevelsUpdatedData, - ManifestLoadingData, - FragBufferedData, -} from '../types/events'; -import { Level, VideoRangeValues, isVideoRange } from '../types/level'; +import BasePlaylistController from './base-playlist-controller'; +import { ErrorDetails, ErrorTypes } from '../errors'; import { Events } from '../events'; -import { ErrorTypes, ErrorDetails } from '../errors'; +import { isVideoRange, Level, VideoRangeValues } from '../types/level'; +import { PlaylistContextType, PlaylistLevelType } from '../types/loader'; import { areCodecsMediaSourceSupported, codecsSetSelectionPreferenceValue, @@ -19,11 +11,19 @@ import { sampleEntryCodesISO, videoCodecPreferenceValue, } from '../utils/codecs'; -import BasePlaylistController from './base-playlist-controller'; -import { PlaylistContextType, PlaylistLevelType } from '../types/loader'; -import ContentSteeringController from './content-steering-controller'; import { reassignFragmentLevelIndexes } from '../utils/level-helper'; +import type ContentSteeringController from './content-steering-controller'; import type Hls from '../hls'; +import type { + ErrorData, + FragBufferedData, + LevelLoadedData, + LevelsUpdatedData, + LevelSwitchingData, + ManifestLoadedData, + ManifestLoadingData, + ManifestParsedData, +} from '../types/events'; import type { HlsUrlParameters, LevelParsed } from '../types/level'; import type { MediaPlaylist } from '../types/media-playlist'; diff --git a/src/controller/stream-controller.ts b/src/controller/stream-controller.ts index 6590068d803..a0346efb217 100644 --- a/src/controller/stream-controller.ts +++ b/src/controller/stream-controller.ts @@ -1,29 +1,23 @@ import BaseStreamController, { State } from './base-stream-controller'; -import { changeTypeSupported } from '../is-supported'; -import { Events } from '../events'; -import { BufferHelper, BufferInfo } from '../utils/buffer-helper'; import { findFragmentByPTS } from './fragment-finders'; import { FragmentState } from './fragment-tracker'; -import { PlaylistContextType, PlaylistLevelType } from '../types/loader'; -import { - ElementaryStreamTypes, - Fragment, - MediaFragment, -} from '../loader/fragment'; -import TransmuxerInterface from '../demux/transmuxer-interface'; -import { ChunkMetadata } from '../types/transmuxer'; import GapController, { MAX_START_GAP_JUMP } from './gap-controller'; +import TransmuxerInterface from '../demux/transmuxer-interface'; import { ErrorDetails } from '../errors'; +import { Events } from '../events'; +import { changeTypeSupported } from '../is-supported'; +import { ElementaryStreamTypes } from '../loader/fragment'; +import { PlaylistContextType, PlaylistLevelType } from '../types/loader'; +import { ChunkMetadata } from '../types/transmuxer'; +import { BufferHelper } from '../utils/buffer-helper'; import { pickMostCompleteCodecName } from '../utils/codecs'; -import type { NetworkComponentAPI } from '../types/component-api'; import type Hls from '../hls'; -import type { Level } from '../types/level'; import type { FragmentTracker } from './fragment-tracker'; +import type { Fragment, MediaFragment } from '../loader/fragment'; import type KeyLoader from '../loader/key-loader'; import type { LevelDetails } from '../loader/level-details'; -import type { TransmuxerResult } from '../types/transmuxer'; -import type { Track, TrackSet } from '../types/track'; import type { SourceBufferName } from '../types/buffer'; +import type { NetworkComponentAPI } from '../types/component-api'; import type { AudioTrackSwitchedData, AudioTrackSwitchingData, @@ -43,6 +37,10 @@ import type { MediaAttachedData, MediaDetachingData, } from '../types/events'; +import type { Level } from '../types/level'; +import type { Track, TrackSet } from '../types/track'; +import type { TransmuxerResult } from '../types/transmuxer'; +import type { BufferInfo } from '../utils/buffer-helper'; const TICK_INTERVAL = 100; // how often to tick in ms diff --git a/src/controller/subtitle-stream-controller.ts b/src/controller/subtitle-stream-controller.ts index 53e5d8dd045..c0f97e63de3 100644 --- a/src/controller/subtitle-stream-controller.ts +++ b/src/controller/subtitle-stream-controller.ts @@ -1,35 +1,36 @@ -import { Events } from '../events'; -import { Bufferable, BufferHelper } from '../utils/buffer-helper'; +import BaseStreamController, { State } from './base-stream-controller'; import { findFragmentByPTS } from './fragment-finders'; -import { alignMediaPlaylistByPDT } from '../utils/discontinuities'; -import { addSliding } from '../utils/level-helper'; import { FragmentState } from './fragment-tracker'; -import BaseStreamController, { State } from './base-stream-controller'; -import { PlaylistLevelType } from '../types/loader'; -import { Level } from '../types/level'; -import { subtitleOptionsIdentical } from '../utils/media-option-attributes'; import { ErrorDetails, ErrorTypes } from '../errors'; +import { Events } from '../events'; +import { Level } from '../types/level'; +import { PlaylistLevelType } from '../types/loader'; +import { BufferHelper } from '../utils/buffer-helper'; +import { alignMediaPlaylistByPDT } from '../utils/discontinuities'; import { - isFullSegmentEncryption, getAesModeFromFullSegmentMethod, + isFullSegmentEncryption, } from '../utils/encryption-methods-util'; -import type { NetworkComponentAPI } from '../types/component-api'; +import { addSliding } from '../utils/level-helper'; +import { subtitleOptionsIdentical } from '../utils/media-option-attributes'; import type Hls from '../hls'; import type { FragmentTracker } from './fragment-tracker'; +import type { Fragment, MediaFragment } from '../loader/fragment'; import type KeyLoader from '../loader/key-loader'; import type { LevelDetails } from '../loader/level-details'; -import type { Fragment, MediaFragment } from '../loader/fragment'; +import type { NetworkComponentAPI } from '../types/component-api'; import type { + BufferFlushingData, ErrorData, FragLoadedData, + LevelLoadedData, + MediaDetachingData, SubtitleFragProcessed, SubtitleTracksUpdatedData, TrackLoadedData, TrackSwitchedData, - BufferFlushingData, - LevelLoadedData, - MediaDetachingData, } from '../types/events'; +import type { Bufferable } from '../utils/buffer-helper'; const TICK_INTERVAL = 500; // how often to tick in ms diff --git a/src/controller/subtitle-track-controller.ts b/src/controller/subtitle-track-controller.ts index 9def71cb6fe..9b93a661167 100644 --- a/src/controller/subtitle-track-controller.ts +++ b/src/controller/subtitle-track-controller.ts @@ -1,31 +1,31 @@ import BasePlaylistController from './base-playlist-controller'; import { Events } from '../events'; -import { - clearCurrentCues, - filterSubtitleTracks, -} from '../utils/texttrack-utils'; import { PlaylistContextType } from '../types/loader'; import { mediaAttributesIdentical, subtitleTrackMatchesTextTrack, } from '../utils/media-option-attributes'; import { findMatchingOption, matchesOption } from '../utils/rendition-helper'; +import { + clearCurrentCues, + filterSubtitleTracks, +} from '../utils/texttrack-utils'; import type Hls from '../hls'; -import type { - MediaPlaylist, - SubtitleSelectionOption, -} from '../types/media-playlist'; -import type { HlsUrlParameters } from '../types/level'; import type { ErrorData, LevelLoadingData, + LevelSwitchingData, + ManifestParsedData, MediaAttachedData, + MediaDetachingData, SubtitleTracksUpdatedData, - ManifestParsedData, TrackLoadedData, - LevelSwitchingData, - MediaDetachingData, } from '../types/events'; +import type { HlsUrlParameters } from '../types/level'; +import type { + MediaPlaylist, + SubtitleSelectionOption, +} from '../types/media-playlist'; class SubtitleTrackController extends BasePlaylistController { private media: HTMLMediaElement | null = null; diff --git a/src/controller/timeline-controller.ts b/src/controller/timeline-controller.ts index 6223ff4e1f5..d3b1f3fdee5 100644 --- a/src/controller/timeline-controller.ts +++ b/src/controller/timeline-controller.ts @@ -1,40 +1,41 @@ import { Events } from '../events'; -import Cea608Parser, { CaptionScreen } from '../utils/cea-608-parser'; -import OutputFilter from '../utils/output-filter'; -import { parseWebVTT } from '../utils/webvtt-parser'; -import { - sendAddTrackEvent, - clearCurrentCues, - addCueToTrack, - removeCuesInRange, - filterSubtitleTracks, -} from '../utils/texttrack-utils'; +import { PlaylistLevelType } from '../types/loader'; +import Cea608Parser from '../utils/cea-608-parser'; +import { IMSC1_CODEC, parseIMSC1 } from '../utils/imsc1-ttml-parser'; import { subtitleOptionsIdentical, subtitleTrackMatchesTextTrack, } from '../utils/media-option-attributes'; -import { parseIMSC1, IMSC1_CODEC } from '../utils/imsc1-ttml-parser'; import { appendUint8Array } from '../utils/mp4-tools'; -import { PlaylistLevelType } from '../types/loader'; -import { Fragment } from '../loader/fragment'; +import OutputFilter from '../utils/output-filter'; +import { + addCueToTrack, + clearCurrentCues, + filterSubtitleTracks, + removeCuesInRange, + sendAddTrackEvent, +} from '../utils/texttrack-utils'; +import { parseWebVTT } from '../utils/webvtt-parser'; +import type { HlsConfig } from '../config'; +import type Hls from '../hls'; +import type { Fragment } from '../loader/fragment'; +import type { ComponentAPI } from '../types/component-api'; import type { - FragParsingUserdataData, - FragLoadedData, - FragDecryptedData, - MediaAttachingData, - ManifestLoadedData, - InitPTSFoundData, - SubtitleTracksUpdatedData, BufferFlushingData, + FragDecryptedData, + FragLoadedData, FragLoadingData, + FragParsingUserdataData, + InitPTSFoundData, + ManifestLoadedData, + MediaAttachingData, MediaDetachingData, + SubtitleTracksUpdatedData, } from '../types/events'; -import type Hls from '../hls'; -import type { ComponentAPI } from '../types/component-api'; -import type { HlsConfig } from '../config'; -import type { CuesInterface } from '../utils/cues'; import type { MediaPlaylist } from '../types/media-playlist'; import type { VTTCCs } from '../types/vtt'; +import type { CaptionScreen } from '../utils/cea-608-parser'; +import type { CuesInterface } from '../utils/cues'; import type { RationalTimestamp } from '../utils/timescale-conversion'; type TrackProperties = { diff --git a/src/crypt/decrypter.ts b/src/crypt/decrypter.ts index a3f988d1c5f..4dae2670585 100644 --- a/src/crypt/decrypter.ts +++ b/src/crypt/decrypter.ts @@ -1,10 +1,10 @@ import AESCrypto from './aes-crypto'; -import FastAESKey from './fast-aes-key'; import AESDecryptor, { removePadding } from './aes-decryptor'; +import { DecrypterAesMode } from './decrypter-aes-mode'; +import FastAESKey from './fast-aes-key'; import { logger } from '../utils/logger'; import { appendUint8Array } from '../utils/mp4-tools'; import { sliceUint8 } from '../utils/typed-array'; -import { DecrypterAesMode } from './decrypter-aes-mode'; import type { HlsConfig } from '../config'; const CHUNK_SIZE = 16; // 16 bytes, 128 bits diff --git a/src/demux/audio/aacdemuxer.ts b/src/demux/audio/aacdemuxer.ts index c62f178cd25..2788c1690d7 100644 --- a/src/demux/audio/aacdemuxer.ts +++ b/src/demux/audio/aacdemuxer.ts @@ -1,12 +1,12 @@ /** * AAC demuxer */ -import BaseAudioDemuxer from './base-audio-demuxer'; +import { getId3Data } from '@svta/common-media-library/id3/getId3Data'; import * as ADTS from './adts'; +import BaseAudioDemuxer from './base-audio-demuxer'; import * as MpegAudio from './mpegaudio'; -import { getId3Data } from '@svta/common-media-library/id3/getId3Data'; -import type { HlsEventEmitter } from '../../events'; import type { HlsConfig } from '../../config'; +import type { HlsEventEmitter } from '../../events'; import type { DemuxedAudioTrack } from '../../types/demuxer'; import type { ILogger } from '../../utils/logger'; diff --git a/src/demux/audio/ac3-demuxer.ts b/src/demux/audio/ac3-demuxer.ts index 3ed5189a2dc..8f130a7a1e5 100644 --- a/src/demux/audio/ac3-demuxer.ts +++ b/src/demux/audio/ac3-demuxer.ts @@ -1,6 +1,6 @@ -import BaseAudioDemuxer from './base-audio-demuxer'; import { getId3Data } from '@svta/common-media-library/id3/getId3Data'; import { getId3Timestamp } from '@svta/common-media-library/id3/getId3Timestamp'; +import BaseAudioDemuxer from './base-audio-demuxer'; import { getAudioBSID } from './dolby'; import type { HlsEventEmitter } from '../../events'; import type { AudioFrame, DemuxedAudioTrack } from '../../types/demuxer'; diff --git a/src/demux/audio/adts.ts b/src/demux/audio/adts.ts index 8701716aeb0..7376818d868 100644 --- a/src/demux/audio/adts.ts +++ b/src/demux/audio/adts.ts @@ -2,14 +2,14 @@ * ADTS parser helper * @link https://wiki.multimedia.cx/index.php?title=ADTS */ +import { ErrorDetails, ErrorTypes } from '../../errors'; +import { Events } from '../../events'; import { logger } from '../../utils/logger'; -import { ErrorTypes, ErrorDetails } from '../../errors'; import type { HlsEventEmitter } from '../../events'; -import { Events } from '../../events'; import type { - DemuxedAudioTrack, AudioFrame, AudioSample, + DemuxedAudioTrack, } from '../../types/demuxer'; type AudioConfig = { diff --git a/src/demux/audio/base-audio-demuxer.ts b/src/demux/audio/base-audio-demuxer.ts index 19d3afacd07..45753618b9a 100644 --- a/src/demux/audio/base-audio-demuxer.ts +++ b/src/demux/audio/base-audio-demuxer.ts @@ -1,21 +1,21 @@ +import { canParseId3 } from '@svta/common-media-library/id3/canParseId3'; +import { getId3Data } from '@svta/common-media-library/id3/getId3Data'; +import { getId3Timestamp } from '@svta/common-media-library/id3/getId3Timestamp'; import { - type DemuxerResult, - type Demuxer, - type DemuxedAudioTrack, type AudioFrame, + type DemuxedAudioTrack, type DemuxedMetadataTrack, - type DemuxedVideoTrackBase, type DemuxedUserdataTrack, + type DemuxedVideoTrackBase, + type Demuxer, + type DemuxerResult, type KeyData, MetadataSchema, } from '../../types/demuxer'; -import { dummyTrack } from '../dummy-demuxed-track'; import { appendUint8Array } from '../../utils/mp4-tools'; import { sliceUint8 } from '../../utils/typed-array'; -import { RationalTimestamp } from '../../utils/timescale-conversion'; -import { getId3Data } from '@svta/common-media-library/id3/getId3Data'; -import { getId3Timestamp } from '@svta/common-media-library/id3/getId3Timestamp'; -import { canParseId3 } from '@svta/common-media-library/id3/canParseId3'; +import { dummyTrack } from '../dummy-demuxed-track'; +import type { RationalTimestamp } from '../../utils/timescale-conversion'; class BaseAudioDemuxer implements Demuxer { protected _audioTrack!: DemuxedAudioTrack; diff --git a/src/demux/audio/mp3demuxer.ts b/src/demux/audio/mp3demuxer.ts index 5c954544a29..8cd5005872d 100644 --- a/src/demux/audio/mp3demuxer.ts +++ b/src/demux/audio/mp3demuxer.ts @@ -1,12 +1,12 @@ /** * MP3 demuxer */ +import { getId3Data } from '@svta/common-media-library/id3/getId3Data'; +import { getId3Timestamp } from '@svta/common-media-library/id3/getId3Timestamp'; import BaseAudioDemuxer from './base-audio-demuxer'; import { getAudioBSID } from './dolby'; -import { logger } from '../../utils/logger'; import * as MpegAudio from './mpegaudio'; -import { getId3Data } from '@svta/common-media-library/id3/getId3Data'; -import { getId3Timestamp } from '@svta/common-media-library/id3/getId3Timestamp'; +import { logger } from '../../utils/logger'; class MP3Demuxer extends BaseAudioDemuxer { resetInitSegment( diff --git a/src/demux/mp4demuxer.ts b/src/demux/mp4demuxer.ts index bdfe5d8c5b9..b3fe086d33f 100644 --- a/src/demux/mp4demuxer.ts +++ b/src/demux/mp4demuxer.ts @@ -1,30 +1,30 @@ /** * MP4 demuxer */ +import { dummyTrack } from './dummy-demuxed-track'; import { - type Demuxer, - type DemuxerResult, - type PassthroughTrack, type DemuxedAudioTrack, - type DemuxedUserdataTrack, type DemuxedMetadataTrack, + type DemuxedUserdataTrack, + type Demuxer, + type DemuxerResult, type KeyData, MetadataSchema, + type PassthroughTrack, } from '../types/demuxer'; import { - findBox, - segmentValidRange, appendUint8Array, + findBox, + hasMoofData, parseEmsg, - parseSamples, parseInitSegment, + parseSamples, RemuxerTrackIdConfig, - hasMoofData, - IEmsgParsingData, + segmentValidRange, } from '../utils/mp4-tools'; -import { dummyTrack } from './dummy-demuxed-track'; -import type { HlsEventEmitter } from '../events'; import type { HlsConfig } from '../config'; +import type { HlsEventEmitter } from '../events'; +import type { IEmsgParsingData } from '../utils/mp4-tools'; const emsgSchemePattern = /\/emsg[-/]ID3/i; diff --git a/src/demux/sample-aes.ts b/src/demux/sample-aes.ts index 20f6bcc52da..0b1aad66497 100644 --- a/src/demux/sample-aes.ts +++ b/src/demux/sample-aes.ts @@ -2,18 +2,18 @@ * SAMPLE-AES decrypter */ -import { HlsConfig } from '../config'; import Decrypter from '../crypt/decrypter'; import { DecrypterAesMode } from '../crypt/decrypter-aes-mode'; -import { HlsEventEmitter } from '../events'; +import { discardEPB } from '../utils/mp4-tools'; +import type { HlsConfig } from '../config'; +import type { HlsEventEmitter } from '../events'; import type { AudioSample, - VideoSample, - VideoSampleUnit, DemuxedVideoTrackBase, KeyData, + VideoSample, + VideoSampleUnit, } from '../types/demuxer'; -import { discardEPB } from '../utils/mp4-tools'; class SampleAesDecrypter { private keyData: KeyData; diff --git a/src/demux/transmuxer-interface.ts b/src/demux/transmuxer-interface.ts index 66119943de5..6c923f60a9a 100644 --- a/src/demux/transmuxer-interface.ts +++ b/src/demux/transmuxer-interface.ts @@ -1,26 +1,25 @@ +import { EventEmitter } from 'eventemitter3'; import { - WorkerContext, hasUMDWorker, injectWorker, loadWorker, removeWorkerFromStore as removeWorkerClient, } from './inject-worker'; -import { Events } from '../events'; import Transmuxer, { + isPromise, TransmuxConfig, TransmuxState, - isPromise, } from '../demux/transmuxer'; -import { ErrorTypes, ErrorDetails } from '../errors'; -import { EventEmitter } from 'eventemitter3'; -import { MediaFragment, Part } from '../loader/fragment'; +import { ErrorDetails, ErrorTypes } from '../errors'; +import { Events } from '../events'; import { getM2TSSupportedAudioTypes } from '../utils/codecs'; - -import type { ChunkMetadata, TransmuxerResult } from '../types/transmuxer'; -import type Hls from '../hls'; +import type { WorkerContext } from './inject-worker'; import type { HlsEventEmitter, HlsListeners } from '../events'; +import type Hls from '../hls'; +import type { MediaFragment, Part } from '../loader/fragment'; import type { ErrorData, FragDecryptedData } from '../types/events'; import type { PlaylistLevelType } from '../types/loader'; +import type { ChunkMetadata, TransmuxerResult } from '../types/transmuxer'; import type { RationalTimestamp } from '../utils/timescale-conversion'; let transmuxerInstanceCount: number = 0; diff --git a/src/demux/transmuxer-worker.ts b/src/demux/transmuxer-worker.ts index ced42482b11..361cc1b5cc9 100644 --- a/src/demux/transmuxer-worker.ts +++ b/src/demux/transmuxer-worker.ts @@ -1,10 +1,10 @@ +import { EventEmitter } from 'eventemitter3'; import Transmuxer, { isPromise } from '../demux/transmuxer'; +import { ErrorDetails, ErrorTypes } from '../errors'; import { Events } from '../events'; import { enableLogs, type ILogFunction, type ILogger } from '../utils/logger'; -import { EventEmitter } from 'eventemitter3'; -import { ErrorDetails, ErrorTypes } from '../errors'; import type { RemuxedTrack, RemuxerResult } from '../types/remuxer'; -import type { TransmuxerResult, ChunkMetadata } from '../types/transmuxer'; +import type { ChunkMetadata, TransmuxerResult } from '../types/transmuxer'; const transmuxers: (Transmuxer | undefined)[] = []; diff --git a/src/demux/transmuxer.ts b/src/demux/transmuxer.ts index 76fdd638aef..a1c11283239 100644 --- a/src/demux/transmuxer.ts +++ b/src/demux/transmuxer.ts @@ -1,24 +1,24 @@ -import type { HlsEventEmitter } from '../events'; -import { Events } from '../events'; -import { ErrorTypes, ErrorDetails } from '../errors'; -import Decrypter from '../crypt/decrypter'; import AACDemuxer from './audio/aacdemuxer'; +import { AC3Demuxer } from './audio/ac3-demuxer'; +import MP3Demuxer from './audio/mp3demuxer'; +import Decrypter from '../crypt/decrypter'; import MP4Demuxer from '../demux/mp4demuxer'; import TSDemuxer from '../demux/tsdemuxer'; -import MP3Demuxer from './audio/mp3demuxer'; -import { AC3Demuxer } from './audio/ac3-demuxer'; +import { ErrorDetails, ErrorTypes } from '../errors'; +import { Events } from '../events'; import MP4Remuxer from '../remux/mp4-remuxer'; import PassThroughRemuxer from '../remux/passthrough-remuxer'; import { PlaylistLevelType } from '../types/loader'; import { - isFullSegmentEncryption, getAesModeFromFullSegmentMethod, + isFullSegmentEncryption, } from '../utils/encryption-methods-util'; -import type { Demuxer, DemuxerResult, KeyData } from '../types/demuxer'; -import type { Remuxer } from '../types/remuxer'; -import type { TransmuxerResult, ChunkMetadata } from '../types/transmuxer'; import type { HlsConfig } from '../config'; +import type { HlsEventEmitter } from '../events'; import type { DecryptData } from '../loader/level-key'; +import type { Demuxer, DemuxerResult, KeyData } from '../types/demuxer'; +import type { Remuxer } from '../types/remuxer'; +import type { ChunkMetadata, TransmuxerResult } from '../types/transmuxer'; import type { TypeSupported } from '../utils/codecs'; import type { ILogger } from '../utils/logger'; import type { RationalTimestamp } from '../utils/timescale-conversion'; diff --git a/src/demux/tsdemuxer.ts b/src/demux/tsdemuxer.ts index 371756a03f6..19777102a1f 100644 --- a/src/demux/tsdemuxer.ts +++ b/src/demux/tsdemuxer.ts @@ -9,34 +9,34 @@ * upon discontinuity or level switch detection, it will also notifies the remuxer so that it can reset its state. */ +import * as AC3 from './audio/ac3-demuxer'; import * as ADTS from './audio/adts'; import * as MpegAudio from './audio/mpegaudio'; -import * as AC3 from './audio/ac3-demuxer'; -import BaseVideoParser from './video/base-video-parser'; +import SampleAesDecrypter from './sample-aes'; import AvcVideoParser from './video/avc-video-parser'; import HevcVideoParser from './video/hevc-video-parser'; -import SampleAesDecrypter from './sample-aes'; +import { ErrorDetails, ErrorTypes } from '../errors'; import { Events } from '../events'; -import { appendUint8Array, RemuxerTrackIdConfig } from '../utils/mp4-tools'; -import { ErrorTypes, ErrorDetails } from '../errors'; -import type { HlsConfig } from '../config'; -import type { HlsEventEmitter } from '../events'; -import type { TypeSupported } from '../utils/codecs'; -import type { ILogger } from '../utils/logger'; import { - MetadataSchema, - type DemuxedVideoTrack, type DemuxedAudioTrack, + type DemuxedMetadataTrack, type DemuxedTrack, + type DemuxedUserdataTrack, + type DemuxedVideoTrack, type Demuxer, type DemuxerResult, - type VideoSample, - type DemuxedMetadataTrack, - type DemuxedUserdataTrack, type ElementaryStreamData, type KeyData, + MetadataSchema, + type VideoSample, } from '../types/demuxer'; +import { appendUint8Array, RemuxerTrackIdConfig } from '../utils/mp4-tools'; +import type { HlsConfig } from '../config'; +import type { HlsEventEmitter } from '../events'; +import type BaseVideoParser from './video/base-video-parser'; import type { AudioFrame } from '../types/demuxer'; +import type { TypeSupported } from '../utils/codecs'; +import type { ILogger } from '../utils/logger'; export type ParsedTimestamp = { pts?: number; diff --git a/src/demux/video/avc-video-parser.ts b/src/demux/video/avc-video-parser.ts index 927db7b41b0..15ff4dc6822 100644 --- a/src/demux/video/avc-video-parser.ts +++ b/src/demux/video/avc-video-parser.ts @@ -1,14 +1,12 @@ import BaseVideoParser from './base-video-parser'; +import ExpGolomb from './exp-golomb'; +import { parseSEIMessageFromNALu } from '../../utils/mp4-tools'; import type { - DemuxedVideoTrack, DemuxedUserdataTrack, + DemuxedVideoTrack, } from '../../types/demuxer'; -import { parseSEIMessageFromNALu } from '../../utils/mp4-tools'; - import type { PES } from '../tsdemuxer'; -import ExpGolomb from './exp-golomb'; - class AvcVideoParser extends BaseVideoParser { public parsePES( track: DemuxedVideoTrack, diff --git a/src/demux/video/base-video-parser.ts b/src/demux/video/base-video-parser.ts index b916ac7f123..93cdd34f26e 100644 --- a/src/demux/video/base-video-parser.ts +++ b/src/demux/video/base-video-parser.ts @@ -1,12 +1,12 @@ -import type { ParsedVideoSample } from '../tsdemuxer'; +import { appendUint8Array } from '../../utils/mp4-tools'; import type { - DemuxedVideoTrack, DemuxedUserdataTrack, + DemuxedVideoTrack, VideoSample, VideoSampleUnit, } from '../../types/demuxer'; +import type { ParsedVideoSample } from '../tsdemuxer'; import type { PES } from '../tsdemuxer'; -import { appendUint8Array } from '../../utils/mp4-tools'; abstract class BaseVideoParser { protected VideoSample: ParsedVideoSample | null = null; diff --git a/src/demux/video/hevc-video-parser.ts b/src/demux/video/hevc-video-parser.ts index 2618d639a40..9454280bef7 100644 --- a/src/demux/video/hevc-video-parser.ts +++ b/src/demux/video/hevc-video-parser.ts @@ -1,15 +1,13 @@ import BaseVideoParser from './base-video-parser'; -import type { ParsedVideoSample } from '../tsdemuxer'; +import ExpGolomb from './exp-golomb'; +import { parseSEIMessageFromNALu } from '../../utils/mp4-tools'; import type { - DemuxedVideoTrack, DemuxedUserdataTrack, + DemuxedVideoTrack, } from '../../types/demuxer'; -import { parseSEIMessageFromNALu } from '../../utils/mp4-tools'; - +import type { ParsedVideoSample } from '../tsdemuxer'; import type { PES } from '../tsdemuxer'; -import ExpGolomb from './exp-golomb'; - class HevcVideoParser extends BaseVideoParser { protected initVPS: Uint8Array | null = null; diff --git a/src/events.ts b/src/events.ts index e93477a5fe2..e95ded3aec8 100644 --- a/src/events.ts +++ b/src/events.ts @@ -1,70 +1,70 @@ import type { - ManifestLoadedData, - ManifestLoadingData, - MediaAttachedData, - MediaAttachingData, - MediaDetachedData, - MediaDetachingData, - MediaEndedData, - LevelLoadingData, - LevelLoadedData, - ManifestParsedData, - LevelUpdatedData, - LevelsUpdatedData, - FragParsingUserdataData, - FragDecryptedData, - FragLoadedData, - InitPTSFoundData, - CuesParsedData, - SubtitleFragProcessedData, - NonNativeTextTracksData, - FragLoadingData, + AssetListLoadedData, + AssetListLoadingData, AudioTrackLoadedData, - SubtitleTrackLoadedData, - ErrorData, - AudioTrackSwitchingData, + AudioTracksUpdatedData, AudioTrackSwitchedData, - KeyLoadedData, - KeyLoadingData, - SubtitleTrackSwitchData, - SubtitleTracksUpdatedData, - LevelSwitchedData, - FragChangedData, + AudioTrackSwitchingData, + AudioTrackUpdatedData, + BackBufferData, + BufferAppendedData, BufferAppendingData, BufferCodecsData, - FragParsingMetadataData, - FragParsingInitSegmentData, - FragBufferedData, - BufferFlushingData, + BufferCreatedData, BufferEOSData, - LevelSwitchingData, - MaxAutoLevelUpdatedData, - FPSDropLevelCappingData, + BufferFlushedData, + BufferFlushingData, + CuesParsedData, + ErrorData, FPSDropData, - BufferCreatedData, - BufferAppendedData, - LevelPTSUpdatedData, - FragParsedData, - AudioTracksUpdatedData, + FPSDropLevelCappingData, + FragBufferedData, + FragChangedData, + FragDecryptedData, + FragLoadedData, FragLoadEmergencyAbortedData, - BackBufferData, - LiveBackBufferData, - TrackLoadingData, - BufferFlushedData, - SteeringManifestLoadedData, - AssetListLoadingData, - AssetListLoadedData, - InterstitialsUpdatedData, - InterstitialsBufferedToBoundaryData, + FragLoadingData, + FragParsedData, + FragParsingInitSegmentData, + FragParsingMetadataData, + FragParsingUserdataData, + InitPTSFoundData, + InterstitialAssetEndedData, + InterstitialAssetErrorData, InterstitialAssetPlayerCreatedData, - InterstitialStartedData, InterstitialAssetStartedData, - InterstitialAssetEndedData, InterstitialEndedData, + InterstitialsBufferedToBoundaryData, InterstitialsPrimaryResumed, - AudioTrackUpdatedData, + InterstitialStartedData, + InterstitialsUpdatedData, + KeyLoadedData, + KeyLoadingData, + LevelLoadedData, + LevelLoadingData, + LevelPTSUpdatedData, + LevelsUpdatedData, + LevelSwitchedData, + LevelSwitchingData, + LevelUpdatedData, + LiveBackBufferData, + ManifestLoadedData, + ManifestLoadingData, + ManifestParsedData, + MaxAutoLevelUpdatedData, + MediaAttachedData, + MediaAttachingData, + MediaDetachedData, + MediaDetachingData, + MediaEndedData, + NonNativeTextTracksData, + SteeringManifestLoadedData, + SubtitleFragProcessedData, + SubtitleTrackLoadedData, + SubtitleTracksUpdatedData, + SubtitleTrackSwitchData, SubtitleTrackUpdatedData, - InterstitialAssetErrorData, + TrackLoadingData, } from './types/events'; export enum Events { diff --git a/src/exports-named.ts b/src/exports-named.ts index 6e0b6ba5a65..a807262b6b0 100644 --- a/src/exports-named.ts +++ b/src/exports-named.ts @@ -1,7 +1,6 @@ -import Hls from './hls'; import AbrController from './controller/abr-controller'; -import AudioTrackController from './controller/audio-track-controller'; import AudioStreamController from './controller/audio-stream-controller'; +import AudioTrackController from './controller/audio-track-controller'; import BasePlaylistController from './controller/base-playlist-controller'; import BaseStreamController from './controller/base-stream-controller'; import BufferController from './controller/buffer-controller'; @@ -12,9 +11,10 @@ import EMEController from './controller/eme-controller'; import ErrorController from './controller/error-controller'; import FPSController from './controller/fps-controller'; import SubtitleTrackController from './controller/subtitle-track-controller'; -import XhrLoader from './utils/xhr-loader'; -import FetchLoader from './utils/fetch-loader'; +import Hls from './hls'; import Cues from './utils/cues'; +import FetchLoader from './utils/fetch-loader'; +import XhrLoader from './utils/xhr-loader'; export default Hls; diff --git a/src/hls.ts b/src/hls.ts index b6e9bc79dfc..44e6fcb811b 100644 --- a/src/hls.ts +++ b/src/hls.ts @@ -1,64 +1,62 @@ +import { uuid } from '@svta/common-media-library/utils/uuid'; +import { EventEmitter } from 'eventemitter3'; import { buildAbsoluteURL } from 'url-toolkit'; -import PlaylistLoader from './loader/playlist-loader'; +import { enableStreamingMode, hlsDefaultConfig, mergeConfig } from './config'; +import { FragmentTracker } from './controller/fragment-tracker'; import ID3TrackController from './controller/id3-track-controller'; import LatencyController from './controller/latency-controller'; import LevelController from './controller/level-controller'; -import { FragmentTracker } from './controller/fragment-tracker'; -import KeyLoader from './loader/key-loader'; import StreamController from './controller/stream-controller'; -import { isMSESupported, isSupported } from './is-supported'; -import { getMediaSource } from './utils/mediasource-helper'; -import { enableLogs, type ILogger } from './utils/logger'; -import { enableStreamingMode, hlsDefaultConfig, mergeConfig } from './config'; -import { EventEmitter } from 'eventemitter3'; +import { ErrorDetails, ErrorTypes } from './errors'; import { Events } from './events'; +import { isMSESupported, isSupported } from './is-supported'; +import KeyLoader from './loader/key-loader'; +import PlaylistLoader from './loader/playlist-loader'; import { MetadataSchema } from './types/demuxer'; -import { ErrorTypes, ErrorDetails } from './errors'; +import { type HdcpLevel, isHdcpLevel, type Level } from './types/level'; +import { enableLogs, type ILogger } from './utils/logger'; +import { getMediaDecodingInfoPromise } from './utils/mediacapabilities-helper'; +import { getMediaSource } from './utils/mediasource-helper'; +import { getAudioTracksByGroup } from './utils/rendition-helper'; import { version } from './version'; -import { isHdcpLevel, type HdcpLevel, type Level } from './types/level'; -import { uuid } from '@svta/common-media-library/utils/uuid'; -import type { HlsEventEmitter, HlsListeners } from './events'; -import type AudioTrackController from './controller/audio-track-controller'; +import type { HlsConfig } from './config'; import type AbrController from './controller/abr-controller'; -import type EwmaBandWidthEstimator from './utils/ewma-bandwidth-estimator'; +import type AudioStreamController from './controller/audio-stream-controller'; +import type AudioTrackController from './controller/audio-track-controller'; +import type BasePlaylistController from './controller/base-playlist-controller'; +import type BaseStreamController from './controller/base-stream-controller'; import type BufferController from './controller/buffer-controller'; import type CapLevelController from './controller/cap-level-controller'; import type CMCDController from './controller/cmcd-controller'; +import type ContentSteeringController from './controller/content-steering-controller'; import type EMEController from './controller/eme-controller'; +import type ErrorController from './controller/error-controller'; +import type FPSController from './controller/fps-controller'; +import type InterstitialsController from './controller/interstitials-controller'; +import type { InterstitialsManager } from './controller/interstitials-controller'; import type SubtitleTrackController from './controller/subtitle-track-controller'; +import type Decrypter from './crypt/decrypter'; +import type TransmuxerInterface from './demux/transmuxer-interface'; +import type { HlsEventEmitter, HlsListeners } from './events'; +import type FragmentLoader from './loader/fragment-loader'; +import type { LevelDetails } from './loader/level-details'; +import type TaskLoop from './task-loop'; +import type { AttachMediaSourceData } from './types/buffer'; import type { AbrComponentAPI, ComponentAPI, NetworkComponentAPI, } from './types/component-api'; +import type { MediaAttachingData } from './types/events'; import type { AudioSelectionOption, MediaPlaylist, SubtitleSelectionOption, VideoSelectionOption, } from './types/media-playlist'; -import type { AttachMediaSourceData } from './types/buffer'; -import type { HlsConfig } from './config'; import type { BufferInfo } from './utils/buffer-helper'; -import type AudioStreamController from './controller/audio-stream-controller'; -import type BasePlaylistController from './controller/base-playlist-controller'; -import type BaseStreamController from './controller/base-stream-controller'; -import type ContentSteeringController from './controller/content-steering-controller'; -import type InterstitialsController from './controller/interstitials-controller'; -import type ErrorController from './controller/error-controller'; -import type FPSController from './controller/fps-controller'; -import type { MediaAttachingData } from './types/events'; -import type { InterstitialsManager } from './controller/interstitials-controller'; -import type Decrypter from './crypt/decrypter'; -import type FragmentLoader from './loader/fragment-loader'; -import type { LevelDetails } from './loader/level-details'; -import type TaskLoop from './task-loop'; -import type TransmuxerInterface from './demux/transmuxer-interface'; -import { getAudioTracksByGroup } from './utils/rendition-helper'; -import { - getMediaDecodingInfoPromise, - MediaDecodingInfo, -} from './utils/mediacapabilities-helper'; +import type EwmaBandWidthEstimator from './utils/ewma-bandwidth-estimator'; +import type { MediaDecodingInfo } from './utils/mediacapabilities-helper'; /** * The `Hls` class is the core of the HLS.js library used to instantiate player instances. diff --git a/src/is-supported.ts b/src/is-supported.ts index 731da3ba668..bbf3b3214f2 100644 --- a/src/is-supported.ts +++ b/src/is-supported.ts @@ -1,5 +1,5 @@ -import { getMediaSource } from './utils/mediasource-helper'; import { mimeTypeForCodec } from './utils/codecs'; +import { getMediaSource } from './utils/mediasource-helper'; import type { ExtendedSourceBuffer } from './types/buffer'; function getSourceBuffer(): typeof self.SourceBuffer { diff --git a/src/loader/fragment-loader.ts b/src/loader/fragment-loader.ts index 13018e1eb8a..22c91be7dc3 100644 --- a/src/loader/fragment-loader.ts +++ b/src/loader/fragment-loader.ts @@ -1,4 +1,4 @@ -import { ErrorTypes, ErrorDetails } from '../errors'; +import { ErrorDetails, ErrorTypes } from '../errors'; import { getLoaderConfigWithoutReties } from '../utils/error-helper'; import type { HlsConfig } from '../config'; import type { BaseSegment, Fragment, Part } from './fragment'; @@ -8,10 +8,10 @@ import type { PartsLoadedData, } from '../types/events'; import type { - Loader, - LoaderConfiguration, FragmentLoaderContext, + Loader, LoaderCallbacks, + LoaderConfiguration, } from '../types/loader'; const MIN_CHUNK_SIZE = Math.pow(2, 17); // 128kb diff --git a/src/loader/fragment.ts b/src/loader/fragment.ts index 8d426c918ba..040c4e54c40 100644 --- a/src/loader/fragment.ts +++ b/src/loader/fragment.ts @@ -1,13 +1,13 @@ import { buildAbsoluteURL } from 'url-toolkit'; -import { LevelKey } from './level-key'; import { LoadStats } from './load-stats'; -import { AttrList } from '../utils/attr-list'; +import type { LevelKey } from './level-key'; import type { FragmentLoaderContext, KeyLoaderContext, Loader, PlaylistLevelType, } from '../types/loader'; +import type { AttrList } from '../utils/attr-list'; import type { KeySystemFormats } from '../utils/mediakeys-helper'; export const enum ElementaryStreamTypes { diff --git a/src/loader/interstitial-asset-list.ts b/src/loader/interstitial-asset-list.ts index 4745281fb77..d1ea81ee058 100644 --- a/src/loader/interstitial-asset-list.ts +++ b/src/loader/interstitial-asset-list.ts @@ -1,11 +1,12 @@ import { - getInterstitialUrl, - InterstitialEvent, type AssetListJSON, + getInterstitialUrl, type InterstitialEventWithAssetList, } from './interstitial-event'; -import { Events } from '../events'; import { ErrorDetails, ErrorTypes } from '../errors'; +import { Events } from '../events'; +import type { InterstitialEvent } from './interstitial-event'; +import type Hls from '../hls'; import type { ErrorData } from '../types/events'; import type { Loader, @@ -16,8 +17,6 @@ import type { LoaderStats, } from '../types/loader'; -import type Hls from '../hls'; - export class AssetListLoader { private hls: Hls; diff --git a/src/loader/interstitial-event.ts b/src/loader/interstitial-event.ts index 8e95e53c89a..ca6b11c0a6f 100644 --- a/src/loader/interstitial-event.ts +++ b/src/loader/interstitial-event.ts @@ -1,7 +1,7 @@ +import { hash } from '../utils/hash'; import type { DateRange, DateRangeCue } from './date-range'; -import type { Loader, LoaderContext } from '../types/loader'; import type { Fragment } from './fragment'; -import { hash } from '../utils/hash'; +import type { Loader, LoaderContext } from '../types/loader'; export const ALIGNED_END_THRESHOLD_SECONDS = 0.02; // 0.1 // 0.2 diff --git a/src/loader/key-loader.ts b/src/loader/key-loader.ts index accddddf529..82ab889ba6a 100644 --- a/src/loader/key-loader.ts +++ b/src/loader/key-loader.ts @@ -1,21 +1,21 @@ -import { ErrorTypes, ErrorDetails } from '../errors'; -import type { - LoaderStats, - LoaderResponse, - LoaderConfiguration, - LoaderCallbacks, - Loader, - KeyLoaderContext, - PlaylistLevelType, -} from '../types/loader'; import { LoadError } from './fragment-loader'; +import { ErrorDetails, ErrorTypes } from '../errors'; import type { HlsConfig } from '../config'; -import type { Fragment } from '../loader/fragment'; -import type { ComponentAPI } from '../types/component-api'; -import type { KeyLoadedData } from '../types/events'; import type { LevelKey } from './level-key'; import type EMEController from '../controller/eme-controller'; import type { MediaKeySessionContext } from '../controller/eme-controller'; +import type { Fragment } from '../loader/fragment'; +import type { ComponentAPI } from '../types/component-api'; +import type { KeyLoadedData } from '../types/events'; +import type { + KeyLoaderContext, + Loader, + LoaderCallbacks, + LoaderConfiguration, + LoaderResponse, + LoaderStats, + PlaylistLevelType, +} from '../types/loader'; import type { KeySystemFormats } from '../utils/mediakeys-helper'; export interface KeyLoaderInfo { diff --git a/src/loader/level-details.ts b/src/loader/level-details.ts index 9d0286684f0..6f396ba4c78 100644 --- a/src/loader/level-details.ts +++ b/src/loader/level-details.ts @@ -1,7 +1,7 @@ -import type { Fragment, MediaFragment, Part } from './fragment'; import type { DateRange } from './date-range'; -import type { AttrList } from '../utils/attr-list'; +import type { Fragment, MediaFragment, Part } from './fragment'; import type { VariableMap } from '../types/level'; +import type { AttrList } from '../utils/attr-list'; const DEFAULT_TARGET_DURATION = 10; diff --git a/src/loader/level-key.ts b/src/loader/level-key.ts index c625685e4af..9af451212e0 100644 --- a/src/loader/level-key.ts +++ b/src/loader/level-key.ts @@ -1,8 +1,8 @@ -import { convertDataUriToArrayBytes } from '../utils/keysystem-util'; import { isFullSegmentEncryption } from '../utils/encryption-methods-util'; +import { convertDataUriToArrayBytes } from '../utils/keysystem-util'; +import { logger } from '../utils/logger'; import { KeySystemFormats, parsePlayReadyWRM } from '../utils/mediakeys-helper'; import { mp4pssh } from '../utils/mp4-tools'; -import { logger } from '../utils/logger'; let keyUriToKeyIdMap: { [uri: string]: Uint8Array } = {}; diff --git a/src/loader/m3u8-parser.ts b/src/loader/m3u8-parser.ts index 07100c46302..fcc2f3a8345 100644 --- a/src/loader/m3u8-parser.ts +++ b/src/loader/m3u8-parser.ts @@ -1,9 +1,10 @@ import { buildAbsoluteURL } from 'url-toolkit'; import { DateRange } from './date-range'; -import { Fragment, MediaFragment, Part } from './fragment'; +import { Fragment, Part } from './fragment'; import { LevelDetails } from './level-details'; import { LevelKey } from './level-key'; import { AttrList } from '../utils/attr-list'; +import { isCodecType } from '../utils/codecs'; import { logger } from '../utils/logger'; import { addVariableDefinition, @@ -11,12 +12,12 @@ import { importVariableDefinition, substituteVariables, } from '../utils/variable-substitution'; -import { isCodecType } from '../utils/codecs'; -import type { CodecType } from '../utils/codecs'; -import type { MediaPlaylist, MediaAttributes } from '../types/media-playlist'; -import type { PlaylistLevelType } from '../types/loader'; -import type { LevelAttributes, LevelParsed, VariableMap } from '../types/level'; +import type { MediaFragment } from './fragment'; import type { ContentSteeringOptions } from '../types/events'; +import type { LevelAttributes, LevelParsed, VariableMap } from '../types/level'; +import type { PlaylistLevelType } from '../types/loader'; +import type { MediaAttributes, MediaPlaylist } from '../types/media-playlist'; +import type { CodecType } from '../utils/codecs'; type M3U8ParserFragments = Array; diff --git a/src/loader/playlist-loader.ts b/src/loader/playlist-loader.ts index 2753fb3d9fe..64a9ffe9148 100644 --- a/src/loader/playlist-loader.ts +++ b/src/loader/playlist-loader.ts @@ -6,9 +6,21 @@ * Uses loader(s) set in config to do actual internal loading of resource tasks. */ -import { Events } from '../events'; -import { ErrorDetails, ErrorTypes } from '../errors'; import M3U8Parser from './m3u8-parser'; +import { ErrorDetails, ErrorTypes } from '../errors'; +import { Events } from '../events'; +import { PlaylistContextType, PlaylistLevelType } from '../types/loader'; +import { AttrList } from '../utils/attr-list'; +import type { LevelDetails } from './level-details'; +import type { LoaderConfig, RetryConfig } from '../config'; +import type Hls from '../hls'; +import type { NetworkComponentAPI } from '../types/component-api'; +import type { + ErrorData, + LevelLoadingData, + ManifestLoadingData, + TrackLoadingData, +} from '../types/events'; import type { LevelParsed, VariableMap } from '../types/level'; import type { Loader, @@ -19,19 +31,7 @@ import type { LoaderStats, PlaylistLoaderContext, } from '../types/loader'; -import { PlaylistContextType, PlaylistLevelType } from '../types/loader'; -import { LevelDetails } from './level-details'; -import { AttrList } from '../utils/attr-list'; -import type Hls from '../hls'; -import type { - ErrorData, - LevelLoadingData, - ManifestLoadingData, - TrackLoadingData, -} from '../types/events'; -import type { NetworkComponentAPI } from '../types/component-api'; import type { MediaAttributes } from '../types/media-playlist'; -import type { LoaderConfig, RetryConfig } from '../config'; function mapContextToLevelType( context: PlaylistLoaderContext, diff --git a/src/remux/mp4-generator.ts b/src/remux/mp4-generator.ts index 5b56c1bc8a8..d2c9f13c37c 100644 --- a/src/remux/mp4-generator.ts +++ b/src/remux/mp4-generator.ts @@ -2,8 +2,8 @@ * Generate MP4 Box */ -import type { DemuxedAudioTrack } from '../types/demuxer'; import { appendUint8Array } from '../utils/mp4-tools'; +import type { DemuxedAudioTrack } from '../types/demuxer'; type HdlrTypes = { video: Uint8Array; diff --git a/src/remux/mp4-remuxer.ts b/src/remux/mp4-remuxer.ts index 58d8f59ec67..e81c6bd88fc 100644 --- a/src/remux/mp4-remuxer.ts +++ b/src/remux/mp4-remuxer.ts @@ -1,34 +1,32 @@ import AAC from './aac-helper'; import MP4 from './mp4-generator'; -import type { HlsEventEmitter } from '../events'; +import { ErrorDetails, ErrorTypes } from '../errors'; import { Events } from '../events'; -import { ErrorTypes, ErrorDetails } from '../errors'; -import type { - InitSegmentData, - Remuxer, - RemuxerResult, - RemuxedMetadata, - RemuxedTrack, - RemuxedUserdata, -} from '../types/remuxer'; import { PlaylistLevelType } from '../types/loader'; -import { - RationalTimestamp, - toMsFromMpegTsClock, -} from '../utils/timescale-conversion'; +import { toMsFromMpegTsClock } from '../utils/timescale-conversion'; +import type { HlsConfig } from '../config'; +import type { HlsEventEmitter } from '../events'; +import type { SourceBufferName } from '../types/buffer'; import type { AudioSample, - VideoSample, DemuxedAudioTrack, - DemuxedVideoTrack, DemuxedMetadataTrack, DemuxedUserdataTrack, + DemuxedVideoTrack, + VideoSample, } from '../types/demuxer'; +import type { + InitSegmentData, + RemuxedMetadata, + RemuxedTrack, + RemuxedUserdata, + Remuxer, + RemuxerResult, +} from '../types/remuxer'; import type { TrackSet } from '../types/track'; -import type { SourceBufferName } from '../types/buffer'; -import type { HlsConfig } from '../config'; import type { TypeSupported } from '../utils/codecs'; import type { ILogger } from '../utils/logger'; +import type { RationalTimestamp } from '../utils/timescale-conversion'; const MAX_SILENT_FRAME_DURATION = 10 * 1000; // 10 seconds const AAC_SAMPLES_PER_FRAME = 1024; diff --git a/src/remux/passthrough-remuxer.ts b/src/remux/passthrough-remuxer.ts index 5a7b802d940..8a1ef95d1cf 100644 --- a/src/remux/passthrough-remuxer.ts +++ b/src/remux/passthrough-remuxer.ts @@ -2,37 +2,34 @@ import { flushTextTrackMetadataCueSamples, flushTextTrackUserdataCueSamples, } from './mp4-remuxer'; -import { - InitData, - InitDataTrack, - patchEncyptionData, -} from '../utils/mp4-tools'; +import { ElementaryStreamTypes } from '../loader/fragment'; +import { getCodecCompatibleName } from '../utils/codecs'; +import { type ILogger, logger } from '../utils/logger'; +import { patchEncyptionData } from '../utils/mp4-tools'; import { getDuration, getStartDTS, offsetStartDTS, parseInitSegment, } from '../utils/mp4-tools'; -import { ElementaryStreamTypes } from '../loader/fragment'; -import { getCodecCompatibleName } from '../utils/codecs'; -import type { HlsEventEmitter } from '../events'; import type { HlsConfig } from '../config'; -import type { TrackSet } from '../types/track'; -import type { - InitSegmentData, - RemuxedTrack, - Remuxer, - RemuxerResult, -} from '../types/remuxer'; +import type { HlsEventEmitter } from '../events'; +import type { DecryptData } from '../loader/level-key'; import type { DemuxedAudioTrack, DemuxedMetadataTrack, DemuxedUserdataTrack, PassthroughTrack, } from '../types/demuxer'; -import type { DecryptData } from '../loader/level-key'; +import type { + InitSegmentData, + RemuxedTrack, + Remuxer, + RemuxerResult, +} from '../types/remuxer'; +import type { TrackSet } from '../types/track'; import type { TypeSupported } from '../utils/codecs'; -import { logger, type ILogger } from '../utils/logger'; +import type { InitData, InitDataTrack } from '../utils/mp4-tools'; import type { RationalTimestamp } from '../utils/timescale-conversion'; class PassThroughRemuxer implements Remuxer { diff --git a/src/types/events.ts b/src/types/events.ts index 0a0f4f1b908..e83d665c49d 100644 --- a/src/types/events.ts +++ b/src/types/events.ts @@ -1,5 +1,15 @@ -import type { Fragment, MediaFragment, Part } from '../loader/fragment'; -import type { LevelDetails } from '../loader/level-details'; +import type { + AttachMediaSourceData, + BaseTrackSet, + BufferCreatedTrackSet, + MediaOverrides, + ParsedTrack, + SourceBufferName, + SourceBufferTrackSet, +} from './buffer'; +import type { ChunkMetadata } from './transmuxer'; +import type { ErrorDetails, ErrorTypes } from '../errors'; +import type { MetadataSample, UserdataSample } from './demuxer'; import type { HdcpLevel, HlsUrlParameters, @@ -8,7 +18,6 @@ import type { LevelParsed, VariableMap, } from './level'; -import type { MediaPlaylist, MediaPlaylistType } from './media-playlist'; import type { Loader, LoaderContext, @@ -17,36 +26,27 @@ import type { PlaylistLevelType, PlaylistLoaderContext, } from './loader'; +import type { MediaPlaylist, MediaPlaylistType } from './media-playlist'; +import type { SteeringManifest } from '../controller/content-steering-controller'; +import type { IErrorAction } from '../controller/error-controller'; +import type { HlsAssetPlayer } from '../controller/interstitial-player'; import type { - AttachMediaSourceData, - BaseTrackSet, - BufferCreatedTrackSet, - MediaOverrides, - ParsedTrack, - SourceBufferName, - SourceBufferTrackSet, -} from './buffer'; -import type { ChunkMetadata } from './transmuxer'; -import type { LoadStats } from '../loader/load-stats'; -import type { ErrorDetails, ErrorTypes } from '../errors'; -import type { MetadataSample, UserdataSample } from './demuxer'; -import type { AttrList } from '../utils/attr-list'; + InterstitialScheduleDurations, + InterstitialScheduleItem, +} from '../controller/interstitials-schedule'; import type { HlsListeners } from '../events'; -import type { KeyLoaderInfo } from '../loader/key-loader'; -import type { LevelKey } from '../loader/level-key'; -import type { IErrorAction } from '../controller/error-controller'; -import type { SteeringManifest } from '../controller/content-steering-controller'; +import type { Fragment, MediaFragment, Part } from '../loader/fragment'; import type { AssetListJSON, InterstitialAssetItem, InterstitialEvent, InterstitialEventWithAssetList, } from '../loader/interstitial-event'; -import type { HlsAssetPlayer } from '../controller/interstitial-player'; -import type { - InterstitialScheduleDurations, - InterstitialScheduleItem, -} from '../controller/interstitials-schedule'; +import type { KeyLoaderInfo } from '../loader/key-loader'; +import type { LevelDetails } from '../loader/level-details'; +import type { LevelKey } from '../loader/level-key'; +import type { LoadStats } from '../loader/load-stats'; +import type { AttrList } from '../utils/attr-list'; export interface MediaAttachingData { media: HTMLMediaElement; diff --git a/src/types/fragment-tracker.ts b/src/types/fragment-tracker.ts index 351aab050cf..dc7cd2c3be7 100644 --- a/src/types/fragment-tracker.ts +++ b/src/types/fragment-tracker.ts @@ -1,6 +1,6 @@ -import type { MediaFragment } from '../loader/fragment'; import type { SourceBufferName } from './buffer'; import type { FragLoadedData } from './events'; +import type { MediaFragment } from '../loader/fragment'; export interface FragmentEntity { body: MediaFragment; diff --git a/src/types/loader.ts b/src/types/loader.ts index fc563688b23..d2112f93a5e 100644 --- a/src/types/loader.ts +++ b/src/types/loader.ts @@ -1,9 +1,9 @@ import type { LoaderConfig } from '../config'; +import type { HlsUrlParameters } from './level'; import type { Fragment } from '../loader/fragment'; import type { Part } from '../loader/fragment'; import type { KeyLoaderInfo } from '../loader/key-loader'; import type { LevelDetails } from '../loader/level-details'; -import type { HlsUrlParameters } from './level'; export interface LoaderContext { // target URL diff --git a/src/types/media-playlist.ts b/src/types/media-playlist.ts index 964589a8e74..947745a4458 100644 --- a/src/types/media-playlist.ts +++ b/src/types/media-playlist.ts @@ -1,7 +1,7 @@ -import type { AttrList } from '../utils/attr-list'; -import type { LevelDetails } from '../loader/level-details'; import type { Level, VideoRange } from './level'; import type { PlaylistLevelType } from './loader'; +import type { LevelDetails } from '../loader/level-details'; +import type { AttrList } from '../utils/attr-list'; export type AudioPlaylistType = 'AUDIO'; diff --git a/src/types/remuxer.ts b/src/types/remuxer.ts index eca3a933907..d3b54c89452 100644 --- a/src/types/remuxer.ts +++ b/src/types/remuxer.ts @@ -1,4 +1,4 @@ -import type { TrackSet } from './track'; +import type { SourceBufferName } from './buffer'; import type { DemuxedAudioTrack, DemuxedMetadataTrack, @@ -7,8 +7,8 @@ import type { MetadataSample, UserdataSample, } from './demuxer'; -import type { SourceBufferName } from './buffer'; import type { PlaylistLevelType } from './loader'; +import type { TrackSet } from './track'; import type { DecryptData } from '../loader/level-key'; import type { RationalTimestamp } from '../utils/timescale-conversion'; diff --git a/src/types/track.ts b/src/types/track.ts index 02b0b34ecc8..af6d2466870 100644 --- a/src/types/track.ts +++ b/src/types/track.ts @@ -1,4 +1,4 @@ -import { BaseTrack } from './buffer'; +import type { BaseTrack } from './buffer'; export interface TrackSet { audio?: Track; diff --git a/src/types/transmuxer.ts b/src/types/transmuxer.ts index fc0c644be7b..1553d60daf0 100644 --- a/src/types/transmuxer.ts +++ b/src/types/transmuxer.ts @@ -1,6 +1,6 @@ -import type { RemuxerResult } from './remuxer'; -import type { HlsChunkPerformanceTiming } from './loader'; import type { SourceBufferName } from './buffer'; +import type { HlsChunkPerformanceTiming } from './loader'; +import type { RemuxerResult } from './remuxer'; export interface TransmuxerResult { remuxResult: RemuxerResult; diff --git a/src/utils/attr-list.ts b/src/utils/attr-list.ts index 0209fab844d..371fe27c64a 100755 --- a/src/utils/attr-list.ts +++ b/src/utils/attr-list.ts @@ -1,7 +1,7 @@ -import type { LevelDetails } from '../loader/level-details'; -import type { ParsedMultivariantPlaylist } from '../loader/m3u8-parser'; import { logger } from './logger'; import { substituteVariables } from './variable-substitution'; +import type { LevelDetails } from '../loader/level-details'; +import type { ParsedMultivariantPlaylist } from '../loader/m3u8-parser'; const DECIMAL_RESOLUTION_REGEX = /^(\d+)x(\d+)$/; const ATTR_LIST_REGEX = /(.+?)=(".*?"|.*?)(?:,|$)/g; diff --git a/src/utils/cea-608-parser.ts b/src/utils/cea-608-parser.ts index 6e6b0275383..996c462af52 100644 --- a/src/utils/cea-608-parser.ts +++ b/src/utils/cea-608-parser.ts @@ -1,5 +1,5 @@ -import OutputFilter from './output-filter'; import { logger } from '../utils/logger'; +import type OutputFilter from './output-filter'; /** * diff --git a/src/utils/cues.ts b/src/utils/cues.ts index a6fefe30b07..1853a65804d 100644 --- a/src/utils/cues.ts +++ b/src/utils/cues.ts @@ -1,7 +1,7 @@ +import { addCueToTrack } from './texttrack-utils'; import { fixLineBreaks } from './vttparser'; -import type { CaptionScreen, Row } from './cea-608-parser'; import { generateCueId } from './webvtt-parser'; -import { addCueToTrack } from './texttrack-utils'; +import type { CaptionScreen, Row } from './cea-608-parser'; const WHITESPACE_CHAR = /\s/; diff --git a/src/utils/discontinuities.ts b/src/utils/discontinuities.ts index 3e09d151daf..4e2e34c6421 100644 --- a/src/utils/discontinuities.ts +++ b/src/utils/discontinuities.ts @@ -1,6 +1,5 @@ -import { logger } from './logger'; import { adjustSliding } from './level-helper'; - +import { logger } from './logger'; import type { Fragment } from '../loader/fragment'; import type { LevelDetails } from '../loader/level-details'; diff --git a/src/utils/error-helper.ts b/src/utils/error-helper.ts index 98798df37b6..dc1eb18aa5d 100644 --- a/src/utils/error-helper.ts +++ b/src/utils/error-helper.ts @@ -1,5 +1,5 @@ import { ErrorDetails } from '../errors'; -import type { LoadPolicy, LoaderConfig, RetryConfig } from '../config'; +import type { LoaderConfig, LoadPolicy, RetryConfig } from '../config'; import type { ErrorData } from '../types/events'; import type { LoaderResponse } from '../types/loader'; diff --git a/src/utils/fetch-loader.ts b/src/utils/fetch-loader.ts index 03e9899cf3f..e838354d14b 100644 --- a/src/utils/fetch-loader.ts +++ b/src/utils/fetch-loader.ts @@ -1,16 +1,16 @@ +import ChunkCache from '../demux/chunk-cache'; +import { isPromise } from '../demux/transmuxer'; +import { LoadStats } from '../loader/load-stats'; +import type { HlsConfig } from '../config'; import type { - LoaderCallbacks, - LoaderContext, Loader, - LoaderStats, + LoaderCallbacks, LoaderConfiguration, + LoaderContext, LoaderOnProgress, LoaderResponse, + LoaderStats, } from '../types/loader'; -import { LoadStats } from '../loader/load-stats'; -import ChunkCache from '../demux/chunk-cache'; -import { isPromise } from '../demux/transmuxer'; -import { type HlsConfig } from '../config'; export function fetchSupported() { if ( diff --git a/src/utils/imsc1-ttml-parser.ts b/src/utils/imsc1-ttml-parser.ts index 164f3815436..764176fc10e 100644 --- a/src/utils/imsc1-ttml-parser.ts +++ b/src/utils/imsc1-ttml-parser.ts @@ -1,12 +1,10 @@ +import { utf8ArrayToStr } from '@svta/common-media-library/utils/utf8ArrayToStr'; import { findBox } from './mp4-tools'; -import { parseTimeStamp } from './vttparser'; +import { toTimescaleFromScale } from './timescale-conversion'; import VTTCue from './vttcue'; -import { utf8ArrayToStr } from '@svta/common-media-library/utils/utf8ArrayToStr'; -import { - RationalTimestamp, - toTimescaleFromScale, -} from './timescale-conversion'; +import { parseTimeStamp } from './vttparser'; import { generateCueId } from './webvtt-parser'; +import type { RationalTimestamp } from './timescale-conversion'; export const IMSC1_CODEC = 'stpp.ttml.im1t'; diff --git a/src/utils/mediacapabilities-helper.ts b/src/utils/mediacapabilities-helper.ts index f9247458d05..b002c518a3f 100644 --- a/src/utils/mediacapabilities-helper.ts +++ b/src/utils/mediacapabilities-helper.ts @@ -1,7 +1,7 @@ import { fillInMissingAV01Params, mimeTypeForCodec } from './codecs'; +import type { AudioTracksByGroup } from './rendition-helper'; import type { Level, VideoRange } from '../types/level'; import type { AudioSelectionOption } from '../types/media-playlist'; -import type { AudioTracksByGroup } from './rendition-helper'; export type MediaDecodingInfo = { supported: boolean; diff --git a/src/utils/mediakeys-helper.ts b/src/utils/mediakeys-helper.ts index 0df1321a970..cccb9bae7ee 100755 --- a/src/utils/mediakeys-helper.ts +++ b/src/utils/mediakeys-helper.ts @@ -1,7 +1,7 @@ -import type { DRMSystemOptions, EMEControllerConfig } from '../config'; import { optionalSelf } from './global'; import { changeEndianness } from './keysystem-util'; import { base64Decode } from './numeric-encoding-utils'; +import type { DRMSystemOptions, EMEControllerConfig } from '../config'; /** * @see https://developer.mozilla.org/en-US/docs/Web/API/Navigator/requestMediaKeySystemAccess diff --git a/src/utils/mp4-tools.ts b/src/utils/mp4-tools.ts index 309750628e1..ec39d8526f7 100644 --- a/src/utils/mp4-tools.ts +++ b/src/utils/mp4-tools.ts @@ -1,11 +1,11 @@ -import { ElementaryStreamTypes } from '../loader/fragment'; -import { sliceUint8 } from './typed-array'; import { utf8ArrayToStr } from '@svta/common-media-library/utils/utf8ArrayToStr'; -import { logger } from '../utils/logger'; import Hex from './hex'; +import { sliceUint8 } from './typed-array'; +import { ElementaryStreamTypes } from '../loader/fragment'; +import { logger } from '../utils/logger'; import type { KeySystemIds } from './mediakeys-helper'; -import type { PassthroughTrack, UserdataSample } from '../types/demuxer'; import type { DecryptData } from '../loader/level-key'; +import type { PassthroughTrack, UserdataSample } from '../types/demuxer'; const UINT32_MAX = Math.pow(2, 32) - 1; const push = [].push; diff --git a/src/utils/output-filter.ts b/src/utils/output-filter.ts index 88d1a355048..c6887f76a61 100644 --- a/src/utils/output-filter.ts +++ b/src/utils/output-filter.ts @@ -1,5 +1,5 @@ -import type { TimelineController } from '../controller/timeline-controller'; import type { CaptionScreen } from './cea-608-parser'; +import type { TimelineController } from '../controller/timeline-controller'; export default class OutputFilter { private timelineController: TimelineController; diff --git a/src/utils/variable-substitution.ts b/src/utils/variable-substitution.ts index d2b7db20c38..d1f5dc8c466 100644 --- a/src/utils/variable-substitution.ts +++ b/src/utils/variable-substitution.ts @@ -1,6 +1,6 @@ import type { AttrList } from './attr-list'; -import type { ParsedMultivariantPlaylist } from '../loader/m3u8-parser'; import type { LevelDetails } from '../loader/level-details'; +import type { ParsedMultivariantPlaylist } from '../loader/m3u8-parser'; import type { VariableMap } from '../types/level'; const VARIABLE_REPLACEMENT_REGEX = /\{\$([a-zA-Z0-9-_]+)\}/g; diff --git a/src/utils/webvtt-parser.ts b/src/utils/webvtt-parser.ts index 2aa5989757a..7e44e3da932 100644 --- a/src/utils/webvtt-parser.ts +++ b/src/utils/webvtt-parser.ts @@ -1,11 +1,9 @@ -import { VTTParser } from './vttparser'; import { utf8ArrayToStr } from '@svta/common-media-library/utils/utf8ArrayToStr'; import { hash } from './hash'; -import { - RationalTimestamp, - toMpegTsClockFromTimescale, -} from './timescale-conversion'; +import { toMpegTsClockFromTimescale } from './timescale-conversion'; +import { VTTParser } from './vttparser'; import { normalizePts } from '../remux/mp4-remuxer'; +import type { RationalTimestamp } from './timescale-conversion'; import type { VTTCCs } from '../types/vtt'; const LINEBREAKS = /\r\n|\n\r|\n|\r/g; diff --git a/src/utils/xhr-loader.ts b/src/utils/xhr-loader.ts index d6155cc622a..0e4d761500a 100644 --- a/src/utils/xhr-loader.ts +++ b/src/utils/xhr-loader.ts @@ -1,15 +1,16 @@ +import { getRetryDelay, shouldRetry } from './error-helper'; +import { LoadStats } from '../loader/load-stats'; import { logger } from '../utils/logger'; +import type { HlsConfig } from '../config'; +import type { RetryConfig } from '../config'; import type { - LoaderCallbacks, - LoaderContext, - LoaderStats, Loader, + LoaderCallbacks, LoaderConfiguration, + LoaderContext, LoaderResponse, + LoaderStats, } from '../types/loader'; -import { LoadStats } from '../loader/load-stats'; -import { type HlsConfig, RetryConfig } from '../config'; -import { getRetryDelay, shouldRetry } from './error-helper'; const AGE_HEADER_LINE_REGEX = /^age:\s*[\d.]+\s*$/im; diff --git a/tests/mocks/hls.mock.ts b/tests/mocks/hls.mock.ts index 4ca97be0601..f52f91c907a 100644 --- a/tests/mocks/hls.mock.ts +++ b/tests/mocks/hls.mock.ts @@ -1,12 +1,11 @@ -import Hls from '../../src/hls'; import { EventEmitter } from 'eventemitter3'; +import * as sinon from 'sinon'; +import Hls from '../../src/hls'; import { logger } from '../../src/utils/logger'; -import type { HlsEventEmitter, HlsListeners } from '../../src/events'; import type { HlsConfig } from '../../src/config'; +import type { HlsEventEmitter, HlsListeners } from '../../src/events'; import type { Level } from '../../src/types/level'; -import * as sinon from 'sinon'; - // All public methods of Hls instance const publicMethods = [ 'destroy', diff --git a/tests/mocks/loader.mock.ts b/tests/mocks/loader.mock.ts index 994405970a9..4770050a07b 100644 --- a/tests/mocks/loader.mock.ts +++ b/tests/mocks/loader.mock.ts @@ -1,4 +1,5 @@ import { LoadStats } from '../../src/loader/load-stats'; +import type { HlsConfig } from '../../src/config'; import type { FragmentLoaderContext, Loader, @@ -6,7 +7,6 @@ import type { LoaderConfiguration, LoaderContext, } from '../../src/types/loader'; -import type { HlsConfig } from '../../src/config'; export class MockXhr implements Loader { context!: LoaderContext; diff --git a/tests/unit/controller/abr-controller.ts b/tests/unit/controller/abr-controller.ts index 5834a84f7a2..b5702ba1749 100644 --- a/tests/unit/controller/abr-controller.ts +++ b/tests/unit/controller/abr-controller.ts @@ -1,20 +1,21 @@ -import AbrController from '../../../src/controller/abr-controller'; -import { Level, LevelParsed } from '../../../src/types/level'; -import { LevelDetails } from '../../../src/loader/level-details'; +import chai from 'chai'; +import sinon from 'sinon'; +import sinonChai from 'sinon-chai'; +import { Events } from '../../../src/events'; +import Hls from '../../../src/hls'; import { Fragment } from '../../../src/loader/fragment'; +import { LevelDetails } from '../../../src/loader/level-details'; import { LoadStats } from '../../../src/loader/load-stats'; -import { AttrList } from '../../../src/utils/attr-list'; +import { Level } from '../../../src/types/level'; import { PlaylistLevelType } from '../../../src/types/loader'; -import { Events, HlsListeners } from '../../../src/events'; -import { +import { AttrList } from '../../../src/utils/attr-list'; +import type AbrController from '../../../src/controller/abr-controller'; +import type { HlsListeners } from '../../../src/events'; +import type { LevelParsed } from '../../../src/types/level'; +import type { MediaAttributes, MediaPlaylist, } from '../../../src/types/media-playlist'; -import Hls from '../../../src/hls'; - -import sinon from 'sinon'; -import chai from 'chai'; -import sinonChai from 'sinon-chai'; chai.use(sinonChai); const expect = chai.expect; diff --git a/tests/unit/controller/audio-stream-controller.ts b/tests/unit/controller/audio-stream-controller.ts index 5b6ad5a49a5..9b7aabee2c2 100644 --- a/tests/unit/controller/audio-stream-controller.ts +++ b/tests/unit/controller/audio-stream-controller.ts @@ -1,27 +1,26 @@ -import Hls from '../../../src/hls'; +import chai from 'chai'; +import sinonChai from 'sinon-chai'; import { hlsDefaultConfig } from '../../../src/config'; import AudioStreamController from '../../../src/controller/audio-stream-controller'; -import { Events } from '../../../src/events'; +import { State } from '../../../src/controller/base-stream-controller'; import { FragmentTracker } from '../../../src/controller/fragment-tracker'; +import { Events } from '../../../src/events'; +import Hls from '../../../src/hls'; import KeyLoader from '../../../src/loader/key-loader'; import { LoadStats } from '../../../src/loader/load-stats'; -import { AttrList } from '../../../src/utils/attr-list'; -import { - MediaAttributes, - MediaPlaylist, -} from '../../../src/types/media-playlist'; import { Level } from '../../../src/types/level'; +import { AttrList } from '../../../src/utils/attr-list'; +import type { Fragment } from '../../../src/loader/fragment'; +import type { LevelDetails } from '../../../src/loader/level-details'; import type { - AudioTrackSwitchingData, AudioTrackLoadedData, + AudioTrackSwitchingData, TrackLoadedData, } from '../../../src/types/events'; -import type { LevelDetails } from '../../../src/loader/level-details'; -import type { Fragment } from '../../../src/loader/fragment'; - -import chai from 'chai'; -import sinonChai from 'sinon-chai'; -import { State } from '../../../src/controller/base-stream-controller'; +import type { + MediaAttributes, + MediaPlaylist, +} from '../../../src/types/media-playlist'; chai.use(sinonChai); const expect = chai.expect; diff --git a/tests/unit/controller/audio-track-controller.ts b/tests/unit/controller/audio-track-controller.ts index dd60cc11985..dea8b94677f 100644 --- a/tests/unit/controller/audio-track-controller.ts +++ b/tests/unit/controller/audio-track-controller.ts @@ -1,26 +1,25 @@ +import chai from 'chai'; +import sinon from 'sinon'; +import sinonChai from 'sinon-chai'; import AudioTrackController from '../../../src/controller/audio-track-controller'; +import { Events } from '../../../src/events'; import Hls from '../../../src/hls'; -import type { - MediaAttributes, - MediaPlaylist, -} from '../../../src/types/media-playlist'; -import { AttrList } from '../../../src/utils/attr-list'; import { LevelDetails } from '../../../src/loader/level-details'; -import { Events } from '../../../src/events'; import { PlaylistContextType } from '../../../src/types/loader'; +import { AttrList } from '../../../src/utils/attr-list'; +import type { + ComponentAPI, + NetworkComponentAPI, +} from '../../../src/types/component-api'; import type { AudioTrackLoadedData, ErrorData, } from '../../../src/types/events'; import type { Level } from '../../../src/types/level'; import type { - ComponentAPI, - NetworkComponentAPI, -} from '../../../src/types/component-api'; - -import sinon from 'sinon'; -import chai from 'chai'; -import sinonChai from 'sinon-chai'; + MediaAttributes, + MediaPlaylist, +} from '../../../src/types/media-playlist'; chai.use(sinonChai); const expect = chai.expect; diff --git a/tests/unit/controller/base-stream-controller.ts b/tests/unit/controller/base-stream-controller.ts index 9f80c19095f..b79ff5e947c 100644 --- a/tests/unit/controller/base-stream-controller.ts +++ b/tests/unit/controller/base-stream-controller.ts @@ -1,14 +1,13 @@ -import Hls from '../../../src/hls'; +import chai from 'chai'; +import sinonChai from 'sinon-chai'; import { hlsDefaultConfig } from '../../../src/config'; import BaseStreamController from '../../../src/controller/stream-controller'; +import Hls from '../../../src/hls'; import KeyLoader from '../../../src/loader/key-loader'; import { TimeRangesMock } from '../../mocks/time-ranges.mock'; -import type { BufferInfo } from '../../../src/utils/buffer-helper'; -import type { LevelDetails } from '../../../src/loader/level-details'; import type { Fragment, Part } from '../../../src/loader/fragment'; - -import chai from 'chai'; -import sinonChai from 'sinon-chai'; +import type { LevelDetails } from '../../../src/loader/level-details'; +import type { BufferInfo } from '../../../src/utils/buffer-helper'; chai.use(sinonChai); const expect = chai.expect; diff --git a/tests/unit/controller/buffer-controller-operations.ts b/tests/unit/controller/buffer-controller-operations.ts index c9672f72842..433b591885e 100644 --- a/tests/unit/controller/buffer-controller-operations.ts +++ b/tests/unit/controller/buffer-controller-operations.ts @@ -1,28 +1,27 @@ -import sinon from 'sinon'; import chai from 'chai'; +import sinon from 'sinon'; import sinonChai from 'sinon-chai'; -import Hls from '../../../src/hls'; - -import BufferOperationQueue from '../../../src/controller/buffer-operation-queue'; import BufferController from '../../../src/controller/buffer-controller'; -import { - BufferOperation, - BufferOperationQueues, - SourceBufferName, - SourceBufferTrackSet, -} from '../../../src/types/buffer'; -import { BufferAppendingData } from '../../../src/types/events'; -import { Events } from '../../../src/events'; import { FragmentTracker } from '../../../src/controller/fragment-tracker'; import { ErrorDetails, ErrorTypes } from '../../../src/errors'; +import { Events } from '../../../src/events'; +import Hls from '../../../src/hls'; import { ElementaryStreamTypes, Fragment } from '../../../src/loader/fragment'; import M3U8Parser from '../../../src/loader/m3u8-parser'; import { PlaylistLevelType } from '../../../src/types/loader'; import { ChunkMetadata } from '../../../src/types/transmuxer'; +import type BufferOperationQueue from '../../../src/controller/buffer-operation-queue'; +import type { + BufferOperation, + BufferOperationQueues, + SourceBufferName, + SourceBufferTrackSet, +} from '../../../src/types/buffer'; import type { ComponentAPI, NetworkComponentAPI, } from '../../../src/types/component-api'; +import type { BufferAppendingData } from '../../../src/types/events'; chai.use(sinonChai); const expect = chai.expect; diff --git a/tests/unit/controller/buffer-controller.ts b/tests/unit/controller/buffer-controller.ts index 8eb771649f9..e6d653e5be2 100644 --- a/tests/unit/controller/buffer-controller.ts +++ b/tests/unit/controller/buffer-controller.ts @@ -1,26 +1,25 @@ -import Hls from '../../../src/hls'; -import BufferController from '../../../src/controller/buffer-controller'; -import { Events } from '../../../src/events'; -import { FragmentTracker } from '../../../src/controller/fragment-tracker'; +import chai from 'chai'; +import sinon from 'sinon'; +import sinonChai from 'sinon-chai'; import { MockMediaElement, MockMediaSource, } from './buffer-controller-operations'; -import type { - ComponentAPI, - NetworkComponentAPI, -} from '../../../src/types/component-api'; +import BufferController from '../../../src/controller/buffer-controller'; +import { FragmentTracker } from '../../../src/controller/fragment-tracker'; +import { Events } from '../../../src/events'; +import Hls from '../../../src/hls'; +import type BufferOperationQueue from '../../../src/controller/buffer-operation-queue'; import type { ExtendedSourceBuffer, ParsedTrack, SourceBuffersTuple, SourceBufferTrackSet, } from '../../../src/types/buffer'; -import type BufferOperationQueue from '../../../src/controller/buffer-operation-queue'; - -import sinon from 'sinon'; -import chai from 'chai'; -import sinonChai from 'sinon-chai'; +import type { + ComponentAPI, + NetworkComponentAPI, +} from '../../../src/types/component-api'; chai.use(sinonChai); const expect = chai.expect; diff --git a/tests/unit/controller/buffer-operation-queue.ts b/tests/unit/controller/buffer-operation-queue.ts index 6e6c44a9ab3..c2554b7c24c 100644 --- a/tests/unit/controller/buffer-operation-queue.ts +++ b/tests/unit/controller/buffer-operation-queue.ts @@ -1,13 +1,12 @@ +import chai from 'chai'; +import sinon from 'sinon'; +import sinonChai from 'sinon-chai'; import BufferOperationQueue from '../../../src/controller/buffer-operation-queue'; import type { BufferOperation, SourceBufferTrackSet, } from '../../../src/types/buffer'; -import sinon from 'sinon'; -import chai from 'chai'; -import sinonChai from 'sinon-chai'; - chai.use(sinonChai); const expect = chai.expect; const queueNames = ['audio', 'video']; diff --git a/tests/unit/controller/cmcd-controller.ts b/tests/unit/controller/cmcd-controller.ts index b58911ee1f2..029cb6e608c 100644 --- a/tests/unit/controller/cmcd-controller.ts +++ b/tests/unit/controller/cmcd-controller.ts @@ -1,13 +1,12 @@ +import { CmcdHeaderField } from '@svta/common-media-library/cmcd/CmcdHeaderField'; +import chai from 'chai'; import CMCDController from '../../../src/controller/cmcd-controller'; import Hls from '../../../src/hls'; -import type { CMCDControllerConfig } from '../../../src/config'; -import { CmcdHeaderField } from '@svta/common-media-library/cmcd/CmcdHeaderField'; import M3U8Parser from '../../../src/loader/m3u8-parser'; import { PlaylistLevelType } from '../../../src/types/loader'; +import type { CMCDControllerConfig } from '../../../src/config'; import type { Fragment, Part } from '../../../src/loader/fragment'; -import chai from 'chai'; - const expect = chai.expect; let cmcdController; diff --git a/tests/unit/controller/content-steering-controller.ts b/tests/unit/controller/content-steering-controller.ts index 69292d38ce4..3ad9bd61c0e 100644 --- a/tests/unit/controller/content-steering-controller.ts +++ b/tests/unit/controller/content-steering-controller.ts @@ -1,15 +1,19 @@ +import chai from 'chai'; +import sinon from 'sinon'; +import sinonChai from 'sinon-chai'; +import { multivariantPlaylistWithPathways } from './level-controller'; +import AudioTrackController from '../../../src/controller/audio-track-controller'; import ContentSteeringController from '../../../src/controller/content-steering-controller'; +import LevelController from '../../../src/controller/level-controller'; +import SubtitleTrackController from '../../../src/controller/subtitle-track-controller'; import { Events } from '../../../src/events'; import { LoadStats } from '../../../src/loader/load-stats'; +import M3U8Parser from '../../../src/loader/m3u8-parser'; +import { getMediaSource } from '../../../src/utils/mediasource-helper'; import HlsMock from '../../mocks/hls.mock'; import { MockXhr } from '../../mocks/loader.mock'; -import { multivariantPlaylistWithPathways } from './level-controller'; -import M3U8Parser, { - ParsedMultivariantPlaylist, -} from '../../../src/loader/m3u8-parser'; -import LevelController from '../../../src/controller/level-controller'; -import AudioTrackController from '../../../src/controller/audio-track-controller'; -import SubtitleTrackController from '../../../src/controller/subtitle-track-controller'; +import type { SteeringManifest } from '../../../src/controller/content-steering-controller'; +import type { ParsedMultivariantPlaylist } from '../../../src/loader/m3u8-parser'; import type { AudioTracksUpdatedData, LevelsUpdatedData, @@ -18,14 +22,8 @@ import type { SubtitleTracksUpdatedData, } from '../../../src/types/events'; import type { Level } from '../../../src/types/level'; -import type { MediaPlaylist } from '../../../src/types/media-playlist'; -import type { SteeringManifest } from '../../../src/controller/content-steering-controller'; import type { LoaderResponse } from '../../../src/types/loader'; - -import sinon from 'sinon'; -import chai from 'chai'; -import sinonChai from 'sinon-chai'; -import { getMediaSource } from '../../../src/utils/mediasource-helper'; +import type { MediaPlaylist } from '../../../src/types/media-playlist'; chai.use(sinonChai); const expect = chai.expect; diff --git a/tests/unit/controller/eme-controller.ts b/tests/unit/controller/eme-controller.ts index 0556f9af5c3..b8f3152266d 100644 --- a/tests/unit/controller/eme-controller.ts +++ b/tests/unit/controller/eme-controller.ts @@ -1,15 +1,13 @@ -import EMEController, { - MediaKeySessionContext, -} from '../../../src/controller/eme-controller'; -import HlsMock from '../../mocks/hls.mock'; +import chai from 'chai'; import { EventEmitter } from 'eventemitter3'; -import { ErrorDetails } from '../../../src/errors'; -import { Events } from '../../../src/events'; - import sinon from 'sinon'; -import chai from 'chai'; import sinonChai from 'sinon-chai'; -import { MediaAttachedData } from '../../../src/types/events'; +import EMEController from '../../../src/controller/eme-controller'; +import { ErrorDetails } from '../../../src/errors'; +import { Events } from '../../../src/events'; +import HlsMock from '../../mocks/hls.mock'; +import type { MediaKeySessionContext } from '../../../src/controller/eme-controller'; +import type { MediaAttachedData } from '../../../src/types/events'; chai.use(sinonChai); const expect = chai.expect; diff --git a/tests/unit/controller/error-controller.ts b/tests/unit/controller/error-controller.ts index 7836d45033d..62bf6433bb3 100644 --- a/tests/unit/controller/error-controller.ts +++ b/tests/unit/controller/error-controller.ts @@ -1,17 +1,16 @@ -import Hls from '../../../src/hls'; -import { Events } from '../../../src/events'; +import chai from 'chai'; +import sinon from 'sinon'; +import sinonChai from 'sinon-chai'; +import { multivariantPlaylistWithRedundantFallbacks } from './level-controller'; import { ErrorDetails, ErrorTypes } from '../../../src/errors'; +import { Events } from '../../../src/events'; +import Hls from '../../../src/hls'; import type { ErrorData, FragLoadedData, LevelSwitchingData, } from '../../../src/types/events'; -import sinon from 'sinon'; -import chai from 'chai'; -import sinonChai from 'sinon-chai'; -import { multivariantPlaylistWithRedundantFallbacks } from './level-controller'; - chai.use(sinonChai); const expect = chai.expect; diff --git a/tests/unit/controller/fragment-tracker.ts b/tests/unit/controller/fragment-tracker.ts index ef56611aaa2..d245ef6fb6c 100644 --- a/tests/unit/controller/fragment-tracker.ts +++ b/tests/unit/controller/fragment-tracker.ts @@ -1,22 +1,21 @@ -import Hls from '../../../src/hls'; -import { Events } from '../../../src/events'; +import chai from 'chai'; +import sinonChai from 'sinon-chai'; import { - FragmentTracker, FragmentState, + FragmentTracker, } from '../../../src/controller/fragment-tracker'; +import { Events } from '../../../src/events'; +import Hls from '../../../src/hls'; +import { ElementaryStreamTypes, Fragment } from '../../../src/loader/fragment'; +import { LoadStats } from '../../../src/loader/load-stats'; import { PlaylistLevelType } from '../../../src/types/loader'; import { ChunkMetadata } from '../../../src/types/transmuxer'; -import { Fragment, ElementaryStreamTypes } from '../../../src/loader/fragment'; -import { LoadStats } from '../../../src/loader/load-stats'; import type { BufferAppendedData, FragBufferedData, FragLoadedData, } from '../../../src/types/events'; -import chai from 'chai'; -import sinonChai from 'sinon-chai'; - chai.use(sinonChai); const expect = chai.expect; diff --git a/tests/unit/controller/interstitials-controller.ts b/tests/unit/controller/interstitials-controller.ts index 5a8fae0bca3..e08f820b1f8 100644 --- a/tests/unit/controller/interstitials-controller.ts +++ b/tests/unit/controller/interstitials-controller.ts @@ -1,11 +1,14 @@ -import Hls from '../../../src/hls'; -import { Events } from '../../../src/events'; +import chai from 'chai'; +import sinon from 'sinon'; +import sinonChai from 'sinon-chai'; import InterstitialsController from '../../../src/controller/interstitials-controller'; +import { Events } from '../../../src/events'; +import Hls from '../../../src/hls'; import { TimelineOccupancy } from '../../../src/loader/interstitial-event'; +import M3U8Parser from '../../../src/loader/m3u8-parser'; import { Level } from '../../../src/types/level'; import { PlaylistLevelType } from '../../../src/types/loader'; import { AttrList } from '../../../src/utils/attr-list'; -import M3U8Parser from '../../../src/loader/m3u8-parser'; import type { HlsConfig } from '../../../src/config'; import type { InterstitialScheduleItem } from '../../../src/controller/interstitials-schedule'; import type { @@ -13,10 +16,6 @@ import type { NetworkComponentAPI, } from '../../../src/types/component-api'; -import sinon from 'sinon'; -import chai from 'chai'; -import sinonChai from 'sinon-chai'; - chai.use(sinonChai); const expect = chai.expect; diff --git a/tests/unit/controller/latency-controller.ts b/tests/unit/controller/latency-controller.ts index dbb224691fb..22ae264fa43 100644 --- a/tests/unit/controller/latency-controller.ts +++ b/tests/unit/controller/latency-controller.ts @@ -1,13 +1,12 @@ /* eslint-disable dot-notation */ +import chai from 'chai'; +import sinon from 'sinon'; +import sinonChai from 'sinon-chai'; import LatencyController from '../../../src/controller/latency-controller'; -import Hls from '../../../src/hls'; import { Events } from '../../../src/events'; +import Hls from '../../../src/hls'; import { LevelDetails } from '../../../src/loader/level-details'; -import { LevelUpdatedData } from '../../../src/types/events'; - -import sinon from 'sinon'; -import chai from 'chai'; -import sinonChai from 'sinon-chai'; +import type { LevelUpdatedData } from '../../../src/types/events'; chai.use(sinonChai); const expect = chai.expect; diff --git a/tests/unit/controller/level-controller.ts b/tests/unit/controller/level-controller.ts index 15907a8a659..232f1928bc6 100755 --- a/tests/unit/controller/level-controller.ts +++ b/tests/unit/controller/level-controller.ts @@ -1,33 +1,29 @@ +import chai from 'chai'; +import sinon from 'sinon'; +import sinonChai from 'sinon-chai'; import LevelController from '../../../src/controller/level-controller'; -import HlsMock from '../../mocks/hls.mock'; -import { Events } from '../../../src/events'; import { ErrorDetails, ErrorTypes } from '../../../src/errors'; +import { Events } from '../../../src/events'; +import M3U8Parser from '../../../src/loader/m3u8-parser'; import { Level } from '../../../src/types/level'; +import { PlaylistLevelType } from '../../../src/types/loader'; import { AttrList } from '../../../src/utils/attr-list'; -import { - PlaylistLevelType, - PlaylistLoaderContext, -} from '../../../src/types/loader'; -import M3U8Parser, { - ParsedMultivariantPlaylist, -} from '../../../src/loader/m3u8-parser'; +import { getMediaSource } from '../../../src/utils/mediasource-helper'; +import HlsMock from '../../mocks/hls.mock'; +import type { Fragment } from '../../../src/loader/fragment'; import type { LevelDetails } from '../../../src/loader/level-details'; +import type { ParsedMultivariantPlaylist } from '../../../src/loader/m3u8-parser'; import type { ManifestLoadedData, ManifestParsedData, } from '../../../src/types/events'; import type { LevelParsed } from '../../../src/types/level'; +import type { PlaylistLoaderContext } from '../../../src/types/loader'; import type { MediaAttributes, MediaPlaylist, MediaPlaylistType, } from '../../../src/types/media-playlist'; -import type { Fragment } from '../../../src/loader/fragment'; - -import sinon from 'sinon'; -import chai from 'chai'; -import sinonChai from 'sinon-chai'; -import { getMediaSource } from '../../../src/utils/mediasource-helper'; chai.use(sinonChai); const expect = chai.expect; diff --git a/tests/unit/controller/level-helper.ts b/tests/unit/controller/level-helper.ts index 0f3ee2d61f4..3d469b0a5ab 100644 --- a/tests/unit/controller/level-helper.ts +++ b/tests/unit/controller/level-helper.ts @@ -1,3 +1,11 @@ +import chai from 'chai'; +import sinon from 'sinon'; +import sinonChai from 'sinon-chai'; +import { Fragment, Part } from '../../../src/loader/fragment'; +import { LevelDetails } from '../../../src/loader/level-details'; +import M3U8Parser from '../../../src/loader/m3u8-parser'; +import { PlaylistLevelType } from '../../../src/types/loader'; +import { AttrList } from '../../../src/utils/attr-list'; import { adjustSliding, computeReloadInterval, @@ -5,14 +13,7 @@ import { mapPartIntersection, mergeDetails, } from '../../../src/utils/level-helper'; -import { LevelDetails } from '../../../src/loader/level-details'; -import { Fragment, MediaFragment, Part } from '../../../src/loader/fragment'; -import M3U8Parser from '../../../src/loader/m3u8-parser'; -import { PlaylistLevelType } from '../../../src/types/loader'; -import { AttrList } from '../../../src/utils/attr-list'; -import sinon from 'sinon'; -import chai from 'chai'; -import sinonChai from 'sinon-chai'; +import type { MediaFragment } from '../../../src/loader/fragment'; chai.use(sinonChai); const expect = chai.expect; diff --git a/tests/unit/controller/stream-controller.ts b/tests/unit/controller/stream-controller.ts index 6ee31e9f121..e56f80b56fb 100644 --- a/tests/unit/controller/stream-controller.ts +++ b/tests/unit/controller/stream-controller.ts @@ -1,25 +1,24 @@ /* eslint-disable dot-notation */ -import Hls from '../../../src/hls'; -import { Events } from '../../../src/events'; -import { - FragmentTracker, - FragmentState, -} from '../../../src/controller/fragment-tracker'; -import StreamController from '../../../src/controller/stream-controller'; +import chai from 'chai'; +import sinon from 'sinon'; +import sinonChai from 'sinon-chai'; import { State } from '../../../src/controller/base-stream-controller'; -import { mockFragments } from '../../mocks/data'; -import { Fragment, MediaFragment } from '../../../src/loader/fragment'; +import { FragmentState } from '../../../src/controller/fragment-tracker'; +import { Events } from '../../../src/events'; +import Hls from '../../../src/hls'; +import { Fragment } from '../../../src/loader/fragment'; import { LevelDetails } from '../../../src/loader/level-details'; -import M3U8Parser from '../../../src/loader/m3u8-parser'; import { LoadStats } from '../../../src/loader/load-stats'; +import M3U8Parser from '../../../src/loader/m3u8-parser'; +import { Level } from '../../../src/types/level'; import { PlaylistLevelType } from '../../../src/types/loader'; import { AttrList } from '../../../src/utils/attr-list'; -import { Level, LevelAttributes } from '../../../src/types/level'; +import { mockFragments } from '../../mocks/data'; +import type { FragmentTracker } from '../../../src/controller/fragment-tracker'; +import type StreamController from '../../../src/controller/stream-controller'; +import type { MediaFragment } from '../../../src/loader/fragment'; import type { ParsedMultivariantPlaylist } from '../../../src/loader/m3u8-parser'; - -import sinon from 'sinon'; -import chai from 'chai'; -import sinonChai from 'sinon-chai'; +import type { LevelAttributes } from '../../../src/types/level'; chai.use(sinonChai); const expect = chai.expect; diff --git a/tests/unit/controller/subtitle-track-controller.ts b/tests/unit/controller/subtitle-track-controller.ts index 573ddf2dfe4..7864f5f3339 100644 --- a/tests/unit/controller/subtitle-track-controller.ts +++ b/tests/unit/controller/subtitle-track-controller.ts @@ -1,22 +1,21 @@ +import chai from 'chai'; +import sinon from 'sinon'; +import sinonChai from 'sinon-chai'; import SubtitleTrackController from '../../../src/controller/subtitle-track-controller'; +import { Events } from '../../../src/events'; import Hls from '../../../src/hls'; -import { LoadStats } from '../../../src/loader/load-stats'; import { LevelDetails } from '../../../src/loader/level-details'; -import { Events } from '../../../src/events'; +import { LoadStats } from '../../../src/loader/load-stats'; import { AttrList } from '../../../src/utils/attr-list'; -import type { - MediaAttributes, - MediaPlaylist, -} from '../../../src/types/media-playlist'; -import type { Level } from '../../../src/types/level'; import type { ComponentAPI, NetworkComponentAPI, } from '../../../src/types/component-api'; - -import sinon from 'sinon'; -import chai from 'chai'; -import sinonChai from 'sinon-chai'; +import type { Level } from '../../../src/types/level'; +import type { + MediaAttributes, + MediaPlaylist, +} from '../../../src/types/media-playlist'; chai.use(sinonChai); const expect = chai.expect; diff --git a/tests/unit/demuxer/base-audio-demuxer.ts b/tests/unit/demuxer/base-audio-demuxer.ts index 5ef53b5a544..efb2bda08d7 100644 --- a/tests/unit/demuxer/base-audio-demuxer.ts +++ b/tests/unit/demuxer/base-audio-demuxer.ts @@ -1,5 +1,5 @@ -import { initPTSFn } from '../../../src/demux/audio/base-audio-demuxer'; import { expect } from 'chai'; +import { initPTSFn } from '../../../src/demux/audio/base-audio-demuxer'; describe('BaseAudioDemuxer', function () { describe('initPTSFn', function () { diff --git a/tests/unit/demuxer/transmuxer.ts b/tests/unit/demuxer/transmuxer.ts index 4f1f2a74bb7..a3c84f80bfc 100644 --- a/tests/unit/demuxer/transmuxer.ts +++ b/tests/unit/demuxer/transmuxer.ts @@ -1,13 +1,14 @@ -import TransmuxerInterface from '../../../src/demux/transmuxer-interface'; -import { TransmuxState, TransmuxConfig } from '../../../src/demux/transmuxer'; -import { ChunkMetadata, TransmuxerResult } from '../../../src/types/transmuxer'; -import { Fragment, MediaFragment } from '../../../src/loader/fragment'; -import { PlaylistLevelType } from '../../../src/types/loader'; -import Hls from '../../../src/hls'; - -import sinon from 'sinon'; import chai from 'chai'; +import sinon from 'sinon'; import sinonChai from 'sinon-chai'; +import { TransmuxConfig, TransmuxState } from '../../../src/demux/transmuxer'; +import TransmuxerInterface from '../../../src/demux/transmuxer-interface'; +import Hls from '../../../src/hls'; +import { Fragment } from '../../../src/loader/fragment'; +import { PlaylistLevelType } from '../../../src/types/loader'; +import { ChunkMetadata } from '../../../src/types/transmuxer'; +import type { MediaFragment } from '../../../src/loader/fragment'; +import type { TransmuxerResult } from '../../../src/types/transmuxer'; chai.use(sinonChai); const expect = chai.expect; diff --git a/tests/unit/hls.ts b/tests/unit/hls.ts index dfa96f1586e..c7f12081c75 100644 --- a/tests/unit/hls.ts +++ b/tests/unit/hls.ts @@ -1,11 +1,10 @@ -import Hls from '../../src/hls'; -import { hlsDefaultConfig } from '../../src/config'; -import { Events } from '../../src/events'; -import { ErrorTypes, ErrorDetails } from '../../src/errors'; - import chai from 'chai'; -import sinonChai from 'sinon-chai'; import sinon from 'sinon'; +import sinonChai from 'sinon-chai'; +import { hlsDefaultConfig } from '../../src/config'; +import { ErrorDetails, ErrorTypes } from '../../src/errors'; +import { Events } from '../../src/events'; +import Hls from '../../src/hls'; chai.use(sinonChai); const expect = chai.expect; diff --git a/tests/unit/loader/date-range.ts b/tests/unit/loader/date-range.ts index 4f4543d8175..69c1385dc88 100644 --- a/tests/unit/loader/date-range.ts +++ b/tests/unit/loader/date-range.ts @@ -1,8 +1,7 @@ +import chai from 'chai'; import { DateRange } from '../../../src/loader/date-range'; import { AttrList } from '../../../src/utils/attr-list'; -import chai from 'chai'; - const expect = chai.expect; describe('DateRange class', function () { diff --git a/tests/unit/loader/fragment-loader.ts b/tests/unit/loader/fragment-loader.ts index c1e1e4c989c..777c80710df 100644 --- a/tests/unit/loader/fragment-loader.ts +++ b/tests/unit/loader/fragment-loader.ts @@ -1,16 +1,15 @@ -import FragmentLoader, { LoadError } from '../../../src/loader/fragment-loader'; +import chai from 'chai'; +import sinon from 'sinon'; +import sinonChai from 'sinon-chai'; +import { hlsDefaultConfig, mergeConfig } from '../../../src/config'; +import { ErrorDetails, ErrorTypes } from '../../../src/errors'; import { Fragment } from '../../../src/loader/fragment'; +import FragmentLoader, { LoadError } from '../../../src/loader/fragment-loader'; import { LevelDetails } from '../../../src/loader/level-details'; -import { ErrorDetails, ErrorTypes } from '../../../src/errors'; import { LoadStats } from '../../../src/loader/load-stats'; -import { hlsDefaultConfig, mergeConfig } from '../../../src/config'; import { PlaylistLevelType } from '../../../src/types/loader'; -import { MockXhr } from '../../mocks/loader.mock'; import { logger } from '../../../src/utils/logger'; - -import sinon from 'sinon'; -import chai from 'chai'; -import sinonChai from 'sinon-chai'; +import { MockXhr } from '../../mocks/loader.mock'; chai.use(sinonChai); const expect = chai.expect; diff --git a/tests/unit/loader/fragment.ts b/tests/unit/loader/fragment.ts index a92287d94eb..2b2cf7d4b0b 100644 --- a/tests/unit/loader/fragment.ts +++ b/tests/unit/loader/fragment.ts @@ -1,10 +1,9 @@ +import chai from 'chai'; +import sinonChai from 'sinon-chai'; import { Fragment } from '../../../src/loader/fragment'; import { LevelKey } from '../../../src/loader/level-key'; import { PlaylistLevelType } from '../../../src/types/loader'; -import chai from 'chai'; -import sinonChai from 'sinon-chai'; - chai.use(sinonChai); const expect = chai.expect; diff --git a/tests/unit/loader/playlist-loader.ts b/tests/unit/loader/playlist-loader.ts index 28c4263a4b3..4f579e5d908 100644 --- a/tests/unit/loader/playlist-loader.ts +++ b/tests/unit/loader/playlist-loader.ts @@ -1,11 +1,10 @@ -import M3U8Parser from '../../../src/loader/m3u8-parser'; -import { AttrList } from '../../../src/utils/attr-list'; -import { PlaylistLevelType } from '../../../src/types/loader'; -import { LevelKey } from '../../../src/loader/level-key'; -import { Fragment, Part } from '../../../src/loader/fragment'; - import chai from 'chai'; import sinonChai from 'sinon-chai'; +import M3U8Parser from '../../../src/loader/m3u8-parser'; +import { PlaylistLevelType } from '../../../src/types/loader'; +import { AttrList } from '../../../src/utils/attr-list'; +import type { Fragment, Part } from '../../../src/loader/fragment'; +import type { LevelKey } from '../../../src/loader/level-key'; chai.use(sinonChai); const expect = chai.expect; diff --git a/tests/unit/utils/discontinuities.ts b/tests/unit/utils/discontinuities.ts index e5c55c479f3..3aa7aacc460 100644 --- a/tests/unit/utils/discontinuities.ts +++ b/tests/unit/utils/discontinuities.ts @@ -1,17 +1,17 @@ +import chai from 'chai'; +import sinonChai from 'sinon-chai'; +import { Fragment } from '../../../src/loader/fragment'; +import { LevelDetails } from '../../../src/loader/level-details'; +import { Level } from '../../../src/types/level'; +import { PlaylistLevelType } from '../../../src/types/loader'; +import { AttrList } from '../../../src/utils/attr-list'; import { - shouldAlignOnDiscontinuities, - alignDiscontinuities, adjustSlidingStart, + alignDiscontinuities, alignMediaPlaylistByPDT, + shouldAlignOnDiscontinuities, } from '../../../src/utils/discontinuities'; -import { LevelDetails } from '../../../src/loader/level-details'; -import { Fragment, MediaFragment } from '../../../src/loader/fragment'; -import { PlaylistLevelType } from '../../../src/types/loader'; - -import chai from 'chai'; -import sinonChai from 'sinon-chai'; -import { AttrList } from '../../../src/utils/attr-list'; -import { Level } from '../../../src/types/level'; +import type { MediaFragment } from '../../../src/loader/fragment'; chai.use(sinonChai); const expect = chai.expect; diff --git a/tests/unit/utils/utf8.ts b/tests/unit/utils/utf8.ts index bde0f703573..a56eedafb39 100644 --- a/tests/unit/utils/utf8.ts +++ b/tests/unit/utils/utf8.ts @@ -1,5 +1,5 @@ -import { expect } from 'chai'; import { utf8ArrayToStr } from '@svta/common-media-library/utils/utf8ArrayToStr'; +import { expect } from 'chai'; describe('UTF8 tests', function () { it('utf8ArrayToStr', function (done) { diff --git a/tests/unit/utils/vttparser.ts b/tests/unit/utils/vttparser.ts index 9d2e08b1a72..bb8638d957f 100644 --- a/tests/unit/utils/vttparser.ts +++ b/tests/unit/utils/vttparser.ts @@ -1,6 +1,6 @@ -import { parseTimeStamp } from '../../../src/utils/vttparser'; import chai from 'chai'; import sinonChai from 'sinon-chai'; +import { parseTimeStamp } from '../../../src/utils/vttparser'; chai.use(sinonChai); const expect = chai.expect;