Installations
npm install youtube-player
Developer Guide
Typescript
No
Module System
CommonJS
Node Version
18.14.0
NPM Version
8.19.3
Score
97.5
Supply Chain
99.5
Quality
75.9
Maintenance
100
Vulnerability
100
License
Releases
Contributors
Unable to fetch Contributors
Languages
JavaScript (100%)
Developer
gajus
Download Statistics
Total Downloads
68,418,361
Last Day
16,893
Last Week
414,267
Last Month
1,733,798
Last Year
18,550,619
GitHub Statistics
373 Stars
109 Commits
80 Forks
12 Watching
11 Branches
14 Contributors
Package Meta Information
Latest Version
5.6.0
Package Id
youtube-player@5.6.0
Unpacked Size
32.07 kB
Size
7.82 kB
File Count
19
NPM Version
8.19.3
Node Version
18.14.0
Publised On
13 Feb 2023
Total Downloads
Cumulative downloads
Total Downloads
68,418,361
Last day
-11.3%
16,893
Compared to previous day
Last week
-4.3%
414,267
Compared to previous week
Last month
-5.6%
1,733,798
Compared to previous month
Last year
13%
18,550,619
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dependencies
3
Dev Dependencies
19
YouTube Player
youtube-player
is an abstraction of YouTube IFrame Player API (YIPA).
The downsides of using YouTube IFrame Player API are:
- Requires to define callbacks in the global scope (
window
). - Requires to track the state of a player (e.g. you must ensure that video player is "ready" before you can use the API).
youtube-player
:
- Registers listeners required to establish when YIPA has been loaded.
- Does not overwrite global YIPA callback functions.
- Queues player API calls until when video player is "ready".
Usage
1/** 2 * @typedef options 3 * @see https://developers.google.com/youtube/iframe_api_reference#Loading_a_Video_Player 4 * @param {Number} width 5 * @param {Number} height 6 * @param {String} videoId 7 * @param {Object} playerVars 8 * @param {Object} events 9 */ 10 11/** 12 * @typedef YT.Player 13 * @see https://developers.google.com/youtube/iframe_api_reference 14 * */ 15 16/** 17 * A factory function used to produce an instance of YT.Player and queue function calls and proxy events of the resulting object. 18 * 19 * @param {YT.Player|HTMLElement|String} elementId Either An existing YT.Player instance, 20 * the DOM element or the id of the HTML element where the API will insert an <iframe>. 21 * @param {YouTubePlayer~options} options See `options` (Ignored when using an existing YT.Player instance). 22 * @param {boolean} strictState A flag designating whether or not to wait for 23 * an acceptable state when calling supported functions. Default: `false`. 24 * See `FunctionStateMap.js` for supported functions and acceptable states. 25 * @returns {Object} 26 */ 27import YouTubePlayer from 'youtube-player';
youtube-player
is a factory function.
The resulting object exposes all functions of an instance of YT.Player
. The difference is that the function body is wrapped in a promise. This promise is resolved only when the player has finished loading and is ready to begin receiving API calls (onReady
). Therefore, all function calls are queued and replayed only when player is ready.
This encapsulation does not affect the API other than making every function return a promise.
1let player; 2 3player = YouTubePlayer('video-player'); 4 5// 'loadVideoById' is queued until the player is ready to receive API calls. 6player.loadVideoById('M7lc1UVf-VE'); 7 8// 'playVideo' is queue until the player is ready to received API calls and after 'loadVideoById' has been called. 9player.playVideo(); 10 11// 'stopVideo' is queued after 'playVideo'. 12player 13 .stopVideo() 14 .then(() => { 15 // Every function returns a promise that is resolved after the target function has been executed. 16 });
Events
player.on
event emitter is used to listen to all YouTube IFrame Player API events, e.g.
1player.on('stateChange', (event) => { 2 // event.data 3}); 4
player.off
removes a previously added event listener, e.g.
1var listener = player.on(/* ... */); 2 3player.off(listener); 4
Polyfills
Note that the built version does not inline polyfills.
You need to polyfill the environment locally (e.g. using a service such as https://polyfill.io/v2/docs/).
Examples
Debugging
youtube-player
is using debug
module to expose debugging information.
The debug
namespace is "youtube-player".
To display youtube-player
logs configure localStorage.debug
, e.g.
1localStorage.debug = 'youtube-player:*'; 2
Download
Using NPM:
1npm install youtube-player
Running the Examples
1npm install 2npm run build 3cd ./examples 4npm install 5npm run start
This will start a HTTP server on port 8000.
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Warn: project license file does not contain an FSF or OSI license.
Reason
dependency not pinned by hash detected -- score normalized to 3
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/feature.yaml:8: update your workflow using https://app.stepsecurity.io/secureworkflow/gajus/youtube-player/feature.yaml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/feature.yaml:12: update your workflow using https://app.stepsecurity.io/secureworkflow/gajus/youtube-player/feature.yaml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/main.yaml:8: update your workflow using https://app.stepsecurity.io/secureworkflow/gajus/youtube-player/main.yaml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/main.yaml:12: update your workflow using https://app.stepsecurity.io/secureworkflow/gajus/youtube-player/main.yaml/main?enable=pin
- Info: 0 out of 4 GitHub-owned GitHubAction dependencies pinned
- Info: 2 out of 2 npmCommand dependencies pinned
Reason
Found 7/25 approved changesets -- score normalized to 2
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: no topLevel permission defined: .github/workflows/feature.yaml:1
- Warn: no topLevel permission defined: .github/workflows/main.yaml:1
- Info: no jobLevel write permissions found
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 12 are checked with a SAST tool
Reason
23 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-67hx-6x53-jw92
- Warn: Project is vulnerable to: GHSA-cwfw-4gq5-mrqx
- Warn: Project is vulnerable to: GHSA-g95f-p29q-9xw4
- Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-f6v4-cf5j-vf3w
- Warn: Project is vulnerable to: GHSA-pfrx-2q88-qq97
- Warn: Project is vulnerable to: GHSA-rc47-6667-2j5j
- Warn: Project is vulnerable to: GHSA-78xj-cgh5-2h22
- Warn: Project is vulnerable to: GHSA-2p57-rm9w-gvfp
- Warn: Project is vulnerable to: GHSA-9c47-m6qq-7p4h
- Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv
- Warn: Project is vulnerable to: GHSA-w9mr-4mfr-499f
- Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw
- Warn: Project is vulnerable to: GHSA-f5x3-32g6-xq36
- Warn: Project is vulnerable to: GHSA-7p7h-4mm5-852v
- Warn: Project is vulnerable to: GHSA-wqq4-5wpv-mx2g
- Warn: Project is vulnerable to: GHSA-3787-6prv-h9w3
- Warn: Project is vulnerable to: GHSA-9qxr-qj54-h672
- Warn: Project is vulnerable to: GHSA-m4v8-wqvr-p9f7
- Warn: Project is vulnerable to: GHSA-j8xg-fqg3-53r7
- Warn: Project is vulnerable to: GHSA-3h5v-q93c-6h6q
- Warn: Project is vulnerable to: GHSA-p9pc-299p-vxgp
Score
3.1
/10
Last Scanned on 2024-12-16
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn MoreOther packages similar to youtube-player
react-player
A React component for playing a variety of URLs, including file paths, YouTube, Facebook, Twitch, SoundCloud, Streamable, Vimeo, Wistia and DailyMotion
@angular/youtube-player
Angular YouTube Player
@types/youtube-player
TypeScript definitions for youtube-player
react-youtube
React.js powered YouTube player component