Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

minijanus

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

minijanus

Really simple and minimal wrapper for talking to the Janus signalling API.

  • 0.1.6
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2
decreased by-33.33%
Maintainers
1
Weekly downloads
 
Created
Source

minijanus.js

npm Build Status

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.

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.

Example

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

var ws = new WebSocket("ws://localhost:8188", "janus-protocol");
  ws.addEventListener("open", () => {
  var session = new Minijanus.JanusSession(ws.send.bind(ws));
  ws.addEventListener("message", ev => session.receive(JSON.parse(ev.data)));
  session.create().then(() => establishConnection(session)).then(() => {
    console.info("Connection established: ", handle);
  });
});

function negotiateIce(conn, handle) {
  return new Promise((resolve, reject) => {
    conn.addEventListener("icecandidate", ev => {
      handle.sendTrickle(ev.candidate || null).then(() => {
        if (!ev.candidate) { // this was the last candidate on our end and now they received it
          resolve();
        }
      });
    });
  });
};

function establishConnection(session) {
  var conn = new RTCPeerConnection({});
  var handle = new Minijanus.JanusPluginHandle(session);
  return handle.attach("janus.plugin.sfu").then(() => {
    var iceReady = negotiateIce(conn, handle);
    var unreliableCh = conn.createDataChannel("unreliable", { ordered: false, maxRetransmits: 0 });
    var reliableCh = conn.createDataChannel("reliable", { ordered: true });
    var mediaReady = navigator.mediaDevices.getUserMedia({ audio: true });
    var offerReady = mediaReady
      .then(media => {
        conn.addStream(media);
        return conn.createOffer({ audio: true });
      }, () => conn.createOffer());
    var localReady = offerReady.then(conn.setLocalDescription.bind(conn));
    var remoteReady = offerReady
      .then(handle.sendJsep.bind(handle))
      .then(answer => conn.setRemoteDescription(answer.jsep));
    return Promise.all([iceReady, localReady, remoteReady]);
  });
}

Building

To generate bundle.js:

$ npm run build

Testing

$ npm run test

Keywords

FAQs

Package last updated on 14 Nov 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc