Skip to content

Commit 2a1984d

Browse files
authored
Merge pull request #1058 from chintan9/update-jsdocs
add more jsdocs
2 parents f8487b6 + 11c5bbe commit 2a1984d

File tree

7 files changed

+50
-1
lines changed

7 files changed

+50
-1
lines changed

dist/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "plyr-react",
3-
"version": "5.1.2",
3+
"version": "5.2.0",
44
"private": false,
55
"description": "A simple HTML5, YouTube and Vimeo player for react using plyr",
66
"keywords": [

example/nextjs/pages/_app.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import "../styles/globals.css";
22

3+
/**
4+
* This is a functional component in JavaScript that returns a component with its props.
5+
* @returns The function `MyApp` is returning the `Component` with the `pageProps` passed as props.
6+
*/
37
function MyApp({ Component, pageProps }) {
48
return <Component {...pageProps} />;
59
}

example/nextjs/pages/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ import dynamic from "next/dynamic";
22

33
const VideoList = dynamic(() => import("../src/video-list"), { ssr: false });
44

5+
/**
6+
* The function returns a component that displays a heading and a list of videos.
7+
* @returns The `Home` component is being returned, which contains a `div` element with a heading
8+
* "Video List" and a `VideoList` component.
9+
*/
510
export default function Home() {
611
return (
712
<div>

example/nextjs/src/video-list.jsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ import Plyr from "plyr-react";
22
import "plyr-react/dist/plyr.css";
33
import contents from "./contents.json";
44

5+
/**
6+
* This code exports a React component called `VideoList` that renders a list of videos using the Plyr
7+
video player.
8+
* @returns Plyr instance
9+
*/
510
export default function VideoList() {
611
return (
712
<ul className="video-list">

example/react/src/audio-player/custom-audio-player.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import "plyr-react/dist/plyr.css";
44

55
const videoOptions = undefined;
66

7+
/* This object is used as the source for the `CustomPlyrInstance` component. */
78
const videoSource = {
89
type: "audio" as const,
910
sources: [
@@ -14,6 +15,9 @@ const videoSource = {
1415
],
1516
};
1617

18+
/* This code defines a custom React component called `CustomPlyrInstance` that uses the
19+
`React.forwardRef` function to forward a ref to a child component. The component takes in two props:
20+
`source` and `options`, which are used to configure the Plyr instance. */
1721
const CustomPlyrInstance = React.forwardRef<APITypes, PlyrProps>(
1822
(props, ref) => {
1923
const { source, options = null } = props;
@@ -29,6 +33,7 @@ const CustomPlyrInstance = React.forwardRef<APITypes, PlyrProps>(
2933
const { current } = ref as React.MutableRefObject<APITypes>;
3034
if (current.plyr.source === null) return;
3135

36+
/* This code is accessing the Plyr instance API and adding event listeners to it. */
3237
const api = current as { plyr: PlyrInstance };
3338
api.plyr.on("ready", () => console.log("I'm ready"));
3439
api.plyr.on("canplay", () => {
@@ -48,6 +53,9 @@ const CustomPlyrInstance = React.forwardRef<APITypes, PlyrProps>(
4853
}
4954
);
5055

56+
/* This code defines a functional component called `PlyrComponent` that renders a `CustomPlyrInstance`
57+
component with a `ref` and `source` and `options` props. The`source` and `options` props are used to
58+
configure the Plyr instance. The component is wrapped in a `div` with a class name of "wrapper". */
5159
const PlyrComponent = () => {
5260
const ref = React.useRef<APITypes>(null);
5361

example/react/src/hls-player/custom-hls-player.tsx

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,17 @@ const videoOptions = null;
88
const videoSource = null;
99
const hlsSource = "https://test-streams.mux.dev/x36xhzz/x36xhzz.m3u8";
1010

11+
/**
12+
* This is a custom hook in TypeScript React that loads and attaches an HLS video source to a Plyr
13+
* player, and sets the quality options for the player.
14+
* @param {string} src - The source URL of the video that will be played.
15+
* @param {Options | null} options - `options` is an object that contains optional configuration
16+
* options for the Plyr player. It can include properties such as `autoplay`, `controls`, `loop`,
17+
* `muted`, `seekTime`, `volume`, and more. This parameter is optional and can be `null`.
18+
* @returns The `useHls` function returns an object with a single property `options`, which is of type
19+
* `Options | null`. The `options` object contains information about the video quality and any other
20+
* custom event listeners that may have been added.
21+
*/
1122
const useHls = (src: string, options: Options | null) => {
1223
const hls = React.useRef<Hls>(new Hls());
1324
const hasQuality = React.useRef<boolean>(false);
@@ -37,6 +48,9 @@ const useHls = (src: string, options: Options | null) => {
3748
default: levels[levels.length - 1].height,
3849
options: levels.map((level) => level.height),
3950
forced: true,
51+
/* `onChange` is a callback function that gets triggered when the user changes the quality of
52+
the video. It takes in a `newQuality` parameter which is the new quality selected by the
53+
user. */
4054
onChange: (newQuality: number) => {
4155
console.log("changes", newQuality);
4256
levels.forEach((level, levelIndex) => {
@@ -54,6 +68,9 @@ const useHls = (src: string, options: Options | null) => {
5468
return { options: plyrOptions };
5569
};
5670

71+
/** `CustomPlyrInstance` is a custom React component that renders a video player using the Plyr library
72+
and supports HLS video streaming. It is created using the `React.forwardRef` function, which allows
73+
the component to receive a `ref` to the player instance as a prop. */
5774
const CustomPlyrInstance = React.forwardRef<
5875
APITypes,
5976
PlyrProps & { hlsSource: string }
@@ -66,13 +83,18 @@ const CustomPlyrInstance = React.forwardRef<
6683
return <video ref={raptorRef} className="plyr-react plyr" />;
6784
});
6885

86+
/** The `PlyrComponent` is a functional component that renders a video player using the Plyr library and
87+
supports HLS video streaming. If it is supported, it renders the `CustomPlyrInstance` component passing in the `ref`,
88+
`source`, `options`, and `hlsSource` props. If HLS is not supported, it renders a message saying so. */
6989
const PlyrComponent = () => {
7090
const ref = React.useRef<APITypes>(null);
7191
const supported = Hls.isSupported();
7292

7393
return (
7494
<div className="wrapper">
7595
{supported ? (
96+
/** `<CustomPlyrInstance>` is a custom React component that renders a video player using the
97+
Plyr library and supports HLS video streaming. It takes in several props: */
7698
<CustomPlyrInstance
7799
ref={ref}
78100
source={videoSource}

example/react/src/video-list/video-list.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ import Plyr from "plyr-react";
22
import "plyr-react/dist/plyr.css";
33
import contents from "./contents.json";
44

5+
/**
6+
* This code exports a React component called `VideoList` that renders a list of videos using the Plyr
7+
video player.
8+
* @returns Plyr instance
9+
*/
510
export default function VideoList() {
611
return (
712
<ul className="video-list">

0 commit comments

Comments
 (0)