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.

RTPStatsCollector.js 44KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360
  1. import { browsers } from '@jitsi/js-utils';
  2. import { getLogger } from 'jitsi-meet-logger';
  3. import * as MediaType from '../../service/RTC/MediaType';
  4. import * as StatisticsEvents from '../../service/statistics/Events';
  5. import browser from '../browser';
  6. const GlobalOnErrorHandler = require('../util/GlobalOnErrorHandler');
  7. const logger = getLogger(__filename);
  8. /**
  9. * The lib-jitsi-meet browser-agnostic names of the browser-specific keys
  10. * reported by RTCPeerConnection#getStats mapped by browser.
  11. */
  12. const KEYS_BY_BROWSER_TYPE = {};
  13. KEYS_BY_BROWSER_TYPE[browsers.FIREFOX] = {
  14. 'ssrc': 'ssrc',
  15. 'packetsReceived': 'packetsReceived',
  16. 'packetsLost': 'packetsLost',
  17. 'packetsSent': 'packetsSent',
  18. 'bytesReceived': 'bytesReceived',
  19. 'bytesSent': 'bytesSent',
  20. 'framerateMean': 'framerateMean',
  21. 'ip': 'address',
  22. 'port': 'port',
  23. 'protocol': 'protocol'
  24. };
  25. KEYS_BY_BROWSER_TYPE[browsers.CHROME] = {
  26. 'receiveBandwidth': 'googAvailableReceiveBandwidth',
  27. 'sendBandwidth': 'googAvailableSendBandwidth',
  28. 'remoteAddress': 'googRemoteAddress',
  29. 'transportType': 'googTransportType',
  30. 'localAddress': 'googLocalAddress',
  31. 'activeConnection': 'googActiveConnection',
  32. 'ssrc': 'ssrc',
  33. 'packetsReceived': 'packetsReceived',
  34. 'packetsSent': 'packetsSent',
  35. 'packetsLost': 'packetsLost',
  36. 'bytesReceived': 'bytesReceived',
  37. 'bytesSent': 'bytesSent',
  38. 'googCodecName': 'googCodecName',
  39. 'googFrameHeightReceived': 'googFrameHeightReceived',
  40. 'googFrameWidthReceived': 'googFrameWidthReceived',
  41. 'googFrameHeightSent': 'googFrameHeightSent',
  42. 'googFrameWidthSent': 'googFrameWidthSent',
  43. 'googFrameRateReceived': 'googFrameRateReceived',
  44. 'googFrameRateSent': 'googFrameRateSent',
  45. 'audioInputLevel': 'audioInputLevel',
  46. 'audioOutputLevel': 'audioOutputLevel',
  47. 'currentRoundTripTime': 'googRtt',
  48. 'remoteCandidateType': 'googRemoteCandidateType',
  49. 'localCandidateType': 'googLocalCandidateType',
  50. 'ip': 'ip',
  51. 'port': 'port',
  52. 'protocol': 'protocol'
  53. };
  54. KEYS_BY_BROWSER_TYPE[browsers.REACT_NATIVE] = {
  55. 'packetsReceived': 'packetsReceived',
  56. 'packetsSent': 'packetsSent',
  57. 'bytesReceived': 'bytesReceived',
  58. 'bytesSent': 'bytesSent',
  59. 'frameWidth': 'frameWidth',
  60. 'frameHeight': 'frameHeight',
  61. 'framesPerSecond': 'framesPerSecond',
  62. 'ip': 'ip',
  63. 'port': 'port',
  64. 'protocol': 'protocol'
  65. };
  66. KEYS_BY_BROWSER_TYPE[browsers.OPERA]
  67. = KEYS_BY_BROWSER_TYPE[browsers.CHROME];
  68. KEYS_BY_BROWSER_TYPE[browsers.NWJS]
  69. = KEYS_BY_BROWSER_TYPE[browsers.CHROME];
  70. KEYS_BY_BROWSER_TYPE[browsers.ELECTRON]
  71. = KEYS_BY_BROWSER_TYPE[browsers.CHROME];
  72. KEYS_BY_BROWSER_TYPE[browsers.SAFARI]
  73. = KEYS_BY_BROWSER_TYPE[browsers.CHROME];
  74. /**
  75. * Calculates packet lost percent using the number of lost packets and the
  76. * number of all packet.
  77. * @param lostPackets the number of lost packets
  78. * @param totalPackets the number of all packets.
  79. * @returns {number} packet loss percent
  80. */
  81. function calculatePacketLoss(lostPackets, totalPackets) {
  82. if (!totalPackets || totalPackets <= 0
  83. || !lostPackets || lostPackets <= 0) {
  84. return 0;
  85. }
  86. return Math.round((lostPackets / totalPackets) * 100);
  87. }
  88. /**
  89. * Holds "statistics" for a single SSRC.
  90. * @constructor
  91. */
  92. function SsrcStats() {
  93. this.loss = {};
  94. this.bitrate = {
  95. download: 0,
  96. upload: 0
  97. };
  98. this.resolution = {};
  99. this.framerate = 0;
  100. this.codec = '';
  101. }
  102. /**
  103. * Sets the "loss" object.
  104. * @param loss the value to set.
  105. */
  106. SsrcStats.prototype.setLoss = function(loss) {
  107. this.loss = loss || {};
  108. };
  109. /**
  110. * Sets resolution that belong to the ssrc represented by this instance.
  111. * @param resolution new resolution value to be set.
  112. */
  113. SsrcStats.prototype.setResolution = function(resolution) {
  114. this.resolution = resolution || {};
  115. };
  116. /**
  117. * Adds the "download" and "upload" fields from the "bitrate" parameter to
  118. * the respective fields of the "bitrate" field of this object.
  119. * @param bitrate an object holding the values to add.
  120. */
  121. SsrcStats.prototype.addBitrate = function(bitrate) {
  122. this.bitrate.download += bitrate.download;
  123. this.bitrate.upload += bitrate.upload;
  124. };
  125. /**
  126. * Resets the bit rate for given <tt>ssrc</tt> that belong to the peer
  127. * represented by this instance.
  128. */
  129. SsrcStats.prototype.resetBitrate = function() {
  130. this.bitrate.download = 0;
  131. this.bitrate.upload = 0;
  132. };
  133. /**
  134. * Sets the "framerate".
  135. * @param framerate the value to set.
  136. */
  137. SsrcStats.prototype.setFramerate = function(framerate) {
  138. this.framerate = framerate || 0;
  139. };
  140. SsrcStats.prototype.setCodec = function(codec) {
  141. this.codec = codec || '';
  142. };
  143. /**
  144. *
  145. */
  146. function ConferenceStats() {
  147. /**
  148. * The bandwidth
  149. * @type {{}}
  150. */
  151. this.bandwidth = {};
  152. /**
  153. * The bit rate
  154. * @type {{}}
  155. */
  156. this.bitrate = {};
  157. /**
  158. * The packet loss rate
  159. * @type {{}}
  160. */
  161. this.packetLoss = null;
  162. /**
  163. * Array with the transport information.
  164. * @type {Array}
  165. */
  166. this.transport = [];
  167. }
  168. /* eslint-disable max-params */
  169. /**
  170. * <tt>StatsCollector</tt> registers for stats updates of given
  171. * <tt>peerconnection</tt> in given <tt>interval</tt>. On each update particular
  172. * stats are extracted and put in {@link SsrcStats} objects. Once the processing
  173. * is done <tt>audioLevelsUpdateCallback</tt> is called with <tt>this</tt>
  174. * instance as an event source.
  175. *
  176. * @param peerconnection WebRTC PeerConnection object.
  177. * @param audioLevelsInterval
  178. * @param statsInterval stats refresh interval given in ms.
  179. * @param eventEmitter
  180. * @constructor
  181. */
  182. export default function StatsCollector(
  183. peerconnection,
  184. audioLevelsInterval,
  185. statsInterval,
  186. eventEmitter) {
  187. // StatsCollector depends entirely on the format of the reports returned by
  188. // RTCPeerConnection#getStats. Given that the value of
  189. // browser#getName() is very unlikely to change at runtime, it
  190. // makes sense to discover whether StatsCollector supports the executing
  191. // browser as soon as possible. Otherwise, (1) getStatValue would have to
  192. // needlessly check a "static" condition multiple times very very often and
  193. // (2) the lack of support for the executing browser would be discovered and
  194. // reported multiple times very very often too late in the execution in some
  195. // totally unrelated callback.
  196. /**
  197. * The browser type supported by this StatsCollector. In other words, the
  198. * type of the browser which initialized this StatsCollector
  199. * instance.
  200. * @private
  201. */
  202. this._browserType = browser.getName();
  203. const keys = KEYS_BY_BROWSER_TYPE[this._browserType];
  204. if (!keys) {
  205. throw new Error(`The browser type '${this._browserType}' isn't supported!`);
  206. }
  207. /**
  208. * Whether to use the Promise-based getStats API or not.
  209. * @type {boolean}
  210. */
  211. this._usesPromiseGetStats
  212. = browser.isWebKitBased() || browser.isFirefox() || browser.isReactNative();
  213. /**
  214. * The function which is to be used to retrieve the value associated in a
  215. * report returned by RTCPeerConnection#getStats with a lib-jitsi-meet
  216. * browser-agnostic name/key.
  217. *
  218. * @function
  219. * @private
  220. */
  221. this._getStatValue
  222. = this._usesPromiseGetStats
  223. ? this._defineNewGetStatValueMethod(keys)
  224. : this._defineGetStatValueMethod(keys);
  225. this.peerconnection = peerconnection;
  226. this.baselineAudioLevelsReport = null;
  227. this.currentAudioLevelsReport = null;
  228. this.currentStatsReport = null;
  229. this.previousStatsReport = null;
  230. this.audioLevelReportHistory = {};
  231. this.audioLevelsIntervalId = null;
  232. this.eventEmitter = eventEmitter;
  233. this.conferenceStats = new ConferenceStats();
  234. // Updates stats interval
  235. this.audioLevelsIntervalMilis = audioLevelsInterval;
  236. this.statsIntervalId = null;
  237. this.statsIntervalMilis = statsInterval;
  238. /**
  239. * Maps SSRC numbers to {@link SsrcStats}.
  240. * @type {Map<number,SsrcStats}
  241. */
  242. this.ssrc2stats = new Map();
  243. }
  244. /* eslint-enable max-params */
  245. /**
  246. * Stops stats updates.
  247. */
  248. StatsCollector.prototype.stop = function() {
  249. if (this.audioLevelsIntervalId) {
  250. clearInterval(this.audioLevelsIntervalId);
  251. this.audioLevelsIntervalId = null;
  252. }
  253. if (this.statsIntervalId) {
  254. clearInterval(this.statsIntervalId);
  255. this.statsIntervalId = null;
  256. }
  257. };
  258. /**
  259. * Callback passed to <tt>getStats</tt> method.
  260. * @param error an error that occurred on <tt>getStats</tt> call.
  261. */
  262. StatsCollector.prototype.errorCallback = function(error) {
  263. GlobalOnErrorHandler.callErrorHandler(error);
  264. logger.error('Get stats error', error);
  265. this.stop();
  266. };
  267. /**
  268. * Starts stats updates.
  269. */
  270. StatsCollector.prototype.start = function(startAudioLevelStats) {
  271. if (startAudioLevelStats) {
  272. if (browser.supportsReceiverStats()) {
  273. logger.info('Using RTCRtpSynchronizationSource for remote audio levels');
  274. }
  275. this.audioLevelsIntervalId = setInterval(
  276. () => {
  277. if (browser.supportsReceiverStats()) {
  278. const audioLevels = this.peerconnection.getAudioLevels();
  279. for (const ssrc in audioLevels) {
  280. if (audioLevels.hasOwnProperty(ssrc)) {
  281. // Use a scaling factor of 2.5 to report the same
  282. // audio levels that getStats reports.
  283. const audioLevel = audioLevels[ssrc] * 2.5;
  284. this.eventEmitter.emit(
  285. StatisticsEvents.AUDIO_LEVEL,
  286. this.peerconnection,
  287. Number.parseInt(ssrc, 10),
  288. audioLevel,
  289. false /* isLocal */);
  290. }
  291. }
  292. } else {
  293. // Interval updates
  294. this.peerconnection.getStats(
  295. report => {
  296. let results = null;
  297. if (!report || !report.result
  298. || typeof report.result !== 'function') {
  299. results = report;
  300. } else {
  301. results = report.result();
  302. }
  303. this.currentAudioLevelsReport = results;
  304. if (this._usesPromiseGetStats) {
  305. this.processNewAudioLevelReport();
  306. } else {
  307. this.processAudioLevelReport();
  308. }
  309. this.baselineAudioLevelsReport
  310. = this.currentAudioLevelsReport;
  311. },
  312. error => this.errorCallback(error)
  313. );
  314. }
  315. },
  316. this.audioLevelsIntervalMilis
  317. );
  318. }
  319. this.statsIntervalId = setInterval(
  320. () => {
  321. // Interval updates
  322. this.peerconnection.getStats(
  323. report => {
  324. let results = null;
  325. if (!report || !report.result
  326. || typeof report.result !== 'function') {
  327. // firefox
  328. results = report;
  329. } else {
  330. // chrome
  331. results = report.result();
  332. }
  333. this.currentStatsReport = results;
  334. try {
  335. if (this._usesPromiseGetStats) {
  336. this.processNewStatsReport();
  337. } else {
  338. this.processStatsReport();
  339. }
  340. } catch (e) {
  341. GlobalOnErrorHandler.callErrorHandler(e);
  342. logger.error(`Unsupported key:${e}`, e);
  343. }
  344. this.previousStatsReport = this.currentStatsReport;
  345. },
  346. error => this.errorCallback(error)
  347. );
  348. },
  349. this.statsIntervalMilis
  350. );
  351. };
  352. /**
  353. * Defines a function which (1) is to be used as a StatsCollector method and (2)
  354. * gets the value from a specific report returned by RTCPeerConnection#getStats
  355. * associated with a lib-jitsi-meet browser-agnostic name.
  356. *
  357. * @param {Object.<string,string>} keys the map of LibJitsi browser-agnostic
  358. * names to RTCPeerConnection#getStats browser-specific keys
  359. */
  360. StatsCollector.prototype._defineGetStatValueMethod = function(keys) {
  361. // Define the function which converts a lib-jitsi-meet browser-asnostic name
  362. // to a browser-specific key of a report returned by
  363. // RTCPeerConnection#getStats.
  364. const keyFromName = function(name) {
  365. const key = keys[name];
  366. if (key) {
  367. return key;
  368. }
  369. throw new Error(`The property '${name}' isn't supported!`);
  370. };
  371. // Define the function which retrieves the value from a specific report
  372. // returned by RTCPeerConnection#getStats associated with a given
  373. // browser-specific key.
  374. let itemStatByKey;
  375. switch (this._browserType) {
  376. case browsers.CHROME:
  377. case browsers.OPERA:
  378. case browsers.NWJS:
  379. case browsers.ELECTRON:
  380. // TODO What about other types of browser which are based on Chrome such
  381. // as NW.js? Every time we want to support a new type browser we have to
  382. // go and add more conditions (here and in multiple other places).
  383. // Cannot we do a feature detection instead of a browser type check? For
  384. // example, if item has a stat property of type function, then it's very
  385. // likely that whoever defined it wanted you to call it in order to
  386. // retrieve the value associated with a specific key.
  387. itemStatByKey = (item, key) => item.stat(key);
  388. break;
  389. default:
  390. itemStatByKey = (item, key) => item[key];
  391. }
  392. // Compose the 2 functions defined above to get a function which retrieves
  393. // the value from a specific report returned by RTCPeerConnection#getStats
  394. // associated with a specific lib-jitsi-meet browser-agnostic name.
  395. return (item, name) => itemStatByKey(item, keyFromName(name));
  396. };
  397. /**
  398. * Obtains a stat value from given stat and converts it to a non-negative
  399. * number. If the value is either invalid or negative then 0 will be returned.
  400. * @param report
  401. * @param {string} name
  402. * @return {number}
  403. * @private
  404. */
  405. StatsCollector.prototype.getNonNegativeStat = function(report, name) {
  406. let value = this._getStatValue(report, name);
  407. if (typeof value !== 'number') {
  408. value = Number(value);
  409. }
  410. if (isNaN(value)) {
  411. return 0;
  412. }
  413. return Math.max(0, value);
  414. };
  415. /* eslint-disable no-continue */
  416. /**
  417. * Stats processing logic.
  418. */
  419. StatsCollector.prototype.processStatsReport = function() {
  420. if (!this.previousStatsReport) {
  421. return;
  422. }
  423. const getStatValue = this._getStatValue;
  424. const byteSentStats = {};
  425. for (const idx in this.currentStatsReport) {
  426. if (!this.currentStatsReport.hasOwnProperty(idx)) {
  427. continue;
  428. }
  429. const now = this.currentStatsReport[idx];
  430. // The browser API may return "undefined" values in the array
  431. if (!now) {
  432. continue;
  433. }
  434. try {
  435. const receiveBandwidth = getStatValue(now, 'receiveBandwidth');
  436. const sendBandwidth = getStatValue(now, 'sendBandwidth');
  437. if (receiveBandwidth || sendBandwidth) {
  438. this.conferenceStats.bandwidth = {
  439. 'download': Math.round(receiveBandwidth / 1000),
  440. 'upload': Math.round(sendBandwidth / 1000)
  441. };
  442. }
  443. } catch (e) { /* not supported*/ }
  444. if (now.type === 'googCandidatePair') {
  445. let active, ip, localCandidateType, localip,
  446. remoteCandidateType, rtt, type;
  447. try {
  448. active = getStatValue(now, 'activeConnection');
  449. if (!active) {
  450. continue;
  451. }
  452. ip = getStatValue(now, 'remoteAddress');
  453. type = getStatValue(now, 'transportType');
  454. localip = getStatValue(now, 'localAddress');
  455. localCandidateType = getStatValue(now, 'localCandidateType');
  456. remoteCandidateType = getStatValue(now, 'remoteCandidateType');
  457. rtt = this.getNonNegativeStat(now, 'currentRoundTripTime');
  458. } catch (e) { /* not supported*/ }
  459. if (!ip || !type || !localip || active !== 'true') {
  460. continue;
  461. }
  462. // Save the address unless it has been saved already.
  463. const conferenceStatsTransport = this.conferenceStats.transport;
  464. if (!conferenceStatsTransport.some(
  465. t =>
  466. t.ip === ip
  467. && t.type === type
  468. && t.localip === localip)) {
  469. conferenceStatsTransport.push({
  470. ip,
  471. type,
  472. localip,
  473. p2p: this.peerconnection.isP2P,
  474. localCandidateType,
  475. remoteCandidateType,
  476. rtt
  477. });
  478. }
  479. continue;
  480. }
  481. if (now.type === 'candidatepair') {
  482. // we need succeeded and selected pairs only
  483. if (now.state !== 'succeeded' || !now.selected) {
  484. continue;
  485. }
  486. const local = this.currentStatsReport[now.localCandidateId];
  487. const remote = this.currentStatsReport[now.remoteCandidateId];
  488. this.conferenceStats.transport.push({
  489. ip: `${remote.ipAddress}:${remote.portNumber}`,
  490. type: local.transport,
  491. localip: `${local.ipAddress}:${local.portNumber}`,
  492. p2p: this.peerconnection.isP2P,
  493. localCandidateType: local.candidateType,
  494. remoteCandidateType: remote.candidateType
  495. });
  496. }
  497. if (now.type !== 'ssrc' && now.type !== 'outboundrtp'
  498. && now.type !== 'inboundrtp' && now.type !== 'track') {
  499. continue;
  500. }
  501. const before = this.previousStatsReport[idx];
  502. let ssrc = this.getNonNegativeStat(now, 'ssrc');
  503. // If type="track", take the first SSRC from ssrcIds.
  504. if (now.type === 'track' && Array.isArray(now.ssrcIds)) {
  505. ssrc = Number(now.ssrcIds[0]);
  506. }
  507. if (!before || !ssrc) {
  508. continue;
  509. }
  510. // isRemote is available only in FF and is ignored in case of chrome
  511. // according to the spec
  512. // https://www.w3.org/TR/webrtc-stats/#dom-rtcrtpstreamstats-isremote
  513. // when isRemote is true indicates that the measurements were done at
  514. // the remote endpoint and reported in an RTCP RR/XR.
  515. // Fixes a problem where we are calculating local stats wrong adding
  516. // the sent bytes to the local download bitrate.
  517. // In new W3 stats spec, type="track" has a remoteSource boolean
  518. // property.
  519. if (now.isRemote === true || now.remoteSource === true) {
  520. continue;
  521. }
  522. let ssrcStats = this.ssrc2stats.get(ssrc);
  523. if (!ssrcStats) {
  524. ssrcStats = new SsrcStats();
  525. this.ssrc2stats.set(ssrc, ssrcStats);
  526. }
  527. let isDownloadStream = true;
  528. let key = 'packetsReceived';
  529. let packetsNow = getStatValue(now, key);
  530. if (typeof packetsNow === 'undefined'
  531. || packetsNow === null || packetsNow === '') {
  532. isDownloadStream = false;
  533. key = 'packetsSent';
  534. packetsNow = getStatValue(now, key);
  535. if (typeof packetsNow === 'undefined' || packetsNow === null) {
  536. logger.warn('No packetsReceived nor packetsSent stat found');
  537. }
  538. }
  539. if (!packetsNow || packetsNow < 0) {
  540. packetsNow = 0;
  541. }
  542. const packetsBefore = this.getNonNegativeStat(before, key);
  543. const packetsDiff = Math.max(0, packetsNow - packetsBefore);
  544. const packetsLostNow
  545. = this.getNonNegativeStat(now, 'packetsLost');
  546. const packetsLostBefore
  547. = this.getNonNegativeStat(before, 'packetsLost');
  548. const packetsLostDiff = Math.max(0, packetsLostNow - packetsLostBefore);
  549. ssrcStats.setLoss({
  550. packetsTotal: packetsDiff + packetsLostDiff,
  551. packetsLost: packetsLostDiff,
  552. isDownloadStream
  553. });
  554. const bytesReceivedNow
  555. = this.getNonNegativeStat(now, 'bytesReceived');
  556. const bytesReceivedBefore
  557. = this.getNonNegativeStat(before, 'bytesReceived');
  558. const bytesReceived
  559. = Math.max(0, bytesReceivedNow - bytesReceivedBefore);
  560. let bytesSent = 0;
  561. // TODO: clean this mess up!
  562. let nowBytesTransmitted = getStatValue(now, 'bytesSent');
  563. if (typeof nowBytesTransmitted === 'number'
  564. || typeof nowBytesTransmitted === 'string') {
  565. nowBytesTransmitted = Number(nowBytesTransmitted);
  566. if (!isNaN(nowBytesTransmitted)) {
  567. byteSentStats[ssrc] = nowBytesTransmitted;
  568. if (nowBytesTransmitted > 0) {
  569. bytesSent = nowBytesTransmitted
  570. - getStatValue(before, 'bytesSent');
  571. }
  572. }
  573. }
  574. bytesSent = Math.max(0, bytesSent);
  575. const timeMs = now.timestamp - before.timestamp;
  576. let bitrateReceivedKbps = 0, bitrateSentKbps = 0;
  577. if (timeMs > 0) {
  578. // TODO is there any reason to round here?
  579. bitrateReceivedKbps = Math.round((bytesReceived * 8) / timeMs);
  580. bitrateSentKbps = Math.round((bytesSent * 8) / timeMs);
  581. }
  582. ssrcStats.addBitrate({
  583. 'download': bitrateReceivedKbps,
  584. 'upload': bitrateSentKbps
  585. });
  586. const resolution = {
  587. height: null,
  588. width: null
  589. };
  590. try {
  591. let height, width;
  592. if ((height = getStatValue(now, 'googFrameHeightReceived'))
  593. && (width = getStatValue(now, 'googFrameWidthReceived'))) {
  594. resolution.height = height;
  595. resolution.width = width;
  596. } else if ((height = getStatValue(now, 'googFrameHeightSent'))
  597. && (width = getStatValue(now, 'googFrameWidthSent'))) {
  598. resolution.height = height;
  599. resolution.width = width;
  600. }
  601. } catch (e) { /* not supported*/ }
  602. // Tries to get frame rate
  603. let frameRate;
  604. try {
  605. frameRate = getStatValue(now, 'googFrameRateReceived')
  606. || getStatValue(now, 'googFrameRateSent') || 0;
  607. } catch (e) {
  608. // if it fails with previous properties(chrome),
  609. // let's try with another one (FF)
  610. try {
  611. frameRate = this.getNonNegativeStat(now, 'framerateMean');
  612. } catch (err) { /* not supported*/ }
  613. }
  614. ssrcStats.setFramerate(Math.round(frameRate || 0));
  615. if (resolution.height && resolution.width) {
  616. ssrcStats.setResolution(resolution);
  617. } else {
  618. ssrcStats.setResolution(null);
  619. }
  620. let codec;
  621. // Try to get the codec for later reporting.
  622. try {
  623. codec = getStatValue(now, 'googCodecName') || '';
  624. } catch (e) { /* not supported*/ }
  625. ssrcStats.setCodec(codec);
  626. }
  627. this.eventEmitter.emit(
  628. StatisticsEvents.BYTE_SENT_STATS, this.peerconnection, byteSentStats);
  629. this._processAndEmitReport();
  630. };
  631. /**
  632. *
  633. */
  634. StatsCollector.prototype._processAndEmitReport = function() {
  635. // process stats
  636. const totalPackets = {
  637. download: 0,
  638. upload: 0
  639. };
  640. const lostPackets = {
  641. download: 0,
  642. upload: 0
  643. };
  644. let bitrateDownload = 0;
  645. let bitrateUpload = 0;
  646. const resolutions = {};
  647. const framerates = {};
  648. const codecs = {};
  649. let audioBitrateDownload = 0;
  650. let audioBitrateUpload = 0;
  651. let audioCodec;
  652. let videoBitrateDownload = 0;
  653. let videoBitrateUpload = 0;
  654. let videoCodec;
  655. for (const [ ssrc, ssrcStats ] of this.ssrc2stats) {
  656. // process packet loss stats
  657. const loss = ssrcStats.loss;
  658. const type = loss.isDownloadStream ? 'download' : 'upload';
  659. totalPackets[type] += loss.packetsTotal;
  660. lostPackets[type] += loss.packetsLost;
  661. // process bitrate stats
  662. bitrateDownload += ssrcStats.bitrate.download;
  663. bitrateUpload += ssrcStats.bitrate.upload;
  664. // collect resolutions and framerates
  665. const track = this.peerconnection.getTrackBySSRC(ssrc);
  666. if (track) {
  667. if (track.isAudioTrack()) {
  668. audioBitrateDownload += ssrcStats.bitrate.download;
  669. audioBitrateUpload += ssrcStats.bitrate.upload;
  670. audioCodec = ssrcStats.codec;
  671. } else {
  672. videoBitrateDownload += ssrcStats.bitrate.download;
  673. videoBitrateUpload += ssrcStats.bitrate.upload;
  674. videoCodec = ssrcStats.codec;
  675. }
  676. const participantId = track.getParticipantId();
  677. if (participantId) {
  678. const resolution = ssrcStats.resolution;
  679. if (resolution.width
  680. && resolution.height
  681. && resolution.width !== -1
  682. && resolution.height !== -1) {
  683. const userResolutions = resolutions[participantId] || {};
  684. userResolutions[ssrc] = resolution;
  685. resolutions[participantId] = userResolutions;
  686. }
  687. if (ssrcStats.framerate !== 0) {
  688. const userFramerates = framerates[participantId] || {};
  689. userFramerates[ssrc] = ssrcStats.framerate;
  690. framerates[participantId] = userFramerates;
  691. }
  692. if (audioCodec && videoCodec) {
  693. const codecDesc = {
  694. 'audio': audioCodec,
  695. 'video': videoCodec
  696. };
  697. const userCodecs = codecs[participantId] || {};
  698. userCodecs[ssrc] = codecDesc;
  699. codecs[participantId] = userCodecs;
  700. }
  701. } else {
  702. logger.error(`No participant ID returned by ${track}`);
  703. }
  704. }
  705. ssrcStats.resetBitrate();
  706. }
  707. this.conferenceStats.bitrate = {
  708. 'upload': bitrateUpload,
  709. 'download': bitrateDownload
  710. };
  711. this.conferenceStats.bitrate.audio = {
  712. 'upload': audioBitrateUpload,
  713. 'download': audioBitrateDownload
  714. };
  715. this.conferenceStats.bitrate.video = {
  716. 'upload': videoBitrateUpload,
  717. 'download': videoBitrateDownload
  718. };
  719. this.conferenceStats.packetLoss = {
  720. total:
  721. calculatePacketLoss(
  722. lostPackets.download + lostPackets.upload,
  723. totalPackets.download + totalPackets.upload),
  724. download:
  725. calculatePacketLoss(lostPackets.download, totalPackets.download),
  726. upload:
  727. calculatePacketLoss(lostPackets.upload, totalPackets.upload)
  728. };
  729. const avgAudioLevels = {};
  730. let localAvgAudioLevels;
  731. Object.keys(this.audioLevelReportHistory).forEach(ssrc => {
  732. const { data, isLocal } = this.audioLevelReportHistory[ssrc];
  733. const avgAudioLevel = data.reduce((sum, currentValue) => sum + currentValue) / data.length;
  734. if (isLocal) {
  735. localAvgAudioLevels = avgAudioLevel;
  736. } else {
  737. const track = this.peerconnection.getTrackBySSRC(Number(ssrc));
  738. if (track) {
  739. const participantId = track.getParticipantId();
  740. if (participantId) {
  741. avgAudioLevels[participantId] = avgAudioLevel;
  742. }
  743. }
  744. }
  745. });
  746. this.audioLevelReportHistory = {};
  747. this.eventEmitter.emit(
  748. StatisticsEvents.CONNECTION_STATS,
  749. this.peerconnection,
  750. {
  751. 'bandwidth': this.conferenceStats.bandwidth,
  752. 'bitrate': this.conferenceStats.bitrate,
  753. 'packetLoss': this.conferenceStats.packetLoss,
  754. 'resolution': resolutions,
  755. 'framerate': framerates,
  756. 'codec': codecs,
  757. 'transport': this.conferenceStats.transport,
  758. localAvgAudioLevels,
  759. avgAudioLevels
  760. });
  761. this.conferenceStats.transport = [];
  762. };
  763. /**
  764. * Stats processing logic.
  765. */
  766. StatsCollector.prototype.processAudioLevelReport = function() {
  767. if (!this.baselineAudioLevelsReport) {
  768. return;
  769. }
  770. const getStatValue = this._getStatValue;
  771. for (const idx in this.currentAudioLevelsReport) {
  772. if (!this.currentAudioLevelsReport.hasOwnProperty(idx)) {
  773. continue;
  774. }
  775. const now = this.currentAudioLevelsReport[idx];
  776. if (now.type !== 'ssrc' && now.type !== 'track') {
  777. continue;
  778. }
  779. const before = this.baselineAudioLevelsReport[idx];
  780. let ssrc = this.getNonNegativeStat(now, 'ssrc');
  781. if (!ssrc && Array.isArray(now.ssrcIds)) {
  782. ssrc = Number(now.ssrcIds[0]);
  783. }
  784. if (!before) {
  785. logger.warn(`${ssrc} not enough data`);
  786. continue;
  787. }
  788. if (!ssrc) {
  789. if ((Date.now() - now.timestamp) < 3000) {
  790. logger.warn('No ssrc: ');
  791. }
  792. continue;
  793. }
  794. // Audio level
  795. let audioLevel;
  796. try {
  797. audioLevel
  798. = getStatValue(now, 'audioInputLevel')
  799. || getStatValue(now, 'audioOutputLevel');
  800. } catch (e) { /* not supported*/
  801. logger.warn('Audio Levels are not available in the statistics.');
  802. clearInterval(this.audioLevelsIntervalId);
  803. return;
  804. }
  805. if (audioLevel) {
  806. let isLocal;
  807. // If type="ssrc" (legacy) check whether they are received packets.
  808. if (now.type === 'ssrc') {
  809. isLocal = !getStatValue(now, 'packetsReceived');
  810. // If type="track", check remoteSource boolean property.
  811. } else {
  812. isLocal = !now.remoteSource;
  813. }
  814. // According to the W3C WebRTC Stats spec, audioLevel should be in
  815. // 0..1 range (0 == silence). However browsers don't behave that
  816. // way so we must convert it to 0..1.
  817. // TODO: Can't find specs about what this value really is, but it
  818. // seems to vary between 0 and around 32k.
  819. audioLevel = audioLevel / 32767;
  820. if (!(ssrc in this.audioLevelReportHistory)) {
  821. this.audioLevelReportHistory[ssrc] = {
  822. isLocal,
  823. data: []
  824. };
  825. }
  826. this.audioLevelReportHistory[ssrc].data.push(audioLevel);
  827. this.eventEmitter.emit(
  828. StatisticsEvents.AUDIO_LEVEL,
  829. this.peerconnection,
  830. ssrc,
  831. audioLevel,
  832. isLocal);
  833. }
  834. }
  835. };
  836. /* eslint-enable no-continue */
  837. /**
  838. * New promised based getStats report processing.
  839. * Tested with chrome, firefox and safari. Not switching it on for chrome as
  840. * frameRate stat is missing and calculating it using framesSent,
  841. * gives values double the values seen in webrtc-internals.
  842. * https://w3c.github.io/webrtc-stats/
  843. */
  844. /**
  845. * Defines a function which (1) is to be used as a StatsCollector method and (2)
  846. * gets the value from a specific report returned by RTCPeerConnection#getStats
  847. * associated with a lib-jitsi-meet browser-agnostic name in case of using
  848. * Promised based getStats.
  849. *
  850. * @param {Object.<string,string>} keys the map of LibJitsi browser-agnostic
  851. * names to RTCPeerConnection#getStats browser-specific keys
  852. */
  853. StatsCollector.prototype._defineNewGetStatValueMethod = function(keys) {
  854. // Define the function which converts a lib-jitsi-meet browser-asnostic name
  855. // to a browser-specific key of a report returned by
  856. // RTCPeerConnection#getStats.
  857. const keyFromName = function(name) {
  858. const key = keys[name];
  859. if (key) {
  860. return key;
  861. }
  862. throw new Error(`The property '${name}' isn't supported!`);
  863. };
  864. // Compose the 2 functions defined above to get a function which retrieves
  865. // the value from a specific report returned by RTCPeerConnection#getStats
  866. // associated with a specific lib-jitsi-meet browser-agnostic name.
  867. return (item, name) => item[keyFromName(name)];
  868. };
  869. /**
  870. * Converts the value to a non-negative number.
  871. * If the value is either invalid or negative then 0 will be returned.
  872. * @param {*} v
  873. * @return {number}
  874. * @private
  875. */
  876. StatsCollector.prototype.getNonNegativeValue = function(v) {
  877. let value = v;
  878. if (typeof value !== 'number') {
  879. value = Number(value);
  880. }
  881. if (isNaN(value)) {
  882. return 0;
  883. }
  884. return Math.max(0, value);
  885. };
  886. /**
  887. * Calculates bitrate between before and now using a supplied field name and its
  888. * value in the stats.
  889. * @param {RTCInboundRtpStreamStats|RTCSentRtpStreamStats} now the current stats
  890. * @param {RTCInboundRtpStreamStats|RTCSentRtpStreamStats} before the
  891. * previous stats.
  892. * @param fieldName the field to use for calculations.
  893. * @return {number} the calculated bitrate between now and before.
  894. * @private
  895. */
  896. StatsCollector.prototype._calculateBitrate = function(now, before, fieldName) {
  897. const bytesNow = this.getNonNegativeValue(now[fieldName]);
  898. const bytesBefore = this.getNonNegativeValue(before[fieldName]);
  899. const bytesProcessed = Math.max(0, bytesNow - bytesBefore);
  900. const timeMs = now.timestamp - before.timestamp;
  901. let bitrateKbps = 0;
  902. if (timeMs > 0) {
  903. // TODO is there any reason to round here?
  904. bitrateKbps = Math.round((bytesProcessed * 8) / timeMs);
  905. }
  906. return bitrateKbps;
  907. };
  908. /**
  909. * Stats processing new getStats logic.
  910. */
  911. StatsCollector.prototype.processNewStatsReport = function() {
  912. if (!this.previousStatsReport) {
  913. return;
  914. }
  915. const getStatValue = this._getStatValue;
  916. const byteSentStats = {};
  917. this.currentStatsReport.forEach(now => {
  918. // RTCIceCandidatePairStats
  919. // https://w3c.github.io/webrtc-stats/#candidatepair-dict*
  920. if (now.type === 'candidate-pair'
  921. && now.nominated
  922. && now.state === 'succeeded') {
  923. const availableIncomingBitrate = now.availableIncomingBitrate;
  924. const availableOutgoingBitrate = now.availableOutgoingBitrate;
  925. if (availableIncomingBitrate || availableOutgoingBitrate) {
  926. this.conferenceStats.bandwidth = {
  927. 'download': Math.round(availableIncomingBitrate / 1000),
  928. 'upload': Math.round(availableOutgoingBitrate / 1000)
  929. };
  930. }
  931. const remoteUsedCandidate
  932. = this.currentStatsReport.get(now.remoteCandidateId);
  933. const localUsedCandidate
  934. = this.currentStatsReport.get(now.localCandidateId);
  935. // RTCIceCandidateStats
  936. // https://w3c.github.io/webrtc-stats/#icecandidate-dict*
  937. // safari currently does not provide ice candidates in stats
  938. if (remoteUsedCandidate && localUsedCandidate) {
  939. const remoteIpAddress = getStatValue(remoteUsedCandidate, 'ip');
  940. const remotePort = getStatValue(remoteUsedCandidate, 'port');
  941. const ip = `${remoteIpAddress}:${remotePort}`;
  942. const localIpAddress = getStatValue(localUsedCandidate, 'ip');
  943. const localPort = getStatValue(localUsedCandidate, 'port');
  944. const localIp = `${localIpAddress}:${localPort}`;
  945. const type = getStatValue(remoteUsedCandidate, 'protocol');
  946. // Save the address unless it has been saved already.
  947. const conferenceStatsTransport = this.conferenceStats.transport;
  948. if (!conferenceStatsTransport.some(
  949. t =>
  950. t.ip === ip
  951. && t.type === type
  952. && t.localip === localIp)) {
  953. conferenceStatsTransport.push({
  954. ip,
  955. type,
  956. localIp,
  957. p2p: this.peerconnection.isP2P,
  958. localCandidateType: localUsedCandidate.candidateType,
  959. remoteCandidateType: remoteUsedCandidate.candidateType,
  960. networkType: localUsedCandidate.networkType,
  961. rtt: now.currentRoundTripTime * 1000
  962. });
  963. }
  964. }
  965. // RTCReceivedRtpStreamStats
  966. // https://w3c.github.io/webrtc-stats/#receivedrtpstats-dict*
  967. // RTCSentRtpStreamStats
  968. // https://w3c.github.io/webrtc-stats/#sentrtpstats-dict*
  969. } else if (now.type === 'inbound-rtp' || now.type === 'outbound-rtp') {
  970. const before = this.previousStatsReport.get(now.id);
  971. const ssrc = this.getNonNegativeValue(now.ssrc);
  972. if (!before || !ssrc) {
  973. return;
  974. }
  975. let ssrcStats = this.ssrc2stats.get(ssrc);
  976. if (!ssrcStats) {
  977. ssrcStats = new SsrcStats();
  978. this.ssrc2stats.set(ssrc, ssrcStats);
  979. }
  980. let isDownloadStream = true;
  981. let key = 'packetsReceived';
  982. if (now.type === 'outbound-rtp') {
  983. isDownloadStream = false;
  984. key = 'packetsSent';
  985. }
  986. let packetsNow = now[key];
  987. if (!packetsNow || packetsNow < 0) {
  988. packetsNow = 0;
  989. }
  990. const packetsBefore = this.getNonNegativeValue(before[key]);
  991. const packetsDiff = Math.max(0, packetsNow - packetsBefore);
  992. const packetsLostNow
  993. = this.getNonNegativeValue(now.packetsLost);
  994. const packetsLostBefore
  995. = this.getNonNegativeValue(before.packetsLost);
  996. const packetsLostDiff
  997. = Math.max(0, packetsLostNow - packetsLostBefore);
  998. ssrcStats.setLoss({
  999. packetsTotal: packetsDiff + packetsLostDiff,
  1000. packetsLost: packetsLostDiff,
  1001. isDownloadStream
  1002. });
  1003. const resolution = {
  1004. height: null,
  1005. width: null
  1006. };
  1007. try {
  1008. resolution.height = getStatValue(now, 'frameHeight');
  1009. resolution.width = getStatValue(now, 'frameWidth');
  1010. } catch (e) { /* not supported*/ }
  1011. // Tries to get frame rate
  1012. let frameRate;
  1013. try {
  1014. frameRate = getStatValue(now, 'framesPerSecond');
  1015. } catch (err) { /* not supported*/ }
  1016. ssrcStats.setFramerate(Math.round(frameRate || 0));
  1017. if (resolution.height && resolution.width) {
  1018. ssrcStats.setResolution(resolution);
  1019. } else {
  1020. ssrcStats.setResolution(null);
  1021. }
  1022. if (now.type === 'inbound-rtp') {
  1023. ssrcStats.addBitrate({
  1024. 'download': this._calculateBitrate(
  1025. now, before, 'bytesReceived'),
  1026. 'upload': 0
  1027. });
  1028. // RTCInboundRtpStreamStats
  1029. // https://w3c.github.io/webrtc-stats/#inboundrtpstats-dict*
  1030. // TODO: can we use framesDecoded for frame rate, available
  1031. // in chrome
  1032. } else {
  1033. byteSentStats[ssrc] = this.getNonNegativeValue(now.bytesSent);
  1034. ssrcStats.addBitrate({
  1035. 'download': 0,
  1036. 'upload': this._calculateBitrate(
  1037. now, before, 'bytesSent')
  1038. });
  1039. // RTCOutboundRtpStreamStats
  1040. // https://w3c.github.io/webrtc-stats/#outboundrtpstats-dict*
  1041. // TODO: can we use framesEncoded for frame rate, available
  1042. // in chrome
  1043. }
  1044. // FF has framerateMean out of spec
  1045. const framerateMean = now.framerateMean;
  1046. if (framerateMean) {
  1047. ssrcStats.setFramerate(Math.round(framerateMean || 0));
  1048. }
  1049. let codec;
  1050. // Try to get the codec for later reporting.
  1051. try {
  1052. codec = this.currentStatsReport.get(now.codecId);
  1053. } catch (e) { /* not supported*/ }
  1054. if (codec) {
  1055. /**
  1056. * The mime type has the following form: video/VP8 or audio/ISAC,
  1057. * so we what to keep just the type after the '/', audio and video
  1058. * keys will be added on the processing side.
  1059. */
  1060. const codecShortType = codec.mimeType.split('/')[1];
  1061. codecShortType && ssrcStats.setCodec(codecShortType);
  1062. }
  1063. // track for resolution
  1064. // RTCVideoHandlerStats
  1065. // https://w3c.github.io/webrtc-stats/#vststats-dict*
  1066. // RTCMediaHandlerStats
  1067. // https://w3c.github.io/webrtc-stats/#mststats-dict*
  1068. } else if (now.type === 'track') {
  1069. const resolution = {
  1070. height: now.frameHeight,
  1071. width: now.frameWidth
  1072. };
  1073. // Tries to get frame rate
  1074. let frameRate = now.framesPerSecond;
  1075. if (!frameRate) {
  1076. // we need to calculate it
  1077. const before = this.previousStatsReport.get(now.id);
  1078. if (before) {
  1079. const timeMs = now.timestamp - before.timestamp;
  1080. if (timeMs > 0 && now.framesSent) {
  1081. const numberOfFramesSinceBefore
  1082. = now.framesSent - before.framesSent;
  1083. frameRate = (numberOfFramesSinceBefore / timeMs) * 1000;
  1084. }
  1085. }
  1086. if (!frameRate) {
  1087. return;
  1088. }
  1089. }
  1090. const trackIdentifier = now.trackIdentifier;
  1091. const ssrc = this.peerconnection.getSsrcByTrackId(trackIdentifier);
  1092. if (!ssrc) {
  1093. return;
  1094. }
  1095. let ssrcStats = this.ssrc2stats.get(ssrc);
  1096. if (!ssrcStats) {
  1097. ssrcStats = new SsrcStats();
  1098. this.ssrc2stats.set(ssrc, ssrcStats);
  1099. }
  1100. ssrcStats.setFramerate(Math.round(frameRate || 0));
  1101. if (resolution.height && resolution.width) {
  1102. ssrcStats.setResolution(resolution);
  1103. } else {
  1104. ssrcStats.setResolution(null);
  1105. }
  1106. }
  1107. });
  1108. this.eventEmitter.emit(
  1109. StatisticsEvents.BYTE_SENT_STATS, this.peerconnection, byteSentStats);
  1110. this._processAndEmitReport();
  1111. };
  1112. /**
  1113. * Stats processing logic.
  1114. */
  1115. StatsCollector.prototype.processNewAudioLevelReport = function() {
  1116. if (!this.baselineAudioLevelsReport) {
  1117. return;
  1118. }
  1119. this.currentAudioLevelsReport.forEach(now => {
  1120. if (now.type !== 'track') {
  1121. return;
  1122. }
  1123. // Audio level
  1124. const audioLevel = now.audioLevel;
  1125. if (!audioLevel) {
  1126. return;
  1127. }
  1128. const trackIdentifier = now.trackIdentifier;
  1129. const ssrc = this.peerconnection.getSsrcByTrackId(trackIdentifier);
  1130. if (ssrc) {
  1131. const isLocal
  1132. = ssrc === this.peerconnection.getLocalSSRC(
  1133. this.peerconnection.getLocalTracks(MediaType.AUDIO));
  1134. this.eventEmitter.emit(
  1135. StatisticsEvents.AUDIO_LEVEL,
  1136. this.peerconnection,
  1137. ssrc,
  1138. audioLevel,
  1139. isLocal);
  1140. }
  1141. });
  1142. };
  1143. /**
  1144. * End new promised based getStats processing methods.
  1145. */