@exode-team/react-recorder 1.1.1 → 1.1.2
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 +2 -0
- package/dist/components/VoiceMessagePlayer/VoiceMessagePlayer.d.ts +1 -0
- package/dist/components/VoiceMessagePlayer/VoiceMessagePlayer.d.ts.map +1 -1
- package/dist/hooks/useVoiceMessagePlayer.d.ts.map +1 -1
- package/dist/index.cjs +36 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +36 -4
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -960,6 +960,13 @@ const useVoiceMessagePlayer = (options) => {
|
|
|
960
960
|
},
|
|
961
961
|
},
|
|
962
962
|
});
|
|
963
|
+
/** Pre-fetch audio without playing (for viewport preloading) */
|
|
964
|
+
const prefetch = useCallback(() => {
|
|
965
|
+
if (isLoading || audioRef.current) {
|
|
966
|
+
return;
|
|
967
|
+
}
|
|
968
|
+
void ensureAudioLoaded();
|
|
969
|
+
}, [isLoading, ensureAudioLoaded]);
|
|
963
970
|
/** Load audio and auto-play after loaded */
|
|
964
971
|
const preload = useCallback(() => {
|
|
965
972
|
if (isLoading || audioRef.current) {
|
|
@@ -1030,6 +1037,7 @@ const useVoiceMessagePlayer = (options) => {
|
|
|
1030
1037
|
currentTime,
|
|
1031
1038
|
waveformLevels,
|
|
1032
1039
|
seekTo,
|
|
1040
|
+
prefetch,
|
|
1033
1041
|
preload,
|
|
1034
1042
|
formatTime,
|
|
1035
1043
|
togglePlayback,
|
|
@@ -2128,8 +2136,9 @@ const BAR_GAP = 2;
|
|
|
2128
2136
|
const BAR_MIN_HEIGHT = 2;
|
|
2129
2137
|
const BAR_MAX_HEIGHT = 24;
|
|
2130
2138
|
const VoiceMessagePlayer = React.forwardRef((props, ref) => {
|
|
2131
|
-
const { src, onClick, onEnded, chainId, duration, className, waveformData, } = props;
|
|
2139
|
+
const { src, onClick, onEnded, chainId, duration, className, waveformData, autoPreload = true, } = props;
|
|
2132
2140
|
const trackRef = useRef(null);
|
|
2141
|
+
const wrapperRef = useRef(null);
|
|
2133
2142
|
const [trackWidth, setTrackWidth] = useState(0);
|
|
2134
2143
|
const handleEnded = useCallback(() => {
|
|
2135
2144
|
onEnded === null || onEnded === void 0 ? void 0 : onEnded();
|
|
@@ -2137,14 +2146,37 @@ const VoiceMessagePlayer = React.forwardRef((props, ref) => {
|
|
|
2137
2146
|
VoicePlaybackChain.playNext(chainId);
|
|
2138
2147
|
}
|
|
2139
2148
|
}, [onEnded, chainId]);
|
|
2140
|
-
const { play, progress, isLoaded, isPlaying, isLoading, currentTime, waveformLevels, seekTo, preload, formatTime, togglePlayback, duration: resolvedDuration, } = useVoiceMessagePlayer({
|
|
2149
|
+
const { play, progress, isLoaded, isPlaying, isLoading, currentTime, waveformLevels, seekTo, prefetch, preload, formatTime, togglePlayback, duration: resolvedDuration, } = useVoiceMessagePlayer({
|
|
2141
2150
|
src,
|
|
2142
2151
|
duration,
|
|
2143
2152
|
waveformData,
|
|
2144
2153
|
preloadedBlob: props.preloadedBlob,
|
|
2145
2154
|
onEnded: handleEnded,
|
|
2146
2155
|
});
|
|
2147
|
-
useImperativeHandle(ref, () => ({ play }), [play]);
|
|
2156
|
+
useImperativeHandle(ref, () => ({ play, prefetch }), [play, prefetch]);
|
|
2157
|
+
/** Auto-preload audio when player enters viewport */
|
|
2158
|
+
useEffect(() => {
|
|
2159
|
+
if (!autoPreload || isLoaded || isLoading) {
|
|
2160
|
+
return;
|
|
2161
|
+
}
|
|
2162
|
+
const el = wrapperRef.current;
|
|
2163
|
+
if (!el) {
|
|
2164
|
+
return;
|
|
2165
|
+
}
|
|
2166
|
+
const observer = new IntersectionObserver(([entry]) => {
|
|
2167
|
+
if (entry.isIntersecting) {
|
|
2168
|
+
prefetch();
|
|
2169
|
+
observer.disconnect();
|
|
2170
|
+
}
|
|
2171
|
+
}, { threshold: 0.1 });
|
|
2172
|
+
observer.observe(el);
|
|
2173
|
+
return () => observer.disconnect();
|
|
2174
|
+
}, [
|
|
2175
|
+
isLoaded,
|
|
2176
|
+
prefetch,
|
|
2177
|
+
isLoading,
|
|
2178
|
+
autoPreload,
|
|
2179
|
+
]);
|
|
2148
2180
|
/** Register in playback chain for sequential playback */
|
|
2149
2181
|
useEffect(() => {
|
|
2150
2182
|
if (chainId != null) {
|
|
@@ -2191,7 +2223,7 @@ const VoiceMessagePlayer = React.forwardRef((props, ref) => {
|
|
|
2191
2223
|
const peak = Math.max(...raw, 1);
|
|
2192
2224
|
return raw.map((v) => (v / peak) * 100);
|
|
2193
2225
|
}, [waveformLevels, trackWidth]);
|
|
2194
|
-
return (jsxs(PlayerWrapper, { onClick: onClick, className: className, children: [jsx(PlayButton, { type: "button", disabled: isLoading || (!src && !props.preloadedBlob), onClick: isLoaded ? togglePlayback : preload, "aria-label": isPlaying ? 'Pause' : 'Play', children: isLoading ? (jsx(LoadingSpinner, {})) : isPlaying ? (jsx(Icon24Pause, {})) : (jsx(Icon24Play, {})) }), jsxs(ContentColumn, { children: [jsx(WaveformTrack, { ref: trackRef, onClick: handleTrackClick, children: interpolatedBars.map((level, i) => {
|
|
2226
|
+
return (jsxs(PlayerWrapper, { ref: wrapperRef, onClick: onClick, className: className, children: [jsx(PlayButton, { type: "button", disabled: isLoading || (!src && !props.preloadedBlob), onClick: isLoaded ? togglePlayback : preload, "aria-label": isPlaying ? 'Pause' : 'Play', children: isLoading ? (jsx(LoadingSpinner, {})) : isPlaying ? (jsx(Icon24Pause, {})) : (jsx(Icon24Play, {})) }), jsxs(ContentColumn, { children: [jsx(WaveformTrack, { ref: trackRef, onClick: handleTrackClick, children: interpolatedBars.map((level, i) => {
|
|
2195
2227
|
const normalized = Math.min(100, level);
|
|
2196
2228
|
const height = BAR_MIN_HEIGHT + (normalized / 100) * (BAR_MAX_HEIGHT - BAR_MIN_HEIGHT);
|
|
2197
2229
|
const barProgress = interpolatedBars.length > 0
|