hls.js 1.5.2-0.canary.9924 → 1.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/hls-demo.js +0 -5
- package/dist/hls-demo.js.map +1 -1
- package/dist/hls.js +686 -762
- package/dist/hls.js.d.ts +47 -49
- package/dist/hls.js.map +1 -1
- package/dist/hls.light.js +471 -563
- package/dist/hls.light.js.map +1 -1
- package/dist/hls.light.min.js +1 -1
- package/dist/hls.light.min.js.map +1 -1
- package/dist/hls.light.mjs +329 -409
- package/dist/hls.light.mjs.map +1 -1
- package/dist/hls.min.js +1 -1
- package/dist/hls.min.js.map +1 -1
- package/dist/hls.mjs +500 -559
- package/dist/hls.mjs.map +1 -1
- package/dist/hls.worker.js +1 -1
- package/dist/hls.worker.js.map +1 -1
- package/package.json +9 -9
- package/src/config.ts +2 -3
- package/src/controller/abr-controller.ts +22 -23
- package/src/controller/audio-stream-controller.ts +14 -11
- package/src/controller/audio-track-controller.ts +1 -1
- package/src/controller/base-playlist-controller.ts +7 -7
- package/src/controller/base-stream-controller.ts +29 -42
- package/src/controller/buffer-controller.ts +11 -10
- package/src/controller/cap-level-controller.ts +2 -1
- package/src/controller/content-steering-controller.ts +6 -8
- package/src/controller/eme-controller.ts +22 -9
- package/src/controller/error-controller.ts +8 -6
- package/src/controller/fps-controller.ts +3 -2
- package/src/controller/gap-controller.ts +10 -16
- package/src/controller/latency-controller.ts +11 -9
- package/src/controller/level-controller.ts +19 -8
- package/src/controller/stream-controller.ts +29 -20
- package/src/controller/subtitle-stream-controller.ts +14 -13
- package/src/controller/subtitle-track-controller.ts +3 -5
- package/src/controller/timeline-controller.ts +30 -23
- package/src/crypt/aes-crypto.ts +2 -21
- package/src/crypt/decrypter.ts +18 -32
- package/src/crypt/fast-aes-key.ts +5 -24
- package/src/demux/audio/adts.ts +4 -9
- package/src/demux/sample-aes.ts +0 -2
- package/src/demux/transmuxer-interface.ts +12 -4
- package/src/demux/transmuxer-worker.ts +4 -4
- package/src/demux/transmuxer.ts +3 -16
- package/src/demux/tsdemuxer.ts +17 -12
- package/src/hls.ts +20 -32
- package/src/loader/fragment-loader.ts +2 -9
- package/src/loader/key-loader.ts +0 -2
- package/src/loader/level-key.ts +9 -10
- package/src/remux/mp4-remuxer.ts +3 -4
- package/src/task-loop.ts +2 -5
- package/src/types/demuxer.ts +0 -1
- package/src/utils/codecs.ts +4 -33
- package/src/utils/logger.ts +24 -53
- package/src/crypt/decrypter-aes-mode.ts +0 -4
- package/src/utils/encryption-methods-util.ts +0 -21
package/src/hls.ts
CHANGED
@@ -8,7 +8,7 @@ import KeyLoader from './loader/key-loader';
|
|
8
8
|
import StreamController from './controller/stream-controller';
|
9
9
|
import { isMSESupported, isSupported } from './is-supported';
|
10
10
|
import { getMediaSource } from './utils/mediasource-helper';
|
11
|
-
import {
|
11
|
+
import { logger, enableLogs } from './utils/logger';
|
12
12
|
import { enableStreamingMode, hlsDefaultConfig, mergeConfig } from './config';
|
13
13
|
import { EventEmitter } from 'eventemitter3';
|
14
14
|
import { Events } from './events';
|
@@ -59,11 +59,6 @@ export default class Hls implements HlsEventEmitter {
|
|
59
59
|
*/
|
60
60
|
public readonly userConfig: Partial<HlsConfig>;
|
61
61
|
|
62
|
-
/**
|
63
|
-
* The logger functions used by this player instance, configured on player instantiation.
|
64
|
-
*/
|
65
|
-
public readonly logger: ILogger;
|
66
|
-
|
67
62
|
private coreComponents: ComponentAPI[];
|
68
63
|
private networkControllers: NetworkComponentAPI[];
|
69
64
|
private started: boolean = false;
|
@@ -147,19 +142,12 @@ export default class Hls implements HlsEventEmitter {
|
|
147
142
|
* @param userConfig - Configuration options applied over `Hls.DefaultConfig`
|
148
143
|
*/
|
149
144
|
constructor(userConfig: Partial<HlsConfig> = {}) {
|
150
|
-
|
151
|
-
|
152
|
-
'Hls instance',
|
153
|
-
));
|
154
|
-
const config = (this.config = mergeConfig(
|
155
|
-
Hls.DefaultConfig,
|
156
|
-
userConfig,
|
157
|
-
logger,
|
158
|
-
));
|
145
|
+
enableLogs(userConfig.debug || false, 'Hls instance');
|
146
|
+
const config = (this.config = mergeConfig(Hls.DefaultConfig, userConfig));
|
159
147
|
this.userConfig = userConfig;
|
160
148
|
|
161
149
|
if (config.progressive) {
|
162
|
-
enableStreamingMode(config
|
150
|
+
enableStreamingMode(config);
|
163
151
|
}
|
164
152
|
|
165
153
|
// core controllers and network loaders
|
@@ -332,7 +320,7 @@ export default class Hls implements HlsEventEmitter {
|
|
332
320
|
try {
|
333
321
|
return this.emit(event, event, eventObject);
|
334
322
|
} catch (error) {
|
335
|
-
|
323
|
+
logger.error(
|
336
324
|
'An internal error happened while handling event ' +
|
337
325
|
event +
|
338
326
|
'. Error message: "' +
|
@@ -366,7 +354,7 @@ export default class Hls implements HlsEventEmitter {
|
|
366
354
|
* Dispose of the instance
|
367
355
|
*/
|
368
356
|
destroy() {
|
369
|
-
|
357
|
+
logger.log('destroy');
|
370
358
|
this.trigger(Events.DESTROYING, undefined);
|
371
359
|
this.detachMedia();
|
372
360
|
this.removeAllListeners();
|
@@ -389,7 +377,7 @@ export default class Hls implements HlsEventEmitter {
|
|
389
377
|
* Attaches Hls.js to a media element
|
390
378
|
*/
|
391
379
|
attachMedia(media: HTMLMediaElement) {
|
392
|
-
|
380
|
+
logger.log('attachMedia');
|
393
381
|
this._media = media;
|
394
382
|
this.trigger(Events.MEDIA_ATTACHING, { media: media });
|
395
383
|
}
|
@@ -398,7 +386,7 @@ export default class Hls implements HlsEventEmitter {
|
|
398
386
|
* Detach Hls.js from the media
|
399
387
|
*/
|
400
388
|
detachMedia() {
|
401
|
-
|
389
|
+
logger.log('detachMedia');
|
402
390
|
this.trigger(Events.MEDIA_DETACHING, undefined);
|
403
391
|
this._media = null;
|
404
392
|
}
|
@@ -419,7 +407,7 @@ export default class Hls implements HlsEventEmitter {
|
|
419
407
|
));
|
420
408
|
this._autoLevelCapping = -1;
|
421
409
|
this._maxHdcpLevel = null;
|
422
|
-
|
410
|
+
logger.log(`loadSource:${loadingSource}`);
|
423
411
|
if (
|
424
412
|
media &&
|
425
413
|
loadedSource &&
|
@@ -440,7 +428,7 @@ export default class Hls implements HlsEventEmitter {
|
|
440
428
|
* Defaults to -1 (None: starts from earliest point)
|
441
429
|
*/
|
442
430
|
startLoad(startPosition: number = -1) {
|
443
|
-
|
431
|
+
logger.log(`startLoad(${startPosition})`);
|
444
432
|
this.started = true;
|
445
433
|
this.networkControllers.forEach((controller) => {
|
446
434
|
controller.startLoad(startPosition);
|
@@ -451,7 +439,7 @@ export default class Hls implements HlsEventEmitter {
|
|
451
439
|
* Stop loading of any stream data.
|
452
440
|
*/
|
453
441
|
stopLoad() {
|
454
|
-
|
442
|
+
logger.log('stopLoad');
|
455
443
|
this.started = false;
|
456
444
|
this.networkControllers.forEach((controller) => {
|
457
445
|
controller.stopLoad();
|
@@ -487,7 +475,7 @@ export default class Hls implements HlsEventEmitter {
|
|
487
475
|
* Swap through possible audio codecs in the stream (for example to switch from stereo to 5.1)
|
488
476
|
*/
|
489
477
|
swapAudioCodec() {
|
490
|
-
|
478
|
+
logger.log('swapAudioCodec');
|
491
479
|
this.streamController.swapAudioCodec();
|
492
480
|
}
|
493
481
|
|
@@ -498,7 +486,7 @@ export default class Hls implements HlsEventEmitter {
|
|
498
486
|
* Automatic recovery of media-errors by this process is configurable.
|
499
487
|
*/
|
500
488
|
recoverMediaError() {
|
501
|
-
|
489
|
+
logger.log('recoverMediaError');
|
502
490
|
const media = this._media;
|
503
491
|
this.detachMedia();
|
504
492
|
if (media) {
|
@@ -529,7 +517,7 @@ export default class Hls implements HlsEventEmitter {
|
|
529
517
|
* Set quality level index immediately. This will flush the current buffer to replace the quality asap. That means playback will interrupt at least shortly to re-buffer and re-sync eventually. Set to -1 for automatic level selection.
|
530
518
|
*/
|
531
519
|
set currentLevel(newLevel: number) {
|
532
|
-
|
520
|
+
logger.log(`set currentLevel:${newLevel}`);
|
533
521
|
this.levelController.manualLevel = newLevel;
|
534
522
|
this.streamController.immediateLevelSwitch();
|
535
523
|
}
|
@@ -548,7 +536,7 @@ export default class Hls implements HlsEventEmitter {
|
|
548
536
|
* @param newLevel - Pass -1 for automatic level selection
|
549
537
|
*/
|
550
538
|
set nextLevel(newLevel: number) {
|
551
|
-
|
539
|
+
logger.log(`set nextLevel:${newLevel}`);
|
552
540
|
this.levelController.manualLevel = newLevel;
|
553
541
|
this.streamController.nextLevelSwitch();
|
554
542
|
}
|
@@ -567,7 +555,7 @@ export default class Hls implements HlsEventEmitter {
|
|
567
555
|
* @param newLevel - Pass -1 for automatic level selection
|
568
556
|
*/
|
569
557
|
set loadLevel(newLevel: number) {
|
570
|
-
|
558
|
+
logger.log(`set loadLevel:${newLevel}`);
|
571
559
|
this.levelController.manualLevel = newLevel;
|
572
560
|
}
|
573
561
|
|
@@ -598,7 +586,7 @@ export default class Hls implements HlsEventEmitter {
|
|
598
586
|
* Sets "first-level", see getter.
|
599
587
|
*/
|
600
588
|
set firstLevel(newLevel: number) {
|
601
|
-
|
589
|
+
logger.log(`set firstLevel:${newLevel}`);
|
602
590
|
this.levelController.firstLevel = newLevel;
|
603
591
|
}
|
604
592
|
|
@@ -623,7 +611,7 @@ export default class Hls implements HlsEventEmitter {
|
|
623
611
|
* (determined from download of first segment)
|
624
612
|
*/
|
625
613
|
set startLevel(newLevel: number) {
|
626
|
-
|
614
|
+
logger.log(`set startLevel:${newLevel}`);
|
627
615
|
// if not in automatic start level detection, ensure startLevel is greater than minAutoLevel
|
628
616
|
if (newLevel !== -1) {
|
629
617
|
newLevel = Math.max(newLevel, this.minAutoLevel);
|
@@ -698,7 +686,7 @@ export default class Hls implements HlsEventEmitter {
|
|
698
686
|
*/
|
699
687
|
set autoLevelCapping(newLevel: number) {
|
700
688
|
if (this._autoLevelCapping !== newLevel) {
|
701
|
-
|
689
|
+
logger.log(`set autoLevelCapping:${newLevel}`);
|
702
690
|
this._autoLevelCapping = newLevel;
|
703
691
|
this.levelController.checkMaxAutoUpdated();
|
704
692
|
}
|
@@ -1044,7 +1032,7 @@ export type {
|
|
1044
1032
|
TSDemuxerConfig,
|
1045
1033
|
} from './config';
|
1046
1034
|
export type { MediaKeySessionContext } from './controller/eme-controller';
|
1047
|
-
export type { ILogger
|
1035
|
+
export type { ILogger } from './utils/logger';
|
1048
1036
|
export type {
|
1049
1037
|
PathwayClone,
|
1050
1038
|
SteeringManifest,
|
@@ -336,11 +336,8 @@ function createLoaderContext(
|
|
336
336
|
if (Number.isFinite(start) && Number.isFinite(end)) {
|
337
337
|
let byteRangeStart = start;
|
338
338
|
let byteRangeEnd = end;
|
339
|
-
if (
|
340
|
-
|
341
|
-
isMethodFullSegmentAesCbc(frag.decryptdata?.method)
|
342
|
-
) {
|
343
|
-
// MAP segment encrypted with method 'AES-128' or 'AES-256' (cbc), when served with HTTP Range,
|
339
|
+
if (frag.sn === 'initSegment' && frag.decryptdata?.method === 'AES-128') {
|
340
|
+
// MAP segment encrypted with method 'AES-128', when served with HTTP Range,
|
344
341
|
// has the unencrypted size specified in the range.
|
345
342
|
// Ref: https://tools.ietf.org/html/draft-pantos-hls-rfc8216bis-08#section-6.3.6
|
346
343
|
const fragmentLen = end - start;
|
@@ -375,10 +372,6 @@ function createGapLoadError(frag: Fragment, part?: Part): LoadError {
|
|
375
372
|
return new LoadError(errorData);
|
376
373
|
}
|
377
374
|
|
378
|
-
function isMethodFullSegmentAesCbc(method) {
|
379
|
-
return method === 'AES-128' || method === 'AES-256';
|
380
|
-
}
|
381
|
-
|
382
375
|
export class LoadError extends Error {
|
383
376
|
public readonly data: FragLoadFailResult;
|
384
377
|
constructor(data: FragLoadFailResult) {
|
package/src/loader/key-loader.ts
CHANGED
@@ -194,8 +194,6 @@ export default class KeyLoader implements ComponentAPI {
|
|
194
194
|
}
|
195
195
|
return this.loadKeyEME(keyInfo, frag);
|
196
196
|
case 'AES-128':
|
197
|
-
case 'AES-256':
|
198
|
-
case 'AES-256-CTR':
|
199
197
|
return this.loadKeyHTTP(keyInfo, frag);
|
200
198
|
default:
|
201
199
|
return Promise.reject(
|
package/src/loader/level-key.ts
CHANGED
@@ -2,7 +2,6 @@ import {
|
|
2
2
|
changeEndianness,
|
3
3
|
convertDataUriToArrayBytes,
|
4
4
|
} from '../utils/keysystem-util';
|
5
|
-
import { isFullSegmentEncryption } from '../utils/encryption-methods-util';
|
6
5
|
import { KeySystemFormats } from '../utils/mediakeys-helper';
|
7
6
|
import { mp4pssh } from '../utils/mp4-tools';
|
8
7
|
import { logger } from '../utils/logger';
|
@@ -52,14 +51,13 @@ export class LevelKey implements DecryptData {
|
|
52
51
|
this.keyFormatVersions = formatversions;
|
53
52
|
this.iv = iv;
|
54
53
|
this.encrypted = method ? method !== 'NONE' : false;
|
55
|
-
this.isCommonEncryption =
|
56
|
-
this.encrypted && !isFullSegmentEncryption(method);
|
54
|
+
this.isCommonEncryption = this.encrypted && method !== 'AES-128';
|
57
55
|
}
|
58
56
|
|
59
57
|
public isSupported(): boolean {
|
60
58
|
// If it's Segment encryption or No encryption, just select that key system
|
61
59
|
if (this.method) {
|
62
|
-
if (
|
60
|
+
if (this.method === 'AES-128' || this.method === 'NONE') {
|
63
61
|
return true;
|
64
62
|
}
|
65
63
|
if (this.keyFormat === 'identity') {
|
@@ -90,15 +88,16 @@ export class LevelKey implements DecryptData {
|
|
90
88
|
return null;
|
91
89
|
}
|
92
90
|
|
93
|
-
if (
|
91
|
+
if (this.method === 'AES-128' && this.uri && !this.iv) {
|
94
92
|
if (typeof sn !== 'number') {
|
95
93
|
// We are fetching decryption data for a initialization segment
|
96
|
-
// If the segment was encrypted with AES-128
|
94
|
+
// If the segment was encrypted with AES-128
|
97
95
|
// It must have an IV defined. We cannot substitute the Segment Number in.
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
96
|
+
if (this.method === 'AES-128' && !this.iv) {
|
97
|
+
logger.warn(
|
98
|
+
`missing IV for initialization segment with method="${this.method}" - compliance issue`,
|
99
|
+
);
|
100
|
+
}
|
102
101
|
// Explicitly set sn to resulting value from implicit conversions 'initSegment' values for IV generation.
|
103
102
|
sn = 0;
|
104
103
|
}
|
package/src/remux/mp4-remuxer.ts
CHANGED
@@ -29,7 +29,6 @@ import type { TrackSet } from '../types/track';
|
|
29
29
|
import type { SourceBufferName } from '../types/buffer';
|
30
30
|
import type { Fragment } from '../loader/fragment';
|
31
31
|
import type { HlsConfig } from '../config';
|
32
|
-
import type { TypeSupported } from '../utils/codecs';
|
33
32
|
|
34
33
|
const MAX_SILENT_FRAME_DURATION = 10 * 1000; // 10 seconds
|
35
34
|
const AAC_SAMPLES_PER_FRAME = 1024;
|
@@ -42,7 +41,7 @@ let safariWebkitVersion: number | null = null;
|
|
42
41
|
export default class MP4Remuxer implements Remuxer {
|
43
42
|
private observer: HlsEventEmitter;
|
44
43
|
private config: HlsConfig;
|
45
|
-
private typeSupported:
|
44
|
+
private typeSupported: any;
|
46
45
|
private ISGenerated: boolean = false;
|
47
46
|
private _initPTS: RationalTimestamp | null = null;
|
48
47
|
private _initDTS: RationalTimestamp | null = null;
|
@@ -928,7 +927,7 @@ export default class MP4Remuxer implements Remuxer {
|
|
928
927
|
for (let j = 0; j < missing; j++) {
|
929
928
|
const newStamp = Math.max(nextPts as number, 0);
|
930
929
|
let fillFrame = AAC.getSilentFrame(
|
931
|
-
track.
|
930
|
+
track.manifestCodec || track.codec,
|
932
931
|
track.channelCount,
|
933
932
|
);
|
934
933
|
if (!fillFrame) {
|
@@ -1078,7 +1077,7 @@ export default class MP4Remuxer implements Remuxer {
|
|
1078
1077
|
const nbSamples: number = Math.ceil((endDTS - startDTS) / frameDuration);
|
1079
1078
|
// silent frame
|
1080
1079
|
const silentFrame: Uint8Array | undefined = AAC.getSilentFrame(
|
1081
|
-
track.
|
1080
|
+
track.manifestCodec || track.codec,
|
1082
1081
|
track.channelCount,
|
1083
1082
|
);
|
1084
1083
|
|
package/src/task-loop.ts
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
import { type ILogger, Logger } from './utils/logger';
|
2
|
-
|
3
1
|
/**
|
4
2
|
* @ignore
|
5
3
|
* Sub-class specialization of EventHandler base class.
|
@@ -29,14 +27,13 @@ import { type ILogger, Logger } from './utils/logger';
|
|
29
27
|
* we are limiting the task execution per call stack to exactly one, but scheduling/post-poning further
|
30
28
|
* task processing on the next main loop iteration (also known as "next tick" in the Node/JS runtime lingo).
|
31
29
|
*/
|
32
|
-
export default class TaskLoop
|
30
|
+
export default class TaskLoop {
|
33
31
|
private readonly _boundTick: () => void;
|
34
32
|
private _tickTimer: number | null = null;
|
35
33
|
private _tickInterval: number | null = null;
|
36
34
|
private _tickCallCount = 0;
|
37
35
|
|
38
|
-
constructor(
|
39
|
-
super(label, logger);
|
36
|
+
constructor() {
|
40
37
|
this._boundTick = this.tick.bind(this);
|
41
38
|
}
|
42
39
|
|
package/src/types/demuxer.ts
CHANGED
package/src/utils/codecs.ts
CHANGED
@@ -147,15 +147,12 @@ function getCodecCompatibleNameLower(
|
|
147
147
|
return CODEC_COMPATIBLE_NAMES[lowerCaseCodec]!;
|
148
148
|
}
|
149
149
|
|
150
|
+
// Idealy fLaC and Opus would be first (spec-compliant) but
|
151
|
+
// some browsers will report that fLaC is supported then fail.
|
152
|
+
// see: https://bugs.chromium.org/p/chromium/issues/detail?id=1422728
|
150
153
|
const codecsToCheck = {
|
151
|
-
// Idealy fLaC and Opus would be first (spec-compliant) but
|
152
|
-
// some browsers will report that fLaC is supported then fail.
|
153
|
-
// see: https://bugs.chromium.org/p/chromium/issues/detail?id=1422728
|
154
154
|
flac: ['flac', 'fLaC', 'FLAC'],
|
155
155
|
opus: ['opus', 'Opus'],
|
156
|
-
// Replace audio codec info if browser does not support mp4a.40.34,
|
157
|
-
// and demuxer can fallback to 'audio/mpeg' or 'audio/mp4;codecs="mp3"'
|
158
|
-
'mp4a.40.34': ['mp3'],
|
159
156
|
}[lowerCaseCodec];
|
160
157
|
|
161
158
|
for (let i = 0; i < codecsToCheck.length; i++) {
|
@@ -168,18 +165,13 @@ function getCodecCompatibleNameLower(
|
|
168
165
|
) {
|
169
166
|
CODEC_COMPATIBLE_NAMES[lowerCaseCodec] = codecsToCheck[i];
|
170
167
|
return codecsToCheck[i];
|
171
|
-
} else if (
|
172
|
-
codecsToCheck[i] === 'mp3' &&
|
173
|
-
getMediaSource(preferManagedMediaSource)?.isTypeSupported('audio/mpeg')
|
174
|
-
) {
|
175
|
-
return '';
|
176
168
|
}
|
177
169
|
}
|
178
170
|
|
179
171
|
return lowerCaseCodec;
|
180
172
|
}
|
181
173
|
|
182
|
-
const AUDIO_CODEC_REGEXP = /flac|opus
|
174
|
+
const AUDIO_CODEC_REGEXP = /flac|opus/i;
|
183
175
|
export function getCodecCompatibleName(
|
184
176
|
codec: string,
|
185
177
|
preferManagedMediaSource = true,
|
@@ -217,24 +209,3 @@ export function convertAVC1ToAVCOTI(codec: string) {
|
|
217
209
|
}
|
218
210
|
return codec;
|
219
211
|
}
|
220
|
-
|
221
|
-
export interface TypeSupported {
|
222
|
-
mpeg: boolean;
|
223
|
-
mp3: boolean;
|
224
|
-
ac3: boolean;
|
225
|
-
}
|
226
|
-
|
227
|
-
export function getM2TSSupportedAudioTypes(
|
228
|
-
preferManagedMediaSource: boolean,
|
229
|
-
): TypeSupported {
|
230
|
-
const MediaSource = getMediaSource(preferManagedMediaSource) || {
|
231
|
-
isTypeSupported: () => false,
|
232
|
-
};
|
233
|
-
return {
|
234
|
-
mpeg: MediaSource.isTypeSupported('audio/mpeg'),
|
235
|
-
mp3: MediaSource.isTypeSupported('audio/mp4; codecs="mp3"'),
|
236
|
-
ac3: __USE_M2TS_ADVANCED_CODECS__
|
237
|
-
? MediaSource.isTypeSupported('audio/mp4; codecs="ac-3"')
|
238
|
-
: false,
|
239
|
-
};
|
240
|
-
}
|
package/src/utils/logger.ts
CHANGED
@@ -11,25 +11,6 @@ export interface ILogger {
|
|
11
11
|
error: ILogFunction;
|
12
12
|
}
|
13
13
|
|
14
|
-
export class Logger implements ILogger {
|
15
|
-
trace: ILogFunction;
|
16
|
-
debug: ILogFunction;
|
17
|
-
log: ILogFunction;
|
18
|
-
warn: ILogFunction;
|
19
|
-
info: ILogFunction;
|
20
|
-
error: ILogFunction;
|
21
|
-
|
22
|
-
constructor(label: string, logger: ILogger) {
|
23
|
-
const lb = `[${label}]:`;
|
24
|
-
this.trace = noop;
|
25
|
-
this.debug = logger.debug.bind(null, lb);
|
26
|
-
this.log = logger.log.bind(null, lb);
|
27
|
-
this.warn = logger.warn.bind(null, lb);
|
28
|
-
this.info = logger.info.bind(null, lb);
|
29
|
-
this.error = logger.error.bind(null, lb);
|
30
|
-
}
|
31
|
-
}
|
32
|
-
|
33
14
|
const noop: ILogFunction = function () {};
|
34
15
|
|
35
16
|
const fakeLogger: ILogger = {
|
@@ -41,9 +22,7 @@ const fakeLogger: ILogger = {
|
|
41
22
|
error: noop,
|
42
23
|
};
|
43
24
|
|
44
|
-
|
45
|
-
return Object.assign({}, fakeLogger);
|
46
|
-
}
|
25
|
+
let exportedLogger: ILogger = fakeLogger;
|
47
26
|
|
48
27
|
// let lastCallTime;
|
49
28
|
// function formatMsgWithTimeInfo(type, msg) {
|
@@ -54,37 +33,33 @@ function createLogger() {
|
|
54
33
|
// return msg;
|
55
34
|
// }
|
56
35
|
|
57
|
-
function consolePrintFn(type: string
|
36
|
+
function consolePrintFn(type: string): ILogFunction {
|
58
37
|
const func: ILogFunction = self.console[type];
|
59
|
-
|
60
|
-
|
61
|
-
|
38
|
+
if (func) {
|
39
|
+
return func.bind(self.console, `[${type}] >`);
|
40
|
+
}
|
41
|
+
return noop;
|
62
42
|
}
|
63
43
|
|
64
|
-
function
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
)
|
69
|
-
|
70
|
-
|
71
|
-
|
44
|
+
function exportLoggerFunctions(
|
45
|
+
debugConfig: boolean | ILogger,
|
46
|
+
...functions: string[]
|
47
|
+
): void {
|
48
|
+
functions.forEach(function (type) {
|
49
|
+
exportedLogger[type] = debugConfig[type]
|
50
|
+
? debugConfig[type].bind(debugConfig)
|
51
|
+
: consolePrintFn(type);
|
52
|
+
});
|
72
53
|
}
|
73
54
|
|
74
|
-
|
75
|
-
|
76
|
-
export function enableLogs(
|
77
|
-
debugConfig: boolean | ILogger,
|
78
|
-
context: string,
|
79
|
-
id?: string | undefined,
|
80
|
-
): ILogger {
|
55
|
+
export function enableLogs(debugConfig: boolean | ILogger, id: string): void {
|
81
56
|
// check that console is available
|
82
|
-
const newLogger = createLogger();
|
83
57
|
if (
|
84
58
|
(typeof console === 'object' && debugConfig === true) ||
|
85
59
|
typeof debugConfig === 'object'
|
86
60
|
) {
|
87
|
-
|
61
|
+
exportLoggerFunctions(
|
62
|
+
debugConfig,
|
88
63
|
// Remove out from list here to hard-disable a log-level
|
89
64
|
// 'trace',
|
90
65
|
'debug',
|
@@ -92,23 +67,19 @@ export function enableLogs(
|
|
92
67
|
'info',
|
93
68
|
'warn',
|
94
69
|
'error',
|
95
|
-
|
96
|
-
keys.forEach((key) => {
|
97
|
-
newLogger[key] = getLoggerFn(key, debugConfig, id);
|
98
|
-
});
|
70
|
+
);
|
99
71
|
// Some browsers don't allow to use bind on console object anyway
|
100
72
|
// fallback to default if needed
|
101
73
|
try {
|
102
|
-
|
103
|
-
`Debug logs enabled for "${
|
74
|
+
exportedLogger.log(
|
75
|
+
`Debug logs enabled for "${id}" in hls.js version ${__VERSION__}`,
|
104
76
|
);
|
105
77
|
} catch (e) {
|
106
|
-
|
107
|
-
return createLogger();
|
78
|
+
exportedLogger = fakeLogger;
|
108
79
|
}
|
80
|
+
} else {
|
81
|
+
exportedLogger = fakeLogger;
|
109
82
|
}
|
110
|
-
exportedLogger = newLogger;
|
111
|
-
return newLogger;
|
112
83
|
}
|
113
84
|
|
114
85
|
export const logger: ILogger = exportedLogger;
|
@@ -1,21 +0,0 @@
|
|
1
|
-
import { DecrypterAesMode } from '../crypt/decrypter-aes-mode';
|
2
|
-
|
3
|
-
export function isFullSegmentEncryption(method: string): boolean {
|
4
|
-
return (
|
5
|
-
method === 'AES-128' || method === 'AES-256' || method === 'AES-256-CTR'
|
6
|
-
);
|
7
|
-
}
|
8
|
-
|
9
|
-
export function getAesModeFromFullSegmentMethod(
|
10
|
-
method: string,
|
11
|
-
): DecrypterAesMode {
|
12
|
-
switch (method) {
|
13
|
-
case 'AES-128':
|
14
|
-
case 'AES-256':
|
15
|
-
return DecrypterAesMode.cbc;
|
16
|
-
case 'AES-256-CTR':
|
17
|
-
return DecrypterAesMode.ctr;
|
18
|
-
default:
|
19
|
-
throw new Error(`invalid full segment method ${method}`);
|
20
|
-
}
|
21
|
-
}
|