You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

TraceablePeerConnection.js 25KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653
  1. /* global mozRTCPeerConnection, webkitRTCPeerConnection */
  2. import { getLogger } from "jitsi-meet-logger";
  3. const logger = getLogger(__filename);
  4. import SdpConsistency from "./SdpConsistency.js";
  5. import RtxModifier from "./RtxModifier.js";
  6. var RTCBrowserType = require("../RTC/RTCBrowserType.js");
  7. var XMPPEvents = require("../../service/xmpp/XMPPEvents");
  8. var transform = require('sdp-transform');
  9. var SDP = require("./SDP");
  10. var SDPUtil = require("./SDPUtil");
  11. var SIMULCAST_LAYERS = 3;
  12. function TraceablePeerConnection(ice_config, constraints, session) {
  13. var self = this;
  14. this.session = session;
  15. var RTCPeerConnectionType = null;
  16. if (RTCBrowserType.isFirefox()) {
  17. RTCPeerConnectionType = mozRTCPeerConnection;
  18. } else if (RTCBrowserType.isTemasysPluginUsed()) {
  19. RTCPeerConnectionType = RTCPeerConnection;
  20. } else {
  21. RTCPeerConnectionType = webkitRTCPeerConnection;
  22. }
  23. this.peerconnection = new RTCPeerConnectionType(ice_config, constraints);
  24. this.updateLog = [];
  25. this.stats = {};
  26. this.statsinterval = null;
  27. this.maxstats = 0; // limit to 300 values, i.e. 5 minutes; set to 0 to disable
  28. var Interop = require('sdp-interop').Interop;
  29. this.interop = new Interop();
  30. var Simulcast = require('sdp-simulcast');
  31. this.simulcast = new Simulcast({numOfLayers: SIMULCAST_LAYERS,
  32. explodeRemoteSimulcast: false});
  33. this.sdpConsistency = new SdpConsistency();
  34. this.rtxModifier = new RtxModifier();
  35. this.eventEmitter = this.session.room.eventEmitter;
  36. // override as desired
  37. this.trace = function (what, info) {
  38. /*logger.warn('WTRACE', what, info);
  39. if (info && RTCBrowserType.isIExplorer()) {
  40. if (info.length > 1024) {
  41. logger.warn('WTRACE', what, info.substr(1024));
  42. }
  43. if (info.length > 2048) {
  44. logger.warn('WTRACE', what, info.substr(2048));
  45. }
  46. }*/
  47. self.updateLog.push({
  48. time: new Date(),
  49. type: what,
  50. value: info || ""
  51. });
  52. };
  53. this.onicecandidate = null;
  54. this.peerconnection.onicecandidate = function (event) {
  55. // FIXME: this causes stack overflow with Temasys Plugin
  56. if (!RTCBrowserType.isTemasysPluginUsed())
  57. self.trace('onicecandidate', JSON.stringify(event.candidate, null, ' '));
  58. if (self.onicecandidate !== null) {
  59. self.onicecandidate(event);
  60. }
  61. };
  62. this.onaddstream = null;
  63. this.peerconnection.onaddstream = function (event) {
  64. self.trace('onaddstream', event.stream.id);
  65. if (self.onaddstream !== null) {
  66. self.onaddstream(event);
  67. }
  68. };
  69. this.onremovestream = null;
  70. this.peerconnection.onremovestream = function (event) {
  71. self.trace('onremovestream', event.stream.id);
  72. if (self.onremovestream !== null) {
  73. self.onremovestream(event);
  74. }
  75. };
  76. this.onsignalingstatechange = null;
  77. this.peerconnection.onsignalingstatechange = function (event) {
  78. self.trace('onsignalingstatechange', self.signalingState);
  79. if (self.onsignalingstatechange !== null) {
  80. self.onsignalingstatechange(event);
  81. }
  82. };
  83. this.oniceconnectionstatechange = null;
  84. this.peerconnection.oniceconnectionstatechange = function (event) {
  85. self.trace('oniceconnectionstatechange', self.iceConnectionState);
  86. if (self.oniceconnectionstatechange !== null) {
  87. self.oniceconnectionstatechange(event);
  88. }
  89. };
  90. this.onnegotiationneeded = null;
  91. this.peerconnection.onnegotiationneeded = function (event) {
  92. self.trace('onnegotiationneeded');
  93. if (self.onnegotiationneeded !== null) {
  94. self.onnegotiationneeded(event);
  95. }
  96. };
  97. self.ondatachannel = null;
  98. this.peerconnection.ondatachannel = function (event) {
  99. self.trace('ondatachannel', event);
  100. if (self.ondatachannel !== null) {
  101. self.ondatachannel(event);
  102. }
  103. };
  104. // XXX: do all non-firefox browsers which we support also support this?
  105. if (!RTCBrowserType.isFirefox() && this.maxstats) {
  106. this.statsinterval = window.setInterval(function() {
  107. self.peerconnection.getStats(function(stats) {
  108. var results = stats.result();
  109. var now = new Date();
  110. for (var i = 0; i < results.length; ++i) {
  111. results[i].names().forEach(function (name) {
  112. var id = results[i].id + '-' + name;
  113. if (!self.stats[id]) {
  114. self.stats[id] = {
  115. startTime: now,
  116. endTime: now,
  117. values: [],
  118. times: []
  119. };
  120. }
  121. self.stats[id].values.push(results[i].stat(name));
  122. self.stats[id].times.push(now.getTime());
  123. if (self.stats[id].values.length > self.maxstats) {
  124. self.stats[id].values.shift();
  125. self.stats[id].times.shift();
  126. }
  127. self.stats[id].endTime = now;
  128. });
  129. }
  130. });
  131. }, 1000);
  132. }
  133. }
  134. /**
  135. * Returns a string representation of a SessionDescription object.
  136. */
  137. var dumpSDP = function(description) {
  138. if (typeof description === 'undefined' || description == null) {
  139. return '';
  140. }
  141. return 'type: ' + description.type + '\r\n' + description.sdp;
  142. };
  143. /**
  144. * Returns map with keys msid and values ssrc.
  145. * @param desc the SDP that will be modified.
  146. */
  147. function extractSSRCMap(desc) {
  148. if (typeof desc !== 'object' || desc === null ||
  149. typeof desc.sdp !== 'string') {
  150. logger.warn('An empty description was passed as an argument.');
  151. return desc;
  152. }
  153. var ssrcList = {};
  154. var ssrcGroups = {};
  155. var session = transform.parse(desc.sdp);
  156. if (!Array.isArray(session.media))
  157. {
  158. return;
  159. }
  160. session.media.forEach(function (bLine) {
  161. if (!Array.isArray(bLine.ssrcs))
  162. {
  163. return;
  164. }
  165. if (typeof bLine.ssrcGroups !== 'undefined' &&
  166. Array.isArray(bLine.ssrcGroups)) {
  167. bLine.ssrcGroups.forEach(function (group) {
  168. if (typeof group.semantics !== 'undefined' &&
  169. typeof group.ssrcs !== 'undefined') {
  170. var primarySSRC = Number(group.ssrcs.split(' ')[0]);
  171. ssrcGroups[primarySSRC] = ssrcGroups[primarySSRC] || [];
  172. ssrcGroups[primarySSRC].push(group);
  173. }
  174. });
  175. }
  176. bLine.ssrcs.forEach(function (ssrc) {
  177. if(ssrc.attribute !== 'msid')
  178. return;
  179. ssrcList[ssrc.value] = ssrcList[ssrc.value] ||
  180. {groups: [], ssrcs: []};
  181. ssrcList[ssrc.value].ssrcs.push(ssrc.id);
  182. if(ssrcGroups[ssrc.id]){
  183. ssrcGroups[ssrc.id].forEach(function (group) {
  184. ssrcList[ssrc.value].groups.push(
  185. {primarySSRC: ssrc.id, group: group});
  186. });
  187. }
  188. });
  189. });
  190. return ssrcList;
  191. }
  192. /**
  193. * Takes a SessionDescription object and returns a "normalized" version.
  194. * Currently it only takes care of ordering the a=ssrc lines.
  195. */
  196. var normalizePlanB = function(desc) {
  197. if (typeof desc !== 'object' || desc === null ||
  198. typeof desc.sdp !== 'string') {
  199. logger.warn('An empty description was passed as an argument.');
  200. return desc;
  201. }
  202. var transform = require('sdp-transform');
  203. var session = transform.parse(desc.sdp);
  204. if (typeof session !== 'undefined' &&
  205. typeof session.media !== 'undefined' && Array.isArray(session.media)) {
  206. session.media.forEach(function (mLine) {
  207. // Chrome appears to be picky about the order in which a=ssrc lines
  208. // are listed in an m-line when rtx is enabled (and thus there are
  209. // a=ssrc-group lines with FID semantics). Specifically if we have
  210. // "a=ssrc-group:FID S1 S2" and the "a=ssrc:S2" lines appear before
  211. // the "a=ssrc:S1" lines, SRD fails.
  212. // So, put SSRC which appear as the first SSRC in an FID ssrc-group
  213. // first.
  214. var firstSsrcs = [];
  215. var newSsrcLines = [];
  216. if (typeof mLine.ssrcGroups !== 'undefined' &&
  217. Array.isArray(mLine.ssrcGroups)) {
  218. mLine.ssrcGroups.forEach(function (group) {
  219. if (typeof group.semantics !== 'undefined' &&
  220. group.semantics === 'FID') {
  221. if (typeof group.ssrcs !== 'undefined') {
  222. firstSsrcs.push(Number(group.ssrcs.split(' ')[0]));
  223. }
  224. }
  225. });
  226. }
  227. if (typeof mLine.ssrcs !== 'undefined' && Array.isArray(mLine.ssrcs)) {
  228. var i;
  229. for (i = 0; i<mLine.ssrcs.length; i++){
  230. if (typeof mLine.ssrcs[i] === 'object'
  231. && typeof mLine.ssrcs[i].id !== 'undefined'
  232. && firstSsrcs.indexOf(mLine.ssrcs[i].id) >= 0) {
  233. newSsrcLines.push(mLine.ssrcs[i]);
  234. delete mLine.ssrcs[i];
  235. }
  236. }
  237. for (i = 0; i<mLine.ssrcs.length; i++){
  238. if (typeof mLine.ssrcs[i] !== 'undefined') {
  239. newSsrcLines.push(mLine.ssrcs[i]);
  240. }
  241. }
  242. mLine.ssrcs = newSsrcLines;
  243. }
  244. });
  245. }
  246. var resStr = transform.write(session);
  247. return new RTCSessionDescription({
  248. type: desc.type,
  249. sdp: resStr
  250. });
  251. };
  252. var getters = {
  253. signalingState: function () {
  254. return this.peerconnection.signalingState;
  255. },
  256. iceConnectionState: function () {
  257. return this.peerconnection.iceConnectionState;
  258. },
  259. localDescription: function() {
  260. var desc = this.peerconnection.localDescription;
  261. this.trace('getLocalDescription::preTransform', dumpSDP(desc));
  262. // if we're running on FF, transform to Plan B first.
  263. if (RTCBrowserType.usesUnifiedPlan()) {
  264. desc = this.interop.toPlanB(desc);
  265. this.trace('getLocalDescription::postTransform (Plan B)',
  266. dumpSDP(desc));
  267. }
  268. return desc;
  269. },
  270. remoteDescription: function() {
  271. var desc = this.peerconnection.remoteDescription;
  272. this.trace('getRemoteDescription::preTransform', dumpSDP(desc));
  273. // if we're running on FF, transform to Plan B first.
  274. if (RTCBrowserType.usesUnifiedPlan()) {
  275. desc = this.interop.toPlanB(desc);
  276. this.trace('getRemoteDescription::postTransform (Plan B)', dumpSDP(desc));
  277. }
  278. return desc;
  279. }
  280. };
  281. Object.keys(getters).forEach(function (prop) {
  282. Object.defineProperty(
  283. TraceablePeerConnection.prototype,
  284. prop, {
  285. get: getters[prop]
  286. }
  287. );
  288. });
  289. TraceablePeerConnection.prototype.addStream = function (stream, ssrcInfo) {
  290. this.trace('addStream', stream ? stream.id : "null");
  291. if (stream)
  292. this.peerconnection.addStream(stream);
  293. if (ssrcInfo && ssrcInfo.type === "addMuted") {
  294. this.sdpConsistency.setPrimarySsrc(ssrcInfo.ssrc.ssrcs[0]);
  295. const simGroup =
  296. ssrcInfo.ssrc.groups.find(groupInfo => {
  297. return groupInfo.group.semantics === "SIM";
  298. });
  299. if (simGroup) {
  300. const simSsrcs = SDPUtil.parseGroupSsrcs(simGroup.group);
  301. this.simulcast.setSsrcCache(simSsrcs);
  302. }
  303. const fidGroups =
  304. ssrcInfo.ssrc.groups.filter(groupInfo => {
  305. return groupInfo.group.semantics === "FID";
  306. });
  307. if (fidGroups) {
  308. const rtxSsrcMapping = new Map();
  309. fidGroups.forEach(fidGroup => {
  310. const fidGroupSsrcs =
  311. SDPUtil.parseGroupSsrcs(fidGroup.group);
  312. const primarySsrc = fidGroupSsrcs[0];
  313. const rtxSsrc = fidGroupSsrcs[1];
  314. rtxSsrcMapping.set(primarySsrc, rtxSsrc);
  315. });
  316. this.rtxModifier.setSsrcCache(rtxSsrcMapping);
  317. }
  318. }
  319. };
  320. TraceablePeerConnection.prototype.removeStream = function (stream) {
  321. this.trace('removeStream', stream.id);
  322. // FF doesn't support this yet.
  323. if (this.peerconnection.removeStream) {
  324. this.peerconnection.removeStream(stream);
  325. }
  326. };
  327. TraceablePeerConnection.prototype.createDataChannel = function (label, opts) {
  328. this.trace('createDataChannel', label, opts);
  329. return this.peerconnection.createDataChannel(label, opts);
  330. };
  331. TraceablePeerConnection.prototype.setLocalDescription
  332. = function (description, successCallback, failureCallback) {
  333. this.trace('setLocalDescription::preTransform', dumpSDP(description));
  334. // if we're running on FF, transform to Plan A first.
  335. if (RTCBrowserType.usesUnifiedPlan()) {
  336. description = this.interop.toUnifiedPlan(description);
  337. this.trace('setLocalDescription::postTransform (Plan A)',
  338. dumpSDP(description));
  339. }
  340. var self = this;
  341. this.peerconnection.setLocalDescription(description,
  342. function () {
  343. self.trace('setLocalDescriptionOnSuccess');
  344. successCallback();
  345. },
  346. function (err) {
  347. self.trace('setLocalDescriptionOnFailure', err);
  348. self.eventEmitter.emit(XMPPEvents.SET_LOCAL_DESCRIPTION_FAILED,
  349. err, self.peerconnection);
  350. failureCallback(err);
  351. }
  352. );
  353. };
  354. TraceablePeerConnection.prototype.setRemoteDescription
  355. = function (description, successCallback, failureCallback) {
  356. this.trace('setRemoteDescription::preTransform', dumpSDP(description));
  357. // TODO the focus should squeze or explode the remote simulcast
  358. description = this.simulcast.mungeRemoteDescription(description);
  359. this.trace('setRemoteDescription::postTransform (simulcast)', dumpSDP(description));
  360. // if we're running on FF, transform to Plan A first.
  361. if (RTCBrowserType.usesUnifiedPlan()) {
  362. description.sdp = this.rtxModifier.stripRtx(description.sdp);
  363. this.trace('setRemoteDescription::postTransform (stripRtx)', dumpSDP(description));
  364. description = this.interop.toUnifiedPlan(description);
  365. this.trace('setRemoteDescription::postTransform (Plan A)', dumpSDP(description));
  366. }
  367. if (RTCBrowserType.usesPlanB()) {
  368. description = normalizePlanB(description);
  369. }
  370. var self = this;
  371. this.peerconnection.setRemoteDescription(description,
  372. function () {
  373. self.trace('setRemoteDescriptionOnSuccess');
  374. successCallback();
  375. },
  376. function (err) {
  377. self.trace('setRemoteDescriptionOnFailure', err);
  378. self.eventEmitter.emit(XMPPEvents.SET_REMOTE_DESCRIPTION_FAILED,
  379. err, self.peerconnection);
  380. failureCallback(err);
  381. }
  382. );
  383. /*
  384. if (this.statsinterval === null && this.maxstats > 0) {
  385. // start gathering stats
  386. }
  387. */
  388. };
  389. /**
  390. * Makes the underlying TraceablePeerConnection generate new SSRC for
  391. * the recvonly video stream.
  392. * @deprecated
  393. */
  394. TraceablePeerConnection.prototype.generateRecvonlySsrc = function() {
  395. // FIXME replace with SDPUtil.generateSsrc (when it's added)
  396. const newSSRC = this.generateNewStreamSSRCInfo().ssrcs[0];
  397. logger.info("Generated new recvonly SSRC: " + newSSRC);
  398. this.sdpConsistency.setPrimarySsrc(newSSRC);
  399. };
  400. TraceablePeerConnection.prototype.close = function () {
  401. this.trace('stop');
  402. if (this.statsinterval !== null) {
  403. window.clearInterval(this.statsinterval);
  404. this.statsinterval = null;
  405. }
  406. this.peerconnection.close();
  407. };
  408. /**
  409. * Modifies the values of the setup attributes (defined by
  410. * {@link http://tools.ietf.org/html/rfc4145#section-4}) of a specific SDP
  411. * answer in order to overcome a delay of 1 second in the connection
  412. * establishment between Chrome and Videobridge.
  413. *
  414. * @param {SDP} offer - the SDP offer to which the specified SDP answer is
  415. * being prepared to respond
  416. * @param {SDP} answer - the SDP to modify
  417. * @private
  418. */
  419. var _fixAnswerRFC4145Setup = function (offer, answer) {
  420. if (!RTCBrowserType.isChrome()) {
  421. // It looks like Firefox doesn't agree with the fix (at least in its
  422. // current implementation) because it effectively remains active even
  423. // after we tell it to become passive. Apart from Firefox which I tested
  424. // after the fix was deployed, I tested Chrome only. In order to prevent
  425. // issues with other browsers, limit the fix to Chrome for the time
  426. // being.
  427. return;
  428. }
  429. // XXX Videobridge is the (SDP) offerer and WebRTC (e.g. Chrome) is the
  430. // answerer (as orchestrated by Jicofo). In accord with
  431. // http://tools.ietf.org/html/rfc5245#section-5.2 and because both peers
  432. // are ICE FULL agents, Videobridge will take on the controlling role and
  433. // WebRTC will take on the controlled role. In accord with
  434. // https://tools.ietf.org/html/rfc5763#section-5, Videobridge will use the
  435. // setup attribute value of setup:actpass and WebRTC will be allowed to
  436. // choose either the setup attribute value of setup:active or
  437. // setup:passive. Chrome will by default choose setup:active because it is
  438. // RECOMMENDED by the respective RFC since setup:passive adds additional
  439. // latency. The case of setup:active allows WebRTC to send a DTLS
  440. // ClientHello as soon as an ICE connectivity check of its succeeds.
  441. // Unfortunately, Videobridge will be unable to respond immediately because
  442. // may not have WebRTC's answer or may have not completed the ICE
  443. // connectivity establishment. Even more unfortunate is that in the
  444. // described scenario Chrome's DTLS implementation will insist on
  445. // retransmitting its ClientHello after a second (the time is in accord
  446. // with the respective RFC) and will thus cause the whole connection
  447. // establishment to exceed at least 1 second. To work around Chrome's
  448. // idiosyncracy, don't allow it to send a ClientHello i.e. change its
  449. // default choice of setup:active to setup:passive.
  450. if (offer && answer
  451. && offer.media && answer.media
  452. && offer.media.length == answer.media.length) {
  453. answer.media.forEach(function (a, i) {
  454. if (SDPUtil.find_line(
  455. offer.media[i],
  456. 'a=setup:actpass',
  457. offer.session)) {
  458. answer.media[i]
  459. = a.replace(/a=setup:active/g, 'a=setup:passive');
  460. }
  461. });
  462. answer.raw = answer.session + answer.media.join('');
  463. }
  464. };
  465. TraceablePeerConnection.prototype.createAnswer
  466. = function (successCallback, failureCallback, constraints) {
  467. this.trace('createAnswer', JSON.stringify(constraints, null, ' '));
  468. this.peerconnection.createAnswer(
  469. (answer) => {
  470. try {
  471. this.trace(
  472. 'createAnswerOnSuccess::preTransform', dumpSDP(answer));
  473. // if we're running on FF, transform to Plan A first.
  474. if (RTCBrowserType.usesUnifiedPlan()) {
  475. answer = this.interop.toPlanB(answer);
  476. this.trace('createAnswerOnSuccess::postTransform (Plan B)',
  477. dumpSDP(answer));
  478. }
  479. /**
  480. * We don't keep ssrcs consitent for Firefox because rewriting
  481. * the ssrcs between createAnswer and setLocalDescription
  482. * breaks the caching in sdp-interop (sdp-interop must
  483. * know about all ssrcs, and it updates its cache in
  484. * toPlanB so if we rewrite them after that, when we
  485. * try and go back to unified plan it will complain
  486. * about unmapped ssrcs)
  487. */
  488. if (!RTCBrowserType.isFirefox()) {
  489. answer.sdp = this.sdpConsistency.makeVideoPrimarySsrcsConsistent(answer.sdp);
  490. this.trace('createAnswerOnSuccess::postTransform (make primary video ssrcs consistent)',
  491. dumpSDP(answer));
  492. }
  493. // Add simulcast streams if simulcast is enabled
  494. if (!this.session.room.options.disableSimulcast
  495. && this.simulcast.isSupported()) {
  496. answer = this.simulcast.mungeLocalDescription(answer);
  497. this.trace(
  498. 'createAnswerOnSuccess::postTransform (simulcast)',
  499. dumpSDP(answer));
  500. }
  501. if (!this.session.room.options.disableRtx) {
  502. answer.sdp = this.rtxModifier.modifyRtxSsrcs(answer.sdp);
  503. this.trace(
  504. 'createAnswerOnSuccess::postTransform (rtx modifier)',
  505. dumpSDP(answer));
  506. }
  507. // Fix the setup attribute (see _fixAnswerRFC4145Setup for
  508. // details)
  509. let remoteDescription = new SDP(this.remoteDescription.sdp);
  510. let localDescription = new SDP(answer.sdp);
  511. _fixAnswerRFC4145Setup(remoteDescription, localDescription);
  512. answer.sdp = localDescription.raw;
  513. this.eventEmitter.emit(XMPPEvents.SENDRECV_STREAMS_CHANGED,
  514. extractSSRCMap(answer));
  515. successCallback(answer);
  516. } catch (e) {
  517. this.trace('createAnswerOnError', e);
  518. this.trace('createAnswerOnError', dumpSDP(answer));
  519. logger.error('createAnswerOnError', e, dumpSDP(answer));
  520. failureCallback(e);
  521. }
  522. },
  523. (err) => {
  524. this.trace('createAnswerOnFailure', err);
  525. this.eventEmitter.emit(XMPPEvents.CREATE_ANSWER_FAILED, err,
  526. this.peerconnection);
  527. failureCallback(err);
  528. },
  529. constraints
  530. );
  531. };
  532. TraceablePeerConnection.prototype.addIceCandidate
  533. // eslint-disable-next-line no-unused-vars
  534. = function (candidate, successCallback, failureCallback) {
  535. //var self = this;
  536. this.trace('addIceCandidate', JSON.stringify(candidate, null, ' '));
  537. this.peerconnection.addIceCandidate(candidate);
  538. /* maybe later
  539. this.peerconnection.addIceCandidate(candidate,
  540. function () {
  541. self.trace('addIceCandidateOnSuccess');
  542. successCallback();
  543. },
  544. function (err) {
  545. self.trace('addIceCandidateOnFailure', err);
  546. failureCallback(err);
  547. }
  548. );
  549. */
  550. };
  551. TraceablePeerConnection.prototype.getStats = function(callback, errback) {
  552. // TODO: Is this the correct way to handle Opera, Temasys?
  553. if (RTCBrowserType.isFirefox()
  554. || RTCBrowserType.isTemasysPluginUsed()
  555. || RTCBrowserType.isReactNative()) {
  556. // ignore for now...
  557. if(!errback)
  558. errback = function () {};
  559. this.peerconnection.getStats(null, callback, errback);
  560. } else {
  561. this.peerconnection.getStats(callback);
  562. }
  563. };
  564. /**
  565. * Generate ssrc info object for a stream with the following properties:
  566. * - ssrcs - Array of the ssrcs associated with the stream.
  567. * - groups - Array of the groups associated with the stream.
  568. */
  569. TraceablePeerConnection.prototype.generateNewStreamSSRCInfo = function () {
  570. let ssrcInfo = {ssrcs: [], groups: []};
  571. if (!this.session.room.options.disableSimulcast
  572. && this.simulcast.isSupported()) {
  573. for (let i = 0; i < SIMULCAST_LAYERS; i++) {
  574. ssrcInfo.ssrcs.push(SDPUtil.generateSsrc());
  575. }
  576. ssrcInfo.groups.push({
  577. primarySSRC: ssrcInfo.ssrcs[0],
  578. group: {ssrcs: ssrcInfo.ssrcs.join(" "), semantics: "SIM"}});
  579. ssrcInfo;
  580. } else {
  581. ssrcInfo = {ssrcs: [SDPUtil.generateSsrc()], groups: []};
  582. }
  583. if (!this.session.room.options.disableRtx) {
  584. // Specifically use a for loop here because we'll
  585. // be adding to the list we're iterating over, so we
  586. // only want to iterate through the items originally
  587. // on the list
  588. const currNumSsrcs = ssrcInfo.ssrcs.length;
  589. for (let i = 0; i < currNumSsrcs; ++i) {
  590. const primarySsrc = ssrcInfo.ssrcs[i];
  591. const rtxSsrc = SDPUtil.generateSsrc();
  592. ssrcInfo.ssrcs.push(rtxSsrc);
  593. ssrcInfo.groups.push({
  594. primarySSRC: primarySsrc,
  595. group: {
  596. ssrcs: primarySsrc + " " + rtxSsrc,
  597. semantics: "FID"
  598. }
  599. });
  600. }
  601. }
  602. return ssrcInfo;
  603. };
  604. module.exports = TraceablePeerConnection;