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

nile.js

v1.0.13

Published

A tool for scalable peer-to-peer video streaming using WebTorrent

Downloads

12

Readme

nile.js

A tool for scalable peer-to-peer video streaming using WebTorrent.

Why WebTorrent?

By using the collective power of WebTorrent, video streams get progressively stronger as more peers contribute to a torrent. With torrents, it is also possible for users to access previous parts of a stream unlike traditional WebRTC video streaming.

About

Server

This is the plug-and-play middleware that receives the torrent link from the broadcasting client and sets up the proper Socket.io connections for the viewing clients.

Broadcaster

This is the client component that records video from a device's camera, saving it to generated torrent files, and sending those torrents' magnet link out to the viewing clients.

Viewer

This is the client which views what the Broadcaster is recording. It receives a torrent magnet link and renders the video from that torrent to an injected video tag using WebTorrent.

Usage

Server

Nile.js utilizes Express middleware and socket.io to receive torrent information, broadcast it to as many clients it can comfortably handle who will then send it out to the rest of the clients.

To use it, require nileServer from our package and pass in the Node Server instance you're using. In Express, you can get this instance by calling app.listen:

const server = app.listen(8000);
const nileServer = require('nile.js/nileServer')(server);

Now add the nile.js middleware w/ app.use:

app.use('/', nileServer);

Note that this middleware will use a "magnet" route to accept POST requests with the magnet link from the Broadcaster.

Client

Broadcaster

If using a file bundler e.g. (webpack), you may import the module.

import { Broadcaster } from 'nile.js'

If you just want to test the module without bundling, it is currently being hosted on unpkg CDN. Use it as a script in your html file.

https://unpkg.com/[email protected]/client/dist/nile.Broadcaster.min.js

4 parameters:

  1. recordInterval - The Interval that the webcam recording should seed each segment of the video (ms)
  2. videoNodeIDForPlayback - The id of the video node in the html where the broadcaster can see their own recording
  3. startStreamID - The id of the button node that BEGINS the recording/live streaming
  4. stopStreamID - The id of the button node that ENDS the recording/live streaming

The Broadcaster object is used to stream video to a torrent and send the torrent link to the server and then to the network of viewers.

Because torrents are immutable, we approximate streaming with torrents by setting a recordInterval, in milliseconds. This sets how long each clip will be before being sent via torrent. From our experience, we recommend an interval 6000-10000 (6-10 seconds).

Next, pass in the ID of the video tag you'd like to view your recording playback from as well as button IDs for the starting and stopping the stream.

Example:

const broadcaster = new Broadcaster(8000, 'video', 'button-play-gum', 'button-stop-gum');

Viewer

If using a file bundler e.g. (webpack), you may import the module.

import { Viewer } from 'nile.js'

If you just want to test the module without bundling, it is currently being hosted on unpkg CDN. Use it as a script in your html file.

https://unpkg.com/[email protected]/client/dist/nile.Viewer.min.js

2 parameters:

  1. ID_of_NodeToRenderVideo - ID of DOM element to render live feed to
  2. addedIceServers - Array of extra WebRTC ICE servers, based on this interface laid out by W3C

The Viewer object receives torrent links from Socket.io or RTCDataChannel connections and progressively renders the videos from the torrents to the supplied ID, ID_of_NodeToRenderVideo.

Example:

const viewer = new Viewer('videos');

The Viewer maintains two WebRTC connections, one to a parent (client closest to server) and a child client (farther from server). These two connections create a chain of clients that propagate server-sent torrent information down to subsequent viewers down the chain.

In the event of a client disconnecting, the disconnecting Viewer will let its immediate child client know and tell it to reconnect to its parent. This maintains network integrity and ensures that the stream will still reach every client in that chain.