Permalink
Browse files

feat(RTC): store peer connections and assign IDs

  • Loading branch information...
paweldomas committed Jan 12, 2017
1 parent 122cce2 commit 0902fc5447266cc2a9c264d57c69a6838b761a7d
Showing with 48 additions and 3 deletions.
  1. +38 −2 modules/RTC/RTC.js
  2. +10 −1 modules/RTC/TraceablePeerConnection.js
View
@@ -41,6 +41,17 @@ export default class RTC extends Listenable {
constructor(conference, options = {}) {
super();
this.conference = conference;
/**
* A map of active <tt>TraceablePeerConnection</tt>.
* @type {Object.<number, TraceablePeerConnection>}
*/
this.peerConnections = { };
/**
* The counter used to generated id numbers assigned to peer connections
* @type {number}
*/
this.peerConnIdCounter = 1;
this.localTracks = [];
//FIXME: We should support multiple streams per jid.
this.remoteTracks = {};
@@ -211,8 +222,33 @@ export default class RTC extends Listenable {
* @return {TraceablePeerConnection}
*/
createPeerConnection (signalling, iceConfig, options) {
return new TraceablePeerConnection(
this, signalling, iceConfig, RTC.getPCConstraints(), options);
const newConnection
= new TraceablePeerConnection(
this,
this.peerConnIdCounter,
signalling, iceConfig, RTC.getPCConstraints(), options);
this.peerConnections[newConnection.id] = newConnection;
this.peerConnIdCounter += 1;
return newConnection;
}
/**
* Removed given peer connection from this RTC module instance.
* @param {TraceablePeerConnection} traceablePeerConnection
* @return {boolean} <tt>true</tt> if the given peer connection was removed
* successfully or <tt>false</tt> if there was no peer connection mapped in
* this RTC instance.
*/
_removePeerConnection (traceablePeerConnection) {
const id = traceablePeerConnection.id;
if (this.peerConnections[id]) {
// NOTE Remote tracks are not removed here.
delete this.peerConnections[id];
return true;
} else {
return false;
}
}
addLocalTrack (track) {
@@ -18,6 +18,7 @@ var SIMULCAST_LAYERS = 3;
* Creates new instance of 'TraceablePeerConnection'.
*
* @param {RTC} rtc the instance of <tt>RTC</tt> service
* @param {number} id the peer connection id assigned by the parent RTC module.
* @param {SignallingLayer} signallingLayer the signalling layer instance
* @param {object} ice_config WebRTC 'PeerConnection' ICE config
* @param {object} constraints WebRTC 'PeerConnection' constraints
@@ -35,7 +36,7 @@ var SIMULCAST_LAYERS = 3;
*
* @constructor
*/
function TraceablePeerConnection(rtc, signallingLayer, ice_config,
function TraceablePeerConnection(rtc, id, signallingLayer, ice_config,
constraints, options) {
var self = this;
/**
@@ -44,6 +45,11 @@ function TraceablePeerConnection(rtc, signallingLayer, ice_config,
* @type {RTC}
*/
this.rtc = rtc;
/**
* The peer connection identifier assigned by the RTC module.
* @type {number}
*/
this.id = id;
/**
* The signalling layer which operates this peer connection.
* @type {SignallingLayer}
@@ -682,6 +688,9 @@ TraceablePeerConnection.prototype.generateRecvonlySsrc = function() {
TraceablePeerConnection.prototype.close = function () {
this.trace('stop');
if (!this.rtc._removePeerConnection(this)) {
logger.error("RTC._removePeerConnection returned false");
}
if (this.statsinterval !== null) {
window.clearInterval(this.statsinterval);
this.statsinterval = null;

0 comments on commit 0902fc5

Please sign in to comment.