softbuilders-react-video-player 1.1.72 → 1.1.74
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/dist/components/ControlBar/index.js +1 -0
- package/dist/components/ControlBar/index.js.map +1 -1
- package/dist/components/ControlBar/index.tsx +1 -0
- package/dist/components/CreateNoteMenu/index.d.ts +3 -2
- package/dist/components/CreateNoteMenu/index.js +2 -2
- package/dist/components/CreateNoteMenu/index.js.map +1 -1
- package/dist/components/CreateNoteMenu/index.tsx +1 -1
- package/dist/components/MenuButton/index.js +2 -2
- package/dist/components/MenuButton/index.js.map +1 -1
- package/dist/components/MenuButton/index.tsx +2 -2
- package/dist/components/NoteTooltip/index.js +14 -11
- package/dist/components/NoteTooltip/index.js.map +1 -1
- package/dist/components/NoteTooltip/index.tsx +13 -9
- package/dist/components/SoftBuildersVideoPlayer/index.js +56 -33
- package/dist/components/SoftBuildersVideoPlayer/index.js.map +1 -1
- package/dist/components/SoftBuildersVideoPlayer/index.tsx +81 -41
- package/dist/components/VideoPlayerComponent/index.js +44 -58
- package/dist/components/VideoPlayerComponent/index.js.map +1 -1
- package/dist/components/VideoPlayerComponent/index.tsx +55 -58
- package/dist/components/VolumeSlider/index.js +1 -1
- package/dist/components/VolumeSlider/index.js.map +1 -1
- package/dist/components/VolumeSlider/index.tsx +1 -1
- package/dist/index.mjs +91 -110
- package/package.json +2 -1
package/dist/index.mjs
CHANGED
@@ -31,7 +31,14 @@ var __objRest = (source, exclude) => {
|
|
31
31
|
};
|
32
32
|
|
33
33
|
// src/components/SoftBuildersVideoPlayer/index.tsx
|
34
|
-
import {
|
34
|
+
import {
|
35
|
+
forwardRef as forwardRef2,
|
36
|
+
memo,
|
37
|
+
useCallback as useCallback4,
|
38
|
+
useEffect as useEffect15,
|
39
|
+
useMemo,
|
40
|
+
useState as useState15
|
41
|
+
} from "react";
|
35
42
|
|
36
43
|
// src/components/VideoPlayerComponent/index.tsx
|
37
44
|
import { forwardRef, useEffect as useEffect14, useRef as useRef2, useState as useState14 } from "react";
|
@@ -521,7 +528,7 @@ var VolumeSlider = ({
|
|
521
528
|
const [volume, setVolume] = useState2(0);
|
522
529
|
useEffect2(() => {
|
523
530
|
const updateVolumeState = () => {
|
524
|
-
const currentVolume = (player == null ? void 0 : player.muted()) ? 0 : Number(player == null ? void 0 : player.volume()) * 100;
|
531
|
+
const currentVolume = (player == null ? void 0 : player.muted()) ? 0 : Number((player == null ? void 0 : player.volume()) || 0) * 100;
|
525
532
|
setVolume(currentVolume);
|
526
533
|
};
|
527
534
|
updateVolumeState();
|
@@ -635,8 +642,8 @@ var MenuButton = ({
|
|
635
642
|
setIsOpen(false);
|
636
643
|
}, []);
|
637
644
|
useEffect3(() => {
|
638
|
-
const handleClickOutside = (
|
639
|
-
if (buttonRef.current && !buttonRef.current.contains(
|
645
|
+
const handleClickOutside = (event) => {
|
646
|
+
if (buttonRef.current && !buttonRef.current.contains(event.target) && menuRef.current && !menuRef.current.contains(event.target)) {
|
640
647
|
setIsOpen(false);
|
641
648
|
}
|
642
649
|
};
|
@@ -661,10 +668,10 @@ var MenuButton = ({
|
|
661
668
|
{
|
662
669
|
ref: buttonRef,
|
663
670
|
onClick: (e) => {
|
664
|
-
|
671
|
+
e.stopPropagation();
|
665
672
|
toggleMenu();
|
666
673
|
onClick && onClick(e, !isOpen);
|
667
|
-
noteButtonClick && noteButtonClick(
|
674
|
+
noteButtonClick && noteButtonClick(true);
|
668
675
|
},
|
669
676
|
"aria-haspopup": "true",
|
670
677
|
"aria-expanded": isOpen,
|
@@ -808,7 +815,7 @@ var QualityMenu = ({ width, onClick }) => {
|
|
808
815
|
var QualityMenu_default = QualityMenu;
|
809
816
|
|
810
817
|
// src/components/CreateNoteMenu/index.tsx
|
811
|
-
import { useState as useState5 } from "react";
|
818
|
+
import React5, { useState as useState5 } from "react";
|
812
819
|
import { jsx as jsx22, jsxs as jsxs7 } from "react/jsx-runtime";
|
813
820
|
var CreateNoteMenu = ({
|
814
821
|
handleSaveNoteAction,
|
@@ -878,13 +885,13 @@ var CreateNoteMenu = ({
|
|
878
885
|
}
|
879
886
|
);
|
880
887
|
};
|
881
|
-
var CreateNoteMenu_default = CreateNoteMenu;
|
888
|
+
var CreateNoteMenu_default = React5.memo(CreateNoteMenu);
|
882
889
|
|
883
890
|
// src/components/NotesPanal/index.tsx
|
884
891
|
import { useEffect as useEffect6, useState as useState7 } from "react";
|
885
892
|
|
886
893
|
// src/components/NoteTooltip/index.tsx
|
887
|
-
import {
|
894
|
+
import { useState as useState6 } from "react";
|
888
895
|
|
889
896
|
// src/components/Tooltip/index.tsx
|
890
897
|
import { jsx as jsx23 } from "react/jsx-runtime";
|
@@ -904,18 +911,14 @@ var Tooltip_default = Tooltip;
|
|
904
911
|
import { jsx as jsx24, jsxs as jsxs8 } from "react/jsx-runtime";
|
905
912
|
var NoteTooltip = ({ note }) => {
|
906
913
|
const [open, setOpen] = useState6(false);
|
907
|
-
const { currentTime } = useSoftBuildersVideoPlayerContext();
|
908
|
-
|
909
|
-
|
910
|
-
|
911
|
-
setTimeout(() => {
|
912
|
-
setOpen(false);
|
913
|
-
}, 5e3);
|
914
|
-
}
|
915
|
-
}, [currentTime, note.time]);
|
914
|
+
const { currentTime, player } = useSoftBuildersVideoPlayerContext();
|
915
|
+
const handleValueChange = () => {
|
916
|
+
player == null ? void 0 : player.currentTime(note.time);
|
917
|
+
};
|
916
918
|
return /* @__PURE__ */ jsx24(
|
917
919
|
"div",
|
918
920
|
{
|
921
|
+
onClick: handleValueChange,
|
919
922
|
className: "sb-w-1 sb-h-1 sb-rounded-full sb-bg-white sb-absolute sb-z-30",
|
920
923
|
style: { left: `${note.percentage}%` },
|
921
924
|
onMouseEnter: () => setOpen(true),
|
@@ -1472,6 +1475,7 @@ var ControlBar = ({
|
|
1472
1475
|
time: Number((player == null ? void 0 : player.currentTime()) || 0),
|
1473
1476
|
isOpen: e
|
1474
1477
|
});
|
1478
|
+
player.pause();
|
1475
1479
|
}
|
1476
1480
|
}
|
1477
1481
|
) }),
|
@@ -1555,19 +1559,22 @@ var controlBarRoot = {};
|
|
1555
1559
|
var renderControlBar = (id, player, isPaused, setIsPaused, duration, notes, chapters, seekStep = 5, handleSaveNoteAction, opacity = "0", handleControlDisplayTimer = () => {
|
1556
1560
|
}, bgColor = "transparent", setIsQualityMenuOpen, setIsSubtitleMenuOpen, disableNote, setNoteOpen, noteButtonClick) => {
|
1557
1561
|
const container = document.getElementById(`video-container-${id}`);
|
1562
|
+
console.log("container: ", container);
|
1558
1563
|
if (container) {
|
1564
|
+
console.log("container1: ");
|
1559
1565
|
container.style.height = "100%";
|
1560
1566
|
container.style.aspectRatio = "16 / 9";
|
1561
1567
|
const element = container.querySelector(".vjs-control-bar");
|
1562
1568
|
if (element) {
|
1569
|
+
console.log("container2: ");
|
1563
1570
|
if (!controlBarRoot[id]) {
|
1564
1571
|
controlBarRoot[id] = ReactDOM.createRoot(element);
|
1572
|
+
element.style.display = "flex";
|
1573
|
+
element.style.height = "100%";
|
1574
|
+
element.style.alignItems = "flex-end";
|
1565
1575
|
}
|
1566
|
-
element.style.display = "flex";
|
1567
1576
|
element.style.opacity = opacity;
|
1568
1577
|
element.style.backgroundColor = `${bgColor} !important`;
|
1569
|
-
element.style.height = "100%";
|
1570
|
-
element.style.alignItems = "flex-end";
|
1571
1578
|
controlBarRoot[id].render(
|
1572
1579
|
/* @__PURE__ */ jsx36(SoftBuildersVideoPlayerProvider, { children: /* @__PURE__ */ jsx36(
|
1573
1580
|
ControlBar_default,
|
@@ -1609,7 +1616,6 @@ var VideoPlayerComponent = forwardRef(
|
|
1609
1616
|
bottomRedBar = true,
|
1610
1617
|
noteButtonClick
|
1611
1618
|
}, ref) => {
|
1612
|
-
var _a;
|
1613
1619
|
const videoRef = useRef2(void 0);
|
1614
1620
|
const playerRef = useRef2(void 0);
|
1615
1621
|
const [isReady, setIsReady] = useState14(false);
|
@@ -1620,9 +1626,9 @@ var VideoPlayerComponent = forwardRef(
|
|
1620
1626
|
const [bgColor, setBgColor] = useState14("transparent");
|
1621
1627
|
const [isQualityMenuOpen, setIsQualityMenuOpen] = useState14(false);
|
1622
1628
|
const [isSubtitleMenuOpen, setIsSubtitleMenuOpen] = useState14(false);
|
1623
|
-
const [isHovered, setIsHovered] = useState14(false);
|
1624
1629
|
const [isNoteOpen, setNoteOpen] = useState14(false);
|
1625
1630
|
const onReady = (player) => {
|
1631
|
+
console.log("onReady: ", onReady);
|
1626
1632
|
if (playerRef) {
|
1627
1633
|
playerRef.current = player;
|
1628
1634
|
setIsReady(true);
|
@@ -1655,20 +1661,6 @@ var VideoPlayerComponent = forwardRef(
|
|
1655
1661
|
onReady(playerRef.current);
|
1656
1662
|
});
|
1657
1663
|
}
|
1658
|
-
return () => {
|
1659
|
-
if (playerRef.current) {
|
1660
|
-
setTimeout(() => {
|
1661
|
-
if (bigPlayButtonRoot[id]) {
|
1662
|
-
bigPlayButtonRoot[id].unmount();
|
1663
|
-
bigPlayButtonRoot[id] = void 0;
|
1664
|
-
}
|
1665
|
-
if (controlBarRoot[id]) {
|
1666
|
-
controlBarRoot[id].unmount();
|
1667
|
-
controlBarRoot[id] = void 0;
|
1668
|
-
}
|
1669
|
-
}, 0);
|
1670
|
-
}
|
1671
|
-
};
|
1672
1664
|
}, [options, poster]);
|
1673
1665
|
useEffect14(() => {
|
1674
1666
|
if (playerRef.current && isReady) {
|
@@ -1704,7 +1696,7 @@ var VideoPlayerComponent = forwardRef(
|
|
1704
1696
|
setNoteOpen,
|
1705
1697
|
noteButtonClick
|
1706
1698
|
);
|
1707
|
-
},
|
1699
|
+
}, 0);
|
1708
1700
|
return () => clearTimeout(controlBarTimeout);
|
1709
1701
|
}
|
1710
1702
|
}, [
|
@@ -1741,19 +1733,30 @@ var VideoPlayerComponent = forwardRef(
|
|
1741
1733
|
return () => clearInterval(intervalId);
|
1742
1734
|
}
|
1743
1735
|
}, []);
|
1736
|
+
useEffect14(() => {
|
1737
|
+
var _a, _b;
|
1738
|
+
if (playerRef.current) {
|
1739
|
+
(_a = playerRef.current) == null ? void 0 : _a.currentTime(startTime);
|
1740
|
+
console.log("startTimenotes: ", startTime);
|
1741
|
+
(_b = playerRef.current) == null ? void 0 : _b.play();
|
1742
|
+
}
|
1743
|
+
}, [startTime]);
|
1744
1744
|
useEffect14(() => {
|
1745
1745
|
return () => {
|
1746
1746
|
if (playerRef.current) {
|
1747
|
-
|
1748
|
-
|
1749
|
-
|
1750
|
-
|
1751
|
-
|
1752
|
-
|
1753
|
-
|
1754
|
-
|
1755
|
-
|
1756
|
-
|
1747
|
+
setTimeout(() => {
|
1748
|
+
var _a;
|
1749
|
+
if (bigPlayButtonRoot[id]) {
|
1750
|
+
bigPlayButtonRoot[id].unmount();
|
1751
|
+
bigPlayButtonRoot[id] = void 0;
|
1752
|
+
}
|
1753
|
+
if (controlBarRoot[id]) {
|
1754
|
+
controlBarRoot[id].unmount();
|
1755
|
+
controlBarRoot[id] = void 0;
|
1756
|
+
}
|
1757
|
+
(_a = playerRef.current) == null ? void 0 : _a.dispose();
|
1758
|
+
playerRef.current = void 0;
|
1759
|
+
}, 0);
|
1757
1760
|
}
|
1758
1761
|
};
|
1759
1762
|
}, []);
|
@@ -1775,22 +1778,12 @@ var VideoPlayerComponent = forwardRef(
|
|
1775
1778
|
}
|
1776
1779
|
}, [isQualityMenuOpen, isSubtitleMenuOpen]);
|
1777
1780
|
useEffect14(() => {
|
1778
|
-
|
1779
|
-
if (isNoteOpen) {
|
1780
|
-
if (timeoutRef.current) {
|
1781
|
-
clearTimeout(timeoutRef.current);
|
1782
|
-
}
|
1783
|
-
} else {
|
1784
|
-
if (timeoutRef.current) {
|
1785
|
-
clearTimeout(timeoutRef.current);
|
1786
|
-
}
|
1787
|
-
timeoutRef.current = setTimeout(() => {
|
1788
|
-
setIsControlBarPresent(false);
|
1789
|
-
}, 3e3);
|
1781
|
+
if (playerRef.current) {
|
1790
1782
|
}
|
1791
|
-
}, [
|
1783
|
+
}, [notes]);
|
1792
1784
|
const handlePlayerClick = async (e, isTimerOnly = false) => {
|
1793
1785
|
e.preventDefault();
|
1786
|
+
console.log("handlePlayerClick: ", isTimerOnly);
|
1794
1787
|
if (timeoutRef.current) {
|
1795
1788
|
clearTimeout(timeoutRef.current);
|
1796
1789
|
}
|
@@ -1828,9 +1821,9 @@ var VideoPlayerComponent = forwardRef(
|
|
1828
1821
|
const observer = new IntersectionObserver(
|
1829
1822
|
(entries) => {
|
1830
1823
|
entries.forEach((entry) => {
|
1831
|
-
var
|
1824
|
+
var _a, _b;
|
1832
1825
|
if (entry.isIntersecting === false) {
|
1833
|
-
if (((
|
1826
|
+
if (((_a = playerRef == null ? void 0 : playerRef.current) == null ? void 0 : _a.paused()) === false) {
|
1834
1827
|
try {
|
1835
1828
|
(_b = playerRef == null ? void 0 : playerRef.current) == null ? void 0 : _b.pause();
|
1836
1829
|
setIsPaused(true);
|
@@ -1858,31 +1851,28 @@ var VideoPlayerComponent = forwardRef(
|
|
1858
1851
|
const [timeSeeker, setTimeSeeker] = useState14("0");
|
1859
1852
|
useEffect14(() => {
|
1860
1853
|
const updateTimeSeeker = () => {
|
1861
|
-
|
1862
|
-
|
1863
|
-
const
|
1864
|
-
const duration2 = (_d = (_c = playerRef.current) == null ? void 0 : _c.duration) == null ? void 0 : _d.call(_c);
|
1854
|
+
if (playerRef.current) {
|
1855
|
+
const currentTime = playerRef.current.currentTime();
|
1856
|
+
const duration2 = playerRef.current.duration();
|
1865
1857
|
if (duration2 && currentTime !== void 0) {
|
1866
|
-
|
1867
|
-
setTimeSeeker(value);
|
1858
|
+
setTimeSeeker(`${currentTime / duration2 * 100}%`);
|
1868
1859
|
} else {
|
1869
1860
|
setTimeSeeker("0");
|
1870
1861
|
}
|
1871
1862
|
}
|
1872
1863
|
};
|
1873
|
-
updateTimeSeeker
|
1874
|
-
|
1864
|
+
const interval = setInterval(updateTimeSeeker, 500);
|
1865
|
+
return () => clearInterval(interval);
|
1866
|
+
}, [playerRef]);
|
1875
1867
|
return /* @__PURE__ */ jsxs15(
|
1876
1868
|
"div",
|
1877
1869
|
{
|
1878
1870
|
ref: videoRefs,
|
1879
1871
|
id: `video-container-${id}`,
|
1880
|
-
onMouseMove: () => {
|
1881
|
-
|
1872
|
+
onMouseMove: (e) => {
|
1873
|
+
handlePlayerClick(e, true);
|
1882
1874
|
},
|
1883
1875
|
className: "sb-relative sb-rounded-md sb-overflow-hidden sb-w-full sb-h-full sb-bottom-2 ",
|
1884
|
-
onMouseEnter: () => setIsHovered(true),
|
1885
|
-
onMouseLeave: () => setIsHovered(false),
|
1886
1876
|
children: [
|
1887
1877
|
bottomRedBar && /* @__PURE__ */ jsx36(
|
1888
1878
|
"div",
|
@@ -1944,48 +1934,38 @@ var Component = forwardRef2(
|
|
1944
1934
|
bottomRedBar,
|
1945
1935
|
noteButtonClick
|
1946
1936
|
}, ref) => {
|
1947
|
-
|
1948
|
-
|
1949
|
-
|
1950
|
-
|
1951
|
-
navigationUI: "hide"
|
1952
|
-
}
|
1953
|
-
|
1954
|
-
|
1955
|
-
options.autoplay = DEFAULT_OPTIONS.autoplay;
|
1956
|
-
if (options.controls === void 0)
|
1957
|
-
options.controls = DEFAULT_OPTIONS.controls;
|
1958
|
-
if (options.fluid === void 0) options.fluid = DEFAULT_OPTIONS.fluid;
|
1959
|
-
if ((options == null ? void 0 : options.muted) === void 0) options.muted = DEFAULT_OPTIONS == null ? void 0 : DEFAULT_OPTIONS.muted;
|
1960
|
-
if (options.height === void 0) options.height = DEFAULT_OPTIONS.height;
|
1961
|
-
if (options.width === void 0) options.width = DEFAULT_OPTIONS.width;
|
1937
|
+
const mergedOptions = useMemo(
|
1938
|
+
() => __spreadProps(__spreadValues(__spreadValues({}, DEFAULT_OPTIONS), options), {
|
1939
|
+
responsive: true,
|
1940
|
+
inactivityTimeout: 0,
|
1941
|
+
fullscreen: { navigationUI: "hide" }
|
1942
|
+
}),
|
1943
|
+
[options]
|
1944
|
+
);
|
1962
1945
|
const [tracks, setTracks] = useState15([]);
|
1963
|
-
|
1964
|
-
|
1965
|
-
|
1966
|
-
|
1967
|
-
|
1968
|
-
|
1969
|
-
|
1970
|
-
let src = s.src;
|
1971
|
-
if (s.memeType == "text/srt") {
|
1972
|
-
src = await convertSRTtoVTT(s.src);
|
1973
|
-
}
|
1974
|
-
newTracks.push(__spreadProps(__spreadValues({}, s), {
|
1975
|
-
src
|
1976
|
-
}));
|
1946
|
+
const getTracks = useCallback4(async () => {
|
1947
|
+
const newTracks = [];
|
1948
|
+
if (Array.isArray(mergedOptions.tracks)) {
|
1949
|
+
for (const s of mergedOptions.tracks) {
|
1950
|
+
let src = s.src;
|
1951
|
+
if (s.memeType === "text/srt") {
|
1952
|
+
src = await convertSRTtoVTT(s.src);
|
1977
1953
|
}
|
1978
|
-
|
1979
|
-
|
1954
|
+
newTracks.push(__spreadProps(__spreadValues({}, s), { src }));
|
1955
|
+
}
|
1956
|
+
}
|
1957
|
+
setTracks(newTracks);
|
1958
|
+
}, [mergedOptions.tracks]);
|
1959
|
+
useEffect15(() => {
|
1980
1960
|
getTracks();
|
1981
|
-
}, [
|
1982
|
-
const id = (Date.now() + Math.random() * 100).toString();
|
1961
|
+
}, [getTracks]);
|
1962
|
+
const id = useMemo(() => (Date.now() + Math.random() * 100).toString(), []);
|
1983
1963
|
return /* @__PURE__ */ jsx37(
|
1984
1964
|
VideoPlayerComponent_default,
|
1985
1965
|
{
|
1986
1966
|
id,
|
1987
1967
|
chapters,
|
1988
|
-
options: __spreadProps(__spreadValues({},
|
1968
|
+
options: __spreadProps(__spreadValues({}, mergedOptions), { tracks }),
|
1989
1969
|
notes,
|
1990
1970
|
poster: "",
|
1991
1971
|
startTime,
|
@@ -2001,7 +1981,8 @@ var Component = forwardRef2(
|
|
2001
1981
|
}
|
2002
1982
|
);
|
2003
1983
|
var SoftBuildersVideoPlayer = memo(Component, (prevProps, nextProps) => {
|
2004
|
-
return prevProps.options === nextProps.options && prevProps.notes === nextProps.notes &&
|
1984
|
+
return prevProps.options === nextProps.options && // prevProps.notes === nextProps.notes &&
|
1985
|
+
prevProps.chapters === nextProps.chapters && prevProps.startTime === nextProps.startTime;
|
2005
1986
|
});
|
2006
1987
|
var SoftBuildersVideoPlayer_default = SoftBuildersVideoPlayer;
|
2007
1988
|
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "softbuilders-react-video-player",
|
3
3
|
"description": "Standalone video player component",
|
4
|
-
"version": "1.1.
|
4
|
+
"version": "1.1.74",
|
5
5
|
"main": "dist/index.js",
|
6
6
|
"types": "dist/index.d.ts",
|
7
7
|
"files": [
|
@@ -33,6 +33,7 @@
|
|
33
33
|
"@swc/core": "^1.7.26",
|
34
34
|
"@types/react": "^18.3.5",
|
35
35
|
"@types/react-dom": "^18.3.0",
|
36
|
+
"@types/video.js": "^7.3.58",
|
36
37
|
"autoprefixer": "^10.4.20",
|
37
38
|
"concurrently": "^9.0.1",
|
38
39
|
"copyfiles": "^2.4.1",
|