Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Commit 3692321

Browse files
committed
Update compilation of module, and usage with typescript
1 parent 28f84a3 commit 3692321

8 files changed

Lines changed: 21 additions & 60 deletions

File tree

.eslintrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
"react/prefer-stateless-function": "off",
3232
"react/prop-types": 0,
3333
"react-hooks/exhaustive-deps": "warn",
34+
"jsx-a11y/media-has-caption": "off",
3435
"prettier/prettier": [
3536
"error",
3637
{

README.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,6 @@
55
![Libraries.io dependency status for latest release](https://img.shields.io/librariesio/release/npm/react-hls-player)
66
![npm bundle size](https://img.shields.io/bundlephobia/min/react-hls-player)
77

8-
## Overview
9-
10-
V2 is now out and includes better TypeScript support. I had to make a large jump from the previous V1 as this new version included a couple small breaking changes, primarily to the way props are named. One big difference, is that the component now accepts all video element props in the formatting you would expect them with (previously autoPlay was passed as autoplay, and various other props weren't being handled properly). We're also using `src` instead of `url` to provide the source to the underlying video player.
11-
12-
As always, PRs, issues and recommendations are always welcome.
13-
148
## Introduction
159

1610
`react-hls-player` is a simple HLS live stream player.

example/App/App.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ function App() {
6565
loop={true}
6666
width="100%"
6767
height="auto"
68-
autoPlay={true}
68+
autoPlay
6969
playerRef={playerRef}
7070
src={hlsUrl}
7171
/>

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "react-hls-player",
33
"version": "3.0.0",
44
"description": "A simple and easy to use react component for playing an hls live stream",
5-
"main": "./dist/react-hls-player.js",
5+
"main": "./dist/index.js",
66
"types": "./dist",
77
"scripts": {
88
"test": "echo \"Error: no test specified\" && exit 1",

src/index.tsx

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,13 @@ function ReactHlsPlayer({
3737

3838
newHls.on(Hls.Events.MANIFEST_PARSED, () => {
3939
if (autoPlay) {
40-
playerRef?.current?.play();
40+
playerRef?.current
41+
?.play()
42+
.catch(() =>
43+
console.log(
44+
'Unable to autoplay prior to user interaction with the dom.'
45+
)
46+
);
4147
}
4248
});
4349
});
@@ -61,7 +67,10 @@ function ReactHlsPlayer({
6167
hls = newHls;
6268
}
6369

64-
_initPlayer();
70+
// Check for Media Source support
71+
if (Hls.isSupported()) {
72+
_initPlayer();
73+
}
6574

6675
return () => {
6776
if (hls != null) {
@@ -70,7 +79,11 @@ function ReactHlsPlayer({
7079
};
7180
}, [autoPlay, hlsConfig, playerRef, src]);
7281

73-
return <video ref={playerRef} {...props} />;
82+
// If Media Source is supported, use HLS.js to play video
83+
if (Hls.isSupported()) return <video ref={playerRef} {...props} />;
84+
85+
// Fallback to using a regular video player if HLS is supported by default in the user's browser
86+
return <video ref={playerRef} src={src} autoPlay={autoPlay} {...props} />;
7487
}
7588

7689
export default ReactHlsPlayer;

typings/index.d.ts

Lines changed: 0 additions & 24 deletions
This file was deleted.

webpack/webpack.dev.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ module.exports = merge(config, {
1212
open: true,
1313
historyApiFallback: true,
1414
contentBase: 'public',
15+
host: '0.0.0.0',
16+
public: 'localhost:8000',
1517
},
1618
plugins: [
1719
new HtmlWebpackPlugin({

webpack/webpack.prod.js

Lines changed: 0 additions & 25 deletions
This file was deleted.

0 commit comments

Comments
 (0)