@videojs/hlsjs-video 10.1.0 → 10.2.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/live.js +6 -17
- package/dist/dev/live.js +6 -17
- package/dist/dev/live.js.map +1 -1
- package/package.json +7 -8
package/dist/default/live.js
CHANGED
|
@@ -4,7 +4,6 @@ import Hls from "hls.js";
|
|
|
4
4
|
function HlsJsLiveMixin(BaseClass) {
|
|
5
5
|
class HlsJsLive extends BaseClass {
|
|
6
6
|
#targetLiveWindow = NaN;
|
|
7
|
-
#liveEdgeStartOffset;
|
|
8
7
|
#seekToLiveAbort = null;
|
|
9
8
|
#seekToLivePending = false;
|
|
10
9
|
constructor(...args) {
|
|
@@ -29,22 +28,18 @@ function HlsJsLiveMixin(BaseClass) {
|
|
|
29
28
|
return this.#targetLiveWindow;
|
|
30
29
|
}
|
|
31
30
|
get liveEdgeStart() {
|
|
32
|
-
if (this.#
|
|
31
|
+
if (Number.isNaN(this.#targetLiveWindow)) return NaN;
|
|
33
32
|
const { target } = this;
|
|
34
|
-
if (!target) return NaN;
|
|
35
|
-
|
|
36
|
-
if (!seekable.length) return NaN;
|
|
37
|
-
return seekable.end(seekable.length - 1) - this.#liveEdgeStartOffset;
|
|
33
|
+
if (!target?.seekable.length) return NaN;
|
|
34
|
+
return this.engine?.liveSyncPosition ?? NaN;
|
|
38
35
|
}
|
|
39
36
|
#derive(details) {
|
|
40
37
|
if (!details.live) return this.#reset();
|
|
41
38
|
const info = getStreamInfoFromHlsjsLevelDetails(details);
|
|
42
|
-
this.#liveEdgeStartOffset = info.liveEdgeStartOffset;
|
|
43
39
|
this.#updateConfig(info);
|
|
44
40
|
this.#setTargetLiveWindow(info.targetLiveWindow);
|
|
45
41
|
}
|
|
46
42
|
#reset() {
|
|
47
|
-
this.#liveEdgeStartOffset = void 0;
|
|
48
43
|
this.#setTargetLiveWindow(NaN);
|
|
49
44
|
}
|
|
50
45
|
#updateConfig({ streamType, lowLatency }) {
|
|
@@ -98,16 +93,10 @@ function HlsJsLiveMixin(BaseClass) {
|
|
|
98
93
|
}
|
|
99
94
|
const getStreamInfoFromHlsjsLevelDetails = (levelDetails) => {
|
|
100
95
|
const playlistType = levelDetails.type;
|
|
101
|
-
const streamType = toStreamTypeFromPlaylistType(playlistType);
|
|
102
|
-
const targetLiveWindow = toTargetLiveWindowFromPlaylistType(playlistType);
|
|
103
|
-
const lowLatency = !!levelDetails.partList?.length;
|
|
104
|
-
let liveEdgeStartOffset;
|
|
105
|
-
if (streamType === MediaStreamTypes.LIVE) liveEdgeStartOffset = lowLatency ? levelDetails.partHoldBack || levelDetails.partTarget * 2 : levelDetails.holdBack || levelDetails.targetduration * 3;
|
|
106
96
|
return {
|
|
107
|
-
streamType,
|
|
108
|
-
targetLiveWindow,
|
|
109
|
-
|
|
110
|
-
lowLatency
|
|
97
|
+
streamType: toStreamTypeFromPlaylistType(playlistType),
|
|
98
|
+
targetLiveWindow: toTargetLiveWindowFromPlaylistType(playlistType),
|
|
99
|
+
lowLatency: !!levelDetails.partList?.length
|
|
111
100
|
};
|
|
112
101
|
};
|
|
113
102
|
const toStreamTypeFromPlaylistType = (playlistType) => {
|
package/dist/dev/live.js
CHANGED
|
@@ -4,7 +4,6 @@ import Hls from "hls.js";
|
|
|
4
4
|
function HlsJsLiveMixin(BaseClass) {
|
|
5
5
|
class HlsJsLive extends BaseClass {
|
|
6
6
|
#targetLiveWindow = NaN;
|
|
7
|
-
#liveEdgeStartOffset;
|
|
8
7
|
#seekToLiveAbort = null;
|
|
9
8
|
#seekToLivePending = false;
|
|
10
9
|
constructor(...args) {
|
|
@@ -29,22 +28,18 @@ function HlsJsLiveMixin(BaseClass) {
|
|
|
29
28
|
return this.#targetLiveWindow;
|
|
30
29
|
}
|
|
31
30
|
get liveEdgeStart() {
|
|
32
|
-
if (this.#
|
|
31
|
+
if (Number.isNaN(this.#targetLiveWindow)) return NaN;
|
|
33
32
|
const { target } = this;
|
|
34
|
-
if (!target) return NaN;
|
|
35
|
-
|
|
36
|
-
if (!seekable.length) return NaN;
|
|
37
|
-
return seekable.end(seekable.length - 1) - this.#liveEdgeStartOffset;
|
|
33
|
+
if (!target?.seekable.length) return NaN;
|
|
34
|
+
return this.engine?.liveSyncPosition ?? NaN;
|
|
38
35
|
}
|
|
39
36
|
#derive(details) {
|
|
40
37
|
if (!details.live) return this.#reset();
|
|
41
38
|
const info = getStreamInfoFromHlsjsLevelDetails(details);
|
|
42
|
-
this.#liveEdgeStartOffset = info.liveEdgeStartOffset;
|
|
43
39
|
this.#updateConfig(info);
|
|
44
40
|
this.#setTargetLiveWindow(info.targetLiveWindow);
|
|
45
41
|
}
|
|
46
42
|
#reset() {
|
|
47
|
-
this.#liveEdgeStartOffset = void 0;
|
|
48
43
|
this.#setTargetLiveWindow(NaN);
|
|
49
44
|
}
|
|
50
45
|
#updateConfig({ streamType, lowLatency }) {
|
|
@@ -98,16 +93,10 @@ function HlsJsLiveMixin(BaseClass) {
|
|
|
98
93
|
}
|
|
99
94
|
const getStreamInfoFromHlsjsLevelDetails = (levelDetails) => {
|
|
100
95
|
const playlistType = levelDetails.type;
|
|
101
|
-
const streamType = toStreamTypeFromPlaylistType(playlistType);
|
|
102
|
-
const targetLiveWindow = toTargetLiveWindowFromPlaylistType(playlistType);
|
|
103
|
-
const lowLatency = !!levelDetails.partList?.length;
|
|
104
|
-
let liveEdgeStartOffset;
|
|
105
|
-
if (streamType === MediaStreamTypes.LIVE) liveEdgeStartOffset = lowLatency ? levelDetails.partHoldBack || levelDetails.partTarget * 2 : levelDetails.holdBack || levelDetails.targetduration * 3;
|
|
106
96
|
return {
|
|
107
|
-
streamType,
|
|
108
|
-
targetLiveWindow,
|
|
109
|
-
|
|
110
|
-
lowLatency
|
|
97
|
+
streamType: toStreamTypeFromPlaylistType(playlistType),
|
|
98
|
+
targetLiveWindow: toTargetLiveWindowFromPlaylistType(playlistType),
|
|
99
|
+
lowLatency: !!levelDetails.partList?.length
|
|
111
100
|
};
|
|
112
101
|
};
|
|
113
102
|
const toStreamTypeFromPlaylistType = (playlistType) => {
|
package/dist/dev/live.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"live.js","names":[],"sources":["../../src/live.ts"],"sourcesContent":["import { MediaStreamTypes } from '@videojs/media';\nimport type { Constructor } from '@videojs/utils/types';\nimport type { LevelLoadedData } from 'hls.js';\nimport Hls from 'hls.js';\n\nimport type { HlsEngineHost, HlsPlaylistTypes } from './types';\n\nexport function HlsJsLiveMixin<Base extends Constructor<HlsEngineHost>>(BaseClass: Base) {\n class HlsJsLive extends (BaseClass as Constructor<HlsEngineHost>) {\n #targetLiveWindow = Number.NaN;\n #
|
|
1
|
+
{"version":3,"file":"live.js","names":[],"sources":["../../src/live.ts"],"sourcesContent":["import { MediaStreamTypes } from '@videojs/media';\nimport type { Constructor } from '@videojs/utils/types';\nimport type { LevelLoadedData } from 'hls.js';\nimport Hls from 'hls.js';\n\nimport type { HlsEngineHost, HlsPlaylistTypes } from './types';\n\nexport function HlsJsLiveMixin<Base extends Constructor<HlsEngineHost>>(BaseClass: Base) {\n class HlsJsLive extends (BaseClass as Constructor<HlsEngineHost>) {\n #targetLiveWindow = Number.NaN;\n #seekToLiveAbort: AbortController | null = null;\n #seekToLivePending = false;\n\n constructor(...args: any[]) {\n super(...args);\n\n const { engine } = this;\n\n engine?.on(Hls.Events.MANIFEST_LOADING, () => {\n this.#reset();\n this.#armSeekToLive();\n });\n engine?.on(Hls.Events.MEDIA_ATTACHED, () => this.#armSeekToLive());\n engine?.on(Hls.Events.MEDIA_DETACHED, () => this.#disarmSeekToLive());\n engine?.on(Hls.Events.DESTROYING, () => {\n this.#reset();\n this.#disarmSeekToLive();\n });\n engine?.on(Hls.Events.LEVEL_LOADED, (_event: string, data: LevelLoadedData) => {\n this.#derive(data.details);\n\n // For `preload=\"none\"`/`\"metadata\"` the manifest only loads after the\n // first play, so retry the seek once `liveEdgeStart` becomes finite.\n if (this.#seekToLivePending) this.#trySeekToLive();\n });\n }\n\n get targetLiveWindow() {\n return this.#targetLiveWindow;\n }\n\n // Read from hls.js at read time. No cached state, no event. hls.js applies the playlist hold-back, the\n // `liveSyncDuration` / `liveSyncDurationCount` config and `lowLatencyMode`, so this is where hls.js itself plays.\n get liveEdgeStart() {\n if (Number.isNaN(this.#targetLiveWindow)) return Number.NaN;\n\n // Keep `NaN` until the media has a seekable range, so the first-play seek does not run before the media can seek.\n const { target } = this;\n if (!target?.seekable.length) return Number.NaN;\n\n return this.engine?.liveSyncPosition ?? Number.NaN;\n }\n\n #derive(details: LevelLoadedData['details']) {\n if (!details.live) return this.#reset();\n\n const info = getStreamInfoFromHlsjsLevelDetails(details);\n\n this.#updateConfig(info);\n this.#setTargetLiveWindow(info.targetLiveWindow);\n }\n\n #reset() {\n this.#setTargetLiveWindow(Number.NaN);\n }\n\n #updateConfig({ streamType, lowLatency }: StreamInfo) {\n if (streamType === MediaStreamTypes.LIVE) {\n // Update hls.js config for live/ll-live\n const hls = this.engine;\n if (!hls) return;\n\n if (lowLatency) {\n hls.config.backBufferLength = hls.userConfig.backBufferLength ?? 4;\n hls.config.maxFragLookUpTolerance = hls.userConfig.maxFragLookUpTolerance ?? 0.001;\n // For ll-hls, ensure that up switches are weighted the same as down switches to mitigate\n // cases of getting stuck at lower bitrates.\n hls.config.abrBandWidthUpFactor = hls.userConfig.abrBandWidthUpFactor ?? hls.config.abrBandWidthFactor;\n } else {\n hls.config.backBufferLength = hls.userConfig.backBufferLength ?? 8;\n }\n }\n }\n\n #setTargetLiveWindow(value: number) {\n if (Object.is(this.#targetLiveWindow, value)) return;\n\n this.#targetLiveWindow = value;\n this.dispatchEvent(new Event('targetlivewindowchange'));\n }\n\n /**\n * Arm a one-shot seek-to-live on the first user-initiated `play`. Skipped when `autoplay` is set, since hls.js\n * positions at the live edge during its own startup sequence and a programmatic seek would race that.\n */\n #armSeekToLive() {\n this.#disarmSeekToLive();\n\n const target = this.target as HTMLVideoElement | null;\n if (!target || target.autoplay) return;\n\n this.#seekToLiveAbort = new AbortController();\n target.addEventListener(\n 'play',\n () => {\n this.#seekToLivePending = true;\n this.#trySeekToLive();\n },\n { signal: this.#seekToLiveAbort.signal, once: true }\n );\n }\n\n #disarmSeekToLive() {\n this.#seekToLiveAbort?.abort();\n this.#seekToLiveAbort = null;\n this.#seekToLivePending = false;\n }\n\n #trySeekToLive() {\n const target = this.target as HTMLVideoElement | null;\n if (!target) return;\n\n const { liveEdgeStart } = this;\n if (!Number.isFinite(liveEdgeStart)) return;\n\n if (target.currentTime < liveEdgeStart) {\n target.currentTime = liveEdgeStart;\n }\n\n this.#seekToLivePending = false;\n }\n }\n\n return HlsJsLive as unknown as Base &\n Constructor<{ readonly liveEdgeStart: number; readonly targetLiveWindow: number }>;\n}\n\ntype StreamInfo = ReturnType<typeof getStreamInfoFromHlsjsLevelDetails>;\n\nconst getStreamInfoFromHlsjsLevelDetails = (levelDetails: LevelLoadedData['details']) => {\n const playlistType: HlsPlaylistTypes = levelDetails.type as HlsPlaylistTypes;\n const streamType = toStreamTypeFromPlaylistType(playlistType);\n const targetLiveWindow = toTargetLiveWindowFromPlaylistType(playlistType);\n const lowLatency = !!levelDetails.partList?.length;\n\n return {\n streamType,\n targetLiveWindow,\n lowLatency,\n };\n};\n\nconst toStreamTypeFromPlaylistType = (playlistType: HlsPlaylistTypes) => {\n return playlistType === 'VOD' ? MediaStreamTypes.ON_DEMAND : MediaStreamTypes.LIVE;\n};\n\nconst toTargetLiveWindowFromPlaylistType = (playlistType: HlsPlaylistTypes) => {\n if (playlistType === 'EVENT') return Number.POSITIVE_INFINITY;\n\n if (playlistType === 'VOD') return Number.NaN;\n\n return 0;\n};\n"],"mappings":";;;AAOA,SAAgB,eAAwD,WAAiB;CACvF,MAAM,kBAAmB,UAAyC;EAChE,oBAAoB;EACpB,mBAA2C;EAC3C,qBAAqB;EAErB,YAAY,GAAG,MAAa;GAC1B,MAAM,GAAG,IAAI;GAEb,M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version": "10.2.0",
|
|
4
4
|
"description": "hls.js playback adapter for Video.js",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"hls",
|
|
@@ -35,19 +35,18 @@
|
|
|
35
35
|
"access": "public"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@videojs/media": "10.
|
|
39
|
-
"@videojs/native-hls-video": "10.
|
|
40
|
-
"@videojs/spf": "10.
|
|
41
|
-
"@videojs/utils": "10.
|
|
38
|
+
"@videojs/media": "10.2.0",
|
|
39
|
+
"@videojs/native-hls-video": "10.2.0",
|
|
40
|
+
"@videojs/spf": "10.2.0",
|
|
41
|
+
"@videojs/utils": "10.2.0",
|
|
42
42
|
"hls.js": "1.6.19"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"jsdom": "^26.1.0",
|
|
46
|
-
"vite-plus": "1.
|
|
46
|
+
"vite-plus": "1.1.0"
|
|
47
47
|
},
|
|
48
48
|
"scripts": {
|
|
49
|
-
"
|
|
50
|
-
"dev": "pnpm run build:watch",
|
|
49
|
+
"dev": "vp pack --watch ./src --no-clean",
|
|
51
50
|
"test": "vp test run",
|
|
52
51
|
"test:watch": "vp test",
|
|
53
52
|
"clean": "rimraf --glob dist types '*.tsbuildinfo'"
|