@chunkify/player-react 1.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/LICENSE +21 -0
- package/dist/index.d.ts +76 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +96 -0
- package/dist/index.js.map +1 -0
- package/package.json +42 -0
- package/src/index.ts +160 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Chunkify contributors
|
|
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/dist/index.d.ts
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { type CSSProperties, type DOMAttributes, type HTMLAttributes, type ReactElement, type ReactNode, type Ref } from "react";
|
|
2
|
+
import type { ChunkifyPlayer as PlayerElement, PlaybackErrorDetail, PlayerAspectRatio, PlayerCredentials } from "@chunkify/player";
|
|
3
|
+
declare const mediaEvents: {
|
|
4
|
+
readonly onAbort: "abort";
|
|
5
|
+
readonly onCanPlay: "canplay";
|
|
6
|
+
readonly onCanPlayThrough: "canplaythrough";
|
|
7
|
+
readonly onDurationChange: "durationchange";
|
|
8
|
+
readonly onEmptied: "emptied";
|
|
9
|
+
readonly onEnded: "ended";
|
|
10
|
+
readonly onError: "error";
|
|
11
|
+
readonly onLoadedData: "loadeddata";
|
|
12
|
+
readonly onLoadedMetadata: "loadedmetadata";
|
|
13
|
+
readonly onLoadStart: "loadstart";
|
|
14
|
+
readonly onPause: "pause";
|
|
15
|
+
readonly onPlay: "play";
|
|
16
|
+
readonly onPlaying: "playing";
|
|
17
|
+
readonly onProgress: "progress";
|
|
18
|
+
readonly onRateChange: "ratechange";
|
|
19
|
+
readonly onResize: "resize";
|
|
20
|
+
readonly onSeeked: "seeked";
|
|
21
|
+
readonly onSeeking: "seeking";
|
|
22
|
+
readonly onStalled: "stalled";
|
|
23
|
+
readonly onSuspend: "suspend";
|
|
24
|
+
readonly onTimeUpdate: "timeupdate";
|
|
25
|
+
readonly onVolumeChange: "volumechange";
|
|
26
|
+
readonly onWaiting: "waiting";
|
|
27
|
+
readonly onPlaybackError: "playback-error";
|
|
28
|
+
};
|
|
29
|
+
export type ChunkifyPlayerRef = PlayerElement;
|
|
30
|
+
export type PlayerMediaEvent = Event & {
|
|
31
|
+
readonly currentTarget: PlayerElement;
|
|
32
|
+
};
|
|
33
|
+
export type PlayerPlaybackErrorEvent = CustomEvent<PlaybackErrorDetail> & {
|
|
34
|
+
readonly currentTarget: PlayerElement;
|
|
35
|
+
};
|
|
36
|
+
type MediaCallbacks = {
|
|
37
|
+
[K in keyof typeof mediaEvents]?: ((event: K extends "onPlaybackError" ? PlayerPlaybackErrorEvent : PlayerMediaEvent) => void) | undefined;
|
|
38
|
+
};
|
|
39
|
+
export type ChunkifyPlayerStyle = CSSProperties & {
|
|
40
|
+
"--media-object-fit"?: CSSProperties["objectFit"] | undefined;
|
|
41
|
+
"--media-object-position"?: CSSProperties["objectPosition"] | undefined;
|
|
42
|
+
"--play-button"?: CSSProperties["display"] | undefined;
|
|
43
|
+
"--mute-button"?: CSSProperties["display"] | undefined;
|
|
44
|
+
"--captions-button"?: CSSProperties["display"] | undefined;
|
|
45
|
+
"--pip-button"?: CSSProperties["display"] | undefined;
|
|
46
|
+
"--fullscreen-button"?: CSSProperties["display"] | undefined;
|
|
47
|
+
"--airplay-button"?: CSSProperties["display"] | undefined;
|
|
48
|
+
"--cast-button"?: CSSProperties["display"] | undefined;
|
|
49
|
+
};
|
|
50
|
+
type HostProps = Omit<HTMLAttributes<PlayerElement>, keyof DOMAttributes<PlayerElement> | "style"> & {
|
|
51
|
+
style?: ChunkifyPlayerStyle | undefined;
|
|
52
|
+
};
|
|
53
|
+
export type ChunkifyPlayerProps = HostProps & MediaCallbacks & {
|
|
54
|
+
children?: ReactNode | undefined;
|
|
55
|
+
ref?: Ref<ChunkifyPlayerRef> | undefined;
|
|
56
|
+
src?: string | null | undefined;
|
|
57
|
+
poster?: string | null | undefined;
|
|
58
|
+
thumbnails?: string | null | undefined;
|
|
59
|
+
preload?: string | null | undefined;
|
|
60
|
+
crossOrigin?: string | null | undefined;
|
|
61
|
+
credentials?: PlayerCredentials | null | undefined;
|
|
62
|
+
theme?: string | null | undefined;
|
|
63
|
+
aspectRatio?: PlayerAspectRatio | null | undefined;
|
|
64
|
+
primaryColor?: string | null | undefined;
|
|
65
|
+
secondaryColor?: string | null | undefined;
|
|
66
|
+
accentColor?: string | null | undefined;
|
|
67
|
+
autoPlay?: boolean | undefined;
|
|
68
|
+
loop?: boolean | undefined;
|
|
69
|
+
muted?: boolean | undefined;
|
|
70
|
+
autoSeekToLive?: boolean | undefined;
|
|
71
|
+
controls?: boolean | undefined;
|
|
72
|
+
playsInline?: boolean | undefined;
|
|
73
|
+
};
|
|
74
|
+
export declare function ChunkifyPlayer(props: ChunkifyPlayerProps): ReactElement | null;
|
|
75
|
+
export {};
|
|
76
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAOL,KAAK,aAAa,EAClB,KAAK,aAAa,EAClB,KAAK,cAAc,EACnB,KAAK,YAAY,EACjB,KAAK,SAAS,EACd,KAAK,GAAG,EACT,MAAM,OAAO,CAAC;AACf,OAAO,KAAK,EACV,cAAc,IAAI,aAAa,EAC/B,mBAAmB,EACnB,iBAAiB,EACjB,iBAAiB,EAClB,MAAM,kBAAkB,CAAC;AAE1B,QAAA,MAAM,WAAW;aACf,OAAO,EAAE,OAAO;aAChB,SAAS,EAAE,SAAS;aACpB,gBAAgB,EAAE,gBAAgB;aAClC,gBAAgB,EAAE,gBAAgB;aAClC,SAAS,EAAE,SAAS;aACpB,OAAO,EAAE,OAAO;aAChB,OAAO,EAAE,OAAO;aAChB,YAAY,EAAE,YAAY;aAC1B,gBAAgB,EAAE,gBAAgB;aAClC,WAAW,EAAE,WAAW;aACxB,OAAO,EAAE,OAAO;aAChB,MAAM,EAAE,MAAM;aACd,SAAS,EAAE,SAAS;aACpB,UAAU,EAAE,UAAU;aACtB,YAAY,EAAE,YAAY;aAC1B,QAAQ,EAAE,QAAQ;aAClB,QAAQ,EAAE,QAAQ;aAClB,SAAS,EAAE,SAAS;aACpB,SAAS,EAAE,SAAS;aACpB,SAAS,EAAE,SAAS;aACpB,YAAY,EAAE,YAAY;aAC1B,cAAc,EAAE,cAAc;aAC9B,SAAS,EAAE,SAAS;aACpB,eAAe,EAAE,gBAAgB;CACzB,CAAC;AAIX,MAAM,MAAM,iBAAiB,GAAG,aAAa,CAAC;AAC9C,MAAM,MAAM,gBAAgB,GAAG,KAAK,GA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
package/dist/index.js
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { createElement, useCallback, useEffect, useLayoutEffect, useRef, useState, } from "react";
|
|
3
|
+
const mediaEvents = {
|
|
4
|
+
onAbort: "abort",
|
|
5
|
+
onCanPlay: "canplay",
|
|
6
|
+
onCanPlayThrough: "canplaythrough",
|
|
7
|
+
onDurationChange: "durationchange",
|
|
8
|
+
onEmptied: "emptied",
|
|
9
|
+
onEnded: "ended",
|
|
10
|
+
onError: "error",
|
|
11
|
+
onLoadedData: "loadeddata",
|
|
12
|
+
onLoadedMetadata: "loadedmetadata",
|
|
13
|
+
onLoadStart: "loadstart",
|
|
14
|
+
onPause: "pause",
|
|
15
|
+
onPlay: "play",
|
|
16
|
+
onPlaying: "playing",
|
|
17
|
+
onProgress: "progress",
|
|
18
|
+
onRateChange: "ratechange",
|
|
19
|
+
onResize: "resize",
|
|
20
|
+
onSeeked: "seeked",
|
|
21
|
+
onSeeking: "seeking",
|
|
22
|
+
onStalled: "stalled",
|
|
23
|
+
onSuspend: "suspend",
|
|
24
|
+
onTimeUpdate: "timeupdate",
|
|
25
|
+
onVolumeChange: "volumechange",
|
|
26
|
+
onWaiting: "waiting",
|
|
27
|
+
onPlaybackError: "playback-error",
|
|
28
|
+
};
|
|
29
|
+
const callbackNames = Object.keys(mediaEvents);
|
|
30
|
+
export function ChunkifyPlayer(props) {
|
|
31
|
+
const { ref, ...hostProps } = props;
|
|
32
|
+
const elementRef = useRef(null);
|
|
33
|
+
const attachRef = useCallback((element) => {
|
|
34
|
+
elementRef.current = element;
|
|
35
|
+
const cleanup = typeof ref === "function" ? ref(element) : undefined;
|
|
36
|
+
if (ref && typeof ref !== "function")
|
|
37
|
+
ref.current = element;
|
|
38
|
+
return () => {
|
|
39
|
+
elementRef.current = null;
|
|
40
|
+
if (typeof cleanup === "function")
|
|
41
|
+
cleanup();
|
|
42
|
+
else if (typeof ref === "function")
|
|
43
|
+
ref(null);
|
|
44
|
+
else if (ref)
|
|
45
|
+
ref.current = null;
|
|
46
|
+
};
|
|
47
|
+
}, [ref]);
|
|
48
|
+
const [registered, setRegistered] = useState(false);
|
|
49
|
+
const [failure, setFailure] = useState(null);
|
|
50
|
+
useEffect(() => {
|
|
51
|
+
let active = true;
|
|
52
|
+
void import("@chunkify/player").then(() => { if (active)
|
|
53
|
+
setRegistered(true); }, (error) => { if (active)
|
|
54
|
+
setFailure({ error }); });
|
|
55
|
+
return () => { active = false; };
|
|
56
|
+
}, []);
|
|
57
|
+
useLayoutEffect(() => {
|
|
58
|
+
const element = elementRef.current;
|
|
59
|
+
if (!element)
|
|
60
|
+
return;
|
|
61
|
+
const removeListeners = [];
|
|
62
|
+
for (const name of callbackNames) {
|
|
63
|
+
const callback = props[name];
|
|
64
|
+
if (!callback)
|
|
65
|
+
continue;
|
|
66
|
+
const listener = (event) => {
|
|
67
|
+
if (name === "onPlaybackError")
|
|
68
|
+
props[name]?.(event);
|
|
69
|
+
else
|
|
70
|
+
props[name]?.(event);
|
|
71
|
+
};
|
|
72
|
+
element.addEventListener(mediaEvents[name], listener);
|
|
73
|
+
removeListeners.push(() => element.removeEventListener(mediaEvents[name], listener));
|
|
74
|
+
}
|
|
75
|
+
return () => { for (const remove of removeListeners)
|
|
76
|
+
remove(); };
|
|
77
|
+
}, [registered, props]);
|
|
78
|
+
if (failure)
|
|
79
|
+
throw failure.error;
|
|
80
|
+
if (!registered)
|
|
81
|
+
return null;
|
|
82
|
+
const elementProps = {
|
|
83
|
+
...hostProps,
|
|
84
|
+
ref: attachRef,
|
|
85
|
+
autoPlay: props.autoPlay ?? false,
|
|
86
|
+
muted: props.muted ?? false,
|
|
87
|
+
loop: props.loop ?? false,
|
|
88
|
+
playsInline: props.playsInline ?? false,
|
|
89
|
+
controls: props.controls ?? false,
|
|
90
|
+
autoSeekToLive: props.autoSeekToLive ?? false,
|
|
91
|
+
};
|
|
92
|
+
for (const name of callbackNames)
|
|
93
|
+
delete elementProps[name];
|
|
94
|
+
return createElement("chunkify-player", elementProps);
|
|
95
|
+
}
|
|
96
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,EACL,aAAa,EACb,WAAW,EACX,SAAS,EACT,eAAe,EACf,MAAM,EACN,QAAQ,GAOT,MAAM,OAAO,CAAC;AAQf,MAAM,WAAW,GAAG;IAClB,OAAO,EAAE,OAAO;IAChB,SAAS,EAAE,SAAS;IACpB,gBAAgB,EAAE,gBAAgB;IAClC,gBAAgB,EAAE,gBAAgB;IAClC,SAAS,EAAE,SAAS;IACpB,OAAO,EAAE,OAAO;IAChB,OAAO,EAAE,OAAO;IAChB,YAAY,EAAE,YAAY;IAC1B,gBAAgB,EAAE,gBAAgB;IAClC,WAAW,EAAE,WAAW;IACxB,OAAO,EAAE,OAAO;IAChB,MAAM,EAAE,MAAM;IACd,SAAS,EAAE,SAAS;IACpB,UAAU,EAAE,UAAU;IACtB,YAAY,EAAE,YAAY;IAC1B,QAAQ,EAAE,QAAQ;IAClB,QAAQ,EAAE,QAAQ;IAClB,SAAS,EAAE,SAAS;IACpB,SAAS,EAAE,SAAS;IACpB,SAAS,EAAE,SAAS;IACpB,YAAY,EAAE,YAAY;IAC1B,cAAc,EAAE,cAAc;IAC9B,SAAS,EAAE,SAAS;IACpB,eAAe,EAAE,gBAAgB;CACzB,CAAC;AAEX,MAAM,aAAa,GAAG,MAAM,CAAC,IAAI,CAAC,WAAW,CAAoC,CAAC;AAmDlF,MAAM,UAAU,cAAc,CAAC,KAA0B;IACvD,MAAM,EAAE,GAAG,EAAE,GAAG,SAAS,EAAE,GAAG,KAAK,CAAC;IACpC,MAAM,UAAU,GAAG,MAAM,CAAuB,IAAI,CAAC,CAAC;IACtD,MAAM,SAAS,GAAG,WAAW,CAAC,CAAC,OAA6B,EAAE,EAAE;QAC9D,UAA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,CAAC,QAAQ,IAAI,KAAK;QACjC,cAAc,EAAE,KAAK,CAAC,cAAc,IAAI,KAAK;KAC9C,CAAC;IACF,KAAK,MAAM,IAAI,IAAI,aAAa;QAAE,OAAO,YAAY,CAAC,IAAI,CAAC,CAAC;IAC5D,OAAO,aAAa,CAAC,iBAAiB,EAAE,YAAY,CAAC,CAAC;AACxD,CAAC","sourcesContent":["\"use client\";\n\nimport {\n createElement,\n useCallback,\n useEffect,\n useLayoutEffect,\n useRef,\n useState,\n type CSSProperties,\n type DOMAttributes,\n type HTMLAttributes,\n type ReactElement,\n type ReactNode,\n type Ref,\n} from \"react\";\nimport type {\n ChunkifyPlayer as PlayerElement,\n PlaybackErrorDetail,\n PlayerAspectRatio,\n PlayerCredentials,\n} from \"@chunkify/player\";\n\nconst mediaEvents = {\n onAbort: \"abort\",\n onCanPlay: \"canplay\",\n onCanPlayThrough: \"canplaythrough\",\n onDurationChange: \"durationchange\",\n onEmptied: \"emptied\",\n onEnded: \"ended\",\n onError: \"error\",\n onLoadedData: \"loadeddata\",\n onLoadedMetadata: \"loadedmetadata\",\n onLoadStart: \"loadstart\",\n onPause: \"pause\",\n onPlay: \"play\",\n onPlaying: \"playing\",\n onProgress: \"progress\",\n onRateChange: \"ratechange\",\n onResize: \"resize\",\n onSeeked: \"seeked\",\n onSeeking: \"seeking\",\n onStalled: \"stalled\",\n onSuspend: \"suspend\",\n onTimeUpdate: \"timeupdate\",\n onVolumeChange: \"volumechange\",\n onWaiting: \"waiting\",\n onPlaybackError: \"playback-error\",\n} as const;\n\nconst callbackNames = Object.keys(mediaEvents) as Array<keyof typeof mediaEvents>;\n\nexport type ChunkifyPlayerRef = PlayerElement;\nexport type PlayerMediaEvent = Event & { readonly currentTarget: PlayerElement };\nexport type PlayerPlaybackErrorEvent = CustomEvent<PlaybackErrorDetail> & {\n readonly currentTarget: PlayerElement;\n};\ntype MediaCallbacks = {\n [K in keyof typeof mediaEvents]?: ((event: K extends \"onPlaybackError\"\n ? PlayerPlaybackErrorEvent\n : PlayerMediaEvent) => void) | undefined;\n};\n\nexport type ChunkifyPlayerStyle = CSSProperties & {\n \"--media-object-fit\"?: CSSProperties[\"objectFit\"] | undefined;\n \"--media-object-position\"?: CSSProperties[\"objectPosition\"] | undefined;\n \"--play-button\"?: CSSProperties[\"display\"] | undefined;\n \"--mute-button\"?: CSSProperties[\"display\"] | undefined;\n \"--captions-button\"?: CSSProperties[\"display\"] | undefined;\n \"--pip-button\"?: CSSProperties[\"display\"] | undefined;\n \"--fullscreen-button\"?: CSSProperties[\"display\"] | undefined;\n \"--airplay-button\"?: CSSProperties[\"display\"] | undefined;\n \"--cast-button\"?: CSSProperties[\"display\"] | undefined;\n};\ntype HostProps = Omit<\n HTMLAttributes<PlayerElement>,\n keyof DOMAttributes<PlayerElement> | \"style\"\n> & { style?: ChunkifyPlayerStyle | undefined };\n\nexport type ChunkifyPlayerProps = HostProps & MediaCallbacks & {\n children?: ReactNode | undefined;\n ref?: Ref<ChunkifyPlayerRef> | undefined;\n src?: string | null | undefined;\n poster?: string | null | undefined;\n thumbnails?: string | null | undefined;\n preload?: string | null | undefined;\n crossOrigin?: string | null | undefined;\n credentials?: PlayerCredentials | null | undefined;\n theme?: string | null | undefined;\n aspectRatio?: PlayerAspectRatio | null | undefined;\n primaryColor?: string | null | undefined;\n secondaryColor?: string | null | undefined;\n accentColor?: string | null | undefined;\n autoPlay?: boolean | undefined;\n loop?: boolean | undefined;\n muted?: boolean | undefined;\n autoSeekToLive?: boolean | undefined;\n controls?: boolean | undefined;\n playsInline?: boolean | undefined;\n};\n\nexport function ChunkifyPlayer(props: ChunkifyPlayerProps): ReactElement | null {\n const { ref, ...hostProps } = props;\n const elementRef = useRef<PlayerElement | null>(null);\n const attachRef = useCallback((element: PlayerElement | null) => {\n elementRef.current = element;\n const cleanup = typeof ref === \"function\" ? ref(element) : undefined;\n if (ref && typeof ref !== \"function\") ref.current = element;\n return () => {\n elementRef.current = null;\n if (typeof cleanup === \"function\") cleanup();\n else if (typeof ref === \"function\") ref(null);\n else if (ref) ref.current = null;\n };\n }, [ref]);\n const [registered, setRegistered] = useState(false);\n const [failure, setFailure] = useState<{ error: unknown } | null>(null);\n\n useEffect(() => {\n let active = true;\n void import(\"@chunkify/player\").then(\n () => { if (active) setRegistered(true); },\n (error: unknown) => { if (active) setFailure({ error }); },\n );\n return () => { active = false; };\n }, []);\n\n useLayoutEffect(() => {\n const element = elementRef.current;\n if (!element) return;\n const removeListeners: Array<() => void> = [];\n for (const name of callbackNames) {\n const callback = props[name];\n if (!callback) continue;\n const listener = (event: Event) => {\n if (name === \"onPlaybackError\") props[name]?.(event as PlayerPlaybackErrorEvent);\n else props[name]?.(event as PlayerMediaEvent);\n };\n element.addEventListener(mediaEvents[name], listener);\n removeListeners.push(() => element.removeEventListener(mediaEvents[name], listener));\n }\n return () => { for (const remove of removeListeners) remove(); };\n }, [registered, props]);\n\n if (failure) throw failure.error;\n if (!registered) return null;\n\n const elementProps: Record<string, unknown> = {\n ...hostProps,\n ref: attachRef,\n autoPlay: props.autoPlay ?? false,\n muted: props.muted ?? false,\n loop: props.loop ?? false,\n playsInline: props.playsInline ?? false,\n controls: props.controls ?? false,\n autoSeekToLive: props.autoSeekToLive ?? false,\n };\n for (const name of callbackNames) delete elementProps[name];\n return createElement(\"chunkify-player\", elementProps);\n}\n"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@chunkify/player-react",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Typed React wrapper for the Chunkify player Web Component",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/chunkifydev/chunkify-player.git",
|
|
9
|
+
"directory": "packages/player-react"
|
|
10
|
+
},
|
|
11
|
+
"homepage": "https://github.com/chunkifydev/chunkify-player#readme",
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/chunkifydev/chunkify-player/issues"
|
|
14
|
+
},
|
|
15
|
+
"type": "module",
|
|
16
|
+
"files": [
|
|
17
|
+
"dist",
|
|
18
|
+
"src"
|
|
19
|
+
],
|
|
20
|
+
"types": "./dist/index.d.ts",
|
|
21
|
+
"exports": {
|
|
22
|
+
".": {
|
|
23
|
+
"types": "./dist/index.d.ts",
|
|
24
|
+
"import": "./dist/index.js"
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
"publishConfig": {
|
|
28
|
+
"access": "public"
|
|
29
|
+
},
|
|
30
|
+
"scripts": {
|
|
31
|
+
"clean": "node -e \"require('node:fs').rmSync('dist', { recursive: true, force: true })\"",
|
|
32
|
+
"build": "npm run clean && tsc -p tsconfig.json",
|
|
33
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
34
|
+
"prepack": "npm run build"
|
|
35
|
+
},
|
|
36
|
+
"dependencies": {
|
|
37
|
+
"@chunkify/player": "1.0.0"
|
|
38
|
+
},
|
|
39
|
+
"peerDependencies": {
|
|
40
|
+
"react": "^19.0.0"
|
|
41
|
+
}
|
|
42
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
createElement,
|
|
5
|
+
useCallback,
|
|
6
|
+
useEffect,
|
|
7
|
+
useLayoutEffect,
|
|
8
|
+
useRef,
|
|
9
|
+
useState,
|
|
10
|
+
type CSSProperties,
|
|
11
|
+
type DOMAttributes,
|
|
12
|
+
type HTMLAttributes,
|
|
13
|
+
type ReactElement,
|
|
14
|
+
type ReactNode,
|
|
15
|
+
type Ref,
|
|
16
|
+
} from "react";
|
|
17
|
+
import type {
|
|
18
|
+
ChunkifyPlayer as PlayerElement,
|
|
19
|
+
PlaybackErrorDetail,
|
|
20
|
+
PlayerAspectRatio,
|
|
21
|
+
PlayerCredentials,
|
|
22
|
+
} from "@chunkify/player";
|
|
23
|
+
|
|
24
|
+
const mediaEvents = {
|
|
25
|
+
onAbort: "abort",
|
|
26
|
+
onCanPlay: "canplay",
|
|
27
|
+
onCanPlayThrough: "canplaythrough",
|
|
28
|
+
onDurationChange: "durationchange",
|
|
29
|
+
onEmptied: "emptied",
|
|
30
|
+
onEnded: "ended",
|
|
31
|
+
onError: "error",
|
|
32
|
+
onLoadedData: "loadeddata",
|
|
33
|
+
onLoadedMetadata: "loadedmetadata",
|
|
34
|
+
onLoadStart: "loadstart",
|
|
35
|
+
onPause: "pause",
|
|
36
|
+
onPlay: "play",
|
|
37
|
+
onPlaying: "playing",
|
|
38
|
+
onProgress: "progress",
|
|
39
|
+
onRateChange: "ratechange",
|
|
40
|
+
onResize: "resize",
|
|
41
|
+
onSeeked: "seeked",
|
|
42
|
+
onSeeking: "seeking",
|
|
43
|
+
onStalled: "stalled",
|
|
44
|
+
onSuspend: "suspend",
|
|
45
|
+
onTimeUpdate: "timeupdate",
|
|
46
|
+
onVolumeChange: "volumechange",
|
|
47
|
+
onWaiting: "waiting",
|
|
48
|
+
onPlaybackError: "playback-error",
|
|
49
|
+
} as const;
|
|
50
|
+
|
|
51
|
+
const callbackNames = Object.keys(mediaEvents) as Array<keyof typeof mediaEvents>;
|
|
52
|
+
|
|
53
|
+
export type ChunkifyPlayerRef = PlayerElement;
|
|
54
|
+
export type PlayerMediaEvent = Event & { readonly currentTarget: PlayerElement };
|
|
55
|
+
export type PlayerPlaybackErrorEvent = CustomEvent<PlaybackErrorDetail> & {
|
|
56
|
+
readonly currentTarget: PlayerElement;
|
|
57
|
+
};
|
|
58
|
+
type MediaCallbacks = {
|
|
59
|
+
[K in keyof typeof mediaEvents]?: ((event: K extends "onPlaybackError"
|
|
60
|
+
? PlayerPlaybackErrorEvent
|
|
61
|
+
: PlayerMediaEvent) => void) | undefined;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
export type ChunkifyPlayerStyle = CSSProperties & {
|
|
65
|
+
"--media-object-fit"?: CSSProperties["objectFit"] | undefined;
|
|
66
|
+
"--media-object-position"?: CSSProperties["objectPosition"] | undefined;
|
|
67
|
+
"--play-button"?: CSSProperties["display"] | undefined;
|
|
68
|
+
"--mute-button"?: CSSProperties["display"] | undefined;
|
|
69
|
+
"--captions-button"?: CSSProperties["display"] | undefined;
|
|
70
|
+
"--pip-button"?: CSSProperties["display"] | undefined;
|
|
71
|
+
"--fullscreen-button"?: CSSProperties["display"] | undefined;
|
|
72
|
+
"--airplay-button"?: CSSProperties["display"] | undefined;
|
|
73
|
+
"--cast-button"?: CSSProperties["display"] | undefined;
|
|
74
|
+
};
|
|
75
|
+
type HostProps = Omit<
|
|
76
|
+
HTMLAttributes<PlayerElement>,
|
|
77
|
+
keyof DOMAttributes<PlayerElement> | "style"
|
|
78
|
+
> & { style?: ChunkifyPlayerStyle | undefined };
|
|
79
|
+
|
|
80
|
+
export type ChunkifyPlayerProps = HostProps & MediaCallbacks & {
|
|
81
|
+
children?: ReactNode | undefined;
|
|
82
|
+
ref?: Ref<ChunkifyPlayerRef> | undefined;
|
|
83
|
+
src?: string | null | undefined;
|
|
84
|
+
poster?: string | null | undefined;
|
|
85
|
+
thumbnails?: string | null | undefined;
|
|
86
|
+
preload?: string | null | undefined;
|
|
87
|
+
crossOrigin?: string | null | undefined;
|
|
88
|
+
credentials?: PlayerCredentials | null | undefined;
|
|
89
|
+
theme?: string | null | undefined;
|
|
90
|
+
aspectRatio?: PlayerAspectRatio | null | undefined;
|
|
91
|
+
primaryColor?: string | null | undefined;
|
|
92
|
+
secondaryColor?: string | null | undefined;
|
|
93
|
+
accentColor?: string | null | undefined;
|
|
94
|
+
autoPlay?: boolean | undefined;
|
|
95
|
+
loop?: boolean | undefined;
|
|
96
|
+
muted?: boolean | undefined;
|
|
97
|
+
autoSeekToLive?: boolean | undefined;
|
|
98
|
+
controls?: boolean | undefined;
|
|
99
|
+
playsInline?: boolean | undefined;
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
export function ChunkifyPlayer(props: ChunkifyPlayerProps): ReactElement | null {
|
|
103
|
+
const { ref, ...hostProps } = props;
|
|
104
|
+
const elementRef = useRef<PlayerElement | null>(null);
|
|
105
|
+
const attachRef = useCallback((element: PlayerElement | null) => {
|
|
106
|
+
elementRef.current = element;
|
|
107
|
+
const cleanup = typeof ref === "function" ? ref(element) : undefined;
|
|
108
|
+
if (ref && typeof ref !== "function") ref.current = element;
|
|
109
|
+
return () => {
|
|
110
|
+
elementRef.current = null;
|
|
111
|
+
if (typeof cleanup === "function") cleanup();
|
|
112
|
+
else if (typeof ref === "function") ref(null);
|
|
113
|
+
else if (ref) ref.current = null;
|
|
114
|
+
};
|
|
115
|
+
}, [ref]);
|
|
116
|
+
const [registered, setRegistered] = useState(false);
|
|
117
|
+
const [failure, setFailure] = useState<{ error: unknown } | null>(null);
|
|
118
|
+
|
|
119
|
+
useEffect(() => {
|
|
120
|
+
let active = true;
|
|
121
|
+
void import("@chunkify/player").then(
|
|
122
|
+
() => { if (active) setRegistered(true); },
|
|
123
|
+
(error: unknown) => { if (active) setFailure({ error }); },
|
|
124
|
+
);
|
|
125
|
+
return () => { active = false; };
|
|
126
|
+
}, []);
|
|
127
|
+
|
|
128
|
+
useLayoutEffect(() => {
|
|
129
|
+
const element = elementRef.current;
|
|
130
|
+
if (!element) return;
|
|
131
|
+
const removeListeners: Array<() => void> = [];
|
|
132
|
+
for (const name of callbackNames) {
|
|
133
|
+
const callback = props[name];
|
|
134
|
+
if (!callback) continue;
|
|
135
|
+
const listener = (event: Event) => {
|
|
136
|
+
if (name === "onPlaybackError") props[name]?.(event as PlayerPlaybackErrorEvent);
|
|
137
|
+
else props[name]?.(event as PlayerMediaEvent);
|
|
138
|
+
};
|
|
139
|
+
element.addEventListener(mediaEvents[name], listener);
|
|
140
|
+
removeListeners.push(() => element.removeEventListener(mediaEvents[name], listener));
|
|
141
|
+
}
|
|
142
|
+
return () => { for (const remove of removeListeners) remove(); };
|
|
143
|
+
}, [registered, props]);
|
|
144
|
+
|
|
145
|
+
if (failure) throw failure.error;
|
|
146
|
+
if (!registered) return null;
|
|
147
|
+
|
|
148
|
+
const elementProps: Record<string, unknown> = {
|
|
149
|
+
...hostProps,
|
|
150
|
+
ref: attachRef,
|
|
151
|
+
autoPlay: props.autoPlay ?? false,
|
|
152
|
+
muted: props.muted ?? false,
|
|
153
|
+
loop: props.loop ?? false,
|
|
154
|
+
playsInline: props.playsInline ?? false,
|
|
155
|
+
controls: props.controls ?? false,
|
|
156
|
+
autoSeekToLive: props.autoSeekToLive ?? false,
|
|
157
|
+
};
|
|
158
|
+
for (const name of callbackNames) delete elementProps[name];
|
|
159
|
+
return createElement("chunkify-player", elementProps);
|
|
160
|
+
}
|