@universal-web-video-player/player-react 0.5.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/README.md +50 -0
- package/dist/index.cjs +158 -0
- package/dist/index.d.cts +76 -0
- package/dist/index.d.ts +76 -0
- package/dist/index.js +140 -0
- package/package.json +55 -0
package/README.md
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# @universal-web-video-player/player-react
|
|
2
|
+
|
|
3
|
+
React wrapper for the Universal Video Player.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @universal-web-video-player/player-react @universal-web-video-player/player-web-component
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```tsx
|
|
14
|
+
import { UvpReactPlayer } from '@universal-web-video-player/player-react';
|
|
15
|
+
|
|
16
|
+
function App() {
|
|
17
|
+
return (
|
|
18
|
+
<div style={{ width: '800px', height: '450px' }}>
|
|
19
|
+
<UvpReactPlayer
|
|
20
|
+
sourceUrl="https://example.com/video.mp4"
|
|
21
|
+
autoplay
|
|
22
|
+
muted
|
|
23
|
+
onPlay={() => console.log('Playing!')}
|
|
24
|
+
/>
|
|
25
|
+
</div>
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Props
|
|
31
|
+
|
|
32
|
+
- `sourceUrl`: string
|
|
33
|
+
- `sourceType`: 'mp4' | 'mov' | 'hls' | 'dash'
|
|
34
|
+
- `qualities`: UvpQualityOption[]
|
|
35
|
+
- `autoplay`: boolean
|
|
36
|
+
- `muted`: boolean
|
|
37
|
+
- `poster`: string
|
|
38
|
+
- `controls`: boolean (default true)
|
|
39
|
+
- `playlist`: UvpSourceItem[]
|
|
40
|
+
|
|
41
|
+
## Methods (via Ref)
|
|
42
|
+
|
|
43
|
+
```tsx
|
|
44
|
+
const playerRef = useRef<UvpReactPlayerHandle>(null);
|
|
45
|
+
|
|
46
|
+
// ...
|
|
47
|
+
playerRef.current?.play();
|
|
48
|
+
playerRef.current?.pause();
|
|
49
|
+
playerRef.current?.seek(10);
|
|
50
|
+
```
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
"use client";
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
|
|
21
|
+
// src/index.tsx
|
|
22
|
+
var index_exports = {};
|
|
23
|
+
__export(index_exports, {
|
|
24
|
+
UvpReactPlayer: () => UvpReactPlayer
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(index_exports);
|
|
27
|
+
var import_player_web_component = require("@universal-web-video-player/player-web-component");
|
|
28
|
+
var import_react = require("react");
|
|
29
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
30
|
+
(0, import_player_web_component.defineUvpPlayerElement)();
|
|
31
|
+
function UvpReactPlayerImpl(props, ref) {
|
|
32
|
+
const elementRef = (0, import_react.useRef)(null);
|
|
33
|
+
(0, import_react.useImperativeHandle)(ref, () => ({
|
|
34
|
+
play: () => elementRef.current?.play() ?? Promise.resolve(),
|
|
35
|
+
pause: () => elementRef.current?.pause(),
|
|
36
|
+
seek: (seconds) => elementRef.current?.seek(seconds),
|
|
37
|
+
next: () => elementRef.current?.next(),
|
|
38
|
+
previous: () => elementRef.current?.previous(),
|
|
39
|
+
seekToLive: () => elementRef.current?.seekToLive(),
|
|
40
|
+
getPlayerState: () => elementRef.current?.getPlayerState(),
|
|
41
|
+
get playbackRate() {
|
|
42
|
+
return elementRef.current?.playbackRate ?? 1;
|
|
43
|
+
},
|
|
44
|
+
set playbackRate(val) {
|
|
45
|
+
if (elementRef.current) elementRef.current.playbackRate = val;
|
|
46
|
+
},
|
|
47
|
+
get volume() {
|
|
48
|
+
return elementRef.current?.volume ?? 1;
|
|
49
|
+
},
|
|
50
|
+
set volume(val) {
|
|
51
|
+
if (elementRef.current) elementRef.current.volume = val;
|
|
52
|
+
},
|
|
53
|
+
get muted() {
|
|
54
|
+
return elementRef.current?.muted ?? false;
|
|
55
|
+
},
|
|
56
|
+
set muted(val) {
|
|
57
|
+
if (elementRef.current) elementRef.current.muted = val;
|
|
58
|
+
},
|
|
59
|
+
get loop() {
|
|
60
|
+
return elementRef.current?.loop ?? false;
|
|
61
|
+
},
|
|
62
|
+
set loop(val) {
|
|
63
|
+
if (elementRef.current) elementRef.current.loop = val;
|
|
64
|
+
},
|
|
65
|
+
get config() {
|
|
66
|
+
return elementRef.current?.config;
|
|
67
|
+
},
|
|
68
|
+
set config(val) {
|
|
69
|
+
if (elementRef.current) elementRef.current.config = val;
|
|
70
|
+
}
|
|
71
|
+
}));
|
|
72
|
+
(0, import_react.useEffect)(() => {
|
|
73
|
+
if (elementRef.current && props.volume !== void 0) {
|
|
74
|
+
elementRef.current.volume = props.volume;
|
|
75
|
+
}
|
|
76
|
+
}, [props.volume]);
|
|
77
|
+
(0, import_react.useEffect)(() => {
|
|
78
|
+
if (elementRef.current && props.playbackRate !== void 0) {
|
|
79
|
+
elementRef.current.playbackRate = props.playbackRate;
|
|
80
|
+
}
|
|
81
|
+
}, [props.playbackRate]);
|
|
82
|
+
(0, import_react.useEffect)(() => {
|
|
83
|
+
if (elementRef.current && props.loop !== void 0) {
|
|
84
|
+
elementRef.current.loop = props.loop;
|
|
85
|
+
}
|
|
86
|
+
}, [props.loop]);
|
|
87
|
+
(0, import_react.useEffect)(() => {
|
|
88
|
+
const element = elementRef.current;
|
|
89
|
+
if (!element) return;
|
|
90
|
+
const listeners = [
|
|
91
|
+
["ready", props.onReady ? (e) => props.onReady?.(e) : void 0],
|
|
92
|
+
["play", props.onPlay ? (e) => props.onPlay?.(e) : void 0],
|
|
93
|
+
["pause", props.onPause ? (e) => props.onPause?.(e) : void 0],
|
|
94
|
+
["ended", props.onEnded ? (e) => props.onEnded?.(e) : void 0],
|
|
95
|
+
["qualitychange", props.onQualityChange ? (e) => props.onQualityChange?.(e) : void 0],
|
|
96
|
+
["error", props.onError ? (e) => props.onError?.(e) : void 0],
|
|
97
|
+
["uvp-state-change", props.onStateChange ? (e) => props.onStateChange?.(e.detail) : void 0]
|
|
98
|
+
];
|
|
99
|
+
listeners.forEach(([name, handler]) => {
|
|
100
|
+
if (handler) element.addEventListener(name, handler);
|
|
101
|
+
});
|
|
102
|
+
return () => {
|
|
103
|
+
listeners.forEach(([name, handler]) => {
|
|
104
|
+
if (handler) element.removeEventListener(name, handler);
|
|
105
|
+
});
|
|
106
|
+
};
|
|
107
|
+
}, [props.onEnded, props.onError, props.onPause, props.onPlay, props.onQualityChange, props.onReady, props.onStateChange]);
|
|
108
|
+
const attributes = (0, import_react.useMemo)(
|
|
109
|
+
() => ({
|
|
110
|
+
"source-url": props.sourceUrl,
|
|
111
|
+
"source-type": props.sourceType,
|
|
112
|
+
"source-qualities": props.qualities && props.qualities.length > 0 ? JSON.stringify(props.qualities) : void 0,
|
|
113
|
+
playlist: props.playlist ? JSON.stringify(props.playlist) : void 0,
|
|
114
|
+
poster: props.poster,
|
|
115
|
+
autoplay: props.autoplay ? "" : void 0,
|
|
116
|
+
muted: props.muted ? "" : void 0,
|
|
117
|
+
controls: props.controls === false ? "false" : void 0,
|
|
118
|
+
"auto-next": props.autoNext ? "true" : void 0,
|
|
119
|
+
"custom-controls": props.customControls ? "true" : void 0,
|
|
120
|
+
"scale-mode": props.scaleMode,
|
|
121
|
+
"hide-settings": props.hideSettings ? "" : void 0,
|
|
122
|
+
"hide-fullscreen": props.hideFullscreen ? "" : void 0,
|
|
123
|
+
"hide-playlist": props.hidePlaylist ? "" : void 0,
|
|
124
|
+
"hide-volume": props.hideVolume ? "" : void 0
|
|
125
|
+
}),
|
|
126
|
+
[
|
|
127
|
+
props.poster,
|
|
128
|
+
props.playlist,
|
|
129
|
+
props.qualities,
|
|
130
|
+
props.sourceType,
|
|
131
|
+
props.sourceUrl,
|
|
132
|
+
props.autoplay,
|
|
133
|
+
props.muted,
|
|
134
|
+
props.controls,
|
|
135
|
+
props.autoNext,
|
|
136
|
+
props.customControls,
|
|
137
|
+
props.scaleMode,
|
|
138
|
+
props.hideSettings,
|
|
139
|
+
props.hideFullscreen,
|
|
140
|
+
props.hidePlaylist,
|
|
141
|
+
props.hideVolume
|
|
142
|
+
]
|
|
143
|
+
);
|
|
144
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
145
|
+
"uvp-player",
|
|
146
|
+
{
|
|
147
|
+
ref: elementRef,
|
|
148
|
+
className: props.className,
|
|
149
|
+
...attributes,
|
|
150
|
+
children: props.children
|
|
151
|
+
}
|
|
152
|
+
);
|
|
153
|
+
}
|
|
154
|
+
var UvpReactPlayer = (0, import_react.forwardRef)(UvpReactPlayerImpl);
|
|
155
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
156
|
+
0 && (module.exports = {
|
|
157
|
+
UvpReactPlayer
|
|
158
|
+
});
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { UvpState, UvpQualityOption, UvpSourceItem, UvpScaleMode } from '@universal-web-video-player/player-core';
|
|
3
|
+
|
|
4
|
+
declare global {
|
|
5
|
+
namespace JSX {
|
|
6
|
+
interface IntrinsicElements {
|
|
7
|
+
"uvp-player": React.DetailedHTMLProps<React.HTMLAttributes<HTMLElement>, HTMLElement> & {
|
|
8
|
+
"source-url"?: string;
|
|
9
|
+
"source-type"?: "mp4" | "mov" | "hls" | "dash";
|
|
10
|
+
"source-qualities"?: string;
|
|
11
|
+
poster?: string;
|
|
12
|
+
autoplay?: boolean | string;
|
|
13
|
+
muted?: boolean | string;
|
|
14
|
+
controls?: boolean | string;
|
|
15
|
+
"auto-next"?: boolean | string;
|
|
16
|
+
loop?: boolean | string;
|
|
17
|
+
"playback-rate"?: number | string;
|
|
18
|
+
volume?: number | string;
|
|
19
|
+
"custom-controls"?: boolean | string;
|
|
20
|
+
playlist?: string;
|
|
21
|
+
"scale-mode"?: string;
|
|
22
|
+
"hide-settings"?: boolean | string;
|
|
23
|
+
"hide-fullscreen"?: boolean | string;
|
|
24
|
+
"hide-playlist"?: boolean | string;
|
|
25
|
+
"hide-volume"?: boolean | string;
|
|
26
|
+
ref?: React.Ref<HTMLElement & UvpReactPlayerHandle>;
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
interface UvpReactPlayerProps {
|
|
32
|
+
sourceUrl?: string;
|
|
33
|
+
sourceType?: "mp4" | "mov" | "hls" | "dash";
|
|
34
|
+
qualities?: UvpQualityOption[];
|
|
35
|
+
autoplay?: boolean;
|
|
36
|
+
muted?: boolean;
|
|
37
|
+
autoNext?: boolean;
|
|
38
|
+
loop?: boolean;
|
|
39
|
+
playbackRate?: number;
|
|
40
|
+
volume?: number;
|
|
41
|
+
customControls?: boolean;
|
|
42
|
+
poster?: string;
|
|
43
|
+
controls?: boolean;
|
|
44
|
+
className?: string;
|
|
45
|
+
playlist?: UvpSourceItem[];
|
|
46
|
+
scaleMode?: UvpScaleMode;
|
|
47
|
+
hideSettings?: boolean;
|
|
48
|
+
hideFullscreen?: boolean;
|
|
49
|
+
hidePlaylist?: boolean;
|
|
50
|
+
hideVolume?: boolean;
|
|
51
|
+
onReady?: (event: CustomEvent) => void;
|
|
52
|
+
onPlay?: (event: CustomEvent) => void;
|
|
53
|
+
onPause?: (event: CustomEvent) => void;
|
|
54
|
+
onEnded?: (event: CustomEvent) => void;
|
|
55
|
+
onQualityChange?: (event: CustomEvent) => void;
|
|
56
|
+
onError?: (event: CustomEvent) => void;
|
|
57
|
+
onStateChange?: (state: UvpState) => void;
|
|
58
|
+
children?: React.ReactNode;
|
|
59
|
+
}
|
|
60
|
+
interface UvpReactPlayerHandle {
|
|
61
|
+
play: () => Promise<void>;
|
|
62
|
+
pause: () => void;
|
|
63
|
+
seek: (seconds: number) => void;
|
|
64
|
+
next: () => void;
|
|
65
|
+
previous: () => void;
|
|
66
|
+
seekToLive: () => void;
|
|
67
|
+
playbackRate: number;
|
|
68
|
+
volume: number;
|
|
69
|
+
muted: boolean;
|
|
70
|
+
loop: boolean;
|
|
71
|
+
config: any;
|
|
72
|
+
getPlayerState: () => UvpState;
|
|
73
|
+
}
|
|
74
|
+
declare const UvpReactPlayer: React.ForwardRefExoticComponent<UvpReactPlayerProps & React.RefAttributes<UvpReactPlayerHandle>>;
|
|
75
|
+
|
|
76
|
+
export { UvpReactPlayer, type UvpReactPlayerHandle, type UvpReactPlayerProps };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { UvpState, UvpQualityOption, UvpSourceItem, UvpScaleMode } from '@universal-web-video-player/player-core';
|
|
3
|
+
|
|
4
|
+
declare global {
|
|
5
|
+
namespace JSX {
|
|
6
|
+
interface IntrinsicElements {
|
|
7
|
+
"uvp-player": React.DetailedHTMLProps<React.HTMLAttributes<HTMLElement>, HTMLElement> & {
|
|
8
|
+
"source-url"?: string;
|
|
9
|
+
"source-type"?: "mp4" | "mov" | "hls" | "dash";
|
|
10
|
+
"source-qualities"?: string;
|
|
11
|
+
poster?: string;
|
|
12
|
+
autoplay?: boolean | string;
|
|
13
|
+
muted?: boolean | string;
|
|
14
|
+
controls?: boolean | string;
|
|
15
|
+
"auto-next"?: boolean | string;
|
|
16
|
+
loop?: boolean | string;
|
|
17
|
+
"playback-rate"?: number | string;
|
|
18
|
+
volume?: number | string;
|
|
19
|
+
"custom-controls"?: boolean | string;
|
|
20
|
+
playlist?: string;
|
|
21
|
+
"scale-mode"?: string;
|
|
22
|
+
"hide-settings"?: boolean | string;
|
|
23
|
+
"hide-fullscreen"?: boolean | string;
|
|
24
|
+
"hide-playlist"?: boolean | string;
|
|
25
|
+
"hide-volume"?: boolean | string;
|
|
26
|
+
ref?: React.Ref<HTMLElement & UvpReactPlayerHandle>;
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
interface UvpReactPlayerProps {
|
|
32
|
+
sourceUrl?: string;
|
|
33
|
+
sourceType?: "mp4" | "mov" | "hls" | "dash";
|
|
34
|
+
qualities?: UvpQualityOption[];
|
|
35
|
+
autoplay?: boolean;
|
|
36
|
+
muted?: boolean;
|
|
37
|
+
autoNext?: boolean;
|
|
38
|
+
loop?: boolean;
|
|
39
|
+
playbackRate?: number;
|
|
40
|
+
volume?: number;
|
|
41
|
+
customControls?: boolean;
|
|
42
|
+
poster?: string;
|
|
43
|
+
controls?: boolean;
|
|
44
|
+
className?: string;
|
|
45
|
+
playlist?: UvpSourceItem[];
|
|
46
|
+
scaleMode?: UvpScaleMode;
|
|
47
|
+
hideSettings?: boolean;
|
|
48
|
+
hideFullscreen?: boolean;
|
|
49
|
+
hidePlaylist?: boolean;
|
|
50
|
+
hideVolume?: boolean;
|
|
51
|
+
onReady?: (event: CustomEvent) => void;
|
|
52
|
+
onPlay?: (event: CustomEvent) => void;
|
|
53
|
+
onPause?: (event: CustomEvent) => void;
|
|
54
|
+
onEnded?: (event: CustomEvent) => void;
|
|
55
|
+
onQualityChange?: (event: CustomEvent) => void;
|
|
56
|
+
onError?: (event: CustomEvent) => void;
|
|
57
|
+
onStateChange?: (state: UvpState) => void;
|
|
58
|
+
children?: React.ReactNode;
|
|
59
|
+
}
|
|
60
|
+
interface UvpReactPlayerHandle {
|
|
61
|
+
play: () => Promise<void>;
|
|
62
|
+
pause: () => void;
|
|
63
|
+
seek: (seconds: number) => void;
|
|
64
|
+
next: () => void;
|
|
65
|
+
previous: () => void;
|
|
66
|
+
seekToLive: () => void;
|
|
67
|
+
playbackRate: number;
|
|
68
|
+
volume: number;
|
|
69
|
+
muted: boolean;
|
|
70
|
+
loop: boolean;
|
|
71
|
+
config: any;
|
|
72
|
+
getPlayerState: () => UvpState;
|
|
73
|
+
}
|
|
74
|
+
declare const UvpReactPlayer: React.ForwardRefExoticComponent<UvpReactPlayerProps & React.RefAttributes<UvpReactPlayerHandle>>;
|
|
75
|
+
|
|
76
|
+
export { UvpReactPlayer, type UvpReactPlayerHandle, type UvpReactPlayerProps };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
// src/index.tsx
|
|
4
|
+
import { defineUvpPlayerElement } from "@universal-web-video-player/player-web-component";
|
|
5
|
+
import {
|
|
6
|
+
forwardRef,
|
|
7
|
+
useEffect,
|
|
8
|
+
useImperativeHandle,
|
|
9
|
+
useMemo,
|
|
10
|
+
useRef
|
|
11
|
+
} from "react";
|
|
12
|
+
import { jsx } from "react/jsx-runtime";
|
|
13
|
+
defineUvpPlayerElement();
|
|
14
|
+
function UvpReactPlayerImpl(props, ref) {
|
|
15
|
+
const elementRef = useRef(null);
|
|
16
|
+
useImperativeHandle(ref, () => ({
|
|
17
|
+
play: () => elementRef.current?.play() ?? Promise.resolve(),
|
|
18
|
+
pause: () => elementRef.current?.pause(),
|
|
19
|
+
seek: (seconds) => elementRef.current?.seek(seconds),
|
|
20
|
+
next: () => elementRef.current?.next(),
|
|
21
|
+
previous: () => elementRef.current?.previous(),
|
|
22
|
+
seekToLive: () => elementRef.current?.seekToLive(),
|
|
23
|
+
getPlayerState: () => elementRef.current?.getPlayerState(),
|
|
24
|
+
get playbackRate() {
|
|
25
|
+
return elementRef.current?.playbackRate ?? 1;
|
|
26
|
+
},
|
|
27
|
+
set playbackRate(val) {
|
|
28
|
+
if (elementRef.current) elementRef.current.playbackRate = val;
|
|
29
|
+
},
|
|
30
|
+
get volume() {
|
|
31
|
+
return elementRef.current?.volume ?? 1;
|
|
32
|
+
},
|
|
33
|
+
set volume(val) {
|
|
34
|
+
if (elementRef.current) elementRef.current.volume = val;
|
|
35
|
+
},
|
|
36
|
+
get muted() {
|
|
37
|
+
return elementRef.current?.muted ?? false;
|
|
38
|
+
},
|
|
39
|
+
set muted(val) {
|
|
40
|
+
if (elementRef.current) elementRef.current.muted = val;
|
|
41
|
+
},
|
|
42
|
+
get loop() {
|
|
43
|
+
return elementRef.current?.loop ?? false;
|
|
44
|
+
},
|
|
45
|
+
set loop(val) {
|
|
46
|
+
if (elementRef.current) elementRef.current.loop = val;
|
|
47
|
+
},
|
|
48
|
+
get config() {
|
|
49
|
+
return elementRef.current?.config;
|
|
50
|
+
},
|
|
51
|
+
set config(val) {
|
|
52
|
+
if (elementRef.current) elementRef.current.config = val;
|
|
53
|
+
}
|
|
54
|
+
}));
|
|
55
|
+
useEffect(() => {
|
|
56
|
+
if (elementRef.current && props.volume !== void 0) {
|
|
57
|
+
elementRef.current.volume = props.volume;
|
|
58
|
+
}
|
|
59
|
+
}, [props.volume]);
|
|
60
|
+
useEffect(() => {
|
|
61
|
+
if (elementRef.current && props.playbackRate !== void 0) {
|
|
62
|
+
elementRef.current.playbackRate = props.playbackRate;
|
|
63
|
+
}
|
|
64
|
+
}, [props.playbackRate]);
|
|
65
|
+
useEffect(() => {
|
|
66
|
+
if (elementRef.current && props.loop !== void 0) {
|
|
67
|
+
elementRef.current.loop = props.loop;
|
|
68
|
+
}
|
|
69
|
+
}, [props.loop]);
|
|
70
|
+
useEffect(() => {
|
|
71
|
+
const element = elementRef.current;
|
|
72
|
+
if (!element) return;
|
|
73
|
+
const listeners = [
|
|
74
|
+
["ready", props.onReady ? (e) => props.onReady?.(e) : void 0],
|
|
75
|
+
["play", props.onPlay ? (e) => props.onPlay?.(e) : void 0],
|
|
76
|
+
["pause", props.onPause ? (e) => props.onPause?.(e) : void 0],
|
|
77
|
+
["ended", props.onEnded ? (e) => props.onEnded?.(e) : void 0],
|
|
78
|
+
["qualitychange", props.onQualityChange ? (e) => props.onQualityChange?.(e) : void 0],
|
|
79
|
+
["error", props.onError ? (e) => props.onError?.(e) : void 0],
|
|
80
|
+
["uvp-state-change", props.onStateChange ? (e) => props.onStateChange?.(e.detail) : void 0]
|
|
81
|
+
];
|
|
82
|
+
listeners.forEach(([name, handler]) => {
|
|
83
|
+
if (handler) element.addEventListener(name, handler);
|
|
84
|
+
});
|
|
85
|
+
return () => {
|
|
86
|
+
listeners.forEach(([name, handler]) => {
|
|
87
|
+
if (handler) element.removeEventListener(name, handler);
|
|
88
|
+
});
|
|
89
|
+
};
|
|
90
|
+
}, [props.onEnded, props.onError, props.onPause, props.onPlay, props.onQualityChange, props.onReady, props.onStateChange]);
|
|
91
|
+
const attributes = useMemo(
|
|
92
|
+
() => ({
|
|
93
|
+
"source-url": props.sourceUrl,
|
|
94
|
+
"source-type": props.sourceType,
|
|
95
|
+
"source-qualities": props.qualities && props.qualities.length > 0 ? JSON.stringify(props.qualities) : void 0,
|
|
96
|
+
playlist: props.playlist ? JSON.stringify(props.playlist) : void 0,
|
|
97
|
+
poster: props.poster,
|
|
98
|
+
autoplay: props.autoplay ? "" : void 0,
|
|
99
|
+
muted: props.muted ? "" : void 0,
|
|
100
|
+
controls: props.controls === false ? "false" : void 0,
|
|
101
|
+
"auto-next": props.autoNext ? "true" : void 0,
|
|
102
|
+
"custom-controls": props.customControls ? "true" : void 0,
|
|
103
|
+
"scale-mode": props.scaleMode,
|
|
104
|
+
"hide-settings": props.hideSettings ? "" : void 0,
|
|
105
|
+
"hide-fullscreen": props.hideFullscreen ? "" : void 0,
|
|
106
|
+
"hide-playlist": props.hidePlaylist ? "" : void 0,
|
|
107
|
+
"hide-volume": props.hideVolume ? "" : void 0
|
|
108
|
+
}),
|
|
109
|
+
[
|
|
110
|
+
props.poster,
|
|
111
|
+
props.playlist,
|
|
112
|
+
props.qualities,
|
|
113
|
+
props.sourceType,
|
|
114
|
+
props.sourceUrl,
|
|
115
|
+
props.autoplay,
|
|
116
|
+
props.muted,
|
|
117
|
+
props.controls,
|
|
118
|
+
props.autoNext,
|
|
119
|
+
props.customControls,
|
|
120
|
+
props.scaleMode,
|
|
121
|
+
props.hideSettings,
|
|
122
|
+
props.hideFullscreen,
|
|
123
|
+
props.hidePlaylist,
|
|
124
|
+
props.hideVolume
|
|
125
|
+
]
|
|
126
|
+
);
|
|
127
|
+
return /* @__PURE__ */ jsx(
|
|
128
|
+
"uvp-player",
|
|
129
|
+
{
|
|
130
|
+
ref: elementRef,
|
|
131
|
+
className: props.className,
|
|
132
|
+
...attributes,
|
|
133
|
+
children: props.children
|
|
134
|
+
}
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
var UvpReactPlayer = forwardRef(UvpReactPlayerImpl);
|
|
138
|
+
export {
|
|
139
|
+
UvpReactPlayer
|
|
140
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@universal-web-video-player/player-react",
|
|
3
|
+
"version": "0.5.0",
|
|
4
|
+
"description": "React wrapper for universal video player",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.cjs",
|
|
7
|
+
"module": "dist/index.js",
|
|
8
|
+
"types": "dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js",
|
|
13
|
+
"require": "./dist/index.cjs"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist"
|
|
18
|
+
],
|
|
19
|
+
"scripts": {
|
|
20
|
+
"build": "tsup src/index.tsx --dts --format esm,cjs --clean",
|
|
21
|
+
"test": "vitest run --environment jsdom",
|
|
22
|
+
"lint": "tsc --noEmit",
|
|
23
|
+
"typecheck": "tsc --noEmit"
|
|
24
|
+
},
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"@universal-web-video-player/player-web-component": "0.5.0",
|
|
27
|
+
"react": "^18.3.1"
|
|
28
|
+
},
|
|
29
|
+
"peerDependencies": {
|
|
30
|
+
"react": ">=18"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"@types/react": "^18.3.5",
|
|
34
|
+
"jsdom": "^26.1.0",
|
|
35
|
+
"tsup": "^8.1.0",
|
|
36
|
+
"typescript": "^5.8.3",
|
|
37
|
+
"vitest": "^2.1.8"
|
|
38
|
+
},
|
|
39
|
+
"license": "MIT",
|
|
40
|
+
"author": "AIPXPERTS",
|
|
41
|
+
"repository": {
|
|
42
|
+
"type": "git",
|
|
43
|
+
"url": "https://github.com/aipxperts/aipxperts-video-player.git",
|
|
44
|
+
"directory": "packages/react"
|
|
45
|
+
},
|
|
46
|
+
"bugs": {
|
|
47
|
+
"url": "https://github.com/aipxperts/aipxperts-video-player/issues"
|
|
48
|
+
},
|
|
49
|
+
"homepage": "https://github.com/aipxperts/aipxperts-video-player#readme",
|
|
50
|
+
"keywords": [
|
|
51
|
+
"video",
|
|
52
|
+
"player",
|
|
53
|
+
"react"
|
|
54
|
+
]
|
|
55
|
+
}
|