@codenkay/video-nsgplayer-react 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +5 -0
- package/LICENSE +21 -0
- package/README.md +24 -0
- package/dist/index.cjs +190 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +48 -0
- package/dist/index.d.ts +48 -0
- package/dist/index.js +172 -0
- package/dist/index.js.map +1 -0
- package/package.json +40 -0
package/CHANGELOG.md
ADDED
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) NSG Player
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# @codenkay/video-nsgplayer-react
|
|
2
|
+
|
|
3
|
+
React adapter for `@codenkay/video-nsgplayer-core`.
|
|
4
|
+
|
|
5
|
+
```tsx
|
|
6
|
+
import { VideoPlayer } from "@codenkay/video-nsgplayer-react";
|
|
7
|
+
|
|
8
|
+
<VideoPlayer
|
|
9
|
+
videoId="123"
|
|
10
|
+
auth={{ getToken: (ctx) => fetch("/api/auth-token", { method: "POST", body: JSON.stringify(ctx) }).then(r => r.json()) }}
|
|
11
|
+
playback={{
|
|
12
|
+
getSource: ({ videoId }) => fetch(`/api/videos/${videoId}/signed-url`).then(r => r.json()),
|
|
13
|
+
refreshSource: ({ videoId }) => fetch(`/api/videos/${videoId}/proxy-refresh`, { method: "POST" }).then(r => r.json()),
|
|
14
|
+
}}
|
|
15
|
+
config={{
|
|
16
|
+
player: { autoplay: true, startMuted: true },
|
|
17
|
+
controls: { showQuality: true },
|
|
18
|
+
theme: { seekProgressColor: "#38bdf8" },
|
|
19
|
+
watermark: { text: "user@corp" },
|
|
20
|
+
}}
|
|
21
|
+
/>
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Works in Next.js App Router as a Client Component (`"use client"`).
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
VideoPlayer: () => VideoPlayer,
|
|
24
|
+
useVideoPlayer: () => useVideoPlayer
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(index_exports);
|
|
27
|
+
|
|
28
|
+
// src/VideoPlayer.tsx
|
|
29
|
+
var import_video_nsgplayer_core = require("@codenkay/video-nsgplayer-core");
|
|
30
|
+
var import_react = require("react");
|
|
31
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
32
|
+
var VideoPlayer = (0, import_react.forwardRef)(
|
|
33
|
+
function VideoPlayer2(props, ref) {
|
|
34
|
+
const videoRef = (0, import_react.useRef)(null);
|
|
35
|
+
const containerRef = (0, import_react.useRef)(null);
|
|
36
|
+
const playerRef = (0, import_react.useRef)(null);
|
|
37
|
+
const generationRef = (0, import_react.useRef)(0);
|
|
38
|
+
const [state, setState] = (0, import_react.useState)("idle");
|
|
39
|
+
const [resolvedConfig, setResolvedConfig] = (0, import_react.useState)(
|
|
40
|
+
() => (0, import_video_nsgplayer_core.mergePlayerConfig)(props.config)
|
|
41
|
+
);
|
|
42
|
+
(0, import_react.useImperativeHandle)(ref, () => playerRef.current, [state]);
|
|
43
|
+
(0, import_react.useEffect)(() => {
|
|
44
|
+
const el = videoRef.current;
|
|
45
|
+
if (!el) return;
|
|
46
|
+
const generation = ++generationRef.current;
|
|
47
|
+
const nextConfig = (0, import_video_nsgplayer_core.mergePlayerConfig)(props.config);
|
|
48
|
+
setResolvedConfig(nextConfig);
|
|
49
|
+
const options = {
|
|
50
|
+
videoId: props.videoId,
|
|
51
|
+
mount: el,
|
|
52
|
+
auth: props.auth,
|
|
53
|
+
playback: props.playback,
|
|
54
|
+
sourceUrl: props.sourceUrl,
|
|
55
|
+
player: nextConfig.player,
|
|
56
|
+
controls: nextConfig.controls,
|
|
57
|
+
theme: nextConfig.theme,
|
|
58
|
+
watermark: nextConfig.watermark,
|
|
59
|
+
streaming: nextConfig.streaming,
|
|
60
|
+
logging: nextConfig.logging,
|
|
61
|
+
debug: nextConfig.debug,
|
|
62
|
+
accessibility: nextConfig.accessibility
|
|
63
|
+
};
|
|
64
|
+
const player = (0, import_video_nsgplayer_core.createVideoPlayer)(options);
|
|
65
|
+
playerRef.current = player;
|
|
66
|
+
const unsubs = [
|
|
67
|
+
player.on("statechange", ({ state: s }) => {
|
|
68
|
+
if (generation !== generationRef.current) return;
|
|
69
|
+
setState(s);
|
|
70
|
+
}),
|
|
71
|
+
player.on("ready", () => props.onReady?.()),
|
|
72
|
+
player.on("error", (err) => props.onError?.(err)),
|
|
73
|
+
player.on("play", () => props.onPlay?.()),
|
|
74
|
+
player.on("pause", () => props.onPause?.()),
|
|
75
|
+
player.on("autherror", (err) => props.onAuthError?.(err))
|
|
76
|
+
];
|
|
77
|
+
return () => {
|
|
78
|
+
for (const off of unsubs) off();
|
|
79
|
+
player.destroy();
|
|
80
|
+
if (playerRef.current === player) playerRef.current = null;
|
|
81
|
+
};
|
|
82
|
+
}, [props.videoId, props.sourceUrl]);
|
|
83
|
+
(0, import_react.useEffect)(() => {
|
|
84
|
+
const next = (0, import_video_nsgplayer_core.mergePlayerConfig)(props.config);
|
|
85
|
+
setResolvedConfig(next);
|
|
86
|
+
playerRef.current?.updateConfig(props.config);
|
|
87
|
+
}, [props.config]);
|
|
88
|
+
const cssVars = (0, import_video_nsgplayer_core.themeToCssVars)(resolvedConfig.theme);
|
|
89
|
+
const headless = !resolvedConfig.controls.enabled;
|
|
90
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
91
|
+
"div",
|
|
92
|
+
{
|
|
93
|
+
ref: containerRef,
|
|
94
|
+
"data-player-theme": true,
|
|
95
|
+
"data-player-state": state,
|
|
96
|
+
className: props.className,
|
|
97
|
+
style: {
|
|
98
|
+
position: "relative",
|
|
99
|
+
width: "100%",
|
|
100
|
+
background: "#000",
|
|
101
|
+
...cssVars,
|
|
102
|
+
...props.style
|
|
103
|
+
},
|
|
104
|
+
children: [
|
|
105
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
106
|
+
"video",
|
|
107
|
+
{
|
|
108
|
+
ref: videoRef,
|
|
109
|
+
playsInline: true,
|
|
110
|
+
style: { width: "100%", height: "100%", display: "block" }
|
|
111
|
+
}
|
|
112
|
+
),
|
|
113
|
+
!headless && props.children,
|
|
114
|
+
!headless && resolvedConfig.watermark.enabled && resolvedConfig.watermark.text && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
115
|
+
"div",
|
|
116
|
+
{
|
|
117
|
+
"aria-hidden": true,
|
|
118
|
+
style: {
|
|
119
|
+
position: "absolute",
|
|
120
|
+
top: "12%",
|
|
121
|
+
left: "8%",
|
|
122
|
+
color: "rgba(255,255,255,0.55)",
|
|
123
|
+
fontSize: 12,
|
|
124
|
+
pointerEvents: "none",
|
|
125
|
+
userSelect: "none"
|
|
126
|
+
},
|
|
127
|
+
children: resolvedConfig.watermark.text
|
|
128
|
+
}
|
|
129
|
+
)
|
|
130
|
+
]
|
|
131
|
+
}
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
);
|
|
135
|
+
function useVideoPlayer(options) {
|
|
136
|
+
const [player, setPlayer] = (0, import_react.useState)(null);
|
|
137
|
+
const [state, setState] = (0, import_react.useState)("idle");
|
|
138
|
+
const [error, setError] = (0, import_react.useState)(null);
|
|
139
|
+
const videoRef = (0, import_react.useRef)(null);
|
|
140
|
+
(0, import_react.useEffect)(() => {
|
|
141
|
+
const el = videoRef.current;
|
|
142
|
+
if (!el) return;
|
|
143
|
+
const config = (0, import_video_nsgplayer_core.mergePlayerConfig)(options.config);
|
|
144
|
+
const instance = (0, import_video_nsgplayer_core.createVideoPlayer)({
|
|
145
|
+
videoId: options.videoId,
|
|
146
|
+
mount: el,
|
|
147
|
+
auth: options.auth,
|
|
148
|
+
playback: options.playback,
|
|
149
|
+
sourceUrl: options.sourceUrl,
|
|
150
|
+
player: config.player,
|
|
151
|
+
controls: config.controls,
|
|
152
|
+
theme: config.theme,
|
|
153
|
+
watermark: config.watermark,
|
|
154
|
+
streaming: config.streaming,
|
|
155
|
+
logging: config.logging,
|
|
156
|
+
debug: config.debug,
|
|
157
|
+
accessibility: config.accessibility
|
|
158
|
+
});
|
|
159
|
+
setPlayer(instance);
|
|
160
|
+
const offs = [
|
|
161
|
+
instance.on("statechange", ({ state: s }) => setState(s)),
|
|
162
|
+
instance.on("error", (err) => setError(err)),
|
|
163
|
+
instance.on("ready", () => options.onReady?.())
|
|
164
|
+
];
|
|
165
|
+
return () => {
|
|
166
|
+
for (const off of offs) off();
|
|
167
|
+
instance.destroy();
|
|
168
|
+
setPlayer(null);
|
|
169
|
+
};
|
|
170
|
+
}, [options.videoId, options.sourceUrl]);
|
|
171
|
+
return {
|
|
172
|
+
videoRef,
|
|
173
|
+
player,
|
|
174
|
+
state,
|
|
175
|
+
error,
|
|
176
|
+
play: () => player?.play(),
|
|
177
|
+
pause: () => player?.pause(),
|
|
178
|
+
seek: (t) => player?.seek(t),
|
|
179
|
+
goToLive: () => player?.goToLive(),
|
|
180
|
+
isLive: () => player?.isLive() ?? false,
|
|
181
|
+
isAtLiveEdge: () => player?.isAtLiveEdge() ?? true,
|
|
182
|
+
destroy: () => player?.destroy()
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
186
|
+
0 && (module.exports = {
|
|
187
|
+
VideoPlayer,
|
|
188
|
+
useVideoPlayer
|
|
189
|
+
});
|
|
190
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/VideoPlayer.tsx"],"sourcesContent":["export {\n VideoPlayer,\n useVideoPlayer,\n type VideoPlayerProps,\n type VideoPlayerHandle,\n type UseVideoPlayerOptions,\n} from \"./VideoPlayer\";\n","\"use client\";\n\nimport {\n createVideoPlayer,\n mergePlayerConfig,\n themeToCssVars,\n type AuthConfig,\n type CreateVideoPlayerOptions,\n type PlaybackCredentialConfig,\n type PlayerConfig,\n type PlayerState,\n type VideoPlayer as CorePlayer,\n} from \"@codenkay/video-nsgplayer-core\";\nimport {\n useEffect,\n useImperativeHandle,\n useRef,\n useState,\n forwardRef,\n type CSSProperties,\n type ReactNode,\n} from \"react\";\n\nexport type VideoPlayerHandle = CorePlayer;\n\nexport type VideoPlayerProps = {\n videoId?: string;\n auth?: AuthConfig;\n playback?: PlaybackCredentialConfig;\n sourceUrl?: string;\n config?: Parameters<typeof mergePlayerConfig>[0];\n className?: string;\n style?: CSSProperties;\n children?: ReactNode;\n onReady?: () => void;\n onError?: (error: { code: string; message: string; fatal: boolean }) => void;\n onPlay?: () => void;\n onPause?: () => void;\n onAuthError?: (error: { message: string; retryable: boolean }) => void;\n};\n\nexport const VideoPlayer = forwardRef<VideoPlayerHandle, VideoPlayerProps>(\n function VideoPlayer(props, ref) {\n const videoRef = useRef<HTMLVideoElement | null>(null);\n const containerRef = useRef<HTMLDivElement | null>(null);\n const playerRef = useRef<CorePlayer | null>(null);\n const generationRef = useRef(0);\n const [state, setState] = useState<PlayerState>(\"idle\");\n const [resolvedConfig, setResolvedConfig] = useState<PlayerConfig>(() =>\n mergePlayerConfig(props.config),\n );\n\n useImperativeHandle(ref, () => playerRef.current as CorePlayer, [state]);\n\n useEffect(() => {\n const el = videoRef.current;\n if (!el) return;\n\n const generation = ++generationRef.current;\n const nextConfig = mergePlayerConfig(props.config);\n setResolvedConfig(nextConfig);\n\n const options: CreateVideoPlayerOptions = {\n videoId: props.videoId,\n mount: el,\n auth: props.auth,\n playback: props.playback,\n sourceUrl: props.sourceUrl,\n player: nextConfig.player,\n controls: nextConfig.controls,\n theme: nextConfig.theme,\n watermark: nextConfig.watermark,\n streaming: nextConfig.streaming,\n logging: nextConfig.logging,\n debug: nextConfig.debug,\n accessibility: nextConfig.accessibility,\n };\n\n const player = createVideoPlayer(options);\n playerRef.current = player;\n\n const unsubs = [\n player.on(\"statechange\", ({ state: s }) => {\n if (generation !== generationRef.current) return;\n setState(s);\n }),\n player.on(\"ready\", () => props.onReady?.()),\n player.on(\"error\", (err) => props.onError?.(err)),\n player.on(\"play\", () => props.onPlay?.()),\n player.on(\"pause\", () => props.onPause?.()),\n player.on(\"autherror\", (err) => props.onAuthError?.(err)),\n ];\n\n return () => {\n for (const off of unsubs) off();\n player.destroy();\n if (playerRef.current === player) playerRef.current = null;\n };\n // Recreate when identity of source/auth changes\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [props.videoId, props.sourceUrl]);\n\n useEffect(() => {\n const next = mergePlayerConfig(props.config);\n setResolvedConfig(next);\n playerRef.current?.updateConfig(props.config);\n }, [props.config]);\n\n const cssVars = themeToCssVars(resolvedConfig.theme) as CSSProperties;\n const headless = !resolvedConfig.controls.enabled;\n\n return (\n <div\n ref={containerRef}\n data-player-theme\n data-player-state={state}\n className={props.className}\n style={{\n position: \"relative\",\n width: \"100%\",\n background: \"#000\",\n ...cssVars,\n ...props.style,\n }}\n >\n <video\n ref={videoRef}\n playsInline\n style={{ width: \"100%\", height: \"100%\", display: \"block\" }}\n />\n {!headless && props.children}\n {!headless &&\n resolvedConfig.watermark.enabled &&\n resolvedConfig.watermark.text && (\n <div\n aria-hidden\n style={{\n position: \"absolute\",\n top: \"12%\",\n left: \"8%\",\n color: \"rgba(255,255,255,0.55)\",\n fontSize: 12,\n pointerEvents: \"none\",\n userSelect: \"none\",\n }}\n >\n {resolvedConfig.watermark.text}\n </div>\n )}\n </div>\n );\n },\n);\n\nexport type UseVideoPlayerOptions = Omit<VideoPlayerProps, \"className\" | \"style\" | \"children\">;\n\nexport function useVideoPlayer(options: UseVideoPlayerOptions) {\n const [player, setPlayer] = useState<CorePlayer | null>(null);\n const [state, setState] = useState<PlayerState>(\"idle\");\n const [error, setError] = useState<{\n code: string;\n message: string;\n } | null>(null);\n const videoRef = useRef<HTMLVideoElement | null>(null);\n\n useEffect(() => {\n const el = videoRef.current;\n if (!el) return;\n const config = mergePlayerConfig(options.config);\n const instance = createVideoPlayer({\n videoId: options.videoId,\n mount: el,\n auth: options.auth,\n playback: options.playback,\n sourceUrl: options.sourceUrl,\n player: config.player,\n controls: config.controls,\n theme: config.theme,\n watermark: config.watermark,\n streaming: config.streaming,\n logging: config.logging,\n debug: config.debug,\n accessibility: config.accessibility,\n });\n setPlayer(instance);\n const offs = [\n instance.on(\"statechange\", ({ state: s }) => setState(s)),\n instance.on(\"error\", (err) => setError(err)),\n instance.on(\"ready\", () => options.onReady?.()),\n ];\n return () => {\n for (const off of offs) off();\n instance.destroy();\n setPlayer(null);\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [options.videoId, options.sourceUrl]);\n\n return {\n videoRef,\n player,\n state,\n error,\n play: () => player?.play(),\n pause: () => player?.pause(),\n seek: (t: number) => player?.seek(t),\n goToLive: () => player?.goToLive(),\n isLive: () => player?.isLive() ?? false,\n isAtLiveEdge: () => player?.isAtLiveEdge() ?? true,\n destroy: () => player?.destroy(),\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACEA,kCAUO;AACP,mBAQO;AA2FD;AAvEC,IAAM,kBAAc;AAAA,EACzB,SAASA,aAAY,OAAO,KAAK;AAC/B,UAAM,eAAW,qBAAgC,IAAI;AACrD,UAAM,mBAAe,qBAA8B,IAAI;AACvD,UAAM,gBAAY,qBAA0B,IAAI;AAChD,UAAM,oBAAgB,qBAAO,CAAC;AAC9B,UAAM,CAAC,OAAO,QAAQ,QAAI,uBAAsB,MAAM;A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,IAC9C,SAAS,MAAM,QAAQ,QAAQ;AAAA,EACjC;AACF;","names":["VideoPlayer"]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import * as _codenkay_video_nsgplayer_core from '@codenkay/video-nsgplayer-core';
|
|
2
|
+
import { AuthConfig, PlaybackCredentialConfig, mergePlayerConfig, VideoPlayer as VideoPlayer$1, PlayerState } from '@codenkay/video-nsgplayer-core';
|
|
3
|
+
import * as react from 'react';
|
|
4
|
+
import { CSSProperties, ReactNode } from 'react';
|
|
5
|
+
|
|
6
|
+
type VideoPlayerHandle = VideoPlayer$1;
|
|
7
|
+
type VideoPlayerProps = {
|
|
8
|
+
videoId?: string;
|
|
9
|
+
auth?: AuthConfig;
|
|
10
|
+
playback?: PlaybackCredentialConfig;
|
|
11
|
+
sourceUrl?: string;
|
|
12
|
+
config?: Parameters<typeof mergePlayerConfig>[0];
|
|
13
|
+
className?: string;
|
|
14
|
+
style?: CSSProperties;
|
|
15
|
+
children?: ReactNode;
|
|
16
|
+
onReady?: () => void;
|
|
17
|
+
onError?: (error: {
|
|
18
|
+
code: string;
|
|
19
|
+
message: string;
|
|
20
|
+
fatal: boolean;
|
|
21
|
+
}) => void;
|
|
22
|
+
onPlay?: () => void;
|
|
23
|
+
onPause?: () => void;
|
|
24
|
+
onAuthError?: (error: {
|
|
25
|
+
message: string;
|
|
26
|
+
retryable: boolean;
|
|
27
|
+
}) => void;
|
|
28
|
+
};
|
|
29
|
+
declare const VideoPlayer: react.ForwardRefExoticComponent<VideoPlayerProps & react.RefAttributes<VideoPlayer$1>>;
|
|
30
|
+
type UseVideoPlayerOptions = Omit<VideoPlayerProps, "className" | "style" | "children">;
|
|
31
|
+
declare function useVideoPlayer(options: UseVideoPlayerOptions): {
|
|
32
|
+
videoRef: react.RefObject<HTMLVideoElement | null>;
|
|
33
|
+
player: VideoPlayer$1 | null;
|
|
34
|
+
state: PlayerState;
|
|
35
|
+
error: {
|
|
36
|
+
code: string;
|
|
37
|
+
message: string;
|
|
38
|
+
} | null;
|
|
39
|
+
play: () => Promise<void> | undefined;
|
|
40
|
+
pause: () => void | undefined;
|
|
41
|
+
seek: (t: number) => void | undefined;
|
|
42
|
+
goToLive: () => _codenkay_video_nsgplayer_core.SeekToLiveResult | undefined;
|
|
43
|
+
isLive: () => boolean;
|
|
44
|
+
isAtLiveEdge: () => boolean;
|
|
45
|
+
destroy: () => void | undefined;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export { type UseVideoPlayerOptions, VideoPlayer, type VideoPlayerHandle, type VideoPlayerProps, useVideoPlayer };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import * as _codenkay_video_nsgplayer_core from '@codenkay/video-nsgplayer-core';
|
|
2
|
+
import { AuthConfig, PlaybackCredentialConfig, mergePlayerConfig, VideoPlayer as VideoPlayer$1, PlayerState } from '@codenkay/video-nsgplayer-core';
|
|
3
|
+
import * as react from 'react';
|
|
4
|
+
import { CSSProperties, ReactNode } from 'react';
|
|
5
|
+
|
|
6
|
+
type VideoPlayerHandle = VideoPlayer$1;
|
|
7
|
+
type VideoPlayerProps = {
|
|
8
|
+
videoId?: string;
|
|
9
|
+
auth?: AuthConfig;
|
|
10
|
+
playback?: PlaybackCredentialConfig;
|
|
11
|
+
sourceUrl?: string;
|
|
12
|
+
config?: Parameters<typeof mergePlayerConfig>[0];
|
|
13
|
+
className?: string;
|
|
14
|
+
style?: CSSProperties;
|
|
15
|
+
children?: ReactNode;
|
|
16
|
+
onReady?: () => void;
|
|
17
|
+
onError?: (error: {
|
|
18
|
+
code: string;
|
|
19
|
+
message: string;
|
|
20
|
+
fatal: boolean;
|
|
21
|
+
}) => void;
|
|
22
|
+
onPlay?: () => void;
|
|
23
|
+
onPause?: () => void;
|
|
24
|
+
onAuthError?: (error: {
|
|
25
|
+
message: string;
|
|
26
|
+
retryable: boolean;
|
|
27
|
+
}) => void;
|
|
28
|
+
};
|
|
29
|
+
declare const VideoPlayer: react.ForwardRefExoticComponent<VideoPlayerProps & react.RefAttributes<VideoPlayer$1>>;
|
|
30
|
+
type UseVideoPlayerOptions = Omit<VideoPlayerProps, "className" | "style" | "children">;
|
|
31
|
+
declare function useVideoPlayer(options: UseVideoPlayerOptions): {
|
|
32
|
+
videoRef: react.RefObject<HTMLVideoElement | null>;
|
|
33
|
+
player: VideoPlayer$1 | null;
|
|
34
|
+
state: PlayerState;
|
|
35
|
+
error: {
|
|
36
|
+
code: string;
|
|
37
|
+
message: string;
|
|
38
|
+
} | null;
|
|
39
|
+
play: () => Promise<void> | undefined;
|
|
40
|
+
pause: () => void | undefined;
|
|
41
|
+
seek: (t: number) => void | undefined;
|
|
42
|
+
goToLive: () => _codenkay_video_nsgplayer_core.SeekToLiveResult | undefined;
|
|
43
|
+
isLive: () => boolean;
|
|
44
|
+
isAtLiveEdge: () => boolean;
|
|
45
|
+
destroy: () => void | undefined;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export { type UseVideoPlayerOptions, VideoPlayer, type VideoPlayerHandle, type VideoPlayerProps, useVideoPlayer };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
// src/VideoPlayer.tsx
|
|
2
|
+
import {
|
|
3
|
+
createVideoPlayer,
|
|
4
|
+
mergePlayerConfig,
|
|
5
|
+
themeToCssVars
|
|
6
|
+
} from "@codenkay/video-nsgplayer-core";
|
|
7
|
+
import {
|
|
8
|
+
useEffect,
|
|
9
|
+
useImperativeHandle,
|
|
10
|
+
useRef,
|
|
11
|
+
useState,
|
|
12
|
+
forwardRef
|
|
13
|
+
} from "react";
|
|
14
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
15
|
+
var VideoPlayer = forwardRef(
|
|
16
|
+
function VideoPlayer2(props, ref) {
|
|
17
|
+
const videoRef = useRef(null);
|
|
18
|
+
const containerRef = useRef(null);
|
|
19
|
+
const playerRef = useRef(null);
|
|
20
|
+
const generationRef = useRef(0);
|
|
21
|
+
const [state, setState] = useState("idle");
|
|
22
|
+
const [resolvedConfig, setResolvedConfig] = useState(
|
|
23
|
+
() => mergePlayerConfig(props.config)
|
|
24
|
+
);
|
|
25
|
+
useImperativeHandle(ref, () => playerRef.current, [state]);
|
|
26
|
+
useEffect(() => {
|
|
27
|
+
const el = videoRef.current;
|
|
28
|
+
if (!el) return;
|
|
29
|
+
const generation = ++generationRef.current;
|
|
30
|
+
const nextConfig = mergePlayerConfig(props.config);
|
|
31
|
+
setResolvedConfig(nextConfig);
|
|
32
|
+
const options = {
|
|
33
|
+
videoId: props.videoId,
|
|
34
|
+
mount: el,
|
|
35
|
+
auth: props.auth,
|
|
36
|
+
playback: props.playback,
|
|
37
|
+
sourceUrl: props.sourceUrl,
|
|
38
|
+
player: nextConfig.player,
|
|
39
|
+
controls: nextConfig.controls,
|
|
40
|
+
theme: nextConfig.theme,
|
|
41
|
+
watermark: nextConfig.watermark,
|
|
42
|
+
streaming: nextConfig.streaming,
|
|
43
|
+
logging: nextConfig.logging,
|
|
44
|
+
debug: nextConfig.debug,
|
|
45
|
+
accessibility: nextConfig.accessibility
|
|
46
|
+
};
|
|
47
|
+
const player = createVideoPlayer(options);
|
|
48
|
+
playerRef.current = player;
|
|
49
|
+
const unsubs = [
|
|
50
|
+
player.on("statechange", ({ state: s }) => {
|
|
51
|
+
if (generation !== generationRef.current) return;
|
|
52
|
+
setState(s);
|
|
53
|
+
}),
|
|
54
|
+
player.on("ready", () => props.onReady?.()),
|
|
55
|
+
player.on("error", (err) => props.onError?.(err)),
|
|
56
|
+
player.on("play", () => props.onPlay?.()),
|
|
57
|
+
player.on("pause", () => props.onPause?.()),
|
|
58
|
+
player.on("autherror", (err) => props.onAuthError?.(err))
|
|
59
|
+
];
|
|
60
|
+
return () => {
|
|
61
|
+
for (const off of unsubs) off();
|
|
62
|
+
player.destroy();
|
|
63
|
+
if (playerRef.current === player) playerRef.current = null;
|
|
64
|
+
};
|
|
65
|
+
}, [props.videoId, props.sourceUrl]);
|
|
66
|
+
useEffect(() => {
|
|
67
|
+
const next = mergePlayerConfig(props.config);
|
|
68
|
+
setResolvedConfig(next);
|
|
69
|
+
playerRef.current?.updateConfig(props.config);
|
|
70
|
+
}, [props.config]);
|
|
71
|
+
const cssVars = themeToCssVars(resolvedConfig.theme);
|
|
72
|
+
const headless = !resolvedConfig.controls.enabled;
|
|
73
|
+
return /* @__PURE__ */ jsxs(
|
|
74
|
+
"div",
|
|
75
|
+
{
|
|
76
|
+
ref: containerRef,
|
|
77
|
+
"data-player-theme": true,
|
|
78
|
+
"data-player-state": state,
|
|
79
|
+
className: props.className,
|
|
80
|
+
style: {
|
|
81
|
+
position: "relative",
|
|
82
|
+
width: "100%",
|
|
83
|
+
background: "#000",
|
|
84
|
+
...cssVars,
|
|
85
|
+
...props.style
|
|
86
|
+
},
|
|
87
|
+
children: [
|
|
88
|
+
/* @__PURE__ */ jsx(
|
|
89
|
+
"video",
|
|
90
|
+
{
|
|
91
|
+
ref: videoRef,
|
|
92
|
+
playsInline: true,
|
|
93
|
+
style: { width: "100%", height: "100%", display: "block" }
|
|
94
|
+
}
|
|
95
|
+
),
|
|
96
|
+
!headless && props.children,
|
|
97
|
+
!headless && resolvedConfig.watermark.enabled && resolvedConfig.watermark.text && /* @__PURE__ */ jsx(
|
|
98
|
+
"div",
|
|
99
|
+
{
|
|
100
|
+
"aria-hidden": true,
|
|
101
|
+
style: {
|
|
102
|
+
position: "absolute",
|
|
103
|
+
top: "12%",
|
|
104
|
+
left: "8%",
|
|
105
|
+
color: "rgba(255,255,255,0.55)",
|
|
106
|
+
fontSize: 12,
|
|
107
|
+
pointerEvents: "none",
|
|
108
|
+
userSelect: "none"
|
|
109
|
+
},
|
|
110
|
+
children: resolvedConfig.watermark.text
|
|
111
|
+
}
|
|
112
|
+
)
|
|
113
|
+
]
|
|
114
|
+
}
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
);
|
|
118
|
+
function useVideoPlayer(options) {
|
|
119
|
+
const [player, setPlayer] = useState(null);
|
|
120
|
+
const [state, setState] = useState("idle");
|
|
121
|
+
const [error, setError] = useState(null);
|
|
122
|
+
const videoRef = useRef(null);
|
|
123
|
+
useEffect(() => {
|
|
124
|
+
const el = videoRef.current;
|
|
125
|
+
if (!el) return;
|
|
126
|
+
const config = mergePlayerConfig(options.config);
|
|
127
|
+
const instance = createVideoPlayer({
|
|
128
|
+
videoId: options.videoId,
|
|
129
|
+
mount: el,
|
|
130
|
+
auth: options.auth,
|
|
131
|
+
playback: options.playback,
|
|
132
|
+
sourceUrl: options.sourceUrl,
|
|
133
|
+
player: config.player,
|
|
134
|
+
controls: config.controls,
|
|
135
|
+
theme: config.theme,
|
|
136
|
+
watermark: config.watermark,
|
|
137
|
+
streaming: config.streaming,
|
|
138
|
+
logging: config.logging,
|
|
139
|
+
debug: config.debug,
|
|
140
|
+
accessibility: config.accessibility
|
|
141
|
+
});
|
|
142
|
+
setPlayer(instance);
|
|
143
|
+
const offs = [
|
|
144
|
+
instance.on("statechange", ({ state: s }) => setState(s)),
|
|
145
|
+
instance.on("error", (err) => setError(err)),
|
|
146
|
+
instance.on("ready", () => options.onReady?.())
|
|
147
|
+
];
|
|
148
|
+
return () => {
|
|
149
|
+
for (const off of offs) off();
|
|
150
|
+
instance.destroy();
|
|
151
|
+
setPlayer(null);
|
|
152
|
+
};
|
|
153
|
+
}, [options.videoId, options.sourceUrl]);
|
|
154
|
+
return {
|
|
155
|
+
videoRef,
|
|
156
|
+
player,
|
|
157
|
+
state,
|
|
158
|
+
error,
|
|
159
|
+
play: () => player?.play(),
|
|
160
|
+
pause: () => player?.pause(),
|
|
161
|
+
seek: (t) => player?.seek(t),
|
|
162
|
+
goToLive: () => player?.goToLive(),
|
|
163
|
+
isLive: () => player?.isLive() ?? false,
|
|
164
|
+
isAtLiveEdge: () => player?.isAtLiveEdge() ?? true,
|
|
165
|
+
destroy: () => player?.destroy()
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
export {
|
|
169
|
+
VideoPlayer,
|
|
170
|
+
useVideoPlayer
|
|
171
|
+
};
|
|
172
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/VideoPlayer.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n createVideoPlayer,\n mergePlayerConfig,\n themeToCssVars,\n type AuthConfig,\n type CreateVideoPlayerOptions,\n type PlaybackCredentialConfig,\n type PlayerConfig,\n type PlayerState,\n type VideoPlayer as CorePlayer,\n} from \"@codenkay/video-nsgplayer-core\";\nimport {\n useEffect,\n useImperativeHandle,\n useRef,\n useState,\n forwardRef,\n type CSSProperties,\n type ReactNode,\n} from \"react\";\n\nexport type VideoPlayerHandle = CorePlayer;\n\nexport type VideoPlayerProps = {\n videoId?: string;\n auth?: AuthConfig;\n playback?: PlaybackCredentialConfig;\n sourceUrl?: string;\n config?: Parameters<typeof mergePlayerConfig>[0];\n className?: string;\n style?: CSSProperties;\n children?: ReactNode;\n onReady?: () => void;\n onError?: (error: { code: string; message: string; fatal: boolean }) => void;\n onPlay?: () => void;\n onPause?: () => void;\n onAuthError?: (error: { message: string; retryable: boolean }) => void;\n};\n\nexport const VideoPlayer = forwardRef<VideoPlayerHandle, VideoPlayerProps>(\n function VideoPlayer(props, ref) {\n const videoRef = useRef<HTMLVideoElement | null>(null);\n const containerRef = useRef<HTMLDivElement | null>(null);\n const playerRef = useRef<CorePlayer | null>(null);\n const generationRef = useRef(0);\n const [state, setState] = useState<PlayerState>(\"idle\");\n const [resolvedConfig, setResolvedConfig] = useState<PlayerConfig>(() =>\n mergePlayerConfig(props.config),\n );\n\n useImperativeHandle(ref, () => playerRef.current as CorePlayer, [state]);\n\n useEffect(() => {\n const el = videoRef.current;\n if (!el) return;\n\n const generation = ++generationRef.current;\n const nextConfig = mergePlayerConfig(props.config);\n setResolvedConfig(nextConfig);\n\n const options: CreateVideoPlayerOptions = {\n videoId: props.videoId,\n mount: el,\n auth: props.auth,\n playback: props.playback,\n sourceUrl: props.sourceUrl,\n player: nextConfig.player,\n controls: nextConfig.controls,\n theme: nextConfig.theme,\n watermark: nextConfig.watermark,\n streaming: nextConfig.streaming,\n logging: nextConfig.logging,\n debug: nextConfig.debug,\n accessibility: nextConfig.accessibility,\n };\n\n const player = createVideoPlayer(options);\n playerRef.current = player;\n\n const unsubs = [\n player.on(\"statechange\", ({ state: s }) => {\n if (generation !== generationRef.current) return;\n setState(s);\n }),\n player.on(\"ready\", () => props.onReady?.()),\n player.on(\"error\", (err) => props.onError?.(err)),\n player.on(\"play\", () => props.onPlay?.()),\n player.on(\"pause\", () => props.onPause?.()),\n player.on(\"autherror\", (err) => props.onAuthError?.(err)),\n ];\n\n return () => {\n for (const off of unsubs) off();\n player.destroy();\n if (playerRef.current === player) playerRef.current = null;\n };\n // Recreate when identity of source/auth changes\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [props.videoId, props.sourceUrl]);\n\n useEffect(() => {\n const next = mergePlayerConfig(props.config);\n setResolvedConfig(next);\n playerRef.current?.updateConfig(props.config);\n }, [props.config]);\n\n const cssVars = themeToCssVars(resolvedConfig.theme) as CSSProperties;\n const headless = !resolvedConfig.controls.enabled;\n\n return (\n <div\n ref={containerRef}\n data-player-theme\n data-player-state={state}\n className={props.className}\n style={{\n position: \"relative\",\n width: \"100%\",\n background: \"#000\",\n ...cssVars,\n ...props.style,\n }}\n >\n <video\n ref={videoRef}\n playsInline\n style={{ width: \"100%\", height: \"100%\", display: \"block\" }}\n />\n {!headless && props.children}\n {!headless &&\n resolvedConfig.watermark.enabled &&\n resolvedConfig.watermark.text && (\n <div\n aria-hidden\n style={{\n position: \"absolute\",\n top: \"12%\",\n left: \"8%\",\n color: \"rgba(255,255,255,0.55)\",\n fontSize: 12,\n pointerEvents: \"none\",\n userSelect: \"none\",\n }}\n >\n {resolvedConfig.watermark.text}\n </div>\n )}\n </div>\n );\n },\n);\n\nexport type UseVideoPlayerOptions = Omit<VideoPlayerProps, \"className\" | \"style\" | \"children\">;\n\nexport function useVideoPlayer(options: UseVideoPlayerOptions) {\n const [player, setPlayer] = useState<CorePlayer | null>(null);\n const [state, setState] = useState<PlayerState>(\"idle\");\n const [error, setError] = useState<{\n code: string;\n message: string;\n } | null>(null);\n const videoRef = useRef<HTMLVideoElement | null>(null);\n\n useEffect(() => {\n const el = videoRef.current;\n if (!el) return;\n const config = mergePlayerConfig(options.config);\n const instance = createVideoPlayer({\n videoId: options.videoId,\n mount: el,\n auth: options.auth,\n playback: options.playback,\n sourceUrl: options.sourceUrl,\n player: config.player,\n controls: config.controls,\n theme: config.theme,\n watermark: config.watermark,\n streaming: config.streaming,\n logging: config.logging,\n debug: config.debug,\n accessibility: config.accessibility,\n });\n setPlayer(instance);\n const offs = [\n instance.on(\"statechange\", ({ state: s }) => setState(s)),\n instance.on(\"error\", (err) => setError(err)),\n instance.on(\"ready\", () => options.onReady?.()),\n ];\n return () => {\n for (const off of offs) off();\n instance.destroy();\n setPlayer(null);\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [options.videoId, options.sourceUrl]);\n\n return {\n videoRef,\n player,\n state,\n error,\n play: () => player?.play(),\n pause: () => player?.pause(),\n seek: (t: number) => player?.seek(t),\n goToLive: () => player?.goToLive(),\n isLive: () => player?.isLive() ?? false,\n isAtLiveEdge: () => player?.isAtLiveEdge() ?? true,\n destroy: () => player?.destroy(),\n };\n}\n"],"mappings":";AAEA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAOK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAGK;AA2FD,SAaE,KAbF;AAvEC,IAAM,cAAc;AAAA,EACzB,SAASA,aAAY,OAAO,KAAK;AAC/B,UAAM,WAAW,OAAgC,IAAI;AACrD,UAAM,eAAe,OAA8B,IAAI;AACvD,UAAM,YAAY,OAA0B,IAAI;AAChD,UAAM,gBAAgB,OAAO,CAAC;AAC9B,UAAM,CAAC,OAAO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,aAAa,KAAK;AAAA,IAC9C,SAAS,MAAM,QAAQ,QAAQ;AAAA,EACjC;AACF;","names":["VideoPlayer"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@codenkay/video-nsgplayer-react",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "React bindings for NSG video player",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "NSG Player",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"main": "./dist/index.cjs",
|
|
9
|
+
"module": "./dist/index.js",
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"import": "./dist/index.js",
|
|
15
|
+
"require": "./dist/index.cjs"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"files": ["dist", "README.md", "LICENSE", "CHANGELOG.md"],
|
|
19
|
+
"sideEffects": false,
|
|
20
|
+
"peerDependencies": {
|
|
21
|
+
"@codenkay/video-nsgplayer-core": "^0.1.0",
|
|
22
|
+
"react": ">=18",
|
|
23
|
+
"react-dom": ">=18"
|
|
24
|
+
},
|
|
25
|
+
"scripts": {
|
|
26
|
+
"build": "tsup src/index.ts --format esm,cjs --dts --clean --sourcemap --external react --external react-dom --external @codenkay/video-nsgplayer-core",
|
|
27
|
+
"typecheck": "tsc --noEmit",
|
|
28
|
+
"test": "vitest run --config vitest.config.ts"
|
|
29
|
+
},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"@codenkay/video-nsgplayer-core": "*",
|
|
32
|
+
"@types/react": "^19",
|
|
33
|
+
"@types/react-dom": "^19",
|
|
34
|
+
"react": "19.2.8",
|
|
35
|
+
"react-dom": "19.2.8",
|
|
36
|
+
"tsup": "^8.5.0",
|
|
37
|
+
"typescript": "^5",
|
|
38
|
+
"vitest": "^4.1.10"
|
|
39
|
+
}
|
|
40
|
+
}
|