@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.
Files changed (41) hide show
  1. package/README.md +7 -9
  2. package/package.json +1 -1
  3. package/src/components/DevModePanel.tsx +244 -143
  4. package/src/components/Icons.tsx +105 -25
  5. package/src/components/IdleScreen.tsx +262 -128
  6. package/src/components/LoadingScreen.tsx +169 -151
  7. package/src/components/LogoOverlay.tsx +3 -6
  8. package/src/components/Player.tsx +84 -56
  9. package/src/components/PlayerControls.tsx +349 -256
  10. package/src/components/PlayerErrorBoundary.tsx +6 -13
  11. package/src/components/SeekBar.tsx +96 -88
  12. package/src/components/SkipIndicator.tsx +2 -12
  13. package/src/components/SpeedIndicator.tsx +2 -11
  14. package/src/components/StatsPanel.tsx +31 -22
  15. package/src/components/StreamStateOverlay.tsx +105 -49
  16. package/src/components/SubtitleRenderer.tsx +29 -29
  17. package/src/components/ThumbnailOverlay.tsx +5 -6
  18. package/src/components/TitleOverlay.tsx +2 -8
  19. package/src/components/players/DashJsPlayer.tsx +13 -11
  20. package/src/components/players/HlsJsPlayer.tsx +13 -11
  21. package/src/components/players/MewsWsPlayer/index.tsx +13 -11
  22. package/src/components/players/MistPlayer.tsx +13 -11
  23. package/src/components/players/MistWebRTCPlayer/index.tsx +19 -10
  24. package/src/components/players/NativePlayer.tsx +10 -12
  25. package/src/components/players/VideoJsPlayer.tsx +13 -11
  26. package/src/context/PlayerContext.tsx +4 -8
  27. package/src/context/index.ts +3 -3
  28. package/src/hooks/useMetaTrack.ts +27 -27
  29. package/src/hooks/usePlaybackQuality.ts +3 -3
  30. package/src/hooks/usePlayerController.ts +186 -138
  31. package/src/hooks/usePlayerSelection.ts +6 -6
  32. package/src/hooks/useStreamState.ts +51 -56
  33. package/src/hooks/useTelemetry.ts +18 -3
  34. package/src/hooks/useViewerEndpoints.ts +34 -23
  35. package/src/index.tsx +36 -28
  36. package/src/types.ts +8 -8
  37. package/src/ui/badge.tsx +6 -5
  38. package/src/ui/button.tsx +9 -8
  39. package/src/ui/context-menu.tsx +42 -61
  40. package/src/ui/select.tsx +13 -7
  41. 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 'react';
9
- import { MistWebRTCPlayerImpl } from '@livepeer-frameworks/player-core';
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.initialize(
43
- containerRef.current,
44
- { url: src, type: 'webrtc' },
45
- { autoplay: autoPlay, muted, controls, poster, onReady, onError: (e) => onError?.(typeof e === 'string' ? new Error(e) : e) }
46
- ).catch((e) => {
47
- onError?.(e instanceof Error ? e : new Error(String(e)));
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: '100%', height: '100%' }} />;
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 'react';
9
- import { NativePlayerImpl, DirectPlaybackPlayerImpl } from '@livepeer-frameworks/player-core';
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 = 'html5/video/mp4',
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.initialize(
42
- containerRef.current,
43
- { url: src, type },
44
- { autoplay: autoPlay, muted, controls }
45
- ).catch((e) => {
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: '100%', height: '100%' }} />;
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 'react';
9
- import { VideoJsPlayerImpl } from '@livepeer-frameworks/player-core';
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.initialize(
40
- containerRef.current,
41
- { url: src, type: 'html5/application/vnd.apple.mpegurl' },
42
- { autoplay: autoPlay, muted, controls }
43
- ).catch((e) => {
44
- onError?.(e instanceof Error ? e : new Error(String(e)));
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: '100%', height: '100%' }} />;
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 'react';
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 '../hooks/usePlayerController';
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('usePlayerContext must be used within a PlayerProvider');
48
+ throw new Error("usePlayerContext must be used within a PlayerProvider");
53
49
  }
54
50
  return context;
55
51
  }
@@ -6,6 +6,6 @@ export {
6
6
  PlayerProvider,
7
7
  usePlayerContext,
8
8
  usePlayerContextOptional,
9
- PlayerContext
10
- } from './PlayerContext';
11
- export type { PlayerContextValue, UsePlayerControllerConfig } from './PlayerContext';
9
+ PlayerContext,
10
+ } from "./PlayerContext";
11
+ export type { PlayerContextValue, UsePlayerControllerConfig } from "./PlayerContext";
@@ -1,12 +1,12 @@
1
- import { useEffect, useState, useRef, useCallback } from 'react';
2
- import { MetaTrackManager, type MetaTrackEvent } from '@livepeer-frameworks/player-core';
3
- import type { UseMetaTrackOptions } from '../types';
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: 'disconnected' | 'connecting' | 'connected' | 'reconnecting';
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<'disconnected' | 'connecting' | 'connected' | 'reconnecting'>('disconnected');
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('disconnected');
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 === 'connected');
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('disconnected');
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((trackId: string, callback: (event: MetaTrackEvent) => void): () => void => {
119
- if (!managerRef.current) {
120
- return () => {};
121
- }
115
+ const subscribe = useCallback(
116
+ (trackId: string, callback: (event: MetaTrackEvent) => void): (() => void) => {
117
+ if (!managerRef.current) {
118
+ return () => {};
119
+ }
122
120
 
123
- const unsubscribe = managerRef.current.subscribe(trackId, callback);
124
- setSubscribedTracks(managerRef.current.getSubscribedTracks());
121
+ const unsubscribe = managerRef.current.subscribe(trackId, callback);
122
+ setSubscribedTracks(managerRef.current.getSubscribedTracks());
125
123
 
126
- return () => {
127
- unsubscribe();
128
- if (managerRef.current) {
129
- setSubscribedTracks(managerRef.current.getSubscribedTracks());
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 'react';
2
- import { QualityMonitor, type PlaybackQuality } from '@livepeer-frameworks/player-core';
3
- import type { UsePlaybackQualityOptions } from '../types';
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