Skip to content

Commit

Permalink
Fix lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
John Bartos committed Sep 12, 2019
1 parent aa31864 commit 8a97c9b
Show file tree
Hide file tree
Showing 34 changed files with 420 additions and 427 deletions.
6 changes: 2 additions & 4 deletions src/controller/abr-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class AbrController extends EventHandler {
}
}

/*
/*
This method monitors the download rate of the current fragment, and will downswitch if that fragment will not load
quickly enough to prevent underbuffering
TODO: Can we enhance this method when progressively streaming?
Expand Down Expand Up @@ -147,7 +147,7 @@ class AbrController extends EventHandler {
if (Number.isFinite(bwEstimate)) {
bwEstimate = (bwEstimate / 1024).toFixed(3);
} else {
bwEstimate = 'Unknown'
bwEstimate = 'Unknown';
}
logger.warn(`Fragment ${frag.sn} of level ${frag.level} is loading too slowly and will cause an underbuffer; aborting and switching to level ${nextLoadLevel}
Current BW estimate: ${bwEstimate} Kb/s
Expand Down Expand Up @@ -341,6 +341,4 @@ class AbrController extends EventHandler {
}
}



export default AbrController;
98 changes: 49 additions & 49 deletions src/controller/audio-stream-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,52 +90,52 @@ class AudioStreamController extends BaseStreamController {
const { media } = this;

switch (this.state) {
case State.ERROR:
// don't do anything in error state to avoid breaking further ...
break;
case State.PAUSED:
// TODO: Remove useless PAUSED state
// don't do anything in paused state either ...
break;
case State.STARTING:
this.state = State.WAITING_TRACK;
this.loadedmetadata = false;
break;
case State.IDLE:
this.doTickIdle();
break;
case State.WAITING_TRACK: {
const {levels, trackId} = this;
if (levels && levels[trackId] && levels[trackId].details) {
// check if playlist is already loaded
this.state = State.WAITING_INIT_PTS;
}
break;
case State.ERROR:
// don't do anything in error state to avoid breaking further ...
break;
case State.PAUSED:
// TODO: Remove useless PAUSED state
// don't do anything in paused state either ...
break;
case State.STARTING:
this.state = State.WAITING_TRACK;
this.loadedmetadata = false;
break;
case State.IDLE:
this.doTickIdle();
break;
case State.WAITING_TRACK: {
const { levels, trackId } = this;
if (levels && levels[trackId] && levels[trackId].details) {
// check if playlist is already loaded
this.state = State.WAITING_INIT_PTS;
}
case State.FRAG_LOADING_WAITING_RETRY:
const now = performance.now();
const retryDate = this.retryDate;
const isSeeking = media && media.seeking;
// if current time is gt than retryDate, or if media seeking let's switch to IDLE state to retry loading
if (!retryDate || (now >= retryDate) || isSeeking) {
this.log('RetryDate reached, switch back to IDLE state');
this.state = State.IDLE;
}
break;
case State.WAITING_INIT_PTS:
const videoTrackCC = this.videoTrackCC;
if (Number.isFinite(this.initPTS[videoTrackCC])) {
this.state = State.IDLE;
}
break;
case State.STOPPED:
case State.FRAG_LOADING:
case State.PARSING:
case State.PARSED:
case State.ENDED:
break;
default:
break;
break;
}
case State.FRAG_LOADING_WAITING_RETRY:
const now = performance.now();
const retryDate = this.retryDate;
const isSeeking = media && media.seeking;
// if current time is gt than retryDate, or if media seeking let's switch to IDLE state to retry loading
if (!retryDate || (now >= retryDate) || isSeeking) {
this.log('RetryDate reached, switch back to IDLE state');
this.state = State.IDLE;
}
break;
case State.WAITING_INIT_PTS:
const videoTrackCC = this.videoTrackCC;
if (Number.isFinite(this.initPTS[videoTrackCC])) {
this.state = State.IDLE;
}
break;
case State.STOPPED:
case State.FRAG_LOADING:
case State.PARSING:
case State.PARSED:
case State.ENDED:
break;
default:
break;
}

this.onTickEnd();
Expand All @@ -157,7 +157,7 @@ class AudioStreamController extends BaseStreamController {
this.lastCurrentTime = media.currentTime;
}

private doTickIdle() {
private doTickIdle () {
const { hls, levels, media, trackId } = this;

const config = hls.config;
Expand Down Expand Up @@ -233,7 +233,7 @@ class AudioStreamController extends BaseStreamController {
if (frag.encrypted) {
this.log(`Loading key for ${frag.sn} of [${trackDetails.startSN} ,${trackDetails.endSN}],track ${trackId}`);
this.state = State.KEY_LOADING;
hls.trigger(Event.KEY_LOADING, {frag: frag});
hls.trigger(Event.KEY_LOADING, { frag: frag });
} else {
this.log(`Loading ${frag.sn}, cc: ${frag.cc} of [${trackDetails.startSN} ,${trackDetails.endSN}],track ${trackId}, currentTime:${pos},bufferEnd:${bufferInfo.end.toFixed(3)}`);
this.loadFragment(frag);
Expand Down Expand Up @@ -282,7 +282,7 @@ class AudioStreamController extends BaseStreamController {
const { fragCurrent, transmuxer } = this;

if (fragCurrent && fragCurrent.loader) {
fragCurrent.loader.abort();
fragCurrent.loader.abort();
}
this.fragCurrent = null;
// destroy useless transmuxer when switching audio to main
Expand All @@ -309,7 +309,7 @@ class AudioStreamController extends BaseStreamController {

onAudioTrackLoaded (data: { details: LevelDetails, id: number }) {
const { levels } = this;
const { details: newDetails, id: trackId, } = data;
const { details: newDetails, id: trackId } = data;
if (!levels) {
this.warn(`Audio tracks were reset while loading level ${trackId}`);
return;
Expand Down
25 changes: 12 additions & 13 deletions src/controller/buffer-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@ import EventHandler from '../event-handler';
import { logger } from '../utils/logger';
import { ErrorDetails, ErrorTypes } from '../errors';
import { getMediaSource } from '../utils/mediasource-helper';
import Fragment from '../loader/fragment';

import Fragment, { ElementaryStreamTypes } from '../loader/fragment';
import { TrackSet } from '../types/track';
import { BufferAppendingEventPayload } from '../types/bufferAppendingEventPayload';
import { ElementaryStreamTypes } from '../loader/fragment';
import BufferOperationQueue from './buffer-operation-queue';

import {
Expand All @@ -21,7 +19,6 @@ import {
SourceBufferName,
SourceBufferListener
} from '../types/buffer';
import { ChunkMetadata } from '../types/transmuxer';

const MediaSource = getMediaSource();

Expand All @@ -32,7 +29,7 @@ export default class BufferController extends EventHandler {
// the target duration of the current media playlist
private _levelTargetDuration: number | null = null;
// current stream state: true - for live broadcast, false - for VoD content
private _live: boolean = false;
private _live: boolean = false;
// cache the self generated object url to detect hijack of video tag
private _objectUrl: string | null = null;
// A queue of buffer operations which require the SourceBuffer to not be updating upon execution
Expand Down Expand Up @@ -263,7 +260,9 @@ export default class BufferController extends EventHandler {
onComplete: () => {
this.hls.trigger(Events.BUFFER_FLUSHED);
},
onError: (e) => { logger.warn(`[buffer-controller]: Failed to remove from ${type} SourceBuffer`, e); }
onError: (e) => {
logger.warn(`[buffer-controller]: Failed to remove from ${type} SourceBuffer`, e);
}
});

if (data.type) {
Expand All @@ -286,7 +285,7 @@ export default class BufferController extends EventHandler {
}
console.assert(buffersAppendedTo.length, 'Fragments must have at least one ElementaryStreamType set', frag);

logger.log(`[buffer-controller]: All fragment chunks received, enqueueing operation to signal fragment buffered`);
logger.log('[buffer-controller]: All fragment chunks received, enqueueing operation to signal fragment buffered');
const onUnblocked = () => {
frag.stats.buffering.end = window.performance.now();
this.hls.trigger(Events.FRAG_BUFFERED, { frag, stats: frag.stats, id: frag.type });
Expand Down Expand Up @@ -318,7 +317,7 @@ export default class BufferController extends EventHandler {
// Allow this to throw and be caught by the enqueueing function
mediaSource.endOfStream();
};
logger.log(`[buffer-controller: End of stream signalled, enqueuing end of stream operation`);
logger.log('[buffer-controller: End of stream signalled, enqueuing end of stream operation');
this.blockBuffers(endStream);
}

Expand All @@ -330,7 +329,7 @@ export default class BufferController extends EventHandler {
this._live = details.live;

const levelDuration = details.totalduration + details.fragments[0].start;
logger.log(`[buffer-controller]: Duration update required; enqueueing duration change operation`);
logger.log('[buffer-controller]: Duration update required; enqueueing duration change operation');
if (this.getSourceBufferTypes().length) {
this.blockBuffers(this.updateMediaElementDuration.bind(this, levelDuration));
} else {
Expand Down Expand Up @@ -521,7 +520,7 @@ export default class BufferController extends EventHandler {

operation.onComplete();
operationQueue.shiftAndExecuteNext(type);
};
}

private _onSBUpdateError (type: SourceBufferName, event: Event) {
logger.error(`[buffer-controller]: ${type} SourceBuffer error`, event);
Expand Down Expand Up @@ -596,7 +595,7 @@ export default class BufferController extends EventHandler {
// upon completion, since we already do it here
private blockBuffers (onUnblocked: Function, buffers: Array<SourceBufferName> = this.getSourceBufferTypes()) {
if (!buffers.length) {
logger.log(`[buffer-controller]: Blocking operation requested, but no SourceBuffers exist`);
logger.log('[buffer-controller]: Blocking operation requested, but no SourceBuffers exist');
onUnblocked();
return;
}
Expand All @@ -615,7 +614,7 @@ export default class BufferController extends EventHandler {
if (!sb || !sb.updating) {
operationQueue.shiftAndExecuteNext(type);
}
})
});
});
}

Expand All @@ -639,7 +638,7 @@ export default class BufferController extends EventHandler {
return;
}
this.listeners[type].forEach(l => {
buffer.removeEventListener(l.event, l.listener);
buffer.removeEventListener(l.event, l.listener);
});
}
}
6 changes: 4 additions & 2 deletions src/controller/buffer-operation-queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ export default class BufferOperationQueue {

public appendBlocker (type: SourceBufferName) : Promise<{}> {
let execute;
const promise: Promise<{}> = new Promise((resolve, reject) => { execute = resolve; });
const promise: Promise<{}> = new Promise((resolve, reject) => {
execute = resolve;
});
const operation = {
execute,
onComplete: () => {},
Expand All @@ -48,7 +50,7 @@ export default class BufferOperationQueue {
// which do not end with this event must call _onSBUpdateEnd manually
operation.execute();
} catch (e) {
logger.warn(`[buffer-operation-queue]: Unhandled exception executing the current operation`);
logger.warn('[buffer-operation-queue]: Unhandled exception executing the current operation');
operation.onError(e);

// Only shift the current operation off, otherwise the updateend handler will do this for us
Expand Down
4 changes: 2 additions & 2 deletions src/controller/fragment-tracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ export class FragmentTracker extends EventHandler {
return state;
}

isTimeBuffered (startPTS: number , endPTS: number , timeRange: TimeRanges): boolean {
isTimeBuffered (startPTS: number, endPTS: number, timeRange: TimeRanges): boolean {
let startTime;
let endTime;
for (let i = 0; i < timeRange.length; i++) {
Expand Down Expand Up @@ -299,4 +299,4 @@ function isPartial (fragmentEntity: FragmentEntity): boolean {

function getFragmentKey (fragment: Fragment): string {
return `${fragment.type}_${fragment.level}_${fragment.urlId}_${fragment.sn}`;
}
}
2 changes: 1 addition & 1 deletion src/controller/level-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export default class LevelController extends EventHandler {
let audioCodecFound = false;

// regroup redundant levels together
data.levels.forEach((levelParsed: LevelParsed) => {
data.levels.forEach((levelParsed: LevelParsed) => {
const attributes = levelParsed.attrs;

videoCodecFound = videoCodecFound || !!levelParsed.videoCodec;
Expand Down
2 changes: 1 addition & 1 deletion src/controller/level-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ export function getProgramDateTimeAtEndOfLastEncodedFragment (levelDetails: Leve
const encodedFragments = levelDetails.fragments.filter((fragment) => !fragment.prefetch);
const lastEncodedFrag = encodedFragments[encodedFragments.length - 1];
if (Number.isFinite(<number>lastEncodedFrag.programDateTime)) {
return <number>lastEncodedFrag.programDateTime + lastEncodedFrag.duration * 1000;
return <number > lastEncodedFrag.programDateTime + lastEncodedFrag.duration * 1000;
}
}
return null;
Expand Down
4 changes: 2 additions & 2 deletions src/controller/stream-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ export default class StreamController extends BaseStreamController {
media.removeEventListener('seeking', this.onvseeking);
media.removeEventListener('seeked', this.onvseeked);
media.removeEventListener('ended', this.onvended);
this.onvseeking = this.onvseeked = this.onvended = null
this.onvseeking = this.onvseeked = this.onvended = null;
}
this.media = this.mediaBuffer = null;
this.loadedmetadata = false;
Expand Down Expand Up @@ -643,7 +643,7 @@ export default class StreamController extends BaseStreamController {
const media = this.mediaBuffer ? this.mediaBuffer : this.media;
const stats = frag.stats;
this.fragPrevious = frag;
this.fragLastKbps = Math.round(8 * stats.total / (stats.buffering.end- stats.loading.first));
this.fragLastKbps = Math.round(8 * stats.total / (stats.buffering.end - stats.loading.first));

this.log(`Buffered fragment ${frag.sn} of level ${frag.level}. PTS:[${frag.startPTS},${frag.endPTS}],DTS:[${frag.startDTS}/${frag.endDTS}], Buffered: ${TimeRanges.toString(media.buffered)}`);
this.state = State.IDLE;
Expand Down
7 changes: 3 additions & 4 deletions src/crypt/decrypter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export default class Decrypter {
return new Uint8Array(result);
}

public webCryptoDecrypt (data: Uint8Array, key: ArrayBuffer, iv: ArrayBuffer): Promise<ArrayBuffer> {
public webCryptoDecrypt (data: Uint8Array, key: ArrayBuffer, iv: ArrayBuffer): Promise<ArrayBuffer> {
const subtle = this.subtle;
if (this.key !== key || !this.fastAesKey) {
this.key = key;
Expand All @@ -118,21 +118,20 @@ export default class Decrypter {
return crypto.decrypt(data.buffer, aesKey)
.catch((err) => {
return this.onWebCryptoError(err, data, key, iv);
})
});
})
.catch((err) => {
return this.onWebCryptoError(err, data, key, iv);
});
}

private onWebCryptoError (err, data, key, iv) {
private onWebCryptoError (err, data, key, iv) {
logger.warn('[decrypter.ts]: WebCrypto Error, disable WebCrypto API:', err);
this.config.enableSoftwareAES = true;
this.logEnabled = true;
return this.softwareDecrypt(data, key, iv);
}


private getValidChunk (data: Uint8Array) : Uint8Array {
let currentChunk = data;
const splitPoint = data.length - (data.length % CHUNK_SIZE);
Expand Down
Loading

0 comments on commit 8a97c9b

Please sign in to comment.