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

bitstream-js

v1.3.0

Published

A simple javascript library to enable P2P playback / streaming on an HLS source.

Downloads

4

Readme

Bitstream.js

A simple javascript library to enable P2P playback / streaming on an HLS source.

How it works

After you have a stream playlist loading with P2P is as simple as with Hls.js. On any html page on your site you simply need to include a single javascript dependency and instantiate the stream with a video tag:

<html>

<head>
  <script src="https://cdn.jsdelivr.net/npm/bitstream-js@latest"></script>
  <style>
    #video {
      width: 100%;
    }
  </style>
</head>

<body>
  <video id="video" controls></video>

  <script>
    const video = document.getElementById("video");
    const stream = new Bitstream();
    stream.attachMedia(video);
    stream.loadSource("stream.m3u8");
  </script>
</body>

</html>

This will then allow viewers of the stream to share chunks with each other when available instead of only downloading them from the stream server.

How to instantiate a simple stream

You send your stream via rtmp to a VPS (eg. using NGINX with the rtmp plugin). Then, start a stream with ffmpeg:

ffmpeg -i /dev/video0 -f hls -hls_time 5 -hls_playlist_type event rtmp://[hostname]:1935/live/stream

Then just add the bitstream script tag, and load the source from wherever you are writing the HLS manifest file to.

Affect on bandwidth

Ideally the bandwidth reduction from P2P will be enough to get this to run on a metered VPS. However, that depends on several factors. If the viewers are geographically distributed then P2P will hit less often.

Take a simple calculation of a 720p stream with 5000 live viewers. Traditionally if you have to stream to every viewer at a cost of $0.01 / GB. Then a 2 hour livestream will cost $100 to run. That's a pretty heafty toll depending on how frequently audience members donate etc. However with Bitstream (depending on geographic distribution, and user connectivity) you can typically expect over 80% p2p, and so the bandwidth would cost around $20.

Why not PeerTube?

We actually use the same P2P streaming technology from peertube and bundle it differently. However we feel like there are many thousands of lines of code in Peertube that are unnecessary when trying to do something simple like get video streamed P2P. A lot of that code is for purposes of integrating ActivityPub, and another huge amount is used to make it "feel" like youtube.

Bitstream's philosophy is different. It asks why blogging is relatively decentralized where video sharing is not, the answer seems to be bandwidth (and thus the need to couple the data to a proprietary platform which can show ads to pay the data transfer bills).

Note

There is a setting in modern Firefox to disable webrtc peers. In this case we fall back to plain old HLS, but you may want to warn users that they are sucking up bandwidth using this setting. The setting is media.peerconnection. Eventually we might allow for a "force P2P setting" to be handled in case you very need to conserve bandwidth.