@videojs/hlsjs-video 10.0.0-rc.1

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.
Files changed (56) hide show
  1. package/LICENSE +20 -0
  2. package/README.md +36 -0
  3. package/dist/default/adapter.js +289 -0
  4. package/dist/default/adapter.js.map +1 -0
  5. package/dist/default/airplay-bridge.js +76 -0
  6. package/dist/default/airplay-bridge.js.map +1 -0
  7. package/dist/default/cap-level.js +191 -0
  8. package/dist/default/cap-level.js.map +1 -0
  9. package/dist/default/drm.js +46 -0
  10. package/dist/default/drm.js.map +1 -0
  11. package/dist/default/errors.js +58 -0
  12. package/dist/default/errors.js.map +1 -0
  13. package/dist/default/hls-js-only.js +99 -0
  14. package/dist/default/hls-js-only.js.map +1 -0
  15. package/dist/default/index.js +3 -0
  16. package/dist/default/live.js +124 -0
  17. package/dist/default/live.js.map +1 -0
  18. package/dist/default/media-tracks.js +123 -0
  19. package/dist/default/media-tracks.js.map +1 -0
  20. package/dist/default/metadata-tracks.js +40 -0
  21. package/dist/default/metadata-tracks.js.map +1 -0
  22. package/dist/default/preload.js +91 -0
  23. package/dist/default/preload.js.map +1 -0
  24. package/dist/default/stream-type.js +43 -0
  25. package/dist/default/stream-type.js.map +1 -0
  26. package/dist/default/text-tracks.js +162 -0
  27. package/dist/default/text-tracks.js.map +1 -0
  28. package/dist/dev/adapter.d.ts +188 -0
  29. package/dist/dev/adapter.d.ts.map +1 -0
  30. package/dist/dev/adapter.js +305 -0
  31. package/dist/dev/adapter.js.map +1 -0
  32. package/dist/dev/airplay-bridge.js +76 -0
  33. package/dist/dev/airplay-bridge.js.map +1 -0
  34. package/dist/dev/cap-level.js +191 -0
  35. package/dist/dev/cap-level.js.map +1 -0
  36. package/dist/dev/drm.js +50 -0
  37. package/dist/dev/drm.js.map +1 -0
  38. package/dist/dev/errors.js +58 -0
  39. package/dist/dev/errors.js.map +1 -0
  40. package/dist/dev/hls-js-only.js +99 -0
  41. package/dist/dev/hls-js-only.js.map +1 -0
  42. package/dist/dev/index.d.ts +3 -0
  43. package/dist/dev/index.js +3 -0
  44. package/dist/dev/live.js +124 -0
  45. package/dist/dev/live.js.map +1 -0
  46. package/dist/dev/media-tracks.js +123 -0
  47. package/dist/dev/media-tracks.js.map +1 -0
  48. package/dist/dev/metadata-tracks.js +40 -0
  49. package/dist/dev/metadata-tracks.js.map +1 -0
  50. package/dist/dev/preload.js +91 -0
  51. package/dist/dev/preload.js.map +1 -0
  52. package/dist/dev/stream-type.js +43 -0
  53. package/dist/dev/stream-type.js.map +1 -0
  54. package/dist/dev/text-tracks.js +162 -0
  55. package/dist/dev/text-tracks.js.map +1 -0
  56. package/package.json +54 -0
