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

@networked-aframe/minijanus

v0.7.0

Published

A small Javascript wrapper for talking to the Janus WebRTC signalling API.

Downloads

8

Readme

minijanus.js

npm

A super-simplistic and -minimal wrapper for talking to the Janus signalling API. Developed for use with Janus as a web game networking backend via janus-plugin-sfu, but fundamentally plugin-agnostic. Designed to provide useful possible abstractions while still providing the maximum possible control over RTCPeerConnection configuration and precise plugin signalling flow.

If you want a batteries-included wrapper, you should use the one distributed by the Janus developers -- janus.js. This one is different in a few ways:

  1. It doesn't try to maintain compatibility with older browsers very hard; the use case is modern browsers only.
  2. It's very small and straightforward, so it may serve as a useful reference client for people who want to better understand the signalling API.
  3. It gives you control over most of the configuration and usage of the RTCPeerConnection directly, whereas janus.js wraps and manages the connection for you.

If you want a similar but moderately more featureful wrapper, check out minnie-janus.

Example

Require minijanus in Node, or link to bundle.js in a browser. Then:

var ws = new WebSocket("ws://localhost:8188", "janus-protocol");
var session = new JanusPluginSession(ws.send.bind(ws));
var handle = new JanusPluginHandle(session);
var conn = new RTCPeerConnection({});

ws.addEventListener("message", ev => session.receive(JSON.parse(ev.data)));
ws.addEventListener("open", _ => {
  session.create()
    .then(_ => handle.attach("janus.plugin.sfu"))
    .then(_ => {
      conn.addEventListener("icecandidate", ev => {
        handle.sendTrickle(ev.candidate || null).catch(e => console.error("Error trickling ICE: ", e));
      });
      conn.addEventListener("negotiationneeded", _ => {
        var offer = conn.createOffer();
        var local = offer.then(o => conn.setLocalDescription(o));
        var remote = offer.then(j => handle.sendJsep(j)).then(r => conn.setRemoteDescription(r.jsep));
        Promise.all([local, remote]).catch(e => console.error("Error negotiating offer: ", e));
      });
      var unreliableCh = conn.createDataChannel("unreliable", { ordered: false, maxRetransmits: 0 });
      var reliableCh = conn.createDataChannel("reliable", { ordered: true });
      navigator.mediaDevices.getUserMedia({ audio: true })
        .then(m => m.getTracks().forEach(t => conn.addTrack(t, m)))
        .catch(e => console.error("Error acquiring media: ", e));
      return new Promise(resolve => handle.on("webrtcup", resolve));
    })
    .then(_ => { console.info("Connected to Janus: ", conn); })
    .catch(e => { console.error("Error connecting to Janus: ", e); });
});

(Note that this example code first negotiates only the data channels, and then renegotiates afterward when the microphone permission is provided. Only recent versions of Janus support renegotiation. If you didn't want this, you would instead wait to create the connection until the microphone permission was granted.)

Building

To generate bundle.js:

$ npm run build

Testing

$ npm test