選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

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. const processStats = () => {
  320. // Interval updates
  321. this.peerconnection.getStats(
  322. report => {
  323. let results = null;
  324. if (!report || !report.result
  325. || typeof report.result !== 'function') {
  326. // firefox
  327. results = report;
  328. } else {
  329. // chrome
  330. results = report.result();
  331. }
  332. this.currentStatsReport = results;
  333. try {
  334. if (this._usesPromiseGetStats) {
  335. this.processNewStatsReport();
  336. } else {
  337. this.processStatsReport();
  338. }
  339. } catch (e) {
  340. GlobalOnErrorHandler.callErrorHandler(e);
  341. logger.error(`Unsupported key:${e}`, e);
  342. }
  343. this.previousStatsReport = this.currentStatsReport;
  344. },
  345. error => this.errorCallback(error)
  346. );
  347. };
  348. processStats();
  349. this.statsIntervalId = setInterval(processStats, this.statsIntervalMilis);
  350. };
  351. /**
  352. * Defines a function which (1) is to be used as a StatsCollector method and (2)
  353. * gets the value from a specific report returned by RTCPeerConnection#getStats
  354. * associated with a lib-jitsi-meet browser-agnostic name.
  355. *
  356. * @param {Object.<string,string>} keys the map of LibJitsi browser-agnostic
  357. * names to RTCPeerConnection#getStats browser-specific keys
  358. */
  359. StatsCollector.prototype._defineGetStatValueMethod = function(keys) {
  360. // Define the function which converts a lib-jitsi-meet browser-asnostic name
  361. // to a browser-specific key of a report returned by
  362. // RTCPeerConnection#getStats.
  363. const keyFromName = function(name) {
  364. const key = keys[name];
  365. if (key) {
  366. return key;
  367. }
  368. throw new Error(`The property '${name}' isn't supported!`);
  369. };
  370. // Define the function which retrieves the value from a specific report
  371. // returned by RTCPeerConnection#getStats associated with a given
  372. // browser-specific key.
  373. let itemStatByKey;
  374. switch (this._browserType) {
  375. case browsers.CHROME:
  376. case browsers.OPERA:
  377. case browsers.NWJS:
  378. case browsers.ELECTRON:
  379. // TODO What about other types of browser which are based on Chrome such
  380. // as NW.js? Every time we want to support a new type browser we have to
  381. // go and add more conditions (here and in multiple other places).
  382. // Cannot we do a feature detection instead of a browser type check? For
  383. // example, if item has a stat property of type function, then it's very
  384. // likely that whoever defined it wanted you to call it in order to
  385. // retrieve the value associated with a specific key.
  386. itemStatByKey = (item, key) => item.stat(key);
  387. break;
  388. default:
  389. itemStatByKey = (item, key) => item[key];
  390. }
  391. // Compose the 2 functions defined above to get a function which retrieves
  392. // the value from a specific report returned by RTCPeerConnection#getStats
  393. // associated with a specific lib-jitsi-meet browser-agnostic name.
  394. return (item, name) => itemStatByKey(item, keyFromName(name));
  395. };
  396. /**
  397. * Obtains a stat value from given stat and converts it to a non-negative
  398. * number. If the value is either invalid or negative then 0 will be returned.
  399. * @param report
  400. * @param {string} name
  401. * @return {number}
  402. * @private
  403. */
  404. StatsCollector.prototype.getNonNegativeStat = function(report, name) {
  405. let value = this._getStatValue(report, name);
  406. if (typeof value !== 'number') {
  407. value = Number(value);
  408. }
  409. if (isNaN(value)) {
  410. return 0;
  411. }
  412. return Math.max(0, value);
  413. };
  414. /* eslint-disable no-continue */
  415. /**
  416. * Stats processing logic.
  417. */
  418. StatsCollector.prototype.processStatsReport = function() {
  419. if (!this.previousStatsReport) {
  420. return;
  421. }
  422. const getStatValue = this._getStatValue;
  423. const byteSentStats = {};
  424. for (const idx in this.currentStatsReport) {
  425. if (!this.currentStatsReport.hasOwnProperty(idx)) {
  426. continue;
  427. }
  428. const now = this.currentStatsReport[idx];
  429. // The browser API may return "undefined" values in the array
  430. if (!now) {
  431. continue;
  432. }
  433. try {
  434. const receiveBandwidth = getStatValue(now, 'receiveBandwidth');
  435. const sendBandwidth = getStatValue(now, 'sendBandwidth');
  436. if (receiveBandwidth || sendBandwidth) {
  437. this.conferenceStats.bandwidth = {
  438. 'download': Math.round(receiveBandwidth / 1000),
  439. 'upload': Math.round(sendBandwidth / 1000)
  440. };
  441. }
  442. } catch (e) { /* not supported*/ }
  443. if (now.type === 'googCandidatePair') {
  444. let active, ip, localCandidateType, localip,
  445. remoteCandidateType, rtt, type;
  446. try {
  447. active = getStatValue(now, 'activeConnection');
  448. if (!active) {
  449. continue;
  450. }
  451. ip = getStatValue(now, 'remoteAddress');
  452. type = getStatValue(now, 'transportType');
  453. localip = getStatValue(now, 'localAddress');
  454. localCandidateType = getStatValue(now, 'localCandidateType');
  455. remoteCandidateType = getStatValue(now, 'remoteCandidateType');
  456. rtt = this.getNonNegativeStat(now, 'currentRoundTripTime');
  457. } catch (e) { /* not supported*/ }
  458. if (!ip || !type || !localip || active !== 'true') {
  459. continue;
  460. }
  461. // Save the address unless it has been saved already.
  462. const conferenceStatsTransport = this.conferenceStats.transport;
  463. if (!conferenceStatsTransport.some(
  464. t =>
  465. t.ip === ip
  466. && t.type === type
  467. && t.localip === localip)) {
  468. conferenceStatsTransport.push({
  469. ip,
  470. type,
  471. localip,
  472. p2p: this.peerconnection.isP2P,
  473. localCandidateType,
  474. remoteCandidateType,
  475. rtt
  476. });
  477. }
  478. continue;
  479. }
  480. if (now.type === 'candidatepair') {
  481. // we need succeeded and selected pairs only
  482. if (now.state !== 'succeeded' || !now.selected) {
  483. continue;
  484. }
  485. const local = this.currentStatsReport[now.localCandidateId];
  486. const remote = this.currentStatsReport[now.remoteCandidateId];
  487. this.conferenceStats.transport.push({
  488. ip: `${remote.ipAddress}:${remote.portNumber}`,
  489. type: local.transport,
  490. localip: `${local.ipAddress}:${local.portNumber}`,
  491. p2p: this.peerconnection.isP2P,
  492. localCandidateType: local.candidateType,
  493. remoteCandidateType: remote.candidateType
  494. });
  495. }
  496. if (now.type !== 'ssrc' && now.type !== 'outboundrtp'
  497. && now.type !== 'inboundrtp' && now.type !== 'track') {
  498. continue;
  499. }
  500. const before = this.previousStatsReport[idx];
  501. let ssrc = this.getNonNegativeStat(now, 'ssrc');
  502. // If type="track", take the first SSRC from ssrcIds.
  503. if (now.type === 'track' && Array.isArray(now.ssrcIds)) {
  504. ssrc = Number(now.ssrcIds[0]);
  505. }
  506. if (!before || !ssrc) {
  507. continue;
  508. }
  509. // isRemote is available only in FF and is ignored in case of chrome
  510. // according to the spec
  511. // https://www.w3.org/TR/webrtc-stats/#dom-rtcrtpstreamstats-isremote
  512. // when isRemote is true indicates that the measurements were done at
  513. // the remote endpoint and reported in an RTCP RR/XR.
  514. // Fixes a problem where we are calculating local stats wrong adding
  515. // the sent bytes to the local download bitrate.
  516. // In new W3 stats spec, type="track" has a remoteSource boolean
  517. // property.
  518. if (now.isRemote === true || now.remoteSource === true) {
  519. continue;
  520. }
  521. let ssrcStats = this.ssrc2stats.get(ssrc);
  522. if (!ssrcStats) {
  523. ssrcStats = new SsrcStats();
  524. this.ssrc2stats.set(ssrc, ssrcStats);
  525. }
  526. let isDownloadStream = true;
  527. let key = 'packetsReceived';
  528. let packetsNow = getStatValue(now, key);
  529. if (typeof packetsNow === 'undefined'
  530. || packetsNow === null || packetsNow === '') {
  531. isDownloadStream = false;
  532. key = 'packetsSent';
  533. packetsNow = getStatValue(now, key);
  534. if (typeof packetsNow === 'undefined' || packetsNow === null) {
  535. logger.warn('No packetsReceived nor packetsSent stat found');
  536. }
  537. }
  538. if (!packetsNow || packetsNow < 0) {
  539. packetsNow = 0;
  540. }
  541. const packetsBefore = this.getNonNegativeStat(before, key);
  542. const packetsDiff = Math.max(0, packetsNow - packetsBefore);
  543. const packetsLostNow
  544. = this.getNonNegativeStat(now, 'packetsLost');
  545. const packetsLostBefore
  546. = this.getNonNegativeStat(before, 'packetsLost');
  547. const packetsLostDiff = Math.max(0, packetsLostNow - packetsLostBefore);
  548. ssrcStats.setLoss({
  549. packetsTotal: packetsDiff + packetsLostDiff,
  550. packetsLost: packetsLostDiff,
  551. isDownloadStream
  552. });
  553. const bytesReceivedNow
  554. = this.getNonNegativeStat(now, 'bytesReceived');
  555. const bytesReceivedBefore
  556. = this.getNonNegativeStat(before, 'bytesReceived');
  557. const bytesReceived
  558. = Math.max(0, bytesReceivedNow - bytesReceivedBefore);
  559. let bytesSent = 0;
  560. // TODO: clean this mess up!
  561. let nowBytesTransmitted = getStatValue(now, 'bytesSent');
  562. if (typeof nowBytesTransmitted === 'number'
  563. || typeof nowBytesTransmitted === 'string') {
  564. nowBytesTransmitted = Number(nowBytesTransmitted);
  565. if (!isNaN(nowBytesTransmitted)) {
  566. byteSentStats[ssrc] = nowBytesTransmitted;
  567. if (nowBytesTransmitted > 0) {
  568. bytesSent = nowBytesTransmitted
  569. - getStatValue(before, 'bytesSent');
  570. }
  571. }
  572. }
  573. bytesSent = Math.max(0, bytesSent);
  574. const timeMs = now.timestamp - before.timestamp;
  575. let bitrateReceivedKbps = 0, bitrateSentKbps = 0;
  576. if (timeMs > 0) {
  577. // TODO is there any reason to round here?
  578. bitrateReceivedKbps = Math.round((bytesReceived * 8) / timeMs);
  579. bitrateSentKbps = Math.round((bytesSent * 8) / timeMs);
  580. }
  581. ssrcStats.addBitrate({
  582. 'download': bitrateReceivedKbps,
  583. 'upload': bitrateSentKbps
  584. });
  585. const resolution = {
  586. height: null,
  587. width: null
  588. };
  589. try {
  590. let height, width;
  591. if ((height = getStatValue(now, 'googFrameHeightReceived'))
  592. && (width = getStatValue(now, 'googFrameWidthReceived'))) {
  593. resolution.height = height;
  594. resolution.width = width;
  595. } else if ((height = getStatValue(now, 'googFrameHeightSent'))
  596. && (width = getStatValue(now, 'googFrameWidthSent'))) {
  597. resolution.height = height;
  598. resolution.width = width;
  599. }
  600. } catch (e) { /* not supported*/ }
  601. // Tries to get frame rate
  602. let frameRate;
  603. try {
  604. frameRate = getStatValue(now, 'googFrameRateReceived')
  605. || getStatValue(now, 'googFrameRateSent') || 0;
  606. } catch (e) {
  607. // if it fails with previous properties(chrome),
  608. // let's try with another one (FF)
  609. try {
  610. frameRate = this.getNonNegativeStat(now, 'framerateMean');
  611. } catch (err) { /* not supported*/ }
  612. }
  613. ssrcStats.setFramerate(Math.round(frameRate || 0));
  614. if (resolution.height && resolution.width) {
  615. ssrcStats.setResolution(resolution);
  616. } else {
  617. ssrcStats.setResolution(null);
  618. }
  619. let codec;
  620. // Try to get the codec for later reporting.
  621. try {
  622. codec = getStatValue(now, 'googCodecName') || '';
  623. } catch (e) { /* not supported*/ }
  624. ssrcStats.setCodec(codec);
  625. }
  626. this.eventEmitter.emit(
  627. StatisticsEvents.BYTE_SENT_STATS, this.peerconnection, byteSentStats);
  628. this._processAndEmitReport();
  629. };
  630. /**
  631. *
  632. */
  633. StatsCollector.prototype._processAndEmitReport = function() {
  634. // process stats
  635. const totalPackets = {
  636. download: 0,
  637. upload: 0
  638. };
  639. const lostPackets = {
  640. download: 0,
  641. upload: 0
  642. };
  643. let bitrateDownload = 0;
  644. let bitrateUpload = 0;
  645. const resolutions = {};
  646. const framerates = {};
  647. const codecs = {};
  648. let audioBitrateDownload = 0;
  649. let audioBitrateUpload = 0;
  650. let audioCodec;
  651. let videoBitrateDownload = 0;
  652. let videoBitrateUpload = 0;
  653. let videoCodec;
  654. for (const [ ssrc, ssrcStats ] of this.ssrc2stats) {
  655. // process packet loss stats
  656. const loss = ssrcStats.loss;
  657. const type = loss.isDownloadStream ? 'download' : 'upload';
  658. totalPackets[type] += loss.packetsTotal;
  659. lostPackets[type] += loss.packetsLost;
  660. // process bitrate stats
  661. bitrateDownload += ssrcStats.bitrate.download;
  662. bitrateUpload += ssrcStats.bitrate.upload;
  663. // collect resolutions and framerates
  664. const track = this.peerconnection.getTrackBySSRC(ssrc);
  665. if (track) {
  666. if (track.isAudioTrack()) {
  667. audioBitrateDownload += ssrcStats.bitrate.download;
  668. audioBitrateUpload += ssrcStats.bitrate.upload;
  669. audioCodec = ssrcStats.codec;
  670. } else {
  671. videoBitrateDownload += ssrcStats.bitrate.download;
  672. videoBitrateUpload += ssrcStats.bitrate.upload;
  673. videoCodec = ssrcStats.codec;
  674. }
  675. const participantId = track.getParticipantId();
  676. if (participantId) {
  677. const resolution = ssrcStats.resolution;
  678. if (resolution.width
  679. && resolution.height
  680. && resolution.width !== -1
  681. && resolution.height !== -1) {
  682. const userResolutions = resolutions[participantId] || {};
  683. userResolutions[ssrc] = resolution;
  684. resolutions[participantId] = userResolutions;
  685. }
  686. if (ssrcStats.framerate !== 0) {
  687. const userFramerates = framerates[participantId] || {};
  688. userFramerates[ssrc] = ssrcStats.framerate;
  689. framerates[participantId] = userFramerates;
  690. }
  691. if (audioCodec && videoCodec) {
  692. const codecDesc = {
  693. 'audio': audioCodec,
  694. 'video': videoCodec
  695. };
  696. const userCodecs = codecs[participantId] || {};
  697. userCodecs[ssrc] = codecDesc;
  698. codecs[participantId] = userCodecs;
  699. }
  700. } else {
  701. logger.error(`No participant ID returned by ${track}`);
  702. }
  703. }
  704. ssrcStats.resetBitrate();
  705. }
  706. this.conferenceStats.bitrate = {
  707. 'upload': bitrateUpload,
  708. 'download': bitrateDownload
  709. };
  710. this.conferenceStats.bitrate.audio = {
  711. 'upload': audioBitrateUpload,
  712. 'download': audioBitrateDownload
  713. };
  714. this.conferenceStats.bitrate.video = {
  715. 'upload': videoBitrateUpload,
  716. 'download': videoBitrateDownload
  717. };
  718. this.conferenceStats.packetLoss = {
  719. total:
  720. calculatePacketLoss(
  721. lostPackets.download + lostPackets.upload,
  722. totalPackets.download + totalPackets.upload),
  723. download:
  724. calculatePacketLoss(lostPackets.download, totalPackets.download),
  725. upload:
  726. calculatePacketLoss(lostPackets.upload, totalPackets.upload)
  727. };
  728. const avgAudioLevels = {};
  729. let localAvgAudioLevels;
  730. Object.keys(this.audioLevelReportHistory).forEach(ssrc => {
  731. const { data, isLocal } = this.audioLevelReportHistory[ssrc];
  732. const avgAudioLevel = data.reduce((sum, currentValue) => sum + currentValue) / data.length;
  733. if (isLocal) {
  734. localAvgAudioLevels = avgAudioLevel;
  735. } else {
  736. const track = this.peerconnection.getTrackBySSRC(Number(ssrc));
  737. if (track) {
  738. const participantId = track.getParticipantId();
  739. if (participantId) {
  740. avgAudioLevels[participantId] = avgAudioLevel;
  741. }
  742. }
  743. }
  744. });
  745. this.audioLevelReportHistory = {};
  746. this.eventEmitter.emit(
  747. StatisticsEvents.CONNECTION_STATS,
  748. this.peerconnection,
  749. {
  750. 'bandwidth': this.conferenceStats.bandwidth,
  751. 'bitrate': this.conferenceStats.bitrate,
  752. 'packetLoss': this.conferenceStats.packetLoss,
  753. 'resolution': resolutions,
  754. 'framerate': framerates,
  755. 'codec': codecs,
  756. 'transport': this.conferenceStats.transport,
  757. localAvgAudioLevels,
  758. avgAudioLevels
  759. });
  760. this.conferenceStats.transport = [];
  761. };
  762. /**
  763. * Stats processing logic.
  764. */
  765. StatsCollector.prototype.processAudioLevelReport = function() {
  766. if (!this.baselineAudioLevelsReport) {
  767. return;
  768. }
  769. const getStatValue = this._getStatValue;
  770. for (const idx in this.currentAudioLevelsReport) {
  771. if (!this.currentAudioLevelsReport.hasOwnProperty(idx)) {
  772. continue;
  773. }
  774. const now = this.currentAudioLevelsReport[idx];
  775. if (now.type !== 'ssrc' && now.type !== 'track') {
  776. continue;
  777. }
  778. const before = this.baselineAudioLevelsReport[idx];
  779. let ssrc = this.getNonNegativeStat(now, 'ssrc');
  780. if (!ssrc && Array.isArray(now.ssrcIds)) {
  781. ssrc = Number(now.ssrcIds[0]);
  782. }
  783. if (!before) {
  784. logger.warn(`${ssrc} not enough data`);
  785. continue;
  786. }
  787. if (!ssrc) {
  788. if ((Date.now() - now.timestamp) < 3000) {
  789. logger.warn('No ssrc: ');
  790. }
  791. continue;
  792. }
  793. // Audio level
  794. let audioLevel;
  795. try {
  796. audioLevel
  797. = getStatValue(now, 'audioInputLevel')
  798. || getStatValue(now, 'audioOutputLevel');
  799. } catch (e) { /* not supported*/
  800. logger.warn('Audio Levels are not available in the statistics.');
  801. clearInterval(this.audioLevelsIntervalId);
  802. return;
  803. }
  804. if (audioLevel) {
  805. let isLocal;
  806. // If type="ssrc" (legacy) check whether they are received packets.
  807. if (now.type === 'ssrc') {
  808. isLocal = !getStatValue(now, 'packetsReceived');
  809. // If type="track", check remoteSource boolean property.
  810. } else {
  811. isLocal = !now.remoteSource;
  812. }
  813. // According to the W3C WebRTC Stats spec, audioLevel should be in
  814. // 0..1 range (0 == silence). However browsers don't behave that
  815. // way so we must convert it to 0..1.
  816. // TODO: Can't find specs about what this value really is, but it
  817. // seems to vary between 0 and around 32k.
  818. audioLevel = audioLevel / 32767;
  819. if (!(ssrc in this.audioLevelReportHistory)) {
  820. this.audioLevelReportHistory[ssrc] = {
  821. isLocal,
  822. data: []
  823. };
  824. }
  825. this.audioLevelReportHistory[ssrc].data.push(audioLevel);
  826. this.eventEmitter.emit(
  827. StatisticsEvents.AUDIO_LEVEL,
  828. this.peerconnection,
  829. ssrc,
  830. audioLevel,
  831. isLocal);
  832. }
  833. }
  834. };
  835. /* eslint-enable no-continue */
  836. /**
  837. * New promised based getStats report processing.
  838. * Tested with chrome, firefox and safari. Not switching it on for chrome as
  839. * frameRate stat is missing and calculating it using framesSent,
  840. * gives values double the values seen in webrtc-internals.
  841. * https://w3c.github.io/webrtc-stats/
  842. */
  843. /**
  844. * Defines a function which (1) is to be used as a StatsCollector method and (2)
  845. * gets the value from a specific report returned by RTCPeerConnection#getStats
  846. * associated with a lib-jitsi-meet browser-agnostic name in case of using
  847. * Promised based getStats.
  848. *
  849. * @param {Object.<string,string>} keys the map of LibJitsi browser-agnostic
  850. * names to RTCPeerConnection#getStats browser-specific keys
  851. */
  852. StatsCollector.prototype._defineNewGetStatValueMethod = function(keys) {
  853. // Define the function which converts a lib-jitsi-meet browser-asnostic name
  854. // to a browser-specific key of a report returned by
  855. // RTCPeerConnection#getStats.
  856. const keyFromName = function(name) {
  857. const key = keys[name];
  858. if (key) {
  859. return key;
  860. }
  861. throw new Error(`The property '${name}' isn't supported!`);
  862. };
  863. // Compose the 2 functions defined above to get a function which retrieves
  864. // the value from a specific report returned by RTCPeerConnection#getStats
  865. // associated with a specific lib-jitsi-meet browser-agnostic name.
  866. return (item, name) => item[keyFromName(name)];
  867. };
  868. /**
  869. * Converts the value to a non-negative number.
  870. * If the value is either invalid or negative then 0 will be returned.
  871. * @param {*} v
  872. * @return {number}
  873. * @private
  874. */
  875. StatsCollector.prototype.getNonNegativeValue = function(v) {
  876. let value = v;
  877. if (typeof value !== 'number') {
  878. value = Number(value);
  879. }
  880. if (isNaN(value)) {
  881. return 0;
  882. }
  883. return Math.max(0, value);
  884. };
  885. /**
  886. * Calculates bitrate between before and now using a supplied field name and its
  887. * value in the stats.
  888. * @param {RTCInboundRtpStreamStats|RTCSentRtpStreamStats} now the current stats
  889. * @param {RTCInboundRtpStreamStats|RTCSentRtpStreamStats} before the
  890. * previous stats.
  891. * @param fieldName the field to use for calculations.
  892. * @return {number} the calculated bitrate between now and before.
  893. * @private
  894. */
  895. StatsCollector.prototype._calculateBitrate = function(now, before, fieldName) {
  896. const bytesNow = this.getNonNegativeValue(now[fieldName]);
  897. const bytesBefore = this.getNonNegativeValue(before[fieldName]);
  898. const bytesProcessed = Math.max(0, bytesNow - bytesBefore);
  899. const timeMs = now.timestamp - before.timestamp;
  900. let bitrateKbps = 0;
  901. if (timeMs > 0) {
  902. // TODO is there any reason to round here?
  903. bitrateKbps = Math.round((bytesProcessed * 8) / timeMs);
  904. }
  905. return bitrateKbps;
  906. };
  907. /**
  908. * Stats processing new getStats logic.
  909. */
  910. StatsCollector.prototype.processNewStatsReport = function() {
  911. if (!this.previousStatsReport) {
  912. return;
  913. }
  914. const getStatValue = this._getStatValue;
  915. const byteSentStats = {};
  916. this.currentStatsReport.forEach(now => {
  917. // RTCIceCandidatePairStats
  918. // https://w3c.github.io/webrtc-stats/#candidatepair-dict*
  919. if (now.type === 'candidate-pair'
  920. && now.nominated
  921. && now.state === 'succeeded') {
  922. const availableIncomingBitrate = now.availableIncomingBitrate;
  923. const availableOutgoingBitrate = now.availableOutgoingBitrate;
  924. if (availableIncomingBitrate || availableOutgoingBitrate) {
  925. this.conferenceStats.bandwidth = {
  926. 'download': Math.round(availableIncomingBitrate / 1000),
  927. 'upload': Math.round(availableOutgoingBitrate / 1000)
  928. };
  929. }
  930. const remoteUsedCandidate
  931. = this.currentStatsReport.get(now.remoteCandidateId);
  932. const localUsedCandidate
  933. = this.currentStatsReport.get(now.localCandidateId);
  934. // RTCIceCandidateStats
  935. // https://w3c.github.io/webrtc-stats/#icecandidate-dict*
  936. // safari currently does not provide ice candidates in stats
  937. if (remoteUsedCandidate && localUsedCandidate) {
  938. const remoteIpAddress = getStatValue(remoteUsedCandidate, 'ip');
  939. const remotePort = getStatValue(remoteUsedCandidate, 'port');
  940. const ip = `${remoteIpAddress}:${remotePort}`;
  941. const localIpAddress = getStatValue(localUsedCandidate, 'ip');
  942. const localPort = getStatValue(localUsedCandidate, 'port');
  943. const localIp = `${localIpAddress}:${localPort}`;
  944. const type = getStatValue(remoteUsedCandidate, 'protocol');
  945. // Save the address unless it has been saved already.
  946. const conferenceStatsTransport = this.conferenceStats.transport;
  947. if (!conferenceStatsTransport.some(
  948. t =>
  949. t.ip === ip
  950. && t.type === type
  951. && t.localip === localIp)) {
  952. conferenceStatsTransport.push({
  953. ip,
  954. type,
  955. localIp,
  956. p2p: this.peerconnection.isP2P,
  957. localCandidateType: localUsedCandidate.candidateType,
  958. remoteCandidateType: remoteUsedCandidate.candidateType,
  959. networkType: localUsedCandidate.networkType,
  960. rtt: now.currentRoundTripTime * 1000
  961. });
  962. }
  963. }
  964. // RTCReceivedRtpStreamStats
  965. // https://w3c.github.io/webrtc-stats/#receivedrtpstats-dict*
  966. // RTCSentRtpStreamStats
  967. // https://w3c.github.io/webrtc-stats/#sentrtpstats-dict*
  968. } else if (now.type === 'inbound-rtp' || now.type === 'outbound-rtp') {
  969. const before = this.previousStatsReport.get(now.id);
  970. const ssrc = this.getNonNegativeValue(now.ssrc);
  971. if (!before || !ssrc) {
  972. return;
  973. }
  974. let ssrcStats = this.ssrc2stats.get(ssrc);
  975. if (!ssrcStats) {
  976. ssrcStats = new SsrcStats();
  977. this.ssrc2stats.set(ssrc, ssrcStats);
  978. }
  979. let isDownloadStream = true;
  980. let key = 'packetsReceived';
  981. if (now.type === 'outbound-rtp') {
  982. isDownloadStream = false;
  983. key = 'packetsSent';
  984. }
  985. let packetsNow = now[key];
  986. if (!packetsNow || packetsNow < 0) {
  987. packetsNow = 0;
  988. }
  989. const packetsBefore = this.getNonNegativeValue(before[key]);
  990. const packetsDiff = Math.max(0, packetsNow - packetsBefore);
  991. const packetsLostNow
  992. = this.getNonNegativeValue(now.packetsLost);
  993. const packetsLostBefore
  994. = this.getNonNegativeValue(before.packetsLost);
  995. const packetsLostDiff
  996. = Math.max(0, packetsLostNow - packetsLostBefore);
  997. ssrcStats.setLoss({
  998. packetsTotal: packetsDiff + packetsLostDiff,
  999. packetsLost: packetsLostDiff,
  1000. isDownloadStream
  1001. });
  1002. const resolution = {
  1003. height: null,
  1004. width: null
  1005. };
  1006. try {
  1007. resolution.height = getStatValue(now, 'frameHeight');
  1008. resolution.width = getStatValue(now, 'frameWidth');
  1009. } catch (e) { /* not supported*/ }
  1010. // Tries to get frame rate
  1011. let frameRate;
  1012. try {
  1013. frameRate = getStatValue(now, 'framesPerSecond');
  1014. } catch (err) { /* not supported*/ }
  1015. ssrcStats.setFramerate(Math.round(frameRate || 0));
  1016. if (resolution.height && resolution.width) {
  1017. ssrcStats.setResolution(resolution);
  1018. } else {
  1019. ssrcStats.setResolution(null);
  1020. }
  1021. if (now.type === 'inbound-rtp') {
  1022. ssrcStats.addBitrate({
  1023. 'download': this._calculateBitrate(
  1024. now, before, 'bytesReceived'),
  1025. 'upload': 0
  1026. });
  1027. // RTCInboundRtpStreamStats
  1028. // https://w3c.github.io/webrtc-stats/#inboundrtpstats-dict*
  1029. // TODO: can we use framesDecoded for frame rate, available
  1030. // in chrome
  1031. } else {
  1032. byteSentStats[ssrc] = this.getNonNegativeValue(now.bytesSent);
  1033. ssrcStats.addBitrate({
  1034. 'download': 0,
  1035. 'upload': this._calculateBitrate(
  1036. now, before, 'bytesSent')
  1037. });
  1038. // RTCOutboundRtpStreamStats
  1039. // https://w3c.github.io/webrtc-stats/#outboundrtpstats-dict*
  1040. // TODO: can we use framesEncoded for frame rate, available
  1041. // in chrome
  1042. }
  1043. // FF has framerateMean out of spec
  1044. const framerateMean = now.framerateMean;
  1045. if (framerateMean) {
  1046. ssrcStats.setFramerate(Math.round(framerateMean || 0));
  1047. }
  1048. let codec;
  1049. // Try to get the codec for later reporting.
  1050. try {
  1051. codec = this.currentStatsReport.get(now.codecId);
  1052. } catch (e) { /* not supported*/ }
  1053. if (codec) {
  1054. /**
  1055. * The mime type has the following form: video/VP8 or audio/ISAC,
  1056. * so we what to keep just the type after the '/', audio and video
  1057. * keys will be added on the processing side.
  1058. */
  1059. const codecShortType = codec.mimeType.split('/')[1];
  1060. codecShortType && ssrcStats.setCodec(codecShortType);
  1061. }
  1062. // track for resolution
  1063. // RTCVideoHandlerStats
  1064. // https://w3c.github.io/webrtc-stats/#vststats-dict*
  1065. // RTCMediaHandlerStats
  1066. // https://w3c.github.io/webrtc-stats/#mststats-dict*
  1067. } else if (now.type === 'track') {
  1068. const resolution = {
  1069. height: now.frameHeight,
  1070. width: now.frameWidth
  1071. };
  1072. // Tries to get frame rate
  1073. let frameRate = now.framesPerSecond;
  1074. if (!frameRate) {
  1075. // we need to calculate it
  1076. const before = this.previousStatsReport.get(now.id);
  1077. if (before) {
  1078. const timeMs = now.timestamp - before.timestamp;
  1079. if (timeMs > 0 && now.framesSent) {
  1080. const numberOfFramesSinceBefore
  1081. = now.framesSent - before.framesSent;
  1082. frameRate = (numberOfFramesSinceBefore / timeMs) * 1000;
  1083. }
  1084. }
  1085. if (!frameRate) {
  1086. return;
  1087. }
  1088. }
  1089. const trackIdentifier = now.trackIdentifier;
  1090. const ssrc = this.peerconnection.getSsrcByTrackId(trackIdentifier);
  1091. if (!ssrc) {
  1092. return;
  1093. }
  1094. let ssrcStats = this.ssrc2stats.get(ssrc);
  1095. if (!ssrcStats) {
  1096. ssrcStats = new SsrcStats();
  1097. this.ssrc2stats.set(ssrc, ssrcStats);
  1098. }
  1099. ssrcStats.setFramerate(Math.round(frameRate || 0));
  1100. if (resolution.height && resolution.width) {
  1101. ssrcStats.setResolution(resolution);
  1102. } else {
  1103. ssrcStats.setResolution(null);
  1104. }
  1105. }
  1106. });
  1107. this.eventEmitter.emit(
  1108. StatisticsEvents.BYTE_SENT_STATS, this.peerconnection, byteSentStats);
  1109. this._processAndEmitReport();
  1110. };
  1111. /**
  1112. * Stats processing logic.
  1113. */
  1114. StatsCollector.prototype.processNewAudioLevelReport = function() {
  1115. if (!this.baselineAudioLevelsReport) {
  1116. return;
  1117. }
  1118. this.currentAudioLevelsReport.forEach(now => {
  1119. if (now.type !== 'track') {
  1120. return;
  1121. }
  1122. // Audio level
  1123. const audioLevel = now.audioLevel;
  1124. if (!audioLevel) {
  1125. return;
  1126. }
  1127. const trackIdentifier = now.trackIdentifier;
  1128. const ssrc = this.peerconnection.getSsrcByTrackId(trackIdentifier);
  1129. if (ssrc) {
  1130. const isLocal
  1131. = ssrc === this.peerconnection.getLocalSSRC(
  1132. this.peerconnection.getLocalTracks(MediaType.AUDIO));
  1133. this.eventEmitter.emit(
  1134. StatisticsEvents.AUDIO_LEVEL,
  1135. this.peerconnection,
  1136. ssrc,
  1137. audioLevel,
  1138. isLocal);
  1139. }
  1140. });
  1141. };
  1142. /**
  1143. * End new promised based getStats processing methods.
  1144. */