@codenkay/video-nsgplayer-ui 3.0.0 → 4.0.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/CHANGELOG.md +21 -0
- package/README.md +11 -0
- package/dist/index.cjs +283 -30
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +77 -5
- package/dist/index.d.ts +77 -5
- package/dist/index.js +276 -29
- package/dist/index.js.map +1 -1
- package/dist/player-ui.css +9 -2
- package/package.json +16 -6
- package/styles.css +462 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,26 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 4.0.0
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- Fix minor issues
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies
|
|
12
|
+
- @codenkay/video-nsgplayer-core@4.0.0
|
|
13
|
+
- @codenkay/video-nsgplayer-react@4.0.0
|
|
14
|
+
|
|
15
|
+
## 3.0.4
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- Preserve "use client" in React/UI builds, forward analytics, intermittent watermark, Angular Ivy packaging, and packaging metadata.
|
|
20
|
+
- Updated dependencies
|
|
21
|
+
- @codenkay/video-nsgplayer-core@3.0.4
|
|
22
|
+
- @codenkay/video-nsgplayer-react@3.0.4
|
|
23
|
+
|
|
3
24
|
## 3.0.0
|
|
4
25
|
|
|
5
26
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -32,3 +32,14 @@ import "@codenkay/video-nsgplayer-ui/styles.css";
|
|
|
32
32
|
| `@codenkay/video-nsgplayer-ui` | Full control bar (this package) |
|
|
33
33
|
|
|
34
34
|
Zoom is UI-only (CSS `scale`). Import `styles.css` once in the host app.
|
|
35
|
+
|
|
36
|
+
Published bundles include a `"use client";` banner for Next.js App Router. Pass `analytics`, use `ref` for `getDiagnostics()` / runtime API, and set `watermark.durationMs` / `intervalMaxMs` for intermittent anti-leak watermarks.
|
|
37
|
+
|
|
38
|
+
## Samples
|
|
39
|
+
|
|
40
|
+
| Lab | Repo | Port |
|
|
41
|
+
|-----|------|------|
|
|
42
|
+
| Vite + UI (public `sourceUrl`) | [nsgplayer-sample-react](https://github.com/codenannu/nsgplayer-sample-react) | 5173 |
|
|
43
|
+
| Next.js BFF + UI (mock/real) | [nsgplayer-sample-nextjs](https://github.com/codenannu/nsgplayer-sample-nextjs) | 3001 |
|
|
44
|
+
|
|
45
|
+
Index and clone commands: [docs/samples.md](../../docs/samples.md).
|
package/dist/index.cjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
"use client";
|
|
1
2
|
"use strict";
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -31,21 +32,30 @@ __export(index_exports, {
|
|
|
31
32
|
PlayerMenu: () => PlayerMenu,
|
|
32
33
|
PlayerMenuItem: () => PlayerMenuItem,
|
|
33
34
|
PlayerSkipCue: () => PlayerSkipCue,
|
|
35
|
+
QUALITY_PREFERENCE_STORAGE_KEY: () => QUALITY_PREFERENCE_STORAGE_KEY,
|
|
34
36
|
QualitySelector: () => QualitySelector,
|
|
35
37
|
SeekBar: () => SeekBar,
|
|
36
38
|
TextTrackSelector: () => TextTrackSelector,
|
|
37
39
|
ZOOM_STEPS: () => ZOOM_STEPS,
|
|
38
40
|
formatPlaybackTime: () => formatPlaybackTime,
|
|
41
|
+
matchQualityPreference: () => matchQualityPreference,
|
|
39
42
|
nextZoom: () => nextZoom,
|
|
43
|
+
preferenceFromSelection: () => preferenceFromSelection,
|
|
44
|
+
randomFirstShowDelay: () => randomFirstShowDelay,
|
|
45
|
+
randomWatermarkDelay: () => randomWatermarkDelay,
|
|
46
|
+
randomWatermarkPosition: () => randomWatermarkPosition,
|
|
47
|
+
readQualityPreference: () => readQualityPreference,
|
|
40
48
|
resolvePlayerOverlay: () => resolvePlayerOverlay,
|
|
41
49
|
resolveVisiblePlaybackRates: () => resolveVisiblePlaybackRates,
|
|
42
50
|
snapPlaybackRate: () => snapPlaybackRate,
|
|
43
|
-
|
|
51
|
+
usePlaybackWatermark: () => usePlaybackWatermark,
|
|
52
|
+
usePlayerControls: () => usePlayerControls,
|
|
53
|
+
writeQualityPreference: () => writeQualityPreference
|
|
44
54
|
});
|
|
45
55
|
module.exports = __toCommonJS(index_exports);
|
|
46
56
|
|
|
47
57
|
// src/NsgVideoPlayerWithControls.tsx
|
|
48
|
-
var
|
|
58
|
+
var import_react8 = require("react");
|
|
49
59
|
var import_video_nsgplayer_core2 = require("@codenkay/video-nsgplayer-core");
|
|
50
60
|
var import_video_nsgplayer_react = require("@codenkay/video-nsgplayer-react");
|
|
51
61
|
|
|
@@ -116,6 +126,62 @@ function nextZoom(current, direction) {
|
|
|
116
126
|
return ZOOM_STEPS[next] ?? 1;
|
|
117
127
|
}
|
|
118
128
|
|
|
129
|
+
// src/utils/qualityPreference.ts
|
|
130
|
+
var QUALITY_PREFERENCE_STORAGE_KEY = "nsg-player:quality-preference";
|
|
131
|
+
function readQualityPreference() {
|
|
132
|
+
if (typeof window === "undefined" || !window.localStorage) {
|
|
133
|
+
return "auto";
|
|
134
|
+
}
|
|
135
|
+
try {
|
|
136
|
+
const raw = window.localStorage.getItem(QUALITY_PREFERENCE_STORAGE_KEY);
|
|
137
|
+
if (!raw) {
|
|
138
|
+
return "auto";
|
|
139
|
+
}
|
|
140
|
+
if (raw === "auto") {
|
|
141
|
+
return "auto";
|
|
142
|
+
}
|
|
143
|
+
const parsed = JSON.parse(raw);
|
|
144
|
+
if (parsed && typeof parsed === "object" && "height" in parsed && typeof parsed.height === "number" && Number.isFinite(parsed.height) && parsed.height > 0) {
|
|
145
|
+
return { height: parsed.height };
|
|
146
|
+
}
|
|
147
|
+
} catch {
|
|
148
|
+
}
|
|
149
|
+
return "auto";
|
|
150
|
+
}
|
|
151
|
+
function writeQualityPreference(preference) {
|
|
152
|
+
if (typeof window === "undefined" || !window.localStorage) {
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
try {
|
|
156
|
+
if (preference === "auto") {
|
|
157
|
+
window.localStorage.setItem(QUALITY_PREFERENCE_STORAGE_KEY, "auto");
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
window.localStorage.setItem(
|
|
161
|
+
QUALITY_PREFERENCE_STORAGE_KEY,
|
|
162
|
+
JSON.stringify({ height: preference.height })
|
|
163
|
+
);
|
|
164
|
+
} catch {
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
function matchQualityPreference(preference, levels) {
|
|
168
|
+
if (preference === "auto" || levels.length === 0) {
|
|
169
|
+
return "auto";
|
|
170
|
+
}
|
|
171
|
+
const match = levels.find((level) => level.height === preference.height);
|
|
172
|
+
return match ? match.index : "auto";
|
|
173
|
+
}
|
|
174
|
+
function preferenceFromSelection(selection, levels) {
|
|
175
|
+
if (selection === "auto") {
|
|
176
|
+
return "auto";
|
|
177
|
+
}
|
|
178
|
+
const level = levels.find((item) => item.index === selection);
|
|
179
|
+
if (!level || level.height <= 0) {
|
|
180
|
+
return "auto";
|
|
181
|
+
}
|
|
182
|
+
return { height: level.height };
|
|
183
|
+
}
|
|
184
|
+
|
|
119
185
|
// src/hooks/usePlayerControls.ts
|
|
120
186
|
function usePlayerControls(options) {
|
|
121
187
|
const { player, config, containerRef } = options;
|
|
@@ -143,16 +209,31 @@ function usePlayerControls(options) {
|
|
|
143
209
|
(0, import_react.useEffect)(() => {
|
|
144
210
|
setZoom(config.player.defaultZoom || 1);
|
|
145
211
|
}, [config.player.defaultZoom]);
|
|
212
|
+
(0, import_react.useEffect)(() => {
|
|
213
|
+
setVolumeState(config.player.volume);
|
|
214
|
+
setMuted(config.player.startMuted);
|
|
215
|
+
}, [config.player.volume, config.player.startMuted]);
|
|
146
216
|
(0, import_react.useEffect)(() => {
|
|
147
217
|
if (!player) return;
|
|
148
218
|
if (containerRef?.current) {
|
|
149
219
|
player.setFullscreenElement(containerRef.current);
|
|
150
220
|
}
|
|
151
221
|
const syncTracks = () => {
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
222
|
+
const levels = player.getAvailableQualities();
|
|
223
|
+
setQualities(levels);
|
|
224
|
+
let selection = player.getQuality();
|
|
225
|
+
if (config.controls.persistQualityPreference && levels.length > 0) {
|
|
226
|
+
const preferred = matchQualityPreference(
|
|
227
|
+
readQualityPreference(),
|
|
228
|
+
levels
|
|
229
|
+
);
|
|
230
|
+
if (preferred !== selection) {
|
|
231
|
+
player.setQuality(preferred);
|
|
232
|
+
selection = preferred;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
setQualitySelection(selection);
|
|
236
|
+
setActiveLevel(typeof selection === "number" ? selection : -1);
|
|
156
237
|
setTextTracks(player.getTextTracks());
|
|
157
238
|
setSelectedTextTrack(player.getSelectedTextTrack());
|
|
158
239
|
setAudioTracks(player.getAudioTracks());
|
|
@@ -161,7 +242,12 @@ function usePlayerControls(options) {
|
|
|
161
242
|
setAtLiveEdge(player.isAtLiveEdge());
|
|
162
243
|
setVolumeState(player.getVolume());
|
|
163
244
|
setMuted(player.isMuted());
|
|
164
|
-
|
|
245
|
+
if (player.isLive()) {
|
|
246
|
+
player.setPlaybackRate(1);
|
|
247
|
+
setPlaybackRateState(1);
|
|
248
|
+
} else {
|
|
249
|
+
setPlaybackRateState(player.getPlaybackRate());
|
|
250
|
+
}
|
|
165
251
|
setIsFullscreen(player.isFullscreen());
|
|
166
252
|
};
|
|
167
253
|
const offs = [
|
|
@@ -226,7 +312,7 @@ function usePlayerControls(options) {
|
|
|
226
312
|
for (const off of offs) off();
|
|
227
313
|
document.removeEventListener("fullscreenchange", onFs);
|
|
228
314
|
};
|
|
229
|
-
}, [player, containerRef]);
|
|
315
|
+
}, [player, containerRef, config.controls.persistQualityPreference]);
|
|
230
316
|
const togglePlay = (0, import_react.useCallback)(() => {
|
|
231
317
|
if (!player) return;
|
|
232
318
|
if (player.getState() === "playing") {
|
|
@@ -267,6 +353,9 @@ function usePlayerControls(options) {
|
|
|
267
353
|
}, [player]);
|
|
268
354
|
const setPlaybackRate = (0, import_react.useCallback)(
|
|
269
355
|
(rate) => {
|
|
356
|
+
if (player?.isLive()) {
|
|
357
|
+
return;
|
|
358
|
+
}
|
|
270
359
|
player?.setPlaybackRate(rate);
|
|
271
360
|
setPlaybackRateState(rate);
|
|
272
361
|
},
|
|
@@ -275,8 +364,16 @@ function usePlayerControls(options) {
|
|
|
275
364
|
const setQuality = (0, import_react.useCallback)(
|
|
276
365
|
(selection) => {
|
|
277
366
|
player?.setQuality(selection);
|
|
367
|
+
if (config.controls.persistQualityPreference) {
|
|
368
|
+
writeQualityPreference(
|
|
369
|
+
preferenceFromSelection(
|
|
370
|
+
selection,
|
|
371
|
+
player?.getAvailableQualities() ?? []
|
|
372
|
+
)
|
|
373
|
+
);
|
|
374
|
+
}
|
|
278
375
|
},
|
|
279
|
-
[player]
|
|
376
|
+
[player, config.controls.persistQualityPreference]
|
|
280
377
|
);
|
|
281
378
|
const setTextTrack = (0, import_react.useCallback)(
|
|
282
379
|
(selection) => {
|
|
@@ -682,13 +779,15 @@ function SeekBar({
|
|
|
682
779
|
duration,
|
|
683
780
|
bufferedEnd,
|
|
684
781
|
onSeek,
|
|
685
|
-
seekInputRef
|
|
782
|
+
seekInputRef,
|
|
783
|
+
getSeekPreview
|
|
686
784
|
}) {
|
|
687
785
|
const trackRef = (0, import_react5.useRef)(null);
|
|
688
786
|
const [hover, setHover] = (0, import_react5.useState)(INITIAL_HOVER);
|
|
689
787
|
const max = duration > 0 ? duration : 0;
|
|
690
788
|
const bufferedPct = max > 0 ? Math.min(100, bufferedEnd / max * 100) : 0;
|
|
691
789
|
const playedPct = max > 0 ? Math.min(100, currentTime / max * 100) : 0;
|
|
790
|
+
const previewUrl = hover.visible && getSeekPreview ? getSeekPreview(hover.time) : null;
|
|
692
791
|
const updateHover = (0, import_react5.useCallback)(
|
|
693
792
|
(clientX) => {
|
|
694
793
|
const track = trackRef.current;
|
|
@@ -750,13 +849,24 @@ function SeekBar({
|
|
|
750
849
|
style: { width: `${playedPct}%` }
|
|
751
850
|
}
|
|
752
851
|
),
|
|
753
|
-
hover.visible && max > 0 ? /* @__PURE__ */ (0, import_jsx_runtime8.
|
|
852
|
+
hover.visible && max > 0 ? /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
|
|
754
853
|
"div",
|
|
755
854
|
{
|
|
756
855
|
className: "nsg-player-seek__tooltip",
|
|
757
856
|
style: { left: `${hover.percent}%` },
|
|
758
857
|
role: "tooltip",
|
|
759
|
-
children:
|
|
858
|
+
children: [
|
|
859
|
+
previewUrl ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
860
|
+
"img",
|
|
861
|
+
{
|
|
862
|
+
className: "nsg-player-seek__preview",
|
|
863
|
+
src: previewUrl,
|
|
864
|
+
alt: "",
|
|
865
|
+
draggable: false
|
|
866
|
+
}
|
|
867
|
+
) : null,
|
|
868
|
+
formatPlaybackTime(hover.time)
|
|
869
|
+
]
|
|
760
870
|
}
|
|
761
871
|
) : null,
|
|
762
872
|
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
@@ -846,7 +956,8 @@ function PlayerControlBar(props) {
|
|
|
846
956
|
onToggleFullscreen,
|
|
847
957
|
onZoomIn,
|
|
848
958
|
onZoomOut,
|
|
849
|
-
seekBarRef
|
|
959
|
+
seekBarRef,
|
|
960
|
+
getSeekPreview
|
|
850
961
|
} = props;
|
|
851
962
|
const controls = config.controls;
|
|
852
963
|
const showZoom = config.player.zoomEnabled && controls.showZoom;
|
|
@@ -865,7 +976,8 @@ function PlayerControlBar(props) {
|
|
|
865
976
|
duration,
|
|
866
977
|
bufferedEnd,
|
|
867
978
|
onSeek,
|
|
868
|
-
seekInputRef: seekBarRef
|
|
979
|
+
seekInputRef: seekBarRef,
|
|
980
|
+
getSeekPreview
|
|
869
981
|
}
|
|
870
982
|
),
|
|
871
983
|
/* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("div", { className: "nsg-player-control-row", children: [
|
|
@@ -975,7 +1087,7 @@ function PlayerControlBar(props) {
|
|
|
975
1087
|
]
|
|
976
1088
|
}
|
|
977
1089
|
) : null,
|
|
978
|
-
controls.showSpeed ? /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
|
|
1090
|
+
controls.showSpeed && !isLive ? /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
|
|
979
1091
|
PlaybackSpeedSelector,
|
|
980
1092
|
{
|
|
981
1093
|
rate: playbackRate,
|
|
@@ -1074,7 +1186,8 @@ function PlayerChrome({
|
|
|
1074
1186
|
config,
|
|
1075
1187
|
containerRef,
|
|
1076
1188
|
videoSlot,
|
|
1077
|
-
className
|
|
1189
|
+
className,
|
|
1190
|
+
getSeekPreview
|
|
1078
1191
|
}) {
|
|
1079
1192
|
const rootRef = (0, import_react6.useRef)(null);
|
|
1080
1193
|
const seekBarRef = (0, import_react6.useRef)(null);
|
|
@@ -1258,7 +1371,8 @@ function PlayerChrome({
|
|
|
1258
1371
|
onToggleFullscreen: () => void controls.toggleFullscreen(),
|
|
1259
1372
|
onZoomIn: controls.zoomIn,
|
|
1260
1373
|
onZoomOut: controls.zoomOut,
|
|
1261
|
-
seekBarRef
|
|
1374
|
+
seekBarRef,
|
|
1375
|
+
getSeekPreview
|
|
1262
1376
|
}
|
|
1263
1377
|
) : null
|
|
1264
1378
|
]
|
|
@@ -1266,13 +1380,119 @@ function PlayerChrome({
|
|
|
1266
1380
|
);
|
|
1267
1381
|
}
|
|
1268
1382
|
|
|
1383
|
+
// src/hooks/usePlaybackWatermark.ts
|
|
1384
|
+
var import_react7 = require("react");
|
|
1385
|
+
|
|
1386
|
+
// src/utils/watermarkSchedule.ts
|
|
1387
|
+
var WATERMARK_TOP_MIN_PCT = 8;
|
|
1388
|
+
var WATERMARK_TOP_MAX_PCT = 70;
|
|
1389
|
+
var WATERMARK_LEFT_MIN_PCT = 5;
|
|
1390
|
+
var WATERMARK_LEFT_MAX_PCT = 70;
|
|
1391
|
+
var WATERMARK_FIRST_SHOW_MIN_MS = 3e3;
|
|
1392
|
+
var WATERMARK_FIRST_SHOW_MAX_MS = 8e3;
|
|
1393
|
+
function randomInRange(min, max, random = Math.random) {
|
|
1394
|
+
if (max <= min) {
|
|
1395
|
+
return min;
|
|
1396
|
+
}
|
|
1397
|
+
return min + random() * (max - min);
|
|
1398
|
+
}
|
|
1399
|
+
function randomWatermarkPosition(random = Math.random) {
|
|
1400
|
+
const topPct = WATERMARK_TOP_MIN_PCT + random() * (WATERMARK_TOP_MAX_PCT - WATERMARK_TOP_MIN_PCT);
|
|
1401
|
+
const leftPct = WATERMARK_LEFT_MIN_PCT + random() * (WATERMARK_LEFT_MAX_PCT - WATERMARK_LEFT_MIN_PCT);
|
|
1402
|
+
return { topPct, leftPct };
|
|
1403
|
+
}
|
|
1404
|
+
function randomWatermarkDelay(maxMs, random = Math.random) {
|
|
1405
|
+
if (!Number.isFinite(maxMs) || maxMs <= 0) {
|
|
1406
|
+
return 0;
|
|
1407
|
+
}
|
|
1408
|
+
return Math.min(maxMs, Math.floor(random() * (maxMs + 1)));
|
|
1409
|
+
}
|
|
1410
|
+
function randomFirstShowDelay(random = Math.random) {
|
|
1411
|
+
return Math.floor(
|
|
1412
|
+
randomInRange(
|
|
1413
|
+
WATERMARK_FIRST_SHOW_MIN_MS,
|
|
1414
|
+
WATERMARK_FIRST_SHOW_MAX_MS,
|
|
1415
|
+
random
|
|
1416
|
+
)
|
|
1417
|
+
);
|
|
1418
|
+
}
|
|
1419
|
+
|
|
1420
|
+
// src/hooks/usePlaybackWatermark.ts
|
|
1421
|
+
var HIDDEN = {
|
|
1422
|
+
visible: false,
|
|
1423
|
+
topPct: 0,
|
|
1424
|
+
leftPct: 0
|
|
1425
|
+
};
|
|
1426
|
+
function usePlaybackWatermark({
|
|
1427
|
+
enabled,
|
|
1428
|
+
label,
|
|
1429
|
+
active,
|
|
1430
|
+
durationMs,
|
|
1431
|
+
intervalMaxMs,
|
|
1432
|
+
reducedMotion = false
|
|
1433
|
+
}) {
|
|
1434
|
+
const [state, setState] = (0, import_react7.useState)(HIDDEN);
|
|
1435
|
+
const showTimerRef = (0, import_react7.useRef)(null);
|
|
1436
|
+
const hideTimerRef = (0, import_react7.useRef)(null);
|
|
1437
|
+
const generationRef = (0, import_react7.useRef)(0);
|
|
1438
|
+
(0, import_react7.useEffect)(() => {
|
|
1439
|
+
const clearTimers = () => {
|
|
1440
|
+
if (showTimerRef.current !== null) {
|
|
1441
|
+
window.clearTimeout(showTimerRef.current);
|
|
1442
|
+
showTimerRef.current = null;
|
|
1443
|
+
}
|
|
1444
|
+
if (hideTimerRef.current !== null) {
|
|
1445
|
+
window.clearTimeout(hideTimerRef.current);
|
|
1446
|
+
hideTimerRef.current = null;
|
|
1447
|
+
}
|
|
1448
|
+
};
|
|
1449
|
+
generationRef.current += 1;
|
|
1450
|
+
const generation = generationRef.current;
|
|
1451
|
+
clearTimers();
|
|
1452
|
+
setState(HIDDEN);
|
|
1453
|
+
if (!enabled || !label || !active) {
|
|
1454
|
+
return () => {
|
|
1455
|
+
clearTimers();
|
|
1456
|
+
};
|
|
1457
|
+
}
|
|
1458
|
+
if (reducedMotion) {
|
|
1459
|
+
setState({ visible: true, topPct: 12, leftPct: 8 });
|
|
1460
|
+
return () => {
|
|
1461
|
+
clearTimers();
|
|
1462
|
+
};
|
|
1463
|
+
}
|
|
1464
|
+
const scheduleShow = (delayMs) => {
|
|
1465
|
+
showTimerRef.current = window.setTimeout(() => {
|
|
1466
|
+
if (generation !== generationRef.current) {
|
|
1467
|
+
return;
|
|
1468
|
+
}
|
|
1469
|
+
const position = randomWatermarkPosition();
|
|
1470
|
+
setState({ visible: true, ...position });
|
|
1471
|
+
hideTimerRef.current = window.setTimeout(() => {
|
|
1472
|
+
if (generation !== generationRef.current) {
|
|
1473
|
+
return;
|
|
1474
|
+
}
|
|
1475
|
+
setState(HIDDEN);
|
|
1476
|
+
scheduleShow(randomWatermarkDelay(intervalMaxMs));
|
|
1477
|
+
}, durationMs);
|
|
1478
|
+
}, delayMs);
|
|
1479
|
+
};
|
|
1480
|
+
scheduleShow(randomFirstShowDelay());
|
|
1481
|
+
return () => {
|
|
1482
|
+
generationRef.current += 1;
|
|
1483
|
+
clearTimers();
|
|
1484
|
+
};
|
|
1485
|
+
}, [enabled, label, active, durationMs, intervalMaxMs, reducedMotion]);
|
|
1486
|
+
return state;
|
|
1487
|
+
}
|
|
1488
|
+
|
|
1269
1489
|
// src/NsgVideoPlayerWithControls.tsx
|
|
1270
1490
|
var import_jsx_runtime13 = require("react/jsx-runtime");
|
|
1271
|
-
|
|
1272
|
-
const containerRef = (0,
|
|
1273
|
-
const onWatchTimeRef = (0,
|
|
1491
|
+
var NsgVideoPlayerWithControls = (0, import_react8.forwardRef)(function NsgVideoPlayerWithControls2(props, ref) {
|
|
1492
|
+
const containerRef = (0, import_react8.useRef)(null);
|
|
1493
|
+
const onWatchTimeRef = (0, import_react8.useRef)(props.onWatchTime);
|
|
1274
1494
|
onWatchTimeRef.current = props.onWatchTime;
|
|
1275
|
-
const resolvedConfig = (0,
|
|
1495
|
+
const resolvedConfig = (0, import_react8.useMemo)(
|
|
1276
1496
|
() => (0, import_video_nsgplayer_core2.mergePlayerConfig)({
|
|
1277
1497
|
...props.config,
|
|
1278
1498
|
controls: {
|
|
@@ -1288,10 +1508,15 @@ function NsgVideoPlayerWithControls(props) {
|
|
|
1288
1508
|
playback: props.playback,
|
|
1289
1509
|
sourceUrl: props.sourceUrl,
|
|
1290
1510
|
config: resolvedConfig,
|
|
1511
|
+
analytics: props.analytics,
|
|
1291
1512
|
onReady: props.onReady,
|
|
1292
|
-
onError: props.onError
|
|
1513
|
+
onError: props.onError,
|
|
1514
|
+
onPlay: props.onPlay,
|
|
1515
|
+
onPause: props.onPause,
|
|
1516
|
+
onAuthError: props.onAuthError
|
|
1293
1517
|
});
|
|
1294
|
-
(0,
|
|
1518
|
+
(0, import_react8.useImperativeHandle)(ref, () => player, [player]);
|
|
1519
|
+
(0, import_react8.useEffect)(() => {
|
|
1295
1520
|
if (!player) return;
|
|
1296
1521
|
const report = () => {
|
|
1297
1522
|
const t = player.getCurrentTime();
|
|
@@ -1299,9 +1524,7 @@ function NsgVideoPlayerWithControls(props) {
|
|
|
1299
1524
|
};
|
|
1300
1525
|
const offs = [
|
|
1301
1526
|
player.on("pause", report),
|
|
1302
|
-
player.on("ended", report)
|
|
1303
|
-
player.on("play", () => props.onPlay?.()),
|
|
1304
|
-
player.on("pause", () => props.onPause?.())
|
|
1527
|
+
player.on("ended", report)
|
|
1305
1528
|
];
|
|
1306
1529
|
const onBeforeUnload = () => report();
|
|
1307
1530
|
window.addEventListener("beforeunload", onBeforeUnload);
|
|
@@ -1309,7 +1532,16 @@ function NsgVideoPlayerWithControls(props) {
|
|
|
1309
1532
|
for (const off of offs) off();
|
|
1310
1533
|
window.removeEventListener("beforeunload", onBeforeUnload);
|
|
1311
1534
|
};
|
|
1312
|
-
}, [player
|
|
1535
|
+
}, [player]);
|
|
1536
|
+
const watermarkActive = state === "playing" || state === "paused" || state === "buffering";
|
|
1537
|
+
const watermark = usePlaybackWatermark({
|
|
1538
|
+
enabled: resolvedConfig.watermark.enabled,
|
|
1539
|
+
label: resolvedConfig.watermark.text?.trim() || null,
|
|
1540
|
+
active: watermarkActive,
|
|
1541
|
+
durationMs: resolvedConfig.watermark.durationMs,
|
|
1542
|
+
intervalMaxMs: resolvedConfig.watermark.intervalMaxMs,
|
|
1543
|
+
reducedMotion: resolvedConfig.accessibility.reducedMotion
|
|
1544
|
+
});
|
|
1313
1545
|
const cssVars = (0, import_video_nsgplayer_core2.themeToCssVars)(resolvedConfig.theme);
|
|
1314
1546
|
const showBootstrap = state === "loading" || state === "idle";
|
|
1315
1547
|
return /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(
|
|
@@ -1335,6 +1567,7 @@ function NsgVideoPlayerWithControls(props) {
|
|
|
1335
1567
|
player,
|
|
1336
1568
|
config: resolvedConfig,
|
|
1337
1569
|
containerRef,
|
|
1570
|
+
getSeekPreview: props.getSeekPreview,
|
|
1338
1571
|
videoSlot: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
|
|
1339
1572
|
"video",
|
|
1340
1573
|
{
|
|
@@ -1346,13 +1579,24 @@ function NsgVideoPlayerWithControls(props) {
|
|
|
1346
1579
|
)
|
|
1347
1580
|
}
|
|
1348
1581
|
),
|
|
1349
|
-
|
|
1582
|
+
watermark.visible ? /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
|
|
1583
|
+
"div",
|
|
1584
|
+
{
|
|
1585
|
+
className: "nsg-player-watermark",
|
|
1586
|
+
"aria-hidden": true,
|
|
1587
|
+
style: {
|
|
1588
|
+
top: `${watermark.topPct}%`,
|
|
1589
|
+
left: `${watermark.leftPct}%`
|
|
1590
|
+
},
|
|
1591
|
+
children: resolvedConfig.watermark.text
|
|
1592
|
+
}
|
|
1593
|
+
) : null,
|
|
1350
1594
|
error ? /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("p", { className: "nsg-player-error", role: "alert", children: error.message || "Unable to play this video." }) : null,
|
|
1351
1595
|
showBootstrap && !error ? /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("p", { className: "nsg-player-status", children: "Loading video\u2026" }) : null
|
|
1352
1596
|
]
|
|
1353
1597
|
}
|
|
1354
1598
|
);
|
|
1355
|
-
}
|
|
1599
|
+
});
|
|
1356
1600
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1357
1601
|
0 && (module.exports = {
|
|
1358
1602
|
AudioTrackSelector,
|
|
@@ -1366,15 +1610,24 @@ function NsgVideoPlayerWithControls(props) {
|
|
|
1366
1610
|
PlayerMenu,
|
|
1367
1611
|
PlayerMenuItem,
|
|
1368
1612
|
PlayerSkipCue,
|
|
1613
|
+
QUALITY_PREFERENCE_STORAGE_KEY,
|
|
1369
1614
|
QualitySelector,
|
|
1370
1615
|
SeekBar,
|
|
1371
1616
|
TextTrackSelector,
|
|
1372
1617
|
ZOOM_STEPS,
|
|
1373
1618
|
formatPlaybackTime,
|
|
1619
|
+
matchQualityPreference,
|
|
1374
1620
|
nextZoom,
|
|
1621
|
+
preferenceFromSelection,
|
|
1622
|
+
randomFirstShowDelay,
|
|
1623
|
+
randomWatermarkDelay,
|
|
1624
|
+
randomWatermarkPosition,
|
|
1625
|
+
readQualityPreference,
|
|
1375
1626
|
resolvePlayerOverlay,
|
|
1376
1627
|
resolveVisiblePlaybackRates,
|
|
1377
1628
|
snapPlaybackRate,
|
|
1378
|
-
|
|
1629
|
+
usePlaybackWatermark,
|
|
1630
|
+
usePlayerControls,
|
|
1631
|
+
writeQualityPreference
|
|
1379
1632
|
});
|
|
1380
1633
|
//# sourceMappingURL=index.cjs.map
|