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 25KB

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