From 01f7a58f88e0087b2c5d1471f1e9058bd01f4d09 Mon Sep 17 00:00:00 2001 From: Igor Zolotarenko Date: Mon, 27 Nov 2023 23:08:47 +0200 Subject: [PATCH 01/17] Add clappr player. --- p2p-media-loader-demo/package.json | 1 + p2p-media-loader-demo/src/App.tsx | 79 +++++++++++++++---- p2p-media-loader-demo/src/declarations.d.ts | 1 + packages/p2p-media-loader-hlsjs/src/engine.ts | 4 +- pnpm-lock.yaml | 15 +++- 5 files changed, 77 insertions(+), 23 deletions(-) diff --git a/p2p-media-loader-demo/package.json b/p2p-media-loader-demo/package.json index 94839827..142aa51e 100644 --- a/p2p-media-loader-demo/package.json +++ b/p2p-media-loader-demo/package.json @@ -12,6 +12,7 @@ "type-check": "npx tsc --noEmit" }, "dependencies": { + "@clappr/player": "^0.5.0", "dplayer": "^1.27.1", "hls.js": "^1.4.5", "mux.js": "^6.3.0", diff --git a/p2p-media-loader-demo/src/App.tsx b/p2p-media-loader-demo/src/App.tsx index f6b1434c..4299c58a 100644 --- a/p2p-media-loader-demo/src/App.tsx +++ b/p2p-media-loader-demo/src/App.tsx @@ -3,23 +3,27 @@ import { Engine as HlsJsEngine } from "p2p-media-loader-hlsjs"; import { Engine as ShakaEngine } from "p2p-media-loader-shaka"; import Hls from "hls.js"; import DPlayer from "dplayer"; +import Clappr from "@clappr/player"; import shakaLib from "shaka-player"; import muxjs from "mux.js"; import debug from "debug"; window.muxjs = muxjs; +(window as any).Clappr = Clappr; +(window as any).Hls = Hls; const players = [ "hlsjs", "hls-dplayer", "shaka-dplayer", "shaka-player", + "hls-clappr", ] as const; type Player = (typeof players)[number]; type ShakaPlayer = shaka.Player; type ExtendedWindow = Window & { videoPlayer?: { destroy?: () => void } }; -const streamUrl = { +const streamUrls = { bigBunnyBuck: "https://test-streams.mux.dev/x36xhzz/x36xhzz.m3u8", byteRangeVideo: "https://devstreaming-cdn.apple.com/videos/streaming/examples/bipbop_16x9/bipbop_16x9_variant.m3u8", @@ -52,7 +56,7 @@ function App() { const [playerType, setPlayerType] = useState( localStorage.player ); - const [url, setUrl] = useState(localStorage.streamUrl); + const [streamUrl, setStreamUrl] = useState(localStorage.streamUrl); const shakaInstance = useRef(); const hlsInstance = useRef(); const containerRef = useRef(null); @@ -106,10 +110,9 @@ function App() { setPlayerType("hls-dplayer"); } if (!localStorage.streamUrl) { - localStorage.streamUrl = streamUrl.live2; - setUrl(streamUrl.live2); + localStorage.streamUrl = streamUrls.live2; + setStreamUrl(streamUrls.live2); } - createNewPlayer(); }, [playerType]); @@ -207,6 +210,25 @@ function App() { setPlayerToWindow(player); }; + const initHlsClapprPlayer = (url: string) => { + const engine = hlsEngine.current!; + const clapprPlayer = new Clappr.Player({ + parentId: "#player-container", + source: url, + playback: { + hlsjsConfig: { + ...engine.getConfig(), + // enableWorker: true, + }, + }, + }); + clapprPlayer.play(); + console.log(engine); + console.log(clapprPlayer); + initClapprPlayer(clapprPlayer); + setPlayerToWindow(clapprPlayer); + }; + const destroyAndWindowPlayer = () => { const extendedWindow = window as ExtendedWindow; extendedWindow.videoPlayer?.destroy?.(); @@ -219,9 +241,9 @@ function App() { destroyAndWindowPlayer(); }; - const onVideoUrlChange = (url: string) => { - localStorage.streamUrl = url; - setUrl(url); + const onVideoUrlChange = (streamUrl: string) => { + localStorage.streamUrl = streamUrl; + setStreamUrl(streamUrl); }; const createNewPlayer = () => { @@ -229,16 +251,19 @@ function App() { setP2PLoadedGlob(0); switch (playerType) { case "hls-dplayer": - initHlsDPlayer(url); + initHlsDPlayer(streamUrl); break; case "hlsjs": - initHlsJsPlayer(url); + initHlsJsPlayer(streamUrl); break; case "shaka-dplayer": - initShakaDPlayer(url); + initShakaDPlayer(streamUrl); break; case "shaka-player": - initShakaPlayer(url); + initShakaPlayer(streamUrl); + break; + case "hls-clappr": + initHlsClapprPlayer(streamUrl); break; } }; @@ -247,11 +272,11 @@ function App() { switch (playerType) { case "hls-dplayer": case "hlsjs": - hlsInstance.current?.loadSource(url); + hlsInstance.current?.loadSource(streamUrl); break; case "shaka-player": case "shaka-dplayer": - shakaInstance.current?.load(url).catch(() => undefined); + shakaInstance.current?.load(streamUrl).catch(() => undefined); break; } }; @@ -277,10 +302,10 @@ function App() { })}