@livepeer-frameworks/player-react 0.1.0 → 0.1.1
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 +7 -9
- package/package.json +1 -1
- package/src/components/DevModePanel.tsx +244 -143
- package/src/components/Icons.tsx +105 -25
- package/src/components/IdleScreen.tsx +262 -128
- package/src/components/LoadingScreen.tsx +169 -151
- package/src/components/LogoOverlay.tsx +3 -6
- package/src/components/Player.tsx +84 -56
- package/src/components/PlayerControls.tsx +349 -256
- package/src/components/PlayerErrorBoundary.tsx +6 -13
- package/src/components/SeekBar.tsx +96 -88
- package/src/components/SkipIndicator.tsx +2 -12
- package/src/components/SpeedIndicator.tsx +2 -11
- package/src/components/StatsPanel.tsx +31 -22
- package/src/components/StreamStateOverlay.tsx +105 -49
- package/src/components/SubtitleRenderer.tsx +29 -29
- package/src/components/ThumbnailOverlay.tsx +5 -6
- package/src/components/TitleOverlay.tsx +2 -8
- package/src/components/players/DashJsPlayer.tsx +13 -11
- package/src/components/players/HlsJsPlayer.tsx +13 -11
- package/src/components/players/MewsWsPlayer/index.tsx +13 -11
- package/src/components/players/MistPlayer.tsx +13 -11
- package/src/components/players/MistWebRTCPlayer/index.tsx +19 -10
- package/src/components/players/NativePlayer.tsx +10 -12
- package/src/components/players/VideoJsPlayer.tsx +13 -11
- package/src/context/PlayerContext.tsx +4 -8
- package/src/context/index.ts +3 -3
- package/src/hooks/useMetaTrack.ts +27 -27
- package/src/hooks/usePlaybackQuality.ts +3 -3
- package/src/hooks/usePlayerController.ts +186 -138
- package/src/hooks/usePlayerSelection.ts +6 -6
- package/src/hooks/useStreamState.ts +51 -56
- package/src/hooks/useTelemetry.ts +18 -3
- package/src/hooks/useViewerEndpoints.ts +34 -23
- package/src/index.tsx +36 -28
- package/src/types.ts +8 -8
- package/src/ui/badge.tsx +6 -5
- package/src/ui/button.tsx +9 -8
- package/src/ui/context-menu.tsx +42 -61
- package/src/ui/select.tsx +13 -7
- package/src/ui/slider.tsx +18 -29
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
* The implementation is in @livepeer-frameworks/player-core.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import React, { useRef, useEffect } from
|
|
9
|
-
import { MistWebRTCPlayerImpl } from
|
|
8
|
+
import React, { useRef, useEffect } from "react";
|
|
9
|
+
import { MistWebRTCPlayerImpl } from "@livepeer-frameworks/player-core";
|
|
10
10
|
|
|
11
11
|
// Re-export the implementation from core for backwards compatibility
|
|
12
12
|
export { MistWebRTCPlayerImpl };
|
|
@@ -39,13 +39,22 @@ export const MistWebRTCPlayer: React.FC<Props> = ({
|
|
|
39
39
|
const player = new MistWebRTCPlayerImpl();
|
|
40
40
|
playerRef.current = player;
|
|
41
41
|
|
|
42
|
-
player
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
42
|
+
player
|
|
43
|
+
.initialize(
|
|
44
|
+
containerRef.current,
|
|
45
|
+
{ url: src, type: "webrtc" },
|
|
46
|
+
{
|
|
47
|
+
autoplay: autoPlay,
|
|
48
|
+
muted,
|
|
49
|
+
controls,
|
|
50
|
+
poster,
|
|
51
|
+
onReady,
|
|
52
|
+
onError: (e) => onError?.(typeof e === "string" ? new Error(e) : e),
|
|
53
|
+
}
|
|
54
|
+
)
|
|
55
|
+
.catch((e) => {
|
|
56
|
+
onError?.(e instanceof Error ? e : new Error(String(e)));
|
|
57
|
+
});
|
|
49
58
|
|
|
50
59
|
return () => {
|
|
51
60
|
player.destroy();
|
|
@@ -53,7 +62,7 @@ export const MistWebRTCPlayer: React.FC<Props> = ({
|
|
|
53
62
|
};
|
|
54
63
|
}, [src, autoPlay, muted, controls, poster, onReady, onError]);
|
|
55
64
|
|
|
56
|
-
return <div ref={containerRef} style={{ width:
|
|
65
|
+
return <div ref={containerRef} style={{ width: "100%", height: "100%" }} />;
|
|
57
66
|
};
|
|
58
67
|
|
|
59
68
|
export default MistWebRTCPlayerImpl;
|
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
* The implementation is in @livepeer-frameworks/player-core.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import React, { useEffect, useRef } from
|
|
9
|
-
import { NativePlayerImpl, DirectPlaybackPlayerImpl } from
|
|
8
|
+
import React, { useEffect, useRef } from "react";
|
|
9
|
+
import { NativePlayerImpl, DirectPlaybackPlayerImpl } from "@livepeer-frameworks/player-core";
|
|
10
10
|
|
|
11
11
|
// Re-export the implementations from core for backwards compatibility
|
|
12
12
|
export { NativePlayerImpl, DirectPlaybackPlayerImpl };
|
|
@@ -23,11 +23,11 @@ type Props = {
|
|
|
23
23
|
// React component wrapper
|
|
24
24
|
const NativePlayer: React.FC<Props> = ({
|
|
25
25
|
src,
|
|
26
|
-
type =
|
|
26
|
+
type = "html5/video/mp4",
|
|
27
27
|
muted = true,
|
|
28
28
|
autoPlay = true,
|
|
29
29
|
controls = true,
|
|
30
|
-
onError
|
|
30
|
+
onError,
|
|
31
31
|
}) => {
|
|
32
32
|
const containerRef = useRef<HTMLDivElement>(null);
|
|
33
33
|
const playerRef = useRef<NativePlayerImpl | null>(null);
|
|
@@ -38,13 +38,11 @@ const NativePlayer: React.FC<Props> = ({
|
|
|
38
38
|
const player = new NativePlayerImpl();
|
|
39
39
|
playerRef.current = player;
|
|
40
40
|
|
|
41
|
-
player
|
|
42
|
-
containerRef.current,
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
onError?.(e instanceof Error ? e : new Error(String(e)));
|
|
47
|
-
});
|
|
41
|
+
player
|
|
42
|
+
.initialize(containerRef.current, { url: src, type }, { autoplay: autoPlay, muted, controls })
|
|
43
|
+
.catch((e) => {
|
|
44
|
+
onError?.(e instanceof Error ? e : new Error(String(e)));
|
|
45
|
+
});
|
|
48
46
|
|
|
49
47
|
return () => {
|
|
50
48
|
player.destroy();
|
|
@@ -52,7 +50,7 @@ const NativePlayer: React.FC<Props> = ({
|
|
|
52
50
|
};
|
|
53
51
|
}, [src, type, muted, autoPlay, controls, onError]);
|
|
54
52
|
|
|
55
|
-
return <div ref={containerRef} style={{ width:
|
|
53
|
+
return <div ref={containerRef} style={{ width: "100%", height: "100%" }} />;
|
|
56
54
|
};
|
|
57
55
|
|
|
58
56
|
export default NativePlayer;
|
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
* The implementation is in @livepeer-frameworks/player-core.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import React, { useEffect, useRef } from
|
|
9
|
-
import { VideoJsPlayerImpl } from
|
|
8
|
+
import React, { useEffect, useRef } from "react";
|
|
9
|
+
import { VideoJsPlayerImpl } from "@livepeer-frameworks/player-core";
|
|
10
10
|
|
|
11
11
|
// Re-export the implementation from core for backwards compatibility
|
|
12
12
|
export { VideoJsPlayerImpl };
|
|
@@ -25,7 +25,7 @@ const VideoJsPlayer: React.FC<Props> = ({
|
|
|
25
25
|
muted = true,
|
|
26
26
|
autoPlay = true,
|
|
27
27
|
controls = true,
|
|
28
|
-
onError
|
|
28
|
+
onError,
|
|
29
29
|
}) => {
|
|
30
30
|
const containerRef = useRef<HTMLDivElement>(null);
|
|
31
31
|
const playerRef = useRef<VideoJsPlayerImpl | null>(null);
|
|
@@ -36,13 +36,15 @@ const VideoJsPlayer: React.FC<Props> = ({
|
|
|
36
36
|
const player = new VideoJsPlayerImpl();
|
|
37
37
|
playerRef.current = player;
|
|
38
38
|
|
|
39
|
-
player
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
39
|
+
player
|
|
40
|
+
.initialize(
|
|
41
|
+
containerRef.current,
|
|
42
|
+
{ url: src, type: "html5/application/vnd.apple.mpegurl" },
|
|
43
|
+
{ autoplay: autoPlay, muted, controls }
|
|
44
|
+
)
|
|
45
|
+
.catch((e) => {
|
|
46
|
+
onError?.(e instanceof Error ? e : new Error(String(e)));
|
|
47
|
+
});
|
|
46
48
|
|
|
47
49
|
return () => {
|
|
48
50
|
player.destroy();
|
|
@@ -50,7 +52,7 @@ const VideoJsPlayer: React.FC<Props> = ({
|
|
|
50
52
|
};
|
|
51
53
|
}, [src, muted, autoPlay, controls, onError]);
|
|
52
54
|
|
|
53
|
-
return <div ref={containerRef} style={{ width:
|
|
55
|
+
return <div ref={containerRef} style={{ width: "100%", height: "100%" }} />;
|
|
54
56
|
};
|
|
55
57
|
|
|
56
58
|
export default VideoJsPlayer;
|
|
@@ -12,12 +12,12 @@
|
|
|
12
12
|
* ```
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
|
-
import React, { createContext, useContext, type ReactNode } from
|
|
15
|
+
import React, { createContext, useContext, type ReactNode } from "react";
|
|
16
16
|
import {
|
|
17
17
|
usePlayerController,
|
|
18
18
|
type UsePlayerControllerConfig,
|
|
19
19
|
type UsePlayerControllerReturn,
|
|
20
|
-
} from
|
|
20
|
+
} from "../hooks/usePlayerController";
|
|
21
21
|
|
|
22
22
|
// Context holds the full hook return value
|
|
23
23
|
const PlayerContext = createContext<UsePlayerControllerReturn | null>(null);
|
|
@@ -35,11 +35,7 @@ export interface PlayerProviderProps {
|
|
|
35
35
|
export function PlayerProvider({ children, config }: PlayerProviderProps) {
|
|
36
36
|
const playerController = usePlayerController(config);
|
|
37
37
|
|
|
38
|
-
return
|
|
39
|
-
<PlayerContext.Provider value={playerController}>
|
|
40
|
-
{children}
|
|
41
|
-
</PlayerContext.Provider>
|
|
42
|
-
);
|
|
38
|
+
return <PlayerContext.Provider value={playerController}>{children}</PlayerContext.Provider>;
|
|
43
39
|
}
|
|
44
40
|
|
|
45
41
|
/**
|
|
@@ -49,7 +45,7 @@ export function PlayerProvider({ children, config }: PlayerProviderProps) {
|
|
|
49
45
|
export function usePlayerContext(): UsePlayerControllerReturn {
|
|
50
46
|
const context = useContext(PlayerContext);
|
|
51
47
|
if (!context) {
|
|
52
|
-
throw new Error(
|
|
48
|
+
throw new Error("usePlayerContext must be used within a PlayerProvider");
|
|
53
49
|
}
|
|
54
50
|
return context;
|
|
55
51
|
}
|
package/src/context/index.ts
CHANGED
|
@@ -6,6 +6,6 @@ export {
|
|
|
6
6
|
PlayerProvider,
|
|
7
7
|
usePlayerContext,
|
|
8
8
|
usePlayerContextOptional,
|
|
9
|
-
PlayerContext
|
|
10
|
-
} from
|
|
11
|
-
export type { PlayerContextValue, UsePlayerControllerConfig } from
|
|
9
|
+
PlayerContext,
|
|
10
|
+
} from "./PlayerContext";
|
|
11
|
+
export type { PlayerContextValue, UsePlayerControllerConfig } from "./PlayerContext";
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { useEffect, useState, useRef, useCallback } from
|
|
2
|
-
import { MetaTrackManager, type MetaTrackEvent } from
|
|
3
|
-
import type { UseMetaTrackOptions } from
|
|
1
|
+
import { useEffect, useState, useRef, useCallback } from "react";
|
|
2
|
+
import { MetaTrackManager, type MetaTrackEvent } from "@livepeer-frameworks/player-core";
|
|
3
|
+
import type { UseMetaTrackOptions } from "../types";
|
|
4
4
|
|
|
5
5
|
export interface UseMetaTrackReturn {
|
|
6
6
|
/** Whether connected to MistServer WebSocket */
|
|
7
7
|
isConnected: boolean;
|
|
8
8
|
/** Connection state */
|
|
9
|
-
connectionState:
|
|
9
|
+
connectionState: "disconnected" | "connecting" | "connected" | "reconnecting";
|
|
10
10
|
/** List of subscribed track IDs */
|
|
11
11
|
subscribedTracks: string[];
|
|
12
12
|
/** Subscribe to a meta track */
|
|
@@ -54,15 +54,12 @@ export interface UseMetaTrackReturn {
|
|
|
54
54
|
* ```
|
|
55
55
|
*/
|
|
56
56
|
export function useMetaTrack(options: UseMetaTrackOptions): UseMetaTrackReturn {
|
|
57
|
-
const {
|
|
58
|
-
mistBaseUrl,
|
|
59
|
-
streamName,
|
|
60
|
-
subscriptions: initialSubscriptions,
|
|
61
|
-
enabled = true,
|
|
62
|
-
} = options;
|
|
57
|
+
const { mistBaseUrl, streamName, subscriptions: initialSubscriptions, enabled = true } = options;
|
|
63
58
|
|
|
64
59
|
const [isConnected, setIsConnected] = useState(false);
|
|
65
|
-
const [connectionState, setConnectionState] = useState<
|
|
60
|
+
const [connectionState, setConnectionState] = useState<
|
|
61
|
+
"disconnected" | "connecting" | "connected" | "reconnecting"
|
|
62
|
+
>("disconnected");
|
|
66
63
|
const [subscribedTracks, setSubscribedTracks] = useState<string[]>([]);
|
|
67
64
|
const managerRef = useRef<MetaTrackManager | null>(null);
|
|
68
65
|
|
|
@@ -74,7 +71,7 @@ export function useMetaTrack(options: UseMetaTrackOptions): UseMetaTrackReturn {
|
|
|
74
71
|
managerRef.current = null;
|
|
75
72
|
}
|
|
76
73
|
setIsConnected(false);
|
|
77
|
-
setConnectionState(
|
|
74
|
+
setConnectionState("disconnected");
|
|
78
75
|
return;
|
|
79
76
|
}
|
|
80
77
|
|
|
@@ -90,7 +87,7 @@ export function useMetaTrack(options: UseMetaTrackOptions): UseMetaTrackReturn {
|
|
|
90
87
|
if (managerRef.current) {
|
|
91
88
|
const state = managerRef.current.getState();
|
|
92
89
|
setConnectionState(state);
|
|
93
|
-
setIsConnected(state ===
|
|
90
|
+
setIsConnected(state === "connected");
|
|
94
91
|
setSubscribedTracks(managerRef.current.getSubscribedTracks());
|
|
95
92
|
}
|
|
96
93
|
};
|
|
@@ -108,28 +105,31 @@ export function useMetaTrack(options: UseMetaTrackOptions): UseMetaTrackReturn {
|
|
|
108
105
|
managerRef.current = null;
|
|
109
106
|
}
|
|
110
107
|
setIsConnected(false);
|
|
111
|
-
setConnectionState(
|
|
108
|
+
setConnectionState("disconnected");
|
|
112
109
|
};
|
|
113
110
|
}, [enabled, mistBaseUrl, streamName, initialSubscriptions]);
|
|
114
111
|
|
|
115
112
|
/**
|
|
116
113
|
* Subscribe to a meta track
|
|
117
114
|
*/
|
|
118
|
-
const subscribe = useCallback(
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
115
|
+
const subscribe = useCallback(
|
|
116
|
+
(trackId: string, callback: (event: MetaTrackEvent) => void): (() => void) => {
|
|
117
|
+
if (!managerRef.current) {
|
|
118
|
+
return () => {};
|
|
119
|
+
}
|
|
122
120
|
|
|
123
|
-
|
|
124
|
-
|
|
121
|
+
const unsubscribe = managerRef.current.subscribe(trackId, callback);
|
|
122
|
+
setSubscribedTracks(managerRef.current.getSubscribedTracks());
|
|
125
123
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
124
|
+
return () => {
|
|
125
|
+
unsubscribe();
|
|
126
|
+
if (managerRef.current) {
|
|
127
|
+
setSubscribedTracks(managerRef.current.getSubscribedTracks());
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
},
|
|
131
|
+
[]
|
|
132
|
+
);
|
|
133
133
|
|
|
134
134
|
/**
|
|
135
135
|
* Unsubscribe from a meta track
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { useEffect, useState, useRef, useCallback } from
|
|
2
|
-
import { QualityMonitor, type PlaybackQuality } from
|
|
3
|
-
import type { UsePlaybackQualityOptions } from
|
|
1
|
+
import { useEffect, useState, useRef, useCallback } from "react";
|
|
2
|
+
import { QualityMonitor, type PlaybackQuality } from "@livepeer-frameworks/player-core";
|
|
3
|
+
import type { UsePlaybackQualityOptions } from "../types";
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Hook to monitor video playback quality
|