@codenkay/video-nsgplayer-ui 3.0.0 → 3.0.4
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 +9 -0
- package/README.md +2 -0
- package/dist/index.cjs +269 -28
- 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 +262 -27
- package/dist/index.js.map +1 -1
- package/dist/player-ui.css +9 -2
- package/package.json +13 -4
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
2
|
import { CSSProperties, RefObject, ReactNode } from 'react';
|
|
3
|
-
import { AuthConfig, PlaybackCredentialConfig, mergePlayerConfig, VideoPlayer, PlayerConfig, PlaybackRate, HlsQualityLevel, QualitySelection, PlayerTextTrack, TextTrackSelection, PlayerAudioTrack, PlayIconPreset as PlayIconPreset$1 } from '@codenkay/video-nsgplayer-core';
|
|
3
|
+
import { AuthConfig, PlaybackCredentialConfig, mergePlayerConfig, AnalyticsConfig, VideoPlayer, PlayerConfig, PlaybackRate, HlsQualityLevel, QualitySelection, PlayerTextTrack, TextTrackSelection, PlayerAudioTrack, PlayIconPreset as PlayIconPreset$1 } from '@codenkay/video-nsgplayer-core';
|
|
4
4
|
|
|
5
5
|
type NsgVideoPlayerWithControlsProps = {
|
|
6
6
|
videoId: string;
|
|
@@ -8,6 +8,7 @@ type NsgVideoPlayerWithControlsProps = {
|
|
|
8
8
|
playback?: PlaybackCredentialConfig;
|
|
9
9
|
sourceUrl?: string;
|
|
10
10
|
config?: Parameters<typeof mergePlayerConfig>[0];
|
|
11
|
+
analytics?: AnalyticsConfig;
|
|
11
12
|
className?: string;
|
|
12
13
|
style?: CSSProperties;
|
|
13
14
|
onWatchTime?: (time: number) => void;
|
|
@@ -19,12 +20,18 @@ type NsgVideoPlayerWithControlsProps = {
|
|
|
19
20
|
}) => void;
|
|
20
21
|
onPlay?: () => void;
|
|
21
22
|
onPause?: () => void;
|
|
23
|
+
onAuthError?: (error: {
|
|
24
|
+
message: string;
|
|
25
|
+
retryable: boolean;
|
|
26
|
+
}) => void;
|
|
27
|
+
/** Optional seek-bar hover preview image URL for a given media time. */
|
|
28
|
+
getSeekPreview?: (time: number) => string | null | undefined;
|
|
22
29
|
};
|
|
23
30
|
/**
|
|
24
31
|
* Full player with control chrome (seek, quality, speed, live, zoom, keyboard).
|
|
25
32
|
* Does not use native `<video controls>`.
|
|
26
33
|
*/
|
|
27
|
-
declare
|
|
34
|
+
declare const NsgVideoPlayerWithControls: react.ForwardRefExoticComponent<NsgVideoPlayerWithControlsProps & react.RefAttributes<VideoPlayer>>;
|
|
28
35
|
|
|
29
36
|
type PlayerChromeProps = {
|
|
30
37
|
player: VideoPlayer | null;
|
|
@@ -32,12 +39,13 @@ type PlayerChromeProps = {
|
|
|
32
39
|
containerRef: RefObject<HTMLElement | null>;
|
|
33
40
|
videoSlot: ReactNode;
|
|
34
41
|
className?: string;
|
|
42
|
+
getSeekPreview?: (time: number) => string | null | undefined;
|
|
35
43
|
};
|
|
36
44
|
/**
|
|
37
45
|
* Control shell over an already-mounted video (children / videoSlot).
|
|
38
46
|
* Zoom is UI-only via CSS transform.
|
|
39
47
|
*/
|
|
40
|
-
declare function PlayerChrome({ player, config, containerRef, videoSlot, className, }: PlayerChromeProps): react.JSX.Element;
|
|
48
|
+
declare function PlayerChrome({ player, config, containerRef, videoSlot, className, getSeekPreview, }: PlayerChromeProps): react.JSX.Element;
|
|
41
49
|
|
|
42
50
|
declare function formatPlaybackTime(seconds: number): string;
|
|
43
51
|
declare function resolveVisiblePlaybackRates(count: number): PlaybackRate[];
|
|
@@ -87,6 +95,7 @@ type PlayerControlBarProps = {
|
|
|
87
95
|
onZoomIn: () => void;
|
|
88
96
|
onZoomOut: () => void;
|
|
89
97
|
seekBarRef?: RefObject<HTMLInputElement | null>;
|
|
98
|
+
getSeekPreview?: (time: number) => string | null | undefined;
|
|
90
99
|
};
|
|
91
100
|
declare function PlayerControlBar(props: PlayerControlBarProps): react.JSX.Element;
|
|
92
101
|
|
|
@@ -145,12 +154,13 @@ declare function PlaybackSpeedSelector({ rate, speedOptionCount, onSelect, }: {
|
|
|
145
154
|
onSelect: (rate: PlaybackRate) => void;
|
|
146
155
|
}): react.JSX.Element;
|
|
147
156
|
|
|
148
|
-
declare function SeekBar({ currentTime, duration, bufferedEnd, onSeek, seekInputRef, }: {
|
|
157
|
+
declare function SeekBar({ currentTime, duration, bufferedEnd, onSeek, seekInputRef, getSeekPreview, }: {
|
|
149
158
|
currentTime: number;
|
|
150
159
|
duration: number;
|
|
151
160
|
bufferedEnd: number;
|
|
152
161
|
onSeek: (time: number) => void;
|
|
153
162
|
seekInputRef?: RefObject<HTMLInputElement | null> | RefObject<HTMLInputElement>;
|
|
163
|
+
getSeekPreview?: (time: number) => string | null | undefined;
|
|
154
164
|
}): react.JSX.Element;
|
|
155
165
|
|
|
156
166
|
declare function TextTrackSelector({ tracks, selection, onSelect, }: {
|
|
@@ -203,4 +213,66 @@ declare function PlayIconPreset({ preset, size, }: {
|
|
|
203
213
|
size?: number;
|
|
204
214
|
}): react.JSX.Element;
|
|
205
215
|
|
|
206
|
-
|
|
216
|
+
type WatermarkPosition = {
|
|
217
|
+
topPct: number;
|
|
218
|
+
leftPct: number;
|
|
219
|
+
};
|
|
220
|
+
/**
|
|
221
|
+
* Random on-player position within safe margins (percent of container).
|
|
222
|
+
*/
|
|
223
|
+
declare function randomWatermarkPosition(random?: () => number): WatermarkPosition;
|
|
224
|
+
/**
|
|
225
|
+
* Random delay in `[0, maxMs]` for the gap between watermark appearances.
|
|
226
|
+
*/
|
|
227
|
+
declare function randomWatermarkDelay(maxMs: number, random?: () => number): number;
|
|
228
|
+
/**
|
|
229
|
+
* Random delay before the first watermark show after playback is ready.
|
|
230
|
+
*/
|
|
231
|
+
declare function randomFirstShowDelay(random?: () => number): number;
|
|
232
|
+
|
|
233
|
+
type StoredQualityPreference = "auto" | {
|
|
234
|
+
height: number;
|
|
235
|
+
};
|
|
236
|
+
declare const QUALITY_PREFERENCE_STORAGE_KEY = "nsg-player:quality-preference";
|
|
237
|
+
/**
|
|
238
|
+
* Reads the stored quality preference from localStorage.
|
|
239
|
+
* Returns `"auto"` when missing, invalid, or unavailable (SSR).
|
|
240
|
+
*/
|
|
241
|
+
declare function readQualityPreference(): StoredQualityPreference;
|
|
242
|
+
/**
|
|
243
|
+
* Persists quality preference. Stores `"auto"` or `{ height }` only.
|
|
244
|
+
*/
|
|
245
|
+
declare function writeQualityPreference(preference: StoredQualityPreference): void;
|
|
246
|
+
/**
|
|
247
|
+
* Maps a stored preference onto available levels.
|
|
248
|
+
* Missing height → `"auto"` (preference is kept in storage for later videos).
|
|
249
|
+
*/
|
|
250
|
+
declare function matchQualityPreference(preference: StoredQualityPreference, levels: Array<{
|
|
251
|
+
index: number;
|
|
252
|
+
height: number;
|
|
253
|
+
}>): "auto" | number;
|
|
254
|
+
/**
|
|
255
|
+
* Builds a preference payload from the user's runtime selection.
|
|
256
|
+
*/
|
|
257
|
+
declare function preferenceFromSelection(selection: "auto" | number, levels: Array<{
|
|
258
|
+
index: number;
|
|
259
|
+
height: number;
|
|
260
|
+
}>): StoredQualityPreference;
|
|
261
|
+
|
|
262
|
+
type PlaybackWatermarkState = WatermarkPosition & {
|
|
263
|
+
visible: boolean;
|
|
264
|
+
};
|
|
265
|
+
/**
|
|
266
|
+
* Schedules intermittent anti-leak watermark appearances while playback is active.
|
|
267
|
+
* When `reducedMotion` is true, shows a fixed-position watermark continuously.
|
|
268
|
+
*/
|
|
269
|
+
declare function usePlaybackWatermark({ enabled, label, active, durationMs, intervalMaxMs, reducedMotion, }: {
|
|
270
|
+
enabled: boolean;
|
|
271
|
+
label: string | null;
|
|
272
|
+
active: boolean;
|
|
273
|
+
durationMs: number;
|
|
274
|
+
intervalMaxMs: number;
|
|
275
|
+
reducedMotion?: boolean;
|
|
276
|
+
}): PlaybackWatermarkState;
|
|
277
|
+
|
|
278
|
+
export { AudioTrackSelector, LiveBadgeButton, NsgVideoPlayerWithControls, type NsgVideoPlayerWithControlsProps, PlayIconPreset, PlaybackSpeedSelector, type PlaybackWatermarkState, PlayerCenterOverlay, PlayerChrome, type PlayerChromeProps, PlayerControlBar, type PlayerControlBarProps, PlayerMenu, PlayerMenuItem, type PlayerOverlayKind, PlayerSkipCue, type PlayerZoomLevel, QUALITY_PREFERENCE_STORAGE_KEY, QualitySelector, SeekBar, type StoredQualityPreference, TextTrackSelector, type UsePlayerControlsOptions, type UsePlayerControlsResult, type WatermarkPosition, ZOOM_STEPS, formatPlaybackTime, matchQualityPreference, nextZoom, preferenceFromSelection, randomFirstShowDelay, randomWatermarkDelay, randomWatermarkPosition, readQualityPreference, resolvePlayerOverlay, resolveVisiblePlaybackRates, snapPlaybackRate, usePlaybackWatermark, usePlayerControls, writeQualityPreference };
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
1
3
|
// src/NsgVideoPlayerWithControls.tsx
|
|
2
4
|
import {
|
|
3
|
-
|
|
5
|
+
forwardRef,
|
|
6
|
+
useEffect as useEffect7,
|
|
7
|
+
useImperativeHandle,
|
|
4
8
|
useMemo as useMemo2,
|
|
5
|
-
useRef as
|
|
9
|
+
useRef as useRef6
|
|
6
10
|
} from "react";
|
|
7
11
|
import {
|
|
8
12
|
mergePlayerConfig,
|
|
@@ -86,6 +90,62 @@ function nextZoom(current, direction) {
|
|
|
86
90
|
return ZOOM_STEPS[next] ?? 1;
|
|
87
91
|
}
|
|
88
92
|
|
|
93
|
+
// src/utils/qualityPreference.ts
|
|
94
|
+
var QUALITY_PREFERENCE_STORAGE_KEY = "nsg-player:quality-preference";
|
|
95
|
+
function readQualityPreference() {
|
|
96
|
+
if (typeof window === "undefined" || !window.localStorage) {
|
|
97
|
+
return "auto";
|
|
98
|
+
}
|
|
99
|
+
try {
|
|
100
|
+
const raw = window.localStorage.getItem(QUALITY_PREFERENCE_STORAGE_KEY);
|
|
101
|
+
if (!raw) {
|
|
102
|
+
return "auto";
|
|
103
|
+
}
|
|
104
|
+
if (raw === "auto") {
|
|
105
|
+
return "auto";
|
|
106
|
+
}
|
|
107
|
+
const parsed = JSON.parse(raw);
|
|
108
|
+
if (parsed && typeof parsed === "object" && "height" in parsed && typeof parsed.height === "number" && Number.isFinite(parsed.height) && parsed.height > 0) {
|
|
109
|
+
return { height: parsed.height };
|
|
110
|
+
}
|
|
111
|
+
} catch {
|
|
112
|
+
}
|
|
113
|
+
return "auto";
|
|
114
|
+
}
|
|
115
|
+
function writeQualityPreference(preference) {
|
|
116
|
+
if (typeof window === "undefined" || !window.localStorage) {
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
try {
|
|
120
|
+
if (preference === "auto") {
|
|
121
|
+
window.localStorage.setItem(QUALITY_PREFERENCE_STORAGE_KEY, "auto");
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
window.localStorage.setItem(
|
|
125
|
+
QUALITY_PREFERENCE_STORAGE_KEY,
|
|
126
|
+
JSON.stringify({ height: preference.height })
|
|
127
|
+
);
|
|
128
|
+
} catch {
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
function matchQualityPreference(preference, levels) {
|
|
132
|
+
if (preference === "auto" || levels.length === 0) {
|
|
133
|
+
return "auto";
|
|
134
|
+
}
|
|
135
|
+
const match = levels.find((level) => level.height === preference.height);
|
|
136
|
+
return match ? match.index : "auto";
|
|
137
|
+
}
|
|
138
|
+
function preferenceFromSelection(selection, levels) {
|
|
139
|
+
if (selection === "auto") {
|
|
140
|
+
return "auto";
|
|
141
|
+
}
|
|
142
|
+
const level = levels.find((item) => item.index === selection);
|
|
143
|
+
if (!level || level.height <= 0) {
|
|
144
|
+
return "auto";
|
|
145
|
+
}
|
|
146
|
+
return { height: level.height };
|
|
147
|
+
}
|
|
148
|
+
|
|
89
149
|
// src/hooks/usePlayerControls.ts
|
|
90
150
|
function usePlayerControls(options) {
|
|
91
151
|
const { player, config, containerRef } = options;
|
|
@@ -119,10 +179,21 @@ function usePlayerControls(options) {
|
|
|
119
179
|
player.setFullscreenElement(containerRef.current);
|
|
120
180
|
}
|
|
121
181
|
const syncTracks = () => {
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
182
|
+
const levels = player.getAvailableQualities();
|
|
183
|
+
setQualities(levels);
|
|
184
|
+
let selection = player.getQuality();
|
|
185
|
+
if (config.controls.persistQualityPreference && levels.length > 0) {
|
|
186
|
+
const preferred = matchQualityPreference(
|
|
187
|
+
readQualityPreference(),
|
|
188
|
+
levels
|
|
189
|
+
);
|
|
190
|
+
if (preferred !== selection) {
|
|
191
|
+
player.setQuality(preferred);
|
|
192
|
+
selection = preferred;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
setQualitySelection(selection);
|
|
196
|
+
setActiveLevel(typeof selection === "number" ? selection : -1);
|
|
126
197
|
setTextTracks(player.getTextTracks());
|
|
127
198
|
setSelectedTextTrack(player.getSelectedTextTrack());
|
|
128
199
|
setAudioTracks(player.getAudioTracks());
|
|
@@ -196,7 +267,7 @@ function usePlayerControls(options) {
|
|
|
196
267
|
for (const off of offs) off();
|
|
197
268
|
document.removeEventListener("fullscreenchange", onFs);
|
|
198
269
|
};
|
|
199
|
-
}, [player, containerRef]);
|
|
270
|
+
}, [player, containerRef, config.controls.persistQualityPreference]);
|
|
200
271
|
const togglePlay = useCallback(() => {
|
|
201
272
|
if (!player) return;
|
|
202
273
|
if (player.getState() === "playing") {
|
|
@@ -245,8 +316,16 @@ function usePlayerControls(options) {
|
|
|
245
316
|
const setQuality = useCallback(
|
|
246
317
|
(selection) => {
|
|
247
318
|
player?.setQuality(selection);
|
|
319
|
+
if (config.controls.persistQualityPreference) {
|
|
320
|
+
writeQualityPreference(
|
|
321
|
+
preferenceFromSelection(
|
|
322
|
+
selection,
|
|
323
|
+
player?.getAvailableQualities() ?? []
|
|
324
|
+
)
|
|
325
|
+
);
|
|
326
|
+
}
|
|
248
327
|
},
|
|
249
|
-
[player]
|
|
328
|
+
[player, config.controls.persistQualityPreference]
|
|
250
329
|
);
|
|
251
330
|
const setTextTrack = useCallback(
|
|
252
331
|
(selection) => {
|
|
@@ -661,13 +740,15 @@ function SeekBar({
|
|
|
661
740
|
duration,
|
|
662
741
|
bufferedEnd,
|
|
663
742
|
onSeek,
|
|
664
|
-
seekInputRef
|
|
743
|
+
seekInputRef,
|
|
744
|
+
getSeekPreview
|
|
665
745
|
}) {
|
|
666
746
|
const trackRef = useRef3(null);
|
|
667
747
|
const [hover, setHover] = useState4(INITIAL_HOVER);
|
|
668
748
|
const max = duration > 0 ? duration : 0;
|
|
669
749
|
const bufferedPct = max > 0 ? Math.min(100, bufferedEnd / max * 100) : 0;
|
|
670
750
|
const playedPct = max > 0 ? Math.min(100, currentTime / max * 100) : 0;
|
|
751
|
+
const previewUrl = hover.visible && getSeekPreview ? getSeekPreview(hover.time) : null;
|
|
671
752
|
const updateHover = useCallback2(
|
|
672
753
|
(clientX) => {
|
|
673
754
|
const track = trackRef.current;
|
|
@@ -729,13 +810,24 @@ function SeekBar({
|
|
|
729
810
|
style: { width: `${playedPct}%` }
|
|
730
811
|
}
|
|
731
812
|
),
|
|
732
|
-
hover.visible && max > 0 ? /* @__PURE__ */
|
|
813
|
+
hover.visible && max > 0 ? /* @__PURE__ */ jsxs6(
|
|
733
814
|
"div",
|
|
734
815
|
{
|
|
735
816
|
className: "nsg-player-seek__tooltip",
|
|
736
817
|
style: { left: `${hover.percent}%` },
|
|
737
818
|
role: "tooltip",
|
|
738
|
-
children:
|
|
819
|
+
children: [
|
|
820
|
+
previewUrl ? /* @__PURE__ */ jsx8(
|
|
821
|
+
"img",
|
|
822
|
+
{
|
|
823
|
+
className: "nsg-player-seek__preview",
|
|
824
|
+
src: previewUrl,
|
|
825
|
+
alt: "",
|
|
826
|
+
draggable: false
|
|
827
|
+
}
|
|
828
|
+
) : null,
|
|
829
|
+
formatPlaybackTime(hover.time)
|
|
830
|
+
]
|
|
739
831
|
}
|
|
740
832
|
) : null,
|
|
741
833
|
/* @__PURE__ */ jsx8(
|
|
@@ -825,7 +917,8 @@ function PlayerControlBar(props) {
|
|
|
825
917
|
onToggleFullscreen,
|
|
826
918
|
onZoomIn,
|
|
827
919
|
onZoomOut,
|
|
828
|
-
seekBarRef
|
|
920
|
+
seekBarRef,
|
|
921
|
+
getSeekPreview
|
|
829
922
|
} = props;
|
|
830
923
|
const controls = config.controls;
|
|
831
924
|
const showZoom = config.player.zoomEnabled && controls.showZoom;
|
|
@@ -844,7 +937,8 @@ function PlayerControlBar(props) {
|
|
|
844
937
|
duration,
|
|
845
938
|
bufferedEnd,
|
|
846
939
|
onSeek,
|
|
847
|
-
seekInputRef: seekBarRef
|
|
940
|
+
seekInputRef: seekBarRef,
|
|
941
|
+
getSeekPreview
|
|
848
942
|
}
|
|
849
943
|
),
|
|
850
944
|
/* @__PURE__ */ jsxs8("div", { className: "nsg-player-control-row", children: [
|
|
@@ -1053,7 +1147,8 @@ function PlayerChrome({
|
|
|
1053
1147
|
config,
|
|
1054
1148
|
containerRef,
|
|
1055
1149
|
videoSlot,
|
|
1056
|
-
className
|
|
1150
|
+
className,
|
|
1151
|
+
getSeekPreview
|
|
1057
1152
|
}) {
|
|
1058
1153
|
const rootRef = useRef4(null);
|
|
1059
1154
|
const seekBarRef = useRef4(null);
|
|
@@ -1237,7 +1332,8 @@ function PlayerChrome({
|
|
|
1237
1332
|
onToggleFullscreen: () => void controls.toggleFullscreen(),
|
|
1238
1333
|
onZoomIn: controls.zoomIn,
|
|
1239
1334
|
onZoomOut: controls.zoomOut,
|
|
1240
|
-
seekBarRef
|
|
1335
|
+
seekBarRef,
|
|
1336
|
+
getSeekPreview
|
|
1241
1337
|
}
|
|
1242
1338
|
) : null
|
|
1243
1339
|
]
|
|
@@ -1245,11 +1341,117 @@ function PlayerChrome({
|
|
|
1245
1341
|
);
|
|
1246
1342
|
}
|
|
1247
1343
|
|
|
1344
|
+
// src/hooks/usePlaybackWatermark.ts
|
|
1345
|
+
import { useEffect as useEffect6, useRef as useRef5, useState as useState6 } from "react";
|
|
1346
|
+
|
|
1347
|
+
// src/utils/watermarkSchedule.ts
|
|
1348
|
+
var WATERMARK_TOP_MIN_PCT = 8;
|
|
1349
|
+
var WATERMARK_TOP_MAX_PCT = 70;
|
|
1350
|
+
var WATERMARK_LEFT_MIN_PCT = 5;
|
|
1351
|
+
var WATERMARK_LEFT_MAX_PCT = 70;
|
|
1352
|
+
var WATERMARK_FIRST_SHOW_MIN_MS = 3e3;
|
|
1353
|
+
var WATERMARK_FIRST_SHOW_MAX_MS = 8e3;
|
|
1354
|
+
function randomInRange(min, max, random = Math.random) {
|
|
1355
|
+
if (max <= min) {
|
|
1356
|
+
return min;
|
|
1357
|
+
}
|
|
1358
|
+
return min + random() * (max - min);
|
|
1359
|
+
}
|
|
1360
|
+
function randomWatermarkPosition(random = Math.random) {
|
|
1361
|
+
const topPct = WATERMARK_TOP_MIN_PCT + random() * (WATERMARK_TOP_MAX_PCT - WATERMARK_TOP_MIN_PCT);
|
|
1362
|
+
const leftPct = WATERMARK_LEFT_MIN_PCT + random() * (WATERMARK_LEFT_MAX_PCT - WATERMARK_LEFT_MIN_PCT);
|
|
1363
|
+
return { topPct, leftPct };
|
|
1364
|
+
}
|
|
1365
|
+
function randomWatermarkDelay(maxMs, random = Math.random) {
|
|
1366
|
+
if (!Number.isFinite(maxMs) || maxMs <= 0) {
|
|
1367
|
+
return 0;
|
|
1368
|
+
}
|
|
1369
|
+
return Math.min(maxMs, Math.floor(random() * (maxMs + 1)));
|
|
1370
|
+
}
|
|
1371
|
+
function randomFirstShowDelay(random = Math.random) {
|
|
1372
|
+
return Math.floor(
|
|
1373
|
+
randomInRange(
|
|
1374
|
+
WATERMARK_FIRST_SHOW_MIN_MS,
|
|
1375
|
+
WATERMARK_FIRST_SHOW_MAX_MS,
|
|
1376
|
+
random
|
|
1377
|
+
)
|
|
1378
|
+
);
|
|
1379
|
+
}
|
|
1380
|
+
|
|
1381
|
+
// src/hooks/usePlaybackWatermark.ts
|
|
1382
|
+
var HIDDEN = {
|
|
1383
|
+
visible: false,
|
|
1384
|
+
topPct: 0,
|
|
1385
|
+
leftPct: 0
|
|
1386
|
+
};
|
|
1387
|
+
function usePlaybackWatermark({
|
|
1388
|
+
enabled,
|
|
1389
|
+
label,
|
|
1390
|
+
active,
|
|
1391
|
+
durationMs,
|
|
1392
|
+
intervalMaxMs,
|
|
1393
|
+
reducedMotion = false
|
|
1394
|
+
}) {
|
|
1395
|
+
const [state, setState] = useState6(HIDDEN);
|
|
1396
|
+
const showTimerRef = useRef5(null);
|
|
1397
|
+
const hideTimerRef = useRef5(null);
|
|
1398
|
+
const generationRef = useRef5(0);
|
|
1399
|
+
useEffect6(() => {
|
|
1400
|
+
const clearTimers = () => {
|
|
1401
|
+
if (showTimerRef.current !== null) {
|
|
1402
|
+
window.clearTimeout(showTimerRef.current);
|
|
1403
|
+
showTimerRef.current = null;
|
|
1404
|
+
}
|
|
1405
|
+
if (hideTimerRef.current !== null) {
|
|
1406
|
+
window.clearTimeout(hideTimerRef.current);
|
|
1407
|
+
hideTimerRef.current = null;
|
|
1408
|
+
}
|
|
1409
|
+
};
|
|
1410
|
+
generationRef.current += 1;
|
|
1411
|
+
const generation = generationRef.current;
|
|
1412
|
+
clearTimers();
|
|
1413
|
+
setState(HIDDEN);
|
|
1414
|
+
if (!enabled || !label || !active) {
|
|
1415
|
+
return () => {
|
|
1416
|
+
clearTimers();
|
|
1417
|
+
};
|
|
1418
|
+
}
|
|
1419
|
+
if (reducedMotion) {
|
|
1420
|
+
setState({ visible: true, topPct: 12, leftPct: 8 });
|
|
1421
|
+
return () => {
|
|
1422
|
+
clearTimers();
|
|
1423
|
+
};
|
|
1424
|
+
}
|
|
1425
|
+
const scheduleShow = (delayMs) => {
|
|
1426
|
+
showTimerRef.current = window.setTimeout(() => {
|
|
1427
|
+
if (generation !== generationRef.current) {
|
|
1428
|
+
return;
|
|
1429
|
+
}
|
|
1430
|
+
const position = randomWatermarkPosition();
|
|
1431
|
+
setState({ visible: true, ...position });
|
|
1432
|
+
hideTimerRef.current = window.setTimeout(() => {
|
|
1433
|
+
if (generation !== generationRef.current) {
|
|
1434
|
+
return;
|
|
1435
|
+
}
|
|
1436
|
+
setState(HIDDEN);
|
|
1437
|
+
scheduleShow(randomWatermarkDelay(intervalMaxMs));
|
|
1438
|
+
}, durationMs);
|
|
1439
|
+
}, delayMs);
|
|
1440
|
+
};
|
|
1441
|
+
scheduleShow(randomFirstShowDelay());
|
|
1442
|
+
return () => {
|
|
1443
|
+
generationRef.current += 1;
|
|
1444
|
+
clearTimers();
|
|
1445
|
+
};
|
|
1446
|
+
}, [enabled, label, active, durationMs, intervalMaxMs, reducedMotion]);
|
|
1447
|
+
return state;
|
|
1448
|
+
}
|
|
1449
|
+
|
|
1248
1450
|
// src/NsgVideoPlayerWithControls.tsx
|
|
1249
1451
|
import { jsx as jsx13, jsxs as jsxs11 } from "react/jsx-runtime";
|
|
1250
|
-
|
|
1251
|
-
const containerRef =
|
|
1252
|
-
const onWatchTimeRef =
|
|
1452
|
+
var NsgVideoPlayerWithControls = forwardRef(function NsgVideoPlayerWithControls2(props, ref) {
|
|
1453
|
+
const containerRef = useRef6(null);
|
|
1454
|
+
const onWatchTimeRef = useRef6(props.onWatchTime);
|
|
1253
1455
|
onWatchTimeRef.current = props.onWatchTime;
|
|
1254
1456
|
const resolvedConfig = useMemo2(
|
|
1255
1457
|
() => mergePlayerConfig({
|
|
@@ -1267,10 +1469,15 @@ function NsgVideoPlayerWithControls(props) {
|
|
|
1267
1469
|
playback: props.playback,
|
|
1268
1470
|
sourceUrl: props.sourceUrl,
|
|
1269
1471
|
config: resolvedConfig,
|
|
1472
|
+
analytics: props.analytics,
|
|
1270
1473
|
onReady: props.onReady,
|
|
1271
|
-
onError: props.onError
|
|
1474
|
+
onError: props.onError,
|
|
1475
|
+
onPlay: props.onPlay,
|
|
1476
|
+
onPause: props.onPause,
|
|
1477
|
+
onAuthError: props.onAuthError
|
|
1272
1478
|
});
|
|
1273
|
-
|
|
1479
|
+
useImperativeHandle(ref, () => player, [player]);
|
|
1480
|
+
useEffect7(() => {
|
|
1274
1481
|
if (!player) return;
|
|
1275
1482
|
const report = () => {
|
|
1276
1483
|
const t = player.getCurrentTime();
|
|
@@ -1278,9 +1485,7 @@ function NsgVideoPlayerWithControls(props) {
|
|
|
1278
1485
|
};
|
|
1279
1486
|
const offs = [
|
|
1280
1487
|
player.on("pause", report),
|
|
1281
|
-
player.on("ended", report)
|
|
1282
|
-
player.on("play", () => props.onPlay?.()),
|
|
1283
|
-
player.on("pause", () => props.onPause?.())
|
|
1488
|
+
player.on("ended", report)
|
|
1284
1489
|
];
|
|
1285
1490
|
const onBeforeUnload = () => report();
|
|
1286
1491
|
window.addEventListener("beforeunload", onBeforeUnload);
|
|
@@ -1288,7 +1493,16 @@ function NsgVideoPlayerWithControls(props) {
|
|
|
1288
1493
|
for (const off of offs) off();
|
|
1289
1494
|
window.removeEventListener("beforeunload", onBeforeUnload);
|
|
1290
1495
|
};
|
|
1291
|
-
}, [player
|
|
1496
|
+
}, [player]);
|
|
1497
|
+
const watermarkActive = state === "playing" || state === "paused" || state === "buffering";
|
|
1498
|
+
const watermark = usePlaybackWatermark({
|
|
1499
|
+
enabled: resolvedConfig.watermark.enabled,
|
|
1500
|
+
label: resolvedConfig.watermark.text?.trim() || null,
|
|
1501
|
+
active: watermarkActive,
|
|
1502
|
+
durationMs: resolvedConfig.watermark.durationMs,
|
|
1503
|
+
intervalMaxMs: resolvedConfig.watermark.intervalMaxMs,
|
|
1504
|
+
reducedMotion: resolvedConfig.accessibility.reducedMotion
|
|
1505
|
+
});
|
|
1292
1506
|
const cssVars = themeToCssVars(resolvedConfig.theme);
|
|
1293
1507
|
const showBootstrap = state === "loading" || state === "idle";
|
|
1294
1508
|
return /* @__PURE__ */ jsxs11(
|
|
@@ -1314,6 +1528,7 @@ function NsgVideoPlayerWithControls(props) {
|
|
|
1314
1528
|
player,
|
|
1315
1529
|
config: resolvedConfig,
|
|
1316
1530
|
containerRef,
|
|
1531
|
+
getSeekPreview: props.getSeekPreview,
|
|
1317
1532
|
videoSlot: /* @__PURE__ */ jsx13(
|
|
1318
1533
|
"video",
|
|
1319
1534
|
{
|
|
@@ -1325,13 +1540,24 @@ function NsgVideoPlayerWithControls(props) {
|
|
|
1325
1540
|
)
|
|
1326
1541
|
}
|
|
1327
1542
|
),
|
|
1328
|
-
|
|
1543
|
+
watermark.visible ? /* @__PURE__ */ jsx13(
|
|
1544
|
+
"div",
|
|
1545
|
+
{
|
|
1546
|
+
className: "nsg-player-watermark",
|
|
1547
|
+
"aria-hidden": true,
|
|
1548
|
+
style: {
|
|
1549
|
+
top: `${watermark.topPct}%`,
|
|
1550
|
+
left: `${watermark.leftPct}%`
|
|
1551
|
+
},
|
|
1552
|
+
children: resolvedConfig.watermark.text
|
|
1553
|
+
}
|
|
1554
|
+
) : null,
|
|
1329
1555
|
error ? /* @__PURE__ */ jsx13("p", { className: "nsg-player-error", role: "alert", children: error.message || "Unable to play this video." }) : null,
|
|
1330
1556
|
showBootstrap && !error ? /* @__PURE__ */ jsx13("p", { className: "nsg-player-status", children: "Loading video\u2026" }) : null
|
|
1331
1557
|
]
|
|
1332
1558
|
}
|
|
1333
1559
|
);
|
|
1334
|
-
}
|
|
1560
|
+
});
|
|
1335
1561
|
export {
|
|
1336
1562
|
AudioTrackSelector,
|
|
1337
1563
|
LiveBadgeButton,
|
|
@@ -1344,15 +1570,24 @@ export {
|
|
|
1344
1570
|
PlayerMenu,
|
|
1345
1571
|
PlayerMenuItem,
|
|
1346
1572
|
PlayerSkipCue,
|
|
1573
|
+
QUALITY_PREFERENCE_STORAGE_KEY,
|
|
1347
1574
|
QualitySelector,
|
|
1348
1575
|
SeekBar,
|
|
1349
1576
|
TextTrackSelector,
|
|
1350
1577
|
ZOOM_STEPS,
|
|
1351
1578
|
formatPlaybackTime,
|
|
1579
|
+
matchQualityPreference,
|
|
1352
1580
|
nextZoom,
|
|
1581
|
+
preferenceFromSelection,
|
|
1582
|
+
randomFirstShowDelay,
|
|
1583
|
+
randomWatermarkDelay,
|
|
1584
|
+
randomWatermarkPosition,
|
|
1585
|
+
readQualityPreference,
|
|
1353
1586
|
resolvePlayerOverlay,
|
|
1354
1587
|
resolveVisiblePlaybackRates,
|
|
1355
1588
|
snapPlaybackRate,
|
|
1356
|
-
|
|
1589
|
+
usePlaybackWatermark,
|
|
1590
|
+
usePlayerControls,
|
|
1591
|
+
writeQualityPreference
|
|
1357
1592
|
};
|
|
1358
1593
|
//# sourceMappingURL=index.js.map
|