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

castable-video

v1.0.7

Published

Cast your video element to the big screen with ease!

Downloads

273,568

Readme

<castable-video>

NPM Version NPM Downloads jsDelivr hits (npm) npm bundle size

Cast your video element to the big screen with ease!

The lightweight CastableVideoElement class extends the native HTMLVideoElement API and adds casting functionality to any video element. The API aims to be equivalent to the Remote Playback API with a few extra element attributes specific to casting.

It was primarily built for use in Media Chrome but it works great with any custom video controls as you can see in the example.

<script type="module" src="https://cdn.jsdelivr.net/npm/castable-video/+esm"></script>

<castable-video
  id="castable"
  src="https://stream.mux.com/DS00Spx1CV902MCtPj5WknGlR102V5HFkDe/high.mp4"
></castable-video>

<button onclick="castable.play()">Play</button>
<button onclick="castable.pause()">Pause</button>
<button id="castBtn" hidden onclick="castable.prompt()">Cast...</button>

<script type="module">
  castable.remote.watchAvailability((available) => {
    castBtn.hidden = !available;
  });

  castable.remote.addEventListener('connecting', function (event) {
    console.log(event.type);
  });

  castable.remote.addEventListener('connect', function (event) {
    console.log(event.type);
  });

  castable.remote.addEventListener('disconnect', function (event) {
    console.log(event.type);
  });
</script>

Remote Playback API

https://developer.mozilla.org/en-US/docs/Web/API/RemotePlayback

Methods

  • video.remote.prompt(): open the browser casting menu.
  • video.remote.watchAvailability(callback): watch if remote devices are available.
  • video.remote.cancelWatchAvailability(callback): cancel watching for remote devices.

Properties

  • video.remote.state: the current cast state.
    • disconnected: Cast devices are available, but a cast session is not established.
    • connecting: Cast session is being established.
    • connected: Cast session is established.
  • castOptions [readonly]: the cast options passed to the cast session.
    • receiverApplicationId: defaults to Chromecast default receiver.
    • autoJoinPolicy ('ORIGIN_SCOPED')
    • androidReceiverCompatible (false): if true enables Cast Connect.
    • language ('en-US')
    • resumeSavedSession (true)

Events

  • connecting: fires when a cast session is being established.
  • connect: fires when starting casting.
  • disconnect: fires when stopping casting.

e.g. video.remote.addEventListener('connect', () => {})

Attributes

Each attribute has a corresponding element property. e.g. video.castSrc or video.castStreamType.

  • cast-src: if Chromecast requires a different source than the one loaded.
    For example this would be needed if video src is a blob when using MSE.
  • cast-stream-type: add <castable-video cast-stream-type="live"> for live streams.
  • cast-content-type: required if Chromecast can't derive the content type from the source.
  • cast-receiver: the Chromecast receiver app id. Defaults to CC1AD845.

Usage with MSE (for example Hls.js or Dash.js)

When your media element is using Media Source Extension (MSE) element has a src like src="blob://.... If you are using Hls.js or Dash.js you may have noticed this. Because of the blob://.., castable-video has no way to know what the source is, so you must set the cast-src= attribute to the full URL of the video source.

Related