Skip to content

Commit

Permalink
Check hls.js versions.
Browse files Browse the repository at this point in the history
  • Loading branch information
i-zolotarenko committed Dec 24, 2023
1 parent 4fc19a0 commit 2915669
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 10 deletions.
1 change: 1 addition & 0 deletions p2p-media-loader-demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite + React + TS</title>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/hls.js@latest/dist/hls.min.js"></script>
<script
type="text/javascript"
src="https://cdn.jsdelivr.net/npm/clappr@latest"
Expand Down
1 change: 0 additions & 1 deletion p2p-media-loader-demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
},
"dependencies": {
"dplayer": "^1.27.1",
"hls.js": "^1.4.14",
"mux.js": "^6.3.0",
"p2p-media-loader-hlsjs": "workspace:*",
"p2p-media-loader-shaka": "workspace:*",
Expand Down
13 changes: 7 additions & 6 deletions p2p-media-loader-demo/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React, { useCallback, useEffect, useRef, useState } from "react";
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 muxjs from "mux.js";
import debug from "debug";
Expand Down Expand Up @@ -54,7 +53,7 @@ function App() {
);
const [streamUrl, setStreamUrl] = useState<string>(localStorage.streamUrl);
const shakaInstance = useRef<shaka.Player>();
const hlsInstance = useRef<Hls>();
const hlsInstance = useRef<any>();
const containerRef = useRef<HTMLDivElement>(null);
const videoRef = useRef<HTMLVideoElement>(null);
const [httpLoaded, setHttpLoaded] = useState<number>(0);
Expand Down Expand Up @@ -97,7 +96,7 @@ function App() {

useEffect(() => {
if (
!Hls.isSupported() ||
!window.Hls.isSupported() ||
(window as unknown as ExtendedWindow).videoPlayer
) {
return;
Expand All @@ -113,14 +112,16 @@ function App() {
createNewPlayer();
}, [playerType]);

const setPlayerToWindow = (player: DPlayer | ShakaPlayer | Hls) => {
const setPlayerToWindow = (
player: DPlayer | ShakaPlayer | typeof window.Hls,
) => {
(window as unknown as ExtendedWindow).videoPlayer = player;
};

const initHlsJsPlayer = (url: string) => {
if (!videoRef.current || !hlsEngine.current) return;
const engine = hlsEngine.current;
const hls = new Hls({
const hls = new window.Hls({
...engine.getConfig(),
});
engine.setHls(hls);
Expand All @@ -140,7 +141,7 @@ function App() {
type: "customHls",
customType: {
customHls: (video: HTMLVideoElement) => {
const hls = new Hls({
const hls = new window.Hls({
...engine.getConfig(),
liveSyncDurationCount: 7,
});
Expand Down
1 change: 1 addition & 0 deletions p2p-media-loader-demo/src/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ declare global {
DashShakaPlayback: any;
shaka: any;
muxjs: any;
Hls: any;
}
}

Expand Down
3 changes: 0 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 2915669

Please sign in to comment.