package/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2025-present Video.js contributors
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
14
+
15
+ ------------------------------------------------------------------
16
+
17
+ Trademark Notice:
18
+ “Video.js” is a registered trademark of Brightcove Inc.
19
+ The project is maintained independently by the open-source community,
20
+ governed by the Video.js Technical Steering Committee.
package/README.md ADDED
@@ -0,0 +1,36 @@
1
+ # @videojs/hlsjs-video
2
+
3
+ The Video.js playback adapter for [hls.js](https://github.com/video-dev/hls.js). It owns the supported hls.js runtime,
4
+ browser playback implementation, and compatibility tests. `@videojs/mux-video` builds on it.
5
+
6
+ ## Installation
7
+
8
+ Install the adapter with the framework façade your player uses:
9
+
10
+ ```bash
11
+ pnpm add @videojs/html @videojs/hlsjs-video
12
+ # or
13
+ pnpm add @videojs/react @videojs/hlsjs-video
14
+ ```
15
+
16
+ ## Usage
17
+
18
+ Use the HTML or React façade for normal player integration:
19
+
20
+ ```ts
21
+ import '@videojs/html/media/hlsjs-video';
22
+ ```
23
+
24
+ ```tsx
25
+ import { HlsJsVideo } from '@videojs/react/media/hlsjs-video';
26
+ ```
27
+
28
+ Low-level consumers can import the Media and supported hls.js class directly:
29
+
30
+ ```ts
31
+ import { Hls, HlsJsAdapter } from '@videojs/hlsjs-video';
32
+ ```
33
+
34
+ ## License
35
+
36
+ [Apache-2.0](../../LICENSE)
@@ -0,0 +1,289 @@
1
+ import { HlsJsOnlyAdapter } from "./hls-js-only.js";
2
+ import { MediaStreamTypes, bridgeEvents } from "@videojs/media";
3
+ import { HTMLVideoAdapter } from "@videojs/media/dom";
4
+ import { NativeHlsAdapter } from "@videojs/native-hls-video";
5
+ import { deepEqual } from "@videojs/utils/object";
6
+ import Hls$1 from "hls.js";
7
+ //#region src/adapter.ts
8
+ const PlaybackTypes = {
9
+ MSE: "mse",
10
+ NATIVE: "native"
11
+ };
12
+ const ContentTypes = {
13
+ M3U8: "application/vnd.apple.mpegurl",
14
+ MP4: "video/mp4"
15
+ };
16
+ const StreamTypes = MediaStreamTypes;
17
+ var HlsMediaEvent = class extends Event {};
18
+ /**
19
+ * @fires sourcechange - Fired when `source` changes, either directly or by resolving a new `src`. Read `source` for the
20
+ * new value.
21
+ * @fires streamtypechange - Fired when the detected stream type changes. Read `streamType` for the new value.
22
+ * @fires targetlivewindowchange - Fired when the target live window changes. Read `targetLiveWindow` for the new value.
23
+ */
24
+ var HlsJsAdapter = class HlsJsAdapter extends HTMLVideoAdapter {
25
+ static {
26
+ this.defaultProps = {
27
+ src: "",
28
+ source: null,
29
+ preload: "metadata",
30
+ streamType: MediaStreamTypes.UNKNOWN,
31
+ disableRemotePlayback: false
32
+ };
33
+ }
34
+ #delegate = null;
35
+ #mediaElement = null;
36
+ #src = HlsJsAdapter.defaultProps.src;
37
+ #source = HlsJsAdapter.defaultProps.source;
38
+ #preload = HlsJsAdapter.defaultProps.preload;
39
+ #streamType = HlsJsAdapter.defaultProps.streamType;
40
+ #isUserStreamType = false;
41
+ #loadRequested;
42
+ #prevEngineConfigKey;
43
+ /**
44
+ * The author's `disableRemotePlayback`, not the element's current value. Tracked because engines (hls.js or SPF) may
45
+ * alter the value internally. Cached here for cases where this value is set before the delegate is created so it can
46
+ * later be forwarded.
47
+ */
48
+ #authorDisableRemotePlayback;
49
+ constructor() {
50
+ super();
51
+ this.addEventListener("loadstart", this.#stopTargetLoadStartEvent);
52
+ }
53
+ attach(target) {
54
+ this.#mediaElement = target;
55
+ super.attach(target);
56
+ this.#delegate?.attach(target);
57
+ }
58
+ detach() {
59
+ this.#delegate?.detach();
60
+ super.detach();
61
+ this.#mediaElement = null;
62
+ }
63
+ destroy() {
64
+ this.detach();
65
+ this.#engineDestroy();
66
+ super.destroy();
67
+ this.removeEventListener("loadstart", this.#stopTargetLoadStartEvent);
68
+ }
69
+ /**
70
+ * Underlying playback engine — the hls.js `Hls` instance when playing via MSE, otherwise `null`. An advanced escape
71
+ * hatch for direct engine access; normal playback is driven through this element's own properties and methods.
72
+ */
73
+ get engine() {
74
+ return this.#delegate?.engine ?? null;
75
+ }
76
+ get error() {
77
+ return this.#delegate?.error ?? null;
78
+ }
79
+ /** Populated only while the hls.js (MSE) engine is active; otherwise `undefined`. */
80
+ get videoTracks() {
81
+ return this.#delegate instanceof HlsJsOnlyAdapter ? this.#delegate.videoTracks : void 0;
82
+ }
83
+ /** Populated only while the hls.js (MSE) engine is active; otherwise `undefined`. */
84
+ get audioTracks() {
85
+ return this.#delegate instanceof HlsJsOnlyAdapter ? this.#delegate.audioTracks : void 0;
86
+ }
87
+ /** Selectable quality levels, populated only while the hls.js (MSE) engine is active; otherwise `undefined`. */
88
+ get videoRenditions() {
89
+ return this.#delegate instanceof HlsJsOnlyAdapter ? this.#delegate.videoRenditions : void 0;
90
+ }
91
+ /** Selectable audio variants, populated only while the hls.js (MSE) engine is active; otherwise `undefined`. */
92
+ get audioRenditions() {
93
+ return this.#delegate instanceof HlsJsOnlyAdapter ? this.#delegate.audioRenditions : void 0;
94
+ }
95
+ /**
96
+ * Media source URL. Assigning it replaces the identity half of `source` and leaves `type` and the engine options
97
+ * intact, so changing the URL never disturbs engine configuration.
98
+ */
99
+ get src() {
100
+ return this.#src;
101
+ }
102
+ set src(src) {
103
+ const { type, preferPlayback, drm, engine, maxAutoResolution, capRenditionToPlayerSize, minAutoResolution } = this.#source ?? {};
104
+ const next = {
105
+ ...type && { type },
106
+ ...preferPlayback && { preferPlayback },
107
+ ...drm && { drm },
108
+ ...engine && { engine },
109
+ ...maxAutoResolution && { maxAutoResolution },
110
+ ...capRenditionToPlayerSize !== void 0 && { capRenditionToPlayerSize },
111
+ ...minAutoResolution && { minAutoResolution },
112
+ ...src && { src }
113
+ };
114
+ this.source = Object.keys(next).length > 0 ? next : null;
115
+ }
116
+ /**
117
+ * Structured source: what to play (`src`, an optional `type`) plus how to play it (`preferPlayback`, `engine`).
118
+ * Assigning it derives `src`.
119
+ *
120
+ * Sources are compared structurally, so reassigning an equivalent object — an inline React prop, for instance — is a
121
+ * no-op. Only a change to the engine options (or to the resolved content type) recreates the playback engine.
122
+ */
123
+ get source() {
124
+ return this.#source;
125
+ }
126
+ set source(value) {
127
+ const source = value ?? null;
128
+ if (source === this.#source) return;
129
+ const src = source?.src ?? "";
130
+ const srcChanged = this.#src !== src;
131
+ this.#source = source;
132
+ this.#src = src;
133
+ this.#applyRenditionCaps();
134
+ this.dispatchEvent(new Event("sourcechange"));
135
+ if (srcChanged || this.#shouldEngineUpdate(this.#engineConfigKey())) this.#requestLoad();
136
+ }
137
+ /** Preload type (`'none'` / `'metadata'` / `'auto'`). */
138
+ get preload() {
139
+ return this.#preload;
140
+ }
141
+ set preload(value) {
142
+ this.#preload = value;
143
+ if (this.#delegate) this.#delegate.preload = value;
144
+ }
145
+ /** Whether remote playback (AirPlay, Google Cast) is disabled for this media. */
146
+ get disableRemotePlayback() {
147
+ return super.disableRemotePlayback;
148
+ }
149
+ set disableRemotePlayback(value) {
150
+ this.#authorDisableRemotePlayback = value;
151
+ super.disableRemotePlayback = value;
152
+ if (this.#delegate instanceof HlsJsOnlyAdapter) this.#delegate.disableRemotePlayback = value;
153
+ }
154
+ /** Current stream type (`'on-demand'` / `'live'` / `'unknown'`). */
155
+ get streamType() {
156
+ return this.#delegate?.streamType ?? this.#streamType;
157
+ }
158
+ set streamType(value) {
159
+ this.#isUserStreamType = value !== StreamTypes.UNKNOWN;
160
+ if (this.#delegate) {
161
+ this.#delegate.streamType = value;
162
+ this.#streamType = this.#delegate.streamType;
163
+ return;
164
+ }
165
+ if (this.#streamType === value) return;
166
+ this.#streamType = value;
167
+ this.dispatchEvent(new HlsMediaEvent("streamtypechange"));
168
+ }
169
+ /**
170
+ * Presentation time marking the start of the Live Edge Window.
171
+ *
172
+ * Derived from the delegate on every read; `NaN` when no delegate is attached or the stream is not live.
173
+ */
174
+ get liveEdgeStart() {
175
+ return this.#delegate?.liveEdgeStart ?? NaN;
176
+ }
177
+ /**
178
+ * Seekable range size for live content. `0` for standard live, `Infinity` for DVR, `NaN` for on-demand or unknown.
179
+ * Fires `targetlivewindowchange` when the value changes (bridged from the delegate).
180
+ */
181
+ get targetLiveWindow() {
182
+ return this.#delegate?.targetLiveWindow ?? NaN;
183
+ }
184
+ async load() {
185
+ this.#loadRequested = null;
186
+ if (this.remote.state === "connected") {
187
+ this.dispatchEvent(new HlsMediaEvent("loadstart"));
188
+ return super.load();
189
+ }
190
+ if (this.#shouldEngineUpdate(this.#engineConfigKey())) {
191
+ this.#engineDestroy();
192
+ this.#prevEngineConfigKey = this.#engineConfigKey();
193
+ const { type, preferPlayback, drm, engine, maxAutoResolution, capRenditionToPlayerSize, minAutoResolution } = this.#source ?? {};
194
+ const { hlsJs, nativeHls } = engine ?? {};
195
+ const contentType = type ?? inferContentType(this.src);
196
+ const useMse = Hls$1.isSupported() && contentType === ContentTypes.M3U8 && preferPlayback !== PlaybackTypes.NATIVE;
197
+ this.#delegate = useMse ? new HlsJsOnlyAdapter({ config: withDrmSystems(hlsJs, drm) }) : this.#createNativeDelegate(drm, nativeHls, hlsJs);
198
+ bridgeEvents(this.#delegate, this);
199
+ if (this.#isUserStreamType) this.#delegate.streamType = this.#streamType;
200
+ this.#delegate.preload = this.preload;
201
+ this.#applyRenditionCaps();
202
+ if (this.#authorDisableRemotePlayback !== void 0 && this.#delegate instanceof HlsJsOnlyAdapter) this.#delegate.disableRemotePlayback = this.#authorDisableRemotePlayback;
203
+ if (this.#mediaElement) this.#delegate.attach(this.#mediaElement);
204
+ }
205
+ if (this.#delegate) {
206
+ this.dispatchEvent(new HlsMediaEvent("loadstart"));
207
+ this.#delegate.src = this.src;
208
+ }
209
+ }
210
+ /**
211
+ * A native delegate carrying the native half of the source — the DRM configuration and the native engine options,
212
+ * which it applies the same precedence to. Its `src` is assigned separately, once the delegate is wired up, and
213
+ * carries what is set here forward.
214
+ */
215
+ #createNativeDelegate(drm, nativeHls, hlsJs) {
216
+ const media = new NativeHlsAdapter();
217
+ const source = {
218
+ ...drm && { drm },
219
+ ...nativeHls && { engine: { nativeHls } }
220
+ };
221
+ if (Object.keys(source).length > 0) media.source = source;
222
+ return media;
223
+ }
224
+ /** Push the source's rendition caps down; only the hls.js engine has a lever. */
225
+ #applyRenditionCaps() {
226
+ if (this.#delegate instanceof HlsJsOnlyAdapter) {
227
+ this.#delegate.maxAutoResolution = this.#source?.maxAutoResolution;
228
+ this.#delegate.capRenditionToPlayerSize = this.#source?.capRenditionToPlayerSize;
229
+ this.#delegate.minAutoResolution = this.#source?.minAutoResolution;
230
+ }
231
+ }
232
+ #stopTargetLoadStartEvent = (event) => {
233
+ if (!(event instanceof HlsMediaEvent)) event.stopImmediatePropagation();
234
+ };
235
+ async #requestLoad() {
236
+ if (this.#loadRequested) return;
237
+ await (this.#loadRequested = Promise.resolve());
238
+ this.#loadRequested = null;
239
+ this.load();
240
+ }
241
+ #shouldEngineUpdate(nextEngineConfigKey) {
242
+ return !deepEqual(this.#prevEngineConfigKey, nextEngineConfigKey);
243
+ }
244
+ /**
245
+ * Every value the engine is constructed from. Compared structurally, so equivalent engine options never trigger a
246
+ * rebuild — including nested ones like `drmSystems`, which a flat comparison would see as changed whenever the object
247
+ * identity did.
248
+ */
249
+ #engineConfigKey() {
250
+ const { type, preferPlayback, drm, engine } = this.#source ?? {};
251
+ return {
252
+ drm,
253
+ engine,
254
+ preferPlayback,
255
+ contentType: type ?? inferContentType(this.src)
256
+ };
257
+ }
258
+ #engineDestroy() {
259
+ this.#delegate?.destroy();
260
+ this.#delegate = null;
261
+ this.#prevEngineConfigKey = null;
262
+ this.#loadRequested = null;
263
+ if (!this.#isUserStreamType) this.#streamType = StreamTypes.UNKNOWN;
264
+ }
265
+ };
266
+ /**
267
+ * Hls.js configuration with the source's DRM licensing folded in. hls.js takes `drmSystems` in the same shape as
268
+ * `source.drm`, so the standardized config is what it plays from unless `engine.hlsJs` names servers of its own.
269
+ *
270
+ * Hls.js runs key exchange only while `emeEnabled` is set, so configured DRM switches it on — short of an explicit
271
+ * `emeEnabled: false`, which stays a way to describe a source's licensing without acting on it.
272
+ */
273
+ function withDrmSystems(hlsJs, drm) {
274
+ const drmSystems = hlsJs?.drmSystems ?? drm;
275
+ if (!drmSystems || Object.keys(drmSystems).length === 0) return { ...hlsJs };
276
+ return {
277
+ emeEnabled: true,
278
+ ...hlsJs,
279
+ drmSystems
280
+ };
281
+ }
282
+ function inferContentType(src) {
283
+ if ((src.split(/[?#]/)[0] ?? "").endsWith(".mp4")) return ContentTypes.MP4;
284
+ return ContentTypes.M3U8;
285
+ }
286
+ //#endregion
287
+ export { ContentTypes, Hls$1 as Hls, HlsJsAdapter, PlaybackTypes, StreamTypes };
288
+
289
+ //# sourceMappingURL=adapter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"adapter.js","names":["#stopTargetLoadStartEvent","#mediaElement","#delegate","#engineDestroy","#src","#source","#applyRenditionCaps","#shouldEngineUpdate","#engineConfigKey","#requestLoad","#preload","#authorDisableRemotePlayback","#streamType","#isUserStreamType","#loadRequested","#prevEngineConfigKey","Hls","#createNativeDelegate"],"sources":["../../src/adapter.ts"],"sourcesContent":["import {\n bridgeEvents,\n type DrmSystemsConfig,\n KeySystems,\n type MediaResolution,\n type MediaStreamType,\n MediaStreamTypes,\n} from '@videojs/media';\nimport { HTMLVideoAdapter } from '@videojs/media/dom';\nimport { type NativeHlsConfig, NativeHlsAdapter, type NativeHlsSource } from '@videojs/native-hls-video';\nimport { deepEqual } from '@videojs/utils/object';\nimport Hls, { type HlsConfig as HlsJsConfig } from 'hls.js';\n\nimport { HlsJsOnlyAdapter } from './hls-js-only';\n\nexport type PreloadType = '' | 'none' | 'metadata' | 'auto';\n\nexport type { MediaResolution };\n\nexport { Hls };\n\nexport type PlaybackType = (typeof PlaybackTypes)[keyof typeof PlaybackTypes];\nexport type SourceType = (typeof ContentTypes)[keyof typeof ContentTypes];\nexport type StreamType = MediaStreamType;\n\nexport const PlaybackTypes = {\n MSE: 'mse',\n NATIVE: 'native',\n};\n\nexport const ContentTypes = {\n M3U8: 'application/vnd.apple.mpegurl',\n MP4: 'video/mp4',\n};\n\nexport const StreamTypes = MediaStreamTypes;\n\nexport interface HlsJsAdapterProps {\n src: string;\n source: HlsSource | null;\n preload: PreloadType;\n streamType: StreamType;\n disableRemotePlayback: boolean;\n}\n\n/**\n * Structured HLS source: which source to play, plus how to play it.\n *\n * Playback options are namespaced by engine. There are two paths here — hls.js and the browser's own HLS support — and\n * only one of them runs, so a source describes both without either engine reading the other's options.\n *\n * `preferPlayback` and the engine options are all read when the engine is constructed, so changing any of them\n * recreates it.\n */\nexport interface HlsSource {\n /** Manifest URL. Mirrors the host's `src` property. */\n src?: string | undefined;\n /** MIME type of the source. Takes precedence over inference from `src`. */\n type?: SourceType | undefined;\n /**\n * Preferred playback path: `'mse'` for hls.js, `'native'` for the browser's own HLS support. Ignored when the\n * preferred path cannot play the source.\n */\n preferPlayback?: PlaybackType | undefined;\n /**\n * License servers for protected content, keyed by EME key system id.\n *\n * Engine neutral, because which engine plays is decided later: hls.js is handed every system named here (with EME\n * switched on), and native playback negotiates the `com.apple.fps` entry itself. Name every system you hold a license\n * server for — which one is used is the browser's choice.\n */\n drm?: DrmSystemsConfig | undefined;\n /**\n * Highest resolution adaptive bitrate selection may choose on its own.\n *\n * A ceiling on automatic selection, not a filter on what is available: renditions above it stay in `videoRenditions`\n * and can still be selected by hand. Matching is by pixel area, so a `'720p'` cap admits any rendition at or below\n * 1280×720 worth of pixels. When every rendition sits above the cap, the smallest one is used.\n *\n * Applied live — changing it never rebuilds the playback engine. Requires the hls.js (MSE) engine; native HLS\n * playback ignores it.\n *\n * For Mux sources this is distinct from `playback.maxResolution`, which asks Mux to leave higher renditions out of\n * the manifest altogether.\n */\n maxAutoResolution?: MediaResolution | undefined;\n /**\n * Whether the element's rendered size caps automatic selection. Defaults to `true`.\n *\n * A 400px-wide player has no use for a 4K rendition, so selection is held to the smallest rendition that still covers\n * the element, measured in device pixels — a `2` device pixel ratio asks for twice what a CSS measurement would. The\n * cap follows the element as it resizes, and `minAutoResolution` bounds how far down it can go. Set it to `false` for\n * a player whose layout size understates what it needs, such as one that goes fullscreen without a resize.\n *\n * Which rendition covers the element is hls.js's own judgement, weighed on the largest dimension rather than pixel\n * area, so it can land elsewhere than `maxAutoResolution` would for the same ladder.\n *\n * Applied live — changing it never rebuilds the playback engine. Requires the hls.js (MSE) engine; native HLS\n * playback ignores it. Setting hls.js's own `capLevelToPlayerSize` through `source.engine.hlsJs` is a different\n * thing: it stops the loop _every_ cap here is evaluated on, and takes a rebuild.\n */\n capRenditionToPlayerSize?: boolean | undefined;\n /**\n * Lowest resolution `capRenditionToPlayerSize` may cap down to. Defaults to `'720p'`.\n *\n * Not a quality floor. It bounds the size-derived cap and nothing else: when bandwidth is poor, adaptive selection\n * still drops below it, because the cap is a ceiling and selection stays free underneath. Nor does it raise an\n * explicit `maxAutoResolution` — asking for at most `'360p'` alongside a `'720p'` floor yields `'360p'`.\n *\n * The default exists because the low rungs of a ladder are there for poor network conditions, and capping a small\n * player to them looks worse than its size suggests. Name a lower rung to weaken the floor, or `'270p'` to lift it\n * for any real ladder.\n *\n * Applied live — changing it never rebuilds the playback engine. Requires the hls.js (MSE) engine; native HLS\n * playback ignores it.\n */\n minAutoResolution?: MediaResolution | undefined;\n /**\n * Playback options, keyed by the engine that reads them. Only one of the two engines below ends up playing, and each\n * reads only its own key.\n */\n engine?: HlsEngineConfig | undefined;\n}\n\n/** The engines an HLS source can configure. */\nexport interface HlsEngineConfig {\n /**\n * Hls.js's own configuration, passed through untouched. A `drmSystems` of its own replaces `source.drm` for hls.js —\n * an escape hatch for licensing MSE playback differently, or for the parts of hls.js's DRM configuration `source.drm`\n * does not cover.\n */\n hlsJs?: Partial<HlsJsConfig> | undefined;\n /**\n * Options for the browser's own HLS playback, used whenever the native path is the one taken. Its `drmSystems`\n * replaces `source.drm` for that path in the same way.\n */\n nativeHls?: NativeHlsConfig | undefined;\n}\n\nclass HlsMediaEvent extends Event {}\n\n/**\n * @fires sourcechange - Fired when `source` changes, either directly or by resolving a new `src`. Read `source` for the\n * new value.\n * @fires streamtypechange - Fired when the detected stream type changes. Read `streamType` for the new value.\n * @fires targetlivewindowchange - Fired when the target live window changes. Read `targetLiveWindow` for the new value.\n */\nexport class HlsJsAdapter extends HTMLVideoAdapter implements HlsJsAdapterProps {\n static readonly defaultProps: HlsJsAdapterProps = {\n src: '',\n source: null,\n preload: 'metadata',\n streamType: MediaStreamTypes.UNKNOWN,\n disableRemotePlayback: false,\n };\n\n #delegate: HlsJsOnlyAdapter | NativeHlsAdapter | null = null;\n #mediaElement: HTMLVideoElement | null = null;\n #src = HlsJsAdapter.defaultProps.src;\n #source: HlsSource | null = HlsJsAdapter.defaultProps.source;\n #preload = HlsJsAdapter.defaultProps.preload;\n #streamType: StreamType = HlsJsAdapter.defaultProps.streamType;\n #isUserStreamType = false;\n #loadRequested?: Promise<void> | null;\n #prevEngineConfigKey?: Record<string, any> | null;\n /**\n * The author's `disableRemotePlayback`, not the element's current value. Tracked because engines (hls.js or SPF) may\n * alter the value internally. Cached here for cases where this value is set before the delegate is created so it can\n * later be forwarded.\n */\n #authorDisableRemotePlayback?: boolean;\n\n constructor() {\n super();\n // Cancel the native loadstart event, it's handled in the load method.\n this.addEventListener('loadstart', this.#stopTargetLoadStartEvent);\n }\n\n attach(target: HTMLVideoElement) {\n this.#mediaElement = target;\n super.attach(target);\n this.#delegate?.attach(target);\n }\n\n detach() {\n this.#delegate?.detach();\n super.detach();\n this.#mediaElement = null;\n }\n\n destroy() {\n this.detach();\n this.#engineDestroy();\n super.destroy();\n this.removeEventListener('loadstart', this.#stopTargetLoadStartEvent);\n }\n\n /**\n * Underlying playback engine — the hls.js `Hls` instance when playing via MSE, otherwise `null`. An advanced escape\n * hatch for direct engine access; normal playback is driven through this element's own properties and methods.\n */\n get engine() {\n return this.#delegate?.engine ?? null;\n }\n\n get error() {\n return this.#delegate?.error ?? null;\n }\n\n /** Populated only while the hls.js (MSE) engine is active; otherwise `undefined`. */\n get videoTracks() {\n return this.#delegate instanceof HlsJsOnlyAdapter ? this.#delegate.videoTracks : undefined;\n }\n\n /** Populated only while the hls.js (MSE) engine is active; otherwise `undefined`. */\n get audioTracks() {\n return this.#delegate instanceof HlsJsOnlyAdapter ? this.#delegate.audioTracks : undefined;\n }\n\n /** Selectable quality levels, populated only while the hls.js (MSE) engine is active; otherwise `undefined`. */\n get videoRenditions() {\n return this.#delegate instanceof HlsJsOnlyAdapter ? this.#delegate.videoRenditions : undefined;\n }\n\n /** Selectable audio variants, populated only while the hls.js (MSE) engine is active; otherwise `undefined`. */\n get audioRenditions() {\n return this.#delegate instanceof HlsJsOnlyAdapter ? this.#delegate.audioRenditions : undefined;\n }\n\n /**\n * Media source URL. Assigning it replaces the identity half of `source` and leaves `type` and the engine options\n * intact, so changing the URL never disturbs engine configuration.\n */\n get src() {\n return this.#src;\n }\n\n set src(src: string) {\n // `src` says which source to play; every other field says how to play it, so\n // they carry over.\n const { type, preferPlayback, drm, engine, maxAutoResolution, capRenditionToPlayerSize, minAutoResolution } =\n this.#source ?? {};\n const next: HlsSource = {\n ...(type && { type }),\n ...(preferPlayback && { preferPlayback }),\n ...(drm && { drm }),\n ...(engine && { engine }),\n ...(maxAutoResolution && { maxAutoResolution }),\n // Definedness, not truthiness: `false` is the value worth naming, and the\n // falsy one, so the neighbors' pattern would drop it.\n ...(capRenditionToPlayerSize !== undefined && { capRenditionToPlayerSize }),\n ...(minAutoResolution && { minAutoResolution }),\n ...(src && { src }),\n };\n\n // Everything happens in the `source` setter, so there is one path for storing\n // it, deciding on a load, and dispatching `sourcechange`.\n this.source = Object.keys(next).length > 0 ? next : null;\n }\n\n /**\n * Structured source: what to play (`src`, an optional `type`) plus how to play it (`preferPlayback`, `engine`).\n * Assigning it derives `src`.\n *\n * Sources are compared structurally, so reassigning an equivalent object — an inline React prop, for instance — is a\n * no-op. Only a change to the engine options (or to the resolved content type) recreates the playback engine.\n */\n get source(): HlsSource | null {\n return this.#source;\n }\n\n set source(value: HlsSource | null) {\n const source = value ?? null;\n // Changing anything takes a new object, so handing the same one back costs\n // nothing.\n if (source === this.#source) return;\n\n const src = source?.src ?? '';\n const srcChanged = this.#src !== src;\n\n this.#source = source;\n this.#src = src;\n\n // Deliberately outside the engine config key below, so it reaches the engine\n // already running.\n this.#applyRenditionCaps();\n\n // Assigning is always a source change, so it is always announced.\n this.dispatchEvent(new Event('sourcechange'));\n\n // Only reload for something playback depends on. Subclasses add params that\n // describe images rather than the stream — Mux's `poster` and `storyboard` —\n // and changing one of those must not restart what is already playing.\n if (srcChanged || this.#shouldEngineUpdate(this.#engineConfigKey())) this.#requestLoad();\n }\n\n /** Preload type (`'none'` / `'metadata'` / `'auto'`). */\n get preload() {\n return this.#preload;\n }\n\n set preload(value) {\n this.#preload = value;\n\n if (this.#delegate) {\n this.#delegate.preload = value;\n }\n }\n\n /** Whether remote playback (AirPlay, Google Cast) is disabled for this media. */\n get disableRemotePlayback() {\n return super.disableRemotePlayback;\n }\n\n set disableRemotePlayback(value: boolean) {\n this.#authorDisableRemotePlayback = value;\n super.disableRemotePlayback = value;\n\n if (this.#delegate instanceof HlsJsOnlyAdapter) {\n this.#delegate.disableRemotePlayback = value;\n }\n }\n\n /** Current stream type (`'on-demand'` / `'live'` / `'unknown'`). */\n get streamType(): StreamType {\n return this.#delegate?.streamType ?? this.#streamType;\n }\n\n set streamType(value: StreamType) {\n this.#isUserStreamType = value !== StreamTypes.UNKNOWN;\n\n if (this.#delegate) {\n this.#delegate.streamType = value;\n this.#streamType = this.#delegate.streamType;\n return;\n }\n\n if (this.#streamType === value) return;\n\n this.#streamType = value;\n this.dispatchEvent(new HlsMediaEvent('streamtypechange'));\n }\n\n /**\n * Presentation time marking the start of the Live Edge Window.\n *\n * Derived from the delegate on every read; `NaN` when no delegate is attached or the stream is not live.\n */\n get liveEdgeStart() {\n return this.#delegate?.liveEdgeStart ?? Number.NaN;\n }\n\n /**\n * Seekable range size for live content. `0` for standard live, `Infinity` for DVR, `NaN` for on-demand or unknown.\n * Fires `targetlivewindowchange` when the value changes (bridged from the delegate).\n */\n get targetLiveWindow() {\n return this.#delegate?.targetLiveWindow ?? Number.NaN;\n }\n\n async load() {\n this.#loadRequested = null;\n\n if (this.remote.state === 'connected') {\n this.dispatchEvent(new HlsMediaEvent('loadstart'));\n return super.load();\n }\n\n if (this.#shouldEngineUpdate(this.#engineConfigKey())) {\n this.#engineDestroy();\n this.#prevEngineConfigKey = this.#engineConfigKey();\n\n // Read the stored source, not the `source` getter: subclasses override the\n // getter to return what was assigned to them, while the fields below come\n // from what they resolved and handed down (Mux fills in the DRM options).\n const { type, preferPlayback, drm, engine, maxAutoResolution, capRenditionToPlayerSize, minAutoResolution } =\n this.#source ?? {};\n const { hlsJs, nativeHls } = engine ?? {};\n const contentType = type ?? inferContentType(this.src);\n const useMse = Hls.isSupported() && contentType === ContentTypes.M3U8 && preferPlayback !== PlaybackTypes.NATIVE;\n\n if (__DEV__ && !useMse) {\n const ignored = Object.entries({ maxAutoResolution, capRenditionToPlayerSize, minAutoResolution })\n .filter(([, value]) => value !== undefined)\n .map(([key]) => `\\`${key}\\``);\n\n if (ignored.length > 0) {\n const [verb, pronoun] = ignored.length > 1 ? ['require', 'them'] : ['requires', 'it'];\n\n console.warn(\n `[vjs-media] ${ignored.join(', ')} ${verb} the hls.js (MSE) engine; native HLS playback ignores ${pronoun}.`\n );\n }\n }\n\n this.#delegate = useMse\n ? new HlsJsOnlyAdapter({ config: withDrmSystems(hlsJs, drm) })\n : this.#createNativeDelegate(drm, nativeHls, hlsJs);\n\n bridgeEvents(this.#delegate, this);\n\n // Apply user `streamType` before `attach()` so native delegates do not run\n // synchronous duration-based detection first and emit a transient value.\n if (this.#isUserStreamType) {\n this.#delegate.streamType = this.#streamType;\n }\n\n this.#delegate.preload = this.preload;\n this.#applyRenditionCaps();\n\n // Forward the author intent to the delegate, in case it was captured before it existed.\n if (this.#authorDisableRemotePlayback !== undefined && this.#delegate instanceof HlsJsOnlyAdapter) {\n this.#delegate.disableRemotePlayback = this.#authorDisableRemotePlayback;\n }\n\n if (this.#mediaElement) {\n this.#delegate.attach(this.#mediaElement);\n }\n }\n\n if (this.#delegate) {\n this.dispatchEvent(new HlsMediaEvent('loadstart'));\n this.#delegate.src = this.src;\n }\n }\n\n /**\n * A native delegate carrying the native half of the source — the DRM configuration and the native engine options,\n * which it applies the same precedence to. Its `src` is assigned separately, once the delegate is wired up, and\n * carries what is set here forward.\n */\n #createNativeDelegate(\n drm: DrmSystemsConfig | undefined,\n nativeHls: NativeHlsConfig | undefined,\n hlsJs: Partial<HlsJsConfig> | undefined\n ) {\n if (__DEV__) {\n // The delegate applies the same precedence, so the warning has to read — and\n // name — whatever it will end up licensing against. An escape hatch replaces\n // `source.drm` rather than adding to it, so pointing at the wrong one of the\n // two would send a reader looking in a field that is already correct.\n const drmSystems = nativeHls?.drmSystems ?? drm;\n const field = nativeHls?.drmSystems ? 'source.engine.nativeHls.drmSystems' : 'source.drm';\n const isProtected = hlsJs?.emeEnabled || hlsJs?.drmSystems || Object.keys(drmSystems ?? {}).length > 0;\n\n if (isProtected && !drmSystems?.[KeySystems.FAIRPLAY]) {\n console.warn(\n `[vjs-drm] Native HLS playback negotiates FairPlay itself and never sees the hls.js DRM configuration, and no \\`${KeySystems.FAIRPLAY}\\` license server is named in \\`${field}\\`. DRM-protected media will not play.`\n );\n }\n }\n\n const media = new NativeHlsAdapter();\n const source: NativeHlsSource = {\n ...(drm && { drm }),\n ...(nativeHls && { engine: { nativeHls } }),\n };\n\n if (Object.keys(source).length > 0) media.source = source;\n\n return media;\n }\n\n /** Push the source's rendition caps down; only the hls.js engine has a lever. */\n #applyRenditionCaps() {\n if (this.#delegate instanceof HlsJsOnlyAdapter) {\n this.#delegate.maxAutoResolution = this.#source?.maxAutoResolution;\n this.#delegate.capRenditionToPlayerSize = this.#source?.capRenditionToPlayerSize;\n this.#delegate.minAutoResolution = this.#source?.minAutoResolution;\n }\n }\n\n #stopTargetLoadStartEvent = (event: Event) => {\n if (!(event instanceof HlsMediaEvent)) event.stopImmediatePropagation();\n };\n\n async #requestLoad() {\n if (this.#loadRequested) return;\n\n await (this.#loadRequested = Promise.resolve());\n this.#loadRequested = null;\n this.load();\n }\n\n #shouldEngineUpdate(nextEngineConfigKey: Record<string, any>) {\n return !deepEqual(this.#prevEngineConfigKey, nextEngineConfigKey);\n }\n\n /**\n * Every value the engine is constructed from. Compared structurally, so equivalent engine options never trigger a\n * rebuild — including nested ones like `drmSystems`, which a flat comparison would see as changed whenever the object\n * identity did.\n */\n #engineConfigKey() {\n const { type, preferPlayback, drm, engine } = this.#source ?? {};\n\n return { drm, engine, preferPlayback, contentType: type ?? inferContentType(this.src) };\n }\n\n #engineDestroy() {\n this.#delegate?.destroy();\n this.#delegate = null;\n this.#prevEngineConfigKey = null;\n this.#loadRequested = null;\n\n // Delegate teardown already emits `streamtypechange` (bridged); only sync cache.\n if (!this.#isUserStreamType) this.#streamType = StreamTypes.UNKNOWN;\n }\n}\n\n/**\n * Hls.js configuration with the source's DRM licensing folded in. hls.js takes `drmSystems` in the same shape as\n * `source.drm`, so the standardized config is what it plays from unless `engine.hlsJs` names servers of its own.\n *\n * Hls.js runs key exchange only while `emeEnabled` is set, so configured DRM switches it on — short of an explicit\n * `emeEnabled: false`, which stays a way to describe a source's licensing without acting on it.\n */\nfunction withDrmSystems(\n hlsJs: Partial<HlsJsConfig> | undefined,\n drm: DrmSystemsConfig | undefined\n): Partial<HlsJsConfig> {\n const drmSystems = hlsJs?.drmSystems ?? drm;\n if (!drmSystems || Object.keys(drmSystems).length === 0) return { ...hlsJs };\n\n // hls.js declares `serverCertificateUrl` without `undefined`, which an\n // omittable property here is allowed to carry. The values are the same.\n return { emeEnabled: true, ...hlsJs, drmSystems: drmSystems as HlsJsConfig['drmSystems'] };\n}\n\nfunction inferContentType(src: string): SourceType {\n const path = src.split(/[?#]/)[0] ?? '';\n if (path.endsWith('.mp4')) return ContentTypes.MP4;\n\n return ContentTypes.M3U8;\n}\n"],"mappings":";;;;;;;AAyBA,MAAa,gBAAgB;CAC3B,KAAK;CACL,QAAQ;AACV;AAEA,MAAa,eAAe;CAC1B,MAAM;CACN,KAAK;AACP;AAEA,MAAa,cAAc;AAwG3B,IAAM,gBAAN,cAA4B,MAAM,CAAC;;;;;;;AAQnC,IAAa,eAAb,MAAa,qBAAqB,iBAA8C;;EAC5B,KAAA,eAAA;GAChD,KAAK;GACL,QAAQ;GACR,SAAS;GACT,YAAY,iBAAiB;GAC7B,uBAAuB;EACzB;;CAEA,YAAwD;CACxD,gBAAyC;CACzC,OAAO,aAAa,aAAa;CACjC,UAA4B,aAAa,aAAa;CACtD,WAAW,aAAa,aAAa;CACrC,cAA0B,aAAa,aAAa;CACpD,oBAAoB;CACpB;CACA;;;;;;CAMA;CAEA,cAAc;EACZ,MAAM;EAEN,KAAK,iBAAiB,aAAa,KAAKA,yBAAyB;CAC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;CAE/C,OAAO,aAAa;AACtB"}
@@ -0,0 +1,76 @@
1
+ import Hls from "hls.js";
2
+ import { isWebKitAirPlayCapable, listen } from "@videojs/utils/dom";
3
+ //#region src/airplay-bridge.ts
4
+ /**
5
+ * Adds an AirPlay-capable fallback `<source>` to the attached video element so Safari can hand the original HLS
6
+ * manifest off to AirPlay receivers while local playback continues through hls.js (MSE). When wireless-target changes,
7
+ * suspends hls.js loading so we don't double-fetch alongside the AirPlay receiver.
8
+ *
9
+ * Implements the WebKit-recommended pattern:
10
+ * https://webkit.org/blog/15036/how-to-use-media-source-extensions-with-airplay/
11
+ *
12
+ * No-op on non-WebKit platforms (Chromium, Firefox).
13
+ */
14
+ function HlsJsAirPlayMixin(BaseClass) {
15
+ class HlsJsAirPlay extends BaseClass {
16
+ #sourceEl = null;
17
+ #disconnect = null;
18
+ /**
19
+ * The author's `disableRemotePlayback`, not the element's current value. Tracked because engines (hls.js or SPF)
20
+ * may alter the value internally (forced on for ManagedMediaSource), so the element on its own cannot tell an
21
+ * opt-out apart from an MMS requirement.
22
+ */
23
+ #authorDisableRemotePlayback = false;
24
+ constructor(...args) {
25
+ super(...args);
26
+ this.engine?.on(Hls.Events.MEDIA_ATTACHED, () => this.#init());
27
+ this.engine?.on(Hls.Events.MEDIA_DETACHED, () => this.#destroy());
28
+ this.engine?.on(Hls.Events.DESTROYING, () => this.#destroy());
29
+ this.engine?.on(Hls.Events.MANIFEST_LOADING, (_event, data) => {
30
+ if (this.#sourceEl) this.#sourceEl.src = data.url;
31
+ });
32
+ }
33
+ get disableRemotePlayback() {
34
+ return super.disableRemotePlayback;
35
+ }
36
+ set disableRemotePlayback(value) {
37
+ const changed = value !== this.#authorDisableRemotePlayback;
38
+ this.#authorDisableRemotePlayback = value;
39
+ super.disableRemotePlayback = value;
40
+ if (changed && this.#sourceEl) this.#init();
41
+ }
42
+ #init() {
43
+ this.#destroy();
44
+ const target = this.target;
45
+ if (!target || !isWebKitAirPlayCapable(target)) return;
46
+ if (!this.#authorDisableRemotePlayback) target.disableRemotePlayback = false;
47
+ this.#attachSource(target);
48
+ this.#setupLoadControl(target);
49
+ }
50
+ #attachSource(target) {
51
+ this.#sourceEl = document.createElement("source");
52
+ this.#sourceEl.type = "application/x-mpegURL";
53
+ this.#sourceEl.src = this.engine?.url ?? "";
54
+ target.append(this.#sourceEl);
55
+ }
56
+ #setupLoadControl(target) {
57
+ const sync = () => {
58
+ if (target.webkitCurrentPlaybackTargetIsWireless) this.engine?.stopLoad();
59
+ };
60
+ this.#disconnect = new AbortController();
61
+ listen(target, "webkitcurrentplaybacktargetiswirelesschanged", sync, { signal: this.#disconnect.signal });
62
+ sync();
63
+ }
64
+ #destroy() {
65
+ this.#disconnect?.abort();
66
+ this.#disconnect = null;
67
+ this.#sourceEl?.remove();
68
+ this.#sourceEl = null;
69
+ }
70
+ }
71
+ return HlsJsAirPlay;
72
+ }
73
+ //#endregion
74
+ export { HlsJsAirPlayMixin };
75
+
76
+ //# sourceMappingURL=airplay-bridge.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"airplay-bridge.js","names":["#init","#destroy","#sourceEl","#authorDisableRemotePlayback","#attachSource","#setupLoadControl","#disconnect"],"sources":["../../src/airplay-bridge.ts"],"sourcesContent":["import { isWebKitAirPlayCapable, listen, type WebKitVideoElement } from '@videojs/utils/dom';\nimport type { Constructor } from '@videojs/utils/types';\nimport Hls from 'hls.js';\n\nimport type { HlsEngineHost } from './types';\n\n/**\n * Adds an AirPlay-capable fallback `<source>` to the attached video element so Safari can hand the original HLS\n * manifest off to AirPlay receivers while local playback continues through hls.js (MSE). When wireless-target changes,\n * suspends hls.js loading so we don't double-fetch alongside the AirPlay receiver.\n *\n * Implements the WebKit-recommended pattern:\n * https://webkit.org/blog/15036/how-to-use-media-source-extensions-with-airplay/\n *\n * No-op on non-WebKit platforms (Chromium, Firefox).\n */\nexport function HlsJsAirPlayMixin<Base extends Constructor<HlsEngineHost>>(BaseClass: Base) {\n class HlsJsAirPlay extends (BaseClass as Constructor<HlsEngineHost>) {\n #sourceEl: HTMLSourceElement | null = null;\n #disconnect: AbortController | null = null;\n /**\n * The author's `disableRemotePlayback`, not the element's current value. Tracked because engines (hls.js or SPF)\n * may alter the value internally (forced on for ManagedMediaSource), so the element on its own cannot tell an\n * opt-out apart from an MMS requirement.\n */\n #authorDisableRemotePlayback = false;\n\n constructor(...args: any[]) {\n super(...args);\n\n this.engine?.on(Hls.Events.MEDIA_ATTACHED, () => this.#init());\n this.engine?.on(Hls.Events.MEDIA_DETACHED, () => this.#destroy());\n this.engine?.on(Hls.Events.DESTROYING, () => this.#destroy());\n this.engine?.on(Hls.Events.MANIFEST_LOADING, (_event, data) => {\n if (this.#sourceEl) this.#sourceEl.src = data.url;\n });\n }\n\n override get disableRemotePlayback(): boolean {\n return super.disableRemotePlayback;\n }\n\n override set disableRemotePlayback(value: boolean) {\n const changed = value !== this.#authorDisableRemotePlayback;\n\n this.#authorDisableRemotePlayback = value;\n super.disableRemotePlayback = value;\n\n // We need to re initialize with the new value so WebKit reconsiders the source.\n if (changed && this.#sourceEl) this.#init();\n }\n\n #init(): void {\n this.#destroy();\n\n const target = this.target;\n if (!target || !isWebKitAirPlayCapable(target)) return;\n\n // Only toggle this if the author did not explicitly turn it off.\n if (!this.#authorDisableRemotePlayback) {\n target.disableRemotePlayback = false;\n }\n\n this.#attachSource(target);\n this.#setupLoadControl(target);\n }\n\n #attachSource(target: WebKitVideoElement) {\n this.#sourceEl = document.createElement('source');\n this.#sourceEl.type = 'application/x-mpegURL';\n this.#sourceEl.src = this.engine?.url ?? '';\n target.append(this.#sourceEl);\n }\n\n #setupLoadControl(target: WebKitVideoElement) {\n const sync = () => {\n /*\n * From HLS.loadStart \"Depending on default config,\n * client starts loading automatically when a source is set.\"\n * Safari re-sets the source when we turn AirPlay off, so there\n * is no need to call start load here when current playback\n * target is not wireless.\n */\n if (target.webkitCurrentPlaybackTargetIsWireless) {\n this.engine?.stopLoad();\n }\n };\n\n this.#disconnect = new AbortController();\n listen(target as EventTarget, 'webkitcurrentplaybacktargetiswirelesschanged', sync, {\n signal: this.#disconnect.signal,\n });\n\n // AirPlay may already be active at (re)attach.\n sync();\n }\n\n #destroy(): void {\n this.#disconnect?.abort();\n this.#disconnect = null;\n this.#sourceEl?.remove();\n this.#sourceEl = null;\n }\n }\n\n return HlsJsAirPlay as unknown as Base;\n}\n"],"mappings":";;;;;;;;;;;;;AAgBA,SAAgB,kBAA2D,WAAiB;CAC1F,MAAM,qBAAsB,UAAyC;EACnE,YAAsC;EACtC,cAAsC;;;;;;EAMtC,+BAA+B;EAE/B,YAAY,GAAG,MAAa;GAC1B,MAAM,GAAG,IAAI;GAEb,KAAK,QAAQ,GAAG,IAAI,OAAO,sBAAsB,KAAKA,MAAM,CAAC;GAC7D,KAAK,QAAQ,GAAG,IAAI,OAAO,sBAAsB,KAAKC,SAAS,CAAC;GAChE,KAAK,QAAQ,GAAG,IAAI,OAAO,kBAAkB,KAAKA,SAAS,CAAC;GAC5D,KAAK,QAAQ,GAAG,IAAI,OAAO,mBAAmB,QAAQ,SAAS;IAC7D,IAAI,KAAKC,WAAW,KAAKA,UAAU,MAAM,KAAK;GAChD,CAAC;EACH;EAEA,IAAa,wBAAiC;GAC5C,OAAO,MAAM;EACf;EAEA,IAAa,sBAAsB,OAAgB;GACjD,MAAM,UAAU,UAAU,KAAKC;GAE/B,KAAKA,+BAA+B;GACpC,MAAM,wBAAwB;GAG9B,IAAI,WAAW,KAAKD,WAAW,KAAKF,MAAM;EAC5C;EAEA,QAAc;GACZ,KAAKC,SAAS;GAEd,MAAM,SAAS,KAAK;GACpB,IAAI,CAAC,UAAU,CAAC,uBAAuB,MAAM,GAAG;GAGhD,IAAI,CAAC,KAAKE,8BACR,OAAO,wBAAwB;GAGjC,KAAKC,cAAc,MAAM;GACzB,KAAKC,kBAAkB,MAAM;EAC/B;EAEA,cAAc,QAA4B;GACxC,KAAKH,YAAY,SAAS,cAAc,QAAQ;GAChD,KAAKA,UAA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