Skip to content

Commit d79cdda

Browse files
authored
TypeScript 5.8 and ESLint cleanup (#7099)
* TypeScript 5.8 and ESLint cleanup - Uint8Array and ArrayBufferLike typing - no-unused-vars suppress caught error warnings * Remove IE11 Uint8Array polyfill
1 parent 998ce24 commit d79cdda

18 files changed

+81
-94
lines changed

.eslintrc.js

+1
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ module.exports = {
117117
'warn',
118118
{
119119
args: 'none',
120+
caughtErrors: 'none',
120121
},
121122
],
122123
'@typescript-eslint/prefer-optional-chain': 2,

api-extractor/report/hls.js.api.md

+10-10
Original file line numberDiff line numberDiff line change
@@ -1015,19 +1015,19 @@ export interface DecryptData {
10151015
// (undocumented)
10161016
isCommonEncryption: boolean;
10171017
// (undocumented)
1018-
iv: Uint8Array | null;
1018+
iv: Uint8Array<ArrayBuffer> | null;
10191019
// (undocumented)
1020-
key: Uint8Array | null;
1020+
key: Uint8Array<ArrayBuffer> | null;
10211021
// (undocumented)
10221022
keyFormat: string;
10231023
// (undocumented)
10241024
keyFormatVersions: number[];
10251025
// (undocumented)
1026-
keyId: Uint8Array | null;
1026+
keyId: Uint8Array<ArrayBuffer> | null;
10271027
// (undocumented)
10281028
method: string;
10291029
// (undocumented)
1030-
pssh: Uint8Array | null;
1030+
pssh: Uint8Array<ArrayBuffer> | null;
10311031
// (undocumented)
10321032
uri: string;
10331033
}
@@ -1044,15 +1044,15 @@ export class Decrypter {
10441044
// (undocumented)
10451045
destroy(): void;
10461046
// (undocumented)
1047-
flush(): Uint8Array | null;
1047+
flush(): Uint8Array<ArrayBuffer> | null;
10481048
// (undocumented)
10491049
isSync(): boolean;
10501050
// (undocumented)
10511051
reset(): void;
10521052
// (undocumented)
10531053
softwareDecrypt(data: Uint8Array, key: ArrayBuffer, iv: ArrayBuffer, aesMode: DecrypterAesMode): ArrayBuffer | null;
10541054
// (undocumented)
1055-
webCryptoDecrypt(data: Uint8Array, key: ArrayBuffer, iv: ArrayBuffer, aesMode: DecrypterAesMode): Promise<ArrayBuffer>;
1055+
webCryptoDecrypt(data: Uint8Array<ArrayBuffer>, key: ArrayBuffer, iv: ArrayBuffer, aesMode: DecrypterAesMode): Promise<ArrayBuffer>;
10561056
}
10571057

10581058
// Warning: (ae-missing-release-tag) "DecrypterAesMode" is part of the package's API, but it is missing a release tag (@alpha, @beta, @public, or @internal)
@@ -3261,7 +3261,7 @@ export class LevelDetails {
32613261
//
32623262
// @public (undocumented)
32633263
export class LevelKey implements DecryptData {
3264-
constructor(method: string, uri: string, format: string, formatversions?: number[], iv?: Uint8Array | null);
3264+
constructor(method: string, uri: string, format: string, formatversions?: number[], iv?: Uint8Array<ArrayBuffer> | null);
32653265
// (undocumented)
32663266
static clearKeyUriToKeyIdMap(): void;
32673267
// (undocumented)
@@ -3273,15 +3273,15 @@ export class LevelKey implements DecryptData {
32733273
// (undocumented)
32743274
isSupported(): boolean;
32753275
// (undocumented)
3276-
iv: Uint8Array | null;
3276+
iv: Uint8Array<ArrayBuffer> | null;
32773277
// (undocumented)
3278-
key: Uint8Array | null;
3278+
key: Uint8Array<ArrayBuffer> | null;
32793279
// (undocumented)
32803280
readonly keyFormat: string;
32813281
// (undocumented)
32823282
readonly keyFormatVersions: number[];
32833283
// (undocumented)
3284-
keyId: Uint8Array | null;
3284+
keyId: Uint8Array<ArrayBuffer> | null;
32853285
// (undocumented)
32863286
readonly method: string;
32873287
// (undocumented)

src/controller/base-stream-controller.ts

-2
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,6 @@ export default class BaseStreamController
157157

158158
protected onTickEnd() {}
159159

160-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
161160
public startLoad(startPosition: number): void {}
162161

163162
public stopLoad() {
@@ -746,7 +745,6 @@ export default class BaseStreamController
746745
transmuxer.flush(chunkMeta);
747746
}
748747

749-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
750748
protected _handleFragmentLoadProgress(
751749
frag: PartsLoadedData | FragLoadedData,
752750
) {}

src/controller/eme-controller.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,7 @@ class EMEController extends Logger implements ComponentAPI {
554554
this.keyFormatPromise.then((keySystemFormat) => {
555555
const keySystem = keySystemFormatToKeySystemDomain(keySystemFormat);
556556

557-
let keyId: Uint8Array | null | undefined;
557+
let keyId: Uint8Array<ArrayBuffer> | null | undefined;
558558
let keySystemDomain: KeySystems | undefined;
559559

560560
if (initDataType === 'sinf') {
@@ -574,7 +574,7 @@ class EMEController extends Logger implements ComponentAPI {
574574
`'schm' box missing or not cbcs/cenc with schi > tenc`,
575575
);
576576
}
577-
keyId = tenc.subarray(8, 24);
577+
keyId = new Uint8Array(tenc.subarray(8, 24));
578578
keySystemDomain = KeySystems.FAIRPLAY;
579579
} catch (error) {
580580
this.warn(`${logMessage} Failed to parse sinf: ${error}`);
@@ -629,7 +629,7 @@ class EMEController extends Logger implements ComponentAPI {
629629
if (psshInfo.version === 0 && psshInfo.data) {
630630
if (keySystemDomain === KeySystems.WIDEVINE) {
631631
const offset = psshInfo.data.length - 22;
632-
keyId = psshInfo.data.subarray(offset, offset + 16);
632+
keyId = new Uint8Array(psshInfo.data.subarray(offset, offset + 16));
633633
} else if (keySystemDomain === KeySystems.PLAYREADY) {
634634
keyId = parsePlayReadyWRM(psshInfo.data);
635635
}
@@ -696,7 +696,7 @@ class EMEController extends Logger implements ComponentAPI {
696696
keySystemToKeySystemFormat(keySystem) ?? '',
697697
);
698698
decryptdata.pssh = new Uint8Array(initData);
699-
decryptdata.keyId = keyId as Uint8Array;
699+
decryptdata.keyId = keyId;
700700
return this.attemptSetMediaKeys(keySystem, mediaKeys).then(() => {
701701
this.throwIfDestroyed();
702702
const keySessionContext = this.createMediaKeySessionContext({

src/crypt/aes-decryptor.ts

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
import { sliceUint8 } from '../utils/typed-array';
2-
31
// PKCS7
4-
export function removePadding(array: Uint8Array): Uint8Array {
2+
export function removePadding(array: Uint8Array<ArrayBuffer>) {
53
const outputBytes = array.byteLength;
64
const paddingBytes =
75
outputBytes && new DataView(array.buffer).getUint8(outputBytes - 1);
86
if (paddingBytes) {
9-
return sliceUint8(array, 0, outputBytes - paddingBytes);
7+
return array.slice(0, outputBytes - paddingBytes);
108
}
119
return array;
1210
}
@@ -216,7 +214,11 @@ export default class AESDecryptor {
216214
);
217215
}
218216

219-
decrypt(inputArrayBuffer: ArrayBuffer, offset: number, aesIV: ArrayBuffer) {
217+
decrypt(
218+
inputArrayBuffer: ArrayBufferLike,
219+
offset: number,
220+
aesIV: ArrayBuffer,
221+
) {
220222
const nRounds = this.keySize + 6;
221223
const invKeySchedule = this.invKeySchedule;
222224
const invSBOX = this.invSBox;

src/crypt/decrypter.ts

+6-7
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { DecrypterAesMode } from './decrypter-aes-mode';
44
import FastAESKey from './fast-aes-key';
55
import { logger } from '../utils/logger';
66
import { appendUint8Array } from '../utils/mp4-tools';
7-
import { sliceUint8 } from '../utils/typed-array';
87
import type { HlsConfig } from '../config';
98

109
const CHUNK_SIZE = 16; // 16 bytes, 128 bits
@@ -16,7 +15,7 @@ export default class Decrypter {
1615
private softwareDecrypter: AESDecryptor | null = null;
1716
private key: ArrayBuffer | null = null;
1817
private fastAesKey: FastAESKey | null = null;
19-
private remainderData: Uint8Array | null = null;
18+
private remainderData: Uint8Array<ArrayBuffer> | null = null;
2019
private currentIV: ArrayBuffer | null = null;
2120
private currentResult: ArrayBuffer | null = null;
2221
private useSoftware: boolean;
@@ -55,7 +54,7 @@ export default class Decrypter {
5554
return this.useSoftware;
5655
}
5756

58-
public flush(): Uint8Array | null {
57+
public flush(): Uint8Array<ArrayBuffer> | null {
5958
const { currentResult, remainderData } = this;
6059
if (!currentResult || remainderData) {
6160
this.reset();
@@ -142,7 +141,7 @@ export default class Decrypter {
142141
const result = currentResult;
143142

144143
this.currentResult = softwareDecrypter.decrypt(currentChunk.buffer, 0, iv);
145-
this.currentIV = sliceUint8(currentChunk, -16).buffer;
144+
this.currentIV = currentChunk.slice(-16).buffer;
146145

147146
if (!result) {
148147
return null;
@@ -151,7 +150,7 @@ export default class Decrypter {
151150
}
152151

153152
public webCryptoDecrypt(
154-
data: Uint8Array,
153+
data: Uint8Array<ArrayBuffer>,
155154
key: ArrayBuffer,
156155
iv: ArrayBuffer,
157156
aesMode: DecrypterAesMode,
@@ -210,8 +209,8 @@ export default class Decrypter {
210209
let currentChunk = data;
211210
const splitPoint = data.length - (data.length % CHUNK_SIZE);
212211
if (splitPoint !== data.length) {
213-
currentChunk = sliceUint8(data, 0, splitPoint);
214-
this.remainderData = sliceUint8(data, splitPoint);
212+
currentChunk = data.slice(0, splitPoint);
213+
this.remainderData = data.slice(splitPoint);
215214
}
216215
return currentChunk;
217216
}

src/demux/audio/base-audio-demuxer.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import {
1313
MetadataSchema,
1414
} from '../../types/demuxer';
1515
import { appendUint8Array } from '../../utils/mp4-tools';
16-
import { sliceUint8 } from '../../utils/typed-array';
1716
import { dummyTrack } from '../dummy-demuxed-track';
1817
import type { RationalTimestamp } from '../../utils/timescale-conversion';
1918

@@ -129,7 +128,7 @@ class BaseAudioDemuxer implements Demuxer {
129128
offset++;
130129
}
131130
if (offset === length && lastDataIndex !== length) {
132-
const partialData = sliceUint8(data, lastDataIndex);
131+
const partialData = data.slice(lastDataIndex);
133132
if (this.cachedData) {
134133
this.cachedData = appendUint8Array(this.cachedData, partialData);
135134
} else {

src/demux/sample-aes.ts

+10-15
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { discardEPB } from '../utils/mp4-tools';
88
import type { HlsConfig } from '../config';
99
import type { HlsEventEmitter } from '../events';
1010
import type {
11-
AudioSample,
11+
AACAudioSample,
1212
DemuxedVideoTrackBase,
1313
KeyData,
1414
VideoSample,
@@ -37,7 +37,7 @@ class SampleAesDecrypter {
3737

3838
// AAC - encrypt all full 16 bytes blocks starting from offset 16
3939
private decryptAacSample(
40-
samples: AudioSample[],
40+
samples: AACAudioSample[],
4141
sampleIndex: number,
4242
callback: () => void,
4343
) {
@@ -67,7 +67,7 @@ class SampleAesDecrypter {
6767
}
6868

6969
decryptAacSamples(
70-
samples: AudioSample[],
70+
samples: AACAudioSample[],
7171
sampleIndex: number,
7272
callback: () => void,
7373
) {
@@ -109,10 +109,7 @@ class SampleAesDecrypter {
109109
return encryptedData;
110110
}
111111

112-
getAvcDecryptedUnit(
113-
decodedData: Uint8Array,
114-
decryptedData: ArrayLike<number> | ArrayBuffer | SharedArrayBuffer,
115-
) {
112+
getAvcDecryptedUnit(decodedData: Uint8Array, decryptedData: ArrayBufferLike) {
116113
const uint8DecryptedData = new Uint8Array(decryptedData);
117114
let inputPos = 0;
118115
for (
@@ -139,15 +136,13 @@ class SampleAesDecrypter {
139136
const decodedData = discardEPB(curUnit.data);
140137
const encryptedData = this.getAvcEncryptedData(decodedData);
141138

142-
this.decryptBuffer(encryptedData.buffer).then(
143-
(decryptedBuffer: ArrayBuffer) => {
144-
curUnit.data = this.getAvcDecryptedUnit(decodedData, decryptedBuffer);
139+
this.decryptBuffer(encryptedData.buffer).then((decryptedBuffer) => {
140+
curUnit.data = this.getAvcDecryptedUnit(decodedData, decryptedBuffer);
145141

146-
if (!this.decrypter.isSync()) {
147-
this.decryptAvcSamples(samples, sampleIndex, unitIndex + 1, callback);
148-
}
149-
},
150-
);
142+
if (!this.decrypter.isSync()) {
143+
this.decryptAvcSamples(samples, sampleIndex, unitIndex + 1, callback);
144+
}
145+
});
151146
}
152147

153148
decryptAvcSamples(

src/demux/transmuxer.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ export default class Transmuxer {
9595
const stats = chunkMeta.transmuxing;
9696
stats.executeStart = now();
9797

98-
let uintData: Uint8Array = new Uint8Array(data);
98+
let uintData: Uint8Array<ArrayBuffer> = new Uint8Array(data);
9999
const { currentTransmuxState, transmuxConfig } = this;
100100
if (state) {
101101
this.currentTransmuxState = state;

src/demux/tsdemuxer.ts

+13-9
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import { appendUint8Array, RemuxerTrackIdConfig } from '../utils/mp4-tools';
3434
import type { HlsConfig } from '../config';
3535
import type { HlsEventEmitter } from '../events';
3636
import type BaseVideoParser from './video/base-video-parser';
37-
import type { AudioFrame } from '../types/demuxer';
37+
import type { AudioFrame, DemuxedAAC } from '../types/demuxer';
3838
import type { TypeSupported } from '../utils/codecs';
3939
import type { ILogger } from '../utils/logger';
4040

@@ -564,15 +564,19 @@ class TSDemuxer implements Demuxer {
564564
return new Promise((resolve) => {
565565
const { audioTrack, videoTrack } = demuxResult;
566566
if (audioTrack.samples && audioTrack.segmentCodec === 'aac') {
567-
sampleAes.decryptAacSamples(audioTrack.samples, 0, () => {
568-
if (videoTrack.samples) {
569-
sampleAes.decryptAvcSamples(videoTrack.samples, 0, 0, () => {
567+
sampleAes.decryptAacSamples(
568+
(audioTrack as DemuxedAAC).samples,
569+
0,
570+
() => {
571+
if (videoTrack.samples) {
572+
sampleAes.decryptAvcSamples(videoTrack.samples, 0, 0, () => {
573+
resolve(demuxResult);
574+
});
575+
} else {
570576
resolve(demuxResult);
571-
});
572-
} else {
573-
resolve(demuxResult);
574-
}
575-
});
577+
}
578+
},
579+
);
576580
} else if (videoTrack.samples) {
577581
sampleAes.decryptAvcSamples(videoTrack.samples, 0, 0, () => {
578582
resolve(demuxResult);

src/loader/level-key.ts

+10-10
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@ import { logger } from '../utils/logger';
44
import { KeySystemFormats, parsePlayReadyWRM } from '../utils/mediakeys-helper';
55
import { mp4pssh } from '../utils/mp4-tools';
66

7-
let keyUriToKeyIdMap: { [uri: string]: Uint8Array } = {};
7+
let keyUriToKeyIdMap: { [uri: string]: Uint8Array<ArrayBuffer> } = {};
88

99
export interface DecryptData {
1010
uri: string;
1111
method: string;
1212
keyFormat: string;
1313
keyFormatVersions: number[];
14-
iv: Uint8Array | null;
15-
key: Uint8Array | null;
16-
keyId: Uint8Array | null;
17-
pssh: Uint8Array | null;
14+
iv: Uint8Array<ArrayBuffer> | null;
15+
key: Uint8Array<ArrayBuffer> | null;
16+
keyId: Uint8Array<ArrayBuffer> | null;
17+
pssh: Uint8Array<ArrayBuffer> | null;
1818
encrypted: boolean;
1919
isCommonEncryption: boolean;
2020
}
@@ -26,9 +26,9 @@ export class LevelKey implements DecryptData {
2626
public readonly keyFormatVersions: number[];
2727
public readonly encrypted: boolean;
2828
public readonly isCommonEncryption: boolean;
29-
public iv: Uint8Array | null = null;
30-
public key: Uint8Array | null = null;
31-
public keyId: Uint8Array | null = null;
29+
public iv: Uint8Array<ArrayBuffer> | null = null;
30+
public key: Uint8Array<ArrayBuffer> | null = null;
31+
public keyId: Uint8Array<ArrayBuffer> | null = null;
3232
public pssh: Uint8Array<ArrayBuffer> | null = null;
3333

3434
static clearKeyUriToKeyIdMap() {
@@ -40,7 +40,7 @@ export class LevelKey implements DecryptData {
4040
uri: string,
4141
format: string,
4242
formatversions: number[] = [1],
43-
iv: Uint8Array | null = null,
43+
iv: Uint8Array<ArrayBuffer> | null = null,
4444
) {
4545
this.method = method;
4646
this.uri = uri;
@@ -174,7 +174,7 @@ export class LevelKey implements DecryptData {
174174
}
175175
}
176176

177-
function createInitializationVector(segmentNumber: number): Uint8Array {
177+
function createInitializationVector(segmentNumber: number) {
178178
const uint8View = new Uint8Array(16);
179179
for (let i = 12; i < 16; i++) {
180180
uint8View[i] = (segmentNumber >> (8 * (15 - i))) & 0xff;

0 commit comments

Comments
 (0)