UNPKG

rtc-tools

Version:
90 lines (64 loc) 2.53 kB
/* jshint node: true */ 'use strict'; /** # rtc-tools The `rtc-tools` module does most of the heavy lifting within the [rtc.io](http://rtc.io) suite. Primarily it handles the logic of coupling a local `RTCPeerConnection` with it's remote counterpart via an [rtc-signaller](https://github.com/rtc-io/rtc-signaller) signalling channel. ## Getting Started If you decide that the `rtc-tools` module is a better fit for you than either [rtc-quickconnect](https://github.com/rtc-io/rtc-quickconnect) or [rtc](https://github.com/rtc-io/rtc) then the code snippet below will provide you a guide on how to get started using it in conjunction with the [rtc-signaller](https://github.com/rtc-io/rtc-signaller) (version 5.0 and above) and [rtc-media](https://github.com/rtc-io/rtc-media) modules: <<< examples/getting-started.js 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 **/ var gen = require('./generators'); // export detect var detect = exports.detect = require('./detect'); var findPlugin = require('rtc-core/plugin'); // export cog logger for convenience exports.logger = require('cog/logger'); // export peer connection var RTCPeerConnection = exports.RTCPeerConnection = detect('RTCPeerConnection'); // add the couple utility exports.couple = require('./couple'); /** ### createConnection ``` createConnection(opts?, constraints?) => RTCPeerConnection ``` Create a new `RTCPeerConnection` auto generating default opts as required. ```js var conn; // this is ok conn = rtc.createConnection(); // and so is this conn = rtc.createConnection({ iceServers: [] }); ``` **/ exports.createConnection = function(opts, constraints) { var plugin = findPlugin((opts || {}).plugins); var PeerConnection = (opts || {}).RTCPeerConnection || RTCPeerConnection; // generate the config based on options provided var config = gen.config(opts); // generate appropriate connection constraints constraints = gen.connectionConstraints(opts, constraints); if (plugin && typeof plugin.createConnection == 'function') { return plugin.createConnection(config, constraints); } return new PeerConnection(config, constraints); };