You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is it possible to not load hls.js from cloudflare but locally from the own server? We are building a client website that cannot load from third party sites.
Reacted by Adrien J, Schuyler Jager, Tung M. Vu, Dan Cron, Peter Kogo, Brian Westphal, Dirk Haupt and Tali von Huth
I have done the same. I wonder if a PR would be accepted @cookpete cause that would solve a lot of GDPR issues in Europe if you could just reference a local file or your own CDN. :)
If the variables already exist then instead of sourcing the libraries from the CDN react-player simply expects the libraries to already be available at those variables. So all you need to do in your own code is source the libraries as you see fit, attach them to those window variables and then use react-player.
We use this in our own codebase and it works fine. It could be worth including this info in the documentation somewhere?
Reacted by Chris Grigg, nam, Karl, Thinh Kieu, Trevor and Burak
I am preparing to deploy this code to run on servers across the world in production. Some installations will have the server and the client (laptop/browser) connected to the internet, and some installations will be on local networks which are not connected to the internet. Thanks to the window variables provided (see the comment by @tim-mit), it won't be too hard for me to get this to run without internet connectivity.
However, my vote would be to change the code so that by default it does not dynamically download hls.min.js at run time. I would prefer the default to change so HLS is included at build time.
However, my vote would be to change the code so that by default it does not dynamically download hls.min.js at run time. I would prefer the default to change so HLS is included at build time.
This would bundle a 242 KB file into the library, for every implementation, regardless of if they are using HLS or not. Hopefully it's obvious why this isn't a great idea.
@tim-mit's solution is a happy coincidence, but actually quite elegant. Simply including the script (eg <script src="https://cdnjs.cloudflare.com/ajax/libs/hls.js/0.12.4/hls.min.js"></script>) before mounting the player, the library will use whatever is loaded in the global scope, as long as it makes the correct global available.
Hello guys , I am pretty new to React and web development in general . @tim-mit mentioned that we can change the values of HLS_GLOBAL and DASH_GLOBAL to get what we need by accessing some kind of window .
What does that mean ? does the window mean the div that wraps React-Player component ? or is there another way to access HLS_GLOBAL and DASH_GLOBAL ?
Edited:
now i have the code like this before I place the React-Player component
and that managed to crash the code which means i am getting closer , but what values i should place here ?
I got the following error Uncaught (in promise) TypeError: Hls is not a constructor
You'll need to get the Hls constructor that Hls.js exposes attached to the variable window.Hls.
The variable window is a special global object that the browser always has available, if you don't scope your variables differently they will be available as window.<variable name>.
From the looks of things just including <script src="https://cdnjs.cloudflare.com/ajax/libs/hls.js/0.12.4/hls.js"></script> before your own code will likely be enough no more code required as once that external code loads it sets window.Hls. Be careful of asynchronous loading though, i.e. don't try and auto-play in your own js code that may end up being invoked before the third party library has loaded.
If you're using npm modules you may be able to find one of those that packages hls.js up and then not have to worry about the script tag or async loading. You'd just import the Hls constructor provided by the module and then set window.hls to the value you imported.
I think this is a pretty unfortunate workaround, it feels brittle and unnecessary. While I agree that bundling Hls.js with ReactPlayer unfairly penalizes folks who aren't using hls, I feel like there should be a compromise to avoid quietly downloading files from a CDN. This might be extreme but maybe the Hls portions of this library could be split out into a separate package that includes hls.js as a dependency, similar to what you see with Apollo, Babel, Uppy, etc,...?
Regardless, thank you for your work on this library, it's excellent.
Activity
mryarbles commentedon Mar 26, 2019
I had the same issue. Had to fork this project to resolve.
mxmtsk commentedon Mar 26, 2019
I have done the same. I wonder if a PR would be accepted @cookpete cause that would solve a lot of GDPR issues in Europe if you could just reference a local file or your own CDN. :)
schuylr commentedon May 4, 2019
Ideally this should be bundled as a dependency, or at least give us the power to define where it loads from.
tim-mit commentedon May 15, 2019
FYI you can achieve this already and don't need to fork the project or wait for any changes before doing so.
The code that by default loads hls.js (and dash) from a CDN first calls the function at https://github.com/CookPete/react-player/blob/master/src/utils.js#L63-L66. What this does is check for the following window variables existing;
window.Hlswindow.dashjsThese values are defined in
HLS_GLOBALandDASH_GLOBALin https://github.com/CookPete/react-player/blob/master/src/players/FilePlayer.js#L11,L14.If the variables already exist then instead of sourcing the libraries from the CDN
react-playersimply expects the libraries to already be available at those variables. So all you need to do in your own code is source the libraries as you see fit, attach them to those window variables and then usereact-player.We use this in our own codebase and it works fine. It could be worth including this info in the documentation somewhere?
dancron commentedon Jun 12, 2019
I am preparing to deploy this code to run on servers across the world in production. Some installations will have the server and the client (laptop/browser) connected to the internet, and some installations will be on local networks which are not connected to the internet. Thanks to the window variables provided (see the comment by @tim-mit), it won't be too hard for me to get this to run without internet connectivity.
However, my vote would be to change the code so that by default it does not dynamically download hls.min.js at run time. I would prefer the default to change so HLS is included at build time.
cookpete commentedon Sep 19, 2019
This would bundle a 242 KB file into the library, for every implementation, regardless of if they are using HLS or not. Hopefully it's obvious why this isn't a great idea.
@tim-mit's solution is a happy coincidence, but actually quite elegant. Simply including the script (eg
<script src="https://cdnjs.cloudflare.com/ajax/libs/hls.js/0.12.4/hls.min.js"></script>) before mounting the player, the library will use whatever is loaded in the global scope, as long as it makes the correct global available.ahmad-crossplatform commentedon Oct 17, 2019
Hello guys , I am pretty new to React and web development in general .
@tim-mit mentioned that we can change the values of HLS_GLOBAL and DASH_GLOBAL to get what we need by accessing some kind of window .
What does that mean ? does the window mean the div that wraps React-Player component ? or is there another way to access HLS_GLOBAL and DASH_GLOBAL ?
Edited:
now i have the code like this before I place the React-Player component
and that managed to crash the code which means i am getting closer , but what values i should place here ?
I got the following error
Uncaught (in promise) TypeError: Hls is not a constructortim-mit commentedon Oct 17, 2019
You'll need to get the
Hlsconstructor that Hls.js exposes attached to the variablewindow.Hls.The variable
windowis a special global object that the browser always has available, if you don't scope your variables differently they will be available aswindow.<variable name>.From the looks of things just including
<script src="https://cdnjs.cloudflare.com/ajax/libs/hls.js/0.12.4/hls.js"></script>before your own code will likely be enough no more code required as once that external code loads it setswindow.Hls. Be careful of asynchronous loading though, i.e. don't try and auto-play in your own js code that may end up being invoked before the third party library has loaded.If you're using npm modules you may be able to find one of those that packages hls.js up and then not have to worry about the script tag or async loading. You'd just import the
Hlsconstructor provided by the module and then setwindow.hlsto the value you imported.chrislgrigg commentedon Apr 21, 2020
If anyone is using webpack and struggling with getting it just right, you can do it in your webpack config using
imports-loaderlike this:I think this is a pretty unfortunate workaround, it feels brittle and unnecessary. While I agree that bundling Hls.js with ReactPlayer unfairly penalizes folks who aren't using hls, I feel like there should be a compromise to avoid quietly downloading files from a CDN. This might be extreme but maybe the Hls portions of this library could be split out into a separate package that includes hls.js as a dependency, similar to what you see with Apollo, Babel, Uppy, etc,...?
Regardless, thank you for your work on this library, it's excellent.
Use bundled flv.js
Handle playback issues (#165)
Development (#197)
Add readme note about SDK overrides
Add readme note about SDK overrides
Add readme note about SDK overrides
Add readme note about SDK overrides
Add readme note about SDK overrides