|
@@ -1,8 +1,6 @@
|
|
/**
|
|
/**
|
|
* Manages all negotiations between Peers.
|
|
* Manages all negotiations between Peers.
|
|
*/
|
|
*/
|
|
-// TODO: LOCKS.
|
|
|
|
-// TODO: FIREFOX new PC after offer made for DC.
|
|
|
|
var Negotiator = {
|
|
var Negotiator = {
|
|
pcs: {
|
|
pcs: {
|
|
data: {},
|
|
data: {},
|
|
@@ -15,9 +13,7 @@ var Negotiator = {
|
|
Negotiator._idPrefix = 'pc_';
|
|
Negotiator._idPrefix = 'pc_';
|
|
|
|
|
|
/** Returns a PeerConnection object set up correctly (for data, media). */
|
|
/** Returns a PeerConnection object set up correctly (for data, media). */
|
|
-// Options preceeded with _ are ones we add artificially.
|
|
|
|
Negotiator.startConnection = function(connection, options) {
|
|
Negotiator.startConnection = function(connection, options) {
|
|
- //Negotiator._addProvider(provider);
|
|
|
|
var pc = Negotiator._getPeerConnection(connection, options);
|
|
var pc = Negotiator._getPeerConnection(connection, options);
|
|
|
|
|
|
if (connection.type === 'media' && options._stream) {
|
|
if (connection.type === 'media' && options._stream) {
|
|
@@ -55,9 +51,8 @@ Negotiator._getPeerConnection = function(connection, options) {
|
|
var peerConnections = Negotiator.pcs[connection.type][connection.peer];
|
|
var peerConnections = Negotiator.pcs[connection.type][connection.peer];
|
|
|
|
|
|
var pc;
|
|
var pc;
|
|
- if (options.multiplex) {
|
|
|
|
- // TODO: this doesn't work right now because we don't have PC ids.
|
|
|
|
- // Find an existing PC to use.
|
|
|
|
|
|
+ // Not multiplexing while FF and Chrome have not-great support for it.
|
|
|
|
+ /*if (options.multiplex) {
|
|
ids = Object.keys(peerConnections);
|
|
ids = Object.keys(peerConnections);
|
|
for (var i = 0, ii = ids.length; i < ii; i += 1) {
|
|
for (var i = 0, ii = ids.length; i < ii; i += 1) {
|
|
pc = peerConnections[ids[i]];
|
|
pc = peerConnections[ids[i]];
|
|
@@ -65,7 +60,8 @@ Negotiator._getPeerConnection = function(connection, options) {
|
|
break; // We can go ahead and use this PC.
|
|
break; // We can go ahead and use this PC.
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- } else if (options.pc) { // Simplest case: PC id already provided for us.
|
|
|
|
|
|
+ } else */
|
|
|
|
+ if (options.pc) { // Simplest case: PC id already provided for us.
|
|
pc = Negotiator.pcs[connection.type][connection.peer][options.pc];
|
|
pc = Negotiator.pcs[connection.type][connection.peer][options.pc];
|
|
}
|
|
}
|
|
|
|
|
|
@@ -93,7 +89,12 @@ Negotiator._startPeerConnection = function(connection) {
|
|
util.log('Creating RTCPeerConnection.');
|
|
util.log('Creating RTCPeerConnection.');
|
|
|
|
|
|
var id = Negotiator._idPrefix + util.randomToken();
|
|
var id = Negotiator._idPrefix + util.randomToken();
|
|
- pc = new RTCPeerConnection(connection.provider.options.config, {optional: [{RtpDataChannels: true}]});
|
|
|
|
|
|
+ pc = new RTCPeerConnection(connection.provider.options.config, {
|
|
|
|
+ optional: [{
|
|
|
|
+ RtpDataChannels: true,
|
|
|
|
+ DtlsSrtpKeyAgreement: true /* Firefox interop */
|
|
|
|
+ }]
|
|
|
|
+ });
|
|
Negotiator.pcs[connection.type][connection.peer][id] = pc;
|
|
Negotiator.pcs[connection.type][connection.peer][id] = pc;
|
|
|
|
|
|
Negotiator._setupListeners(connection, pc, id);
|
|
Negotiator._setupListeners(connection, pc, id);
|
|
@@ -167,7 +168,6 @@ Negotiator._setupListeners = function(connection, pc, pc_id) {
|
|
};
|
|
};
|
|
}
|
|
}
|
|
|
|
|
|
-// TODO(michelle)
|
|
|
|
Negotiator.cleanup = function(connection) {
|
|
Negotiator.cleanup = function(connection) {
|
|
connection.close(); // Will fail safely if connection is already closed.
|
|
connection.close(); // Will fail safely if connection is already closed.
|
|
util.log('Cleanup PeerConnection for ' + connection.peer);
|
|
util.log('Cleanup PeerConnection for ' + connection.peer);
|