@videojs/hlsjs-video 10.0.1 → 10.1.0
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/default/chapters.js +68 -0
- package/dist/default/hls-js-only.js +5 -2
- package/dist/default/request-credentials.js +32 -0
- package/dist/dev/chapters.js +70 -0
- package/dist/dev/chapters.js.map +1 -0
- package/dist/dev/hls-js-only.js +5 -2
- package/dist/dev/hls-js-only.js.map +1 -1
- package/dist/dev/request-credentials.js +34 -0
- package/dist/dev/request-credentials.js.map +1 -0
- package/package.json +7 -6
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { isCredentialed } from "./request-credentials.js";
|
|
2
|
+
import Hls from "hls.js";
|
|
3
|
+
import { loadChaptersTracks } from "@videojs/spf/dom";
|
|
4
|
+
import { APPLE_HLS_CHAPTERS_DATA_ID } from "@videojs/spf/hls";
|
|
5
|
+
import { isString } from "@videojs/utils/predicate";
|
|
6
|
+
//#region src/chapters.ts
|
|
7
|
+
/**
|
|
8
|
+
* Chapters for hls.js playback: the Apple JSON chapters document the multivariant playlist references
|
|
9
|
+
* (`#EXT-X-SESSION-DATA:DATA-ID="com.apple.hls.chapters"`), loaded as hidden `<track kind="chapters">` elements by
|
|
10
|
+
* SPF's `loadChaptersTracks`, as SPF and native HLS playback do. The track in hls.js's `subtitlePreference` language
|
|
11
|
+
* leads, as SPF's leads in its `preferredSubtitleLanguage`.
|
|
12
|
+
*
|
|
13
|
+
* Read from hls.js's own `sessionData`, which keeps one entry per `DATA-ID` — the last. SPF and native HLS read the
|
|
14
|
+
* first entry with a `URI`, so the paths differ only for a playlist naming several chapters documents.
|
|
15
|
+
*
|
|
16
|
+
* Read on `MANIFEST_LOADED`, whose `url` is the response URL, so a relative `URI` resolves past redirects. The tracks
|
|
17
|
+
* go with the source (`MANIFEST_LOADING`) and the element (`MEDIA_DETACHED`, `DESTROYING`); a manifest that loaded
|
|
18
|
+
* before media was attached loads once it is. The document request sends cookies under `crossorigin="use-credentials"`,
|
|
19
|
+
* as hls.js's own requests do.
|
|
20
|
+
*/
|
|
21
|
+
function HlsJsChaptersMixin(BaseClass) {
|
|
22
|
+
class HlsJsChapters extends BaseClass {
|
|
23
|
+
#chaptersUrl = null;
|
|
24
|
+
#chapters = null;
|
|
25
|
+
constructor(...args) {
|
|
26
|
+
super(...args);
|
|
27
|
+
const { engine } = this;
|
|
28
|
+
if (!engine) return;
|
|
29
|
+
engine.on(Hls.Events.MANIFEST_LOADING, () => this.#reset());
|
|
30
|
+
engine.on(Hls.Events.MANIFEST_LOADED, (_event, data) => {
|
|
31
|
+
const uri = data.sessionData?.[APPLE_HLS_CHAPTERS_DATA_ID]?.URI;
|
|
32
|
+
this.#reset();
|
|
33
|
+
this.#chaptersUrl = isString(uri) && uri ? resolveUrl(uri, data.url) : null;
|
|
34
|
+
this.#load();
|
|
35
|
+
});
|
|
36
|
+
engine.on(Hls.Events.MEDIA_ATTACHED, () => this.#load());
|
|
37
|
+
engine.on(Hls.Events.MEDIA_DETACHED, () => this.#stop());
|
|
38
|
+
engine.on(Hls.Events.DESTROYING, () => this.#reset());
|
|
39
|
+
}
|
|
40
|
+
#load() {
|
|
41
|
+
const target = this.target;
|
|
42
|
+
if (!target || !this.#chaptersUrl || this.#chapters) return;
|
|
43
|
+
this.#chapters = new AbortController();
|
|
44
|
+
loadChaptersTracks(target, this.#chaptersUrl, this.#chapters.signal, {
|
|
45
|
+
preferredLanguage: this.engine?.config.subtitlePreference?.lang,
|
|
46
|
+
credentials: isCredentialed(target.crossOrigin) ? "include" : void 0
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
#stop() {
|
|
50
|
+
this.#chapters?.abort();
|
|
51
|
+
this.#chapters = null;
|
|
52
|
+
}
|
|
53
|
+
#reset() {
|
|
54
|
+
this.#chaptersUrl = null;
|
|
55
|
+
this.#stop();
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return HlsJsChapters;
|
|
59
|
+
}
|
|
60
|
+
function resolveUrl(uri, baseUrl) {
|
|
61
|
+
try {
|
|
62
|
+
return new URL(uri, baseUrl).href;
|
|
63
|
+
} catch {
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
//#endregion
|
|
68
|
+
export { HlsJsChaptersMixin };
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { HlsJsAirPlayMixin } from "./airplay-bridge.js";
|
|
2
2
|
import { DEFAULT_MIN_AUTO_RESOLUTION, createCapLevelController } from "./cap-level.js";
|
|
3
|
+
import { withRequestCredentials } from "./request-credentials.js";
|
|
4
|
+
import { HlsJsChaptersMixin } from "./chapters.js";
|
|
3
5
|
import { setupDrm } from "./drm.js";
|
|
4
6
|
import { HlsJsErrorsMixin } from "./errors.js";
|
|
5
7
|
import { HlsJsLiveMixin } from "./live.js";
|
|
@@ -35,7 +37,8 @@ var HlsJsOnlyAdapterCore = class extends HTMLVideoAdapter {
|
|
|
35
37
|
};
|
|
36
38
|
this.#engine = new Hls({
|
|
37
39
|
...config,
|
|
38
|
-
capLevelController: createCapLevelController(this.#capPolicy, config.capLevelController)
|
|
40
|
+
capLevelController: createCapLevelController(this.#capPolicy, config.capLevelController),
|
|
41
|
+
...withRequestCredentials(config, () => this.target?.crossOrigin)
|
|
39
42
|
});
|
|
40
43
|
setupDrm(this.#engine);
|
|
41
44
|
}
|
|
@@ -91,7 +94,7 @@ var HlsJsOnlyAdapterCore = class extends HTMLVideoAdapter {
|
|
|
91
94
|
this.#engine = null;
|
|
92
95
|
}
|
|
93
96
|
};
|
|
94
|
-
const HlsJsOnlyAdapterComposed = HlsJsAirPlayMixin(HlsJsPreloadMixin(HlsJsLiveMixin(HlsJsStreamTypeMixin(HlsJsMediaTracksMixin(HlsJsMetadataTracksMixin(HlsJsTextTracksMixin(HlsJsErrorsMixin(MediaTracksMixin(HlsJsOnlyAdapterCore)))))))));
|
|
97
|
+
const HlsJsOnlyAdapterComposed = HlsJsAirPlayMixin(HlsJsPreloadMixin(HlsJsLiveMixin(HlsJsStreamTypeMixin(HlsJsMediaTracksMixin(HlsJsChaptersMixin(HlsJsMetadataTracksMixin(HlsJsTextTracksMixin(HlsJsErrorsMixin(MediaTracksMixin(HlsJsOnlyAdapterCore))))))))));
|
|
95
98
|
var HlsJsOnlyAdapter = class extends HlsJsOnlyAdapterComposed {};
|
|
96
99
|
//#endregion
|
|
97
100
|
export { HlsJsOnlyAdapter };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
//#region src/request-credentials.ts
|
|
2
|
+
/** Whether the element's CORS-settings attribute asks for cookies on its resource fetches. */
|
|
3
|
+
function isCredentialed(crossOrigin) {
|
|
4
|
+
return crossOrigin?.toLowerCase() === "use-credentials";
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Layer the media element's `crossorigin` onto hls.js's loader hooks so `use-credentials` sends cookies with every
|
|
8
|
+
* manifest, playlist, and segment request, the way the browser does under native playback.
|
|
9
|
+
*
|
|
10
|
+
* Both hooks are covered because hls.js picks one loader per configuration: `xhrSetup` for the default `XhrLoader`
|
|
11
|
+
* (`withCredentials`), `fetchSetup` for `FetchLoader` (`credentials: 'include'`). A hook the config already names runs
|
|
12
|
+
* after ours, on the same request, so a consumer's own setup keeps working and can still override the mode. Anything
|
|
13
|
+
* but `use-credentials` — `anonymous`, an empty value, no attribute — leaves hls.js's default (`same-origin`).
|
|
14
|
+
*
|
|
15
|
+
* The attribute is read per request rather than at construction: the engine exists before the element is attached, and
|
|
16
|
+
* an author can change the attribute afterwards.
|
|
17
|
+
*/
|
|
18
|
+
function withRequestCredentials(config, crossOrigin) {
|
|
19
|
+
const { xhrSetup, fetchSetup } = config;
|
|
20
|
+
return {
|
|
21
|
+
async xhrSetup(xhr, url) {
|
|
22
|
+
if (isCredentialed(crossOrigin())) xhr.withCredentials = true;
|
|
23
|
+
await xhrSetup?.(xhr, url);
|
|
24
|
+
},
|
|
25
|
+
fetchSetup(context, initParams) {
|
|
26
|
+
if (isCredentialed(crossOrigin())) initParams.credentials = "include";
|
|
27
|
+
return fetchSetup ? fetchSetup(context, initParams) : new Request(context.url, initParams);
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
//#endregion
|
|
32
|
+
export { isCredentialed, withRequestCredentials };
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { isCredentialed } from "./request-credentials.js";
|
|
2
|
+
import Hls from "hls.js";
|
|
3
|
+
import { loadChaptersTracks } from "@videojs/spf/dom";
|
|
4
|
+
import { APPLE_HLS_CHAPTERS_DATA_ID } from "@videojs/spf/hls";
|
|
5
|
+
import { isString } from "@videojs/utils/predicate";
|
|
6
|
+
//#region src/chapters.ts
|
|
7
|
+
/**
|
|
8
|
+
* Chapters for hls.js playback: the Apple JSON chapters document the multivariant playlist references
|
|
9
|
+
* (`#EXT-X-SESSION-DATA:DATA-ID="com.apple.hls.chapters"`), loaded as hidden `<track kind="chapters">` elements by
|
|
10
|
+
* SPF's `loadChaptersTracks`, as SPF and native HLS playback do. The track in hls.js's `subtitlePreference` language
|
|
11
|
+
* leads, as SPF's leads in its `preferredSubtitleLanguage`.
|
|
12
|
+
*
|
|
13
|
+
* Read from hls.js's own `sessionData`, which keeps one entry per `DATA-ID` — the last. SPF and native HLS read the
|
|
14
|
+
* first entry with a `URI`, so the paths differ only for a playlist naming several chapters documents.
|
|
15
|
+
*
|
|
16
|
+
* Read on `MANIFEST_LOADED`, whose `url` is the response URL, so a relative `URI` resolves past redirects. The tracks
|
|
17
|
+
* go with the source (`MANIFEST_LOADING`) and the element (`MEDIA_DETACHED`, `DESTROYING`); a manifest that loaded
|
|
18
|
+
* before media was attached loads once it is. The document request sends cookies under `crossorigin="use-credentials"`,
|
|
19
|
+
* as hls.js's own requests do.
|
|
20
|
+
*/
|
|
21
|
+
function HlsJsChaptersMixin(BaseClass) {
|
|
22
|
+
class HlsJsChapters extends BaseClass {
|
|
23
|
+
#chaptersUrl = null;
|
|
24
|
+
#chapters = null;
|
|
25
|
+
constructor(...args) {
|
|
26
|
+
super(...args);
|
|
27
|
+
const { engine } = this;
|
|
28
|
+
if (!engine) return;
|
|
29
|
+
engine.on(Hls.Events.MANIFEST_LOADING, () => this.#reset());
|
|
30
|
+
engine.on(Hls.Events.MANIFEST_LOADED, (_event, data) => {
|
|
31
|
+
const uri = data.sessionData?.[APPLE_HLS_CHAPTERS_DATA_ID]?.URI;
|
|
32
|
+
this.#reset();
|
|
33
|
+
this.#chaptersUrl = isString(uri) && uri ? resolveUrl(uri, data.url) : null;
|
|
34
|
+
this.#load();
|
|
35
|
+
});
|
|
36
|
+
engine.on(Hls.Events.MEDIA_ATTACHED, () => this.#load());
|
|
37
|
+
engine.on(Hls.Events.MEDIA_DETACHED, () => this.#stop());
|
|
38
|
+
engine.on(Hls.Events.DESTROYING, () => this.#reset());
|
|
39
|
+
}
|
|
40
|
+
#load() {
|
|
41
|
+
const target = this.target;
|
|
42
|
+
if (!target || !this.#chaptersUrl || this.#chapters) return;
|
|
43
|
+
this.#chapters = new AbortController();
|
|
44
|
+
loadChaptersTracks(target, this.#chaptersUrl, this.#chapters.signal, {
|
|
45
|
+
preferredLanguage: this.engine?.config.subtitlePreference?.lang,
|
|
46
|
+
credentials: isCredentialed(target.crossOrigin) ? "include" : void 0
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
#stop() {
|
|
50
|
+
this.#chapters?.abort();
|
|
51
|
+
this.#chapters = null;
|
|
52
|
+
}
|
|
53
|
+
#reset() {
|
|
54
|
+
this.#chaptersUrl = null;
|
|
55
|
+
this.#stop();
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return HlsJsChapters;
|
|
59
|
+
}
|
|
60
|
+
function resolveUrl(uri, baseUrl) {
|
|
61
|
+
try {
|
|
62
|
+
return new URL(uri, baseUrl).href;
|
|
63
|
+
} catch {
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
//#endregion
|
|
68
|
+
export { HlsJsChaptersMixin };
|
|
69
|
+
|
|
70
|
+
//# sourceMappingURL=chapters.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chapters.js","names":[],"sources":["../../src/chapters.ts"],"sourcesContent":["import { loadChaptersTracks } from '@videojs/spf/dom';\nimport { APPLE_HLS_CHAPTERS_DATA_ID } from '@videojs/spf/hls';\nimport { isString } from '@videojs/utils/predicate';\nimport type { Constructor } from '@videojs/utils/types';\nimport type { ManifestLoadedData } from 'hls.js';\nimport Hls from 'hls.js';\n\nimport { isCredentialed } from './request-credentials';\nimport type { HlsEngineHost } from './types';\n\n/**\n * Chapters for hls.js playback: the Apple JSON chapters document the multivariant playlist references\n * (`#EXT-X-SESSION-DATA:DATA-ID=\"com.apple.hls.chapters\"`), loaded as hidden `<track kind=\"chapters\">` elements by\n * SPF's `loadChaptersTracks`, as SPF and native HLS playback do. The track in hls.js's `subtitlePreference` language\n * leads, as SPF's leads in its `preferredSubtitleLanguage`.\n *\n * Read from hls.js's own `sessionData`, which keeps one entry per `DATA-ID` — the last. SPF and native HLS read the\n * first entry with a `URI`, so the paths differ only for a playlist naming several chapters documents.\n *\n * Read on `MANIFEST_LOADED`, whose `url` is the response URL, so a relative `URI` resolves past redirects. The tracks\n * go with the source (`MANIFEST_LOADING`) and the element (`MEDIA_DETACHED`, `DESTROYING`); a manifest that loaded\n * before media was attached loads once it is. The document request sends cookies under `crossorigin=\"use-credentials\"`,\n * as hls.js's own requests do.\n */\nexport function HlsJsChaptersMixin<Base extends Constructor<HlsEngineHost>>(BaseClass: Base) {\n class HlsJsChapters extends (BaseClass as Constructor<HlsEngineHost>) {\n #chaptersUrl: string | null = null;\n #chapters: AbortController | null = null;\n\n constructor(...args: any[]) {\n super(...args);\n\n const { engine } = this;\n if (!engine) return;\n\n engine.on(Hls.Events.MANIFEST_LOADING, () => this.#reset());\n engine.on(Hls.Events.MANIFEST_LOADED, (_event: string, data: ManifestLoadedData) => {\n const uri = data.sessionData?.[APPLE_HLS_CHAPTERS_DATA_ID]?.URI;\n\n this.#reset();\n this.#chaptersUrl = isString(uri) && uri ? resolveUrl(uri, data.url) : null;\n this.#load();\n });\n engine.on(Hls.Events.MEDIA_ATTACHED, () => this.#load());\n engine.on(Hls.Events.MEDIA_DETACHED, () => this.#stop());\n engine.on(Hls.Events.DESTROYING, () => this.#reset());\n }\n\n #load(): void {\n // The hls.js delegate always binds to the real `<video>` element.\n const target = this.target as HTMLVideoElement | null;\n if (!target || !this.#chaptersUrl || this.#chapters) return;\n\n this.#chapters = new AbortController();\n loadChaptersTracks(target, this.#chaptersUrl, this.#chapters.signal, {\n preferredLanguage: this.engine?.config.subtitlePreference?.lang,\n credentials: isCredentialed(target.crossOrigin) ? 'include' : undefined,\n });\n }\n\n #stop(): void {\n this.#chapters?.abort();\n this.#chapters = null;\n }\n\n #reset(): void {\n this.#chaptersUrl = null;\n this.#stop();\n }\n }\n\n return HlsJsChapters as unknown as Base;\n}\n\nfunction resolveUrl(uri: string, baseUrl: string): string | null {\n try {\n return new URL(uri, baseUrl).href;\n } catch {\n return null;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAwBA,SAAgB,mBAA4D,WAAiB;CAC3F,MAAM,sBAAuB,UAAyC;EACpE,eAA8B;EAC9B,YAAoC;EAEpC,YAAY,GAAG,MAAa;GAC1B,MAAM,GAAG,IAAI;GAEb,MAAM,EAAE,WAAW;GACnB,IAAI,CAAC,QAAQ;GAEb,OAAO,GAAG,IAAI,OAAO,wBAAwB,KAAK,OAAO,CAAC;GAC1D,OAAO,GAAG,IAAI,OAAO,kBAAkB,QAAgB,SAA6B;IAClF,MAAM,MAAM,KAAK,cAAc,2BAA2B,EAAE;IAE5D,KAAK,OAAO;IACZ,KAAK,eAAe,SAAS,GAAG,KAAK,MAAM,WAAW,KAAK,KAAK,GAAG,IAAI;IACvE,KAAK,MAAM;GACb,CAAC;GACD,OAAO,GAAG,IAAI,OAAO,sBAAsB,KAAK,MAAM,CAAC;GACvD,OAAO,GAAG,IAAI,OAAO,sBAAsB,KAAK,MAAM,CAAC;GACvD,OAAO,GAAG,IAAI,OAAO,kBAAkB,KAAK,OAAO,CAAC;EACtD;EAEA,QAAc;GAEZ,MAAM,SAAS,KAAK;GACpB,IAAI,CAAC,UAAU,CAAC,KAAK,gBAAgB,KAAK,WAAW;GAErD,KAAK,YAAY,IAAI,gBAAgB;GACrC,mBAAmB,QAAQ,KAAK,cAAc,KAAK,UAAU,QAAQ;IACnE,mBAAmB,KAAK,QAAQ,OAAO,oBAAoB;IAC3D,aAAa,eAAe,OAAO,WAAW,IAAI,YAAY,KAAA;GAChE,CAAC;EACH;EAEA,QAAc;GACZ,KAAK,WAAW,MAAM;GACtB,KAAK,YAAY;EACnB;EAEA,SAAe;GACb,KAAK,eAAe;GACpB,KAAK,MAAM;EACb;CACF;CAEA,OAAO;AACT;AAEA,SAAS,WAAW,KAAa,SAAgC;CAC/D,IAAI;EACF,OAAO,IAAI,IAAI,KAAK,OAAO,CAAC,CAAC;CAC/B,QAAQ;EACN,OAAO;CACT;AACF"}
|
package/dist/dev/hls-js-only.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { HlsJsAirPlayMixin } from "./airplay-bridge.js";
|
|
2
2
|
import { DEFAULT_MIN_AUTO_RESOLUTION, createCapLevelController } from "./cap-level.js";
|
|
3
|
+
import { withRequestCredentials } from "./request-credentials.js";
|
|
4
|
+
import { HlsJsChaptersMixin } from "./chapters.js";
|
|
3
5
|
import { setupDrm } from "./drm.js";
|
|
4
6
|
import { HlsJsErrorsMixin } from "./errors.js";
|
|
5
7
|
import { HlsJsLiveMixin } from "./live.js";
|
|
@@ -35,7 +37,8 @@ var HlsJsOnlyAdapterCore = class extends HTMLVideoAdapter {
|
|
|
35
37
|
};
|
|
36
38
|
this.#engine = new Hls({
|
|
37
39
|
...config,
|
|
38
|
-
capLevelController: createCapLevelController(this.#capPolicy, config.capLevelController)
|
|
40
|
+
capLevelController: createCapLevelController(this.#capPolicy, config.capLevelController),
|
|
41
|
+
...withRequestCredentials(config, () => this.target?.crossOrigin)
|
|
39
42
|
});
|
|
40
43
|
setupDrm(this.#engine);
|
|
41
44
|
}
|
|
@@ -91,7 +94,7 @@ var HlsJsOnlyAdapterCore = class extends HTMLVideoAdapter {
|
|
|
91
94
|
this.#engine = null;
|
|
92
95
|
}
|
|
93
96
|
};
|
|
94
|
-
const HlsJsOnlyAdapterComposed = HlsJsAirPlayMixin(HlsJsPreloadMixin(HlsJsLiveMixin(HlsJsStreamTypeMixin(HlsJsMediaTracksMixin(HlsJsMetadataTracksMixin(HlsJsTextTracksMixin(HlsJsErrorsMixin(MediaTracksMixin(HlsJsOnlyAdapterCore)))))))));
|
|
97
|
+
const HlsJsOnlyAdapterComposed = HlsJsAirPlayMixin(HlsJsPreloadMixin(HlsJsLiveMixin(HlsJsStreamTypeMixin(HlsJsMediaTracksMixin(HlsJsChaptersMixin(HlsJsMetadataTracksMixin(HlsJsTextTracksMixin(HlsJsErrorsMixin(MediaTracksMixin(HlsJsOnlyAdapterCore))))))))));
|
|
95
98
|
var HlsJsOnlyAdapter = class extends HlsJsOnlyAdapterComposed {};
|
|
96
99
|
//#endregion
|
|
97
100
|
export { HlsJsOnlyAdapter };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hls-js-only.js","names":[],"sources":["../../src/hls-js-only.ts"],"sourcesContent":["import type {\n EngineAdapter,\n MediaError,\n MediaLiveCapability,\n MediaResolution,\n MediaSourceCapability,\n MediaStreamTypeCapability,\n} from '@videojs/media';\nimport { HTMLVideoAdapter } from '@videojs/media/dom';\nimport { MediaTracksMixin, type WithMediaTracks } from '@videojs/media/media-tracks';\nimport type { MixinReturn } from '@videojs/utils/types';\nimport Hls, { type HlsConfig } from 'hls.js';\n\nimport { HlsJsAirPlayMixin } from './airplay-bridge';\nimport { createCapLevelController, DEFAULT_MIN_AUTO_RESOLUTION, type RenditionCapPolicy } from './cap-level';\nimport { setupDrm } from './drm';\nimport { HlsJsErrorsMixin } from './errors';\nimport { HlsJsLiveMixin } from './live';\nimport { HlsJsMediaTracksMixin } from './media-tracks';\nimport { HlsJsMetadataTracksMixin } from './metadata-tracks';\nimport { HlsJsPreloadMixin } from './preload';\nimport { HlsJsStreamTypeMixin } from './stream-type';\nimport { HlsJsTextTracksMixin, withPreservedTextTracks } from './text-tracks';\n\nconst defaultHlsConfig: Partial<HlsConfig> = {\n backBufferLength: 30,\n renderTextTracksNatively: false,\n liveDurationInfinity: true,\n // Runs hls.js's capping loop, which every rendition cap is evaluated on, not\n // only the one named after it. `capRenditionToPlayerSize` is the live switch.\n capLevelToPlayerSize: true,\n capLevelOnFPSDrop: true,\n autoStartLoad: false,\n};\n\nexport interface HlsJsOnlyMediaParams {\n /** Options forwarded to the hls.js constructor, merged over {@link defaultHlsConfig}. */\n config: Partial<HlsConfig>;\n}\n\nclass HlsJsOnlyAdapterCore extends HTMLVideoAdapter implements EngineAdapter<Hls, HTMLVideoElement> {\n #engine: Hls | null = null;\n #capPolicy: RenditionCapPolicy = {\n maxAutoResolution: undefined,\n capToPlayerSize: true,\n minAutoResolution: DEFAULT_MIN_AUTO_RESOLUTION,\n };\n\n constructor(params: HlsJsOnlyMediaParams) {\n super();\n const config = { ...defaultHlsConfig, ...params.config };\n\n this.#engine = new Hls({\n ...config,\n // Layered over whatever controller the config already names, so a\n // `capLevelController` passed through `source.engine` keeps working.\n capLevelController: createCapLevelController(this.#capPolicy, config.capLevelController),\n });\n\n setupDrm(this.#engine);\n }\n\n get engine() {\n return this.#engine;\n }\n\n /** Ceiling on automatic rendition selection. See `HlsSource.maxAutoResolution`. */\n get maxAutoResolution(): MediaResolution | undefined {\n return this.#capPolicy.maxAutoResolution;\n }\n\n set maxAutoResolution(value: MediaResolution | undefined) {\n if (this.#capPolicy.maxAutoResolution === value) return;\n\n this.#capPolicy.maxAutoResolution = value;\n this.#capPolicy.controller?.apply();\n }\n\n /** Whether the rendered size caps selection. See `HlsSource.capRenditionToPlayerSize`. */\n get capRenditionToPlayerSize(): boolean {\n return this.#capPolicy.capToPlayerSize;\n }\n\n set capRenditionToPlayerSize(value: boolean | undefined) {\n // Defaults resolve here rather than in the caller, so the getters report the\n // cap that is actually in force instead of what a source happened to name.\n const next = value ?? true;\n if (this.#capPolicy.capToPlayerSize === next) return;\n\n this.#capPolicy.capToPlayerSize = next;\n this.#capPolicy.controller?.apply();\n }\n\n /** Floor on the player-size cap. See `HlsSource.minAutoResolution`. */\n get minAutoResolution(): MediaResolution {\n return this.#capPolicy.minAutoResolution ?? DEFAULT_MIN_AUTO_RESOLUTION;\n }\n\n set minAutoResolution(value: MediaResolution | undefined) {\n const next = value ?? DEFAULT_MIN_AUTO_RESOLUTION;\n if (this.#capPolicy.minAutoResolution === next) return;\n\n this.#capPolicy.minAutoResolution = next;\n this.#capPolicy.controller?.apply();\n }\n\n get src() {\n return this.#engine?.url ?? '';\n }\n\n set src(src: string) {\n // Attaching, detaching, and loading a source each reset every text track on\n // the element, sideloaded ones included. See `withPreservedTextTracks`.\n withPreservedTextTracks(this.target as HTMLVideoElement | null, () => this.#engine?.loadSource(src));\n }\n\n attach(target: HTMLVideoElement) {\n super.attach(target);\n withPreservedTextTracks(target, () => this.#engine?.attachMedia(target));\n }\n\n detach() {\n withPreservedTextTracks(this.target as HTMLVideoElement | null, () => this.#engine?.detachMedia());\n super.detach();\n }\n\n destroy() {\n this.detach();\n this.#engine?.destroy();\n this.#engine = null;\n }\n}\n\ninterface HlsJsMediaCapabilities\n extends MediaStreamTypeCapability, MediaLiveCapability, Pick<MediaSourceCapability, 'preload'> {\n readonly error: MediaError | null;\n}\n\nconst HlsJsOnlyAdapterComposed = HlsJsAirPlayMixin(\n HlsJsPreloadMixin(\n HlsJsLiveMixin(\n HlsJsStreamTypeMixin(\n HlsJsMediaTracksMixin(\n HlsJsMetadataTracksMixin(HlsJsTextTracksMixin(HlsJsErrorsMixin(MediaTracksMixin(HlsJsOnlyAdapterCore))))\n )\n )\n )\n )\n) as unknown as MixinReturn<WithMediaTracks<typeof HlsJsOnlyAdapterCore>, HlsJsMediaCapabilities>;\n\nexport class HlsJsOnlyAdapter extends HlsJsOnlyAdapterComposed {}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"hls-js-only.js","names":[],"sources":["../../src/hls-js-only.ts"],"sourcesContent":["import type {\n EngineAdapter,\n MediaError,\n MediaLiveCapability,\n MediaResolution,\n MediaSourceCapability,\n MediaStreamTypeCapability,\n} from '@videojs/media';\nimport { HTMLVideoAdapter } from '@videojs/media/dom';\nimport { MediaTracksMixin, type WithMediaTracks } from '@videojs/media/media-tracks';\nimport type { MixinReturn } from '@videojs/utils/types';\nimport Hls, { type HlsConfig } from 'hls.js';\n\nimport { HlsJsAirPlayMixin } from './airplay-bridge';\nimport { createCapLevelController, DEFAULT_MIN_AUTO_RESOLUTION, type RenditionCapPolicy } from './cap-level';\nimport { HlsJsChaptersMixin } from './chapters';\nimport { setupDrm } from './drm';\nimport { HlsJsErrorsMixin } from './errors';\nimport { HlsJsLiveMixin } from './live';\nimport { HlsJsMediaTracksMixin } from './media-tracks';\nimport { HlsJsMetadataTracksMixin } from './metadata-tracks';\nimport { HlsJsPreloadMixin } from './preload';\nimport { withRequestCredentials } from './request-credentials';\nimport { HlsJsStreamTypeMixin } from './stream-type';\nimport { HlsJsTextTracksMixin, withPreservedTextTracks } from './text-tracks';\n\nconst defaultHlsConfig: Partial<HlsConfig> = {\n backBufferLength: 30,\n renderTextTracksNatively: false,\n liveDurationInfinity: true,\n // Runs hls.js's capping loop, which every rendition cap is evaluated on, not\n // only the one named after it. `capRenditionToPlayerSize` is the live switch.\n capLevelToPlayerSize: true,\n capLevelOnFPSDrop: true,\n autoStartLoad: false,\n};\n\nexport interface HlsJsOnlyMediaParams {\n /** Options forwarded to the hls.js constructor, merged over {@link defaultHlsConfig}. */\n config: Partial<HlsConfig>;\n}\n\nclass HlsJsOnlyAdapterCore extends HTMLVideoAdapter implements EngineAdapter<Hls, HTMLVideoElement> {\n #engine: Hls | null = null;\n #capPolicy: RenditionCapPolicy = {\n maxAutoResolution: undefined,\n capToPlayerSize: true,\n minAutoResolution: DEFAULT_MIN_AUTO_RESOLUTION,\n };\n\n constructor(params: HlsJsOnlyMediaParams) {\n super();\n const config = { ...defaultHlsConfig, ...params.config };\n\n this.#engine = new Hls({\n ...config,\n // Layered over whatever controller the config already names, so a\n // `capLevelController` passed through `source.engine` keeps working.\n capLevelController: createCapLevelController(this.#capPolicy, config.capLevelController),\n // Likewise layered over the config's own loader hooks: the element's\n // `crossorigin=\"use-credentials\"` sends cookies with every request.\n ...withRequestCredentials(config, () => this.target?.crossOrigin),\n });\n\n setupDrm(this.#engine);\n }\n\n get engine() {\n return this.#engine;\n }\n\n /** Ceiling on automatic rendition selection. See `HlsSource.maxAutoResolution`. */\n get maxAutoResolution(): MediaResolution | undefined {\n return this.#capPolicy.maxAutoResolution;\n }\n\n set maxAutoResolution(value: MediaResolution | undefined) {\n if (this.#capPolicy.maxAutoResolution === value) return;\n\n this.#capPolicy.maxAutoResolution = value;\n this.#capPolicy.controller?.apply();\n }\n\n /** Whether the rendered size caps selection. See `HlsSource.capRenditionToPlayerSize`. */\n get capRenditionToPlayerSize(): boolean {\n return this.#capPolicy.capToPlayerSize;\n }\n\n set capRenditionToPlayerSize(value: boolean | undefined) {\n // Defaults resolve here rather than in the caller, so the getters report the\n // cap that is actually in force instead of what a source happened to name.\n const next = value ?? true;\n if (this.#capPolicy.capToPlayerSize === next) return;\n\n this.#capPolicy.capToPlayerSize = next;\n this.#capPolicy.controller?.apply();\n }\n\n /** Floor on the player-size cap. See `HlsSource.minAutoResolution`. */\n get minAutoResolution(): MediaResolution {\n return this.#capPolicy.minAutoResolution ?? DEFAULT_MIN_AUTO_RESOLUTION;\n }\n\n set minAutoResolution(value: MediaResolution | undefined) {\n const next = value ?? DEFAULT_MIN_AUTO_RESOLUTION;\n if (this.#capPolicy.minAutoResolution === next) return;\n\n this.#capPolicy.minAutoResolution = next;\n this.#capPolicy.controller?.apply();\n }\n\n get src() {\n return this.#engine?.url ?? '';\n }\n\n set src(src: string) {\n // Attaching, detaching, and loading a source each reset every text track on\n // the element, sideloaded ones included. See `withPreservedTextTracks`.\n withPreservedTextTracks(this.target as HTMLVideoElement | null, () => this.#engine?.loadSource(src));\n }\n\n attach(target: HTMLVideoElement) {\n super.attach(target);\n withPreservedTextTracks(target, () => this.#engine?.attachMedia(target));\n }\n\n detach() {\n withPreservedTextTracks(this.target as HTMLVideoElement | null, () => this.#engine?.detachMedia());\n super.detach();\n }\n\n destroy() {\n this.detach();\n this.#engine?.destroy();\n this.#engine = null;\n }\n}\n\ninterface HlsJsMediaCapabilities\n extends MediaStreamTypeCapability, MediaLiveCapability, Pick<MediaSourceCapability, 'preload'> {\n readonly error: MediaError | null;\n}\n\nconst HlsJsOnlyAdapterComposed = HlsJsAirPlayMixin(\n HlsJsPreloadMixin(\n HlsJsLiveMixin(\n HlsJsStreamTypeMixin(\n HlsJsMediaTracksMixin(\n HlsJsChaptersMixin(\n HlsJsMetadataTracksMixin(HlsJsTextTracksMixin(HlsJsErrorsMixin(MediaTracksMixin(HlsJsOnlyAdapterCore))))\n )\n )\n )\n )\n )\n) as unknown as MixinReturn<WithMediaTracks<typeof HlsJsOnlyAdapterCore>, HlsJsMediaCapabilities>;\n\nexport class HlsJsOnlyAdapter extends HlsJsOnlyAdapterComposed {}\n"],"mappings":";;;;;;;;;;;;;;;;AA0BA,MAAM,mBAAuC;CAC3C,kBAAkB;CAClB,0BAA0B;CAC1B,sBAAsB;CAGtB,sBAAsB;CACtB,mBAAmB;CACnB,eAAe;AACjB;AAOA,IAAM,uBAAN,cAAmC,iBAAiE;CAClG,UAAsB;CACtB,aAAiC;EAC/B,mBAAmB,KAAA;EACnB,iBAAiB;EACjB,mBAAmB;CACrB;CAEA,YAAY,QAA8B;EACxC,MAAM;EACN,MAAM,SAAS;GAAE,GAAG;GAAkB,GAAG,OAAO;EAAO;EAEvD,KAAK,UAAU,IAAI,IAAI;GACrB,GAAG;GAGH,oBAAoB,yBAAyB,KAAK,YAAY,OAAO,kBAAkB;GAGvF,GAAG,uBAAuB,cAAc,KAAK,QAAQ,WAAW;EAClE,CAAC;EAED,SAAS,KAAK,OAAO;CACvB;CAEA,IAAI,SAAS;EACX,OAAO,KAAK;CACd;;CAGA,IAAI,oBAAiD;EACnD,OAAO,KAAK,WAAW;CACzB;CAEA,IAAI,kBAAkB,OAAoC;EACxD,IAAI,KAAK,WAAW,sBAAsB,OAAO;EAEjD,KAAK,WAAW,oBAAoB;EACpC,KAAK,WAAW,YAAY,MAAM;CACpC;;CAGA,IAAI,2BAAoC;EACtC,OAAO,KAAK,WAAW;CACzB;CAEA,IAAI,yBAAyB,OAA4B;EAGvD,MAAM,OAAO,SAAS;EACtB,IAAI,KAAK,WAAW,oBAAoB,MAAM;EAE9C,KAAK,WAAW,kBAAkB;EAClC,KAAK,WAAW,YAAY,MAAM;CACpC;;CAGA,IAAI,oBAAqC;EACvC,OAAO,KAAK,WAAW,qBAAA;CACzB;CAEA,IAAI,kBAAkB,OAAoC;EACxD,MAAM,OAAO,SAAA;EACb,IAAI,KAAK,WAAW,sBAAsB,MAAM;EAEhD,KAAK,WAAW,oBAAoB;EACpC,KAAK,WAAW,YAAY,MAAM;CACpC;CAEA,IAAI,MAAM;EACR,OAAO,KAAK,SAAS,OAAO;CAC9B;CAEA,IAAI,IAAI,KAAa;EAGnB,wBAAwB,KAAK,cAAyC,KAAK,SAAS,WAAW,GAAG,CAAC;CACrG;CAEA,OAAO,QAA0B;EAC/B,MAAM,OAAO,MAAM;EACnB,wBAAwB,cAAc,KAAK,SAAS,YAAY,MAAM,CAAC;CACzE;CAEA,SAAS;EACP,wBAAwB,KAAK,cAAyC,KAAK,SAAS,YAAY,CAAC;EACjG,MAAM,OAAO;CACf;CAEA,UAAU;EACR,KAAK,OAAO;EACZ,KAAK,SAAS,QAAQ;EACtB,KAAK,UAAU;CACjB;AACF;AAOA,MAAM,2BAA2B,kBAC/B,kBACE,eACE,qBACE,sBACE,mBACE,yBAAyB,qBAAqB,iBAAiB,iBAAiB,oBAAoB,CAAC,CAAC,CAAC,CACzG,CACF,CACF,CACF,CACF,CACF;AAEA,IAAa,mBAAb,cAAsC,yBAAyB,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
//#region src/request-credentials.ts
|
|
2
|
+
/** Whether the element's CORS-settings attribute asks for cookies on its resource fetches. */
|
|
3
|
+
function isCredentialed(crossOrigin) {
|
|
4
|
+
return crossOrigin?.toLowerCase() === "use-credentials";
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Layer the media element's `crossorigin` onto hls.js's loader hooks so `use-credentials` sends cookies with every
|
|
8
|
+
* manifest, playlist, and segment request, the way the browser does under native playback.
|
|
9
|
+
*
|
|
10
|
+
* Both hooks are covered because hls.js picks one loader per configuration: `xhrSetup` for the default `XhrLoader`
|
|
11
|
+
* (`withCredentials`), `fetchSetup` for `FetchLoader` (`credentials: 'include'`). A hook the config already names runs
|
|
12
|
+
* after ours, on the same request, so a consumer's own setup keeps working and can still override the mode. Anything
|
|
13
|
+
* but `use-credentials` — `anonymous`, an empty value, no attribute — leaves hls.js's default (`same-origin`).
|
|
14
|
+
*
|
|
15
|
+
* The attribute is read per request rather than at construction: the engine exists before the element is attached, and
|
|
16
|
+
* an author can change the attribute afterwards.
|
|
17
|
+
*/
|
|
18
|
+
function withRequestCredentials(config, crossOrigin) {
|
|
19
|
+
const { xhrSetup, fetchSetup } = config;
|
|
20
|
+
return {
|
|
21
|
+
async xhrSetup(xhr, url) {
|
|
22
|
+
if (isCredentialed(crossOrigin())) xhr.withCredentials = true;
|
|
23
|
+
await xhrSetup?.(xhr, url);
|
|
24
|
+
},
|
|
25
|
+
fetchSetup(context, initParams) {
|
|
26
|
+
if (isCredentialed(crossOrigin())) initParams.credentials = "include";
|
|
27
|
+
return fetchSetup ? fetchSetup(context, initParams) : new Request(context.url, initParams);
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
//#endregion
|
|
32
|
+
export { isCredentialed, withRequestCredentials };
|
|
33
|
+
|
|
34
|
+
//# sourceMappingURL=request-credentials.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"request-credentials.js","names":[],"sources":["../../src/request-credentials.ts"],"sourcesContent":["import type { HlsConfig } from 'hls.js';\n\n/** The media element's `crossOrigin`, read at request time — hls.js is built before the element is attached. */\nexport type CrossOriginSource = () => string | null | undefined;\n\n/** Whether the element's CORS-settings attribute asks for cookies on its resource fetches. */\nexport function isCredentialed(crossOrigin: string | null | undefined): boolean {\n return crossOrigin?.toLowerCase() === 'use-credentials';\n}\n\n/**\n * Layer the media element's `crossorigin` onto hls.js's loader hooks so `use-credentials` sends cookies with every\n * manifest, playlist, and segment request, the way the browser does under native playback.\n *\n * Both hooks are covered because hls.js picks one loader per configuration: `xhrSetup` for the default `XhrLoader`\n * (`withCredentials`), `fetchSetup` for `FetchLoader` (`credentials: 'include'`). A hook the config already names runs\n * after ours, on the same request, so a consumer's own setup keeps working and can still override the mode. Anything\n * but `use-credentials` — `anonymous`, an empty value, no attribute — leaves hls.js's default (`same-origin`).\n *\n * The attribute is read per request rather than at construction: the engine exists before the element is attached, and\n * an author can change the attribute afterwards.\n */\nexport function withRequestCredentials(\n config: Partial<HlsConfig>,\n crossOrigin: CrossOriginSource\n): Pick<HlsConfig, 'xhrSetup' | 'fetchSetup'> {\n const { xhrSetup, fetchSetup } = config;\n\n return {\n async xhrSetup(xhr, url) {\n if (isCredentialed(crossOrigin())) xhr.withCredentials = true;\n\n await xhrSetup?.(xhr, url);\n },\n fetchSetup(context, initParams) {\n if (isCredentialed(crossOrigin())) initParams.credentials = 'include';\n\n return fetchSetup ? fetchSetup(context, initParams) : new Request(context.url, initParams);\n },\n };\n}\n"],"mappings":";;AAMA,SAAgB,eAAe,aAAiD;CAC9E,OAAO,aAAa,YAAY,MAAM;AACxC;;;;;;;;;;;;;AAcA,SAAgB,uBACd,QACA,aAC4C;CAC5C,MAAM,EAAE,UAAU,eAAe;CAEjC,OAAO;EACL,MAAM,SAAS,KAAK,KAAK;GACvB,IAAI,eAAe,YAAY,CAAC,GAAG,IAAI,kBAAkB;GAEzD,MAAM,WAAW,KAAK,GAAG;EAC3B;EACA,WAAW,SAAS,YAAY;GAC9B,IAAI,eAAe,YAAY,CAAC,GAAG,WAAW,cAAc;GAE5D,OAAO,aAAa,WAAW,SAAS,UAAU,IAAI,IAAI,QAAQ,QAAQ,KAAK,UAAU;EAC3F;CACF;AACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@videojs/hlsjs-video",
|
|
3
|
-
"version": "10.0
|
|
3
|
+
"version": "10.1.0",
|
|
4
4
|
"description": "hls.js playback adapter for Video.js",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"hls",
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"license": "Apache-2.0",
|
|
14
14
|
"repository": {
|
|
15
15
|
"type": "git",
|
|
16
|
-
"url": "https://github.com/videojs/
|
|
16
|
+
"url": "https://github.com/videojs/video.js",
|
|
17
17
|
"directory": "packages/adapters/hlsjs-video"
|
|
18
18
|
},
|
|
19
19
|
"files": [
|
|
@@ -35,10 +35,11 @@
|
|
|
35
35
|
"access": "public"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@videojs/media": "10.0
|
|
39
|
-
"@videojs/native-hls-video": "10.0
|
|
40
|
-
"@videojs/
|
|
41
|
-
"
|
|
38
|
+
"@videojs/media": "10.1.0",
|
|
39
|
+
"@videojs/native-hls-video": "10.1.0",
|
|
40
|
+
"@videojs/spf": "10.1.0",
|
|
41
|
+
"@videojs/utils": "10.1.0",
|
|
42
|
+
"hls.js": "1.6.19"
|
|
42
43
|
},
|
|
43
44
|
"devDependencies": {
|
|
44
45
|
"jsdom": "^26.1.0",
|