rtc-tools module does most of the heavy lifting within the
rtc.io suite. Primarily it handles the logic of coupling
RTCPeerConnection with it's remote counterpart via an
If you decide that the
rtc-tools module is a better fit for you than either
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 = ;var signaller = ;var rtc = ;var getUserMedia = ;var attachMedia = ;// capture local media first as firefox// will want a local stream and doesn't support onnegotiationneeded event;
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:
createConnection(opts?, constraints?) => RTCPeerConnection
Create a new
RTCPeerConnection auto generating default opts as required.
var conn;// this is okconn = rtc;// and so is thisconn = rtc;
cleanup function is used to ensure that a peer connection is properly
closed and ready to be cleaned up by the browser.
Couple a WebRTC connection with another webrtc connection identified by
targetId via the signaller.
The following options can be provided in the
sdpfilter (default: null)
A simple function for filtering SDP as part of the peer connection handshake (see the Using Filters details below).
var couple = ;;
In certain instances you may wish to modify the raw SDP that is provided
createAnswer calls. This can be done by passing
sdpfilter function (or array) in the options. For example:
// run the sdp from through a local tweakSdp function.;
Provide the rtc-core/detect functionality.
The generators package provides some utility methods for generating constraint objects and similar constructs.
var generators = ;
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.
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 = 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
monitor(pc, targetId, signaller, parentBus) => mbus
The monitor is a useful tool for determining the state of
RTCPeerConnection) instance in the context of your application. The
monitor uses both the
iceConnectionState information of the peer
connection and also the various
to determine when the connection has been
connected and when it has
A monitor created
mbus is returned as the result of a
couple between a local peer
connection and it's remote counterpart.
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
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.