Skip to content

Commit

Permalink
Use bundled flv.js
Browse files Browse the repository at this point in the history
By default react-player tries to lazy-load playback SDK from CDN.
But the application must be able play video files when Internet
connection is not available. To solve that we bundle flv.js and
initialize global variable consumed by react-player's FilePlayer.

See https://www.npmjs.com/package/react-player#sdk-overrides
See cookpete/react-player#605 (comment)
  • Loading branch information
stepan-anokhin committed Oct 26, 2020
1 parent c954a37 commit 5b36c43
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
19 changes: 19 additions & 0 deletions web/package-lock.json

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

1 change: 1 addition & 0 deletions web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"clsx": "^1.1.1",
"d3": "^6.2.0",
"date-fns": "^2.16.1",
"flv.js": "^1.5.0",
"fontsource-roboto": "^2.1.4",
"get-user-locale": "^1.4.0",
"http-status-codes": "^1.4.0",
Expand Down
23 changes: 23 additions & 0 deletions web/src/collection/components/VideoDetailsPage/VideoPlayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,33 @@ import { makeStyles } from "@material-ui/styles";
import { FileType } from "../FileBrowserPage/FileType";
import MediaPreview from "../../../common/components/MediaPreview";
import ReactPlayer from "react-player";
import { FLV_GLOBAL } from "react-player/lib/players/FilePlayer";
import flvjs from "flv.js";
import TimeCaption from "./TimeCaption";
import VideoController from "./VideoController";
import { useServer } from "../../../server-api/context";
import { Status } from "../../../server-api/Response";
import { useIntl } from "react-intl";
import WarningOutlinedIcon from "@material-ui/icons/WarningOutlined";

/**
* Setup bundled flv.js.
*
* By default react-player tries to lazy-load playback SDK from CDN.
* But the application must be able play video files when Internet
* connection is not available. To solve that we bundle flv.js and
* initialize global variable consumed by react-player's FilePlayer.
*
* See https://www.npmjs.com/package/react-player#sdk-overrides
* See https://github.com/CookPete/react-player/issues/605#issuecomment-492561909
*/
function setupBundledFlvJs() {
const FLV_VAR = FLV_GLOBAL || "flvjs";
if (window[FLV_VAR] == null) {
window[FLV_VAR] = flvjs;
}
}

const useStyles = makeStyles((theme) => ({
container: {},
preview: {
Expand Down Expand Up @@ -68,6 +88,9 @@ const VideoPlayer = function VideoPlayer(props) {
const controller = useMemo(() => new VideoController(player, setWatch), []);
const previewActions = useMemo(() => makePreviewActions(handleWatch), []);

// Make sure flv.js is available
useEffect(setupBundledFlvJs, []);

// Provide controller to the consumer
useEffect(() => onReady && onReady(controller), [onReady]);

Expand Down

0 comments on commit 5b36c43

Please sign in to comment.