hls.js 1.6.3-0.canary.11262 → 1.6.3
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.d.mts +1 -0
- package/dist/hls.d.ts +1 -0
- package/dist/hls.js +36 -32
- package/dist/hls.js.d.ts +1 -0
- package/dist/hls.js.map +1 -1
- package/dist/hls.light.js +2 -2
- 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 +2 -2
- 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 +36 -32
- 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 +1 -1
- package/src/controller/eme-controller.ts +43 -28
- package/src/utils/event-listener-helper.ts +2 -2
- package/src/utils/utf8-utils.ts +1 -1
package/package.json
CHANGED
@@ -7,6 +7,10 @@ import { EventEmitter } from 'eventemitter3';
|
|
7
7
|
import { ErrorDetails, ErrorTypes } from '../errors';
|
8
8
|
import { Events } from '../events';
|
9
9
|
import { LevelKey } from '../loader/level-key';
|
10
|
+
import {
|
11
|
+
addEventListener,
|
12
|
+
removeEventListener,
|
13
|
+
} from '../utils/event-listener-helper';
|
10
14
|
import Hex from '../utils/hex';
|
11
15
|
import { Logger } from '../utils/logger';
|
12
16
|
import {
|
@@ -105,10 +109,8 @@ class EMEController extends Logger implements ComponentAPI {
|
|
105
109
|
}
|
106
110
|
|
107
111
|
public destroy() {
|
108
|
-
|
109
|
-
this.unregisterListeners();
|
112
|
+
this.onDestroying();
|
110
113
|
this.onMediaDetached();
|
111
|
-
this._clear(media);
|
112
114
|
// Remove any references that could be held in config options or callbacks
|
113
115
|
const config = this.config;
|
114
116
|
config.requestMediaKeySystemAccessFunc = null;
|
@@ -125,6 +127,7 @@ class EMEController extends Logger implements ComponentAPI {
|
|
125
127
|
this.hls.on(Events.MEDIA_DETACHED, this.onMediaDetached, this);
|
126
128
|
this.hls.on(Events.MANIFEST_LOADING, this.onManifestLoading, this);
|
127
129
|
this.hls.on(Events.MANIFEST_LOADED, this.onManifestLoaded, this);
|
130
|
+
this.hls.on(Events.DESTROYING, this.onDestroying, this);
|
128
131
|
}
|
129
132
|
|
130
133
|
private unregisterListeners() {
|
@@ -132,6 +135,7 @@ class EMEController extends Logger implements ComponentAPI {
|
|
132
135
|
this.hls.off(Events.MEDIA_DETACHED, this.onMediaDetached, this);
|
133
136
|
this.hls.off(Events.MANIFEST_LOADING, this.onManifestLoading, this);
|
134
137
|
this.hls.off(Events.MANIFEST_LOADED, this.onManifestLoaded, this);
|
138
|
+
this.hls.off(Events.DESTROYING, this.onDestroying, this);
|
135
139
|
}
|
136
140
|
|
137
141
|
private getLicenseServerUrl(keySystem: KeySystems): string | undefined {
|
@@ -375,7 +379,7 @@ class EMEController extends Logger implements ComponentAPI {
|
|
375
379
|
|
376
380
|
private updateKeySession(
|
377
381
|
mediaKeySessionContext: MediaKeySessionContext,
|
378
|
-
data: Uint8Array
|
382
|
+
data: Uint8Array<ArrayBuffer>,
|
379
383
|
): Promise<void> {
|
380
384
|
const keySession = mediaKeySessionContext.mediaKeysSession;
|
381
385
|
this.log(
|
@@ -879,8 +883,9 @@ class EMEController extends Logger implements ComponentAPI {
|
|
879
883
|
}
|
880
884
|
});
|
881
885
|
|
882
|
-
context.mediaKeysSession
|
883
|
-
|
886
|
+
addEventListener(context.mediaKeysSession, 'message', onmessage);
|
887
|
+
addEventListener(
|
888
|
+
context.mediaKeysSession,
|
884
889
|
'keystatuseschange',
|
885
890
|
onkeystatuseschange,
|
886
891
|
);
|
@@ -1108,8 +1113,8 @@ class EMEController extends Logger implements ComponentAPI {
|
|
1108
1113
|
|
1109
1114
|
private unpackPlayReadyKeyMessage(
|
1110
1115
|
xhr: XMLHttpRequest,
|
1111
|
-
licenseChallenge: Uint8Array
|
1112
|
-
): Uint8Array {
|
1116
|
+
licenseChallenge: Uint8Array<ArrayBuffer>,
|
1117
|
+
): Uint8Array<ArrayBuffer> {
|
1113
1118
|
// On Edge, the raw license message is UTF-16-encoded XML. We need
|
1114
1119
|
// to unpack the Challenge element (base64-encoded string containing the
|
1115
1120
|
// actual license request) and any HttpHeader elements (sent as request
|
@@ -1156,8 +1161,11 @@ class EMEController extends Logger implements ComponentAPI {
|
|
1156
1161
|
xhr: XMLHttpRequest,
|
1157
1162
|
url: string,
|
1158
1163
|
keysListItem: MediaKeySessionContext,
|
1159
|
-
licenseChallenge: Uint8Array
|
1160
|
-
): Promise<{
|
1164
|
+
licenseChallenge: Uint8Array<ArrayBuffer>,
|
1165
|
+
): Promise<{
|
1166
|
+
xhr: XMLHttpRequest;
|
1167
|
+
licenseChallenge: Uint8Array<ArrayBuffer>;
|
1168
|
+
}> {
|
1161
1169
|
const licenseXhrSetup = this.config.licenseXhrSetup;
|
1162
1170
|
|
1163
1171
|
if (!licenseXhrSetup) {
|
@@ -1209,7 +1217,7 @@ class EMEController extends Logger implements ComponentAPI {
|
|
1209
1217
|
|
1210
1218
|
private requestLicense(
|
1211
1219
|
keySessionContext: MediaKeySessionContext,
|
1212
|
-
licenseChallenge: Uint8Array
|
1220
|
+
licenseChallenge: Uint8Array<ArrayBuffer>,
|
1213
1221
|
): Promise<ArrayBuffer> {
|
1214
1222
|
const keyLoadPolicy = this.config.keyLoadPolicy.default;
|
1215
1223
|
return new Promise((resolve, reject) => {
|
@@ -1305,6 +1313,11 @@ class EMEController extends Logger implements ComponentAPI {
|
|
1305
1313
|
});
|
1306
1314
|
}
|
1307
1315
|
|
1316
|
+
private onDestroying() {
|
1317
|
+
this.unregisterListeners();
|
1318
|
+
this._clear();
|
1319
|
+
}
|
1320
|
+
|
1308
1321
|
private onMediaAttached(
|
1309
1322
|
event: Events.MEDIA_ATTACHED,
|
1310
1323
|
data: MediaAttachedData,
|
@@ -1318,30 +1331,32 @@ class EMEController extends Logger implements ComponentAPI {
|
|
1318
1331
|
// keep reference of media
|
1319
1332
|
this.media = media;
|
1320
1333
|
|
1321
|
-
media
|
1322
|
-
media
|
1323
|
-
media.addEventListener('encrypted', this.onMediaEncrypted);
|
1324
|
-
media.addEventListener('waitingforkey', this.onWaitingForKey);
|
1334
|
+
addEventListener(media, 'encrypted', this.onMediaEncrypted);
|
1335
|
+
addEventListener(media, 'waitingforkey', this.onWaitingForKey);
|
1325
1336
|
}
|
1326
1337
|
|
1327
1338
|
private onMediaDetached() {
|
1328
1339
|
const media = this.media;
|
1329
1340
|
|
1330
1341
|
if (media) {
|
1331
|
-
|
1332
|
-
|
1342
|
+
removeEventListener(media, 'encrypted', this.onMediaEncrypted);
|
1343
|
+
removeEventListener(media, 'waitingforkey', this.onWaitingForKey);
|
1333
1344
|
this.media = null;
|
1334
1345
|
this.mediaKeys = null;
|
1335
1346
|
}
|
1336
1347
|
}
|
1337
1348
|
|
1338
|
-
private _clear(
|
1339
|
-
const mediaKeysList = this.mediaKeySessions;
|
1349
|
+
private _clear() {
|
1340
1350
|
this._requestLicenseFailureCount = 0;
|
1341
|
-
this.mediaKeys = null;
|
1342
|
-
this.setMediaKeysQueue = [];
|
1343
|
-
this.mediaKeySessions = [];
|
1344
1351
|
this.keyIdToKeySessionPromise = {};
|
1352
|
+
if (!this.mediaKeys && !this.mediaKeySessions.length) {
|
1353
|
+
return;
|
1354
|
+
}
|
1355
|
+
const media = this.media;
|
1356
|
+
const mediaKeysList = this.mediaKeySessions.slice();
|
1357
|
+
this.mediaKeySessions = [];
|
1358
|
+
this.mediaKeys = null;
|
1359
|
+
|
1345
1360
|
LevelKey.clearKeyUriToKeyIdMap();
|
1346
1361
|
|
1347
1362
|
// Close all sessions and remove media keys from the video element.
|
@@ -1363,12 +1378,6 @@ class EMEController extends Logger implements ComponentAPI {
|
|
1363
1378
|
}),
|
1364
1379
|
),
|
1365
1380
|
)
|
1366
|
-
.then(() => {
|
1367
|
-
if (keySessionCount) {
|
1368
|
-
this.log('finished closing key sessions and clearing media keys');
|
1369
|
-
mediaKeysList.length = 0;
|
1370
|
-
}
|
1371
|
-
})
|
1372
1381
|
.catch((error) => {
|
1373
1382
|
this.log(`Could not close sessions and clear media keys: ${error}`);
|
1374
1383
|
this.hls?.trigger(Events.ERROR, {
|
@@ -1379,6 +1388,12 @@ class EMEController extends Logger implements ComponentAPI {
|
|
1379
1388
|
`Could not close sessions and clear media keys: ${error}`,
|
1380
1389
|
),
|
1381
1390
|
});
|
1391
|
+
})
|
1392
|
+
|
1393
|
+
.then(() => {
|
1394
|
+
if (keySessionCount) {
|
1395
|
+
this.log('finished closing key sessions and clearing media keys');
|
1396
|
+
}
|
1382
1397
|
});
|
1383
1398
|
}
|
1384
1399
|
|
@@ -1,5 +1,5 @@
|
|
1
1
|
export function addEventListener(
|
2
|
-
el:
|
2
|
+
el: EventTarget,
|
3
3
|
type: string,
|
4
4
|
listener: EventListenerOrEventListenerObject,
|
5
5
|
) {
|
@@ -8,7 +8,7 @@ export function addEventListener(
|
|
8
8
|
}
|
9
9
|
|
10
10
|
export function removeEventListener(
|
11
|
-
el:
|
11
|
+
el: EventTarget,
|
12
12
|
type: string,
|
13
13
|
listener: EventListenerOrEventListenerObject,
|
14
14
|
) {
|
package/src/utils/utf8-utils.ts
CHANGED
@@ -11,7 +11,7 @@ export type Frame = DecodedFrame<ArrayBuffer | string>;
|
|
11
11
|
* This library is free. You can redistribute it and/or modify it.
|
12
12
|
*/
|
13
13
|
|
14
|
-
export function strToUtf8array(str: string)
|
14
|
+
export function strToUtf8array(str: string) {
|
15
15
|
return Uint8Array.from(unescape(encodeURIComponent(str)), (c) =>
|
16
16
|
c.charCodeAt(0),
|
17
17
|
);
|