2012-10-06 22:34:30 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
2013-01-23 11:21:25 -08:00
|
|
|
const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
|
2012-10-06 22:34:30 -07:00
|
|
|
|
|
|
|
Cu.import("resource://gre/modules/Services.jsm");
|
|
|
|
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
|
|
|
|
|
|
|
const PC_CONTRACT = "@mozilla.org/dom/peerconnection;1";
|
2013-10-14 09:53:56 -07:00
|
|
|
const PC_OBS_CONTRACT = "@mozilla.org/dom/peerconnectionobserver;1";
|
2012-10-06 22:34:30 -07:00
|
|
|
const PC_ICE_CONTRACT = "@mozilla.org/dom/rtcicecandidate;1";
|
|
|
|
const PC_SESSION_CONTRACT = "@mozilla.org/dom/rtcsessiondescription;1";
|
2012-11-09 21:04:27 -08:00
|
|
|
const PC_MANAGER_CONTRACT = "@mozilla.org/dom/peerconnectionmanager;1";
|
2013-10-17 15:00:05 -07:00
|
|
|
const PC_STATS_CONTRACT = "@mozilla.org/dom/rtcstatsreport;1";
|
2012-10-06 22:34:30 -07:00
|
|
|
|
2013-10-29 10:29:43 -07:00
|
|
|
const PC_CID = Components.ID("{00e0e20d-1494-4776-8e0e-0f0acbea3c79}");
|
2013-10-14 09:53:56 -07:00
|
|
|
const PC_OBS_CID = Components.ID("{1d44a18e-4545-4ff3-863d-6dbd6234a583}");
|
2013-05-07 17:55:21 -07:00
|
|
|
const PC_ICE_CID = Components.ID("{02b9970c-433d-4cc2-923d-f7028ac66073}");
|
|
|
|
const PC_SESSION_CID = Components.ID("{1775081b-b62d-4954-8ffe-a067bbf508a7}");
|
2012-11-09 21:04:27 -08:00
|
|
|
const PC_MANAGER_CID = Components.ID("{7293e901-2be3-4c02-b4bd-cbef6fc24f78}");
|
2013-10-17 15:00:05 -07:00
|
|
|
const PC_STATS_CID = Components.ID("{7fe6e18b-0da3-4056-bf3b-440ef3809e06}");
|
2012-10-06 22:34:30 -07:00
|
|
|
|
|
|
|
// Global list of PeerConnection objects, so they can be cleaned up when
|
|
|
|
// a page is torn down. (Maps inner window ID to an array of PC objects).
|
|
|
|
function GlobalPCList() {
|
2012-11-18 20:53:14 -08:00
|
|
|
this._list = [];
|
2012-12-11 04:58:12 -08:00
|
|
|
this._networkdown = false; // XXX Need to query current state somehow
|
2012-10-06 22:34:30 -07:00
|
|
|
Services.obs.addObserver(this, "inner-window-destroyed", true);
|
2012-11-18 20:53:14 -08:00
|
|
|
Services.obs.addObserver(this, "profile-change-net-teardown", true);
|
|
|
|
Services.obs.addObserver(this, "network:offline-about-to-go-offline", true);
|
2012-12-11 04:58:12 -08:00
|
|
|
Services.obs.addObserver(this, "network:offline-status-changed", true);
|
2012-10-06 22:34:30 -07:00
|
|
|
}
|
|
|
|
GlobalPCList.prototype = {
|
|
|
|
QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver,
|
2012-11-09 21:04:27 -08:00
|
|
|
Ci.nsISupportsWeakReference,
|
|
|
|
Ci.IPeerConnectionManager]),
|
|
|
|
classID: PC_MANAGER_CID,
|
|
|
|
_xpcom_factory: {
|
|
|
|
createInstance: function(outer, iid) {
|
|
|
|
if (outer) {
|
2013-01-23 11:21:25 -08:00
|
|
|
throw Cr.NS_ERROR_NO_AGGREGATION;
|
2012-11-09 21:04:27 -08:00
|
|
|
}
|
|
|
|
return _globalPCList.QueryInterface(iid);
|
|
|
|
}
|
|
|
|
},
|
2012-10-06 22:34:30 -07:00
|
|
|
|
|
|
|
addPC: function(pc) {
|
|
|
|
let winID = pc._winID;
|
|
|
|
if (this._list[winID]) {
|
2013-05-07 17:55:21 -07:00
|
|
|
this._list[winID].push(Cu.getWeakReference(pc));
|
2012-10-06 22:34:30 -07:00
|
|
|
} else {
|
2013-05-07 17:55:21 -07:00
|
|
|
this._list[winID] = [Cu.getWeakReference(pc)];
|
2012-10-06 22:34:30 -07:00
|
|
|
}
|
2013-01-17 15:11:14 -08:00
|
|
|
this.removeNullRefs(winID);
|
|
|
|
},
|
|
|
|
|
|
|
|
removeNullRefs: function(winID) {
|
|
|
|
if (this._list === undefined || this._list[winID] === undefined) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this._list[winID] = this._list[winID].filter(
|
|
|
|
function (e,i,a) { return e.get() !== null; });
|
2012-10-06 22:34:30 -07:00
|
|
|
},
|
|
|
|
|
2012-11-09 21:04:27 -08:00
|
|
|
hasActivePeerConnection: function(winID) {
|
2013-01-17 15:11:14 -08:00
|
|
|
this.removeNullRefs(winID);
|
2012-11-09 21:04:27 -08:00
|
|
|
return this._list[winID] ? true : false;
|
|
|
|
},
|
|
|
|
|
2012-10-06 22:34:30 -07:00
|
|
|
observe: function(subject, topic, data) {
|
2012-11-18 20:53:14 -08:00
|
|
|
if (topic == "inner-window-destroyed") {
|
|
|
|
let winID = subject.QueryInterface(Ci.nsISupportsPRUint64).data;
|
|
|
|
if (this._list[winID]) {
|
2013-01-17 15:11:14 -08:00
|
|
|
this._list[winID].forEach(function(pcref) {
|
|
|
|
let pc = pcref.get();
|
|
|
|
if (pc !== null) {
|
2013-05-12 19:16:40 -07:00
|
|
|
pc._pc.close();
|
2013-01-17 15:11:14 -08:00
|
|
|
delete pc._observer;
|
|
|
|
pc._pc = null;
|
|
|
|
}
|
2012-11-18 20:53:14 -08:00
|
|
|
});
|
|
|
|
delete this._list[winID];
|
|
|
|
}
|
|
|
|
} else if (topic == "profile-change-net-teardown" ||
|
|
|
|
topic == "network:offline-about-to-go-offline") {
|
2013-05-12 19:16:40 -07:00
|
|
|
// Delete all peerconnections on shutdown - mostly synchronously (we
|
|
|
|
// need them to be done deleting transports and streams before we
|
|
|
|
// return)! All socket operations must be queued to STS thread
|
|
|
|
// before we return to here.
|
2013-01-08 10:40:15 -08:00
|
|
|
// Also kill them if "Work Offline" is selected - more can be created
|
2012-11-18 20:53:14 -08:00
|
|
|
// while offline, but attempts to connect them should fail.
|
|
|
|
let array;
|
|
|
|
while ((array = this._list.pop()) != undefined) {
|
2013-01-17 15:11:14 -08:00
|
|
|
array.forEach(function(pcref) {
|
|
|
|
let pc = pcref.get();
|
|
|
|
if (pc !== null) {
|
2013-05-12 19:16:40 -07:00
|
|
|
pc._pc.close();
|
2013-01-17 15:11:14 -08:00
|
|
|
delete pc._observer;
|
|
|
|
pc._pc = null;
|
|
|
|
}
|
2012-11-18 20:53:14 -08:00
|
|
|
});
|
|
|
|
};
|
2012-12-11 04:58:12 -08:00
|
|
|
this._networkdown = true;
|
|
|
|
}
|
|
|
|
else if (topic == "network:offline-status-changed") {
|
|
|
|
if (data == "offline") {
|
|
|
|
// this._list shold be empty here
|
|
|
|
this._networkdown = true;
|
|
|
|
} else if (data == "online") {
|
|
|
|
this._networkdown = false;
|
|
|
|
}
|
2012-10-06 22:34:30 -07:00
|
|
|
}
|
2012-11-18 20:53:14 -08:00
|
|
|
},
|
2012-10-06 22:34:30 -07:00
|
|
|
};
|
|
|
|
let _globalPCList = new GlobalPCList();
|
|
|
|
|
2013-05-07 17:55:21 -07:00
|
|
|
function RTCIceCandidate() {
|
|
|
|
this.candidate = this.sdpMid = this.sdpMLineIndex = null;
|
2012-10-06 22:34:30 -07:00
|
|
|
}
|
2013-05-07 17:55:21 -07:00
|
|
|
RTCIceCandidate.prototype = {
|
|
|
|
classDescription: "mozRTCIceCandidate",
|
2012-10-06 22:34:30 -07:00
|
|
|
classID: PC_ICE_CID,
|
2013-05-07 17:55:21 -07:00
|
|
|
contractID: PC_ICE_CONTRACT,
|
|
|
|
QueryInterface: XPCOMUtils.generateQI([Ci.nsISupports,
|
|
|
|
Ci.nsIDOMGlobalPropertyInitializer]),
|
2012-10-06 22:34:30 -07:00
|
|
|
|
2013-05-07 17:55:21 -07:00
|
|
|
init: function(win) { this._win = win; },
|
|
|
|
|
|
|
|
__init: function(dict) {
|
|
|
|
this.candidate = dict.candidate;
|
|
|
|
this.sdpMid = dict.sdpMid;
|
2013-08-22 09:26:54 -07:00
|
|
|
this.sdpMLineIndex = ("sdpMLineIndex" in dict)? dict.sdpMLineIndex : null;
|
2012-10-06 22:34:30 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-05-07 17:55:21 -07:00
|
|
|
function RTCSessionDescription() {
|
|
|
|
this.type = this.sdp = null;
|
2012-10-06 22:34:30 -07:00
|
|
|
}
|
2013-05-07 17:55:21 -07:00
|
|
|
RTCSessionDescription.prototype = {
|
|
|
|
classDescription: "mozRTCSessionDescription",
|
2012-10-06 22:34:30 -07:00
|
|
|
classID: PC_SESSION_CID,
|
2013-05-07 17:55:21 -07:00
|
|
|
contractID: PC_SESSION_CONTRACT,
|
|
|
|
QueryInterface: XPCOMUtils.generateQI([Ci.nsISupports,
|
|
|
|
Ci.nsIDOMGlobalPropertyInitializer]),
|
2012-10-06 22:34:30 -07:00
|
|
|
|
2013-05-07 17:55:21 -07:00
|
|
|
init: function(win) { this._win = win; },
|
2012-10-06 22:34:30 -07:00
|
|
|
|
2013-05-07 17:55:21 -07:00
|
|
|
__init: function(dict) {
|
|
|
|
this.type = dict.type;
|
|
|
|
this.sdp = dict.sdp;
|
2012-10-06 22:34:30 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-10-17 15:00:05 -07:00
|
|
|
function RTCStatsReport(win, report) {
|
|
|
|
this._win = win;
|
|
|
|
this.report = report;
|
|
|
|
}
|
|
|
|
RTCStatsReport.prototype = {
|
|
|
|
classDescription: "RTCStatsReport",
|
|
|
|
classID: PC_STATS_CID,
|
|
|
|
contractID: PC_STATS_CONTRACT,
|
|
|
|
QueryInterface: XPCOMUtils.generateQI([Ci.nsISupports,
|
|
|
|
Ci.nsIDOMGlobalPropertyInitializer]),
|
|
|
|
|
|
|
|
forEach: function(cb, thisArg) {
|
|
|
|
for (var key in this.report) {
|
|
|
|
if (this.report.hasOwnProperty(key)) {
|
|
|
|
cb.call(thisArg || this, this.get(key), key, this.report);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
get: function(key) {
|
|
|
|
function publify(win, obj) {
|
|
|
|
let props = {};
|
|
|
|
for (let k in obj) {
|
|
|
|
props[k] = {enumerable:true, configurable:true, writable:true, value:obj[k]};
|
|
|
|
}
|
|
|
|
let pubobj = Cu.createObjectIn(win);
|
|
|
|
Object.defineProperties(pubobj, props);
|
|
|
|
Cu.makeObjectPropsNormal(pubobj);
|
|
|
|
return pubobj;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return a content object rather than a wrapped chrome one.
|
|
|
|
return publify(this._win, this.report[key]);
|
|
|
|
},
|
|
|
|
|
|
|
|
has: function(key) {
|
|
|
|
return this.report[key] !== undefined;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-05-07 17:55:21 -07:00
|
|
|
function RTCPeerConnection() {
|
2012-10-06 22:34:30 -07:00
|
|
|
this._queue = [];
|
|
|
|
|
|
|
|
this._pc = null;
|
|
|
|
this._observer = null;
|
2012-10-20 09:43:57 -07:00
|
|
|
this._closed = false;
|
2012-10-06 22:34:30 -07:00
|
|
|
|
|
|
|
this._onCreateOfferSuccess = null;
|
|
|
|
this._onCreateOfferFailure = null;
|
|
|
|
this._onCreateAnswerSuccess = null;
|
|
|
|
this._onCreateAnswerFailure = null;
|
2013-10-17 15:00:05 -07:00
|
|
|
this._onGetStatsSuccess = null;
|
|
|
|
this._onGetStatsFailure = null;
|
2012-10-06 22:34:30 -07:00
|
|
|
|
2013-01-14 14:25:54 -08:00
|
|
|
this._pendingType = null;
|
|
|
|
this._localType = null;
|
|
|
|
this._remoteType = null;
|
2013-09-16 17:42:39 -07:00
|
|
|
this._trickleIce = false;
|
2013-01-14 14:25:54 -08:00
|
|
|
|
2012-10-06 22:34:30 -07:00
|
|
|
/**
|
|
|
|
* Everytime we get a request from content, we put it in the queue. If
|
|
|
|
* there are no pending operations though, we will execute it immediately.
|
|
|
|
* In PeerConnectionObserver, whenever we are notified that an operation
|
|
|
|
* has finished, we will check the queue for the next operation and execute
|
|
|
|
* if neccesary. The _pending flag indicates whether an operation is currently
|
|
|
|
* in progress.
|
|
|
|
*/
|
|
|
|
this._pending = false;
|
|
|
|
|
2013-05-16 16:40:23 -07:00
|
|
|
// States
|
|
|
|
this._iceGatheringState = this._iceConnectionState = "new";
|
2012-10-06 22:34:30 -07:00
|
|
|
}
|
2013-05-07 17:55:21 -07:00
|
|
|
RTCPeerConnection.prototype = {
|
|
|
|
classDescription: "mozRTCPeerConnection",
|
2012-10-06 22:34:30 -07:00
|
|
|
classID: PC_CID,
|
2013-05-07 17:55:21 -07:00
|
|
|
contractID: PC_CONTRACT,
|
|
|
|
QueryInterface: XPCOMUtils.generateQI([Ci.nsISupports,
|
2013-10-14 09:53:56 -07:00
|
|
|
Ci.nsIDOMGlobalPropertyInitializer]),
|
2013-05-07 17:55:21 -07:00
|
|
|
init: function(win) { this._win = win; },
|
2012-10-06 22:34:30 -07:00
|
|
|
|
2013-05-07 17:55:21 -07:00
|
|
|
__init: function(rtcConfig) {
|
2013-09-16 17:42:39 -07:00
|
|
|
this._trickleIce = Services.prefs.getBoolPref("media.peerconnection.trickle_ice");
|
2013-05-07 17:55:21 -07:00
|
|
|
if (!rtcConfig.iceServers ||
|
2013-02-18 05:49:14 -08:00
|
|
|
!Services.prefs.getBoolPref("media.peerconnection.use_document_iceservers")) {
|
|
|
|
rtcConfig = {iceServers:
|
|
|
|
JSON.parse(Services.prefs.getCharPref("media.peerconnection.default_iceservers"))};
|
2012-10-06 22:34:30 -07:00
|
|
|
}
|
2013-01-23 11:21:25 -08:00
|
|
|
this._mustValidateRTCConfiguration(rtcConfig,
|
|
|
|
"RTCPeerConnection constructor passed invalid RTCConfiguration");
|
2012-12-11 04:58:12 -08:00
|
|
|
if (_globalPCList._networkdown) {
|
2013-09-06 12:29:29 -07:00
|
|
|
throw new this._win.DOMError("",
|
|
|
|
"Can't create RTCPeerConnections when the network is down");
|
2012-12-11 04:58:12 -08:00
|
|
|
}
|
2012-10-06 22:34:30 -07:00
|
|
|
|
2013-05-16 16:40:23 -07:00
|
|
|
this.makeGetterSetterEH("onaddstream");
|
|
|
|
this.makeGetterSetterEH("onicecandidate");
|
|
|
|
this.makeGetterSetterEH("onnegotiationneeded");
|
|
|
|
this.makeGetterSetterEH("onsignalingstatechange");
|
|
|
|
this.makeGetterSetterEH("onremovestream");
|
|
|
|
this.makeGetterSetterEH("ondatachannel");
|
|
|
|
this.makeGetterSetterEH("onconnection");
|
|
|
|
this.makeGetterSetterEH("onclosedconnection");
|
|
|
|
this.makeGetterSetterEH("oniceconnectionstatechange");
|
|
|
|
|
2013-10-14 09:53:56 -07:00
|
|
|
this._pc = new this._win.PeerConnectionImpl();
|
2013-11-01 17:49:48 -07:00
|
|
|
|
|
|
|
this.__DOM_IMPL__._innerObject = this;
|
|
|
|
this._observer = new this._win.PeerConnectionObserver(this.__DOM_IMPL__);
|
2013-05-22 10:05:20 -07:00
|
|
|
this._winID = this._win.QueryInterface(Ci.nsIInterfaceRequestor)
|
|
|
|
.getInterface(Ci.nsIDOMWindowUtils).currentInnerWindowID;
|
|
|
|
|
|
|
|
// Add a reference to the PeerConnection to global list (before init).
|
|
|
|
_globalPCList.addPC(this);
|
2012-10-06 22:34:30 -07:00
|
|
|
|
|
|
|
this._queueOrRun({
|
2013-10-14 09:53:56 -07:00
|
|
|
func: this._initialize,
|
|
|
|
args: [rtcConfig],
|
2013-09-16 17:42:39 -07:00
|
|
|
// If not trickling, suppress start.
|
|
|
|
wait: !this._trickleIce
|
2012-10-06 22:34:30 -07:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2013-10-14 09:53:56 -07:00
|
|
|
_initialize: function(rtcConfig) {
|
|
|
|
this._getPC().initialize(this._observer, this._win, rtcConfig,
|
|
|
|
Services.tm.currentThread);
|
|
|
|
},
|
|
|
|
|
2013-04-16 22:16:02 -07:00
|
|
|
_getPC: function() {
|
|
|
|
if (!this._pc) {
|
2013-09-06 12:29:29 -07:00
|
|
|
throw new this._win.DOMError("",
|
|
|
|
"RTCPeerConnection is gone (did you enter Offline mode?)");
|
2013-04-16 22:16:02 -07:00
|
|
|
}
|
|
|
|
return this._pc;
|
|
|
|
},
|
|
|
|
|
2012-10-06 22:34:30 -07:00
|
|
|
/**
|
|
|
|
* Add a function to the queue or run it immediately if the queue is empty.
|
|
|
|
* Argument is an object with the func, args and wait properties; wait should
|
|
|
|
* be set to true if the function has a success/error callback that will
|
|
|
|
* call _executeNext, false if it doesn't have a callback.
|
|
|
|
*/
|
|
|
|
_queueOrRun: function(obj) {
|
2013-01-17 12:25:17 -08:00
|
|
|
this._checkClosed();
|
2012-10-06 22:34:30 -07:00
|
|
|
if (!this._pending) {
|
2013-01-14 14:25:54 -08:00
|
|
|
if (obj.type !== undefined) {
|
|
|
|
this._pendingType = obj.type;
|
|
|
|
}
|
2012-10-06 22:34:30 -07:00
|
|
|
obj.func.apply(this, obj.args);
|
|
|
|
if (obj.wait) {
|
|
|
|
this._pending = true;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
this._queue.push(obj);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
// Pick the next item from the queue and run it.
|
|
|
|
_executeNext: function() {
|
|
|
|
if (this._queue.length) {
|
|
|
|
let obj = this._queue.shift();
|
2013-01-14 14:25:54 -08:00
|
|
|
if (obj.type !== undefined) {
|
|
|
|
this._pendingType = obj.type;
|
|
|
|
}
|
2012-10-06 22:34:30 -07:00
|
|
|
obj.func.apply(this, obj.args);
|
|
|
|
if (!obj.wait) {
|
|
|
|
this._executeNext();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
this._pending = false;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2013-01-23 11:21:25 -08:00
|
|
|
/**
|
|
|
|
* An RTCConfiguration looks like this:
|
|
|
|
*
|
2013-10-23 01:59:37 -07:00
|
|
|
* { "iceServers": [ { url:"stun:stun.example.org" },
|
2013-05-07 17:55:21 -07:00
|
|
|
* { url:"turn:turn.example.org",
|
|
|
|
* username:"jib", credential:"mypass"} ] }
|
2013-01-23 11:21:25 -08:00
|
|
|
*
|
2013-05-07 17:55:21 -07:00
|
|
|
* WebIDL normalizes structure for us, so we test well-formed stun/turn urls,
|
|
|
|
* but not validity of servers themselves, before passing along to C++.
|
2013-01-23 11:21:25 -08:00
|
|
|
* ErrorMsg is passed in to detail which array-entry failed, if any.
|
|
|
|
*/
|
|
|
|
_mustValidateRTCConfiguration: function(rtcConfig, errorMsg) {
|
2013-09-03 05:01:53 -07:00
|
|
|
var errorCtor = this._win.DOMError;
|
2013-01-23 11:21:25 -08:00
|
|
|
function nicerNewURI(uriStr, errorMsg) {
|
|
|
|
let ios = Cc['@mozilla.org/network/io-service;1'].getService(Ci.nsIIOService);
|
|
|
|
try {
|
|
|
|
return ios.newURI(uriStr, null, null);
|
|
|
|
} catch (e if (e.result == Cr.NS_ERROR_MALFORMED_URI)) {
|
2013-09-03 05:01:53 -07:00
|
|
|
throw new errorCtor("", errorMsg + " - malformed URI: " + uriStr);
|
2013-01-23 11:21:25 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
function mustValidateServer(server) {
|
2013-10-14 09:53:56 -07:00
|
|
|
if (!server.url) {
|
|
|
|
throw new errorCtor("", errorMsg + " - missing url");
|
|
|
|
}
|
2013-01-23 11:21:25 -08:00
|
|
|
let url = nicerNewURI(server.url, errorMsg);
|
2013-08-10 01:19:35 -07:00
|
|
|
if (url.scheme in { turn:1, turns:1 }) {
|
|
|
|
if (!server.username) {
|
2013-09-03 05:01:53 -07:00
|
|
|
throw new errorCtor("", errorMsg + " - missing username: " + server.url);
|
2013-08-10 01:19:35 -07:00
|
|
|
}
|
|
|
|
if (!server.credential) {
|
2013-09-03 05:01:53 -07:00
|
|
|
throw new errorCtor("", errorMsg + " - missing credential: " +
|
|
|
|
server.url);
|
2013-08-10 01:19:35 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (!(url.scheme in { stun:1, stuns:1 })) {
|
2013-09-03 05:01:53 -07:00
|
|
|
throw new errorCtor("", errorMsg + " - improper scheme: " + url.scheme);
|
2013-01-23 11:21:25 -08:00
|
|
|
}
|
|
|
|
}
|
2013-05-07 17:55:21 -07:00
|
|
|
if (rtcConfig.iceServers) {
|
|
|
|
let len = rtcConfig.iceServers.length;
|
|
|
|
for (let i=0; i < len; i++) {
|
|
|
|
mustValidateServer (rtcConfig.iceServers[i], errorMsg);
|
|
|
|
}
|
2013-01-23 11:21:25 -08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-10-25 12:24:30 -07:00
|
|
|
/**
|
2013-10-09 19:27:54 -07:00
|
|
|
* MediaConstraints look like this:
|
2012-10-25 12:24:30 -07:00
|
|
|
*
|
|
|
|
* {
|
2013-02-13 23:08:56 -08:00
|
|
|
* mandatory: {"OfferToReceiveAudio": true, "OfferToReceiveVideo": true },
|
|
|
|
* optional: [{"VoiceActivityDetection": true}, {"FooBar": 10}]
|
2012-10-25 12:24:30 -07:00
|
|
|
* }
|
|
|
|
*
|
2013-10-09 19:27:54 -07:00
|
|
|
* WebIDL normalizes the top structure for us, but the mandatory constraints
|
|
|
|
* member comes in as a raw object so we can detect unknown constraints.
|
|
|
|
* We compare its members against ones we support, and fail if not found.
|
2012-10-25 12:24:30 -07:00
|
|
|
*/
|
2013-02-13 23:08:56 -08:00
|
|
|
_mustValidateConstraints: function(constraints, errorMsg) {
|
|
|
|
if (constraints.mandatory) {
|
2013-10-09 19:27:54 -07:00
|
|
|
let supported;
|
|
|
|
try {
|
|
|
|
// Passing the raw constraints.mandatory here validates its structure
|
|
|
|
supported = this._observer.getSupportedConstraints(constraints.mandatory);
|
|
|
|
} catch (e) {
|
|
|
|
throw new this._win.DOMError("", errorMsg + " - " + e.message);
|
2013-02-13 23:08:56 -08:00
|
|
|
}
|
2013-10-09 19:27:54 -07:00
|
|
|
|
|
|
|
for (let constraint of Object.keys(constraints.mandatory)) {
|
|
|
|
if (!(constraint in supported)) {
|
|
|
|
throw new this._win.DOMError("",
|
|
|
|
errorMsg + " - unknown mandatory constraint: " + constraint);
|
2013-02-13 23:08:56 -08:00
|
|
|
}
|
|
|
|
}
|
2012-10-25 12:24:30 -07:00
|
|
|
}
|
2013-02-13 23:08:56 -08:00
|
|
|
if (constraints.optional) {
|
|
|
|
let len = constraints.optional.length;
|
2013-10-09 19:27:54 -07:00
|
|
|
for (let i = 0; i < len; i++) {
|
2013-02-13 23:08:56 -08:00
|
|
|
let constraints_per_entry = 0;
|
2013-10-09 19:27:54 -07:00
|
|
|
for (let constraint in Object.keys(constraints.optional[i])) {
|
|
|
|
if (constraints_per_entry) {
|
|
|
|
throw new this._win.DOMError("", errorMsg +
|
|
|
|
" - optional constraint must be single key/value pair");
|
2013-02-13 23:08:56 -08:00
|
|
|
}
|
2013-10-09 19:27:54 -07:00
|
|
|
constraints_per_entry += 1;
|
2013-02-13 23:08:56 -08:00
|
|
|
}
|
|
|
|
}
|
2012-10-25 12:24:30 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2013-01-17 12:25:17 -08:00
|
|
|
// Ideally, this should be of the form _checkState(state),
|
|
|
|
// where the state is taken from an enumeration containing
|
|
|
|
// the valid peer connection states defined in the WebRTC
|
|
|
|
// spec. See Bug 831756.
|
|
|
|
_checkClosed: function() {
|
|
|
|
if (this._closed) {
|
2013-09-06 12:29:29 -07:00
|
|
|
throw new this._win.DOMError("", "Peer connection is closed");
|
2013-01-17 12:25:17 -08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2013-05-07 17:55:21 -07:00
|
|
|
dispatchEvent: function(event) {
|
|
|
|
this.__DOM_IMPL__.dispatchEvent(event);
|
|
|
|
},
|
|
|
|
|
2013-05-11 17:48:29 -07:00
|
|
|
// Log error message to web console and window.onerror, if present.
|
|
|
|
reportError: function(msg, file, line) {
|
|
|
|
this.reportMsg(msg, file, line, Ci.nsIScriptError.exceptionFlag);
|
|
|
|
},
|
|
|
|
|
|
|
|
reportWarning: function(msg, file, line) {
|
|
|
|
this.reportMsg(msg, file, line, Ci.nsIScriptError.warningFlag);
|
|
|
|
},
|
|
|
|
|
|
|
|
reportMsg: function(msg, file, line, flag) {
|
|
|
|
let scriptErrorClass = Cc["@mozilla.org/scripterror;1"];
|
|
|
|
let scriptError = scriptErrorClass.createInstance(Ci.nsIScriptError);
|
|
|
|
scriptError.initWithWindowID(msg, file, null, line, 0, flag,
|
|
|
|
"content javascript", this._winID);
|
|
|
|
let console = Cc["@mozilla.org/consoleservice;1"].
|
|
|
|
getService(Ci.nsIConsoleService);
|
|
|
|
console.logMessage(scriptError);
|
|
|
|
|
|
|
|
if (flag != Ci.nsIScriptError.warningFlag) {
|
|
|
|
// Safely call onerror directly if present (necessary for testing)
|
|
|
|
try {
|
|
|
|
if (typeof this._win.onerror === "function") {
|
|
|
|
this._win.onerror(msg, file, line);
|
|
|
|
}
|
|
|
|
} catch(e) {
|
|
|
|
// If onerror itself throws, service it.
|
|
|
|
try {
|
|
|
|
let scriptError = scriptErrorClass.createInstance(Ci.nsIScriptError);
|
|
|
|
scriptError.initWithWindowID(e.message, e.fileName, null, e.lineNumber,
|
|
|
|
0, Ci.nsIScriptError.exceptionFlag,
|
|
|
|
"content javascript",
|
|
|
|
this._winID);
|
|
|
|
console.logMessage(scriptError);
|
|
|
|
} catch(e) {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2013-05-16 16:40:23 -07:00
|
|
|
getEH: function(type) {
|
2013-05-07 17:55:21 -07:00
|
|
|
return this.__DOM_IMPL__.getEventHandler(type);
|
|
|
|
},
|
|
|
|
|
2013-05-16 16:40:23 -07:00
|
|
|
setEH: function(type, handler) {
|
2013-05-07 17:55:21 -07:00
|
|
|
this.__DOM_IMPL__.setEventHandler(type, handler);
|
|
|
|
},
|
|
|
|
|
2013-05-16 16:40:23 -07:00
|
|
|
makeGetterSetterEH: function(name) {
|
|
|
|
Object.defineProperty(this, name,
|
|
|
|
{
|
|
|
|
get:function() { return this.getEH(name); },
|
|
|
|
set:function(h) { return this.setEH(name, h); }
|
|
|
|
});
|
|
|
|
},
|
2013-05-07 17:55:21 -07:00
|
|
|
|
2012-10-06 22:34:30 -07:00
|
|
|
createOffer: function(onSuccess, onError, constraints) {
|
2012-10-26 15:31:17 -07:00
|
|
|
if (!constraints) {
|
|
|
|
constraints = {};
|
|
|
|
}
|
2013-02-13 23:08:56 -08:00
|
|
|
this._mustValidateConstraints(constraints, "createOffer passed invalid constraints");
|
2012-10-06 22:34:30 -07:00
|
|
|
this._onCreateOfferSuccess = onSuccess;
|
|
|
|
this._onCreateOfferFailure = onError;
|
|
|
|
|
2013-10-14 09:53:56 -07:00
|
|
|
this._queueOrRun({ func: this._createOffer, args: [constraints], wait: true });
|
|
|
|
},
|
|
|
|
|
|
|
|
_createOffer: function(constraints) {
|
|
|
|
this._getPC().createOffer(constraints);
|
2012-10-06 22:34:30 -07:00
|
|
|
},
|
|
|
|
|
2013-01-24 19:44:30 -08:00
|
|
|
_createAnswer: function(onSuccess, onError, constraints, provisional) {
|
|
|
|
this._onCreateAnswerSuccess = onSuccess;
|
|
|
|
this._onCreateAnswerFailure = onError;
|
|
|
|
|
2012-10-15 11:35:21 -07:00
|
|
|
if (!this.remoteDescription) {
|
2013-01-24 19:44:30 -08:00
|
|
|
|
2013-03-29 13:30:16 -07:00
|
|
|
this._observer.onCreateAnswerError(Ci.IPeerConnection.kInvalidState,
|
2013-01-24 19:44:30 -08:00
|
|
|
"setRemoteDescription not called");
|
|
|
|
return;
|
2012-10-06 22:34:30 -07:00
|
|
|
}
|
|
|
|
|
2012-10-15 11:35:21 -07:00
|
|
|
if (this.remoteDescription.type != "offer") {
|
2013-01-24 19:44:30 -08:00
|
|
|
|
2013-03-29 13:30:16 -07:00
|
|
|
this._observer.onCreateAnswerError(Ci.IPeerConnection.kInvalidState,
|
2013-01-24 19:44:30 -08:00
|
|
|
"No outstanding offer");
|
|
|
|
return;
|
2012-10-25 12:24:30 -07:00
|
|
|
}
|
|
|
|
|
2013-01-24 19:44:30 -08:00
|
|
|
// TODO: Implement provisional answer.
|
|
|
|
|
2013-04-16 22:16:02 -07:00
|
|
|
this._getPC().createAnswer(constraints);
|
2013-01-24 19:44:30 -08:00
|
|
|
},
|
|
|
|
|
|
|
|
createAnswer: function(onSuccess, onError, constraints, provisional) {
|
2012-10-26 15:31:17 -07:00
|
|
|
if (!constraints) {
|
|
|
|
constraints = {};
|
|
|
|
}
|
|
|
|
|
2013-02-13 23:08:56 -08:00
|
|
|
this._mustValidateConstraints(constraints, "createAnswer passed invalid constraints");
|
2012-10-06 22:34:30 -07:00
|
|
|
|
|
|
|
if (!provisional) {
|
|
|
|
provisional = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
this._queueOrRun({
|
2013-01-24 19:44:30 -08:00
|
|
|
func: this._createAnswer,
|
|
|
|
args: [onSuccess, onError, constraints, provisional],
|
2012-10-06 22:34:30 -07:00
|
|
|
wait: true
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
setLocalDescription: function(desc, onSuccess, onError) {
|
2013-01-17 12:25:17 -08:00
|
|
|
// TODO -- if we have two setLocalDescriptions in the
|
|
|
|
// queue,this code overwrites the callbacks for the first
|
|
|
|
// one with the callbacks for the second one. See Bug 831759.
|
2012-10-06 22:34:30 -07:00
|
|
|
this._onSetLocalDescriptionSuccess = onSuccess;
|
|
|
|
this._onSetLocalDescriptionFailure = onError;
|
|
|
|
|
|
|
|
let type;
|
|
|
|
switch (desc.type) {
|
|
|
|
case "offer":
|
|
|
|
type = Ci.IPeerConnection.kActionOffer;
|
|
|
|
break;
|
|
|
|
case "answer":
|
|
|
|
type = Ci.IPeerConnection.kActionAnswer;
|
|
|
|
break;
|
2013-05-16 16:40:23 -07:00
|
|
|
case "pranswer":
|
2013-09-06 12:29:29 -07:00
|
|
|
throw new this._win.DOMError("", "pranswer not yet implemented");
|
2012-10-06 22:34:30 -07:00
|
|
|
default:
|
2013-09-06 12:29:29 -07:00
|
|
|
throw new this._win.DOMError("",
|
|
|
|
"Invalid type " + desc.type + " provided to setLocalDescription");
|
2012-10-06 22:34:30 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
this._queueOrRun({
|
2013-10-14 09:53:56 -07:00
|
|
|
func: this._setLocalDescription,
|
2012-10-06 22:34:30 -07:00
|
|
|
args: [type, desc.sdp],
|
2013-01-14 14:25:54 -08:00
|
|
|
wait: true,
|
|
|
|
type: desc.type
|
2012-10-06 22:34:30 -07:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2013-10-14 09:53:56 -07:00
|
|
|
_setLocalDescription: function(type, sdp) {
|
|
|
|
this._getPC().setLocalDescription(type, sdp);
|
|
|
|
},
|
|
|
|
|
2012-10-06 22:34:30 -07:00
|
|
|
setRemoteDescription: function(desc, onSuccess, onError) {
|
2013-01-17 12:25:17 -08:00
|
|
|
// TODO -- if we have two setRemoteDescriptions in the
|
|
|
|
// queue, this code overwrites the callbacks for the first
|
|
|
|
// one with the callbacks for the second one. See Bug 831759.
|
2012-10-06 22:34:30 -07:00
|
|
|
this._onSetRemoteDescriptionSuccess = onSuccess;
|
|
|
|
this._onSetRemoteDescriptionFailure = onError;
|
|
|
|
|
|
|
|
let type;
|
|
|
|
switch (desc.type) {
|
|
|
|
case "offer":
|
|
|
|
type = Ci.IPeerConnection.kActionOffer;
|
|
|
|
break;
|
|
|
|
case "answer":
|
|
|
|
type = Ci.IPeerConnection.kActionAnswer;
|
|
|
|
break;
|
2013-05-16 16:40:23 -07:00
|
|
|
case "pranswer":
|
2013-09-06 12:29:29 -07:00
|
|
|
throw new this._win.DOMError("", "pranswer not yet implemented");
|
2012-10-06 22:34:30 -07:00
|
|
|
default:
|
2013-09-06 12:29:29 -07:00
|
|
|
throw new this._win.DOMError("",
|
|
|
|
"Invalid type " + desc.type + " provided to setRemoteDescription");
|
2012-10-06 22:34:30 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
this._queueOrRun({
|
2013-10-14 09:53:56 -07:00
|
|
|
func: this._setRemoteDescription,
|
2012-10-06 22:34:30 -07:00
|
|
|
args: [type, desc.sdp],
|
2013-01-14 14:25:54 -08:00
|
|
|
wait: true,
|
|
|
|
type: desc.type
|
2012-10-06 22:34:30 -07:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2013-10-14 09:53:56 -07:00
|
|
|
_setRemoteDescription: function(type, sdp) {
|
|
|
|
this._getPC().setRemoteDescription(type, sdp);
|
|
|
|
},
|
|
|
|
|
2013-05-07 17:55:21 -07:00
|
|
|
updateIce: function(config, constraints) {
|
2013-09-06 12:29:29 -07:00
|
|
|
throw new this._win.DOMError("", "updateIce not yet implemented");
|
2012-10-06 22:34:30 -07:00
|
|
|
},
|
|
|
|
|
2013-01-31 12:43:03 -08:00
|
|
|
addIceCandidate: function(cand, onSuccess, onError) {
|
2013-05-07 17:55:21 -07:00
|
|
|
if (!cand.candidate && !cand.sdpMLineIndex) {
|
2013-09-06 12:29:29 -07:00
|
|
|
throw new this._win.DOMError("",
|
|
|
|
"Invalid candidate passed to addIceCandidate!");
|
2012-10-06 22:34:30 -07:00
|
|
|
}
|
2013-05-07 17:55:21 -07:00
|
|
|
this._onAddIceCandidateSuccess = onSuccess || null;
|
|
|
|
this._onAddIceCandidateError = onError || null;
|
2013-01-31 12:43:03 -08:00
|
|
|
|
2013-10-14 09:53:56 -07:00
|
|
|
this._queueOrRun({ func: this._addIceCandidate, args: [cand], wait: true });
|
|
|
|
},
|
|
|
|
|
|
|
|
_addIceCandidate: function(cand) {
|
|
|
|
this._getPC().addIceCandidate(cand.candidate, cand.sdpMid || "",
|
|
|
|
(cand.sdpMLineIndex === null)? 0 :
|
|
|
|
cand.sdpMLineIndex + 1);
|
2012-10-06 22:34:30 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
addStream: function(stream, constraints) {
|
2013-05-07 17:55:21 -07:00
|
|
|
if (stream.currentTime === undefined) {
|
2013-09-06 12:29:29 -07:00
|
|
|
throw new this._win.DOMError("", "Invalid stream passed to addStream!");
|
2013-05-07 17:55:21 -07:00
|
|
|
}
|
2012-10-06 22:34:30 -07:00
|
|
|
// TODO: Implement constraints.
|
2013-10-14 09:53:56 -07:00
|
|
|
this._queueOrRun({ func: this._addStream, args: [stream], wait: false });
|
|
|
|
},
|
|
|
|
|
|
|
|
_addStream: function(stream) {
|
|
|
|
this._getPC().addStream(stream);
|
2012-10-06 22:34:30 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
removeStream: function(stream) {
|
2013-05-16 16:40:23 -07:00
|
|
|
//Bug 844295: Not implementing this functionality.
|
2013-09-06 12:29:29 -07:00
|
|
|
throw new this._win.DOMError("", "removeStream not yet implemented");
|
2013-05-16 16:40:23 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
getStreamById: function(id) {
|
2013-09-06 12:29:29 -07:00
|
|
|
throw new this._win.DOMError("", "getStreamById not yet implemented");
|
2012-10-06 22:34:30 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
close: function() {
|
2013-10-14 09:53:56 -07:00
|
|
|
this._queueOrRun({ func: this._close, args: [false], wait: false });
|
2012-10-20 09:43:57 -07:00
|
|
|
this._closed = true;
|
2013-05-16 16:40:23 -07:00
|
|
|
this.changeIceConnectionState("closed");
|
2012-10-06 22:34:30 -07:00
|
|
|
},
|
|
|
|
|
2013-10-14 09:53:56 -07:00
|
|
|
_close: function() {
|
|
|
|
this._getPC().close();
|
|
|
|
},
|
|
|
|
|
2013-05-07 17:55:21 -07:00
|
|
|
getLocalStreams: function() {
|
2013-01-17 12:25:17 -08:00
|
|
|
this._checkClosed();
|
2013-10-14 09:53:56 -07:00
|
|
|
return this._getPC().getLocalStreams();
|
2012-09-13 09:04:31 -07:00
|
|
|
},
|
2013-01-14 14:25:54 -08:00
|
|
|
|
2013-05-07 17:55:21 -07:00
|
|
|
getRemoteStreams: function() {
|
2013-01-17 12:25:17 -08:00
|
|
|
this._checkClosed();
|
2013-10-14 09:53:56 -07:00
|
|
|
return this._getPC().getRemoteStreams();
|
2012-09-13 09:04:31 -07:00
|
|
|
},
|
|
|
|
|
2013-01-14 14:25:54 -08:00
|
|
|
get localDescription() {
|
2013-01-17 12:25:17 -08:00
|
|
|
this._checkClosed();
|
2013-04-16 22:16:02 -07:00
|
|
|
let sdp = this._getPC().localDescription;
|
2013-01-14 14:25:54 -08:00
|
|
|
if (sdp.length == 0) {
|
|
|
|
return null;
|
|
|
|
}
|
2013-05-07 17:55:21 -07:00
|
|
|
return new this._win.mozRTCSessionDescription({ type: this._localType,
|
|
|
|
sdp: sdp });
|
2013-01-14 14:25:54 -08:00
|
|
|
},
|
|
|
|
|
|
|
|
get remoteDescription() {
|
2013-01-17 12:25:17 -08:00
|
|
|
this._checkClosed();
|
2013-04-16 22:16:02 -07:00
|
|
|
let sdp = this._getPC().remoteDescription;
|
2013-01-14 14:25:54 -08:00
|
|
|
if (sdp.length == 0) {
|
|
|
|
return null;
|
|
|
|
}
|
2013-05-07 17:55:21 -07:00
|
|
|
return new this._win.mozRTCSessionDescription({ type: this._remoteType,
|
|
|
|
sdp: sdp });
|
2013-01-14 14:25:54 -08:00
|
|
|
},
|
|
|
|
|
2013-05-16 16:40:23 -07:00
|
|
|
get iceGatheringState() { return this._iceGatheringState; },
|
|
|
|
get iceConnectionState() { return this._iceConnectionState; },
|
|
|
|
|
2013-05-16 16:41:46 -07:00
|
|
|
get signalingState() {
|
|
|
|
// checking for our local pc closed indication
|
|
|
|
// before invoking the pc methods.
|
|
|
|
if(this._closed) {
|
|
|
|
return "closed";
|
|
|
|
}
|
2013-10-14 09:53:56 -07:00
|
|
|
return {
|
|
|
|
"SignalingInvalid": "",
|
|
|
|
"SignalingStable": "stable",
|
|
|
|
"SignalingHaveLocalOffer": "have-local-offer",
|
|
|
|
"SignalingHaveRemoteOffer": "have-remote-offer",
|
|
|
|
"SignalingHaveLocalPranswer": "have-local-pranswer",
|
|
|
|
"SignalingHaveRemotePranswer": "have-remote-pranswer",
|
|
|
|
"SignalingClosed": "closed"
|
|
|
|
}[this._getPC().signalingState];
|
2013-05-16 16:41:46 -07:00
|
|
|
},
|
|
|
|
|
2013-05-16 16:40:23 -07:00
|
|
|
changeIceGatheringState: function(state) {
|
|
|
|
this._iceGatheringState = state;
|
|
|
|
},
|
|
|
|
|
|
|
|
changeIceConnectionState: function(state) {
|
|
|
|
this._iceConnectionState = state;
|
|
|
|
this.dispatchEvent(new this._win.Event("iceconnectionstatechange"));
|
|
|
|
},
|
|
|
|
|
2013-10-17 15:00:05 -07:00
|
|
|
getStats: function(selector, onSuccess, onError) {
|
2013-10-29 10:29:43 -07:00
|
|
|
this._queueOrRun({
|
|
|
|
func: this._getStats,
|
|
|
|
args: [selector, onSuccess, onError, false],
|
|
|
|
wait: true
|
|
|
|
});
|
|
|
|
},
|
2013-10-17 15:00:05 -07:00
|
|
|
|
2013-10-29 10:29:43 -07:00
|
|
|
getStatsInternal: function(selector, onSuccess, onError) {
|
2013-10-17 15:00:05 -07:00
|
|
|
this._queueOrRun({
|
|
|
|
func: this._getStats,
|
2013-10-29 10:29:43 -07:00
|
|
|
args: [selector, onSuccess, onError, true],
|
2013-10-17 15:00:05 -07:00
|
|
|
wait: true
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2013-10-29 10:29:43 -07:00
|
|
|
_getStats: function(selector, onSuccess, onError, internal) {
|
|
|
|
this._onGetStatsSuccess = onSuccess;
|
|
|
|
this._onGetStatsFailure = onError;
|
|
|
|
|
|
|
|
this._getPC().getStats(selector, internal);
|
2013-10-17 15:00:05 -07:00
|
|
|
},
|
|
|
|
|
2012-10-06 22:34:30 -07:00
|
|
|
createDataChannel: function(label, dict) {
|
2013-01-17 12:25:17 -08:00
|
|
|
this._checkClosed();
|
2013-03-31 18:09:25 -07:00
|
|
|
if (dict == undefined) {
|
2013-05-07 17:55:21 -07:00
|
|
|
dict = {};
|
2013-03-31 18:09:25 -07:00
|
|
|
}
|
2013-06-03 14:34:42 -07:00
|
|
|
if (dict.maxRetransmitNum != undefined) {
|
|
|
|
dict.maxRetransmits = dict.maxRetransmitNum;
|
|
|
|
this.reportWarning("Deprecated RTCDataChannelInit dictionary entry maxRetransmitNum used!", null, 0);
|
|
|
|
}
|
|
|
|
if (dict.outOfOrderAllowed != undefined) {
|
|
|
|
dict.ordered = !dict.outOfOrderAllowed; // the meaning is swapped with the name change
|
|
|
|
this.reportWarning("Deprecated RTCDataChannelInit dictionary entry outOfOrderAllowed used!", null, 0);
|
|
|
|
}
|
|
|
|
if (dict.preset != undefined) {
|
|
|
|
dict.negotiated = dict.preset;
|
|
|
|
this.reportWarning("Deprecated RTCDataChannelInit dictionary entry preset used!", null, 0);
|
|
|
|
}
|
|
|
|
if (dict.stream != undefined) {
|
|
|
|
dict.id = dict.stream;
|
|
|
|
this.reportWarning("Deprecated RTCDataChannelInit dictionary entry stream used!", null, 0);
|
|
|
|
}
|
|
|
|
|
2013-03-31 18:09:25 -07:00
|
|
|
if (dict.maxRetransmitTime != undefined &&
|
2013-07-16 11:33:37 -07:00
|
|
|
dict.maxRetransmits != undefined) {
|
2013-09-06 12:29:29 -07:00
|
|
|
throw new this._win.DOMError("",
|
|
|
|
"Both maxRetransmitTime and maxRetransmits cannot be provided");
|
2012-10-06 22:34:30 -07:00
|
|
|
}
|
2013-03-31 18:09:25 -07:00
|
|
|
let protocol;
|
|
|
|
if (dict.protocol == undefined) {
|
|
|
|
protocol = "";
|
|
|
|
} else {
|
|
|
|
protocol = dict.protocol;
|
|
|
|
}
|
2012-10-06 22:34:30 -07:00
|
|
|
|
|
|
|
// Must determine the type where we still know if entries are undefined.
|
|
|
|
let type;
|
|
|
|
if (dict.maxRetransmitTime != undefined) {
|
2012-11-07 11:07:22 -08:00
|
|
|
type = Ci.IPeerConnection.kDataChannelPartialReliableTimed;
|
2013-07-16 11:33:37 -07:00
|
|
|
} else if (dict.maxRetransmits != undefined) {
|
2012-11-07 11:07:22 -08:00
|
|
|
type = Ci.IPeerConnection.kDataChannelPartialReliableRexmit;
|
2012-10-06 22:34:30 -07:00
|
|
|
} else {
|
2012-11-07 11:07:22 -08:00
|
|
|
type = Ci.IPeerConnection.kDataChannelReliable;
|
2012-10-06 22:34:30 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Synchronous since it doesn't block.
|
2013-04-16 22:16:02 -07:00
|
|
|
let channel = this._getPC().createDataChannel(
|
2013-07-16 11:33:37 -07:00
|
|
|
label, protocol, type, !dict.ordered, dict.maxRetransmitTime,
|
|
|
|
dict.maxRetransmits, dict.negotiated ? true : false,
|
|
|
|
dict.id != undefined ? dict.id : 0xFFFF
|
2012-10-06 22:34:30 -07:00
|
|
|
);
|
|
|
|
return channel;
|
|
|
|
},
|
|
|
|
|
|
|
|
connectDataConnection: function(localport, remoteport, numstreams) {
|
|
|
|
if (numstreams == undefined || numstreams <= 0) {
|
|
|
|
numstreams = 16;
|
|
|
|
}
|
|
|
|
this._queueOrRun({
|
2013-10-14 09:53:56 -07:00
|
|
|
func: this._connectDataConnection,
|
2012-10-06 22:34:30 -07:00
|
|
|
args: [localport, remoteport, numstreams],
|
|
|
|
wait: false
|
|
|
|
});
|
2013-10-14 09:53:56 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
_connectDataConnection: function(localport, remoteport, numstreams) {
|
|
|
|
this._getPC().connectDataConnection(localport, remoteport, numstreams);
|
2012-10-06 22:34:30 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-04-16 16:23:07 -07:00
|
|
|
function RTCError(code, message) {
|
|
|
|
this.name = this.reasonName[Math.min(code, this.reasonName.length - 1)];
|
|
|
|
this.message = (typeof message === "string")? message : this.name;
|
|
|
|
this.__exposedProps__ = { name: "rw", message: "rw" };
|
2012-10-06 22:34:30 -07:00
|
|
|
}
|
2013-04-16 16:23:07 -07:00
|
|
|
RTCError.prototype = {
|
2013-03-29 13:30:16 -07:00
|
|
|
// These strings must match those defined in the WebRTC spec.
|
|
|
|
reasonName: [
|
|
|
|
"NO_ERROR", // Should never happen -- only used for testing
|
|
|
|
"INVALID_CONSTRAINTS_TYPE",
|
|
|
|
"INVALID_CANDIDATE_TYPE",
|
|
|
|
"INVALID_MEDIASTREAM_TRACK",
|
|
|
|
"INVALID_STATE",
|
|
|
|
"INVALID_SESSION_DESCRIPTION",
|
|
|
|
"INCOMPATIBLE_SESSION_DESCRIPTION",
|
|
|
|
"INCOMPATIBLE_CONSTRAINTS",
|
|
|
|
"INCOMPATIBLE_MEDIASTREAMTRACK",
|
|
|
|
"INTERNAL_ERROR"
|
2013-04-16 16:23:07 -07:00
|
|
|
]
|
|
|
|
};
|
2013-03-29 13:30:16 -07:00
|
|
|
|
2013-04-16 16:23:07 -07:00
|
|
|
// This is a separate object because we don't want to expose it to DOM.
|
2013-10-14 09:53:56 -07:00
|
|
|
function PeerConnectionObserver() {
|
|
|
|
this._dompc = null;
|
2013-10-19 09:21:06 -07:00
|
|
|
this._guard = new WeakReferent(this);
|
2013-04-16 16:23:07 -07:00
|
|
|
}
|
|
|
|
PeerConnectionObserver.prototype = {
|
2013-10-14 09:53:56 -07:00
|
|
|
classDescription: "PeerConnectionObserver",
|
|
|
|
classID: PC_OBS_CID,
|
|
|
|
contractID: PC_OBS_CONTRACT,
|
|
|
|
QueryInterface: XPCOMUtils.generateQI([Ci.nsISupports,
|
|
|
|
Ci.nsIDOMGlobalPropertyInitializer]),
|
|
|
|
init: function(win) { this._win = win; },
|
|
|
|
|
|
|
|
__init: function(dompc) {
|
2013-11-01 17:49:48 -07:00
|
|
|
this._dompc = dompc._innerObject;
|
2013-10-14 09:53:56 -07:00
|
|
|
},
|
2013-03-29 13:30:16 -07:00
|
|
|
|
2013-05-07 17:55:21 -07:00
|
|
|
dispatchEvent: function(event) {
|
|
|
|
this._dompc.dispatchEvent(event);
|
|
|
|
},
|
|
|
|
|
2013-04-16 16:23:07 -07:00
|
|
|
callCB: function(callback, arg) {
|
2013-03-29 13:30:16 -07:00
|
|
|
if (callback) {
|
|
|
|
try {
|
2013-05-07 17:55:21 -07:00
|
|
|
callback(arg);
|
2013-04-16 16:23:07 -07:00
|
|
|
} catch(e) {
|
|
|
|
// A content script (user-provided) callback threw an error. We don't
|
|
|
|
// want this to take down peerconnection, but we still want the user
|
|
|
|
// to see it, so we catch it, report it, and move on.
|
2013-05-11 17:48:29 -07:00
|
|
|
this._dompc.reportError(e.message, e.fileName, e.lineNumber);
|
2013-05-07 17:55:21 -07:00
|
|
|
}
|
2013-03-29 13:30:16 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2013-05-07 17:55:21 -07:00
|
|
|
onCreateOfferSuccess: function(sdp) {
|
2013-04-16 16:23:07 -07:00
|
|
|
this.callCB(this._dompc._onCreateOfferSuccess,
|
2013-05-07 17:55:21 -07:00
|
|
|
new this._dompc._win.mozRTCSessionDescription({ type: "offer",
|
|
|
|
sdp: sdp }));
|
2012-10-06 22:34:30 -07:00
|
|
|
this._dompc._executeNext();
|
|
|
|
},
|
|
|
|
|
2013-03-29 13:30:16 -07:00
|
|
|
onCreateOfferError: function(code, message) {
|
2013-04-16 16:23:07 -07:00
|
|
|
this.callCB(this._dompc._onCreateOfferFailure, new RTCError(code, message));
|
2012-10-06 22:34:30 -07:00
|
|
|
this._dompc._executeNext();
|
|
|
|
},
|
|
|
|
|
2013-05-07 17:55:21 -07:00
|
|
|
onCreateAnswerSuccess: function(sdp) {
|
2013-04-16 16:23:07 -07:00
|
|
|
this.callCB (this._dompc._onCreateAnswerSuccess,
|
2013-05-07 17:55:21 -07:00
|
|
|
new this._dompc._win.mozRTCSessionDescription({ type: "answer",
|
|
|
|
sdp: sdp }));
|
2012-10-06 22:34:30 -07:00
|
|
|
this._dompc._executeNext();
|
|
|
|
},
|
|
|
|
|
2013-03-29 13:30:16 -07:00
|
|
|
onCreateAnswerError: function(code, message) {
|
2013-04-16 16:23:07 -07:00
|
|
|
this.callCB(this._dompc._onCreateAnswerFailure, new RTCError(code, message));
|
2012-10-06 22:34:30 -07:00
|
|
|
this._dompc._executeNext();
|
|
|
|
},
|
|
|
|
|
2013-03-29 13:30:16 -07:00
|
|
|
onSetLocalDescriptionSuccess: function() {
|
2013-01-14 14:25:54 -08:00
|
|
|
this._dompc._localType = this._dompc._pendingType;
|
|
|
|
this._dompc._pendingType = null;
|
2013-04-16 16:23:07 -07:00
|
|
|
this.callCB(this._dompc._onSetLocalDescriptionSuccess);
|
2013-04-09 14:18:32 -07:00
|
|
|
|
2013-10-02 09:32:59 -07:00
|
|
|
if (this._dompc._iceGatheringState == "complete") {
|
2013-09-16 17:42:39 -07:00
|
|
|
// If we are not trickling or we completed gathering prior
|
|
|
|
// to setLocal, then trigger a call of onicecandidate here.
|
|
|
|
this.foundIceCandidate(null);
|
|
|
|
}
|
2013-04-09 14:18:32 -07:00
|
|
|
|
2012-10-06 22:34:30 -07:00
|
|
|
this._dompc._executeNext();
|
|
|
|
},
|
|
|
|
|
2013-03-29 13:30:16 -07:00
|
|
|
onSetRemoteDescriptionSuccess: function() {
|
2013-01-14 14:25:54 -08:00
|
|
|
this._dompc._remoteType = this._dompc._pendingType;
|
|
|
|
this._dompc._pendingType = null;
|
2013-04-16 16:23:07 -07:00
|
|
|
this.callCB(this._dompc._onSetRemoteDescriptionSuccess);
|
2012-10-06 22:34:30 -07:00
|
|
|
this._dompc._executeNext();
|
|
|
|
},
|
|
|
|
|
2013-03-29 13:30:16 -07:00
|
|
|
onSetLocalDescriptionError: function(code, message) {
|
2013-01-14 14:25:54 -08:00
|
|
|
this._dompc._pendingType = null;
|
2013-04-16 16:23:07 -07:00
|
|
|
this.callCB(this._dompc._onSetLocalDescriptionFailure,
|
|
|
|
new RTCError(code, message));
|
2012-10-06 22:34:30 -07:00
|
|
|
this._dompc._executeNext();
|
|
|
|
},
|
|
|
|
|
2013-03-29 13:30:16 -07:00
|
|
|
onSetRemoteDescriptionError: function(code, message) {
|
2013-01-14 14:25:54 -08:00
|
|
|
this._dompc._pendingType = null;
|
2013-04-16 16:23:07 -07:00
|
|
|
this.callCB(this._dompc._onSetRemoteDescriptionFailure,
|
|
|
|
new RTCError(code, message));
|
2012-10-06 22:34:30 -07:00
|
|
|
this._dompc._executeNext();
|
|
|
|
},
|
|
|
|
|
2013-03-29 13:30:16 -07:00
|
|
|
onAddIceCandidateSuccess: function() {
|
2013-01-31 12:43:03 -08:00
|
|
|
this._dompc._pendingType = null;
|
2013-04-16 16:23:07 -07:00
|
|
|
this.callCB(this._dompc._onAddIceCandidateSuccess);
|
2013-01-31 12:43:03 -08:00
|
|
|
this._dompc._executeNext();
|
|
|
|
},
|
|
|
|
|
2013-03-29 13:30:16 -07:00
|
|
|
onAddIceCandidateError: function(code, message) {
|
2013-01-31 12:43:03 -08:00
|
|
|
this._dompc._pendingType = null;
|
2013-04-16 16:23:07 -07:00
|
|
|
this.callCB(this._dompc._onAddIceCandidateError, new RTCError(code, message));
|
2013-01-31 12:43:03 -08:00
|
|
|
this._dompc._executeNext();
|
|
|
|
},
|
|
|
|
|
2013-09-16 17:42:39 -07:00
|
|
|
onIceCandidate: function(level, mid, candidate) {
|
|
|
|
this.foundIceCandidate(new this._dompc._win.mozRTCIceCandidate(
|
|
|
|
{
|
|
|
|
candidate: candidate,
|
|
|
|
sdpMid: mid,
|
2013-10-09 10:37:04 -07:00
|
|
|
sdpMLineIndex: level - 1
|
2013-09-16 17:42:39 -07:00
|
|
|
}
|
|
|
|
));
|
|
|
|
},
|
|
|
|
|
2013-10-02 09:32:59 -07:00
|
|
|
|
|
|
|
// This method is primarily responsible for updating two attributes:
|
|
|
|
// iceGatheringState and iceConnectionState. These states are defined
|
|
|
|
// in the WebRTC specification as follows:
|
|
|
|
//
|
|
|
|
// iceGatheringState:
|
|
|
|
// ------------------
|
|
|
|
// new The object was just created, and no networking has occurred
|
|
|
|
// yet.
|
|
|
|
//
|
|
|
|
// gathering The ICE engine is in the process of gathering candidates for
|
|
|
|
// this RTCPeerConnection.
|
|
|
|
//
|
|
|
|
// complete The ICE engine has completed gathering. Events such as adding
|
|
|
|
// a new interface or a new TURN server will cause the state to
|
|
|
|
// go back to gathering.
|
|
|
|
//
|
|
|
|
// iceConnectionState:
|
|
|
|
// -------------------
|
|
|
|
// new The ICE Agent is gathering addresses and/or waiting for
|
|
|
|
// remote candidates to be supplied.
|
|
|
|
//
|
|
|
|
// checking The ICE Agent has received remote candidates on at least
|
|
|
|
// one component, and is checking candidate pairs but has not
|
|
|
|
// yet found a connection. In addition to checking, it may
|
|
|
|
// also still be gathering.
|
|
|
|
//
|
|
|
|
// connected The ICE Agent has found a usable connection for all
|
|
|
|
// components but is still checking other candidate pairs to
|
|
|
|
// see if there is a better connection. It may also still be
|
|
|
|
// gathering.
|
|
|
|
//
|
|
|
|
// completed The ICE Agent has finished gathering and checking and found
|
|
|
|
// a connection for all components. Open issue: it is not
|
|
|
|
// clear how the non controlling ICE side knows it is in the
|
|
|
|
// state.
|
|
|
|
//
|
|
|
|
// failed The ICE Agent is finished checking all candidate pairs and
|
|
|
|
// failed to find a connection for at least one component.
|
|
|
|
// Connections may have been found for some components.
|
|
|
|
//
|
|
|
|
// disconnected Liveness checks have failed for one or more components.
|
|
|
|
// This is more aggressive than failed, and may trigger
|
|
|
|
// intermittently (and resolve itself without action) on a
|
|
|
|
// flaky network.
|
|
|
|
//
|
|
|
|
// closed The ICE Agent has shut down and is no longer responding to
|
|
|
|
// STUN requests.
|
|
|
|
|
2013-05-16 16:41:46 -07:00
|
|
|
handleIceStateChanges: function(iceState) {
|
2013-08-26 11:33:31 -07:00
|
|
|
var histogram = Services.telemetry.getHistogramById("WEBRTC_ICE_SUCCESS_RATE");
|
2013-10-02 09:32:59 -07:00
|
|
|
|
2013-10-14 09:53:56 -07:00
|
|
|
const STATE_MAP = {
|
|
|
|
IceGathering:
|
2013-10-02 09:32:59 -07:00
|
|
|
{ gathering: "gathering" },
|
2013-10-14 09:53:56 -07:00
|
|
|
IceWaiting:
|
2013-10-27 07:36:34 -07:00
|
|
|
{ connection: "new", gathering: "complete" },
|
2013-10-14 09:53:56 -07:00
|
|
|
IceChecking:
|
2013-10-27 07:36:34 -07:00
|
|
|
{ connection: "checking" },
|
2013-10-14 09:53:56 -07:00
|
|
|
IceConnected:
|
2013-10-27 07:36:34 -07:00
|
|
|
{ connection: "connected", success: true },
|
2013-10-14 09:53:56 -07:00
|
|
|
IceFailed:
|
2013-10-27 07:36:34 -07:00
|
|
|
{ connection: "failed", success: false }
|
2013-10-14 09:53:56 -07:00
|
|
|
};
|
|
|
|
// These are all the allowed inputs.
|
2013-10-02 09:32:59 -07:00
|
|
|
|
|
|
|
let transitions = STATE_MAP[iceState];
|
|
|
|
|
|
|
|
if ("connection" in transitions) {
|
|
|
|
this._dompc.changeIceConnectionState(transitions.connection);
|
|
|
|
}
|
|
|
|
if ("gathering" in transitions) {
|
|
|
|
this._dompc.changeIceGatheringState(transitions.gathering);
|
|
|
|
}
|
|
|
|
if ("success" in transitions) {
|
|
|
|
histogram.add(transitions.success);
|
|
|
|
}
|
|
|
|
|
2013-10-14 09:53:56 -07:00
|
|
|
if (iceState == "IceWaiting") {
|
2013-10-02 09:32:59 -07:00
|
|
|
if (!this._dompc._trickleIce) {
|
|
|
|
// If we are not trickling, then the queue is in a pending state
|
|
|
|
// waiting for ICE gathering and executeNext frees it
|
|
|
|
this._dompc._executeNext();
|
|
|
|
}
|
2013-11-01 02:37:02 -07:00
|
|
|
else if (this._dompc.localDescription) {
|
2013-10-02 09:32:59 -07:00
|
|
|
// If we are trickling but we have already done setLocal,
|
|
|
|
// then we need to send a final foundIceCandidate(null) to indicate
|
|
|
|
// that we are done gathering.
|
|
|
|
this.foundIceCandidate(null);
|
|
|
|
}
|
2013-05-16 16:41:46 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
onStateChange: function(state) {
|
|
|
|
switch (state) {
|
2013-10-14 09:53:56 -07:00
|
|
|
case "SignalingState":
|
2013-05-16 16:41:46 -07:00
|
|
|
this.callCB(this._dompc.onsignalingstatechange,
|
|
|
|
this._dompc.signalingState);
|
|
|
|
break;
|
|
|
|
|
2013-10-14 09:53:56 -07:00
|
|
|
case "IceState":
|
2013-05-16 16:41:46 -07:00
|
|
|
this.handleIceStateChanges(this._dompc._pc.iceState);
|
|
|
|
break;
|
|
|
|
|
2013-10-14 09:53:56 -07:00
|
|
|
case "SdpState":
|
2013-05-16 16:41:46 -07:00
|
|
|
// No-op
|
|
|
|
break;
|
|
|
|
|
2013-10-14 09:53:56 -07:00
|
|
|
case "ReadyState":
|
2013-10-02 09:32:59 -07:00
|
|
|
// No-op
|
|
|
|
break;
|
|
|
|
|
2013-10-14 09:53:56 -07:00
|
|
|
case "SipccState":
|
2013-05-16 16:41:46 -07:00
|
|
|
// No-op
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
this._dompc.reportWarning("Unhandled state type: " + state, null, 0);
|
2012-10-06 22:34:30 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2013-10-17 15:00:05 -07:00
|
|
|
onGetStatsSuccess: function(dict) {
|
|
|
|
function appendStats(stats, report) {
|
|
|
|
if (stats) {
|
|
|
|
stats.forEach(function(stat) {
|
|
|
|
report[stat.id] = stat;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let report = {};
|
|
|
|
appendStats(dict.rtpStreamStats, report);
|
|
|
|
appendStats(dict.inboundRTPStreamStats, report);
|
|
|
|
appendStats(dict.outboundRTPStreamStats, report);
|
|
|
|
appendStats(dict.mediaStreamTrackStats, report);
|
|
|
|
appendStats(dict.mediaStreamStats, report);
|
|
|
|
appendStats(dict.transportStats, report);
|
|
|
|
appendStats(dict.iceComponentStats, report);
|
2013-10-28 16:02:00 -07:00
|
|
|
appendStats(dict.iceCandidatePairStats, report);
|
2013-10-17 15:00:05 -07:00
|
|
|
appendStats(dict.iceCandidateStats, report);
|
|
|
|
appendStats(dict.codecStats, report);
|
|
|
|
|
|
|
|
this.callCB(this._dompc._onGetStatsSuccess,
|
|
|
|
this._dompc._win.RTCStatsReport._create(this._dompc._win,
|
|
|
|
new RTCStatsReport(this._dompc._win,
|
|
|
|
report)));
|
|
|
|
this._dompc._executeNext();
|
|
|
|
},
|
|
|
|
|
|
|
|
onGetStatsError: function(code, message) {
|
|
|
|
this.callCB(this._dompc._onGetStatsFailure, new RTCError(code, message));
|
|
|
|
this._dompc._executeNext();
|
|
|
|
},
|
|
|
|
|
2013-05-07 17:55:21 -07:00
|
|
|
onAddStream: function(stream) {
|
|
|
|
this.dispatchEvent(new this._dompc._win.MediaStreamEvent("addstream",
|
|
|
|
{ stream: stream }));
|
2012-10-06 22:34:30 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
onRemoveStream: function(stream, type) {
|
2013-05-07 17:55:21 -07:00
|
|
|
this.dispatchEvent(new this._dompc._win.MediaStreamEvent("removestream",
|
|
|
|
{ stream: stream }));
|
2012-10-06 22:34:30 -07:00
|
|
|
},
|
|
|
|
|
2013-10-02 09:32:59 -07:00
|
|
|
foundIceCandidate: function(cand) {
|
2013-05-07 17:55:21 -07:00
|
|
|
this.dispatchEvent(new this._dompc._win.RTCPeerConnectionIceEvent("icecandidate",
|
2013-10-02 09:32:59 -07:00
|
|
|
{ candidate: cand } ));
|
2012-10-06 22:34:30 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
notifyDataChannel: function(channel) {
|
2013-05-16 16:40:23 -07:00
|
|
|
this.dispatchEvent(new this._dompc._win.RTCDataChannelEvent("datachannel",
|
|
|
|
{ channel: channel }));
|
2012-10-06 22:34:30 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
notifyConnection: function() {
|
2013-05-16 16:40:23 -07:00
|
|
|
this.dispatchEvent(new this._dompc._win.Event("connection"));
|
2012-10-06 22:34:30 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
notifyClosedConnection: function() {
|
2013-05-16 16:40:23 -07:00
|
|
|
this.dispatchEvent(new this._dompc._win.Event("closedconnection"));
|
2013-10-09 19:27:54 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
getSupportedConstraints: function(dict) {
|
2013-10-14 09:53:56 -07:00
|
|
|
return dict;
|
2013-10-19 09:21:06 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
get weakReferent() {
|
|
|
|
return this._guard;
|
2012-10-06 22:34:30 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-10-19 09:21:06 -07:00
|
|
|
// A PeerConnectionObserver member that c++ can do weak references on
|
|
|
|
|
|
|
|
function WeakReferent(parent) {
|
|
|
|
this._parent = parent; // prevents parent from going away without us
|
|
|
|
}
|
|
|
|
WeakReferent.prototype = {
|
|
|
|
QueryInterface: XPCOMUtils.generateQI([Ci.nsISupports,
|
|
|
|
Ci.nsISupportsWeakReference]),
|
|
|
|
};
|
|
|
|
|
2012-10-31 09:13:28 -07:00
|
|
|
this.NSGetFactory = XPCOMUtils.generateNSGetFactory(
|
2013-10-14 09:53:56 -07:00
|
|
|
[GlobalPCList, RTCIceCandidate, RTCSessionDescription, RTCPeerConnection,
|
2013-10-17 15:00:05 -07:00
|
|
|
RTCStatsReport, PeerConnectionObserver]
|
2012-10-06 22:34:30 -07:00
|
|
|
);
|