Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 5 additions & 5 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ import resolve from "@rollup/plugin-node-resolve";
import commonjs from "@rollup/plugin-commonjs";
import typescript from "@rollup/plugin-typescript";
import dts from "rollup-plugin-dts";

const packageJson = require("./package.json");

import { terser } from "rollup-plugin-terser";
import peerDepsExternal from 'rollup-plugin-peer-deps-external';
import peerDepsExternal from "rollup-plugin-peer-deps-external";
const packageJson = require("./package.json");

export default [
{
Expand All @@ -23,6 +21,8 @@ export default [
sourcemap: true,
},
],
// Mark dependencies like react, react-dom, and hls.js as external
external: ["react", "react-dom", "hls.js"],
plugins: [
peerDepsExternal(),
resolve(),
Expand All @@ -36,4 +36,4 @@ export default [
output: [{ file: "dist/index.d.ts", format: "esm" }],
plugins: [dts()],
},
];
];
31 changes: 30 additions & 1 deletion src/components/ReactNetflixPlayer/index.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import Hls from 'hls.js';
import React, { useEffect, useState, useRef, SyntheticEvent } from 'react';
import i18n from 'i18next';
import { useTranslation, initReactI18next } from 'react-i18next';
Expand Down Expand Up @@ -506,6 +507,35 @@ export default function ReactNetflixPlayer({
setPlaying(autoPlay);
}
}, [src]);

useEffect(() => {
const video = videoComponent.current;
if (!video || !src) return;

// If it's HLS (.m3u8)
if (src.endsWith('.m3u8')) {
if (Hls.isSupported()) {
const hls = new Hls();
hls.loadSource(src);
hls.attachMedia(video);

hls.on(Hls.Events.ERROR, function (event, data) {
console.error('HLS.js error:', data);
});

return () => {
hls.destroy();
};
} else if (video.canPlayType('application/vnd.apple.mpegurl')) {
// Safari native support
video.src = src;
}
} else {
// Fallback for regular .mp4 or other types
video.src = src;
}
}, [src]);


useEffect(() => {
document.addEventListener('keydown', getKeyBoardInteration, false);
Expand Down Expand Up @@ -614,7 +644,6 @@ export default function ReactNetflixPlayer({
{/* eslint-disable-next-line jsx-a11y/media-has-caption */}
<video
ref={videoComponent}
src={src}
controls={false}
onCanPlay={() => startVideo()}
onTimeUpdate={timeUpdate}
Expand Down