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

rtc-tools

v5.6.0

Published

Cross-browser WebRTC helpers

Downloads

256

Readme

rtc-tools

The rtc-tools module does most of the heavy lifting within the rtc.io suite. Primarily it handles the logic of coupling a local RTCPeerConnection with it's remote counterpart via an rtc-signaller signalling channel.

NPM

Build Status unstable bitHound Score Gitter chat

Getting Started

If you decide that the rtc-tools module is a better fit for you than either rtc-quickconnect or rtc then the code snippet below will provide you a guide on how to get started using it in conjunction with the rtc-signaller (version 5.0 and above) and rtc-media modules:

var messenger = require('rtc-switchboard-messenger');
var signaller = require('rtc-signaller')(messenger('https://switchboard.rtc.io/'));
var rtc = require('rtc-tools');
var getUserMedia = require('getusermedia');
var attachMedia = require('attachmediastream');

// capture local media first as firefox
// will want a local stream and doesn't support onnegotiationneeded event
getUserMedia({ video: true, audio: true }, function(err, localStream) {
  if (err) {
    return console.error('could not capture media: ', err);
  }

  document.body.appendChild(attachMedia(localStream));

  // look for friends
  signaller.on('peer:announce', function(data) {
    var pc = rtc.createConnection();
    var monitor = rtc.couple(pc, data.id, signaller);

    // add the stream to the connection
    pc.addStream(localStream);

    // once the connection is active, log a console message
    monitor.once('connected', function() {
      console.log('connection active to: ' + data.id);

      pc.getRemoteStreams().forEach(function(stream) {
        document.body.appendChild(attachMedia(stream));
      });
    });


    monitor.createOffer();
  });

  // announce ourself in the rtc-getting-started room
  signaller.announce({ room: 'rtc-getting-started' });
});

This code definitely doesn't cover all the cases that you need to consider (i.e. peers leaving, etc) but it should demonstrate how to:

  1. Capture video and add it to a peer connection
  2. Couple a local peer connection with a remote peer connection
  3. Deal with the remote steam being discovered and how to render that to the local interface.

Reference

createConnection

createConnection(opts?, constraints?) => RTCPeerConnection

Create a new RTCPeerConnection auto generating default opts as required.

var conn;

// this is ok
conn = rtc.createConnection();

// and so is this
conn = rtc.createConnection({
  iceServers: []
});

rtc-tools/cleanup

cleanup(pc)

The cleanup function is used to ensure that a peer connection is properly closed and ready to be cleaned up by the browser.

rtc-tools/couple

couple(pc, targetId, signaller, opts?)

Couple a WebRTC connection with another webrtc connection identified by targetId via the signaller.

The following options can be provided in the opts argument:

  • sdpfilter (default: null)

    A simple function for filtering SDP as part of the peer connection handshake (see the Using Filters details below).

Example Usage
var couple = require('rtc/couple');

couple(pc, '54879965-ce43-426e-a8ef-09ac1e39a16d', signaller);
Using Filters

In certain instances you may wish to modify the raw SDP that is provided by the createOffer and createAnswer calls. This can be done by passing a sdpfilter function (or array) in the options. For example:

// run the sdp from through a local tweakSdp function.
couple(pc, '54879965-ce43-426e-a8ef-09ac1e39a16d', signaller, {
  sdpfilter: tweakSdp
});

rtc-tools/detect

Provide the rtc-core/detect functionality.

rtc-tools/generators

The generators package provides some utility methods for generating constraint objects and similar constructs.

var generators = require('rtc/generators');

generators.config(config)

Generate a configuration object suitable for passing into an W3C RTCPeerConnection constructor first argument, based on our custom config.

In the event that you use short term authentication for TURN, and you want to generate new iceServers regularly, you can specify an iceServerGenerator that will be used prior to coupling. This generator should return a fully compliant W3C (RTCIceServer dictionary)[http://www.w3.org/TR/webrtc/#idl-def-RTCIceServer].

If you pass in both a generator and iceServers, the iceServers _will be ignored and the generator used instead.

generators.connectionConstraints(flags, constraints)

This is a helper function that will generate appropriate connection constraints for a new RTCPeerConnection object which is constructed in the following way:

var conn = new RTCPeerConnection(flags, constraints);

In most cases the constraints object can be left empty, but when creating data channels some additional options are required. This function can generate those additional options and intelligently combine any user defined constraints (in constraints) with shorthand flags that might be passed while using the rtc.createConnection helper.

rtc-tools/monitor

monitor(pc, targetId, signaller, parentBus) => mbus

The monitor is a useful tool for determining the state of pc (an RTCPeerConnection) instance in the context of your application. The monitor uses both the iceConnectionState information of the peer connection and also the various signaller events to determine when the connection has been connected and when it has been disconnected.

A monitor created mbus is returned as the result of a couple between a local peer connection and it's remote counterpart.

License(s)

Apache 2.0

Copyright 2015 National ICT Australia Limited (NICTA)

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

 http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.