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.

ConnectionStatsTable.js 21KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812
  1. /* @flow */
  2. import React, { Component } from 'react';
  3. import { translate } from '../../base/i18n';
  4. /**
  5. * The type of the React {@code Component} props of
  6. * {@link ConnectionStatsTable}.
  7. */
  8. type Props = {
  9. /**
  10. * The audio SSRC of this client.
  11. */
  12. audioSsrc: number,
  13. /**
  14. * Statistics related to bandwidth.
  15. * {{
  16. * download: Number,
  17. * upload: Number
  18. * }}
  19. */
  20. bandwidth: Object,
  21. /**
  22. * Statistics related to bitrate.
  23. * {{
  24. * download: Number,
  25. * upload: Number
  26. * }}
  27. */
  28. bitrate: Object,
  29. /**
  30. * The number of bridges (aka media servers) currently used in the
  31. * conference.
  32. */
  33. bridgeCount: number,
  34. /**
  35. * Audio/video codecs in use for the connection.
  36. */
  37. codec: Object,
  38. /**
  39. * A message describing the connection quality.
  40. */
  41. connectionSummary: string,
  42. /**
  43. * The end-to-end round-trip-time.
  44. */
  45. e2eRtt: number,
  46. /**
  47. * The endpoint id of this client.
  48. */
  49. participantId: string,
  50. /**
  51. * Statistics related to frame rates for each ssrc.
  52. * {{
  53. * [ ssrc ]: Number
  54. * }}
  55. */
  56. framerate: Object,
  57. /**
  58. * Whether or not the statistics are for local video.
  59. */
  60. isLocalVideo: boolean,
  61. /**
  62. * The send-side max enabled resolution (aka the highest layer that is not
  63. * suspended on the send-side).
  64. */
  65. maxEnabledResolution: number,
  66. /**
  67. * Callback to invoke when the user clicks on the download logs link.
  68. */
  69. onSaveLogs: Function,
  70. /**
  71. * Callback to invoke when the show additional stats link is clicked.
  72. */
  73. onShowMore: Function,
  74. /**
  75. * Statistics related to packet loss.
  76. * {{
  77. * download: Number,
  78. * upload: Number
  79. * }}
  80. */
  81. packetLoss: Object,
  82. /**
  83. * The region that we think the client is in.
  84. */
  85. region: string,
  86. /**
  87. * Statistics related to display resolutions for each ssrc.
  88. * {{
  89. * [ ssrc ]: {
  90. * height: Number,
  91. * width: Number
  92. * }
  93. * }}
  94. */
  95. resolution: Object,
  96. /**
  97. * The region of the media server that we are connected to.
  98. */
  99. serverRegion: string,
  100. /**
  101. * Whether or not additional stats about bandwidth and transport should be
  102. * displayed. Will not display even if true for remote participants.
  103. */
  104. shouldShowMore: boolean,
  105. /**
  106. * Invoked to obtain translated strings.
  107. */
  108. t: Function,
  109. /**
  110. * The video SSRC of this client.
  111. */
  112. videoSsrc: number,
  113. /**
  114. * Statistics related to transports.
  115. */
  116. transport: Array<Object>
  117. };
  118. /**
  119. * React {@code Component} for displaying connection statistics.
  120. *
  121. * @extends Component
  122. */
  123. class ConnectionStatsTable extends Component<Props> {
  124. /**
  125. * Implements React's {@link Component#render()}.
  126. *
  127. * @inheritdoc
  128. * @returns {ReactElement}
  129. */
  130. render() {
  131. const { isLocalVideo } = this.props;
  132. return (
  133. <div className = 'connection-info'>
  134. { this._renderStatistics() }
  135. <div className = 'connection-actions'>
  136. { isLocalVideo ? this._renderSaveLogs() : null}
  137. { this._renderShowMoreLink() }
  138. </div>
  139. { this.props.shouldShowMore ? this._renderAdditionalStats() : null }
  140. </div>
  141. );
  142. }
  143. /**
  144. * Creates a table as ReactElement that will display additional statistics
  145. * related to bandwidth and transport for the local user.
  146. *
  147. * @private
  148. * @returns {ReactElement}
  149. */
  150. _renderAdditionalStats() {
  151. const { isLocalVideo } = this.props;
  152. return (
  153. <table className = 'connection-info__container'>
  154. <tbody>
  155. { isLocalVideo ? this._renderBandwidth() : null }
  156. { isLocalVideo ? this._renderTransport() : null }
  157. { isLocalVideo ? this._renderRegion() : null }
  158. { this._renderAudioSsrc() }
  159. { this._renderVideoSsrc() }
  160. { this._renderParticipantId() }
  161. </tbody>
  162. </table>
  163. );
  164. }
  165. /**
  166. * Creates a table row as a ReactElement for displaying bandwidth related
  167. * statistics.
  168. *
  169. * @private
  170. * @returns {ReactElement}
  171. */
  172. _renderBandwidth() {
  173. const { download, upload } = this.props.bandwidth || {};
  174. return (
  175. <tr>
  176. <td>
  177. { this.props.t('connectionindicator.bandwidth') }
  178. </td>
  179. <td>
  180. <span className = 'connection-info__download'>
  181. &darr;
  182. </span>
  183. { download ? `${download} Kbps` : 'N/A' }
  184. <span className = 'connection-info__upload'>
  185. &uarr;
  186. </span>
  187. { upload ? `${upload} Kbps` : 'N/A' }
  188. </td>
  189. </tr>
  190. );
  191. }
  192. /**
  193. * Creates a a table row as a ReactElement for displaying bitrate related
  194. * statistics.
  195. *
  196. * @private
  197. * @returns {ReactElement}
  198. */
  199. _renderBitrate() {
  200. const { download, upload } = this.props.bitrate || {};
  201. return (
  202. <tr>
  203. <td>
  204. <span>
  205. { this.props.t('connectionindicator.bitrate') }
  206. </span>
  207. </td>
  208. <td>
  209. <span className = 'connection-info__download'>
  210. &darr;
  211. </span>
  212. { download ? `${download} Kbps` : 'N/A' }
  213. <span className = 'connection-info__upload'>
  214. &uarr;
  215. </span>
  216. { upload ? `${upload} Kbps` : 'N/A' }
  217. </td>
  218. </tr>
  219. );
  220. }
  221. /**
  222. * Creates a table row as a ReactElement for displaying the audio ssrc.
  223. * This will typically be something like "Audio SSRC: 12345".
  224. *
  225. * @returns {JSX.Element}
  226. * @private
  227. */
  228. _renderAudioSsrc() {
  229. const { audioSsrc, t } = this.props;
  230. return (
  231. <tr>
  232. <td>
  233. <span>{ t('connectionindicator.audio_ssrc') }</span>
  234. </td>
  235. <td>{ audioSsrc || 'N/A' }</td>
  236. </tr>
  237. );
  238. }
  239. /**
  240. * Creates a table row as a ReactElement for displaying the video ssrc.
  241. * This will typically be something like "Video SSRC: 12345".
  242. *
  243. * @returns {JSX.Element}
  244. * @private
  245. */
  246. _renderVideoSsrc() {
  247. const { videoSsrc, t } = this.props;
  248. return (
  249. <tr>
  250. <td>
  251. <span>{ t('connectionindicator.video_ssrc') }</span>
  252. </td>
  253. <td>{ videoSsrc || 'N/A' }</td>
  254. </tr>
  255. );
  256. }
  257. /**
  258. * Creates a table row as a ReactElement for displaying the endpoint id.
  259. * This will typically be something like "Endpoint id: 1e8fbg".
  260. *
  261. * @returns {JSX.Element}
  262. * @private
  263. */
  264. _renderParticipantId() {
  265. const { participantId, t } = this.props;
  266. return (
  267. <tr>
  268. <td>
  269. <span>{ t('connectionindicator.participant_id') }</span>
  270. </td>
  271. <td>{ participantId || 'N/A' }</td>
  272. </tr>
  273. );
  274. }
  275. /**
  276. * Creates a a table row as a ReactElement for displaying codec, if present.
  277. * This will typically be something like "Codecs (A/V): Opus, vp8".
  278. *
  279. * @private
  280. * @returns {ReactElement}
  281. */
  282. _renderCodecs() {
  283. const { codec, t } = this.props;
  284. if (!codec) {
  285. return;
  286. }
  287. let codecString;
  288. // Only report one codec, in case there are multiple for a user.
  289. Object.keys(codec || {})
  290. .forEach(ssrc => {
  291. const { audio, video } = codec[ssrc];
  292. codecString = `${audio}, ${video}`;
  293. });
  294. if (!codecString) {
  295. codecString = 'N/A';
  296. }
  297. return (
  298. <tr>
  299. <td>
  300. <span>{ t('connectionindicator.codecs') }</span>
  301. </td>
  302. <td>{ codecString }</td>
  303. </tr>
  304. );
  305. }
  306. /**
  307. * Creates a table row as a ReactElement for displaying a summary message
  308. * about the current connection status.
  309. *
  310. * @private
  311. * @returns {ReactElement}
  312. */
  313. _renderConnectionSummary() {
  314. return (
  315. <tr className = 'connection-info__status'>
  316. <td>
  317. <span>{ this.props.t('connectionindicator.status') }</span>
  318. </td>
  319. <td>{ this.props.connectionSummary }</td>
  320. </tr>
  321. );
  322. }
  323. /**
  324. * Creates a table row as a ReactElement for displaying end-to-end RTT and
  325. * the region.
  326. *
  327. * @returns {ReactElement}
  328. * @private
  329. */
  330. _renderE2eRtt() {
  331. const { e2eRtt, t } = this.props;
  332. const str = e2eRtt ? `${e2eRtt.toFixed(0)}ms` : 'N/A';
  333. return (
  334. <tr>
  335. <td>
  336. <span>{ t('connectionindicator.e2e_rtt') }</span>
  337. </td>
  338. <td>{ str }</td>
  339. </tr>
  340. );
  341. }
  342. /**
  343. * Creates a table row as a ReactElement for displaying the "connected to"
  344. * information.
  345. *
  346. * @returns {ReactElement}
  347. * @private
  348. */
  349. _renderRegion() {
  350. const { region, serverRegion, t } = this.props;
  351. let str = serverRegion;
  352. if (!serverRegion) {
  353. return;
  354. }
  355. if (region && serverRegion && region !== serverRegion) {
  356. str += ` from ${region}`;
  357. }
  358. return (
  359. <tr>
  360. <td>
  361. <span>{ t('connectionindicator.connectedTo') }</span>
  362. </td>
  363. <td>{ str }</td>
  364. </tr>
  365. );
  366. }
  367. /**
  368. * Creates a table row as a ReactElement for displaying the "bridge count"
  369. * information.
  370. *
  371. * @returns {*}
  372. * @private
  373. */
  374. _renderBridgeCount() {
  375. const { bridgeCount, t } = this.props;
  376. // 0 is valid, but undefined/null/NaN aren't.
  377. if (!bridgeCount && bridgeCount !== 0) {
  378. return;
  379. }
  380. return (
  381. <tr>
  382. <td>
  383. <span>{ t('connectionindicator.bridgeCount') }</span>
  384. </td>
  385. <td>{ bridgeCount }</td>
  386. </tr>
  387. );
  388. }
  389. /**
  390. * Creates a table row as a ReactElement for displaying frame rate related
  391. * statistics.
  392. *
  393. * @private
  394. * @returns {ReactElement}
  395. */
  396. _renderFrameRate() {
  397. const { framerate, t } = this.props;
  398. const frameRateString = Object.keys(framerate || {})
  399. .map(ssrc => framerate[ssrc])
  400. .join(', ') || 'N/A';
  401. return (
  402. <tr>
  403. <td>
  404. <span>{ t('connectionindicator.framerate') }</span>
  405. </td>
  406. <td>{ frameRateString }</td>
  407. </tr>
  408. );
  409. }
  410. /**
  411. * Creates a tables row as a ReactElement for displaying packet loss related
  412. * statistics.
  413. *
  414. * @private
  415. * @returns {ReactElement}
  416. */
  417. _renderPacketLoss() {
  418. const { packetLoss, t } = this.props;
  419. let packetLossTableData;
  420. if (packetLoss) {
  421. const { download, upload } = packetLoss;
  422. packetLossTableData = (
  423. <td>
  424. <span className = 'connection-info__download'>
  425. &darr;
  426. </span>
  427. { download === null ? 'N/A' : `${download}%` }
  428. <span className = 'connection-info__upload'>
  429. &uarr;
  430. </span>
  431. { upload === null ? 'N/A' : `${upload}%` }
  432. </td>
  433. );
  434. } else {
  435. packetLossTableData = <td>N/A</td>;
  436. }
  437. return (
  438. <tr>
  439. <td>
  440. <span>
  441. { t('connectionindicator.packetloss') }
  442. </span>
  443. </td>
  444. { packetLossTableData }
  445. </tr>
  446. );
  447. }
  448. /**
  449. * Creates a table row as a ReactElement for displaying resolution related
  450. * statistics.
  451. *
  452. * @private
  453. * @returns {ReactElement}
  454. */
  455. _renderResolution() {
  456. const { resolution, maxEnabledResolution, t } = this.props;
  457. let resolutionString = Object.keys(resolution || {})
  458. .map(ssrc => {
  459. const { width, height } = resolution[ssrc];
  460. return `${width}x${height}`;
  461. })
  462. .join(', ') || 'N/A';
  463. if (maxEnabledResolution && maxEnabledResolution < 720) {
  464. const maxEnabledResolutionTitle = t('connectionindicator.maxEnabledResolution');
  465. resolutionString += ` (${maxEnabledResolutionTitle} ${maxEnabledResolution}p)`;
  466. }
  467. return (
  468. <tr>
  469. <td>
  470. <span>{ t('connectionindicator.resolution') }</span>
  471. </td>
  472. <td>{ resolutionString }</td>
  473. </tr>
  474. );
  475. }
  476. /**
  477. * Creates a ReactElement for display a link to save the logs.
  478. *
  479. * @private
  480. * @returns {ReactElement}
  481. */
  482. _renderSaveLogs() {
  483. return (
  484. <span>
  485. <a
  486. className = 'savelogs link'
  487. onClick = { this.props.onSaveLogs } >
  488. { this.props.t('connectionindicator.savelogs') }
  489. </a>
  490. <span> | </span>
  491. </span>
  492. );
  493. }
  494. /**
  495. * Creates a ReactElement for display a link to toggle showing additional
  496. * statistics.
  497. *
  498. * @private
  499. * @returns {ReactElement}
  500. */
  501. _renderShowMoreLink() {
  502. const translationKey
  503. = this.props.shouldShowMore
  504. ? 'connectionindicator.less'
  505. : 'connectionindicator.more';
  506. return (
  507. <a
  508. className = 'showmore link'
  509. onClick = { this.props.onShowMore } >
  510. { this.props.t(translationKey) }
  511. </a>
  512. );
  513. }
  514. /**
  515. * Creates a table as a ReactElement for displaying connection statistics.
  516. *
  517. * @private
  518. * @returns {ReactElement}
  519. */
  520. _renderStatistics() {
  521. const isRemoteVideo = !this.props.isLocalVideo;
  522. return (
  523. <table className = 'connection-info__container'>
  524. <tbody>
  525. { this._renderConnectionSummary() }
  526. { this._renderBitrate() }
  527. { this._renderPacketLoss() }
  528. { isRemoteVideo ? this._renderE2eRtt() : null }
  529. { isRemoteVideo ? this._renderRegion() : null }
  530. { this._renderResolution() }
  531. { this._renderFrameRate() }
  532. { this._renderCodecs() }
  533. { isRemoteVideo ? null : this._renderBridgeCount() }
  534. </tbody>
  535. </table>
  536. );
  537. }
  538. /**
  539. * Creates table rows as ReactElements for displaying transport related
  540. * statistics.
  541. *
  542. * @private
  543. * @returns {ReactElement[]}
  544. */
  545. _renderTransport() {
  546. const { t, transport } = this.props;
  547. if (!transport || transport.length === 0) {
  548. const NA = (
  549. <tr key = 'address'>
  550. <td>
  551. <span>{ t('connectionindicator.address') }</span>
  552. </td>
  553. <td>
  554. N/A
  555. </td>
  556. </tr>
  557. );
  558. return [ NA ];
  559. }
  560. const data = {
  561. localIP: [],
  562. localPort: [],
  563. remoteIP: [],
  564. remotePort: [],
  565. transportType: []
  566. };
  567. for (let i = 0; i < transport.length; i++) {
  568. const ip = getIP(transport[i].ip);
  569. const localIP = getIP(transport[i].localip);
  570. const localPort = getPort(transport[i].localip);
  571. const port = getPort(transport[i].ip);
  572. if (!data.remoteIP.includes(ip)) {
  573. data.remoteIP.push(ip);
  574. }
  575. if (!data.localIP.includes(localIP)) {
  576. data.localIP.push(localIP);
  577. }
  578. if (!data.localPort.includes(localPort)) {
  579. data.localPort.push(localPort);
  580. }
  581. if (!data.remotePort.includes(port)) {
  582. data.remotePort.push(port);
  583. }
  584. if (!data.transportType.includes(transport[i].type)) {
  585. data.transportType.push(transport[i].type);
  586. }
  587. }
  588. // All of the transports should be either P2P or JVB
  589. let isP2P = false, isTURN = false;
  590. if (transport.length) {
  591. isP2P = transport[0].p2p;
  592. isTURN = transport[0].localCandidateType === 'relay'
  593. || transport[0].remoteCandidateType === 'relay';
  594. }
  595. const additionalData = [];
  596. if (isP2P) {
  597. additionalData.push(
  598. <span> (p2p)</span>);
  599. }
  600. if (isTURN) {
  601. additionalData.push(<span> (turn)</span>);
  602. }
  603. // First show remote statistics, then local, and then transport type.
  604. const tableRowConfigurations = [
  605. {
  606. additionalData,
  607. data: data.remoteIP,
  608. key: 'remoteaddress',
  609. label: t('connectionindicator.remoteaddress',
  610. { count: data.remoteIP.length })
  611. },
  612. {
  613. data: data.remotePort,
  614. key: 'remoteport',
  615. label: t('connectionindicator.remoteport',
  616. { count: transport.length })
  617. },
  618. {
  619. data: data.localIP,
  620. key: 'localaddress',
  621. label: t('connectionindicator.localaddress',
  622. { count: data.localIP.length })
  623. },
  624. {
  625. data: data.localPort,
  626. key: 'localport',
  627. label: t('connectionindicator.localport',
  628. { count: transport.length })
  629. },
  630. {
  631. data: data.transportType,
  632. key: 'transport',
  633. label: t('connectionindicator.transport',
  634. { count: data.transportType.length })
  635. }
  636. ];
  637. return tableRowConfigurations.map(this._renderTransportTableRow);
  638. }
  639. /**
  640. * Creates a table row as a ReactElement for displaying a transport related
  641. * statistic.
  642. *
  643. * @param {Object} config - Describes the contents of the row.
  644. * @param {ReactElement} config.additionalData - Extra data to display next
  645. * to the passed in config.data.
  646. * @param {Array} config.data - The transport statistics to display.
  647. * @param {string} config.key - The ReactElement's key. Must be unique for
  648. * iterating over multiple child rows.
  649. * @param {string} config.label - The text to display describing the data.
  650. * @private
  651. * @returns {ReactElement}
  652. */
  653. _renderTransportTableRow(config: Object) {
  654. const { additionalData, data, key, label } = config;
  655. return (
  656. <tr key = { key }>
  657. <td>
  658. <span>
  659. { label }
  660. </span>
  661. </td>
  662. <td>
  663. { getStringFromArray(data) }
  664. { additionalData || null }
  665. </td>
  666. </tr>
  667. );
  668. }
  669. }
  670. /**
  671. * Utility for getting the IP from a transport statistics object's
  672. * representation of an IP.
  673. *
  674. * @param {string} value - The transport's IP to parse.
  675. * @private
  676. * @returns {string}
  677. */
  678. function getIP(value) {
  679. if (!value) {
  680. return '';
  681. }
  682. return value.substring(0, value.lastIndexOf(':'));
  683. }
  684. /**
  685. * Utility for getting the port from a transport statistics object's
  686. * representation of an IP.
  687. *
  688. * @param {string} value - The transport's IP to parse.
  689. * @private
  690. * @returns {string}
  691. */
  692. function getPort(value) {
  693. if (!value) {
  694. return '';
  695. }
  696. return value.substring(value.lastIndexOf(':') + 1, value.length);
  697. }
  698. /**
  699. * Utility for concatenating values in an array into a comma separated string.
  700. *
  701. * @param {Array} array - Transport statistics to concatenate.
  702. * @private
  703. * @returns {string}
  704. */
  705. function getStringFromArray(array) {
  706. let res = '';
  707. for (let i = 0; i < array.length; i++) {
  708. res += (i === 0 ? '' : ', ') + array[i];
  709. }
  710. return res;
  711. }
  712. export default translate(ConnectionStatsTable);