Skip to content

Commit 22d9806

Browse files
committed
TypeScript 5.8 and ESLint cleanup
- Uint8Array and ArrayBufferLike typing - no-unused-vars suppress caught error warnings
1 parent 2ef42ba commit 22d9806

16 files changed

+80
-74
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

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { sliceUint8 } from '../utils/typed-array';
22

33
// PKCS7
4-
export function removePadding(array: Uint8Array): Uint8Array {
4+
export function removePadding(array: Uint8Array<ArrayBuffer>) {
55
const outputBytes = array.byteLength;
66
const paddingBytes =
77
outputBytes && new DataView(array.buffer).getUint8(outputBytes - 1);
@@ -216,7 +216,11 @@ export default class AESDecryptor {
216216
);
217217
}
218218

219-
decrypt(inputArrayBuffer: ArrayBuffer, offset: number, aesIV: ArrayBuffer) {
219+
decrypt(
220+
inputArrayBuffer: ArrayBufferLike,
221+
offset: number,
222+
aesIV: ArrayBuffer,
223+
) {
220224
const nRounds = this.keySize + 6;
221225
const invKeySchedule = this.invKeySchedule;
222226
const invSBOX = this.invSBox;

src/crypt/decrypter.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export default class Decrypter {
1616
private softwareDecrypter: AESDecryptor | null = null;
1717
private key: ArrayBuffer | null = null;
1818
private fastAesKey: FastAESKey | null = null;
19-
private remainderData: Uint8Array | null = null;
19+
private remainderData: Uint8Array<ArrayBuffer> | null = null;
2020
private currentIV: ArrayBuffer | null = null;
2121
private currentResult: ArrayBuffer | null = null;
2222
private useSoftware: boolean;
@@ -55,7 +55,7 @@ export default class Decrypter {
5555
return this.useSoftware;
5656
}
5757

58-
public flush(): Uint8Array | null {
58+
public flush(): Uint8Array<ArrayBuffer> | null {
5959
const { currentResult, remainderData } = this;
6060
if (!currentResult || remainderData) {
6161
this.reset();
@@ -151,7 +151,7 @@ export default class Decrypter {
151151
}
152152

153153
public webCryptoDecrypt(
154-
data: Uint8Array,
154+
data: Uint8Array<ArrayBuffer>,
155155
key: ArrayBuffer,
156156
iv: ArrayBuffer,
157157
aesMode: DecrypterAesMode,

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;

src/types/demuxer.ts

+11-2
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,11 @@ export interface DemuxedAudioTrack extends DemuxedTrack {
6969
samples: AudioSample[];
7070
}
7171

72+
export type DemuxedAAC = DemuxedAudioTrack & {
73+
segmentCodec: 'aac';
74+
samples: AACAudioSample[];
75+
};
76+
7277
export type DemuxedAC3 = DemuxedAudioTrack & {
7378
segmentCodec: 'ac3';
7479
config: Uint8Array;
@@ -180,6 +185,10 @@ export type AudioSample = {
180185
pts: number;
181186
};
182187

188+
export type AACAudioSample = {
189+
unit: Uint8Array<ArrayBuffer>;
190+
};
191+
183192
export type AudioFrame = {
184193
sample: AudioSample;
185194
length: number;
@@ -193,6 +202,6 @@ export interface ElementaryStreamData {
193202

194203
export interface KeyData {
195204
method: string;
196-
key: Uint8Array;
197-
iv: Uint8Array;
205+
key: Uint8Array<ArrayBuffer>;
206+
iv: Uint8Array<ArrayBuffer>;
198207
}

src/utils/mediakeys-helper.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ function createMediaKeySystemConfigurations(
166166
return [baseConfig];
167167
}
168168

169-
export function parsePlayReadyWRM(keyBytes: Uint8Array): Uint8Array | null {
169+
export function parsePlayReadyWRM(keyBytes: Uint8Array) {
170170
const keyBytesUtf16 = new Uint16Array(
171171
keyBytes.buffer,
172172
keyBytes.byteOffset,

src/utils/mp4-tools.ts

+1-5
Original file line numberDiff line numberDiff line change
@@ -844,14 +844,10 @@ export interface SegmentedRange {
844844
remainder: Uint8Array | null;
845845
}
846846

847-
export function appendUint8Array(
848-
data1: Uint8Array,
849-
data2: Uint8Array,
850-
): Uint8Array {
847+
export function appendUint8Array(data1: Uint8Array, data2: Uint8Array) {
851848
const temp = new Uint8Array(data1.length + data2.length);
852849
temp.set(data1);
853850
temp.set(data2, data1.length);
854-
855851
return temp;
856852
}
857853

0 commit comments

Comments
 (0)