Skip to content

Commit

Permalink
chore(deps): Upgrading TypeScript to 4.0.3.
Browse files Browse the repository at this point in the history
This caused an issue with ESLint due to the change in the TypeScript
AST. Which necessitated an upgrade to the ESLint plugin to fix.

See: microsoft/TypeScript#40446.

As this was a decently large group in some of the underlying versions
for these repos, there were a few issues that came up when I upgraded
with the default settings, but I went through and fixed them.

Some of it was questionable because of our use of a bundler which will
take care of some of the "no-use-before-define" rule. But, I left the
defaults to try and stay as similar to the rest of the ecosystem as
possible.
  • Loading branch information
itsjamie committed Oct 19, 2020
1 parent eca8c97 commit 8b30fa6
Show file tree
Hide file tree
Showing 15 changed files with 628 additions and 363 deletions.
6 changes: 4 additions & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,16 @@ module.exports = {
'no-useless-catch': 0,
'no-prototype-builtins': 0,
'dot-notation': 0,
'lines-between-class-members': 0,
'no-prototype-builtins': 0
'lines-between-class-members': 0
},
'overrides': [
{
'files': ['*.ts'],
'rules': {
'no-unused-vars': 0,
'no-undef': 0,
'no-use-before-define': "off",
'@typescript-eslint/no-use-before-define': ["error"],
'@typescript-eslint/no-unused-vars': 1,
'@typescript-eslint/prefer-optional-chain': 2,
'@typescript-eslint/consistent-type-assertions': [ 2,
Expand Down
645 changes: 448 additions & 197 deletions package-lock.json

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,19 +68,19 @@
"@types/chai": "^4.1.7",
"@types/mocha": "^8.0.0",
"@types/sinon-chai": "^3.2.2",
"@typescript-eslint/eslint-plugin": "^2.24.0",
"@typescript-eslint/parser": "^2.24.0",
"@typescript-eslint/eslint-plugin": "^4.4.1",
"@typescript-eslint/parser": "^4.0.1",
"babel-loader": "^8.0.6",
"babel-plugin-transform-remove-console": "6.9.4",
"chai": "^4.2.0",
"chart.js": "^2.9.3",
"chartjs-plugin-zoom": "^0.7.5",
"chromedriver": "^86.0.0",
"eslint": "^6.8.0",
"eslint-config-standard": "^14.1.0",
"eslint-plugin-import": "^2.20.1",
"eslint-plugin-mocha": "^6.3.0",
"eslint-plugin-node": "^11.0.0",
"eslint": "^7.11.0",
"eslint-config-standard": "^14.1.1",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-mocha": "^8.0.0",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^4.2.1",
"eslint-plugin-standard": "^4.0.1",
"http-server": "^0.12.1",
Expand All @@ -101,7 +101,7 @@
"semver": "^7.3.2",
"sinon": "^9.0.1",
"sinon-chai": "^3.5.0",
"typescript": "^3.7.4",
"typescript": "^4.0.3",
"webpack": "^4.27.1",
"webpack-cli": "^4.0.0",
"webpack-dev-server": "^3.1.4",
Expand Down
34 changes: 17 additions & 17 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,23 @@ export type HlsConfig =
TimelineControllerConfig &
TSDemuxerConfig;

function timelineConfig (): TimelineControllerConfig {
return {
cueHandler: Cues, // used by timeline-controller
enableCEA708Captions: __USE_SUBTITLES__, // used by timeline-controller
enableWebVTT: __USE_SUBTITLES__, // used by timeline-controller
captionsTextTrack1Label: 'English', // used by timeline-controller
captionsTextTrack1LanguageCode: 'en', // used by timeline-controller
captionsTextTrack2Label: 'Spanish', // used by timeline-controller
captionsTextTrack2LanguageCode: 'es', // used by timeline-controller
captionsTextTrack3Label: 'Unknown CC', // used by timeline-controller
captionsTextTrack3LanguageCode: '', // used by timeline-controller
captionsTextTrack4Label: 'Unknown CC', // used by timeline-controller
captionsTextTrack4LanguageCode: '', // used by timeline-controller
renderTextTracksNatively: true
};
}

// If possible, keep hlsDefaultConfig shallow
// It is cloned whenever a new Hls instance is created, by keeping the config
// shallow the properties are cloned, and we don't end up manipulating the default
Expand Down Expand Up @@ -259,20 +276,3 @@ export const hlsDefaultConfig: HlsConfig = {
audioTrackController: (__USE_ALT_AUDIO__) ? AudioTrackController : void 0,
emeController: (__USE_EME_DRM__) ? EMEController : void 0
};

function timelineConfig (): TimelineControllerConfig {
return {
cueHandler: Cues, // used by timeline-controller
enableCEA708Captions: __USE_SUBTITLES__, // used by timeline-controller
enableWebVTT: __USE_SUBTITLES__, // used by timeline-controller
captionsTextTrack1Label: 'English', // used by timeline-controller
captionsTextTrack1LanguageCode: 'en', // used by timeline-controller
captionsTextTrack2Label: 'Spanish', // used by timeline-controller
captionsTextTrack2LanguageCode: 'es', // used by timeline-controller
captionsTextTrack3Label: 'Unknown CC', // used by timeline-controller
captionsTextTrack3LanguageCode: '', // used by timeline-controller
captionsTextTrack4Label: 'Unknown CC', // used by timeline-controller
captionsTextTrack4LanguageCode: '', // used by timeline-controller
renderTextTracksNatively: true
};
}
2 changes: 1 addition & 1 deletion src/controller/buffer-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { Segment } from '../types/segment';
import { BufferControllerConfig } from '../config';

// Add extension properties to SourceBuffers from the DOM API.
type ExtendedSourceBuffer = SourceBuffer & {
type ExtendedSourceBuffer = SourceBuffer & { // eslint-disable-line no-restricted-globals
ended?: boolean
};

Expand Down
98 changes: 49 additions & 49 deletions src/controller/fragment-finders.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,55 @@
import BinarySearch from '../utils/binary-search';
import Fragment from '../loader/fragment';

/**
* The test function used by the findFragmentBySn's BinarySearch to look for the best match to the current buffer conditions.
* @param {*} candidate - The fragment to test
* @param {number} [bufferEnd = 0] - The end of the current buffered range the playhead is currently within
* @param {number} [maxFragLookUpTolerance = 0] - The amount of time that a fragment's start can be within in order to be considered contiguous
* @returns {number} - 0 if it matches, 1 if too low, -1 if too high
*/
export function fragmentWithinToleranceTest (bufferEnd = 0, maxFragLookUpTolerance = 0, candidate: Fragment) {
// offset should be within fragment boundary - config.maxFragLookUpTolerance
// this is to cope with situations like
// bufferEnd = 9.991
// frag[Ø] : [0,10]
// frag[1] : [10,20]
// bufferEnd is within frag[0] range ... although what we are expecting is to return frag[1] here
// frag start frag start+duration
// |-----------------------------|
// <---> <--->
// ...--------><-----------------------------><---------....
// previous frag matching fragment next frag
// return -1 return 0 return 1
// logger.log(`level/sn/start/end/bufEnd:${level}/${candidate.sn}/${candidate.start}/${(candidate.start+candidate.duration)}/${bufferEnd}`);
// Set the lookup tolerance to be small enough to detect the current segment - ensures we don't skip over very small segments
let candidateLookupTolerance = Math.min(maxFragLookUpTolerance, candidate.duration + (candidate.deltaPTS ? candidate.deltaPTS : 0));
if (candidate.start + candidate.duration - candidateLookupTolerance <= bufferEnd) {
return 1;
} else if (candidate.start - candidateLookupTolerance > bufferEnd && candidate.start) {
// if maxFragLookUpTolerance will have negative value then don't return -1 for first element
return -1;
}

return 0;
}

/**
* The test function used by the findFragmentByPdt's BinarySearch to look for the best match to the current buffer conditions.
* This function tests the candidate's program date time values, as represented in Unix time
* @param {*} candidate - The fragment to test
* @param {number} [pdtBufferEnd = 0] - The Unix time representing the end of the current buffered range
* @param {number} [maxFragLookUpTolerance = 0] - The amount of time that a fragment's start can be within in order to be considered contiguous
* @returns {boolean} True if contiguous, false otherwise
*/
export function pdtWithinToleranceTest (pdtBufferEnd: number, maxFragLookUpTolerance: number, candidate: Fragment): boolean {
let candidateLookupTolerance = Math.min(maxFragLookUpTolerance, candidate.duration + (candidate.deltaPTS ? candidate.deltaPTS : 0)) * 1000;

// endProgramDateTime can be null, default to zero
const endProgramDateTime = candidate.endProgramDateTime || 0;
return endProgramDateTime - candidateLookupTolerance > pdtBufferEnd;
}

/**
* Returns first fragment whose endPdt value exceeds the given PDT.
* @param {Array<Fragment>} fragments - The array of candidate fragments
Expand Down Expand Up @@ -64,52 +113,3 @@ export function findFragmentByPTS (fragPrevious: Fragment, fragments: Array<Frag
// If no match was found return the next fragment after fragPrevious, or null
return fragNext;
}

/**
* The test function used by the findFragmentBySn's BinarySearch to look for the best match to the current buffer conditions.
* @param {*} candidate - The fragment to test
* @param {number} [bufferEnd = 0] - The end of the current buffered range the playhead is currently within
* @param {number} [maxFragLookUpTolerance = 0] - The amount of time that a fragment's start can be within in order to be considered contiguous
* @returns {number} - 0 if it matches, 1 if too low, -1 if too high
*/
export function fragmentWithinToleranceTest (bufferEnd = 0, maxFragLookUpTolerance = 0, candidate: Fragment) {
// offset should be within fragment boundary - config.maxFragLookUpTolerance
// this is to cope with situations like
// bufferEnd = 9.991
// frag[Ø] : [0,10]
// frag[1] : [10,20]
// bufferEnd is within frag[0] range ... although what we are expecting is to return frag[1] here
// frag start frag start+duration
// |-----------------------------|
// <---> <--->
// ...--------><-----------------------------><---------....
// previous frag matching fragment next frag
// return -1 return 0 return 1
// logger.log(`level/sn/start/end/bufEnd:${level}/${candidate.sn}/${candidate.start}/${(candidate.start+candidate.duration)}/${bufferEnd}`);
// Set the lookup tolerance to be small enough to detect the current segment - ensures we don't skip over very small segments
let candidateLookupTolerance = Math.min(maxFragLookUpTolerance, candidate.duration + (candidate.deltaPTS ? candidate.deltaPTS : 0));
if (candidate.start + candidate.duration - candidateLookupTolerance <= bufferEnd) {
return 1;
} else if (candidate.start - candidateLookupTolerance > bufferEnd && candidate.start) {
// if maxFragLookUpTolerance will have negative value then don't return -1 for first element
return -1;
}

return 0;
}

/**
* The test function used by the findFragmentByPdt's BinarySearch to look for the best match to the current buffer conditions.
* This function tests the candidate's program date time values, as represented in Unix time
* @param {*} candidate - The fragment to test
* @param {number} [pdtBufferEnd = 0] - The Unix time representing the end of the current buffered range
* @param {number} [maxFragLookUpTolerance = 0] - The amount of time that a fragment's start can be within in order to be considered contiguous
* @returns {boolean} True if contiguous, false otherwise
*/
export function pdtWithinToleranceTest (pdtBufferEnd: number, maxFragLookUpTolerance: number, candidate: Fragment): boolean {
let candidateLookupTolerance = Math.min(maxFragLookUpTolerance, candidate.duration + (candidate.deltaPTS ? candidate.deltaPTS : 0)) * 1000;

// endProgramDateTime can be null, default to zero
const endProgramDateTime = candidate.endProgramDateTime || 0;
return endProgramDateTime - candidateLookupTolerance > pdtBufferEnd;
}
40 changes: 20 additions & 20 deletions src/controller/timeline-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,26 @@ type VTTCCs = {
}
};

function canReuseVttTextTrack (inUseTrack, manifestTrack): boolean {
return inUseTrack && inUseTrack.label === manifestTrack.name && !(inUseTrack.textTrack1 || inUseTrack.textTrack2);
}

function intersection (x1: number, x2: number, y1: number, y2: number): number {
return Math.min(x2, y2) - Math.max(x1, y1);
}

function newVTTCCs (): VTTCCs {
return {
ccOffset: 0,
presentationOffset: 0,
0: {
start: 0,
prevCC: -1,
new: false
}
};
}

class TimelineController extends EventHandler {
private media: HTMLMediaElement | null = null;
private config: HlsConfig;
Expand Down Expand Up @@ -487,24 +507,4 @@ class TimelineController extends EventHandler {
}
}

function canReuseVttTextTrack (inUseTrack, manifestTrack): boolean {
return inUseTrack && inUseTrack.label === manifestTrack.name && !(inUseTrack.textTrack1 || inUseTrack.textTrack2);
}

function intersection (x1: number, x2: number, y1: number, y2: number): number {
return Math.min(x2, y2) - Math.max(x1, y1);
}

function newVTTCCs (): VTTCCs {
return {
ccOffset: 0,
presentationOffset: 0,
0: {
start: 0,
prevCC: -1,
new: false
}
};
}

export default TimelineController;
9 changes: 9 additions & 0 deletions src/hls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,15 @@ export default class Hls extends Observer {
this.levelController.startLevel = newLevel;
}

/**
* Get the current setting for capLevelToPlayerSize
*
* @type {boolean}
*/
get capLevelToPlayerSize (): boolean {
return this.config.capLevelToPlayerSize;
}

/**
* set dynamically set capLevelToPlayerSize against (`CapLevelController`)
*
Expand Down
4 changes: 3 additions & 1 deletion src/is-supported.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ export function isSupported (): boolean {
if (!mediaSource) {
return false;
}
const sourceBuffer = self.SourceBuffer || (self as any).WebKitSourceBuffer as SourceBuffer;
const sourceBuffer = self.SourceBuffer ||
(self as any).WebKitSourceBuffer as SourceBuffer; // eslint-disable-line no-restricted-globals

const isTypeSupported = mediaSource &&
typeof mediaSource.isTypeSupported === 'function' &&
mediaSource.isTypeSupported('video/mp4; codecs="avc1.42E01E,mp4a.40.2"');
Expand Down
1 change: 1 addition & 0 deletions src/loader/fragment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ export default class Fragment {
}

get encrypted () {
// eslint-disable-next-line @typescript-eslint/prefer-optional-chain
return !!((this.decryptdata && this.decryptdata.uri !== null) && (this.decryptdata.key === null));
}

Expand Down
44 changes: 22 additions & 22 deletions src/loader/m3u8-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,28 @@ const LEVEL_PLAYLIST_REGEX_SLOW = /(?:(?:#(EXTM3U))|(?:#EXT-X-(PLAYLIST-TYPE):(.

const MP4_REGEX_SUFFIX = /\.(mp4|m4s|m4v|m4a)$/i;

function backfillProgramDateTimes (fragments, startIndex) {
let fragPrev = fragments[startIndex];
for (let i = startIndex - 1; i >= 0; i--) {
const frag = fragments[i];
frag.programDateTime = fragPrev.programDateTime - (frag.duration * 1000);
fragPrev = frag;
}
}

function assignProgramDateTime (frag, prevFrag) {
if (frag.rawProgramDateTime) {
frag.programDateTime = Date.parse(frag.rawProgramDateTime);
} else if (prevFrag?.programDateTime) {
frag.programDateTime = prevFrag.endProgramDateTime;
}

if (!Number.isFinite(frag.programDateTime)) {
frag.programDateTime = null;
frag.rawProgramDateTime = null;
}
}

export default class M3U8Parser {
static findGroup (groups: Array<AudioGroup>, mediaGroupId: string): AudioGroup | undefined {
for (let i = 0; i < groups.length; i++) {
Expand Down Expand Up @@ -371,25 +393,3 @@ export default class M3U8Parser {
return level;
}
}

function backfillProgramDateTimes (fragments, startIndex) {
let fragPrev = fragments[startIndex];
for (let i = startIndex - 1; i >= 0; i--) {
const frag = fragments[i];
frag.programDateTime = fragPrev.programDateTime - (frag.duration * 1000);
fragPrev = frag;
}
}

function assignProgramDateTime (frag, prevFrag) {
if (frag.rawProgramDateTime) {
frag.programDateTime = Date.parse(frag.rawProgramDateTime);
} else if (prevFrag?.programDateTime) {
frag.programDateTime = prevFrag.endProgramDateTime;
}

if (!Number.isFinite(frag.programDateTime)) {
frag.programDateTime = null;
frag.rawProgramDateTime = null;
}
}
4 changes: 2 additions & 2 deletions src/types/track.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export interface TrackSet {
}

export interface AudioTrack {
buffer: SourceBuffer;
buffer: SourceBuffer; // eslint-disable-line no-restricted-globals
container: string;
codec: string;
id: string;
Expand All @@ -13,7 +13,7 @@ export interface AudioTrack {
}

export interface VideoTrack {
buffer: SourceBuffer;
buffer: SourceBuffer; // eslint-disable-line no-restricted-globals
container: string;
codec: string;
id: string;
Expand Down

0 comments on commit 8b30fa6

Please sign in to comment.