npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

video-cocoon

v1.0.2

Published

JavaScript API wrapper for video platforms that support an iFrame API

Downloads

6

Readme

VideoCocoon

VideoCocoon is a JavaScript API wrapper for video platforms that support an iFrame API. Its purpose is to simplify development with JavaScript video APIs.

Contents

Demo

View a demo illustrating the usage of VideoCocoon.

Installation

NPM

npm i video-cocoon --save

Yarn

yarn add video-cocoon

Usage

Include JavaScript Dependencies

VideoCocoon comes with multiple files that can be loaded asynchronously:

  • VideoCocoon core
  • Provider Implementations
    • YouTube
    • Vimeo
<script type="text/javascript" src="src/script/video-cocoon.js"></script>
<script type="text/javascript" src="src/script/provider/youtube.js"></script>
<script type="text/javascript" src="src/script/provider/vimeo.js"></script>

Alternatively, you may include a bundled version in your project.

<script type="text/javascript" src="src/script/video-cocoon-bundled.js"></script>

Create a new player

Define the HTML object to be used as the target for the iFrame embed (The target option defaults to <body/>):

<div id="youtube-video-example" class="video" data-src="https://www.youtube.com/watch?v=_QqfifH3-rk"></div>

Utilize the VideoCocoon.init method to create a new player.

<script type="text/javascript">
var player = VideoCocoon.init({
  target: document.getElementById('youtube-video-example')
});
</script>

Interact with the player

VideoCocoon.init will return a player object. This object can be referenced to interact with the player:

<script type="text/javascript">
player.play();
</script>

Options

  • target (String | Node) - Default <body/>
    • A selector string or DOM object used to specify where the iFrame is to be embedded.
  • src (String)
    • The video source URL to be parsed for iFrame embedding.
      • The src option can also be implemented via a data-src attribute on the target element
      • The custom for source URLs is to utilize the URL used to view the video on the provider's platform.
  • class (Object)
    • frame (String)
      • CSS class applied to iFrame element
  • events (Object)
    • Object for registering callback events upon player initialization. See the events section for available events.
  • params (Object)
    • api (Object)
      • Arguments passed directly to the provider's JavaScript API
    • query (Object)
      • Arguments added as query parameters to the iFrame's src URL

Methods

Methods are registered directly on the player object.

  • play
  • pause
  • stop
  • seek
  • toggle
    • Toggles the play/pause player status
  • on(name, callback)
    • Method used to register event callbacks on the player instance.
    • Arguments
  • trigger(name)
    • Method used to trigger event callbacks
    • Arguments

Native provider methods can be accessed from the player property of the player object:

Events

Callbacks are registered on a player object via the events property. The player object is set as the scope for callback events.

VideoCocoon events:

  • onApiLoaded
    • Called when the provider API associated with the player is loaded
  • onFrameEmbed
    • Called when the iFrame created for the player is embedded in the DOM
  • onPlayerInitialized
    • Called when the player has finished being initialized

API provider native events:

Player Object

A player object instance is returned when initializing a video via the VideoCocoon.init method. All the player instances are stored in the players property of the VideoCocoon object (VideoCocoon.players).

Refer to the methods section to see available methods on a player instance.

Other properties available on a player instance:

  • events (Object)
    • Object that holds all of the callback events registered on a player.
  • frame (Node)
    • The <iframe/> DOM element created for the embedded video
  • options (Object)
    • The options applied to the player instance
  • player (Object)
    • The API instance returned from the video provider's API
  • src (String)
    • The original source URL

API References

The following references were used for API implementations

Video Providers

Currently supported video providers include

  • YouTube
  • Vimeo

Refer to the video provider documentation for information regarding implementing a new video provider.

Browser Support

License

VideoCocoon is licensed under the MIT License. Go wild and make awesome things :)