Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: players #361

Merged
merged 55 commits into from
May 10, 2024
Merged
Show file tree
Hide file tree
Changes from 52 commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
69cfb52
hls clappr & dplayer
DimaDemchenko Apr 17, 2024
9bd174f
vime player
DimaDemchenko Apr 18, 2024
00d2c34
plyr player
DimaDemchenko Apr 18, 2024
1e71cfe
plyr instance
DimaDemchenko Apr 18, 2024
7ed3c22
openPlayer
DimaDemchenko Apr 18, 2024
b67a41a
added opt groups in playback options
DimaDemchenko Apr 18, 2024
754e21c
shaka player
DimaDemchenko Apr 19, 2024
8bddc57
separated player's props
DimaDemchenko Apr 19, 2024
dd89ff5
shaka DPlayer
DimaDemchenko Apr 19, 2024
cdf763f
Shaka Clappr
DimaDemchenko Apr 19, 2024
34d3b38
Clappr declaration
DimaDemchenko Apr 19, 2024
1b492d0
Add PlayerEvents type
DimaDemchenko Apr 19, 2024
b67ddd7
Plyr imporvements
DimaDemchenko Apr 20, 2024
7404de3
OpenPlayer improvements
DimaDemchenko Apr 20, 2024
c4c63bb
Simplified hls configuration with getConfiguredHlsInstance
DimaDemchenko Apr 20, 2024
7a1773f
simplified shakaP2PEngine configuration
DimaDemchenko Apr 20, 2024
8cd43c1
mediaelement test
DimaDemchenko Apr 20, 2024
a022ab5
simplified render func
DimaDemchenko Apr 21, 2024
1dd1309
shaka import improvements
DimaDemchenko Apr 22, 2024
524f960
fixed playback options
DimaDemchenko Apr 22, 2024
c3874b3
Clappr shakaP2PEngine
DimaDemchenko Apr 22, 2024
eee217b
shaka Plyr
DimaDemchenko Apr 22, 2024
f0aac1a
p2p engine destroy
DimaDemchenko Apr 22, 2024
4a6d5e9
refactored HLS integration in players
DimaDemchenko Apr 23, 2024
8383019
hls mediaElement player container
DimaDemchenko Apr 23, 2024
dbc775e
configure shaka events
DimaDemchenko Apr 23, 2024
45813e4
Plyr improvements
DimaDemchenko Apr 23, 2024
92f1d82
remove window.Hls on cleanup
DimaDemchenko Apr 24, 2024
ccc01bc
refactored cleanup logic for openPlayer
DimaDemchenko Apr 24, 2024
e0ae17d
small adjustments
DimaDemchenko Apr 24, 2024
ff4f57d
small adjustments
DimaDemchenko Apr 24, 2024
3df8c82
MediaElement bug fixed
DimaDemchenko Apr 24, 2024
55a9953
shaka improvements
DimaDemchenko Apr 25, 2024
487b407
clappr styles
DimaDemchenko Apr 25, 2024
cc55355
shaka clappr
DimaDemchenko Apr 25, 2024
641efe5
type declaration
DimaDemchenko Apr 25, 2024
f1b563e
global declaration
DimaDemchenko Apr 25, 2024
e54954b
fixed type errors
DimaDemchenko Apr 26, 2024
4ba662b
Add HLS & shaka support check and error message for unsupported browsers
DimaDemchenko Apr 26, 2024
6dd17fd
Refactor useQueryParams hook to improve readability and performance
DimaDemchenko Apr 26, 2024
fa6d3ca
add custom quality selector for hlsjs player
DimaDemchenko Apr 29, 2024
5e89c63
Fix select-container alignment issue in Hlsjs.css
DimaDemchenko Apr 29, 2024
3e0f27e
removed redundant code
DimaDemchenko Apr 29, 2024
21d87c3
Add playsInline attribute to video elements in players
DimaDemchenko Apr 30, 2024
5581eb9
test vime with mp4
DimaDemchenko Apr 30, 2024
d0069c9
Add vidstack player
DimaDemchenko May 1, 2024
5566b94
Update HLS provider library
DimaDemchenko May 2, 2024
fb01000
Improve types
mrlika May 2, 2024
8a7afe2
simplified vidstack player setup
DimaDemchenko May 2, 2024
dd4c3ab
p2p config improvements
DimaDemchenko May 3, 2024
761b06d
fix type error
DimaDemchenko May 3, 2024
c3983de
changed default player
DimaDemchenko May 3, 2024
7860b04
added debug mode from query params
DimaDemchenko May 10, 2024
d584ad2
Removed Vime player since it will be deprecated
DimaDemchenko May 10, 2024
ee2f4d8
fixed naming
DimaDemchenko May 10, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
"dplayer": "^1.27.1",
"mux.js": "^6.3.0",
"p2p-media-loader-core": "workspace:*",
"p2p-media-loader-demo": "workspace:*",
"p2p-media-loader-hlsjs": "workspace:*",
"p2p-media-loader-shaka": "workspace:*",
"p2p-media-loader-demo": "workspace:*",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
Expand Down
68 changes: 68 additions & 0 deletions demo/public/mejs-controls.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 9 additions & 1 deletion packages/p2p-media-loader-demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,18 @@
"clean-with-modules": "rimraf node_modules && pnpm clean"
},
"dependencies": {
"@vidstack/react": "^1.11.21",
"@vime/react": "^5.4.1",
"d3": "^7.9.0",
"dplayer": "^1.27.1",
"hls.js": "^1.5.7",
"mediaelement": "^7.0.3",
"openplayerjs": "^2.14.3",
"p2p-media-loader-core": "workspace:*",
"p2p-media-loader-hlsjs": "workspace:*"
"p2p-media-loader-hlsjs": "workspace:*",
"p2p-media-loader-shaka": "workspace:*",
"plyr": "^3.7.8",
"shaka-player": "^4.7.13"
},
"devDependencies": {
"@types/d3": "^7.4.3",
Expand Down
76 changes: 51 additions & 25 deletions packages/p2p-media-loader-demo/src/components/P2PVideoDemo.tsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,55 @@
import "./demo.css";
import type Hls from "hls.js";
import { PlaybackOptions } from "./PlaybackOptions";
import { PLAYERS } from "../constants";
import { useQueryParams } from "../hooks/useQueryParams";
import { HlsjsPlayer } from "./players/Hlsjs";
import { HlsjsPlayer } from "./players/hlsjs/Hlsjs";
import { useCallback, useMemo, useRef, useState } from "react";
import { DownloadStatsChart } from "./chart/DownloadStatsChart";
import { NodeNetwork } from "./nodeNetwork/NodeNetwork";
import { DebugTools } from "./debugTools/DebugTools";
import { DownloadStats } from "../types";
import { DownloadStats, PlayerKey } from "../types";
import { HlsjsDPlayer } from "./players/hlsjs/HlsjsDPLayer";
import { HlsjsClapprPlayer } from "./players/hlsjs/HlsjsClapprPlayer";
import { HlsjsVime } from "./players/hlsjs/HlsjsVime";
import { HlsjsPlyr } from "./players/hlsjs/HlsjsPlyr";
import { HlsjsOpenPlayer } from "./players/hlsjs/HlsjsOpenPlayer";
import { Shaka } from "./players/shaka/Shaka";
import { ShakaDPlayer } from "./players/shaka/ShakaDPlayer";
import { ShakaClappr } from "./players/shaka/ShakaClappr";
import { HlsjsMediaElement } from "./players/hlsjs/HlsjsMediaElement";
import { ShakaPlyr } from "./players/shaka/ShakaPlyr";
import { HlsJsP2PEngine } from "p2p-media-loader-hlsjs";
import Hls from "hls.js";
import { HlsjsVidstack } from "./players/hlsjs/HlsjsVidstack";

type DemoProps = {
debugToolsEnabled?: boolean;
};

const HlsWithP2PType = HlsJsP2PEngine.injectMixin(Hls);

declare global {
interface Window {
Hls: typeof Hls;
videoPlayer?: { destroy?: () => void };
shaka?: unknown;
Hls?: typeof HlsWithP2PType;
LevelSelector: unknown;
DashShakaPlayback: unknown;
}
}

export type Player = (typeof PLAYERS)[number];

type DemoProps = {
debugToolsEnabled?: boolean;
const playerComponents = {
openPlayer_hls: HlsjsOpenPlayer,
plyr_hls: HlsjsPlyr,
vime_hls: HlsjsVime,
clappr_hls: HlsjsClapprPlayer,
dplayer_hls: HlsjsDPlayer,
hlsjs_hls: HlsjsPlayer,
shaka: Shaka,
dplayer_shaka: ShakaDPlayer,
clappr_shaka: ShakaClappr,
mediaElement_hls: HlsjsMediaElement,
plyr_shaka: ShakaPlyr,
vidstack_hls: HlsjsVidstack,
};

export const P2PVideoDemo = ({ debugToolsEnabled }: DemoProps) => {
Expand Down Expand Up @@ -72,26 +101,23 @@ export const P2PVideoDemo = ({ debugToolsEnabled }: DemoProps) => {
}, []);

const handlePlaybackOptionsUpdate = (url: string, player: string) => {
if (!PLAYERS.includes(player as Player)) return;
if (!(player in PLAYERS)) return;
setURLQueryParams({ streamUrl: url, player });
};

const renderPlayer = () => {
switch (queryParams.player) {
case "hlsjs":
return (
<HlsjsPlayer
streamUrl={queryParams.streamUrl}
announceTrackers={trackers}
onPeerConnect={onPeerConnect}
onPeerDisconnect={onPeerDisconnect}
onChunkDownloaded={onChunkDownloaded}
onChunkUploaded={onChunkUploaded}
/>
);
default:
return null;
}
const PlayerComponent = playerComponents[queryParams.player as PlayerKey];

return PlayerComponent ? (
<PlayerComponent
streamUrl={queryParams.streamUrl}
announceTrackers={trackers}
onPeerConnect={onPeerConnect}
onPeerDisconnect={onPeerDisconnect}
onChunkDownloaded={onChunkDownloaded}
onChunkUploaded={onChunkUploaded}
/>
) : null;
};

return (
Expand Down
38 changes: 31 additions & 7 deletions packages/p2p-media-loader-demo/src/components/PlaybackOptions.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useRef } from "react";
import { PLAYERS } from "../constants";
import { PlayerKey, PlayerName } from "../types";

type PlaybackOptions = {
updatePlaybackOptions: (url: string, player: string) => void;
Expand All @@ -17,6 +18,17 @@ export const PlaybackOptions = ({

const isHttps = window.location.protocol === "https:";

const hlsPlayers: Partial<Record<PlayerKey, PlayerName>> = {};
const shakaPlayers: Partial<Record<PlayerKey, PlayerName>> = {};

Object.entries(PLAYERS).forEach(([key, name]) => {
if (key.includes("hls")) {
hlsPlayers[key as PlayerKey] = name;
} else if (key.includes("shaka")) {
shakaPlayers[key as PlayerKey] = name;
}
});

const handleApply = () => {
const player = playerSelectRef.current?.value;
const streamUrl = streamUrlInputRef.current?.value;
Expand All @@ -34,6 +46,7 @@ export const PlaybackOptions = ({
Video URL{isHttps ? " (HTTPS only)" : ""}:
</label>
<input
key={streamUrl}
className="item"
defaultValue={streamUrl}
id="streamUrl"
Expand All @@ -45,16 +58,27 @@ export const PlaybackOptions = ({
<label htmlFor="player">Player:</label>
<select
className="item"
key={currentPlayer}
key={String(currentPlayer)}
ref={playerSelectRef}
id="player"
defaultValue={currentPlayer}
defaultValue={String(currentPlayer)}
>
{PLAYERS.map((player) => (
<option key={player} value={player}>
{player}
</option>
))}
<optgroup label="Hls.js P2P Engine (HLS Only)">
{Object.entries(hlsPlayers).map(([key, name]) => (
<option key={key} value={key}>
{name}
</option>
))}
</optgroup>
{Object.keys(shakaPlayers).length > 0 && (
<optgroup label="Shaka Players">
{Object.entries(shakaPlayers).map(([key, name]) => (
<option key={key} value={key}>
{name}
</option>
))}
</optgroup>
)}
</select>
</div>

Expand Down
9 changes: 9 additions & 0 deletions packages/p2p-media-loader-demo/src/components/demo.css
Original file line number Diff line number Diff line change
Expand Up @@ -146,3 +146,12 @@
display: flex;
gap: 1em;
}

.error-message {
margin-top: 1em;
padding: 1em;
background-color: #f8d7da;
border: 1px solid #f5c6cb;
border-radius: 0.25rem;
color: #721c24;
}
67 changes: 0 additions & 67 deletions packages/p2p-media-loader-demo/src/components/players/Hlsjs.tsx

This file was deleted.

Loading